Skip to content

Commit

Permalink
Add Oxiswap adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0077 committed Oct 19, 2024
1 parent 839a88c commit 0a2be4f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
15 changes: 15 additions & 0 deletions projects/helper/chain/fuel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
12 changes: 12 additions & 0 deletions projects/oxiswap/index.js
Original file line number Diff line number Diff line change
@@ -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,
};

0 comments on commit 0a2be4f

Please sign in to comment.