fix broken dex adapters

This commit is contained in:
g1nt0ki
2022-12-08 10:46:57 +01:00
parent aa5752d80d
commit 62ad4bcb11
6 changed files with 25 additions and 17 deletions

View File

@@ -20,16 +20,8 @@ function getUniTVL({ chain = 'ethereum', coreAssets, blacklist = [], factory, bl
factory = factory.toLowerCase()
const key = `${factory}-${chain}`
return async (ts, _block, { [chain]: block }) => {
let cache = await getCache(cacheFolder, key)
if (!cache.pairs) {
cache = {
pairs: [],
token0s: [],
token1s: [],
}
}
let cache = await _getCache(cacheFolder, key)
const _oldPairInfoLength = cache.pairs.length
const length = await sdk.api2.abi.call({ abi: abi.allPairsLength, target: factory, chain, block, })
@@ -75,6 +67,22 @@ function getUniTVL({ chain = 'ethereum', coreAssets, blacklist = [], factory, bl
return transformBalances(chain, balances)
}
async function _getCache(cacheFolder, key) {
let cache = await getCache(cacheFolder, key)
if (cache.pairs) {
if (cache.pairs.includes(null) || cache.token0s.includes(null) || cache.token1s.includes(null))
cache.pairs = undefined
}
if (!cache.pairs) {
cache = {
pairs: [],
token0s: [],
token1s: [],
}
}
return cache
}
}
module.exports = {

View File

@@ -2,7 +2,7 @@ const { stakings } = require("../helper/staking");
const sdk = require('@defillama/sdk')
const { getUniTVL } = require('../helper/unknownTokens')
const getReservesABI = { "inputs": [], "name": "getReserves", "outputs": [{ "internalType": "uint256", "name": "_reserve0", "type": "uint256" }, { "internalType": "uint256", "name": "_reserve1", "type": "uint256" }], "stateMutability": "view", "type": "function" }
const getReserves = { "inputs": [], "name": "getReserves", "outputs": [{ "internalType": "uint256", "name": "_reserve0", "type": "uint256" }, { "internalType": "uint256", "name": "_reserve1", "type": "uint256" }], "stateMutability": "view", "type": "function" }
const stakingAddresses = [
"0x1d37f1e6f0cce814f367d2765ebad5448e59b91b",
@@ -30,7 +30,7 @@ const config = {
Object.keys(config).forEach(chain => {
const { factories = [], factoriesWithDiffABI = [] } = config[chain]
const exports = [
...factoriesWithDiffABI.map(factory => getUniTVL({ chain, factory, useDefaultCoreAssets: false, abis: { getReservesABI } })),
...factoriesWithDiffABI.map(factory => getUniTVL({ chain, factory, useDefaultCoreAssets: false, abis: { getReserves } })),
...factories.map(factory => getUniTVL({ chain, factory, useDefaultCoreAssets: false })),
]
module.exports[chain] = {

View File

@@ -5,12 +5,12 @@
"outputs": [
{
"internalType": "uint112",
"name": "reserve0",
"name": "_reserve0",
"type": "uint112"
},
{
"internalType": "uint112",
"name": "reserve1",
"name": "_reserve1",
"type": "uint112"
}
],

View File

@@ -1,9 +1,9 @@
const sdk = require('@defillama/sdk')
const { getUniTVL } = require('../helper/unknownTokens')
const getReservesABI = require('./abis/sizeGetReserves.json')
const getReserves = require('./abis/sizeGetReserves.json')
const fiveTVL = getUniTVL({ factory: '0x673662e97b05e001816c380ba5a628d2e29f55d1' })
const sizeTVL = getUniTVL({ factory: '0xC480b33eE5229DE3FbDFAD1D2DCD3F3BAD0C56c6', abis: { getReservesABI } })
const sizeTVL = getUniTVL({ factory: '0xC480b33eE5229DE3FbDFAD1D2DCD3F3BAD0C56c6', abis: { getReserves } })
module.exports = {
ethereum: {

View File

@@ -91,7 +91,7 @@ function classic(chain) {
return getUniTVL({ chain, factory: chains[chain].factory, abis: {
allPairsLength: abi.allPoolsLength,
allPairs: abi.allPools,
getReservesABI: abi.getReserves,
getReserves: abi.getReserves,
} })
}

View File

@@ -57,7 +57,7 @@ const getReservesABI = {
}
// had to be disabled till we get multicall working
const tvl_v0 = getUniTVL({ chain: 'godwoken', factory: '0x5ef0d2d41a5f3d5a083bc776f94282667c27b794', useDefaultCoreAssets: false, abis: { getReservesABI }})
const tvl_v0 = getUniTVL({ chain: 'godwoken', factory: '0x5ef0d2d41a5f3d5a083bc776f94282667c27b794', useDefaultCoreAssets: false, abis: { getReserves: getReservesABI }})
const tvl_v1 = getUniTVL({ chain: 'godwoken_v1', factory: '0x7ec2d60880d83614dd4013D39CF273107f30624c', useDefaultCoreAssets: true, })
module.exports = {