ChorusOne / solido

Lido for Solana is a Lido-DAO governed liquid staking protocol for the Solana blockchain.
https://chorusone.github.io/solido/
GNU General Public License v3.0
101 stars 43 forks source link

open api for rates #554

Closed Olitelkes closed 2 years ago

Olitelkes commented 2 years ago

Hey lido team,

I would like to retrieve the price of STSOL/SOL with a simple api call :), at least The amount of stSOL in existence and The amount of SOL managed.77Thank you

ruuda commented 2 years ago

To get the amount of SOL managed, there is https://solana.lido.fi/api/stats, but this is an internal endpoint that is intended for the staking widget only, we don’t make any stability guarantees about the response and we might rate-limit or block it if we see it being abused. To get the amount of stSOL in existence, you can use https://solana.lido.fi/api/stsol?q=totalcoins. This endpoint is stable. Note that the exchange rate is not the current ratio of stSOL supply / SOL managed, it is fixed per epoch, see also https://docs.solana.lido.fi/internals/exchange-rate.

Of course, using that data is at your own risk. You shouldn’t trust data returned by some random endpoint from some random server, it might lie to you. The best way to get the stSOL price is to run your own Solana RPC node (or commission one from somebody you trust), read the Solido instance account, and extract the exchange rate from there. (The true exchange rate used by the program is stored on-chain in the instance.)

We are working on a Typescript library that facilitates this, you can find the code for that here, but it’s a work in progress: https://github.com/ChorusOne/solido/tree/main/js. If you want to do it manually, there are some snippets here: https://docs.solana.lido.fi/development/frontend-integration.

Olitelkes commented 2 years ago

Thank you very much for your very detailed answer, appreciate a lot.

Have a good day.