-
Notifications
You must be signed in to change notification settings - Fork 3
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
Support calculating the amount of TCO2 redeemed based on POOL #38
Comments
@0xmichalis One thing to note is that we can't calculate exact amount of POOL that's requested by user, the reason is the method we implement this is by iteratively searching for TCO2 that would yield the closest POOL amount. 9.99934 POOL - 9.123 TCO2 |
On top of above, we may need to have this estimation function outside the
where |
Why isn't it possible to calculate this exactly rather than via iteration? |
Regarding this:
I just wanted to check my understanding here and try to explicitly document what we are talking about for clarity. I think the key points about our current redemption code are as follows:
So with this approach we first need to know the amount of TCO2 received by redemption, then we can calculate the fee, and that gives us the amount of pool the user will spend:
So the challenge would be to rearrange this equation to solve for Similarly, with depositing, currently we first need to know the amount of TCO2 the user wants to deposit, and then we can calculate how much POOL they receive via:
With depositing I guess it's less important to allow the user to choose how much POOL they'll receive and calculate the amount of TCO2 needed for that, but if we wanted to do that, we'd have to solve this equation for |
I think I answered my own question in https://www.notion.so/Redemption-with-CHAR-spend-as-input-c88f4c4c6c7a4b1b814d8ce20681bf31 |
If they are done in two separate calls then it loses the value doing the estimation on-chain, which is to estimate and redeem atomically in order to avoid race conditions with other deposits/redeems. This way we can guarantee the exact result requested. If instead we accept the race conditions and defend with limit parameters like Both options seem viable to me, but we need to choose between them. Would love to hear what you guys think about this! Cc @0xmichalis |
@aspiers please share above, unable to access. |
I gave you access @kosecki123 |
I think regardless we need to have the slippage protection. Basically you need to assume there is MEV in play. To me the best that covers all is to estimate off-chain and execute on-chain, similarly to AMMs. The diff here is that we cannot have 'exact' amounts as we approximate in case of POOL input. |
This issue tracks the missing functionality of calculating the amount of TCO2 received via redemption when providing POOL amount. Which is opposite to what's available rn.
This should be implemented as an additional option, not to replace existing feature.
#35 (comment)
The text was updated successfully, but these errors were encountered: