Skip to content

Commit

Permalink
Fix: AllStake (#12641)
Browse files Browse the repository at this point in the history
Co-authored-by: g1nt0ki <[email protected]>
  • Loading branch information
0xpeluche and g1nt0ki authored Dec 10, 2024
1 parent 0f4e690 commit 6a6a3dc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 111 deletions.
82 changes: 0 additions & 82 deletions projects/allstake/idls/strategy_manager.json

This file was deleted.

43 changes: 14 additions & 29 deletions projects/allstake/index.js
Original file line number Diff line number Diff line change
@@ -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] });
}
Expand All @@ -26,38 +24,25 @@ 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 = {
near: {
tvl: nearTvl,
},
solana: {
tvl: solanaTvl,
tvl: solanaTvl
},
ethereum: {
tvl: ethereumTvl,
Expand Down

0 comments on commit 6a6a3dc

Please sign in to comment.