diff --git a/projects/allstake/idls/strategy_manager.json b/projects/allstake/idls/strategy_manager.json deleted file mode 100644 index c5434515951f..000000000000 --- a/projects/allstake/idls/strategy_manager.json +++ /dev/null @@ -1,82 +0,0 @@ -{ - "version": "0.1.0", - "name": "strategy_manager", - "instructions": [], - "accounts": [ - { - "name": "StrategyManager", - "type": { - "kind": "struct", - "fields": [ - { - "name": "data", - "type": { - "defined": "VersionedStrategyManager" - } - } - ] - } - } - ], - "types": [ - { - "name": "StrategyManagerV1", - "type": { - "kind": "struct", - "fields": [ - { - "name": "owner", - "docs": [ - "owner of strategy manager program" - ], - "type": "publicKey" - }, - { - "name": "strategyMints", - "docs": [ - "list of supported strategies' mint address" - ], - "type": { - "array": [ - "publicKey", - 32 - ] - } - }, - { - "name": "strategyMintsLen", - "docs": [ - "size of the list above" - ], - "type": "u8" - }, - { - "name": "minWithdrawDelay", - "docs": [ - "min withdraw queueing delay length in seconds" - ], - "type": "i64" - } - ] - } - }, - { - "name": "VersionedStrategyManager", - "type": { - "kind": "enum", - "variants": [ - { - "name": "V1", - "fields": [ - { - "defined": "StrategyManagerV1" - } - ] - } - ] - } - } - ], - "events": [], - "errors": [] -} \ No newline at end of file diff --git a/projects/allstake/index.js b/projects/allstake/index.js index bb58a5242c89..c8b3dbaa4452 100644 --- a/projects/allstake/index.js +++ b/projects/allstake/index.js @@ -1,17 +1,15 @@ const { getUniqueAddresses } = require('../helper/utils'); -const { call, sumTokens } = require('../helper/chain/near'); -const { sumTokens2, getProvider } = require('../helper/solana'); +const { call, sumTokens, } = require('../helper/chain/near'); +const { sumTokens2, getConnection } = require('../helper/solana'); const { sumTokens2: evmSumTokens2 } = require("../helper/unwrapLPs") -const { Program } = require('@coral-xyz/anchor'); const { PublicKey } = require('@solana/web3.js'); const ALLSTAKE_NEAR_CONTRACT = 'allstake.near'; const ALLSTAKE_SOLANA_PROGRAM = new PublicKey('a11zL6Uxue6mYG3JD3APmnVhS4RVjGTJZbENY7L6ZfD'); -const ALLSTAKE_SOLANA_PROGRAM_IDL = require('./idls/strategy_manager.json'); const ALLSTAKE_ETHEREUM_STRATEGY_MANAGER_CONTRACT = '0x344F8B88357A710937f2b3db9d1B974B9a002afB'; async function ethereumTvl(api) { - const strategies = await api.fetchList({ lengthAbi: 'strategiesLen', itemAbi: 'strategies', target: ALLSTAKE_ETHEREUM_STRATEGY_MANAGER_CONTRACT}) + const strategies = await api.fetchList({ lengthAbi: 'strategiesLen', itemAbi: 'strategies', target: ALLSTAKE_ETHEREUM_STRATEGY_MANAGER_CONTRACT }) const tokens = await api.multiCall({ abi: 'address:underlying', calls: strategies }); return evmSumTokens2({ api, tokensAndOwners2: [tokens, strategies] }); } @@ -26,30 +24,17 @@ async function nearTvl() { } async function solanaTvl() { - const provider = getProvider(); - const programId = ALLSTAKE_SOLANA_PROGRAM; - // const idl = await Program.fetchIdl(programId, provider) - const program = new Program(ALLSTAKE_SOLANA_PROGRAM_IDL, programId, provider); - const state = await program.account.strategyManager.all(); - const strategyManager = state[0].account.data.v1[0]; - const tokens = getUniqueAddresses(strategyManager.strategyMints.slice(0, strategyManager.strategyMintsLen).map(mint => mint.toBase58()), true); - - const tokensAndOwners = []; - for (const token of tokens) { - const pubKey = new PublicKey(token); - const owner = PublicKey.findProgramAddressSync( - [ - Buffer.from('STRATEGY'), - pubKey.toBuffer(), - ], - ALLSTAKE_SOLANA_PROGRAM - )[0].toBase58(); - tokensAndOwners.push([token, owner]); - } - - return sumTokens2({ - tokensAndOwners + const result = await getConnection().getProgramAccounts(ALLSTAKE_SOLANA_PROGRAM, { + encoding: "base64", + // We only care about the strategy addresses. + dataSlice: { offset: 0, length: 0 }, + filters: [ + { dataSize: 316 }, + ], }); + const owners = result.map(({ pubkey }) => pubkey); + + return sumTokens2({ owners }); } module.exports = { @@ -57,7 +42,7 @@ module.exports = { tvl: nearTvl, }, solana: { - tvl: solanaTvl, + tvl: solanaTvl }, ethereum: { tvl: ethereumTvl,