diff --git a/projects/delagate-xyz/index.js b/projects/delagate-xyz/index.js new file mode 100644 index 000000000000..0eb3f51366ce --- /dev/null +++ b/projects/delagate-xyz/index.js @@ -0,0 +1,25 @@ +const { getLogs2, } = require('../helper/cache/getLogs') +const { getUniqueAddresses } = require('../helper/tokenMapping') +const { sumTokens2 } = require('../helper/unwrapLPs') + +async function tvl(api) { + const tokens = await getLogs2({ + api, + factory: '0x00000000000000447e69651d841bD8D104Bed493', + fromBlock: 18184587, + eventAbi: 'event DelegateERC721 (address indexed from, address indexed to, address indexed contract, uint256 tokenId, bytes32 rights, bool enable)', + customCacheFunction: ({ cache, logs }) => { + if (!cache.logs) cache.logs = [] + cache.logs.push(...logs.map(i => i.contract)) + cache.logs = getUniqueAddresses(cache.logs) + return cache + }, + }) + return sumTokens2({ owner: '0xc2e257476822377dfb549f001b4cb00103345e66', tokens, permitFailure: true, sumChunkSize: 50 }) +} + +module.exports = { + ethereum: { + tvl, + }, +} \ No newline at end of file diff --git a/projects/helper/tokenMapping.js b/projects/helper/tokenMapping.js index 1136c5aa5250..e5f430de382a 100644 --- a/projects/helper/tokenMapping.js +++ b/projects/helper/tokenMapping.js @@ -63,7 +63,7 @@ const fixBalancesTokens = { ibcChains.forEach(chain => fixBalancesTokens[chain] = { ...ibcMappings, ...(fixBalancesTokens[chain] || {}) }) -function getUniqueAddresses(addresses, chain) { +function getUniqueAddresses(addresses, chain = 'ethereum') { const toLowerCase = !caseSensitiveChains.includes(chain) const set = new Set() addresses.forEach(i => set.add(toLowerCase ? i.toLowerCase() : i)) diff --git a/projects/helper/unwrapLPs.js b/projects/helper/unwrapLPs.js index cdc587eba729..deca1d854b16 100644 --- a/projects/helper/unwrapLPs.js +++ b/projects/helper/unwrapLPs.js @@ -906,8 +906,8 @@ async function sumTokens2({ if (resolveNFTs) { const coreNftTokens = whitelistedNFTs[api.chain] ?? [] - const nftTokens = await Promise.all(owners.map(i => covalentGetTokens(i, api))) - nftTokens.forEach((tokens, i) => ownerTokens.push([[tokens, coreNftTokens].flat(), owners[i]])) + const nftTokens = await Promise.all(owners.map(i => covalentGetTokens(i, api, { onlyWhitelisted: false}))) + nftTokens.forEach((nfts, i) => ownerTokens.push([[nfts, tokens, coreNftTokens].flat(), owners[i]])) } if (solidlyVeNfts.length) { diff --git a/projects/metastreet-airdrop-pass/index.js b/projects/metastreet-airdrop-pass/index.js new file mode 100644 index 000000000000..02e3a35ca40b --- /dev/null +++ b/projects/metastreet-airdrop-pass/index.js @@ -0,0 +1,17 @@ +async function tvl(api) { + const factory = '0xA8a7e295c19b7D9239A992B8D9C053917b8841C6' + const delegateV2 = '0x00000000000000447e69651d841bD8D104Bed493' + const delegations = await api.call({ abi: abi.getIncomingDelegations, target: delegateV2, params: factory }) + delegations.filter(i => i.type_ === '3').forEach(i => api.add(i.contract_, 1)) +} + +module.exports = { + ethereum: { + tvl, + }, + methodology: "TVL is calculated by summing the value of underlying NFTs of the delegation tokens owned by MetaStreet Airdrop Pass Factory." +} + +const abi = { + "getIncomingDelegations": "function getIncomingDelegations(address to) view returns ((uint8 type_, address to, address from, bytes32 rights, address contract_, uint256 tokenId, uint256 amount)[] delegations_)", +}