Skip to content

Commit

Permalink
Add MetaStreet Airdrop Pass functionality (DefiLlama#11367)
Browse files Browse the repository at this point in the history
* add metastreet-airdrop-pass

* code refactor

* code refactor

---------

Co-authored-by: wegory <[email protected]>
  • Loading branch information
2 people authored and tlatkdgus1 committed Nov 25, 2024
1 parent 6e7e2f4 commit be55c84
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
25 changes: 25 additions & 0 deletions projects/delagate-xyz/index.js
Original file line number Diff line number Diff line change
@@ -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,
},
}
2 changes: 1 addition & 1 deletion projects/helper/tokenMapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions projects/helper/unwrapLPs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
17 changes: 17 additions & 0 deletions projects/metastreet-airdrop-pass/index.js
Original file line number Diff line number Diff line change
@@ -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_)",
}

0 comments on commit be55c84

Please sign in to comment.