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

WIP: Calculate fees for multiple redemptions at once #28

Closed
wants to merge 1 commit into from

Conversation

0xmichalis
Copy link
Member

@0xmichalis 0xmichalis commented Dec 20, 2023

WIP as I need to think a bit more about this and add tests

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.

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.
@0xmichalis 0xmichalis marked this pull request as draft December 20, 2023 12:42
// 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;
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Member

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:

  1. 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
    
  2. 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.

  3. 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).

@0xmichalis
Copy link
Member Author

I think this change is largely obsolete now that we have https://github.com/neutral-protocol/dynamic-fee-pools/pull/29

@0xmichalis 0xmichalis closed this Dec 21, 2023
@0xmichalis 0xmichalis deleted the redeem-many branch December 21, 2023 15:44
@0xmichalis
Copy link
Member Author

0xmichalis commented Jan 15, 2024

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

@kosecki123
Copy link
Contributor

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 ?

No, there is no way to do multi-tc02 redemption in code right now.

@aspiers
Copy link
Member

aspiers commented Jan 16, 2024

So shouldn't this be reopened?

Also I don't follow this point:

I think this change is largely obsolete now that we have #29

Please can you elaborate why that would have been obsolete, at least without considering redeemMany() support?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants