Skip to content

Commit 0e070fe

Browse files
g1nt0kiwegory
andauthored
Add MetaStreet Airdrop Pass functionality (DefiLlama#11367)
* add metastreet-airdrop-pass * code refactor * code refactor --------- Co-authored-by: wegory <[email protected]>
1 parent 90573d6 commit 0e070fe

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

projects/delagate-xyz/index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const { getLogs2, } = require('../helper/cache/getLogs')
2+
const { getUniqueAddresses } = require('../helper/tokenMapping')
3+
const { sumTokens2 } = require('../helper/unwrapLPs')
4+
5+
async function tvl(api) {
6+
const tokens = await getLogs2({
7+
api,
8+
factory: '0x00000000000000447e69651d841bD8D104Bed493',
9+
fromBlock: 18184587,
10+
eventAbi: 'event DelegateERC721 (address indexed from, address indexed to, address indexed contract, uint256 tokenId, bytes32 rights, bool enable)',
11+
customCacheFunction: ({ cache, logs }) => {
12+
if (!cache.logs) cache.logs = []
13+
cache.logs.push(...logs.map(i => i.contract))
14+
cache.logs = getUniqueAddresses(cache.logs)
15+
return cache
16+
},
17+
})
18+
return sumTokens2({ owner: '0xc2e257476822377dfb549f001b4cb00103345e66', tokens, permitFailure: true, sumChunkSize: 50 })
19+
}
20+
21+
module.exports = {
22+
ethereum: {
23+
tvl,
24+
},
25+
}

projects/helper/tokenMapping.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const fixBalancesTokens = {
6363

6464
ibcChains.forEach(chain => fixBalancesTokens[chain] = { ...ibcMappings, ...(fixBalancesTokens[chain] || {}) })
6565

66-
function getUniqueAddresses(addresses, chain) {
66+
function getUniqueAddresses(addresses, chain = 'ethereum') {
6767
const toLowerCase = !caseSensitiveChains.includes(chain)
6868
const set = new Set()
6969
addresses.forEach(i => set.add(toLowerCase ? i.toLowerCase() : i))

projects/helper/unwrapLPs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -906,8 +906,8 @@ async function sumTokens2({
906906

907907
if (resolveNFTs) {
908908
const coreNftTokens = whitelistedNFTs[api.chain] ?? []
909-
const nftTokens = await Promise.all(owners.map(i => covalentGetTokens(i, api)))
910-
nftTokens.forEach((tokens, i) => ownerTokens.push([[tokens, coreNftTokens].flat(), owners[i]]))
909+
const nftTokens = await Promise.all(owners.map(i => covalentGetTokens(i, api, { onlyWhitelisted: false})))
910+
nftTokens.forEach((nfts, i) => ownerTokens.push([[nfts, tokens, coreNftTokens].flat(), owners[i]]))
911911
}
912912

913913
if (solidlyVeNfts.length) {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
async function tvl(api) {
2+
const factory = '0xA8a7e295c19b7D9239A992B8D9C053917b8841C6'
3+
const delegateV2 = '0x00000000000000447e69651d841bD8D104Bed493'
4+
const delegations = await api.call({ abi: abi.getIncomingDelegations, target: delegateV2, params: factory })
5+
delegations.filter(i => i.type_ === '3').forEach(i => api.add(i.contract_, 1))
6+
}
7+
8+
module.exports = {
9+
ethereum: {
10+
tvl,
11+
},
12+
methodology: "TVL is calculated by summing the value of underlying NFTs of the delegation tokens owned by MetaStreet Airdrop Pass Factory."
13+
}
14+
15+
const abi = {
16+
"getIncomingDelegations": "function getIncomingDelegations(address to) view returns ((uint8 type_, address to, address from, bytes32 rights, address contract_, uint256 tokenId, uint256 amount)[] delegations_)",
17+
}

0 commit comments

Comments
 (0)