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

Feat: Jito Restaking TVL #2

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

aoikurokawa
Copy link
Collaborator

@aoikurokawa aoikurokawa commented Jan 11, 2025

Name (to be shown on DefiLlama):

Jito

Twitter Link:

https://twitter.com/jito_sol

List of audit links if any:

Solana Stake Pool audits: https://spl.solana.com/stake-pool#security-audits
Jito-Solana client audit (Neodyme): https://2926710696-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ffrb9MGTK6eZJlEQJyylq%2Fuploads%2F1jfEDpGcd5YlnHusbKYO%2FNeodymeJito.pdf
Restaking audits: https://github.com/jito-foundation/restaking/blob/master/security_audits

Website Link:

https://jito.network

Logo (High resolution, preferably in .svg and .png, for application on both white and black backgrounds. Will be shown with rounded borders):

https://storage.googleapis.com/token-metadata/JitoSOL-256.png
image

Current TVL:

in SOL: 307451
in USD: $4,076,800

Chain:

Solana

Coinmarketcap ID (so your TVL can appear on Coinmarketcap): (https://api.coinmarketcap.com/data-api/v3/map/all?listing_status=active,inactive,untracked&start=1&limit=10000)
Short Description (to be shown on DefiLlama):

MEV-Boosted Staking Rewards

Category (full list at https://defillama.com/categories) *Please choose only one:

Liquid Staking, Restaking

Oracle used (Chainlink/Band/API3/TWAP or any other that you are using):
forkedFrom (Does your project originate from another project):

SPL Stake Pool

methodology (what is being counted as tvl, how is tvl being calculated):
What is counted as TVL?

TVL includes the total balance of supported tokens (e.g., jitoSOL) deposited into all Restaking vaults managed by Jito Vault Program.

How is TVL calculated?
  1. Fetch Vault Accounts: Retrieve all vault accounts on-chain using the program ID and a discriminator filter.
  2. Decode Vault Data: Use the Anchor IDL to decode the vault account data for structured information.
  3. Derive Token Accounts: Compute the associated token accounts holding the staked tokens for each vault.
  4. Aggregate Balances: Sum the balances of all token accounts to calculate the total value locked.

u8("isPaused"),
u64("lastStartStateUpdateSlot"),
seq(u8(), 251, "reserved"),
]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to add the vault IDL and fetch the accounts using that rather than defining it custom here? also, did you write this manually or get it from the js client somehow?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the way parsing vault.
Current jito_vault idl use pod type. So I made this PR to fix the type from pod type to primitive type like u64.

});

return sumTokens2({ tokenAccounts: stAssociatedTokenAddresses, allowError: true })
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the return type of this function? is it something like a mapping of {token_mint: amount} ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it returns the sum of balance of tokens. so should be number.

return associatedTokenAddress;
}

async function tvl() {
Copy link
Collaborator

@ebatsell ebatsell Jan 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does defillama say how you can test this? I'm wondering if the special vault tokens like FragSOL are going to show up - perhaps we need to connect an oracle for this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The below command does not work properly:

node test.js projects/jito/restaking.js 

So i just commented out inside projects/jito/index.js, then paste new code like this:

// const { PublicKey } = require("@solana/web3.js");
// const { getConnection } = require("../helper/solana");

// async function tvl() {
//   // https://jito.network/staking
//   const connection = getConnection();
//   const account = await connection.getAccountInfo(new PublicKey('Jito4APyf642JPZPx3hGc6WWJ8zPKtRbRs4P815Awbb'))
//   return {
//     solana: Number(account.data.readBigUint64LE(258))/1e9
//   }
// }

// module.exports = {
//   timetravel: false,
//   methodology:
//     "Uses the SPL Stake Pool SDK to fetch the total supply of deposited SOL into the Jito Stake Pool",
//   solana: {
//     tvl,
//   },
// };

const { PublicKey } = require("@solana/web3.js");
const { sumTokens2, getAssociatedTokenAddress, getProvider, getConnection } = require("../helper/solana");
const { bs58 } = require('@project-serum/anchor/dist/cjs/utils/bytes');
const anchor = require("@project-serum/anchor");
const jitoVaultIdl = require("./jito_vault.json");

const VAULT_PROGRAM_ID = new PublicKey("Vau1t6sLNxnzB7ZDsef8TLbPLfyZMYXH8WTNqUdm9g8");
const VAULT_DISCRIMINATOR = Buffer.from([2]);

function getVaultPubkey(vault) {
    const [associatedTokenAddress] = PublicKey.findProgramAddressSync([Buffer.from("vault"), vault.base.toBuffer()], VAULT_PROGRAM_ID);
    return associatedTokenAddress;
}

async function tvl() {
    const provider = getProvider();
    const connection = getConnection();
    const program = new anchor.Program(jitoVaultIdl, VAULT_PROGRAM_ID, provider);

    const accounts = await connection.getProgramAccounts(
        VAULT_PROGRAM_ID,
        {
            filters: [
            {
                memcmp: {
                offset: 0,
                bytes: bs58.encode(VAULT_DISCRIMINATOR),
                },
            },
            ]
        }
    );

    const vaults = accounts.map((account) => {
        return program.account.vault.coder.accounts.decodeUnchecked("Vault", account.account.data);
    });

    const stAssociatedTokenAddresses = vaults.map((vault) => {
        const vaultPubkey = getVaultPubkey(vault);
        return getAssociatedTokenAddress(vault.supportedMint, vaultPubkey);
    });

    return sumTokens2({ tokenAccounts: stAssociatedTokenAddresses, allowError: true })
}

module.exports = {
  timetravel: false,
  solana: {
    tvl,
  },
};

then run:

node test.js projects/jito/index.js

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To run a test, public api does not support getProgramAccounts method, so you need to write your api in .env file:

...
SOLANA_RPC=?
...

@ebatsell
Copy link
Collaborator

The link to Restaking audits should https://github.com/jito-foundation/restaking/blob/master/security_audits

Also Methodology section should be updating mentioning how we are also fetching the Restaking vaults to parse the amount of deposit tokens

@aoikurokawa aoikurokawa requested a review from ebatsell January 13, 2025 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants