mirror of
https://github.com/alexgo-io/DefiLlama-Adapters.git
synced 2026-01-12 16:53:02 +08:00
Dodo (#8145)
* fix: dodo add base,linea,scroll,manta,mantle chain data * fix dodo --------- Co-authored-by: pengyongjun <pengyongjun@vip.qq.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
const { request, gql } = require("graphql-request");
|
||||
const { request, } = require("graphql-request");
|
||||
const { getBlock } = require('../helper/http')
|
||||
const sdk = require('@defillama/sdk')
|
||||
const { getLogs } = require('../helper/cache/getLogs')
|
||||
|
||||
const graphEndpoints = {
|
||||
'ethereum': "https://api.thegraph.com/subgraphs/name/dodoex/dodoex-v2",
|
||||
@@ -11,36 +12,35 @@ const graphEndpoints = {
|
||||
"aurora": "https://api.thegraph.com/subgraphs/name/dodoex/dodoex-v2-aurora",
|
||||
"avax": "https://api.thegraph.com/subgraphs/name/dodoex/dodoex-v2-avax",
|
||||
"optimism": "https://api.thegraph.com/subgraphs/name/dodoex/dodoex-v2-optimism",
|
||||
// "base": "https://api.dodoex.io/frontend-graphql?chainId=84531&schemaName=dodoex", //different query
|
||||
// "linea": "https://api.dodoex.io/frontend-graphql?chainId=534351&schemaName=dodoex" //different query
|
||||
"base": "https://api.studio.thegraph.com/query/2860/dodoex_v2_base/v0.0.5",
|
||||
// "linea": "https://api.dodoex.io/graphql?chainId=59144&schemaName=dodoex&apikey=graphqldefiLlamadodoYzj5giof",
|
||||
// "scroll": "https://api.dodoex.io/graphql?chain=src&schemaName=dodoex&apikey=graphqldefiLlamadodoYzj5giof", // ChainId mapping error, so using chain
|
||||
// "manta": "https://api.dodoex.io/graphql?chainId=169&schemaName=dodoex&apikey=graphqldefiLlamadodoYzj5giof",
|
||||
// "mantle": "https://api.dodoex.io/graphql?chainId=5000&schemaName=dodoex&apikey=graphqldefiLlamadodoYzj5giof"
|
||||
}
|
||||
const graphQuery = gql`
|
||||
query get_pairs($lastId: String, $block: Int) {
|
||||
pairs(
|
||||
first: 1000,
|
||||
block: { number: $block }
|
||||
where: {id_gt: $lastId}
|
||||
) {
|
||||
id
|
||||
baseReserve
|
||||
quoteReserve
|
||||
baseToken{
|
||||
id
|
||||
symbol
|
||||
usdPrice
|
||||
decimals
|
||||
}
|
||||
quoteToken{
|
||||
id
|
||||
symbol
|
||||
usdPrice
|
||||
decimals
|
||||
}
|
||||
const graphQuery = `query get_pairs($lastId: ID, $block: Int!) {
|
||||
pairs(
|
||||
first: 1000
|
||||
block: {number: $block}
|
||||
where: {and: [{id_gt: $lastId}, {or: [{baseReserve_gt: 0}, {quoteReserve_gt: 0}]}]}
|
||||
) {
|
||||
id
|
||||
baseReserve
|
||||
quoteReserve
|
||||
baseToken {
|
||||
id
|
||||
symbol
|
||||
usdPrice
|
||||
decimals
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
module.exports = {};
|
||||
quoteToken {
|
||||
id
|
||||
symbol
|
||||
usdPrice
|
||||
decimals
|
||||
}
|
||||
}
|
||||
}`
|
||||
|
||||
Object.keys(graphEndpoints).forEach(chain => {
|
||||
module.exports[chain] = {
|
||||
@@ -75,9 +75,9 @@ Object.keys(graphEndpoints).forEach(chain => {
|
||||
allPairs.forEach(pair => {
|
||||
if (pair.id.includes('-'))
|
||||
return null
|
||||
if (!blacklist.includes(pair.baseToken.id.toLowerCase()) && +pair.baseReserve > 1)
|
||||
if (!blacklist.includes(pair.baseToken.id.toLowerCase()) && +pair.baseReserve > 1 && +pair.baseToken.usdPrice > 0)
|
||||
sdk.util.sumSingleBalance(balances, chain + ':' + pair.baseToken.id, pair.baseReserve * (10 ** pair.baseToken.decimals))
|
||||
if (!blacklist.includes(pair.quoteToken.id.toLowerCase()) && +pair.quoteReserve > 1)
|
||||
if (!blacklist.includes(pair.quoteToken.id.toLowerCase()) && +pair.quoteReserve > 1 && +pair.quoteToken.usdPrice > 0)
|
||||
sdk.util.sumSingleBalance(balances, chain + ':' + pair.quoteToken.id, pair.quoteReserve * (10 ** pair.quoteToken.decimals))
|
||||
})
|
||||
|
||||
@@ -85,3 +85,36 @@ Object.keys(graphEndpoints).forEach(chain => {
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const config = {
|
||||
// avax: { factory: '0xfF133A6D335b50bDAa6612D19E1352B049A8aE6a', fromBlock: 8488454, dspFactory: '0x2b0d94Eb7A63B8a2909dE1CB3951ecF7Ae76D2fE', dppFactory: '0xb7865a5cee051d35b09a48b624d7057d3362655a' },
|
||||
aurora: { factory: '0x5515363c0412AdD5c72d3E302fE1bD7dCBCF93Fe', fromBlock: 51263254, dspFactory: '0xbe9a66e49503e84ae59a4d0545365AABedf33b40' },
|
||||
optimism: { factory: '0x2b800dc6270726f7e2266ce8cd5a3f8436fe0b40', fromBlock: 5886090, dspFactory: '0x1f83858cD6d0ae7a08aB1FD977C06DABEcE6d711' },
|
||||
base: { factory: '0x0226fCE8c969604C3A0AD19c37d1FAFac73e13c2', fromBlock: 1996181, dspFactory: '0x200D866Edf41070DE251Ef92715a6Ea825A5Eb80' },
|
||||
linea: { factory: '0xc0F9553Df63De5a97Fe64422c8578D0657C360f7', fromBlock: 91468, dspFactory: '0x2933c0374089D7D98BA0C71c5E02E1A0e09deBEE' },
|
||||
scroll: { factory: '0x5a0C840a7089aa222c4458b3BE0947fe5a5006DE', fromBlock: 83070, dspFactory: '0x7E9c460d0A10bd0605B15F0d0388e307d34a62E6' },
|
||||
manta: { factory: '0x97bBF5BB1dcfC93A8c67e97E50Bea19DB3416A83', fromBlock: 384137, dspFactory: '0x29C7718e8B606cEF1c44Fe6e43e07aF9D0875DE1' },
|
||||
}
|
||||
|
||||
Object.keys(config).forEach(chain => {
|
||||
const { factory, fromBlock, dspFactory, dppFactory } = config[chain]
|
||||
module.exports[chain] = {
|
||||
tvl: async (_, _b, _cb, { api, }) => {
|
||||
const ownerTokens = []
|
||||
await Promise.all([
|
||||
addLogs(factory, 'event NewDVM (address baseToken, address quoteToken, address creator, address pool)'),
|
||||
addLogs(dspFactory, 'event NewDSP(address baseToken, address quoteToken, address creator, address pool)'),
|
||||
addLogs(dppFactory, 'event NewDPP (address baseToken, address quoteToken, address creator, address pool)'),
|
||||
])
|
||||
console.log(ownerTokens.length * 2, api.chain)
|
||||
return api.sumTokens({ ownerTokens })
|
||||
|
||||
async function addLogs(target, eventAbi) {
|
||||
if (!target) return;
|
||||
const convert = i => [[i.baseToken, i.quoteToken], i.pool]
|
||||
const logs = await getLogs({ api, target, eventAbi, onlyArgs: true, fromBlock, })
|
||||
ownerTokens.push(...logs.map(convert))
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
5
test.js
5
test.js
@@ -379,7 +379,7 @@ async function computeTVL(balances, timestamp) {
|
||||
const balance = balances[address];
|
||||
|
||||
if (data == undefined) tokenBalances[`UNKNOWN (${address})`] = balance
|
||||
if ('confidence' in data && data.confidence < confidenceThreshold) return
|
||||
if ('confidence' in data && data.confidence < confidenceThreshold || !data.price) return
|
||||
if (Math.abs(data.timestamp - Date.now() / 1e3) > (24 * 3600)) {
|
||||
console.log(`Price for ${address} is stale, ignoring...`)
|
||||
return
|
||||
@@ -403,6 +403,9 @@ Warning: `)
|
||||
tokenBalances[data.symbol] = (tokenBalances[data.symbol] ?? 0) + amount;
|
||||
usdTokenBalances[data.symbol] = (usdTokenBalances[data.symbol] ?? 0) + usdAmount;
|
||||
usdTvl += usdAmount;
|
||||
if (isNaN(usdTvl)) {
|
||||
throw new Error(`NaN usdTvl for ${address} with balance ${balance} and price ${data.price}`)
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user