Build a Delta Order to Sign

Build a Delta Order to Sign

POST https://api.paraswap.io/orders/build

This endpoint gets the Delta price and with ability to fallback to market prices.

Query Parameters

Name
Type
Description

price*

DeltaPrice

chainId*

string

Chain ID. (Mainnet - 1, Optimism - 10, BSC - 56, Polygon - 137, Fantom - 250, zkEVM - 1101, Base - 8453, Arbitrum - 42161, Avalanche - 43114, Gnosis - 100).

owner*

string

Order owner address.

beneficiary

string

Order beneficiary. Default: zero address, meaning owner address.

slippage

number

Slippage in base points (100 is 1%). Default: 100.

deadline

number

Order expiry time as UNIX timestamp. Default: 1 hour from order creation.

nonce

string

Arbitrary uint256 value to be used as order nonce. Default: value generated with internal algos. It is recommended to omit this param.

permit

string

partiallyFillable

boolean

If true, order will be generated as partially fillable. Default: false.

partnerAddress

string

Address of the partner. Used to collect fees from the order. Default: zero address.

partnerFeeBps

number

Partner fee percent in base points (100 is 1%). Max value is 200. Default: 0.

partnerTakesSurplus

boolean

If true, partner will collect 50% of the order surplus instead of flat percent fee. Default: false.

{
    "toSign": {
        "domain": {
            "name": "Portikus",
            "version": "2.0.0",
            "chainId": 8453,
            "verifyingContract": "0x0000000000bbf5c5fd284e657f01bd000933c96d"
        },
        "types": {
            "Order": [
                {
                    "name": "owner",
                    "type": "address"
                },
                {
                    "name": "beneficiary",
                    "type": "address"
                },
                {
                    "name": "srcToken",
                    "type": "address"
                },
                {
                    "name": "destToken",
                    "type": "address"
                },
                {
                    "name": "srcAmount",
                    "type": "uint256"
                },
                {
                    "name": "destAmount",
                    "type": "uint256"
                },
                {
                    "name": "expectedDestAmount",
                    "type": "uint256"
                },
                {
                    "name": "deadline",
                    "type": "uint256"
                },
                {
                    "name": "nonce",
                    "type": "uint256"
                },
                {
                    "name": "partnerAndFee",
                    "type": "uint256"
                },
                {
                    "name": "permit",
                    "type": "bytes"
                }
            ]
        },
        "value": {
            "owner": "0x75c94990d2ad92d8da4e0a238d872d09ec16706e",
            "beneficiary": "0x0000000000000000000000000000000000000000",
            "srcToken": "0x50c5725949a6f0c72e6c4a641f24049a917db0cb",
            "destToken": "0xd9aaec86b65d86f6a7b5b1b0c42ffa531710b6ca",
            "srcAmount": "1000000000000000000",
            "destAmount": "950782",
            "expectedDestAmount": "960386",
            "deadline": 1733947775,
            "nonce": "85031176186664120289528593255020940612605526029367271061861981722040477929716",
            "permit": "0x",
            "partnerAndFee": "0"
        }
    }
}

Most common error types

  • ValidationError - validation for params failed

  • UnsupportedChain - the chain ID is not supported by Delta.

  • UnsupportedToken - the token is not supported by Delta.

  • InvalidHmac - hmac check failed, meaning price object returned from /quote endpoint was mutated.

Supported Permits

  • Permit(ERC-2612) - expected to have 224 bytes length.

  • Permit2

    • TransferFrom format - expected length is 96 bytes (32 for permitNonce, 64 for compact signature), amount and deadline should be the same as in Order.

    • Allowance format - expected length is 192 bytes.

  • DAI Style Permit - expected length is 256 bytes.

  • 0x01 - special permit value that signifies existing Permit2 allowance.

Delta Contract should be specified as a spender is a permit.

Sign an Order

Currently only EIP-712 signing is supported for Delta Orders.

Example using ethers and axios:

import { ethers, TypedDataEncoder } from "ethers"; // ethers V6
import axios from "axios";

const userWallet = new ethers.Wallet(ethers.id("alice"));
const userAddress = userWallet.address;
const chainId = 1;
// fetch price
const { data: quoteData } = await axios.get("https://api.paraswap.io/quote?mode=delta&...");
const price = quoteData.delta;
// prepare build order params
const buildOrderParams = {
    price,
    owner: userAddress,
    chainId,
    partnerAddress: "0x81037e7be71bce9591de0c54bb485ad3e048b8de",
    partnerFeeBps: 100, // 1%
    partnerTakesSurplus: false, // the default
};
// build the order to sign
const { data: buildOrderData } = await axios.post("https://api.paraswap.io/orders/build", buildOrderParams);
const { domain, types, value: order } = buildOrderData.toSign;
// hash the order
const eip712Hash = TypedDataEncoder.hash(
  domain,
  types,
  order,
);
// sign and compact
const signature = userWallet.signingKey.sign(typedHash).compactSerialized; // ERC-2098 representation

Partner Fees

This is just technical explanation. If you are using our Order Building endpoint, this knowledge is not required.

The fees are enabled by encoding partnerAndFee param of the order, before its signed by a user.

The param includes three values:

  • partnerAddress - on-chain address which will be able to collect the fees.

  • partnerFeeBps - flat fee percent which will be taken from the order. The value is in base points (100is 1%), which the maximum allowed value of 200.

  • partnerTakeSurplus - a flag that, if set, allows the partner to collect 50% of the surplus as fees instead of the flat fee specified with partnerFeeBps.

These are encoded into a single uint256 value, which then is used as partnerAndFee.

Last updated