Limit Orders
A limit order, and the <AoriOrder>
object, constitute the main type of object in the Aori API. A reference used within the Aori smart contract can be found here.
<AoriOrder>
Object Interface
- Name
offerer
- Type
- string
- Description
The address of the order creator
- Name
inputToken
- Type
- string
- Description
The token address being offered
- Name
inputAmount
- Type
- bigint
- Description
The amount of input token being offered
- Name
outputToken
- Type
- string
- Description
The token address being requested
- Name
outputAmount
- Type
- bigint
- Description
The amount of output token being requested
- Name
recipient
- Type
- string
- Description
The address to receive the output tokens
- Name
zone
- Type
- string
- Description
The zone address for the order
- Name
chainId
- Type
- number
- Description
The blockchain network ID
- Name
startTime
- Type
- number
- Description
Unix timestamp when the order becomes valid
- Name
endTime
- Type
- number
- Description
Unix timestamp when the order expires
- Name
toWithdraw
- Type
- boolean
- Description
Flag indicating if tokens should be withdrawn
Example Order
{
"offerer": "0x..",
"inputToken": "0x..",
"inputAmount": 100000,
"outputToken": "0x..",
"outputAmount": 100000,
"recipient": "0x..",
"zone": "0x..",
"chainId": 1,
"startTime": 1714857600,
"endTime": 1714861200,
"toWithdraw": false
}
Creating a Limit Order
Each SDK will provide a function to help create limit orders more easily.
import { formatIntoLimitOrder } from '@aori-io/sdk';
const limitOrder = await formatIntoLimitOrder({
offerer: "0x..",
startTime: number,
endTime: number,
inputToken: "0x..",
inputAmount: 1000..,
outputToken: "0x..",
outputAmount: 100000,
zone: "0x..",
chainId: 1,
toWithdraw: boolean
});
Signing a Limit Order
To ensure that your limit order has not been tampered with, a signature is required alongside the limit order when sending it through the API.
To sign the order, you must first generate the orderHash
of the order. The order hash is a keccak256 of the fields within the order struct.
const orderHash = solidityPackedKeccak256([
"address", // offerer
// Input
"address", // inputToken
"uint256", // inputAmount
"uint256", // outputAmount
"address", // outputToken
"address", // recipient
// Other details
"address", // zone
"uint256", // chainId
"uint256", // startTime
"uint256", // endTime
"bool" // toWithdraw
], [
offerer, inputToken, inputAmount,
outputToken, outputAmount, recipient,
zone, chainId, startTime, endTime, toWithdraw
]);
You then sign the orderHash
with your private key as a Hash
(e.g via taking it as a Bytes
slice or by doing getBytes(...)
), not a utf-8
string.