1

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.

KunLun
  • 3,109
  • 3
  • 18
  • 65

1 Answers1

2
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']
});
sleeping
  • 31
  • 4
  • I am trying to do this swap from the explorer. And at `Arg2` (your code `vec`), I don't really understand what to write. I receive all the time: `Expect 0x2::coin::Coin<0x2::sui::SUI> to be a array, received string` – KunLun Jul 03 '23 at 12:52
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 04 '23 at 06:30