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

Idex polygon tvl #535

Open
wants to merge 2 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
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
16 changes: 16 additions & 0 deletions chains/polygon/idex/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const sdk = require('../../../../sdk');

module.exports = {
name: "IDEX",
token: "IDEX",
chain: "polygon",
category: "DEXes",
start: 1638316800,
tokenHolderMap: [{
tokens: async () => {
const allTokens = await sdk.api.util.tokenList();
return allTokens.map(token => token.contract);
},
holders: '0x3bcc4eca0a40358558ca8d1bcd2d1dbde63eb468',
}],
};
23 changes: 0 additions & 23 deletions projects/idex/api.js

This file was deleted.

37 changes: 19 additions & 18 deletions projects/idex/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,39 @@
==================================================*/

const sdk = require("../../sdk");
const { getAssets } = require("./api");

const API_CALL_CHUNK_SIZE = 100;
const IDEX_CUSTODY_CONTRACT = "0xE5c405C5578d84c5231D3a9a29Ef4374423fA0c2";

/*==================================================
TVL
==================================================*/

async function tvl(timestamp, block) {
const assets = await getAssets();
async function tvl(_timestamp, block) {
const assets = await sdk.api.util.tokenList();

const balances = {
"0x0000000000000000000000000000000000000000": (
await sdk.api.eth.getBalance({ target: IDEX_CUSTODY_CONTRACT, block })
).output
};

const assetBalancesResult = await sdk.api.abi.multiCall({
abi: "erc20:balanceOf",
block,
calls: assets.reduce((arr, asset) => {
if (asset.symbol !== "ETH") {
arr.push({
target: asset.contractAddress,
params: IDEX_CUSTODY_CONTRACT,
});
}
return arr;
}, []),
});

sdk.util.sumMultiBalanceOf(balances, assetBalancesResult);
while (assets.length) {
const assetBalancesResult = await sdk.api.abi.multiCall({
abi: "erc20:balanceOf",
block,
calls: assets.splice(0,API_CALL_CHUNK_SIZE).reduce((arr, asset) => {
if (asset.symbol !== "ETH") {
arr.push({
target: asset.contract,
params: IDEX_CUSTODY_CONTRACT,
});
}
return arr;
}, []),
});
sdk.util.sumMultiBalanceOf(balances, assetBalancesResult);
}

return balances;
}
Expand Down
15 changes: 15 additions & 0 deletions v2/projects/idex/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const sdk = require("../../sdk");

module.exports = {
name: "IDEX",
token: "IDEX",
category: "DEXes",
start: 1603166400,
tokenHolderMap: [{
tokens: async () => {
const allTokens = await sdk.api.util.tokenList();
return allTokens.map(token => token.contract);
},
holders: '0xE5c405C5578d84c5231D3a9a29Ef4374423fA0c2',
}],
};