Adapt Swap to Register
Opened this issue · 2 comments
Currently interest is calculated in the sp.cpp function addInterestPegged, however this function should also count the total derivative position one is holding and apply the interest that way. It's complicated to auto-sell additional swaps to re-hedge ALL into the pegged currency, so we'll skip it.
Logically, we first check for derivatives positions then we check for pegged currency. So the swaps in the reserve for the pegged currency get the interest, then the interest goes out to pegged currency holders.
We need to delineate between derivatives that are free balance and derivatives that are reserved for pegged currency.
However this is important just to have interest on the Oracle perp. So this ticket should be done in two phases:
-
clean up the interest calculation to apply to all normal derivatives positions
-
discern which ones are reserved for pegged currency and passing on the interest. This could be done by the distributive property rather than tracing a series of operations between specific addresses and specific tranches of pegged currency. Instead, just pro-rate the total interest paid to reserved derivatives with 1x collateral.
Pending testing
This PR is for part 1, I haven't yet refactored the pegged function. It's more or less correct anyway? For now it is shrouded beyond an activation for dcurrency.