@t2000/sdk 10.8.0 → 10.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -4224,6 +4224,51 @@ async function buildTokenizeTx(args) {
4224
4224
  return tx;
4225
4225
  }
4226
4226
 
4227
+ // src/capital/swap.ts
4228
+ init_errors();
4229
+ init_token_registry();
4230
+ var CETUS_INTEGRATE_PUBLISHED_AT = process.env.CETUS_INTEGRATE_PUBLISHED_AT ?? "0xfbb32ac0fa89a3cb0c56c745b688c6d2a53ac8e43447119ad822763997ffb9c3";
4231
+ var MIN_SQRT_PRICE = 4295048016n;
4232
+ var MAX_SQRT_PRICE = 79226673515401279992447579055n;
4233
+ async function buildDirectPoolSwapTx(args) {
4234
+ if (args.amountIn <= 0n) {
4235
+ throw new exports.T2000Error("INVALID_AMOUNT", "amountIn must be positive");
4236
+ }
4237
+ const pool = await args.client.core.getObject({ objectId: args.poolId }).catch(() => null);
4238
+ const m = pool?.object?.type?.match(/Pool<(.+),\s*(.+)>$/);
4239
+ if (!m) {
4240
+ throw new exports.T2000Error("PROTOCOL_UNAVAILABLE", `not a Cetus pool: ${args.poolId}`);
4241
+ }
4242
+ const [typeA, typeB] = [m[1].trim(), m[2].trim()];
4243
+ const aIsUsdc = typeA === exports.USDC_TYPE;
4244
+ if (!aIsUsdc && typeB !== exports.USDC_TYPE) {
4245
+ throw new exports.T2000Error("INVALID_ASSET", "pool is not USDC-quoted");
4246
+ }
4247
+ const a2b = args.direction === "buy" ? aIsUsdc : !aIsUsdc;
4248
+ const inputType = args.direction === "buy" ? exports.USDC_TYPE : a2b ? typeA : typeB;
4249
+ const tx = new transactions.Transaction();
4250
+ tx.setSender(args.sender);
4251
+ const input = transactions.coinWithBalance({ type: inputType, balance: args.amountIn });
4252
+ const vec = tx.makeMoveVec({ elements: [input] });
4253
+ tx.moveCall({
4254
+ target: `${CETUS_INTEGRATE_PUBLISHED_AT}::pool_script::${a2b ? "swap_a2b" : "swap_b2a"}`,
4255
+ typeArguments: [typeA, typeB],
4256
+ arguments: [
4257
+ tx.object(CETUS_GLOBAL_CONFIG_ID),
4258
+ tx.object(args.poolId),
4259
+ vec,
4260
+ tx.pure.bool(true),
4261
+ // by_amount_in
4262
+ tx.pure.u64(args.amountIn),
4263
+ tx.pure.u64(args.minOut),
4264
+ // amount_limit = the slippage floor
4265
+ tx.pure.u128(a2b ? MIN_SQRT_PRICE : MAX_SQRT_PRICE),
4266
+ tx.object.clock()
4267
+ ]
4268
+ });
4269
+ return tx;
4270
+ }
4271
+
4227
4272
  exports.A2A_ESCROW_FEE_CONFIG_ID = A2A_ESCROW_FEE_CONFIG_ID;
4228
4273
  exports.A2A_ESCROW_PACKAGE_ID = A2A_ESCROW_PACKAGE_ID;
4229
4274
  exports.AGENT_CAPITAL_PACKAGE_ID = AGENT_CAPITAL_PACKAGE_ID;
@@ -4243,6 +4288,7 @@ exports.CAPITAL_REGISTRY_ID = CAPITAL_REGISTRY_ID;
4243
4288
  exports.CAPITAL_REGISTRY_VERSION = CAPITAL_REGISTRY_VERSION;
4244
4289
  exports.CETUS_CLMM_PACKAGE_ID = CETUS_CLMM_PACKAGE_ID;
4245
4290
  exports.CETUS_GLOBAL_CONFIG_ID = CETUS_GLOBAL_CONFIG_ID;
4291
+ exports.CETUS_INTEGRATE_PUBLISHED_AT = CETUS_INTEGRATE_PUBLISHED_AT;
4246
4292
  exports.CETUS_POOLS_ID = CETUS_POOLS_ID;
4247
4293
  exports.CETUS_POSITION_TYPE = CETUS_POSITION_TYPE;
4248
4294
  exports.CETUS_USDC_SUI_POOL = CETUS_USDC_SUI_POOL;
@@ -4292,6 +4338,7 @@ exports.buildAddLeafTx = buildAddLeafTx;
4292
4338
  exports.buildAgentCoinModule = buildAgentCoinModule;
4293
4339
  exports.buildCreateJobTx = buildCreateJobTx;
4294
4340
  exports.buildDeliverJobTx = buildDeliverJobTx;
4341
+ exports.buildDirectPoolSwapTx = buildDirectPoolSwapTx;
4295
4342
  exports.buildPublishAgentCoinTx = buildPublishAgentCoinTx;
4296
4343
  exports.buildRefundJobTx = buildRefundJobTx;
4297
4344
  exports.buildRejectJobTx = buildRejectJobTx;