Skip to content

Commit

Permalink
Merge branch 'DefiLlama:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan-zkLinkLabs authored May 11, 2024
2 parents 622eb24 + 3c59ce9 commit 2201de9
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 60 deletions.
16 changes: 16 additions & 0 deletions projects/apestore/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { sumTokensExport } = require("../helper/unwrapLPs");
const coreAssets = require("../helper/coreAssets.json");

const routers = [
"0xF6Af6C034E92694A4c79569B03543d580df402D7",
"0x992D40d9ED8937Bb0Ad3c0Ba99713072Ae0a05b3",
"0x135De7F9223C76b7d0278FFe854eC480D37FE906"
];

const tokens = [coreAssets.null];

module.exports = {
base: {
tvl: sumTokensExport({ owners: routers, tokens })
},
};
3 changes: 2 additions & 1 deletion projects/cerra/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ const { sumTokens2 } = require("../helper/chain/cardano");

const LENDING_SCRIPT = "addr1z878lgw0676mfkusf0f2h9wl3w5q2zu0klrlcamv6g2werc0pqnxu0fg7wvwgjtgzvg6lg6avzczmwf84aclygrvlkhqfmh5zc";
const AMM_SCRIPT = "addr1zyl8u7cw93g99g2e68cq3k27ad7rd8p6yy3yg9vesgahrus0pqnxu0fg7wvwgjtgzvg6lg6avzczmwf84aclygrvlkhq2a0paj";
const BATCHER_SCRIPT = "addr1wye2x4ygs0e3u7wp8d2q82uj60gvfe2wjgc284evk8a5cfqw2hvmv";

async function tvl() {
return sumTokens2({ scripts: [LENDING_SCRIPT, AMM_SCRIPT] })
return sumTokens2({ scripts: [LENDING_SCRIPT, AMM_SCRIPT, BATCHER_SCRIPT] })
}

