从SUI区块链在Cetus DEX上进行程序化的交换

huangapple go评论68阅读模式
英文:

Swap programmatically on Cetus DEX from SUI blockchain

问题

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.

英文:

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

得分: 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),          // 固定值
      tx.pure(poolObj.data.objectId), // 固定值
      vec,                        // 由 tokenA 创建
      tx.pure(true),              // 固定值或不固定?我不知道
      tx.pure(aifrensBalance),    // 数量
      tx.pure(amount_out_limit),  // 限制数量
      tx.pure(4295048016),        // getDefaultSqrtPriceLimit,硬编码
      tx.pure('0x6'),             // 时钟
  ],
  typeArguments: ['0x9fe1780ac27ec50c9c441fb31822f5c148f841f09ee455c6a0daf7c634a30a27::aifrens::AIFRENS', '0x2::sui::SUI']
});

请注意,代码中的注释已被翻译成中文。

英文:
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']
});

huangapple
  • 本文由 发表于 2023年5月25日 18:32:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76331328.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定