-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
100 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { GraphQLClient } from 'graphql-request'; | ||
import { getSdk } from '../subgraphs/balancer-subgraph/generated/balancer-subgraph-types'; | ||
import { prisma } from '../../prisma/prisma-client'; | ||
import { Chain } from '@prisma/client'; | ||
|
||
/** | ||
* 'Latest FX Price' is relevant only to FX pools. It is sourced from offchain platforms, like Chainlink. | ||
* The subgraph actively indexes this price by listening to the 'Answer Updated' events emitted by Chainlink oracles. | ||
* For reference and more details, see the code at: | ||
* https://github.com/balancer/balancer-subgraph-v2/blob/master/src/mappings/pricing.ts#L373 | ||
* | ||
* Note: 'LatestFXPrice' is a dependency of SORv2. | ||
*/ | ||
export const syncLatestFXPrices = async (subgraphUrl: string, chain: Chain) => { | ||
const { pools } = await fetchFxPools(subgraphUrl); | ||
|
||
for (const pool of pools) { | ||
const { tokens } = pool; | ||
if (!tokens) continue; | ||
|
||
for (const token of tokens) { | ||
try { | ||
await prisma.prismaPoolTokenDynamicData.update({ | ||
where: { | ||
id_chain: { | ||
id: token.id, | ||
chain, | ||
}, | ||
}, | ||
data: { | ||
latestFxPrice: token.token.latestFXPrice ? parseFloat(token.token.latestFXPrice) : undefined, | ||
}, | ||
}); | ||
} catch (e) { | ||
console.error(`Error updating latest FX price for token ${token.id} on chain ${chain}: ${e}`); | ||
} | ||
} | ||
} | ||
|
||
return true; | ||
}; | ||
|
||
const fetchFxPools = (subgraphUrl: string) => { | ||
const sdk = getSdk(new GraphQLClient(subgraphUrl)); | ||
|
||
return sdk.BalancerPools({ | ||
where: { poolType: 'FX' }, | ||
}); | ||
}; |
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
2 changes: 2 additions & 0 deletions
2
prisma/migrations/20231215151625_latest_fx_price/migration.sql
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "PrismaPoolTokenDynamicData" ADD COLUMN "latestFxPrice" DOUBLE PRECISION; |
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