Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: AllStake #12641

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading