BlockPo / BlockPo-to-Tradelayer

Incubation Repo for the TradeLayer protocol, 0.2.0
http://www.tradelayer.org
Other
8 stars 8 forks source link

Adapt Swap to Register #495

Open patrickdugan opened 1 year ago

patrickdugan commented 1 year ago

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:

1) clean up the interest calculation to apply to all normal derivatives positions

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

patrickdugan commented 1 year ago

Pending testing

https://github.com/BlockPo/BlockPo-to-Tradelayer/pull/498/

patrickdugan commented 1 year ago

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.