module.exports = {
Expand Down
12 changes: 10 additions & 2 deletions projects/diva/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
const ADDRESSES = require('../helper/coreAssets.json')
const { sumTokensExport } = require('../helper/unwrapLPs')
const sdk = require("@defillama/sdk")

module.exports = {
methodology: 'ETH and stETH in vaults',
ethereum: {
tvl: sumTokensExport({ owners: [
tvl: sdk.util.sumChainTvls([sumTokensExport({ owners: [
"0x1ce8aafb51e79f6bdc0ef2ebd6fd34b00620f6db",
"0x16770d642e882e1769ce4ac8612b8bc0601506fc"
], tokens: [
ADDRESSES.ethereum.WETH,
ADDRESSES.ethereum.STETH
]}),
]}), async (api) => {
return {
[ADDRESSES.ethereum.WETH]: await api.call({
target: "0x6c1edce139291af5b84fb1e496c9747f83e876c9",
abi: "uint256:totalAssets"
})
}
}]),
}
};
14 changes: 13 additions & 1 deletion projects/helper/utils/solana/layouts/raydium-layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,18 @@ const RAYDIUM_STABLE_STATE_LAYOUT_V1 = struct([
seq(u64("padding"), 64, "padding"),
])

const KeyLayoutv4 = struct([
publicKey('vaultA'),
publicKey('vaultB'),
publicKey('mintA'),
publicKey('mintB'),
])

const TokenAmountLayout = struct([
u64('amount'),
])


module.exports = {
RAYDIUM_LIQUIDITY_STATE_LAYOUT_CLMM, RAYDIUM_STABLE_STATE_LAYOUT_V1,
RAYDIUM_LIQUIDITY_STATE_LAYOUT_CLMM, RAYDIUM_STABLE_STATE_LAYOUT_V1, KeyLayoutv4, TokenAmountLayout,
}
5 changes: 5 additions & 0 deletions projects/keller-v3/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const { uniV3Export } = require('../helper/uniswapV3')

module.exports = uniV3Export({
scroll: { factory: "0x952aC46B2586737df679e836d9B980E43E12B2d8", fromBlock: 4627488 },
})
24 changes: 7 additions & 17 deletions projects/marinade-native/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,15 @@ const { StakeProgram } = require("@solana/web3.js")
const { getConnection } = require('../helper/solana')

async function tvl() {
let hasNext = true
let offset = 0
let length = 9
let nativeTvl = 0
do {
const _stakeAccounts = await getConnection().getProgramAccounts(StakeProgram.programId, {
filters: [{
memcmp: { bytes: 'stWirqFCf2Uts1JBL1Jsd3r6VBWhgnpdPxCTe1MFjrq', offset: 4 + 8 }
}],
dataSlice: { offset, length }
})
nativeTvl += _stakeAccounts.reduce((tvl, { account }) => { return tvl + account.lamports / 1e9 }, 0)

hasNext = _stakeAccounts.length === length
offset += length
} while (hasNext)
const stakeAccounts = await getConnection().getProgramAccounts(StakeProgram.programId, {
filters: [{
memcmp: { bytes: 'stWirqFCf2Uts1JBL1Jsd3r6VBWhgnpdPxCTe1MFjrq', offset: 4 + 8 }
}],
dataSlice: { offset: 0, length: 1 } // we dont care about the data, just the lamports
})

return {
solana: nativeTvl
solana: stakeAccounts.reduce((tvl, { account }) => { return tvl + account.lamports / 1e9 }, 0)
}
}

Expand Down
2 changes: 1 addition & 1 deletion projects/puffer/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const PUF_ETH = '0xD9A442856C234a39a81a089C06451EBAa4306a72';

async function tvl(api) {
return api.erc4626Sum({ calls: [PUF_ETH], isOG4626: true })
return api.erc4626Sum({ calls: [PUF_ETH], isOG4626: true, permitFailure: true, })
}

module.exports = {
Expand Down
115 changes: 80 additions & 35 deletions projects/raydium.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
const { getConnection, sumTokens2, decodeAccount, } = require("./helper/solana");
const { PublicKey, } = require("@solana/web3.js");
const sdk = require('@defillama/sdk');
const sdk = require('@defillama/sdk')

const { TokenAmountLayout, KeyLayoutv4 } = require("./helper/utils/solana/layouts/raydium-layout");
const { transformDexBalances } = require("./helper/portedTokens");
const { sleep } = require("./helper/utils");

const CLMM = 'CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK'
const AmmV4 = '675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8'
Expand Down Expand Up @@ -31,49 +35,90 @@ async function tvlCLMM() {
}


async function ammV4Tvl() {
const owner = '5Q544fKrFoe6tsEbD7S8EmxGTJYAKtTVhAW5Q5pge4j1'
return sumTokens2({ owner, getAllTokenAccounts: true })
async function ammV4Tvl(api) {
const connection = getConnection()
const auth = '5Q544fKrFoe6tsEbD7S8EmxGTJYAKtTVhAW5Q5pge4j1'

await sleep(10000)
const allPoolVaultAmount = await connection.getProgramAccounts(new PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'), { filters: [{ dataSize: 165 }, { memcmp: { offset: 32, bytes: auth } }], dataSlice: { offset: 64, length: TokenAmountLayout.span } })
await sleep(30000)
const allPoolKeyInfo = await connection.getProgramAccounts(new PublicKey(AmmV4), { filters: [{ dataSize: 752 }], dataSlice: { offset: 336, length: KeyLayoutv4.span } })

const vaultIdToAmount = {}
for (const item of allPoolVaultAmount) {
vaultIdToAmount[item.pubkey.toString()] = TokenAmountLayout.decode(item.account.data).amount.toString()
}

let i = 0
let j = 0
let data = []
const emptyKey = PublicKey.default.toString()
for (const item of allPoolKeyInfo) {
const poolKey = KeyLayoutv4.decode(item.account.data)
if (poolKey.vaultA.toString() === emptyKey) continue
const vaultA = poolKey.vaultA.toString()
const vaultB = poolKey.vaultB.toString()
if (isNaN(vaultIdToAmount[vaultA]) || isNaN(vaultIdToAmount[vaultB])) continue

data.push({
token0: poolKey.mintA.toString(),
token1: poolKey.mintB.toString(),
token0Bal: vaultIdToAmount[vaultA],
token1Bal: vaultIdToAmount[vaultB],
})
j++
if (i > 5000) {
await transformDexBalances({ api, data })
data = []
i = 0
}
i++
}
await transformDexBalances({ api, data })
return api.getBalances()
}

async function ammV2V3() {
return sumTokens2({ tokenAccounts: [
// v2
'8tA74jqYPNmr8pcvZE3FBxmLMDqFMvZryny8XojCD5CE',
'7t51g6PFAfnBtWqooQhHErneVqQb4SN1QuPnG7iGa87M',
'5fHS778vozoDDYzzJz2xYG39whTzGGW6bF71GVxRyMXi',
'CzVe191iLM2E31DBW7isXpZBPtcufRRsaxNRc8uShcEs',
'G2zmxUhRGn12fuePJy9QsmJKem6XCRnmAEkf8G6xcRTj',
'H617sH2JNjMqPhRxsu43C8vD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FDDww9k6gq5ws',
'GoRindEPofTJ3axsonTnbyf7cFwdFdG1A3MG9ENyBZsn',
]
})
}

module.exports = {
timetravel: false,
misrepresentedTokens: true,
hallmarks: [[1667865600, "FTX collapse"]],
solana: {
tvl: sdk.util.sumChainTvls([tvlCLMM, ammStableTvl, ammV4Tvl, ammV2V3]),
staking: () => sumTokens2({ tokenAccounts: ['8tnpAECxAT9nHBqR1Ba494Ar5dQMPGhL31MmPJz1zZvY']})
staking: () => sumTokens2({ tokenAccounts: ['8tnpAECxAT9nHBqR1Ba494Ar5dQMPGhL31MmPJz1zZvY'] })
},
};
10 changes: 7 additions & 3 deletions projects/xWinFinance/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Object.keys(config).forEach(chain => {
const { portfolioURL, strategyUrl, privateKey, } = config[chain]
module.exports[chain] = {
tvl: async (api) => {
const vaults = (await getConfig('xWinFinance/vaults/' + api.chain, strategyUrl)).map(i => i.contractaddress)
let vaults = (await getConfig('xWinFinance/vaults/' + api.chain, strategyUrl)).map(i => i.contractaddress)
const privateVaults = await getConfig('xWinFinance/privateVaults', PrivateURL)

vaults.push(...privateVaults[privateKey])
Expand All @@ -34,14 +34,18 @@ Object.keys(config).forEach(chain => {
vaults.push(...portfolioVaults.map(i => i.contractaddress))
}

const bals = await api.multiCall({ abi: 'uint256:getVaultValues', calls: vaults })

const isValidVault = await api.multiCall({ abi: 'uint256:getVaultValues', calls: vaults, permitFailure: true })
vaults = vaults.filter((_, i) => isValidVault[i])

const bals = await api.multiCall({ abi: 'uint256:getVaultValues', calls: vaults, permitFailure: true })
const tokens = await api.multiCall({ abi: 'address:baseToken', calls: vaults })
const decimals = await api.multiCall({ abi: 'erc20:decimals', calls: tokens })


//Get Vault Values returns 18 decimals even if the base token is not
//For loop that removes the extra zeros if the base token is not 18 decimals.
bals.forEach((bal, i) => bals[i] = bal / 10 ** (18 - decimals[i]))
bals.forEach((bal, i) => bals[i] = (bal ?? 0) / 10 ** (18 - decimals[i]))

api.addTokens(tokens, bals)
}
Expand Down

0 comments on commit 2201de9

Please sign in to comment.