Paddle Finance
  • Introduction
  • V1 Liquidity Solution
    • Basket Collateral
    • Collateral Loan
      • Peer-To-Peer Lending
      • Peer-To-Crowd Lending
    • OTC Exchange
    • Parameters
  • V2 Liquidity Solution
  • Peer-To-Pool Lending
    • Market List
    • Interest Bearing Token (iToken)
  • Risk Framework
    • Asset Risk
      • From Risks to Risk Parameters
      • Risk Parameters
    • Liquidity Risk
      • Utilization
      • Interest Rate Model
  • Liquidation
  • Price Oracle
  • PADD Liquidity Incentives
  • BGT Emission + Beratrax Integration (Thoon)
  • User Guide
    • Borrower
    • Lender
  • Paddle Battle
    • Mechanics
    • Revenue
    • Referral System
  • Governance
    • PADDenomics
    • About PADD
    • PADD Reward
    • Fee Collection & Distribution
  • User Guide
    • Borrower
    • Lender
  • OTC Trade
  • API Documentation
    • API Guide
    • Loan Endpoints
    • OTC Endpoints
    • REST Endpoints
    • Tutorials
      • Source
      • Parameter Explanation
      • Loan - Create order
      • Loan - Cancel Order
      • Loan - Lend
      • Loan - Repayment
      • Loan - Liquidate
      • OTC - Create OTC Order
      • OTC - Cancel Order
      • OTC - Take Order
  • Links
    • Website
    • Twitter
    • dApp (Mainnet)
    • Audit Report_V1
    • Brand Kit
Powered by GitBook
On this page
  1. API Documentation
  2. Tutorials

OTC - Take Order

The following code example is provided to help you understand the business process. For commercial use, you must handle parameter validation and exception handling on your own.

This example is tested on the Polygon-Amoy chain. Information used in the example can be retrieved from the Source directory. Any amounts involved must be converted using toWei(amount, "decimal") for proper precision.


Code Example

javascriptCopy code// Import web3js library
import Web3 from 'web3';
import OTCTradeABI from '../abi/OTCTrade.json';

// This example is tested on the Polygon-Amoy chain
const amoy_chainId = 80002;
const amoy_chainName = "AMOY";
const amoy_chainRpcUrl = "https://polygon-amoy.infura.io/v3/4ba314367838400fb88f2a1d0e14d42d";
const amoy_contract_OTCTrade = "0x0C4A4390A1ae1186644a0F0354c49880595aD328";
const amoy_account = "0xA3932E6Dbf96983Ffdf43974c0BF7edE9fed76DF";

// Initialize web3 instance
// WalletProvider or HttpProvider
const web3 = new Web3("** Wallet **"); // window.ethereum
const Contract = new web3.eth.Contract(OTCTradeABI, amoy_contract_OTCTrade);

// 1. Buy Order Parameters
// These parameters are retrieved from the creator's history API in the `f_order_info` field.

const maker = "0xA3932E6Dbf96983Ffdf43974c0BF7edE9fed76DF";
const taker = "0x0000000000000000000000000000000000000000"; // Open to all buyers

const asset = [
    {collection: "0x9A3fad316eB9cC7db65aB6f89672796574CD1B76", assetClass: "0x0000000000000000000000000000000000000721", amountOrID: "28308257", name: "Bored Ape Yacht Club", symbol: "BAYC", decimal: 0},
    {collection: "0x9A3fad316eB9cC7db65aB6f89672796574CD1B76", assetClass: "0x0000000000000000000000000000000000000721", amountOrID: "28308487", name: "Bored Ape Yacht Club", symbol: "BAYC", decimal: 0},
    {collection: "0x98700d8fF27Af5F16FdA3bE3bD30aa4585234DCa", assetClass: "0x0000000000000000000000000000000000000020", amountOrID: "100000000", name: "WBTC", symbol: "Wrapped BTC", decimal: 9},
    {collection: "0xc94BC02ecFf5f14b73fe1A3137bb587f5Fa62F5d", assetClass: "0x0000000000000000000000000000000000000020", amountOrID: "100000", name: "USDT", symbol: "Tether USD", decimal: 6}
];

const currency = [
    {collection: "0x0000000000000000000000000000000000000001", assetClass: "0x0000000000000000000000000000000000000000", amountOrID: "100000000000000000", name: "MATIC", symbol: "MATIC", decimal: 18}
];

const deadline = "1728955149"; // End of transaction validity (in seconds)
const sig = "0x65ca1ca8dc706025eb125e40e059e1b768abf909956698237d3ed9eafb276ec03ddb9ef68364652c362f245fce464a286a0fc692470d09de741404621236a4db1b"; // Signature from order creation

// 2. Purchase Operation
// During the transaction, the platform service fee must be paid. You can query the fee via the API.
// The `asset` array represents the assets being acquired, while the `currency` array represents the assets being paid.
// Ensure sufficient wallet balance and approvals for the currency assets.

const handleBuy = Contract.methods.swap([
    maker,
    taker,
    asset.map(item => { return [item.collection, item.assetClass, item.amountOrID]; }),
    currency.map(item => { return [item.collection, item.assetClass, item.amountOrID]; }),
    deadline,
    sig
]).send({
    from: amoy_account,
    value: "platform service fee" + "network native token included the required assets" // Note: Include platform service fee and the network native token amount being paid
});

handleBuy.then(receipt => {
    console.log(receipt);
}).catch(error => {
    console.log(error);
});

Key Notes:

  1. Order Parameters: These parameters (e.g., maker, asset, currency) are retrieved from the creator's order details, typically from the history API. No extra processing is needed for the data.

  2. Platform Service Fee: The platform service fee must be paid during the transaction. The fee amount can be queried from the platform's fee API.

  3. Assets and Currency: Ensure sufficient balances and approvals for the assets and currency involved. For ERC20 tokens, ensure that the precision is properly converted using toWei(amount, "decimal").

  4. Network Native Token Payment: If the payment involves the network native token (e.g., MATIC), it should be included in the value field along with the service fee.

This example demonstrates how to buy an OTC order on the Polygon-Amoy chain. Adjust the parameters as needed for your specific use case.

PreviousOTC - Cancel Order

Last updated 6 months ago