Moon.cx
  • OVERVIEW
    • Moon.cx
  • PROTOCOL
    • DEX
      • Swap
      • Liquidity
      • Boost
    • ORDER
      • Lock
      • Vesting
  • Developers
    • SDK
      • DEX
      • ORDER
  • Listing
Powered by GitBook
On this page
  • Prepare
  • Create order
  • Fill order
  • Cancel order
  • Vesting trigger
  • Getters
  1. Developers
  2. SDK

ORDER

Prepare

if(!process.env.MNEMONIC) {
    throw new Error('MNEMINIC IS REQUIRED!');
}

// init wallet
const mnemonic = process.env.MNEMONIC.split(" ");
const keys = await mnemonicToPrivateKey(mnemonic);

const wallet = tonClient.open(
    WalletContractV4.create({
        workchain: 0,
        publicKey: keys.publicKey
    })
);

// get config
const apiConfig = await getApiConfig();

// get listed assets
const apiAssets = await getApiAssets();

// init order factory
const orderFactory = tonClient.open(OrderFactory.createFromAddress(apiConfig.order_factory));

Create order

// select assets
const asset1_id = Address.parse(apiAssets[2].asset_id); // bolt
const asset2_id = Address.parse(apiAssets[1].asset_id); // usdt, in this case

// create order TON -> JETTON
await orderFactory.sendCreateOrderTon(
    wallet.sender(keys.secretKey),
    123, // query_id
    toNano('10'), // amount
    asset2_id, // trade ton for
    calculateRate(toNano('10'), toNano('20')), // rate 1 : 2
    false, // lock order?
    3000, // 3000 seconds vesting time
);

// create order JETTON -> TON/JETTON
await orderFactory.sendCreateOrderJetton(
    wallet.sender(keys.secretKey),
    123,
    toNano('20'),
    asset1_id, // BOLT
    asset2_id, // USDT in this case. Put null if you want BOLT -> TON
    calculateRate(toNano('20'), 5000000n),
    true, // order locked, can't be cancelled
    0 // no vesting
);

// Use calculateRate. 1st amount - you send, 2nd - you wish to receive.

Fill order

// fill order with ton
await order.sendOrderFillTon(
    wallet.sender(keys.secretKey),
    123, // query_id
    toNano('10'), // amount
    someAddress, // recipient address, will receive fill result
    someCell, // recipient payload
    someOtherAddress, // reject address, will receive refund on any fails
);

// fill order with jetton
const jettonMaster = tonClient.open(JettonMinter.createFromAddress(asset2_id));
const jettonWallet = await jettonMaster.getWallet(wallet.address);

await order.sendOrderFillJetton(
    wallet.sender(keys.secretKey),
    jettonWallet, // your jetton wallet 
    123, // query_id
    13000000n, // amount
    wallet.address, // recipient address
    null, // recipient payload
    wallet.address // reject address
);

Cancel order

// init order
const order = tonClient.open(Order.createFromAddress(orderAddr));

// cancel order
await order.sendCancel(
    wallet.sender(keys.secretKey),
    123, // query_id
);

Vesting trigger

// You can manually send vesting trigger

await order.sendExternalVestingTrigger();

Getters

const orderData = await order.getOrder(); // full data in one call
const fillOut = await order.getFillOut(100000n); // fill result
const vestingData = await order.getVestingData(); // will fail if order status != 7.
const orderStatus = await order.getStatus();
const orderAmount = await order.getAmount();
const orderAssets = await order.getAssets();
const orderWallets = await order.getWallets();

Last updated 1 month ago