-
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
WIP: Calculate fees for multiple redemptions at once #28
Conversation
This is going to be useful for both `redeemMany` and eventually `redeemAuto` in the pool contract as these functions already support redemption of multiple TCO2s within a single transaction. We can even get rid of `calculateRedemptionFees` altogether since I don't forsee it being used in the Toucan pools but this can be done in a follow-up if needed.
// Update total pool supply to account for the tokens to be burnt | ||
// so the next iteration charges fees using the intermediate | ||
// pool supply. | ||
totalPoolSupply = totalPoolSupply - redemptionAmount + feeAmount; |
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.
The amount by which the totalPoolSupply will change should be
totalPoolSupply-=redemptionAmount
feeAmount is not being burnt.
The way in works from the user perspective is as follows:
- user want to redeem the 10 tco2 from the pool
- fee calculated would be let's say 0.1
- user will pay 10.1 pool tokens and receive the 10 tco2
This different from the deposits where:
- user has 10 tco2
- fee calculated for deposit is 0.1
- user receives 9.9 pool tokens
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.
Also in case someone passes
2 items which both are same tco2
you would need to track the tco2Balance as well
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.
The way in works from the user perspective is as follows:
- user want to redeem the 10 tco2 from the pool
- fee calculated would be let's say 0.1
- user will pay 10.1 pool tokens and receive the 10 tco2
@kosecki123 @0xmichalis I could be misunderstanding, but this sounds problematic to me, for the following reasons:
-
If the user wants to redeem all their pool tokens, it requires them to work backwards from their balance to figure out the correct redemption amount. In your example above, if they have exactly 10 pool tokens, they would need to find a value around 9.9 tokens to redeem which totals exactly 10 pool tokens when the fee is added on top. However, because the fee is on a non-linear curve, I suspect this turns into a really complicated mathematical equation to solve, even if there's UI code to do it for the user:
desiredTCO2Amount + redemptionFee(desiredTCO2Amount, ...) == userPoolBalance
-
If the pool diversity changes slightly to increase the fee in between receiving the quote and submitting the transaction, it could easily increase the fee enough that the amount of pool tokens would exceed their balance of 10, and the transaction would fail.
-
If instead the fee decreases in that window between quote and execution, then the user gets left with annoying amount of pool token dust which they probably can't make use of because it's not worth the gas fees to get rid of it.
In contrast, if we take the approach that the fee is deducted from the amount of pool tokens the user requests to redeem, then all of these problems go away: the user will always spend exactly 10 pool tokens, and the only thing which can change is how much TCO2 they get back (which BTW will also have a lower bound due to the max fee cap which we are adding).
I think this change is largely obsolete now that we have https://github.com/neutral-protocol/dynamic-fee-pools/pull/29 |
I think we need to revive this as currently there is no way to accurately calculate fees for a multi-TCO2 redemption, is there @kosecki123 @PawelTroka @aspiers ? Let's move this discussion in https://github.com/neutral-protocol/dynamic-fee-pools/issues/35 |
No, there is no way to do multi-tc02 redemption in code right now. |
So shouldn't this be reopened? Also I don't follow this point:
Please can you elaborate why that would have been obsolete, at least without considering |
WIP as I need to think a bit more about this and add tests
This is going to be useful for both
redeemMany
and eventuallyredeemAuto
in the pool contract as these functions already support redemption of multiple TCO2s within a single transaction.