Copy const afSdk = new Aftermath("MAINNET");
await afSdk.init(); // initialize provider
const dca = afSdk.Dca();
const limitOrders = afSdk.LimitOrders();
const userData = afSdk.UserData();
Copy LimitOrders.constants = {
gasAmount: BigInt(50_000_000),
};
To use the Aftermath Limit Orders service, you'll need to create a user account by signing a personal message in two cases:
When creating your first order
When fetching your active orders
This signature serves two important purposes:
It provides essential data that helps ensure the service works correctly
It verifies authorization identity
Copy const messageToSign = userData.createUserAccountMessageToSign();
const signedMessage = await signPersonalMessage({
message: new TextEncoder().encode(JSON.stringify(messageToSign)),
});
Copy const activeOrders = await limit.getActiveLimitOrders({
walletAddress: "0x..",
bytes: signedMessage.bytes,
signature: signedMessage.signature
});
const pastOrders = await limit.getPastLimitOrders({
walletAddress: "0x..",
});
Copy export interface LimitOrderObject {
objectId: string;
allocatedCoin: {
coin: string;
amount: string;
};
buyCoin: {
coin: string;
amount: string;
};
currentAmountSold: string;
currentAmountBought: string;
recipient: string;
created: {
timestamp: number;
txnDigest: string;
};
finished?: {
timestamp: number;
txnDigest: string;
};
expiryTimestamp: number;
status:
| "Active"
| "Canceled"
| "Failed"
| "Filled"
| "Expired"
| "StopLossTriggered";
error?: string;
integratorFee?: {
feeBps: number;
feeRecipient: SuiAddress;
};
outputToInputStopLossExchangeRate?: number;
}
Copy const tx = await limitOrders.getCreateLimitOrderTx({
walletAddress: "0x..",
allocateCoinType:
"0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN",
allocateCoinAmount: BigInt(50000),
buyCoinType:
"0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",
expiryDurationMs: 0,
outputToInputExchangeRate: 0.45,
outputToInputStopLossExchangeRate: 0,
integratorFee: {
feeBps: 6000, // 60%
feeRecipient: "0x...",
},
});
Copy const messageToSign = limit.cancelLimitOrderMessageToSign({
orderIds: ["0x.."]
});
const signedMessage = await signPersonalMessage({
message: new TextEncoder().encode(JSON.stringify(messageToSign)),
});
const success = await limit.cancelLimitOrder({
...signedMessage,
walletAddress: "0x..",
});