-
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
estimate tco2 redemption amount given pool redemption amount #40
base: main
Are you sure you want to change the base?
estimate tco2 redemption amount given pool redemption amount #40
Conversation
Some extra info on gas usage: estimateTCO2RedemptionAmount gas usage depends on the max iterations amount Higher the amount = better estimate, still even with 10 iterations we are below 1% error 40 iterations = 1267785 If we use this as view calls from outside, we should keep 40. If we want to anyways put this into redeem transaction we should go with 10 or lower. All gas usages taken by using:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, lets's wait for @0xmichalis
Unfortunately I am not too strong on math but I'd expect this to be implemented with the use of the inverse of the current function that estimates fees so we don't have to approximate a response. Is that wishful thinking? :) cc @aspiers |
I am not sure if that is possible given we have implicit function there |
Hrm, I think you are right. Somehow I thought the inverse of the current curve would be useful but it doesn't make much sense on a second thought. |
It's not an inverse function exactly. I have taken a stab at documenting here: but I probably made mistakes. Can we use something more efficient than linear bisection, like Newton's method? |
…terations in estimation algorithm can be set up after deploying the contract
…demption amount to calculate estimated pool amount
…ith increased iterations it lowers slippage
Co-Authored-By: Michalis Kargakis <[email protected]>
62ed793
to
9cc622a
Compare
Unfortunately I do not seem to have access to this notion page :( To be totally honest I am not 100% sold on Newton's method as there is a small risk that it may not converge in all cases. Also a derivative for our |
@PawelTroka I gave you access to the page. (BTW I think you can maybe also request access to Notion pages - if so, feel free to do that in future!) That's a good point about the derivative. I would have thought that given the smoothness of the curve, it should converge easily, but you're definitely a much stronger mathematician than me so I trust your judgement! However the main question here is whether we should really be doing this estimation on-chain - please see https://github.com/neutral-protocol/dynamic-fee-pools/issues/38#issuecomment-1916932139 and https://www.notion.so/toucan-protocol/Redemption-with-CHAR-spend-as-input-c88f4c4c6c7a4b1b814d8ce20681bf31?pvs=4#e1c6949b8fa2494986a413b31c43c203 |
To be clear: if we do it on-chain atomically as part of the redemption, then the accuracy/gas trade-off is challenging and so far it's yet to be proven where there's a sweet spot in this trade-off for acceptable UX. If we do it off-chain with "slippage" protection, then accuracy and gas both cease to be issues. |
fixes #38
simulator can be found here: https://colab.research.google.com/drive/1v66a-_ez8foIbsIsg7cwRj3Et-bapU2r#scrollTo=EPhXZrXW1BDS&line=73&uniqifier=1