@cetusprotocol/aggregator-sdk 1.5.0 → 1.5.2

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
@@ -3,7 +3,7 @@
3
3
  var transactions = require('@mysten/sui/transactions');
4
4
  var JSONbig = require('json-bigint');
5
5
  var utils = require('@mysten/sui/utils');
6
- var grpc = require('@mysten/sui/grpc');
6
+ var jsonRpc = require('@mysten/sui/jsonRpc');
7
7
  var hermesClient = require('@pythnetwork/hermes-client');
8
8
  var bcs = require('@mysten/sui/bcs');
9
9
 
@@ -43,9 +43,9 @@ var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__
43
43
  mod2
44
44
  ));
45
45
 
46
- // node_modules/bn.js/lib/bn.js
46
+ // node_modules/.pnpm/bn.js@5.2.3/node_modules/bn.js/lib/bn.js
47
47
  var require_bn = __commonJS({
48
- "node_modules/bn.js/lib/bn.js"(exports, module) {
48
+ "node_modules/.pnpm/bn.js@5.2.3/node_modules/bn.js/lib/bn.js"(exports$1, module) {
49
49
  (function(module2, exports2) {
50
50
  function assert(val, msg) {
51
51
  if (!val) throw new Error(msg || "Assertion failed");
@@ -351,7 +351,7 @@ var require_bn = __commonJS({
351
351
  };
352
352
  if (typeof Symbol !== "undefined" && typeof Symbol.for === "function") {
353
353
  try {
354
- BN7.prototype[Symbol.for("nodejs.util.inspect.custom")] = inspect;
354
+ BN7.prototype[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")] = inspect;
355
355
  } catch (e) {
356
356
  BN7.prototype.inspect = inspect;
357
357
  }
@@ -1768,6 +1768,10 @@ var require_bn = __commonJS({
1768
1768
  var mask = 67108863 ^ 67108863 >>> r << r;
1769
1769
  this.words[this.length - 1] &= mask;
1770
1770
  }
1771
+ if (this.length === 0) {
1772
+ this.words[0] = 0;
1773
+ this.length = 1;
1774
+ }
1771
1775
  return this._strip();
1772
1776
  };
1773
1777
  BN7.prototype.maskn = function maskn(bits) {
@@ -2783,7 +2787,7 @@ var require_bn = __commonJS({
2783
2787
  var res = this.imod(a._invmp(this.m).mul(this.r2));
2784
2788
  return res._forceRed(this);
2785
2789
  };
2786
- })(typeof module === "undefined" || module, exports);
2790
+ })(typeof module === "undefined" || module, exports$1);
2787
2791
  }
2788
2792
  });
2789
2793
 
@@ -3416,7 +3420,7 @@ var AGGREGATOR_V3_CONFIG = {
3416
3420
  };
3417
3421
 
3418
3422
  // src/api.ts
3419
- var SDK_VERSION = 1010500;
3423
+ var SDK_VERSION = 1010502;
3420
3424
  function parseRouterResponse(data, byAmountIn) {
3421
3425
  let packages = /* @__PURE__ */ new Map();
3422
3426
  if (data.packages) {
@@ -3852,7 +3856,7 @@ var AggregatorConfig = class {
3852
3856
  // src/math.ts
3853
3857
  var import_bn3 = __toESM(require_bn());
3854
3858
 
3855
- // node_modules/decimal.js/decimal.mjs
3859
+ // node_modules/.pnpm/decimal.js@10.6.0/node_modules/decimal.js/decimal.mjs
3856
3860
  var EXP_LIMIT = 9e15;
3857
3861
  var MAX_DIGITS = 1e9;
3858
3862
  var NUMERALS = "0123456789abcdef";
@@ -6021,7 +6025,7 @@ function tanh(x) {
6021
6025
  function trunc(x) {
6022
6026
  return finalise(x = new this(x), x.e + 1, 1);
6023
6027
  }
6024
- P[Symbol.for("nodejs.util.inspect.custom")] = P.toString;
6028
+ P[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")] = P.toString;
6025
6029
  P[Symbol.toStringTag] = "Decimal";
6026
6030
  var Decimal = P.constructor = clone(DEFAULTS);
6027
6031
  LN10 = new Decimal(LN10);
@@ -7857,11 +7861,12 @@ var PythAdapter = class {
7857
7861
  if (this.baseUpdateFee !== void 0) {
7858
7862
  return this.baseUpdateFee;
7859
7863
  }
7860
- const { object } = await this.client.getObject({
7861
- objectId: this.pythStateId,
7862
- include: { json: true }
7864
+ const res = await this.client.getObject({
7865
+ id: this.pythStateId,
7866
+ options: { showContent: true }
7863
7867
  });
7864
- const json = object.json;
7868
+ const content = res.data?.content;
7869
+ const json = content && "fields" in content ? content.fields : null;
7865
7870
  if (!json) {
7866
7871
  throw new Error("Unable to fetch pyth state object");
7867
7872
  }
@@ -7869,16 +7874,21 @@ var PythAdapter = class {
7869
7874
  return this.baseUpdateFee;
7870
7875
  }
7871
7876
  async getPackageId(objectId) {
7872
- const { object } = await this.client.getObject({
7873
- objectId,
7874
- include: { json: true }
7877
+ const res = await this.client.getObject({
7878
+ id: objectId,
7879
+ options: { showContent: true }
7875
7880
  });
7876
- const json = object.json;
7881
+ const content = res.data?.content;
7882
+ const json = content && "fields" in content ? content.fields : null;
7877
7883
  if (!json) {
7878
7884
  throw new Error(`Cannot fetch package id for object ${objectId}`);
7879
7885
  }
7880
7886
  if ("upgrade_cap" in json) {
7881
- return json.upgrade_cap.package;
7887
+ const upgradeCap = json.upgrade_cap;
7888
+ const packageId = upgradeCap?.fields?.package;
7889
+ if (typeof packageId === "string") {
7890
+ return packageId;
7891
+ }
7882
7892
  }
7883
7893
  throw new Error("upgrade_cap not found");
7884
7894
  }
@@ -7902,20 +7912,19 @@ var PythAdapter = class {
7902
7912
  const { id: tableId, fieldType } = await this.getPriceTableInfo();
7903
7913
  const feedIdBytes = Buffer.from(normalizedFeedId, "hex");
7904
7914
  try {
7905
- const PriceIdentifier = bcs.bcs.struct("PriceIdentifier", {
7906
- bytes: bcs.bcs.vector(bcs.bcs.u8())
7907
- });
7908
- const bcsBytes = PriceIdentifier.serialize({ bytes: Array.from(feedIdBytes) }).toBytes();
7909
- const result = await this.client.getDynamicField({
7915
+ const result = await this.client.getDynamicFieldObject({
7910
7916
  parentId: tableId,
7911
7917
  name: {
7912
- type: fieldType,
7913
- bcs: bcsBytes
7918
+ type: `${fieldType}::price_identifier::PriceIdentifier`,
7919
+ value: { bytes: Array.from(feedIdBytes) }
7914
7920
  }
7915
7921
  });
7916
- const valueBcs = result.dynamicField.value.bcs;
7917
- const valueBytes = valueBcs instanceof Uint8Array ? valueBcs : new Uint8Array(Object.values(valueBcs));
7918
- const objectId = "0x" + Array.from(valueBytes).map((b) => b.toString(16).padStart(2, "0")).join("");
7922
+ const content = result.data?.content;
7923
+ const json = content && "fields" in content ? content.fields : null;
7924
+ const objectId = typeof json?.value === "string" ? json.value : void 0;
7925
+ if (!objectId) {
7926
+ return void 0;
7927
+ }
7919
7928
  this.priceFeedObjectIdCache.set(normalizedFeedId, objectId);
7920
7929
  return objectId;
7921
7930
  } catch {
@@ -7926,35 +7935,22 @@ var PythAdapter = class {
7926
7935
  if (this.priceTableInfo !== void 0) {
7927
7936
  return this.priceTableInfo;
7928
7937
  }
7929
- let cursor = null;
7930
- let hasNextPage = true;
7931
- while (hasNextPage) {
7932
- const dynamicFields = await this.client.listDynamicFields({
7933
- parentId: this.pythStateId,
7934
- cursor
7935
- });
7936
- for (const field of dynamicFields.dynamicFields) {
7937
- if (field.name.type === "vector<u8>") {
7938
- const objectId = field.$kind === "DynamicObject" && field.childId ? field.childId : field.fieldId;
7939
- const fieldObj = await this.client.getObject({
7940
- objectId,
7941
- include: { json: true }
7942
- });
7943
- const type = fieldObj.object.type;
7944
- if (type.includes("table::Table")) {
7945
- const innerTypes = type.replace(/.*table::Table</, "").replace(/>$/, "");
7946
- const fieldType = innerTypes.split(",")[0].trim();
7947
- this.priceTableInfo = { id: fieldObj.object.objectId, fieldType };
7948
- return this.priceTableInfo;
7949
- }
7950
- }
7938
+ const result = await this.client.getDynamicFieldObject({
7939
+ parentId: this.pythStateId,
7940
+ name: {
7941
+ type: "vector<u8>",
7942
+ value: "price_info"
7951
7943
  }
7952
- hasNextPage = dynamicFields.hasNextPage;
7953
- cursor = dynamicFields.cursor;
7944
+ });
7945
+ if (!result.data?.type) {
7946
+ throw new Error(
7947
+ "Price Table not found, contract may not be initialized"
7948
+ );
7954
7949
  }
7955
- throw new Error(
7956
- "Price Table not found, contract may not be initialized"
7957
- );
7950
+ let type = result.data.type.replace("0x2::table::Table<", "");
7951
+ type = type.replace("::price_identifier::PriceIdentifier, 0x2::object::ID>", "");
7952
+ this.priceTableInfo = { id: result.data.objectId, fieldType: type };
7953
+ return this.priceTableInfo;
7958
7954
  }
7959
7955
  extractVaaBytesFromAccumulatorMessage(accumulatorMessage) {
7960
7956
  const trailingPayloadSize = accumulatorMessage.readUint8(6);
@@ -8138,21 +8134,21 @@ async function getOrCreateAccountCap(txb, client, owner) {
8138
8134
  }
8139
8135
  async function getAccountCap(client, owner) {
8140
8136
  const limit = 50;
8141
- let cursor = null;
8137
+ let cursor = void 0;
8142
8138
  while (true) {
8143
- const ownedObjects = await client.listOwnedObjects({
8139
+ const ownedObjects = await client.getOwnedObjects({
8144
8140
  owner,
8145
8141
  cursor,
8146
8142
  limit,
8147
- type: `${DEEPBOOK_PACKAGE_ID}::${DEEPBOOK_CUSTODIAN_V2_MODULE}::AccountCap`
8143
+ filter: { StructType: `${DEEPBOOK_PACKAGE_ID}::${DEEPBOOK_CUSTODIAN_V2_MODULE}::AccountCap` }
8148
8144
  });
8149
- if (ownedObjects.objects.length !== 0) {
8150
- return ownedObjects.objects[0].objectId;
8145
+ if (ownedObjects.data.length !== 0) {
8146
+ return ownedObjects.data[0].data?.objectId ?? null;
8151
8147
  }
8152
8148
  if (!ownedObjects.hasNextPage) {
8153
8149
  break;
8154
8150
  }
8155
- cursor = ownedObjects.cursor;
8151
+ cursor = ownedObjects.nextCursor ?? void 0;
8156
8152
  }
8157
8153
  return null;
8158
8154
  }
@@ -8180,10 +8176,10 @@ function getAggregatorV2Extend2PublishedAt(publishedAt, packages) {
8180
8176
  // src/utils/gas.ts
8181
8177
  var import_bn4 = __toESM(require_bn());
8182
8178
  function extractGasMetrics(result) {
8183
- const txResult = result.Transaction ?? result.FailedTransaction;
8184
- const effects = txResult?.effects;
8185
- if (!effects || !effects.status.success) {
8186
- const errorMsg = effects?.status.success === false ? effects.status.error.message : "Unknown error";
8179
+ const effects = result.effects;
8180
+ const isSuccess = !result.error && effects.status.status === "success";
8181
+ if (!isSuccess) {
8182
+ const errorMsg = result.error ?? effects.status.error ?? "Unknown error";
8187
8183
  return {
8188
8184
  computationCost: "0",
8189
8185
  storageCost: "0",
@@ -8846,8 +8842,8 @@ var _AggregatorClient = class _AggregatorClient {
8846
8842
  constructor(params) {
8847
8843
  this.endpoint = params.endpoint ? processEndpoint(params.endpoint) : DEFAULT_ENDPOINT;
8848
8844
  const network = params.env === 1 /* Testnet */ ? "testnet" : "mainnet";
8849
- const grpcUrl = params.env === 1 /* Testnet */ ? "https://fullnode.testnet.sui.io:443" : "https://fullnode.mainnet.sui.io:443";
8850
- this.client = params.client ?? new grpc.SuiGrpcClient({ network, baseUrl: grpcUrl });
8845
+ const rpcUrl = params.env === 1 /* Testnet */ ? "https://fullnode.testnet.sui.io:443" : "https://fullnode.mainnet.sui.io:443";
8846
+ this.client = params.client ?? new jsonRpc.SuiJsonRpcClient({ network, url: rpcUrl });
8851
8847
  this.signer = params.signer || "";
8852
8848
  this.env = params.env || 0 /* Mainnet */;
8853
8849
  const config2 = _AggregatorClient.CONFIG[this.env];
@@ -8888,13 +8884,13 @@ var _AggregatorClient = class _AggregatorClient {
8888
8884
  }
8889
8885
  async getOneCoinUsedToMerge(coinType) {
8890
8886
  try {
8891
- const gotCoin = await this.client.listCoins({
8887
+ const gotCoin = await this.client.getCoins({
8892
8888
  owner: this.signer,
8893
8889
  coinType,
8894
8890
  limit: 1
8895
8891
  });
8896
- if (gotCoin.objects.length === 1) {
8897
- return gotCoin.objects[0].objectId;
8892
+ if (gotCoin.data.length === 1) {
8893
+ return gotCoin.data[0].coinObjectId;
8898
8894
  }
8899
8895
  return null;
8900
8896
  } catch (error) {
@@ -9308,7 +9304,7 @@ var _AggregatorClient = class _AggregatorClient {
9308
9304
  return outputCoin;
9309
9305
  }
9310
9306
  async routerSwap(params) {
9311
- const { router, inputCoin, slippage, txb, partner } = params;
9307
+ const { router, inputCoin, slippage, txb, partner, cetusDlmmPartner } = params;
9312
9308
  if (slippage > 1 || slippage < 0) {
9313
9309
  throw new Error(CLIENT_CONFIG.ERRORS.INVALID_SLIPPAGE);
9314
9310
  }
@@ -9342,7 +9338,8 @@ var _AggregatorClient = class _AggregatorClient {
9342
9338
  amountOut.toString(),
9343
9339
  amountLimit.toString(),
9344
9340
  priceInfoObjectIds,
9345
- partner ?? this.partner
9341
+ partner ?? this.partner,
9342
+ cetusDlmmPartner ?? this.cetusDlmmPartner
9346
9343
  );
9347
9344
  } else {
9348
9345
  return this.expectOutputSwapV3(
@@ -9365,7 +9362,15 @@ var _AggregatorClient = class _AggregatorClient {
9365
9362
  * @throws Error if input coin amount exceeds maxAmountIn
9366
9363
  */
9367
9364
  async routerSwapWithMaxAmountIn(params) {
9368
- const { router, inputCoin, slippage, txb, partner, maxAmountIn } = params;
9365
+ const {
9366
+ router,
9367
+ inputCoin,
9368
+ slippage,
9369
+ txb,
9370
+ partner,
9371
+ cetusDlmmPartner,
9372
+ maxAmountIn
9373
+ } = params;
9369
9374
  if (slippage > 1 || slippage < 0) {
9370
9375
  throw new Error(CLIENT_CONFIG.ERRORS.INVALID_SLIPPAGE);
9371
9376
  }
@@ -9400,7 +9405,8 @@ var _AggregatorClient = class _AggregatorClient {
9400
9405
  amountOut.toString(),
9401
9406
  amountLimit.toString(),
9402
9407
  priceInfoObjectIds,
9403
- partner ?? this.partner
9408
+ partner ?? this.partner,
9409
+ cetusDlmmPartner ?? this.cetusDlmmPartner
9404
9410
  );
9405
9411
  } else {
9406
9412
  return this.expectOutputSwapV3WithMaxAmountIn(
@@ -9417,7 +9423,14 @@ var _AggregatorClient = class _AggregatorClient {
9417
9423
  // auto build input coin
9418
9424
  // auto merge, transfer or destory target coin.
9419
9425
  async fastRouterSwap(params) {
9420
- const { router, slippage, txb, partner, payDeepFeeAmount } = params;
9426
+ const {
9427
+ router,
9428
+ slippage,
9429
+ txb,
9430
+ partner,
9431
+ cetusDlmmPartner,
9432
+ payDeepFeeAmount
9433
+ } = params;
9421
9434
  const fromCoinType = router.paths[0].from;
9422
9435
  const targetCoinType = router.paths[router.paths.length - 1].target;
9423
9436
  const byAmountIn = router.byAmountIn;
@@ -9458,6 +9471,7 @@ var _AggregatorClient = class _AggregatorClient {
9458
9471
  slippage,
9459
9472
  txb,
9460
9473
  partner: partner ?? this.partner,
9474
+ cetusDlmmPartner: cetusDlmmPartner ?? this.cetusDlmmPartner,
9461
9475
  deepbookv3DeepFee: deepCoin
9462
9476
  };
9463
9477
  const targetCoin = await this.routerSwap(routerSwapParams);
@@ -9573,7 +9587,7 @@ var _AggregatorClient = class _AggregatorClient {
9573
9587
  }
9574
9588
  }
9575
9589
  async fixableRouterSwapV3(params) {
9576
- const { router, inputCoin, slippage, txb, partner } = params;
9590
+ const { router, inputCoin, slippage, txb, partner, cetusDlmmPartner } = params;
9577
9591
  checkOverlayFeeConfig(this.overlayFeeRate, this.overlayFeeReceiver);
9578
9592
  let overlayFee = 0;
9579
9593
  if (router.byAmountIn) {
@@ -9602,7 +9616,8 @@ var _AggregatorClient = class _AggregatorClient {
9602
9616
  expectedAmountOut.toString(),
9603
9617
  amountLimit.toString(),
9604
9618
  priceInfoObjectIds,
9605
- partner ?? this.partner
9619
+ partner ?? this.partner,
9620
+ cetusDlmmPartner ?? this.cetusDlmmPartner
9606
9621
  );
9607
9622
  } else {
9608
9623
  return this.expectOutputSwapV3(
@@ -9639,18 +9654,16 @@ var _AggregatorClient = class _AggregatorClient {
9639
9654
  });
9640
9655
  }
9641
9656
  tx.setSenderIfNotSet(this.signer || "0x0");
9642
- const simulateRes = await this.client.simulateTransaction({
9643
- transaction: tx,
9644
- include: { events: true, effects: true }
9657
+ const simulateRes = await this.client.devInspectTransactionBlock({
9658
+ sender: this.signer || "0x0",
9659
+ transactionBlock: tx
9645
9660
  });
9646
- const txResult = simulateRes.Transaction ?? simulateRes.FailedTransaction;
9647
- if (!txResult || simulateRes.$kind === "FailedTransaction") {
9648
- const errorMsg = txResult?.status.success === false ? txResult.status.error.message : "Unknown error";
9649
- throw new Error("Simulation error: " + errorMsg);
9661
+ if (simulateRes.error) {
9662
+ throw new Error("Simulation error: " + simulateRes.error);
9650
9663
  }
9651
- const events = txResult.events ?? [];
9664
+ const events = simulateRes.events ?? [];
9652
9665
  const valueData = events.filter((item) => {
9653
- return item.eventType.includes("CalculatedSwapResultEvent");
9666
+ return item.type.includes("CalculatedSwapResultEvent");
9654
9667
  });
9655
9668
  if (valueData.length === 0 || valueData.length !== pools.length) {
9656
9669
  throw new Error("Simulate event result error");
@@ -9658,7 +9671,7 @@ var _AggregatorClient = class _AggregatorClient {
9658
9671
  let tempMaxAmount = byAmountIn ? new import_bn6.default(0) : new import_bn6.default(U64_MAX);
9659
9672
  let tempIndex = 0;
9660
9673
  for (let i = 0; i < valueData.length; i += 1) {
9661
- const eventJson2 = valueData[i].json;
9674
+ const eventJson2 = valueData[i].parsedJson;
9662
9675
  if (eventJson2?.data?.is_exceed) {
9663
9676
  continue;
9664
9677
  }
@@ -9676,11 +9689,11 @@ var _AggregatorClient = class _AggregatorClient {
9676
9689
  }
9677
9690
  }
9678
9691
  }
9679
- const eventJson = valueData[tempIndex].json;
9692
+ const eventJson = valueData[tempIndex].parsedJson;
9680
9693
  const eventData = eventJson?.data;
9681
9694
  const [decimalA, decimalB] = await Promise.all([
9682
- this.client.getCoinMetadata({ coinType: coinA }).then((res) => res.coinMetadata?.decimals ?? null),
9683
- this.client.getCoinMetadata({ coinType: coinB }).then((res) => res.coinMetadata?.decimals ?? null)
9695
+ this.client.getCoinMetadata({ coinType: coinA }).then((res) => res?.decimals ?? null),
9696
+ this.client.getCoinMetadata({ coinType: coinB }).then((res) => res?.decimals ?? null)
9684
9697
  ]);
9685
9698
  if (decimalA == null || decimalB == null) {
9686
9699
  throw new Error("Cannot get coin decimals");
@@ -9749,9 +9762,9 @@ var _AggregatorClient = class _AggregatorClient {
9749
9762
  }
9750
9763
  async devInspectTransactionBlock(txb) {
9751
9764
  txb.setSenderIfNotSet(this.signer || "0x0");
9752
- const res = await this.client.simulateTransaction({
9753
- transaction: txb,
9754
- include: { events: true, effects: true }
9765
+ const res = await this.client.devInspectTransactionBlock({
9766
+ sender: this.signer || "0x0",
9767
+ transactionBlock: txb
9755
9768
  });
9756
9769
  return res;
9757
9770
  }
@@ -9759,7 +9772,7 @@ var _AggregatorClient = class _AggregatorClient {
9759
9772
  const res = await this.client.signAndExecuteTransaction({
9760
9773
  transaction: txb,
9761
9774
  signer,
9762
- include: { effects: true, events: true, balanceChanges: true }
9775
+ options: { showEffects: true, showEvents: true, showBalanceChanges: true }
9763
9776
  });
9764
9777
  return res;
9765
9778
  }
package/dist/index.d.cts CHANGED
@@ -1,8 +1,8 @@
1
- import * as _mysten_sui_client from '@mysten/sui/client';
1
+ import * as _mysten_sui_jsonRpc from '@mysten/sui/jsonRpc';
2
+ import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
2
3
  import { TransactionObjectArgument, Transaction, TransactionArgument } from '@mysten/sui/transactions';
3
4
  import BN from 'bn.js';
4
5
  import Decimal from 'decimal.js';
5
- import { SuiGrpcClient } from '@mysten/sui/grpc';
6
6
  import { Signer } from '@mysten/sui/cryptography';
7
7
 
8
8
  interface FindRouterParams {
@@ -308,7 +308,7 @@ declare class PythAdapter {
308
308
  private priceTableInfo;
309
309
  private priceFeedObjectIdCache;
310
310
  private baseUpdateFee;
311
- constructor(client: SuiGrpcClient, pythStateId: ObjectId, wormholeStateId: ObjectId, hermesUrls: string[]);
311
+ constructor(client: SuiJsonRpcClient, pythStateId: ObjectId, wormholeStateId: ObjectId, hermesUrls: string[]);
312
312
  getPriceFeedsUpdateData(priceIDs: string[]): Promise<Buffer[]>;
313
313
  getBaseUpdateFee(): Promise<number>;
314
314
  getPackageId(objectId: ObjectId): Promise<string>;
@@ -365,6 +365,7 @@ type BuildRouterSwapParamsV3 = {
365
365
  slippage: number;
366
366
  txb: Transaction;
367
367
  partner?: string;
368
+ cetusDlmmPartner?: string;
368
369
  deepbookv3DeepFee?: TransactionObjectArgument;
369
370
  fixable?: boolean;
370
371
  };
@@ -373,6 +374,7 @@ type BuildFastRouterSwapParamsV3 = {
373
374
  slippage: number;
374
375
  txb: Transaction;
375
376
  partner?: string;
377
+ cetusDlmmPartner?: string;
376
378
  refreshAllCoins?: boolean;
377
379
  payDeepFeeAmount?: number;
378
380
  };
@@ -403,7 +405,7 @@ declare function getProvidersIncluding(includeProviders: string[]): string[];
403
405
  type AggregatorClientParams = {
404
406
  endpoint?: string;
405
407
  signer?: string;
406
- client?: SuiGrpcClient;
408
+ client?: SuiJsonRpcClient;
407
409
  env?: Env;
408
410
  pythUrls?: string[];
409
411
  apiKey?: string;
@@ -415,7 +417,7 @@ type AggregatorClientParams = {
415
417
  declare class AggregatorClient {
416
418
  endpoint: string;
417
419
  signer: string;
418
- client: SuiGrpcClient;
420
+ client: SuiJsonRpcClient;
419
421
  env: Env;
420
422
  apiKey: string;
421
423
  protected pythAdapter: PythAdapter;
@@ -457,15 +459,8 @@ declare class AggregatorClient {
457
459
  fixableRouterSwapV3(params: BuildRouterSwapParamsV3): Promise<TransactionObjectArgument>;
458
460
  swapInPools(params: SwapInPoolsParams): Promise<SwapInPoolsResultV3>;
459
461
  updatePythPriceIDs(priceIDs: string[], txb: Transaction): Promise<Map<string, string>>;
460
- devInspectTransactionBlock(txb: Transaction): Promise<_mysten_sui_client.SuiClientTypes.SimulateTransactionResult<{
461
- events: true;
462
- effects: true;
463
- }>>;
464
- sendTransaction(txb: Transaction, signer: Signer): Promise<_mysten_sui_client.SuiClientTypes.TransactionResult<{
465
- effects: true;
466
- events: true;
467
- balanceChanges: true;
468
- }>>;
462
+ devInspectTransactionBlock(txb: Transaction): Promise<_mysten_sui_jsonRpc.DevInspectResults>;
463
+ sendTransaction(txb: Transaction, signer: Signer): Promise<_mysten_sui_jsonRpc.SuiTransactionBlockResponse>;
469
464
  }
470
465
 
471
466
  /**
@@ -498,7 +493,7 @@ type GetOrCreateAccountCapResult = {
498
493
  accountCap: TransactionObjectArgument;
499
494
  isCreate: boolean;
500
495
  };
501
- declare function getOrCreateAccountCap(txb: Transaction, client: SuiGrpcClient, owner: string): Promise<GetOrCreateAccountCapResult>;
496
+ declare function getOrCreateAccountCap(txb: Transaction, client: SuiJsonRpcClient, owner: string): Promise<GetOrCreateAccountCapResult>;
502
497
 
503
498
  /**
504
499
  * Represents a SUI address, which is a string.
@@ -648,67 +643,23 @@ interface Dex {
648
643
  }
649
644
 
650
645
  /**
651
- * Matches the shape of SuiClientTypes.SimulateTransactionResult with effects included.
646
+ * Matches the shape of DevInspectResults from JSON-RPC.
652
647
  * Using a local type so gas.ts can be used without importing the full SDK.
653
648
  */
654
649
  type SimulateTransactionResult = {
655
- $kind: 'Transaction' | 'FailedTransaction';
656
- Transaction?: {
657
- status: {
658
- success: true;
659
- error: null;
660
- } | {
661
- success: false;
662
- error: {
663
- message: string;
664
- };
665
- };
666
- effects?: {
667
- status: {
668
- success: true;
669
- error: null;
670
- } | {
671
- success: false;
672
- error: {
673
- message: string;
674
- };
675
- };
676
- gasUsed: {
677
- computationCost: string;
678
- storageCost: string;
679
- storageRebate: string;
680
- nonRefundableStorageFee: string;
681
- };
682
- };
683
- };
684
- FailedTransaction?: {
650
+ effects: {
685
651
  status: {
686
- success: true;
687
- error: null;
688
- } | {
689
- success: false;
690
- error: {
691
- message: string;
692
- };
652
+ status: 'success' | 'failure';
653
+ error?: string;
693
654
  };
694
- effects?: {
695
- status: {
696
- success: true;
697
- error: null;
698
- } | {
699
- success: false;
700
- error: {
701
- message: string;
702
- };
703
- };
704
- gasUsed: {
705
- computationCost: string;
706
- storageCost: string;
707
- storageRebate: string;
708
- nonRefundableStorageFee: string;
709
- };
655
+ gasUsed: {
656
+ computationCost: string;
657
+ storageCost: string;
658
+ storageRebate: string;
659
+ nonRefundableStorageFee: string;
710
660
  };
711
661
  };
662
+ error?: string | null;
712
663
  };
713
664
  interface GasMetrics {
714
665
  computationCost: string;
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import * as _mysten_sui_client from '@mysten/sui/client';
1
+ import * as _mysten_sui_jsonRpc from '@mysten/sui/jsonRpc';
2
+ import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
2
3
  import { TransactionObjectArgument, Transaction, TransactionArgument } from '@mysten/sui/transactions';
3
4
  import BN from 'bn.js';
4
5
  import Decimal from 'decimal.js';
5
- import { SuiGrpcClient } from '@mysten/sui/grpc';
6
6
  import { Signer } from '@mysten/sui/cryptography';
7
7
 
8
8
  interface FindRouterParams {
@@ -308,7 +308,7 @@ declare class PythAdapter {
308
308
  private priceTableInfo;
309
309
  private priceFeedObjectIdCache;
310
310
  private baseUpdateFee;
311
- constructor(client: SuiGrpcClient, pythStateId: ObjectId, wormholeStateId: ObjectId, hermesUrls: string[]);
311
+ constructor(client: SuiJsonRpcClient, pythStateId: ObjectId, wormholeStateId: ObjectId, hermesUrls: string[]);
312
312
  getPriceFeedsUpdateData(priceIDs: string[]): Promise<Buffer[]>;
313
313
  getBaseUpdateFee(): Promise<number>;
314
314
  getPackageId(objectId: ObjectId): Promise<string>;
@@ -365,6 +365,7 @@ type BuildRouterSwapParamsV3 = {
365
365
  slippage: number;
366
366
  txb: Transaction;
367
367
  partner?: string;
368
+ cetusDlmmPartner?: string;
368
369
  deepbookv3DeepFee?: TransactionObjectArgument;
369
370
  fixable?: boolean;
370
371
  };
@@ -373,6 +374,7 @@ type BuildFastRouterSwapParamsV3 = {
373
374
  slippage: number;
374
375
  txb: Transaction;
375
376
  partner?: string;
377
+ cetusDlmmPartner?: string;
376
378
  refreshAllCoins?: boolean;
377
379
  payDeepFeeAmount?: number;
378
380
  };
@@ -403,7 +405,7 @@ declare function getProvidersIncluding(includeProviders: string[]): string[];
403
405
  type AggregatorClientParams = {
404
406
  endpoint?: string;
405
407
  signer?: string;
406
- client?: SuiGrpcClient;
408
+ client?: SuiJsonRpcClient;
407
409
  env?: Env;
408
410
  pythUrls?: string[];
409
411
  apiKey?: string;
@@ -415,7 +417,7 @@ type AggregatorClientParams = {
415
417
  declare class AggregatorClient {
416
418
  endpoint: string;
417
419
  signer: string;
418
- client: SuiGrpcClient;
420
+ client: SuiJsonRpcClient;
419
421
  env: Env;
420
422
  apiKey: string;
421
423
  protected pythAdapter: PythAdapter;
@@ -457,15 +459,8 @@ declare class AggregatorClient {
457
459
  fixableRouterSwapV3(params: BuildRouterSwapParamsV3): Promise<TransactionObjectArgument>;
458
460
  swapInPools(params: SwapInPoolsParams): Promise<SwapInPoolsResultV3>;
459
461
  updatePythPriceIDs(priceIDs: string[], txb: Transaction): Promise<Map<string, string>>;
460
- devInspectTransactionBlock(txb: Transaction): Promise<_mysten_sui_client.SuiClientTypes.SimulateTransactionResult<{
461
- events: true;
462
- effects: true;
463
- }>>;
464
- sendTransaction(txb: Transaction, signer: Signer): Promise<_mysten_sui_client.SuiClientTypes.TransactionResult<{
465
- effects: true;
466
- events: true;
467
- balanceChanges: true;
468
- }>>;
462
+ devInspectTransactionBlock(txb: Transaction): Promise<_mysten_sui_jsonRpc.DevInspectResults>;
463
+ sendTransaction(txb: Transaction, signer: Signer): Promise<_mysten_sui_jsonRpc.SuiTransactionBlockResponse>;
469
464
  }
470
465
 
471
466
  /**
@@ -498,7 +493,7 @@ type GetOrCreateAccountCapResult = {
498
493
  accountCap: TransactionObjectArgument;
499
494
  isCreate: boolean;
500
495
  };
501
- declare function getOrCreateAccountCap(txb: Transaction, client: SuiGrpcClient, owner: string): Promise<GetOrCreateAccountCapResult>;
496
+ declare function getOrCreateAccountCap(txb: Transaction, client: SuiJsonRpcClient, owner: string): Promise<GetOrCreateAccountCapResult>;
502
497
 
503
498
  /**
504
499
  * Represents a SUI address, which is a string.
@@ -648,67 +643,23 @@ interface Dex {
648
643
  }
649
644
 
650
645
  /**
651
- * Matches the shape of SuiClientTypes.SimulateTransactionResult with effects included.
646
+ * Matches the shape of DevInspectResults from JSON-RPC.
652
647
  * Using a local type so gas.ts can be used without importing the full SDK.
653
648
  */
654
649
  type SimulateTransactionResult = {
655
- $kind: 'Transaction' | 'FailedTransaction';
656
- Transaction?: {
657
- status: {
658
- success: true;
659
- error: null;
660
- } | {
661
- success: false;
662
- error: {
663
- message: string;
664
- };
665
- };
666
- effects?: {
667
- status: {
668
- success: true;
669
- error: null;
670
- } | {
671
- success: false;
672
- error: {
673
- message: string;
674
- };
675
- };
676
- gasUsed: {
677
- computationCost: string;
678
- storageCost: string;
679
- storageRebate: string;
680
- nonRefundableStorageFee: string;
681
- };
682
- };
683
- };
684
- FailedTransaction?: {
650
+ effects: {
685
651
  status: {
686
- success: true;
687
- error: null;
688
- } | {
689
- success: false;
690
- error: {
691
- message: string;
692
- };
652
+ status: 'success' | 'failure';
653
+ error?: string;
693
654
  };
694
- effects?: {
695
- status: {
696
- success: true;
697
- error: null;
698
- } | {
699
- success: false;
700
- error: {
701
- message: string;
702
- };
703
- };
704
- gasUsed: {
705
- computationCost: string;
706
- storageCost: string;
707
- storageRebate: string;
708
- nonRefundableStorageFee: string;
709
- };
655
+ gasUsed: {
656
+ computationCost: string;
657
+ storageCost: string;
658
+ storageRebate: string;
659
+ nonRefundableStorageFee: string;
710
660
  };
711
661
  };
662
+ error?: string | null;
712
663
  };
713
664
  interface GasMetrics {
714
665
  computationCost: string;
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { coinWithBalance, Transaction } from '@mysten/sui/transactions';
2
2
  import JSONbig from 'json-bigint';
3
3
  import { normalizeSuiObjectId, SUI_CLOCK_OBJECT_ID } from '@mysten/sui/utils';
4
- import { SuiGrpcClient } from '@mysten/sui/grpc';
4
+ import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
5
5
  import { HermesClient } from '@pythnetwork/hermes-client';
6
6
  import { bcs } from '@mysten/sui/bcs';
7
7
 
@@ -37,9 +37,9 @@ var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__
37
37
  mod2
38
38
  ));
39
39
 
40
- // node_modules/bn.js/lib/bn.js
40
+ // node_modules/.pnpm/bn.js@5.2.3/node_modules/bn.js/lib/bn.js
41
41
  var require_bn = __commonJS({
42
- "node_modules/bn.js/lib/bn.js"(exports, module) {
42
+ "node_modules/.pnpm/bn.js@5.2.3/node_modules/bn.js/lib/bn.js"(exports$1, module) {
43
43
  (function(module2, exports2) {
44
44
  function assert(val, msg) {
45
45
  if (!val) throw new Error(msg || "Assertion failed");
@@ -345,7 +345,7 @@ var require_bn = __commonJS({
345
345
  };
346
346
  if (typeof Symbol !== "undefined" && typeof Symbol.for === "function") {
347
347
  try {
348
- BN7.prototype[Symbol.for("nodejs.util.inspect.custom")] = inspect;
348
+ BN7.prototype[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")] = inspect;
349
349
  } catch (e) {
350
350
  BN7.prototype.inspect = inspect;
351
351
  }
@@ -1762,6 +1762,10 @@ var require_bn = __commonJS({
1762
1762
  var mask = 67108863 ^ 67108863 >>> r << r;
1763
1763
  this.words[this.length - 1] &= mask;
1764
1764
  }
1765
+ if (this.length === 0) {
1766
+ this.words[0] = 0;
1767
+ this.length = 1;
1768
+ }
1765
1769
  return this._strip();
1766
1770
  };
1767
1771
  BN7.prototype.maskn = function maskn(bits) {
@@ -2777,7 +2781,7 @@ var require_bn = __commonJS({
2777
2781
  var res = this.imod(a._invmp(this.m).mul(this.r2));
2778
2782
  return res._forceRed(this);
2779
2783
  };
2780
- })(typeof module === "undefined" || module, exports);
2784
+ })(typeof module === "undefined" || module, exports$1);
2781
2785
  }
2782
2786
  });
2783
2787
 
@@ -3410,7 +3414,7 @@ var AGGREGATOR_V3_CONFIG = {
3410
3414
  };
3411
3415
 
3412
3416
  // src/api.ts
3413
- var SDK_VERSION = 1010500;
3417
+ var SDK_VERSION = 1010502;
3414
3418
  function parseRouterResponse(data, byAmountIn) {
3415
3419
  let packages = /* @__PURE__ */ new Map();
3416
3420
  if (data.packages) {
@@ -3846,7 +3850,7 @@ var AggregatorConfig = class {
3846
3850
  // src/math.ts
3847
3851
  var import_bn3 = __toESM(require_bn());
3848
3852
 
3849
- // node_modules/decimal.js/decimal.mjs
3853
+ // node_modules/.pnpm/decimal.js@10.6.0/node_modules/decimal.js/decimal.mjs
3850
3854
  var EXP_LIMIT = 9e15;
3851
3855
  var MAX_DIGITS = 1e9;
3852
3856
  var NUMERALS = "0123456789abcdef";
@@ -6015,7 +6019,7 @@ function tanh(x) {
6015
6019
  function trunc(x) {
6016
6020
  return finalise(x = new this(x), x.e + 1, 1);
6017
6021
  }
6018
- P[Symbol.for("nodejs.util.inspect.custom")] = P.toString;
6022
+ P[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")] = P.toString;
6019
6023
  P[Symbol.toStringTag] = "Decimal";
6020
6024
  var Decimal = P.constructor = clone(DEFAULTS);
6021
6025
  LN10 = new Decimal(LN10);
@@ -7851,11 +7855,12 @@ var PythAdapter = class {
7851
7855
  if (this.baseUpdateFee !== void 0) {
7852
7856
  return this.baseUpdateFee;
7853
7857
  }
7854
- const { object } = await this.client.getObject({
7855
- objectId: this.pythStateId,
7856
- include: { json: true }
7858
+ const res = await this.client.getObject({
7859
+ id: this.pythStateId,
7860
+ options: { showContent: true }
7857
7861
  });
7858
- const json = object.json;
7862
+ const content = res.data?.content;
7863
+ const json = content && "fields" in content ? content.fields : null;
7859
7864
  if (!json) {
7860
7865
  throw new Error("Unable to fetch pyth state object");
7861
7866
  }
@@ -7863,16 +7868,21 @@ var PythAdapter = class {
7863
7868
  return this.baseUpdateFee;
7864
7869
  }
7865
7870
  async getPackageId(objectId) {
7866
- const { object } = await this.client.getObject({
7867
- objectId,
7868
- include: { json: true }
7871
+ const res = await this.client.getObject({
7872
+ id: objectId,
7873
+ options: { showContent: true }
7869
7874
  });
7870
- const json = object.json;
7875
+ const content = res.data?.content;
7876
+ const json = content && "fields" in content ? content.fields : null;
7871
7877
  if (!json) {
7872
7878
  throw new Error(`Cannot fetch package id for object ${objectId}`);
7873
7879
  }
7874
7880
  if ("upgrade_cap" in json) {
7875
- return json.upgrade_cap.package;
7881
+ const upgradeCap = json.upgrade_cap;
7882
+ const packageId = upgradeCap?.fields?.package;
7883
+ if (typeof packageId === "string") {
7884
+ return packageId;
7885
+ }
7876
7886
  }
7877
7887
  throw new Error("upgrade_cap not found");
7878
7888
  }
@@ -7896,20 +7906,19 @@ var PythAdapter = class {
7896
7906
  const { id: tableId, fieldType } = await this.getPriceTableInfo();
7897
7907
  const feedIdBytes = Buffer.from(normalizedFeedId, "hex");
7898
7908
  try {
7899
- const PriceIdentifier = bcs.struct("PriceIdentifier", {
7900
- bytes: bcs.vector(bcs.u8())
7901
- });
7902
- const bcsBytes = PriceIdentifier.serialize({ bytes: Array.from(feedIdBytes) }).toBytes();
7903
- const result = await this.client.getDynamicField({
7909
+ const result = await this.client.getDynamicFieldObject({
7904
7910
  parentId: tableId,
7905
7911
  name: {
7906
- type: fieldType,
7907
- bcs: bcsBytes
7912
+ type: `${fieldType}::price_identifier::PriceIdentifier`,
7913
+ value: { bytes: Array.from(feedIdBytes) }
7908
7914
  }
7909
7915
  });
7910
- const valueBcs = result.dynamicField.value.bcs;
7911
- const valueBytes = valueBcs instanceof Uint8Array ? valueBcs : new Uint8Array(Object.values(valueBcs));
7912
- const objectId = "0x" + Array.from(valueBytes).map((b) => b.toString(16).padStart(2, "0")).join("");
7916
+ const content = result.data?.content;
7917
+ const json = content && "fields" in content ? content.fields : null;
7918
+ const objectId = typeof json?.value === "string" ? json.value : void 0;
7919
+ if (!objectId) {
7920
+ return void 0;
7921
+ }
7913
7922
  this.priceFeedObjectIdCache.set(normalizedFeedId, objectId);
7914
7923
  return objectId;
7915
7924
  } catch {
@@ -7920,35 +7929,22 @@ var PythAdapter = class {
7920
7929
  if (this.priceTableInfo !== void 0) {
7921
7930
  return this.priceTableInfo;
7922
7931
  }
7923
- let cursor = null;
7924
- let hasNextPage = true;
7925
- while (hasNextPage) {
7926
- const dynamicFields = await this.client.listDynamicFields({
7927
- parentId: this.pythStateId,
7928
- cursor
7929
- });
7930
- for (const field of dynamicFields.dynamicFields) {
7931
- if (field.name.type === "vector<u8>") {
7932
- const objectId = field.$kind === "DynamicObject" && field.childId ? field.childId : field.fieldId;
7933
- const fieldObj = await this.client.getObject({
7934
- objectId,
7935
- include: { json: true }
7936
- });
7937
- const type = fieldObj.object.type;
7938
- if (type.includes("table::Table")) {
7939
- const innerTypes = type.replace(/.*table::Table</, "").replace(/>$/, "");
7940
- const fieldType = innerTypes.split(",")[0].trim();
7941
- this.priceTableInfo = { id: fieldObj.object.objectId, fieldType };
7942
- return this.priceTableInfo;
7943
- }
7944
- }
7932
+ const result = await this.client.getDynamicFieldObject({
7933
+ parentId: this.pythStateId,
7934
+ name: {
7935
+ type: "vector<u8>",
7936
+ value: "price_info"
7945
7937
  }
7946
- hasNextPage = dynamicFields.hasNextPage;
7947
- cursor = dynamicFields.cursor;
7938
+ });
7939
+ if (!result.data?.type) {
7940
+ throw new Error(
7941
+ "Price Table not found, contract may not be initialized"
7942
+ );
7948
7943
  }
7949
- throw new Error(
7950
- "Price Table not found, contract may not be initialized"
7951
- );
7944
+ let type = result.data.type.replace("0x2::table::Table<", "");
7945
+ type = type.replace("::price_identifier::PriceIdentifier, 0x2::object::ID>", "");
7946
+ this.priceTableInfo = { id: result.data.objectId, fieldType: type };
7947
+ return this.priceTableInfo;
7952
7948
  }
7953
7949
  extractVaaBytesFromAccumulatorMessage(accumulatorMessage) {
7954
7950
  const trailingPayloadSize = accumulatorMessage.readUint8(6);
@@ -8132,21 +8128,21 @@ async function getOrCreateAccountCap(txb, client, owner) {
8132
8128
  }
8133
8129
  async function getAccountCap(client, owner) {
8134
8130
  const limit = 50;
8135
- let cursor = null;
8131
+ let cursor = void 0;
8136
8132
  while (true) {
8137
- const ownedObjects = await client.listOwnedObjects({
8133
+ const ownedObjects = await client.getOwnedObjects({
8138
8134
  owner,
8139
8135
  cursor,
8140
8136
  limit,
8141
- type: `${DEEPBOOK_PACKAGE_ID}::${DEEPBOOK_CUSTODIAN_V2_MODULE}::AccountCap`
8137
+ filter: { StructType: `${DEEPBOOK_PACKAGE_ID}::${DEEPBOOK_CUSTODIAN_V2_MODULE}::AccountCap` }
8142
8138
  });
8143
- if (ownedObjects.objects.length !== 0) {
8144
- return ownedObjects.objects[0].objectId;
8139
+ if (ownedObjects.data.length !== 0) {
8140
+ return ownedObjects.data[0].data?.objectId ?? null;
8145
8141
  }
8146
8142
  if (!ownedObjects.hasNextPage) {
8147
8143
  break;
8148
8144
  }
8149
- cursor = ownedObjects.cursor;
8145
+ cursor = ownedObjects.nextCursor ?? void 0;
8150
8146
  }
8151
8147
  return null;
8152
8148
  }
@@ -8174,10 +8170,10 @@ function getAggregatorV2Extend2PublishedAt(publishedAt, packages) {
8174
8170
  // src/utils/gas.ts
8175
8171
  var import_bn4 = __toESM(require_bn());
8176
8172
  function extractGasMetrics(result) {
8177
- const txResult = result.Transaction ?? result.FailedTransaction;
8178
- const effects = txResult?.effects;
8179
- if (!effects || !effects.status.success) {
8180
- const errorMsg = effects?.status.success === false ? effects.status.error.message : "Unknown error";
8173
+ const effects = result.effects;
8174
+ const isSuccess = !result.error && effects.status.status === "success";
8175
+ if (!isSuccess) {
8176
+ const errorMsg = result.error ?? effects.status.error ?? "Unknown error";
8181
8177
  return {
8182
8178
  computationCost: "0",
8183
8179
  storageCost: "0",
@@ -8840,8 +8836,8 @@ var _AggregatorClient = class _AggregatorClient {
8840
8836
  constructor(params) {
8841
8837
  this.endpoint = params.endpoint ? processEndpoint(params.endpoint) : DEFAULT_ENDPOINT;
8842
8838
  const network = params.env === 1 /* Testnet */ ? "testnet" : "mainnet";
8843
- const grpcUrl = params.env === 1 /* Testnet */ ? "https://fullnode.testnet.sui.io:443" : "https://fullnode.mainnet.sui.io:443";
8844
- this.client = params.client ?? new SuiGrpcClient({ network, baseUrl: grpcUrl });
8839
+ const rpcUrl = params.env === 1 /* Testnet */ ? "https://fullnode.testnet.sui.io:443" : "https://fullnode.mainnet.sui.io:443";
8840
+ this.client = params.client ?? new SuiJsonRpcClient({ network, url: rpcUrl });
8845
8841
  this.signer = params.signer || "";
8846
8842
  this.env = params.env || 0 /* Mainnet */;
8847
8843
  const config2 = _AggregatorClient.CONFIG[this.env];
@@ -8882,13 +8878,13 @@ var _AggregatorClient = class _AggregatorClient {
8882
8878
  }
8883
8879
  async getOneCoinUsedToMerge(coinType) {
8884
8880
  try {
8885
- const gotCoin = await this.client.listCoins({
8881
+ const gotCoin = await this.client.getCoins({
8886
8882
  owner: this.signer,
8887
8883
  coinType,
8888
8884
  limit: 1
8889
8885
  });
8890
- if (gotCoin.objects.length === 1) {
8891
- return gotCoin.objects[0].objectId;
8886
+ if (gotCoin.data.length === 1) {
8887
+ return gotCoin.data[0].coinObjectId;
8892
8888
  }
8893
8889
  return null;
8894
8890
  } catch (error) {
@@ -9302,7 +9298,7 @@ var _AggregatorClient = class _AggregatorClient {
9302
9298
  return outputCoin;
9303
9299
  }
9304
9300
  async routerSwap(params) {
9305
- const { router, inputCoin, slippage, txb, partner } = params;
9301
+ const { router, inputCoin, slippage, txb, partner, cetusDlmmPartner } = params;
9306
9302
  if (slippage > 1 || slippage < 0) {
9307
9303
  throw new Error(CLIENT_CONFIG.ERRORS.INVALID_SLIPPAGE);
9308
9304
  }
@@ -9336,7 +9332,8 @@ var _AggregatorClient = class _AggregatorClient {
9336
9332
  amountOut.toString(),
9337
9333
  amountLimit.toString(),
9338
9334
  priceInfoObjectIds,
9339
- partner ?? this.partner
9335
+ partner ?? this.partner,
9336
+ cetusDlmmPartner ?? this.cetusDlmmPartner
9340
9337
  );
9341
9338
  } else {
9342
9339
  return this.expectOutputSwapV3(
@@ -9359,7 +9356,15 @@ var _AggregatorClient = class _AggregatorClient {
9359
9356
  * @throws Error if input coin amount exceeds maxAmountIn
9360
9357
  */
9361
9358
  async routerSwapWithMaxAmountIn(params) {
9362
- const { router, inputCoin, slippage, txb, partner, maxAmountIn } = params;
9359
+ const {
9360
+ router,
9361
+ inputCoin,
9362
+ slippage,
9363
+ txb,
9364
+ partner,
9365
+ cetusDlmmPartner,
9366
+ maxAmountIn
9367
+ } = params;
9363
9368
  if (slippage > 1 || slippage < 0) {
9364
9369
  throw new Error(CLIENT_CONFIG.ERRORS.INVALID_SLIPPAGE);
9365
9370
  }
@@ -9394,7 +9399,8 @@ var _AggregatorClient = class _AggregatorClient {
9394
9399
  amountOut.toString(),
9395
9400
  amountLimit.toString(),
9396
9401
  priceInfoObjectIds,
9397
- partner ?? this.partner
9402
+ partner ?? this.partner,
9403
+ cetusDlmmPartner ?? this.cetusDlmmPartner
9398
9404
  );
9399
9405
  } else {
9400
9406
  return this.expectOutputSwapV3WithMaxAmountIn(
@@ -9411,7 +9417,14 @@ var _AggregatorClient = class _AggregatorClient {
9411
9417
  // auto build input coin
9412
9418
  // auto merge, transfer or destory target coin.
9413
9419
  async fastRouterSwap(params) {
9414
- const { router, slippage, txb, partner, payDeepFeeAmount } = params;
9420
+ const {
9421
+ router,
9422
+ slippage,
9423
+ txb,
9424
+ partner,
9425
+ cetusDlmmPartner,
9426
+ payDeepFeeAmount
9427
+ } = params;
9415
9428
  const fromCoinType = router.paths[0].from;
9416
9429
  const targetCoinType = router.paths[router.paths.length - 1].target;
9417
9430
  const byAmountIn = router.byAmountIn;
@@ -9452,6 +9465,7 @@ var _AggregatorClient = class _AggregatorClient {
9452
9465
  slippage,
9453
9466
  txb,
9454
9467
  partner: partner ?? this.partner,
9468
+ cetusDlmmPartner: cetusDlmmPartner ?? this.cetusDlmmPartner,
9455
9469
  deepbookv3DeepFee: deepCoin
9456
9470
  };
9457
9471
  const targetCoin = await this.routerSwap(routerSwapParams);
@@ -9567,7 +9581,7 @@ var _AggregatorClient = class _AggregatorClient {
9567
9581
  }
9568
9582
  }
9569
9583
  async fixableRouterSwapV3(params) {
9570
- const { router, inputCoin, slippage, txb, partner } = params;
9584
+ const { router, inputCoin, slippage, txb, partner, cetusDlmmPartner } = params;
9571
9585
  checkOverlayFeeConfig(this.overlayFeeRate, this.overlayFeeReceiver);
9572
9586
  let overlayFee = 0;
9573
9587
  if (router.byAmountIn) {
@@ -9596,7 +9610,8 @@ var _AggregatorClient = class _AggregatorClient {
9596
9610
  expectedAmountOut.toString(),
9597
9611
  amountLimit.toString(),
9598
9612
  priceInfoObjectIds,
9599
- partner ?? this.partner
9613
+ partner ?? this.partner,
9614
+ cetusDlmmPartner ?? this.cetusDlmmPartner
9600
9615
  );
9601
9616
  } else {
9602
9617
  return this.expectOutputSwapV3(
@@ -9633,18 +9648,16 @@ var _AggregatorClient = class _AggregatorClient {
9633
9648
  });
9634
9649
  }
9635
9650
  tx.setSenderIfNotSet(this.signer || "0x0");
9636
- const simulateRes = await this.client.simulateTransaction({
9637
- transaction: tx,
9638
- include: { events: true, effects: true }
9651
+ const simulateRes = await this.client.devInspectTransactionBlock({
9652
+ sender: this.signer || "0x0",
9653
+ transactionBlock: tx
9639
9654
  });
9640
- const txResult = simulateRes.Transaction ?? simulateRes.FailedTransaction;
9641
- if (!txResult || simulateRes.$kind === "FailedTransaction") {
9642
- const errorMsg = txResult?.status.success === false ? txResult.status.error.message : "Unknown error";
9643
- throw new Error("Simulation error: " + errorMsg);
9655
+ if (simulateRes.error) {
9656
+ throw new Error("Simulation error: " + simulateRes.error);
9644
9657
  }
9645
- const events = txResult.events ?? [];
9658
+ const events = simulateRes.events ?? [];
9646
9659
  const valueData = events.filter((item) => {
9647
- return item.eventType.includes("CalculatedSwapResultEvent");
9660
+ return item.type.includes("CalculatedSwapResultEvent");
9648
9661
  });
9649
9662
  if (valueData.length === 0 || valueData.length !== pools.length) {
9650
9663
  throw new Error("Simulate event result error");
@@ -9652,7 +9665,7 @@ var _AggregatorClient = class _AggregatorClient {
9652
9665
  let tempMaxAmount = byAmountIn ? new import_bn6.default(0) : new import_bn6.default(U64_MAX);
9653
9666
  let tempIndex = 0;
9654
9667
  for (let i = 0; i < valueData.length; i += 1) {
9655
- const eventJson2 = valueData[i].json;
9668
+ const eventJson2 = valueData[i].parsedJson;
9656
9669
  if (eventJson2?.data?.is_exceed) {
9657
9670
  continue;
9658
9671
  }
@@ -9670,11 +9683,11 @@ var _AggregatorClient = class _AggregatorClient {
9670
9683
  }
9671
9684
  }
9672
9685
  }
9673
- const eventJson = valueData[tempIndex].json;
9686
+ const eventJson = valueData[tempIndex].parsedJson;
9674
9687
  const eventData = eventJson?.data;
9675
9688
  const [decimalA, decimalB] = await Promise.all([
9676
- this.client.getCoinMetadata({ coinType: coinA }).then((res) => res.coinMetadata?.decimals ?? null),
9677
- this.client.getCoinMetadata({ coinType: coinB }).then((res) => res.coinMetadata?.decimals ?? null)
9689
+ this.client.getCoinMetadata({ coinType: coinA }).then((res) => res?.decimals ?? null),
9690
+ this.client.getCoinMetadata({ coinType: coinB }).then((res) => res?.decimals ?? null)
9678
9691
  ]);
9679
9692
  if (decimalA == null || decimalB == null) {
9680
9693
  throw new Error("Cannot get coin decimals");
@@ -9743,9 +9756,9 @@ var _AggregatorClient = class _AggregatorClient {
9743
9756
  }
9744
9757
  async devInspectTransactionBlock(txb) {
9745
9758
  txb.setSenderIfNotSet(this.signer || "0x0");
9746
- const res = await this.client.simulateTransaction({
9747
- transaction: txb,
9748
- include: { events: true, effects: true }
9759
+ const res = await this.client.devInspectTransactionBlock({
9760
+ sender: this.signer || "0x0",
9761
+ transactionBlock: txb
9749
9762
  });
9750
9763
  return res;
9751
9764
  }
@@ -9753,7 +9766,7 @@ var _AggregatorClient = class _AggregatorClient {
9753
9766
  const res = await this.client.signAndExecuteTransaction({
9754
9767
  transaction: txb,
9755
9768
  signer,
9756
- include: { effects: true, events: true, balanceChanges: true }
9769
+ options: { showEffects: true, showEvents: true, showBalanceChanges: true }
9757
9770
  });
9758
9771
  return res;
9759
9772
  }
package/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "@cetusprotocol/aggregator-sdk",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "module": "dist/index.js",
9
- "author": "Cetus",
10
9
  "scripts": {
11
10
  "build": "tsup --format cjs,esm --dts",
12
11
  "dev": "tsup --watch",