use injected chain api for querying

This commit is contained in:
g1nt0ki
2022-12-23 01:24:37 +01:00
parent ca49c87e7f
commit 7e3af20f68
4 changed files with 20 additions and 19 deletions

12
package-lock.json generated
View File

@@ -60,9 +60,9 @@
}
},
"node_modules/@defillama/sdk": {
"version": "3.0.14",
"resolved": "https://registry.npmjs.org/@defillama/sdk/-/sdk-3.0.14.tgz",
"integrity": "sha512-CJmqpRSXYNxTutTtoS16qMHrddvieHrbxeGIBra/MyrpVZl76BH1X1rW7MTNWXFutfZ1n4ezYPwaA+I+1zZowA==",
"version": "3.0.15",
"resolved": "https://registry.npmjs.org/@defillama/sdk/-/sdk-3.0.15.tgz",
"integrity": "sha512-+HwKYzPEjqUi9iG5l2SccdCv5IAr10OLoK9tFbdjMCvTShi7BYogR7Qw/+OUWMjZAhcQgIfXmuSQLiWftk1MSQ==",
"dependencies": {
"@supercharge/promise-pool": "^2.1.0",
"ethers": "^5.4.5",
@@ -2978,9 +2978,9 @@
}
},
"@defillama/sdk": {
"version": "3.0.14",
"resolved": "https://registry.npmjs.org/@defillama/sdk/-/sdk-3.0.14.tgz",
"integrity": "sha512-CJmqpRSXYNxTutTtoS16qMHrddvieHrbxeGIBra/MyrpVZl76BH1X1rW7MTNWXFutfZ1n4ezYPwaA+I+1zZowA==",
"version": "3.0.15",
"resolved": "https://registry.npmjs.org/@defillama/sdk/-/sdk-3.0.15.tgz",
"integrity": "sha512-+HwKYzPEjqUi9iG5l2SccdCv5IAr10OLoK9tFbdjMCvTShi7BYogR7Qw/+OUWMjZAhcQgIfXmuSQLiWftk1MSQ==",
"requires": {
"@supercharge/promise-pool": "^2.1.0",
"ethers": "^5.4.5",

View File

@@ -7,12 +7,12 @@ const orderBook = '0x5D36b36c53438C0fb70DCA5082EE5BDe25Bd888B'
const factory = '0x3ee4154c7f42d94e1092ad8ce5debb4b743ed0b2'
const chain = 'polygon'
const tvl = async (_, _b, { polygon: block }) => {
const tvl = async (_, _b, { polygon: block }, { api, }) => {
const balances = {}
const calls = await sdk.api2.abi.fetchList({ block, chain, lengthAbi: uniswapAbi.allPairsLength, itemAbi: uniswapAbi.allPairs, target: factory })
const token0s = await sdk.api2.abi.multiCall({ abi: uniswapAbi.token0, chain, block, calls })
const token1s = await sdk.api2.abi.multiCall({ abi: uniswapAbi.token1, chain, block, calls })
const reserves = await sdk.api2.abi.multiCall({ abi: uniswapAbi.getReserves, chain, block, calls })
const calls = await api.fetchList({ lengthAbi: uniswapAbi.allPairsLength, itemAbi: uniswapAbi.allPairs, target: factory })
const token0s = await api.multiCall({ abi: uniswapAbi.token0, calls })
const token1s = await api.multiCall({ abi: uniswapAbi.token1, calls })
const reserves = await api.multiCall({ abi: uniswapAbi.getReserves, calls })
reserves.forEach(({ _reserve0, _reserve1}, i) => {
sdk.util.sumSingleBalance(balances,token0s[i],_reserve0, chain)
sdk.util.sumSingleBalance(balances,token1s[i],_reserve1, chain)

View File

@@ -1,25 +1,23 @@
const sdk = require("@defillama/sdk");
const abi = require('./tricrypto-vault.json');
module.exports = {
misrepresentedTokens: true,
hallmarks: [
[1670856656,"Launch GLP Vaults"]
[1670856656, "Launch GLP Vaults"]
],
arbitrum: {
tvl: async (_, _b, {arbitrum: block}) => {
tvl: async (_, _b, _cb, { api }) => {
const vaults = [
'0x1d42783E7eeacae12EbC315D1D2D0E3C6230a068', // tricrypto
'0xf9305009fba7e381b3337b5fa157936d73c2cf36', // dnGmxSeniorVault
'0x8478ab5064ebac770ddce77e7d31d969205f041e', // dnGmxJuniorVault
]
const bals = await sdk.api2.abi.multiCall({
abi,calls: vaults,
chain: 'arbitrum', block,
const bals = await api.multiCall({
abi, calls: vaults,
})
return {
tether: bals.reduce((a,i) => a + i/1e6, 0),
tether: bals.reduce((a, i) => a + i / 1e6, 0),
}
}
}

View File

@@ -45,7 +45,10 @@ async function getTvl(
knownTokenPrices
) {
if (!isFetchFunction) {
const tvlBalances = await tvlFunction(unixTimestamp, ethBlock, chainBlocks);
const chain = storedKey.split('-')[0]
const block = chainBlocks[chain]
const api = new sdk.api2.abi.ChainApi({ chain, block: chainBlocks[chain] })
const tvlBalances = await tvlFunction(unixTimestamp, ethBlock, chainBlocks, { api, chain, block, storedKey });
const tvlResults = await computeTVL(
tvlBalances,
"now",