👩‍💻
Unlockd Developers Docs
Unlockd for Devs V2
Unlockd for Devs V2
  • Introduction
  • ⚙️Core
    • Unlockd
    • BaseCore
    • BaseCoreModule
  • ⚙️Modules
    • Installer
    • Manager
    • Action
    • SellNow
    • BuyNow
    • Market
    • Auction
  • 🆕Vault and Tokens
    • UTokenVault
    • BaseToken
    • ScaledToken
    • WethGateway
  • 🆕Adapters and Strategies
    • ReservoirAdapter
    • MaxApyStrategy
  • 🆕Storage
    • CoreStorage
    • UVaultStorage
  • 📔Deployed Contracts
    • Ethereum Sepolia
    • Ethereum Mainnet
  • 📫Unlockd Account (Wallet)
    • Introduction
    • Architecture
    • DelegationWalletFactory
    • DelegationWalletRegistry
    • DelegationOwner
    • GuardOwner
    • ProtocolOwner
    • TransactionGuard
    • DelegationRecipes
    • AllowedControllers
    • Deployed Contracts
      • Ethereum Sepolia (Testnet)
  • 🧰SDK
    • Typescript Package
    • SDK Docs
  • 🤝DEVELOPERS HELP
    • Best Practices
    • Security and Risk Management
    • Github
    • Bug Bounty - ACTIVE
Powered by GitBook
On this page
  • Key functions:
  • Parameters:
  • Returns:
  • Parameters:
  • Signature
  1. Modules

BuyNow

BuyNow.sol is a module contract that enables users to buy assets within the Unlockd Protocol. It provides functionality for instant asset purchases, allowing users to buy assets using a combination of their own funds and borrowed funds from the protocol.

Key functions:

function getCalculations(
    DataTypes.SignBuyNow calldata signBuyMarket
) external pure returns (uint256, uint256)

Calculates the minimum amount required and the maximum amount that can be borrowed for a buy now operation based on the buy now data.

Parameters:

signBuyMarket: The signed buy now data.

Returns:

The minimum amount required from the user.

The maximum amount that can be borrowed.


function buy(
    uint256 amount,
    DataTypes.SignBuyNow calldata signBuyMarket,
    DataTypes.EIP712Signature calldata sig
) external 

Allows users to perform a buy now operation, purchasing an asset using the specified amount and creating a loan if necessary. It validates the signature, retrieves the user's Unlockd wallet and protocol owner addresses, updates the reserve state, transfers the user's contribution to the market adapter, creates a loan if necessary, and purchases the asset using the market adapter.

Parameters:

amount: The amount to contribute towards the purchase.

signBuyMarket: The signed buy now data.

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

Signature

signBuyMarket (type: DataTypes.SignBuyNow), it contains the following fields:

asset (type: DataTypes.SignAsset): The asset data, including the asset ID, collection address, token ID, price, nonce, and deadline.

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

assetLiquidationThreshold (type: uint256): The liquidation threshold of the asset.

from (type: address): The address from which the buy now action is initiated.

to (type: address): The address to which the asset is being bought.

data (type: bytes): Additional data for the buy now action.

value (type: uint256): The value being sent with the buy now action.

marketAdapter (type: address): The address of the market adapter used for the buy now action.

marketApproval (type: address): The address for market approval.

marketPrice (type: uint256): The market price of the asset.

underlyingAsset (type: address): The address of the underlying 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.

PreviousSellNowNextMarket

Last updated 1 year ago

⚙️