Action

Action.sol is a module contract that handles various user actions within the Unlockd Protocol, such as borrowing, repaying, and unlocking assets.

Key functions:

function getLoan(
    bytes32 loanId
) external view returns (DataTypes.Loan memory)

Returns the details of a loan given its ID.

Parameters:

loanId: The ID of the loan to retrieve.


function getAmountToRepay(
    bytes32 loanId
) external view returns (uint256 amount)

Returns the amount required to repay a loan.

Parameters:

loanId: The ID of the loan to calculate the repayment amount for.


function borrow(
    uint256 amount,
    DataTypes.Asset[] calldata assets,
    DataTypes.SignAction calldata signAction,
    DataTypes.EIP712Signature calldata sig
) external

Allows users to borrow assets using the specified loan and collateral. It validates the signature, updates the loan state, and performs the necessary actions to borrow the assets.

Parameters:

amount: The amount to borrow.

assets: An array of assets to be used as collateral.

signAction: The signed action data.

sig: The EIP-712 signature for the borrow operation.


function repay(
    uint256 amount,
    DataTypes.SignAction calldata signAction,
    DataTypes.EIP712Signature calldata sig
) external

Allows users to repay a loan and unlock assets if the health factor is above 1. It validates the signature, updates the loan state, transfers the repayment amount, and unlocks the assets if the health factor is above 1 or the total amount repaid.

Parameters:

amount: The amount to repay.

signAction: The signed action data.

sig: The EIP-712 signature for the repay operation.

Signature

signAction (type: DataTypes.SignAction), it contains the following fields:

loan (type: DataTypes.SignLoanConfig): The loan configuration data, including the loan ID, aggregated loan price, LTV, liquidation threshold, total assets, nonce, and deadline.

assets (type: bytes32[]): An array of assetIDs involved in the action.

underlyingAsset (type: address): The address of the underlying asset for the loan.

nonce (type: uint256): The nonce value is used to ensure the uniqueness of the signature and prevent replay attacks.

deadline (type: uint256): The deadline timestamp until which the signature is considered valid.

sig (type: DataTypes.EIP712Signature), it contains the following fields:

v (type: uint8): The recovery ID of the signature.

r (type: bytes32): The first 32 bytes of the signature.

s (type: bytes32): The second 32 bytes of the signature.

deadline (type: uint256): The deadline timestamp until which the signature is considered valid.

Last updated