Skip to content

Commit

Permalink
code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
g1nt0ki committed Aug 21, 2024
1 parent cfdd50f commit d3eedf1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 41 deletions.
4 changes: 0 additions & 4 deletions projects/metastreet-airdrop-pass/abi.json

This file was deleted.

45 changes: 8 additions & 37 deletions projects/metastreet-airdrop-pass/index.js
Original file line number Diff line number Diff line change
@@ -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."
Expand Down

0 comments on commit d3eedf1

Please sign in to comment.