Native Documentation
  • introduction
    • What is Native
    • About Native V2
    • Benefits for Key Players
  • SOLUTION
    • Native Credit Pool
    • Native Swap Engine
  • CONCEPTS
    • Orderbook
    • Firm Quote Orders
    • Auto Sign Orders
    • Swap Fees
    • Slippage
    • Base and Listed Assets
    • Single-Sided Liquidity Pools
    • Total Available Liquidity
    • Liquidity Pairing
    • Liquidity Bootstrapping
    • Health Ratio
    • Earning Fees and Incentives
    • Credit-Based Swap
      • Collateral Factor
      • PMM Credit
      • Settlement and Liquidation
    • Market-Responsive Pricing
    • Risks
  • USER GUIDE
    • Add Liquidity
    • Pair Liquidity
    • Claim Rewards
    • Swap with Native
  • Build with Native
    • Swap Aggregators
      • Guide
      • FirmQuote Swap APIs
        • GET Orderbook
        • GET Indicative quote
        • GET Firm quote
    • Asset Issuers
      • For Pegged Assets
      • For General Assets
  • Resources
    • Addresses
    • Audits
    • Github
    • System Status
    • Business Source License
    • Media Kit
Powered by GitBook
On this page
  • Endpoint
  • Params
  • Order signing
  • Response
  1. Build with Native
  2. Private Market Makers[june]
  3. Guide
  4. REST API Integration

Sign-Quote

After validating the firm quote, Native will request you to sign the quote, authorizing the swap for the approved amount. The sign quote endpoint must adhere to the following format:

Endpoint

POST <base-url>/sign-quote

Params

Name
Description

nonce

ID to prevent the transaction from being executed more than once. Incremental for each transaction by txOrigin and pool.

signer

Public address of the signer who will sign this order

seller

The address that will send the seller token to the market maker

buyer

Native pool contract address that will execute this order

sellerTokenAmount

The token input amount of the order, in wei

buyerTokenAmount

The token output amount of the order, in wei. Can be modified by the signer to determine the final output amount.

sellerToken

The ERC20 token address that will be sent to the market maker

buyerToken

The ERC20 token address that will be received from the market maker

chainId

Chain ID of the network (e.g., 1 for Ethereum, 56 for BSC)

deadlineTimestamp

The expiration time of the order, in block timestamp. Can be modified by the signer to determine the expiration time.

txOrigin

Address of the trader who initiated the order

quoteId

Unique ID for this order request in UUID v5

auth

The auth string received from firm-quote. Used by the signer to verify the authenticity of the quote data. Native just relays the auth string from pricer to signer.

Example

{
    "nonce": 0,
    "signer": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
    "buyer": "0xaaE854bdd940cf402d79e8051DC7E3390e32A3ac",
    "seller": "0x7d1F5C43998570629f5d00134321fB6a95451ec3",
    "buyerToken": "0x55d398326f99059ff775485246999027b3197955",
    "sellerToken": "0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d",
    "buyerTokenAmount": "10100000000000000000000", // From firm-quote
    "sellerTokenAmount": "10000000000000000000000",
    "deadlineTimestamp": "1671086729", // From firm-quote
    "chainId": 56,
    "txOrigin": "0x7d1F5C43998570629f5d00134321fB6a95451ec3",
    "auth": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9", // From firm-quote
    "quoteId": "62716-206e-41cb-8559-013f1ed1a65a"
}

In this example, a user requests to sign an order of 10,000 USDC for 10,100 USDT on Binance Smart Chain (BSC) to be transacted on the market maker's Native pool (0xaaE854bdd940cf402d79e8051DC7E3390e32A3ac). The order must be signed by the signer (0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266) for successful on-chain execution.

Order signing

Native uses EIP-712 signatures to ensure the order is endorsed only by the assigned signer. The inputs required to sign the order correspond to the data sent in the POST sign-quote request. The code snippet below generates bytes encoded in hexadecimal to be returned in response to the POST /sign-quote request.

async function signOrderNative(data) {
    const wallet = new ethers.Wallet(privateKey, provider);
    const order = {
        id: data.nonce,
        signer: data.signer,
        buyer: data.buyer,
        seller: data.seller,
        buyerToken: data.buyerToken,
        sellerToken: data.sellerToken,
        buyerTokenAmount: data.buyerTokenAmount,
        sellerTokenAmount: data.sellerTokenAmount,
        deadlineTimestamp: data.deadlineTimestamp,
        caller: data.txOrigin,
        quoteId: data.quoteId
    };
    const signature = await generateSignature(order, wallet, data.buyer, data.chainId);

    return {
        success: true,
        signature: signature,
        order: order
    };
}

async function generateSignature(data, wallet, nativePool, chainId) {
    const signatureData = {
        types: {
            Order: [
                { name: "id", type: "uint256" },
                { name: "signer", type: "address" },
                { name: "buyer", type: "address" },
                { name: "seller", type: "address" },
                { name: "buyerToken", type: "address" },
                { name: "sellerToken", type: "address" },
                { name: "buyerTokenAmount", type: "uint256" },
                { name: "sellerTokenAmount", type: "uint256" },
                { name: "deadlineTimestamp", type: "uint256" },
                { name: "caller", type: "address" },
                { name: "quoteId", type: "bytes16" }
            ],
        },
        primaryType: 'Order',
        domain: {
            name: "native pool",
            version: "1",
            verifyingContract: nativePool,
            chainId
        },
        message: {
            id: data.id,
            signer: data.signer,
            buyer: data.buyer,
            seller: data.seller,
            buyerToken: data.buyerToken,
            sellerToken: data.sellerToken,
            buyerTokenAmount: data.buyerTokenAmount,
            sellerTokenAmount: data.sellerTokenAmount,
            deadlineTimestamp: data.deadlineTimestamp,
            caller: data.caller,
            quoteId: Buffer.from(data.quoteId.replace(/-/g, ""), "hex")
        },
    };

    const signature = await wallet._signTypedData(signatureData.domain, signatureData.types, signatureData.message);
    return signature;
}

Response

The response must be in the following format:

Name
Description

success

Indicates whether you can sign the firm quote (true/false)

signature

The signature from signing the EIP-712 order object

order

Example

{
  "success": true,
  "signature": "0x4547e11611094f4295c4175a3266ebd98028edfb30d29a1dc0c42b8bf71401ef4e61c41a4f7aa5e536a6118273d22ed9efe5139005a750745994de6771e273181c",
  "order": {
    "id": 1, // Same as the nonce 
    "signer": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
    "buyer": "0xaaE854bdd940cf402d79e8051DC7E3390e32A3ac",
    "seller": "0x7d1F5C43998570629f5d00134321fB6a95451ec3",
    "buyerToken": "0x55d398326f99059ff775485246999027b3197955",
    "sellerToken": "0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d",
    "buyerTokenAmount": "10100000000000000000000",
    "sellerTokenAmount": "10000000000000000000000",
    "deadlineTimestamp": "1671086729",
    "caller": "0x7d1F5C43998570629f5d00134321fB6a95451ec3", // Same as seller
    "quoteId": "62716-206e-41cb-8559-013f1ed1a65a"
  }
}

In the response above, the market maker returns the generated signature and the corresponding order object to Native. With the signature, the customer can submit the transaction to execute the swap.

Note

  • The signature must start with 0x and have a total of 132 characters.

Congratulations! You have successfully integrated with Native and are now a Market Maker.

Last updated 8 months ago

The order object that contains the order details, similar to

A full code sample for signing can be found .

here
Params