Nolus Docs
ProtocolBorrowing

Repaying and closing

Manual repayment, market close (full), and partial close flows.

The protocol applies any repayment amount in a strict order:

  1. Overdue protocol interest
  2. Overdue loan interest
  3. Current-period protocol interest
  4. Current-period loan interest
  5. 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

  1. Initiation. The borrower calls Repay on the position contract. The payment must currently be in LPN.
  2. 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) and loan payment (amount destined for the LPP).
  3. 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.
  4. Protocol interest settlement. If change covers the protocol interest, it's paid in full. Otherwise a portion is paid and the rest stays due.
  5. Loan interest settlement. If change remains after protocol interest, the position queries the LPP for the loan interest owed and pays as much as possible.
  6. Update working variables. If loan interest is fully covered, the interest due period is renewed. loan payment is updated.
  7. Principal repayment. Any remaining change is applied to the outstanding principal.
  8. 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.

  1. Initiation. The user or the protocol triggers the full closure.
  2. Asset conversion. All position assets are swapped to LPN on the host DEX and bridged back via IBC, with acknowledgments at each step.
  3. Debt assessment. The contract computes protocol interest due, loan interest due, and principal due.
  4. 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.
  5. Loan finalization. If internal funds cover all debts, the position is Paid; the loan entry is deleted from the LPP. No follow-up Repay call is needed.
  6. Automatic asset distribution. The remaining LPN is returned to the borrower automatically - no manual claim required.
  7. Status update. Position transitions directly from Opened to Closed.

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.

  1. Initiation. The user triggers a partial close, specifying the portion of the position to apply to repayment. No external funds involved.
  2. Internal asset conversion. The specified portion is swapped to LPN on the host DEX (if not already LPN) and bridged back via IBC.
  3. Debt assessment. The contract computes protocol interest due, loan interest due, and principal due.
  4. Repayment execution. The converted LPN is applied in order: protocol interest, loan interest, principal. If the full debt is covered, the position transitions from Opened to Paid. Otherwise it stays Opened with reduced liability.
  5. 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.
  6. Manual claim. Since the position isn't auto-closed, the borrower calls Claim to retrieve any excess LPN and the remaining unutilized assets. Until claimed, those funds stay locked and the position remains Paid. Once claimed, status moves to Closed.

On this page