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

BETS/wstETH pool not returning bptPrice #548

Closed
brunoguerios opened this issue Nov 27, 2023 · 17 comments · Fixed by #549
Closed

BETS/wstETH pool not returning bptPrice #548

brunoguerios opened this issue Nov 27, 2023 · 17 comments · Fixed by #549
Assignees
Labels
bug Something isn't working

Comments

@brunoguerios
Copy link
Member

BETS/wstETH pool on mainnet is apparently not returning a bptPrice. Was working before apparently.

Fwd: Hi team, I wasn't able to get an answer from Discord, perhaps you could help,
We're facing the issue Error fetching token prices from coingecko with status 400 when fetching the SDK method balancer.pools.bptPrice(pool), is there a way to fix?

@brunoguerios brunoguerios added the bug Something isn't working label Nov 27, 2023
@lgahdl
Copy link
Contributor

lgahdl commented Nov 28, 2023

The bptPrice function is fetching 88 tokens at the same time, the max allowed by coingecko is 10

@RomualdH
Copy link

The bptPrice function is fetching 88 tokens at the same time, the max allowed by coingecko is 10

Is there a way to fetch only one?

@lgahdl
Copy link
Contributor

lgahdl commented Nov 28, 2023

Yeah, but to find this bpt price, our flow is fetching prices for 88 tokens, so I separated our coingecko requests into chunks of 10, because now they have paid plan and free plan, and the free plan can fetch only 10 tokens per request :/
Info: https://www.coingecko.com/en/api/pricing

{
	"timestamp": "2023-11-28T20:54:17.207+00:00",
	"error_code": 10012,
	"status": {
		"error_message": "Number of contract addresses in the request exceeds the allowed limit (10 addresses). Please note that to ensure fair usage and prevent abuse, the allowed limit may be adjusted periodically. To enjoy higher allowed limit, please subscribe to Demo plan or a paid plan at https://www.coingecko.com/en/api/pricing"
	}
}

@RomualdH
Copy link

so I separated our coingecko requests into chunks of 10

Thanks for your answer @lgahdl!
Is it published so that we could update the package?

@brunoguerios
Copy link
Member Author

@RomualdH - it's published on the new beta package here

@brunoguerios
Copy link
Member Author

@RomualdH - in case you're using the SDK instead of the SOR directly, you can find the change here

@RomualdH
Copy link

@RomualdH - in case you're using the SDK instead of the SOR directly, you can find the change here

Hi @brunoguerios, seems now the error is Error fetching token prices from coingecko with status 429
My snippet is:

price = await balancer.pools.bptPrice(
  await balancer.pools.find('0x26cc136e9b8fd65466f193a8e5710661ed9a98270002000000000000000005ad')
)

@brunoguerios
Copy link
Member Author

Thanks for reporting @RomualdH - I created a new issue so we can keep track of it. We'll get to it as soon as possible.

@lgahdl
Copy link
Contributor

lgahdl commented Dec 19, 2023

Hi @RomualdH, the coingecko API reduced their rate limit to 5 instead of 30 requests per minute today, I added a new config to add coingecko API Key, if you have a paid plan you will be able to initialize the SDK with your coingecko API Key:

const balancerSDK = new BalancerSDK({
  network: 1,
  rpcUrl: 'https://rpc.ankr.com/eth',
  coingecko: {
    coingeckoApiKey: 'YOUR_API_KEY',
    tokensPerPriceRequest: 30
  },
})

PR: #557

@RomualdH
Copy link

if you have a paid plan

Hi @lgahdl, is there a way to calculate the bpt price based on its underlaying tokens?

@brunoguerios
Copy link
Member Author

Hi @lgahdl, is there a way to calculate the bpt price based on its underlaying tokens?

@RomualdH - if you look at the implementation within the SDK you'll see that it uses the underlying token prices to calculate the bptPrice. Is that what you mean?

@RomualdH
Copy link

Hi @lgahdl, is there a way to calculate the bpt price based on its underlaying tokens?

@RomualdH - if you look at the implementation within the SDK you'll see that it uses the underlying token prices to calculate the bptPrice. Is that what you mean?

Yes, but why do we need the price feed from CG if we have the weight of each token in the pool? That wouldn't be enough to calculate the price?

@brunoguerios
Copy link
Member Author

Yes, but why do we need the price feed from CG if we have the weight of each token in the pool? That wouldn't be enough to calculate the price?

No, it's not enough. Price in the end means USD value. You need each token USD value + weight to calculate the bptPrice.

@RomualdH
Copy link

No, it's not enough. Price in the end means USD value. You need each token USD value + weight to calculate the bptPrice.

Can't I calculate wstETH price from it's wstETH/USDC pool, and then BETS price from wstETH/BETS pool based on the number of tokens weight (8020)?
Or maybe do a swap simulation from the BPT to USDC to know the price?

@brunoguerios
Copy link
Member Author

Can't I calculate wstETH price from it's wstETH/USDC pool, and then BETS price from wstETH/BETS pool based on the number of tokens weight (8020)? Or maybe do a swap simulation from the BPT to USDC to know the price?

You sure can 👍
The USD value approach is the one that we use and is suited for a more generalized solution.
If you're interested in a single specific BPT price, you can use any of those options you mentioned.
Please keep in mind that they are estimates based on the pools you're querying. If these pools happen to be out of balance compared to the current market price, the estimates will be off.
Although I believe estimates should be quite good as long as the pools you're querying have deep liquidity.

@RomualdH
Copy link

Do you have a snippet to help me calculate it please?

@RomualdH
Copy link

I managed to do it with APIs and this formula (BETS.balance * BETSPrice + wstETH.balance * wstETHPrice) / pool.totalShares.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants