Close

How to close a margin tarde.

Close a position by swapping the collateral back to loan tokens, paying back the loan to the lender and withdrawing the remainder either in the loan or the collateral currency.

function closeWithSwap(bytes32 loanId, address receiver, uint256 swapAmount, bool returnTokenIsCollateral, bytes ) public nonpayable nonReentrant globallyNonReentrant iTokenSupplyUnchanged whenNotPaused 
returns(loanCloseAmount uint256, withdrawAmount uint256, withdrawToken address)

Arguments

Name
Type
Description

loanId

bytes32

The id of the loan.

receiver

address

The receiver of the remainder (unused collateral + profit).

swapAmount

uint256

Defines how much of the position should be closed and is denominated in collateral tokens. If swapAmount >= collateral, the complete position will be closed.

returnTokenIsCollateral

bool

Defines if the remainder should be paid out in the loan or the collateral currency.

bytes

loanId The id of the loan.

Returns

The amount of the loan which was closed, the amount of tokens sent to the receiver, the address of the tokens sent to the receiver (loan or collateral)

Last updated