-
Notifications
You must be signed in to change notification settings - Fork 10
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
4 changed files
with
66 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Abi } from 'abitype'; | ||
import FX from '../../../pool/abi/FxPool.json'; | ||
import { getViemClient, ViemClient } from '../../../sources/viem-client'; | ||
import { Chain, PrismaPoolType } from '@prisma/client'; | ||
import { update } from '../v3/type-data/update'; | ||
|
||
export const syncPoolTypeOnchainData = async ( | ||
pools: { id: string; address: string; type: PrismaPoolType }[], | ||
chain: Chain, | ||
) => { | ||
const viemClient = getViemClient(chain); | ||
|
||
// Get FX pools | ||
const fxPools = pools.filter((pool) => pool.type === 'FX'); | ||
const quoteTokens = await fetchFxQuoteTokens(fxPools, viemClient); | ||
await update(quoteTokens); | ||
|
||
return true; | ||
}; | ||
|
||
export const fetchFxQuoteTokens = async (pools: { id: string; address: string }[], viemClient: ViemClient) => { | ||
// Fetch the tokens from the subgraph | ||
const contracts = pools.map(({ address }) => { | ||
return { | ||
address: address as `0x${string}`, | ||
abi: FX as Abi, | ||
functionName: 'derivatives', | ||
args: [1], | ||
}; | ||
}); | ||
|
||
const results = await viemClient.multicall({ contracts, allowFailure: true }); | ||
|
||
return results | ||
.map((call, index) => { | ||
// If the call failed, return null | ||
if (call.status === 'failure') return null; | ||
|
||
return { | ||
id: pools[index].id, | ||
typeData: { quoteToken: (call.result as string).toLowerCase() }, | ||
}; | ||
}) | ||
.filter((quoteToken): quoteToken is { id: string; typeData: { quoteToken: string } } => quoteToken !== null); | ||
}; |
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