The lease owner can set Stop Loss, SL, or/and TakeProfit, TP, triggers after the lease has been fully opened. They may be set up and removed individually, or together until the lease is fully paid, fully closed, or fully liquidated.
The trigger of SL and TP is defined as LTV percent such as Liquidation% > SL% > current LTV% >= TP%. Note that the Liquidation% is set on the Lease Open time and remains intact over the Lease Lifetime.
Correspondingly, a Full Close of the position occurs if
SL is set and current LTV% >= SL%, or
TP is set and TP% > current LTV%.
If the Liquidation% and SL% are surpassed simultaneously, and since the higher amount of liquidation and the stop-loss should be closed, the protocol should take the SL event with precedence and act accordingly.
The full position close implies that a trigger is consumed and no longer valid once fired.
It's worth noting that since TP and SL are meant to be triggered on price changes, not liquidations or payments, the TP% is reset if a partial liquidation or a payment takes the position LTV below the TP%.
Both would be communicated with the customers, the former on setting TP, and the latter on payment.
Design
Define struct ClosePolicy and keep an instance in lease::position::spec::Spec next to liability.
Introduce enum Close<Asset> with two variants Full and Partial, similar to lease::position::Liquidation<Asset>, and fn Position::trigger(&Due, Price<Asset>) -> Option<Close<Asset>> .
Two options to continue, either
(a) Rename appropriately, and amend fn Lease::check_debt to accommodate the trigger result handling, optionally starting a position close. Add a new variant DebtStatus::FireClose(Close<asset>) (how are the alarms scheduled?) , or
(b) add a sibling method to fn Lease::check_debt that checks for a position close. Merge the liability and trigger zones to proceed with setting up alarms.
Tasks
[ ] implement the core logic and unit tests as per the design described above
[ ] add a Lease execute message to setup triggers
[ ] consider "smart" or no migration of the existing leases to add the new properties or ClosePolicy to the Position Spec, e.g. "#serde[default]"
[ ] add events that leave enough trace in the chain for audibility
@kostovster selected Medium size though my confidence is not higher than 50%, so would say it would take somewhat in between Medium and Large Tasks, i.e. 3-4w
The lease owner can set Stop Loss, SL, or/and TakeProfit, TP, triggers after the lease has been fully opened. They may be set up and removed individually, or together until the lease is fully paid, fully closed, or fully liquidated.
The trigger of SL and TP is defined as LTV percent such as
Liquidation% > SL% > current LTV% >= TP%
. Note that theLiquidation%
is set on the Lease Open time and remains intact over the Lease Lifetime.Correspondingly, a Full Close of the position occurs if
current LTV% >= SL%
, orTP% > current LTV%
.If the Liquidation% and SL% are surpassed simultaneously, and since the higher amount of liquidation and the stop-loss should be closed, the protocol should take the SL event with precedence and act accordingly.
The full position close implies that a trigger is consumed and no longer valid once fired.
It's worth noting that since TP and SL are meant to be triggered on price changes, not liquidations or payments, the TP% is reset if a partial liquidation or a payment takes the position LTV below the TP%. Both would be communicated with the customers, the former on setting TP, and the latter on payment.
Design Define
struct ClosePolicy
and keep an instance inlease::position::spec::Spec
next toliability
. Introduceenum Close<Asset>
with two variantsFull
andPartial
, similar tolease::position::Liquidation<Asset>
, andfn Position::trigger(&Due, Price<Asset>) -> Option<Close<Asset>>
. Two options to continue, either (a) Rename appropriately, and amendfn Lease::check_debt
to accommodate the trigger result handling, optionally starting a position close. Add a new variantDebtStatus::FireClose(Close<asset>)
(how are the alarms scheduled?) , or (b) add a sibling method tofn Lease::check_debt
that checks for a position close. Merge the liability and trigger zones to proceed with setting up alarms.Tasks