glitchful-dev / sol-stake-pool-apy

2 stars 7 forks source link

support-all-SPL-stakepools-automatically #3

Closed Cerbah closed 3 months ago

Cerbah commented 1 year ago

Hello,

I think this SDK could be vastly improved if it was able to fetch the list of all "SPL stakepools" on-chain and calculate their APY too. Would it be be possible to look into how we could do it?

Cerbah commented 1 year ago

comment by jonny: "yes 100% it should be the same. Just means moving to permissionless instead of an allowlist of pools spl-stake-pool list-all < get list of all pool ids then you just run the calc once per pool"

solanaguide commented 1 year ago

I took another look at this today. In short:

  1. The @solana/spl-stake-pool library does not expose all methods provided by the stake pool program. Specifically it does not include a method to list all stake pools as it was built for a UI for a single stake pool.

It'd be best to contribute the method back to the main library, but a quick fix to get around it would be to run the command line tool spl-stake-pool list-all --output json

This returns the status of all stake pools known to the program.

Once you have the JSON you can loop through and get the pool.address for each pool

  1. You currently simulate a deposit into each pool. This seems unnecessary, as using the above JSON you can retrieve pool.poolTokenSupply and pool.totalLamports. By dividing totalLamports by poolTokenSupply you should have this epoch's figure for the poolSol:SOL exchange rate

Given all this information is provided in the list-all json response, you may not need to call SPLStakePoolTracker at all?

  1. Since the info provided by list-all does not include pool names, it would be simpler to save the data to POOL_KEY.csv instead of name.csv. This would also save hardcoding values when integrating the sdk
janlegner commented 1 year ago

I took another look at this today. In short:

1. The @solana/spl-stake-pool library does not expose all methods provided by the stake pool program. Specifically it does not include a method to list all stake pools as it was built for a UI for a single stake pool.

It'd be best to contribute the method back to the main library, but a quick fix to get around it would be to run the command line tool spl-stake-pool list-all --output json

This returns the status of all stake pools known to the program.

Once you have the JSON you can loop through and get the pool.address for each pool

2. You currently simulate a deposit into each pool. This seems unnecessary, as using the above JSON you can retrieve `pool.poolTokenSupply` and `pool.totalLamports`. By dividing totalLamports by poolTokenSupply you should have this epoch's figure for the poolSol:SOL exchange rate

Given all this information is provided in the list-all json response, you may not need to call SPLStakePoolTracker at all?

3. Since the info provided by list-all does not include pool names, it would be simpler to save the data to POOL_KEY.csv instead of name.csv. This would also save hardcoding values when integrating the sdk

I still haven gotten to upgrading this. However, the txs are no longer simulated, which allows this to be implemented.