Market

Market.sol is a module contract that handles market-related functionalities in the Unlockd Protocol. It allows users to create and manage orders, place bids, claim assets, and perform buy and sell operations.

Key functions:

function getOrder(
    bytes32 orderId
) external view returns (DataTypes.Order memory)

Returns the details of an order given its ID.

Parameters:

orderId: The ID of the order to retrieve.


function getMinBidPrice(
    bytes32 orderId,
    address underlyingAsset,
    uint256 aggLoanPrice,
    uint256 aggLtv
) external view returns (uint256 minBid)

Returns the minimum bid price for an order.

Parameters:

orderId: The ID of the order.

underlyingAsset: The address of the underlying asset.

aggLoanPrice: The aggregated loan price.

aggLtv: The aggregated loan-to-value ratio.


function getBuyNowPrice(
    bytes32 orderId,
    address underlyingAsset,
    uint256 aggLoanPrice,
    uint256 aggLtv
) external view returns (uint256 amount)

Returns the buy-now price for an order.

Parameters:

orderId: The ID of the order.

underlyingAsset: The address of the underlying asset.

aggLoanPrice: The aggregated loan price.

aggLtv: The aggregated loan-to-value ratio.


function create(
    address underlyingAsset,
    Constants.OrderType orderType,
    CreateOrderInput calldata config,
    DataTypes.SignMarket calldata signMarket,
    DataTypes.EIP712Signature calldata sig
) external

Allows users to create a new order. It validates the signature, retrieves the loan details, updates the loan state, validates the order creation, and creates a new order with the specified parameters.

Parameters:

underlyingAsset: The address of the underlying asset.

orderType: The type of the order.

config: The configuration parameters for creating the order.

signMarket: The signed market data.

sig: The EIP-712 signature for the order creation.


function cancel(bytes32 orderId) external

Allows the order owner to cancel an existing order. It retrieves the order and loan details, validates the cancellation action, refunds any existing bid, and deletes the order.

Parameters:

orderId: The ID of the order to cancel.


function bid(
    bytes32 orderId,
    uint128 amountToPay,
    uint128 amountOfDebt,
    DataTypes.SignMarket calldata signMarket,
    DataTypes.EIP712Signature calldata sig
) external 

Allows users to place a bid on an order. It validates the signature, retrieves the order and loan details, validates the bid action, transfers the bid amount, creates a new loan for the bidder if a debt is requested, refunds any existing bid, and updates the order with the new bid details.

Parameters:

orderId: The ID of the order to bid on.

amountToPay: The amount to pay for the bid.

amountOfDebt: The amount of debt associated with the bid.

signMarket: The signed market data.

sig: The EIP-712 signature for the bid.


function claim(
    bool claimOnUWallet,
    bytes32 orderId,
    DataTypes.SignMarket calldata signMarket,
    DataTypes.EIP712Signature calldata sig
) external

Allows users to claim assets from a completed order. It validates the signature, retrieves the order and loan details, validates the claim action, transfers the claimed amount, updates the loan state, and transfers the claimed assets to the winning bidder.

Parameters:

claimOnUWallet: A flag indicating whether to claim the assets on the user's Unlockd wallet.

orderId: The ID of the order to claim assets from.

signMarket: The signed market data.

sig: The EIP-712 signature for the claim.


function cancelClaim(
    bytes32 orderId,
    DataTypes.SignMarket calldata signMarket,
    DataTypes.EIP712Signature calldata sig
) external

Allows users to cancel a pending claim on an order. It validates the signature, retrieves the order and loan details, validates the claim cancellation action, and refunds the pending claim amount.

Parameters:

orderId: The ID of the order associated with the claim to cancel.

signMarket: The signed market data.

sig: The EIP-712 signature for the claim cancellation.


 function buyNow(
    bool claimOnUWallet,
    bytes32 orderId,
    uint256 amountToPay,
    uint256 amountOfDebt,
    DataTypes.SignMarket calldata signMarket,
    DataTypes.EIP712Signature calldata sig
 ) external

It allows users to perform a buy-now operation on an order. It validates the signature, retrieves the order and loan details, validates the buy-now action, transfers the buy-now amount, creates a new loan for the buyer if a debt is requested, refunds any existing bid, and transfers the bought assets to the buyer.

Parameters:

claimOnUWallet: A flag indicating whether to claim the assets on the user's Unlockd wallet.

orderId: The ID of the order to buy.

amountToPay: The amount to pay for the buy now operation.

amountOfDebt: The amount of debt associated with the buy-now operation.

signMarket: The signed market data.

sig: The EIP-712 signature for the buy now operation.

Signature

signMarket (type: DataTypes.SignMarket), 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.

assetId (type: bytes32): The ID of the asset involved in the market action.

collection (type: address): The address of the asset collection.

tokenId (type: uint256): The token ID of the asset.

assetPrice (type: uint256): The price of the asset.

assetLtv (type: uint256): The loan-to-value ratio of the asset.

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