From d3eedf16b0ffd48d424480f1aa0e0ccba24ff02e Mon Sep 17 00:00:00 2001 From: g1nt0ki <99907941+g1nt0ki@users.noreply.github.com> Date: Wed, 21 Aug 2024 13:31:02 +0200 Subject: [PATCH] code refactor --- projects/metastreet-airdrop-pass/abi.json | 4 -- projects/metastreet-airdrop-pass/index.js | 45 ++++------------------- 2 files changed, 8 insertions(+), 41 deletions(-) delete mode 100644 projects/metastreet-airdrop-pass/abi.json diff --git a/projects/metastreet-airdrop-pass/abi.json b/projects/metastreet-airdrop-pass/abi.json deleted file mode 100644 index a5b7deaa24..0000000000 --- a/projects/metastreet-airdrop-pass/abi.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "delegateTokenIds": "function delegateTokenIds(address airdropPassToken, uint256 offset, uint256 count) external view returns (uint256[] memory)", - "AirdropPassTokenDeployed": "event AirdropPassTokenDeployed(address indexed airdropPassToken, bytes32 indexed deploymentHash, address indexed token, uint256 expiry, bytes32 rights)" -} \ No newline at end of file diff --git a/projects/metastreet-airdrop-pass/index.js b/projects/metastreet-airdrop-pass/index.js index ba45addd9b..500cf68363 100644 --- a/projects/metastreet-airdrop-pass/index.js +++ b/projects/metastreet-airdrop-pass/index.js @@ -1,47 +1,18 @@ -const abi = require("./abi.json"); -var ethers = require("ethers"); -var getLogs = require("../helper/cache/getLogs"); - -const CHAINS = { - ethereum: { - airdropPassFactory: "0xA8a7e295c19b7D9239A992B8D9C053917b8841C6", - fromBlock: 20518021, // Block number of pool factory creation - } -}; -const MAX_UINT_128 = "0xffffffffffffffffffffffffffffffff"; -const AIRDROP_PASS_DEPLOYED_TOPIC = "0x15fc3a903a61f172517fb952e6bd117215850f3dbfb9de008591509754dabf59"; - +const { getLogs2, getAddress } = require('../helper/cache/getLogs') async function tvl(api) { - const chainInfo = CHAINS[api.chain] - const contract = new ethers.Contract(chainInfo.airdropPassFactory, [abi["AirdropPassTokenDeployed"]]); - - /* Get airdrop pass deployed logs and parse it */ - const rawLogs = await getLogs.getLogs({ - target: chainInfo.airdropPassFactory, - fromBlock: chainInfo.fromBlock, + const logs = await getLogs2({ api, - topics: [AIRDROP_PASS_DEPLOYED_TOPIC], - }); - const parsedLogs = rawLogs.map((log) => ({ - ...contract.interface.parseLog(log), - })).filter(o => o.args[3] > api.timestamp); - - /* Compute delegate tokens balances held by factory */ - const delegateTokenIds = await api.multiCall({ abi: abi.delegateTokenIds, calls: parsedLogs.map((log) => ({ - target: chainInfo.airdropPassFactory, - params: [log.args[0], 0, MAX_UINT_128]}))}); - const balances = {} - parsedLogs.map((log, index) => { - const k = `${api.chain}:${log.args[2]}` - balances[k] = delegateTokenIds[index].length + factory:'0xA8a7e295c19b7D9239A992B8D9C053917b8841C6', + fromBlock: 20518021, + topics: ['0x15fc3a903a61f172517fb952e6bd117215850f3dbfb9de008591509754dabf59'] }) - - return balances; + const nfts = logs.map(log => getAddress(log.topics[3])) + return api.sumTokens({ owner: '0xc2e257476822377dfb549f001b4cb00103345e66', tokens: nfts}) } module.exports = { ethereum: { - tvl + tvl, }, methodology: "TVL is calculated by summing the value of underlying NFTs of the delegation tokens owned by MetaStreet Airdrop Pass Factory."