Swap programmatically on Cetus DEX from SUI blockchain

191 Views Asked by At

I want to make a swap programmatically on the Cetus DEX from SUI blockchain, but I have some problems about understanding the inputs of the methods for swap.

This is the contract (module pool_script): https://suiexplorer.com/object/0x2eeaab737b37137b94bfa8f841f92e36a153641119da3456dec1926b9960d9be?module=pool_script

The methods are swap_a2b and swap_b2a. I don't understand what represent the inputs.

If someone can explain to me.

1

There are 1 best solutions below

2
On
let count = await get_json('https://api-sui.cetus.zone/v2/sui/swap/count');

const pool = count.data.pools.find((pool) => {
    return pool.symbol == 'xAIFRENS-SUI';
});
console.log("pool: ", pool);

let poolObj = await provider.getObject({
   id : pool.swap_account,
   options: {
       showContent : true,
       showType : true
   }
});

const globalConfig = '0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f';

const vec = tx.makeMoveVec({
  objects: aifrensObjs.map((obj) => tx.object(obj.coinObjectId)),
});

let b = tx.moveCall({
  target: `${packageId}::pool_script::swap_a2b`,
  arguments: [
      tx.pure(globalConfig),          // fixed
      tx.pure(poolObj.data.objectId), // fixed
      vec,                        // tokenA create by 
      tx.pure(true),              // fixed or not? i don't known
      tx.pure(aifrensBalance),    // amount
      tx.pure(amount_out_limit),  // amount_limit
      tx.pure(4295048016),        // getDefaultSqrtPriceLimit, hardcode
      tx.pure('0x6'),             // clock
  ],
  typeArguments: ['0x9fe1780ac27ec50c9c441fb31822f5c148f841f09ee455c6a0daf7c634a30a27::aifrens::AIFRENS', '0x2::sui::SUI']
});