diff --git a/projects/helper/chain/fuel.js b/projects/helper/chain/fuel.js index 240224438a50..fd1dd1e07727 100644 --- a/projects/helper/chain/fuel.js +++ b/projects/helper/chain/fuel.js @@ -28,7 +28,22 @@ async function sumTokens({ api, owner, owners, token, tokens = [], tokensAndOwne } } +async function sumAllTokens({ api, owners = [] }) { + const query = owners.map((owner, i) => `q${i}: contractBalances( + filter: { contract: "${owner}" }, first: 100 + ) { nodes { assetId amount } }`).join('\n'); + + const results = await client.request(`{${query}}`); + Object.values(results).forEach(res => { + res.nodes.forEach(node => { + api.add(node.assetId, node.amount); + }); + }); + + return transformBalances('fuel', api.getBalances()); +} module.exports = { sumTokens, + sumAllTokens } \ No newline at end of file diff --git a/projects/oxiswap/index.js b/projects/oxiswap/index.js new file mode 100644 index 000000000000..884a12beef1b --- /dev/null +++ b/projects/oxiswap/index.js @@ -0,0 +1,12 @@ +const { sumAllTokens } = require("../helper/chain/fuel") + +async function tvl(_, _1, _2, { api }) { + const pairContract = '0x0da1be8528c8f546521ba9507d334cdb06cbc8b8842b3c0a871b1b4195635363'; + return sumAllTokens({ api, owners: [pairContract] }); +} + +module.exports = { + methodology: "TVL is calculated by summing the value of all tokens held in the pair contract.", + fuel: { tvl }, + timetravel: false, +}; \ No newline at end of file