Repaying and closing
Manual repayment, market close (full), and partial close flows.
The protocol applies any repayment amount in a strict order:
- Overdue protocol interest
- Overdue loan interest
- Current-period protocol interest
- Current-period loan interest
- Principal repayment to the LPP
A partial repayment or partial close that uses position-internal funds
settles outstanding liabilities; the borrower must call Claim afterward
to withdraw leftover margin. A full close - via full repayment or full
liquidation - settles automatically and returns the remaining funds
without a manual claim.
Manual repayment
- Initiation. The borrower calls
Repayon the position contract. The payment must currently be in LPN. - Query outstanding debt. The contract fetches principal due and total
loan interest due from the LPP, and initializes two working variables:
change(remaining repayment after each step) andloan payment(amount destined for the LPP). - Interest due period enforcement. Each borrower has a window in which outstanding interest must be paid. Paying both protocol and loan interest in full extends the next due date by the full period; a partial payment extends it proportionally (e.g., a 30-day period extends by 15 days if half the interest is paid). Missing the deadline triggers a partial liquidation to cover the unpaid amount.
- Protocol interest settlement. If
changecovers the protocol interest, it's paid in full. Otherwise a portion is paid and the rest stays due. - Loan interest settlement. If
changeremains after protocol interest, the position queries the LPP for the loan interest owed and pays as much as possible. - Update working variables. If loan interest is fully covered, the
interest due period is renewed.
loan paymentis updated. - Principal repayment. Any remaining
changeis applied to the outstanding principal. - Refund and cleanup. Any surplus is returned to the user, the loan
record is deleted from the LPP, and the borrower can withdraw the
remaining margin from the position contract via
Claim.
Market close (full)
In a market close, the position is fully settled using only the funds already held in the contract - no external capital from the borrower.
- Initiation. The user or the protocol triggers the full closure.
- Asset conversion. All position assets are swapped to LPN on the host DEX and bridged back via IBC, with acknowledgments at each step.
- Debt assessment. The contract computes protocol interest due, loan interest due, and principal due.
- Repayment from internal funds. Debt is settled in the standard order (overdue protocol interest, overdue loan interest, current protocol interest, current loan interest, principal) - same as manual repayment, but sourced entirely from the position's internal balance.
- Loan finalization. If internal funds cover all debts, the position
is
Paid; the loan entry is deleted from the LPP. No follow-upRepaycall is needed. - Automatic asset distribution. The remaining LPN is returned to the borrower automatically - no manual claim required.
- Status update. Position transitions directly from
OpenedtoClosed.
Partial close
In a partial close, the borrower uses a portion of the position's internal funds to settle part or all of the debt. Unlike a full close, this does not automatically close the position.
- Initiation. The user triggers a partial close, specifying the portion of the position to apply to repayment. No external funds involved.
- Internal asset conversion. The specified portion is swapped to LPN on the host DEX (if not already LPN) and bridged back via IBC.
- Debt assessment. The contract computes protocol interest due, loan interest due, and principal due.
- Repayment execution. The converted LPN is applied in order:
protocol interest, loan interest, principal. If the full debt is
covered, the position transitions from
OpenedtoPaid. Otherwise it staysOpenedwith reduced liability. - Remaining balance. If the converted amount exceeded the debt (e.g., $120 to cover $100), the surplus stays in the position contract. The unused portion of the position (e.g., the remaining $80 in volatile or collateral assets) also stays.
- Manual claim. Since the position isn't auto-closed, the borrower
calls
Claimto retrieve any excess LPN and the remaining unutilized assets. Until claimed, those funds stay locked and the position remainsPaid. Once claimed, status moves toClosed.