mirror of
https://github.com/alexgo-io/DefiLlama-Adapters.git
synced 2026-04-29 13:25:30 +08:00
add sushi on harmony
This commit is contained in:
6
package-lock.json
generated
6
package-lock.json
generated
@@ -341,9 +341,9 @@
|
||||
}
|
||||
},
|
||||
"@defillama/sdk": {
|
||||
"version": "2.2.2",
|
||||
"resolved": "https://registry.npmjs.org/@defillama/sdk/-/sdk-2.2.2.tgz",
|
||||
"integrity": "sha512-wIxP/Od2jQMCiXM6SeUy+ZpMaver6ZP/9DVAEoLkECZZEVavn4t5qkWt9nMLtrLLbd1XXLzQJCMmMLksQOMsOw==",
|
||||
"version": "2.2.6",
|
||||
"resolved": "https://registry.npmjs.org/@defillama/sdk/-/sdk-2.2.6.tgz",
|
||||
"integrity": "sha512-sVWatqCKKVLQv5lZhw3QotVH+Pz9tBd/lUDYNOPXtSmudslY94HYAoUDnaGf7ODyrBy0jSTPGfjG4EuUOcdysg==",
|
||||
"requires": {
|
||||
"ethers": "^5.0.32",
|
||||
"graphql": "^15.5.0",
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@acala-network/api": "^2.0.1",
|
||||
"@defillama/sdk": "^2.2.2",
|
||||
"@defillama/sdk": "^2.2.6",
|
||||
"@makerdao/multicall": "^0.12.0",
|
||||
"@polkadot/api": "^5.4.1",
|
||||
"@project-serum/serum": "^0.13.38",
|
||||
|
||||
@@ -5,6 +5,21 @@ const token1 = require('./abis/token1.json');
|
||||
const getReserves = require('./abis/getReserves.json');
|
||||
const factoryAbi = require('./abis/factory.json');
|
||||
|
||||
async function requery(results, chain, block, abi){
|
||||
if(results.some(r=>!r.success)){
|
||||
const failed = results.filter(r=>!r.success)
|
||||
const newResults = await sdk.api.abi
|
||||
.multiCall({
|
||||
abi,
|
||||
chain,
|
||||
calls: failed.map((f) => ({
|
||||
target: f.input.target,
|
||||
})),
|
||||
block,
|
||||
}).then(({ output }) => output);
|
||||
}
|
||||
}
|
||||
|
||||
async function calculateUniTvl(getAddress, block, chain, FACTORY, START_BLOCK, useMulticall = false) {
|
||||
let pairAddresses;
|
||||
if (useMulticall) {
|
||||
|
||||
@@ -131,6 +131,22 @@ async function transformHecoAddress() {
|
||||
};
|
||||
}
|
||||
|
||||
async function transformHarmonyAddress() {
|
||||
const bridge = (await utils.fetchURL("https://be4.bridge.hmny.io/tokens/?page=0&size=1000")).data.content
|
||||
|
||||
return (addr) => {
|
||||
if(compareAddresses(addr, "0x6983D1E6DEf3690C4d616b13597A09e6193EA013")){
|
||||
return "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
|
||||
}
|
||||
const srcToken = bridge.find(token => compareAddresses(addr, token.hrc20Address))
|
||||
if (srcToken !== undefined) {
|
||||
const prefix = srcToken.network === "BINANCE"?"bsc:":""
|
||||
return prefix+srcToken.erc20Address
|
||||
}
|
||||
return `harmony:${addr}`
|
||||
}
|
||||
}
|
||||
|
||||
function fixAvaxBalances(balances){
|
||||
for(const representation of ["avax:0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7", '0x9dEbca6eA3af87Bf422Cea9ac955618ceb56EfB4']){
|
||||
if(balances[representation] !== undefined){
|
||||
@@ -140,6 +156,15 @@ function fixAvaxBalances(balances){
|
||||
}
|
||||
}
|
||||
|
||||
function fixHarmonyBalances(balances){
|
||||
for(const representation of ["harmony:0xcf664087a5bb0237a0bad6742852ec6c8d69a27a", '0xcf664087a5bb0237a0bad6742852ec6c8d69a27a', 'harmony:0xcF664087a5bB0237a0BAd6742852ec6c8d69A27a', '0xcF664087a5bB0237a0BAd6742852ec6c8d69A27a', 'bsc:0xdE976f3344cd9F06E451aF3A94a324afC3E154F4', 'bsc:0xde976f3344cd9f06e451af3a94a324afc3e154f4']){
|
||||
if(balances[representation] !== undefined){
|
||||
balances['harmony'] = Number(balances[representation])/1e18
|
||||
delete balances[representation]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
transformFantomAddress,
|
||||
transformBscAddress,
|
||||
@@ -147,5 +172,7 @@ module.exports = {
|
||||
transformXdaiAddress,
|
||||
transformAvaxAddress,
|
||||
transformHecoAddress,
|
||||
fixAvaxBalances
|
||||
transformHarmonyAddress,
|
||||
fixAvaxBalances,
|
||||
fixHarmonyBalances
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
const { request, gql } = require("graphql-request");
|
||||
const { toUSDTBalances } = require('../helper/balances');
|
||||
const { calculateUniTvl } = require('../helper/calculateUniTvl.js')
|
||||
const { transformFantomAddress, transformXdaiAddress } = require('../helper/portedTokens')
|
||||
const { transformFantomAddress, transformHarmonyAddress, fixHarmonyBalances } = require('../helper/portedTokens')
|
||||
const { getBlock } = require('../helper/getBlock')
|
||||
const sdk = require('@defillama/sdk')
|
||||
|
||||
@@ -48,14 +48,21 @@ async function fantom(timestamp, ethBlock, chainBlocks) {
|
||||
}
|
||||
|
||||
async function xdai(timestamp, ethBlock, chainBlocks) {
|
||||
const transform = await transformXdaiAddress()
|
||||
return calculateUniTvl(transform, chainBlocks['xdai'], 'xdai', factory, 0, true);
|
||||
return calculateUniTvl(addr=>`xdai:${addr}`, chainBlocks['xdai'], 'xdai', factory, 0, true);
|
||||
}
|
||||
|
||||
async function bsc(timestamp, ethBlock, chainBlocks) {
|
||||
return calculateUniTvl(addr => `bsc:${addr}`, chainBlocks['bsc'], 'bsc', factory, 0, true);
|
||||
}
|
||||
|
||||
async function harmony(timestamp, ethBlock, chainBlocks) {
|
||||
const block = await getBlock(timestamp, 'harmony', chainBlocks);
|
||||
const transform = await transformHarmonyAddress()
|
||||
const balances = await calculateUniTvl(transform, block, 'harmony', factory, 0, true);
|
||||
fixHarmonyBalances(balances)
|
||||
return balances
|
||||
}
|
||||
|
||||
// Not good support from coingecko
|
||||
async function heco(timestamp, ethBlock, chainBlocks) {
|
||||
const block = undefined //TODO: FIx
|
||||
@@ -66,6 +73,12 @@ async function heco(timestamp, ethBlock, chainBlocks) {
|
||||
|
||||
module.exports = {
|
||||
misrepresentedTokens: true,
|
||||
xdai: {
|
||||
tvl: xdai
|
||||
},
|
||||
harmony:{
|
||||
tvl: harmony
|
||||
},
|
||||
ethereum: {
|
||||
tvl: eth,
|
||||
},
|
||||
@@ -78,11 +91,8 @@ module.exports = {
|
||||
bsc: {
|
||||
tvl: bsc
|
||||
},
|
||||
xdai: {
|
||||
tvl: xdai
|
||||
},
|
||||
heco:{
|
||||
tvl: heco
|
||||
},
|
||||
tvl: sdk.util.sumChainTvls([eth, polygon, fantom, bsc, xdai, heco])
|
||||
tvl: sdk.util.sumChainTvls([eth, polygon, fantom, bsc, xdai, heco, harmony])
|
||||
}
|
||||
Reference in New Issue
Block a user