-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from ixofoundation/develop
fix: fix bonds index parallel
- Loading branch information
Showing
10 changed files
with
72 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,51 @@ | ||
import { QueryBondsDetailedResponse } from "@ixo/impactxclient-sdk/types/codegen/ixo/bonds/v1beta1/query"; | ||
import { Prisma } from "@prisma/client"; | ||
import * as BondHandler from "../handlers/bond_handler"; | ||
import { prisma } from "../prisma/prisma_client"; | ||
|
||
export const syncBondsInfo = async ( | ||
bondsInfo: QueryBondsDetailedResponse, | ||
timestamp: Date | ||
) => { | ||
for (const bond of bondsInfo.bondsDetailed) { | ||
try { | ||
const bondExists = await BondHandler.listBondByBondDid(bond.bondDid); | ||
if (!!bondExists) { | ||
const amount = new Prisma.Decimal(bond.spotPrice[0].amount); | ||
const denom = bond.spotPrice[0].denom; | ||
const lastPrice = await BondHandler.getLastPrice(bond.bondDid); | ||
if (!bondsInfo.bondsDetailed?.length) return; | ||
|
||
if (!!lastPrice) { | ||
if (!lastPrice.price.equals(amount)) { | ||
const bonds = await prisma.bond.findMany({ | ||
where: { | ||
bondDid: { in: bondsInfo.bondsDetailed.map((bond) => bond.bondDid) }, | ||
}, | ||
}); | ||
|
||
await Promise.all( | ||
bondsInfo.bondsDetailed.map(async (bond) => { | ||
try { | ||
// const bondExists = await BondHandler.listBondByBondDid(bond.bondDid); | ||
// if (bondExists) { | ||
if (bonds?.find((b) => b?.bondDid === bond.bondDid)) { | ||
const amount = new Prisma.Decimal(bond.spotPrice[0].amount); | ||
const denom = bond.spotPrice[0].denom; | ||
const lastPrice = await BondHandler.getLastPrice(bond.bondDid); | ||
|
||
if (lastPrice) { | ||
if (!lastPrice.price.equals(amount)) { | ||
await BondHandler.createPriceEntry({ | ||
bondDid: bond.bondDid, | ||
time: timestamp, | ||
denom: denom, | ||
price: amount, | ||
}); | ||
} | ||
} else { | ||
await BondHandler.createPriceEntry({ | ||
bondDid: bond.bondDid, | ||
time: timestamp, | ||
denom: denom, | ||
price: amount, | ||
}); | ||
} | ||
} else { | ||
await BondHandler.createPriceEntry({ | ||
bondDid: bond.bondDid, | ||
time: timestamp, | ||
denom: denom, | ||
price: amount, | ||
}); | ||
} | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
} | ||
}) | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters