From cdcbc9d03311146dcf27a9ae16aa474168ead87d Mon Sep 17 00:00:00 2001 From: newzcard Date: Tue, 11 Jan 2022 22:15:53 -0800 Subject: [PATCH 1/2] feat: json adapter for IDEX/polygon --- chains/polygon/idex/index.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 chains/polygon/idex/index.js diff --git a/chains/polygon/idex/index.js b/chains/polygon/idex/index.js new file mode 100644 index 00000000..f56a6c74 --- /dev/null +++ b/chains/polygon/idex/index.js @@ -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', + }], +}; From 197288e7c9cd175b0b9ba89ffa364da86fd4ae1e Mon Sep 17 00:00:00 2001 From: newzcard Date: Tue, 11 Jan 2022 22:39:18 -0800 Subject: [PATCH 2/2] feat: update v1 idex adapter, add ETH v2 json adapter --- projects/idex/api.js | 23 ----------------------- projects/idex/index.js | 37 +++++++++++++++++++------------------ v2/projects/idex/index.js | 15 +++++++++++++++ 3 files changed, 34 insertions(+), 41 deletions(-) delete mode 100644 projects/idex/api.js create mode 100644 v2/projects/idex/index.js diff --git a/projects/idex/api.js b/projects/idex/api.js deleted file mode 100644 index f61cb4b3..00000000 --- a/projects/idex/api.js +++ /dev/null @@ -1,23 +0,0 @@ -const axios = require('axios'); - -const client = axios.create({ - baseURL: 'https://api.idex.io/v1', - headers: { - 'User-Agent': 'defi-pulse-adapter' - } -}) - -/** - * Capture the assets from the IDEX v2 API - * - * @see https://docs.idex.io/#get-assets - */ -async function getAssets() { - const { data } = await client.get('assets'); - - return data -} - -module.exports = { - getAssets -} diff --git a/projects/idex/index.js b/projects/idex/index.js index c80ee0c4..8ea0cec0 100644 --- a/projects/idex/index.js +++ b/projects/idex/index.js @@ -3,16 +3,16 @@ ==================================================*/ 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": ( @@ -20,21 +20,22 @@ async function tvl(timestamp, 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; } diff --git a/v2/projects/idex/index.js b/v2/projects/idex/index.js new file mode 100644 index 00000000..67928353 --- /dev/null +++ b/v2/projects/idex/index.js @@ -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', + }], +}; \ No newline at end of file