-
Notifications
You must be signed in to change notification settings - Fork 83
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
fix: only award redeem premium upto the secure threshold #1201
Conversation
The solution is not 100% correct. But maybe it's good enough.. The problem is what you're doing is:
The "right" way to do this, is to calculate the maximum amount of premium to payout using math: CollateralizationRate = totalCollateral / convertToCollateral(totalTokens)
// When doing a premium redeem, this changes to:
// NewCollateralization = (oldCol - maxPremium) / ( oldTokens*EXCH - maxPremium/FEE)
// we want NewCollateralization = SECURE threshold, so
SECURE = (oldCol - maxPremium) / ( oldTokens*EXCH - maxPremium/FEE)
// rewriting gives..
maxPremium = (FEE * (oldCol - oldTokens * EXCH * SECURE)) / (FEE -SECURE)
// plugging in number from the test..
maxPremium = (0.05*(2000 - 650 * 2 * 2)) / (0.05 - 2)
= 15.3846153846 In comparison, #589 would award max 15, and this PR awards 15.375. Both are pretty close, so I'm not sure we really need the math based approach. @gregdhill what do you think? |
Changed the approach based on the new formula provided. |
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.
We have a vaultRegistry_getPremiumRedeemVaults
rpc. @gregdhill I think we should we update that to return only the amount that is premium-redeemable, right?
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.
@gregdhill @nud3l Do we want to award a premium up to the global secure threshold, or to the vault's custom threshold? Personally for my vault I would prefer to only award a premium upto the global secure threshold, otherwise setting a higher threshold seemingly increases the risk of losing money through premium payouts
Agree with using the second approach @sander2, as for your other comments we should only return the amount that is premium redeemable in the RPC and I also agree we should award premium up to the global secure threshold since that is always lower. |
08b1cdc
to
5a00bac
Compare
Co-authored-by: sander2 <sanderbosma@gmail.com>
…y/interbtc into nakul/fix_premium_redeem
bb88f6b
to
4c1eb93
Compare
went ahead with 2 approach cc: @gregdhill |
I'm ok with moving the rpc to the redeem crate. We could keep the rpc name identical s.t. it doesn't require UI changes. Fwiw there is also an option 3 to add a new getter to the vault_registry config trait, but option 2 works for me as well |
changed the RPC method name from |
I think it will require an update in the lib maybe? |
Yea it for sure affects frontend/lib. Let's keep the old naming as an alias, see https://docs.rs/jsonrpsee-proc-macros/0.20.3/jsonrpsee_proc_macros/attr.rpc.html#method-attribute |
8d28e92
to
31556f2
Compare
99cdd84
to
c275fbe
Compare
I pushed a small change. The I also made some changes to the testing code |
c275fbe
to
0f67fd9
Compare
1a3c3d6
to
339bfa7
Compare
Description Imported from Pr 589
2 significant changes:
issued_tokens
to determine whether or not a vault is below the premium redeem threshold, now use the "to_be_backed" tokens, i.e. the tokens if all open issues and redeems execute successfully (= issued + to_be_issued - to_be_redeemed). This is required because otherwise additional redeems would again be able to de a premium redeem.Since this significantly modifies audited code, I'd like to have 2 people approve this PR before we merge
Example based on test case
Premium redeem fee should be given on difference_in_tokens_to_reach_secure_threshold + potential_decrease_in_issued_tokens_after_giving_out_collatral_as_premium_fees = 150 tokens + 3.75 tokens = 153.75 tokens equivalent to 307.5 COL tokens if exchange_rate is 2max_premium_amount
a vault can pay = 153.84 tokens equivalent to 307.68 COL tokens if exchange_rate is 2max_premium_amount
:SECURE = (oldCol - maxPremium) / ( oldTokens*EXCH - maxPremium/FEE)