Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update our description etc. #13255

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 39 additions & 47 deletions projects/xbanking/index.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,45 @@
const sdk = require("@defillama/sdk");
const abi = require("./abi.json");
const contracts = require("./contracts.json");
const { pool2 } = require("../helper/pool2");
const vaults = [
contracts.ftmVault,
contracts.ethVault,
contracts.avaxVault,
contracts.tombVault,
]
const utils = require('../helper/utils');
let _response;

const tokens = [
contracts.FTM,
contracts.WETH,
contracts.AVAX,
contracts.TOMB,
]
function fetchChain(chainId, staking) {
return async () => {
if (!_response) {
_response = utils.fetchURL('https://api.xbanking.org/v2/platform/tvl');
}
const response = await _response;
let tvl = 0;

async function tvl(api) {
const _tokens = [...tokens]
const owners = [...vaults, ...vaults]
vaults.forEach(v => _tokens.push(contracts.Collateral))
return api.sumTokens({ tokensAndOwners2: [_tokens, owners] })
}

async function borrowed(api) {
const vaults0 = vaults.slice(0, 2);
const vaults1 = vaults.slice(2);
const tokens0 = tokens.slice(0, 2);
const tokens1 = tokens.slice(2);
const balances = await api.multiCall({ abi: abi.see_s1ftm_circ, calls: vaults0 })
const balances1 = await api.multiCall({ abi: abi.see_s1tomb_circ, calls: vaults1 })
api.addTokens(tokens0, balances)
api.addTokens(tokens1, balances1)
const chainName = Object.keys(response).find(key => key.toLowerCase() === chainId.toLowerCase());

if (chainName) {
tvl = Number(response[chainName]);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we cant use this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so u need new code to just change our token chain and new links and smart contract in the start of topic?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we cant fetch a tvl number from your api endpoint. please rewrite the adapter to use on chain data


const chainApi = new sdk.ChainApi({ chain: api.chain, block: api.block })
chainApi.sumTokens({ tokensAndOwners2: [tokens, vaults] })
Object.entries(chainApi.getBalances()).forEach(([token, balance]) => {
api.add(token, balance * -1, { skipChain: true })
})
return api.getBalances()
if (tvl === 0) {
throw new Error(`chain ${chainId} tvl is 0`);
}
return tvl;
};
}

const chains = {
ethereum: 'ethereum',
avax: 'avax',
arbitrum: 'arbitrum',
binance: 'binance',
solana: 'solana',
bitcoin: 'bitcoin',
ton: 'ton',
aptos: 'aptos',
sui: 'sui'
};

module.exports = {
fantom: {
tvl,
borrowed,
pool2: pool2(
[contracts.pool2, contracts.pool2],
[contracts.daiPool2, contracts.ftmPool2],
)
}
}
timetravel: false,
misrepresentedTokens: true,
doublecounted: true,
...Object.fromEntries(Object.entries(chains).map(chain => [chain[0], {
tvl: fetchChain(chain[1], false),
staking: fetchChain(chain[1], true),
}]))
};
Loading