-
Notifications
You must be signed in to change notification settings - Fork 13
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
17 changed files
with
455 additions
and
43 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
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,62 @@ | ||
import { PoolTokenCreate } from '@modules/stores/pools_store'; | ||
import { parseAbi } from 'viem'; | ||
import { ViemClient } from '../types'; | ||
|
||
type PoolTokenInfo = { | ||
tokens: `0x${string}`[], | ||
tokenTypes: number[], | ||
balancesRaw: bigint[], | ||
decimalScalingFactors: bigint[], | ||
rateProviders: `0x${string}`[], | ||
}; | ||
|
||
const abi = parseAbi([ | ||
'function getPoolTokenInfo(address pool) view returns (address[] tokens, uint8[] tokenTypes, uint[] balancesRaw, uint[] decimalScalingFactors, address[] rateProviders)' | ||
]); | ||
|
||
const poolTokensTransformer = ( | ||
poolAddress: string, | ||
poolTokenInfo: PoolTokenInfo, | ||
): PoolTokenCreate[] => poolTokenInfo.tokens.map((address, i) => ({ | ||
id: `${poolAddress}-${address}`, | ||
address, | ||
index: i, | ||
priceRateProvider: poolTokenInfo.rateProviders[i], | ||
exemptFromProtocolYieldFee: false, // where do we have this information onchain? | ||
nestedPoolId: null, // TODO: might be easier to do that in SQL on read | ||
})); | ||
|
||
export async function fetchPoolTokens(vault: string, pools: string[], client: ViemClient) { | ||
const contracts = pools | ||
.map((pool) => [ | ||
{ | ||
address: vault as `0x${string}`, | ||
abi, | ||
args: [pool as `0x${string}`], | ||
functionName: 'getPoolTokenInfo', | ||
}, | ||
]) | ||
.flat(); | ||
|
||
const results = await client.multicall({ contracts }); | ||
|
||
// Parse the results | ||
const parsedResults = results.map((result, i) => { | ||
if (result.status === 'success' && result.result !== undefined) { | ||
// parse the result here using the abi | ||
const poolTokens = poolTokensTransformer(pools[i], { | ||
tokens: result.result[0], | ||
tokenTypes: result.result[1], | ||
balancesRaw: result.result[2], | ||
decimalScalingFactors: result.result[3], | ||
rateProviders: result.result[4], | ||
} as PoolTokenInfo) | ||
|
||
return [pools[i], poolTokens]; | ||
} | ||
// Handle the error | ||
return undefined; | ||
}).filter((result): result is [string, PoolTokenCreate[]] => result !== undefined); | ||
|
||
return Object.fromEntries(parsedResults); | ||
} |
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 +1,2 @@ | ||
export * from './fetch_pool_headers'; | ||
export * from './fetch-erc20-headers'; | ||
export * from './fetch-pool-tokens'; |
Oops, something went wrong.