@cetusprotocol/aggregator-sdk 1.5.4 → 1.5.5

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.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import * as _mysten_sui_jsonRpc from '@mysten/sui/jsonRpc';
2
- import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
1
+ import * as _mysten_sui_client from '@mysten/sui/client';
3
2
  import { TransactionObjectArgument, Transaction, TransactionArgument } from '@mysten/sui/transactions';
4
3
  import BN from 'bn.js';
5
4
  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 {
@@ -309,7 +309,7 @@ declare class PythAdapter {
309
309
  private priceTableInfo;
310
310
  private priceFeedObjectIdCache;
311
311
  private baseUpdateFee;
312
- constructor(client: SuiJsonRpcClient, pythStateId: ObjectId, wormholeStateId: ObjectId, hermesUrls: string[]);
312
+ constructor(client: SuiGrpcClient, pythStateId: ObjectId, wormholeStateId: ObjectId, hermesUrls: string[]);
313
313
  getPriceFeedsUpdateData(priceIDs: string[]): Promise<Buffer[]>;
314
314
  getBaseUpdateFee(): Promise<number>;
315
315
  getPackageId(objectId: ObjectId): Promise<string>;
@@ -407,7 +407,7 @@ declare function getProvidersIncluding(includeProviders: string[]): string[];
407
407
  type AggregatorClientParams = {
408
408
  endpoint?: string;
409
409
  signer?: string;
410
- client?: SuiJsonRpcClient;
410
+ client?: SuiGrpcClient;
411
411
  env?: Env;
412
412
  pythUrls?: string[];
413
413
  apiKey?: string;
@@ -419,7 +419,7 @@ type AggregatorClientParams = {
419
419
  declare class AggregatorClient {
420
420
  endpoint: string;
421
421
  signer: string;
422
- client: SuiJsonRpcClient;
422
+ client: SuiGrpcClient;
423
423
  env: Env;
424
424
  apiKey: string;
425
425
  protected pythAdapter: PythAdapter;
@@ -461,8 +461,15 @@ declare class AggregatorClient {
461
461
  fixableRouterSwapV3(params: BuildRouterSwapParamsV3): Promise<TransactionObjectArgument>;
462
462
  swapInPools(params: SwapInPoolsParams): Promise<SwapInPoolsResultV3>;
463
463
  updatePythPriceIDs(priceIDs: string[], txb: Transaction): Promise<Map<string, string>>;
464
- devInspectTransactionBlock(txb: Transaction): Promise<_mysten_sui_jsonRpc.DevInspectResults>;
465
- sendTransaction(txb: Transaction, signer: Signer): Promise<_mysten_sui_jsonRpc.SuiTransactionBlockResponse>;
464
+ devInspectTransactionBlock(txb: Transaction): Promise<_mysten_sui_client.SuiClientTypes.SimulateTransactionResult<{
465
+ events: true;
466
+ effects: true;
467
+ }>>;
468
+ sendTransaction(txb: Transaction, signer: Signer): Promise<_mysten_sui_client.SuiClientTypes.TransactionResult<{
469
+ effects: true;
470
+ events: true;
471
+ balanceChanges: true;
472
+ }>>;
466
473
  }
467
474
 
468
475
  /**
@@ -495,7 +502,7 @@ type GetOrCreateAccountCapResult = {
495
502
  accountCap: TransactionObjectArgument;
496
503
  isCreate: boolean;
497
504
  };
498
- declare function getOrCreateAccountCap(txb: Transaction, client: SuiJsonRpcClient, owner: string): Promise<GetOrCreateAccountCapResult>;
505
+ declare function getOrCreateAccountCap(txb: Transaction, client: SuiGrpcClient, owner: string): Promise<GetOrCreateAccountCapResult>;
499
506
 
500
507
  /**
501
508
  * Represents a SUI address, which is a string.
@@ -645,23 +652,67 @@ interface Dex {
645
652
  }
646
653
 
647
654
  /**
648
- * Matches the shape of DevInspectResults from JSON-RPC.
655
+ * Matches the shape of SuiClientTypes.SimulateTransactionResult with effects included.
649
656
  * Using a local type so gas.ts can be used without importing the full SDK.
650
657
  */
651
658
  type SimulateTransactionResult = {
652
- effects: {
659
+ $kind: 'Transaction' | 'FailedTransaction';
660
+ Transaction?: {
653
661
  status: {
654
- status: 'success' | 'failure';
655
- error?: string;
662
+ success: true;
663
+ error: null;
664
+ } | {
665
+ success: false;
666
+ error: {
667
+ message: string;
668
+ };
656
669
  };
657
- gasUsed: {
658
- computationCost: string;
659
- storageCost: string;
660
- storageRebate: string;
661
- nonRefundableStorageFee: string;
670
+ effects?: {
671
+ status: {
672
+ success: true;
673
+ error: null;
674
+ } | {
675
+ success: false;
676
+ error: {
677
+ message: string;
678
+ };
679
+ };
680
+ gasUsed: {
681
+ computationCost: string;
682
+ storageCost: string;
683
+ storageRebate: string;
684
+ nonRefundableStorageFee: string;
685
+ };
686
+ };
687
+ };
688
+ FailedTransaction?: {
689
+ status: {
690
+ success: true;
691
+ error: null;
692
+ } | {
693
+ success: false;
694
+ error: {
695
+ message: string;
696
+ };
697
+ };
698
+ effects?: {
699
+ status: {
700
+ success: true;
701
+ error: null;
702
+ } | {
703
+ success: false;
704
+ error: {
705
+ message: string;
706
+ };
707
+ };
708
+ gasUsed: {
709
+ computationCost: string;
710
+ storageCost: string;
711
+ storageRebate: string;
712
+ nonRefundableStorageFee: string;
713
+ };
662
714
  };
663
715
  };
664
- error?: string | null;
665
716
  };
666
717
  interface GasMetrics {
667
718
  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 { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
4
+ import { SuiGrpcClient } from '@mysten/sui/grpc';
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/.pnpm/bn.js@5.2.3/node_modules/bn.js/lib/bn.js
40
+ // node_modules/bn.js/lib/bn.js
41
41
  var require_bn = __commonJS({
42
- "node_modules/.pnpm/bn.js@5.2.3/node_modules/bn.js/lib/bn.js"(exports$1, module) {
42
+ "node_modules/bn.js/lib/bn.js"(exports, 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[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")] = inspect;
348
+ BN7.prototype[Symbol.for("nodejs.util.inspect.custom")] = inspect;
349
349
  } catch (e) {
350
350
  BN7.prototype.inspect = inspect;
351
351
  }
@@ -1762,10 +1762,6 @@ 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
- }
1769
1765
  return this._strip();
1770
1766
  };
1771
1767
  BN7.prototype.maskn = function maskn(bits) {
@@ -2781,7 +2777,7 @@ var require_bn = __commonJS({
2781
2777
  var res = this.imod(a._invmp(this.m).mul(this.r2));
2782
2778
  return res._forceRed(this);
2783
2779
  };
2784
- })(typeof module === "undefined" || module, exports$1);
2780
+ })(typeof module === "undefined" || module, exports);
2785
2781
  }
2786
2782
  });
2787
2783
 
@@ -3414,7 +3410,7 @@ var AGGREGATOR_V3_CONFIG = {
3414
3410
  };
3415
3411
 
3416
3412
  // src/api.ts
3417
- var SDK_VERSION = 1010504;
3413
+ var SDK_VERSION = 1010505;
3418
3414
  function parseRouterResponse(data, byAmountIn) {
3419
3415
  let packages = /* @__PURE__ */ new Map();
3420
3416
  if (data.packages) {
@@ -3850,7 +3846,7 @@ var AggregatorConfig = class {
3850
3846
  // src/math.ts
3851
3847
  var import_bn3 = __toESM(require_bn());
3852
3848
 
3853
- // node_modules/.pnpm/decimal.js@10.6.0/node_modules/decimal.js/decimal.mjs
3849
+ // node_modules/decimal.js/decimal.mjs
3854
3850
  var EXP_LIMIT = 9e15;
3855
3851
  var MAX_DIGITS = 1e9;
3856
3852
  var NUMERALS = "0123456789abcdef";
@@ -6019,7 +6015,7 @@ function tanh(x) {
6019
6015
  function trunc(x) {
6020
6016
  return finalise(x = new this(x), x.e + 1, 1);
6021
6017
  }
6022
- P[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")] = P.toString;
6018
+ P[Symbol.for("nodejs.util.inspect.custom")] = P.toString;
6023
6019
  P[Symbol.toStringTag] = "Decimal";
6024
6020
  var Decimal = P.constructor = clone(DEFAULTS);
6025
6021
  LN10 = new Decimal(LN10);
@@ -7855,12 +7851,11 @@ var PythAdapter = class {
7855
7851
  if (this.baseUpdateFee !== void 0) {
7856
7852
  return this.baseUpdateFee;
7857
7853
  }
7858
- const res = await this.client.getObject({
7859
- id: this.pythStateId,
7860
- options: { showContent: true }
7854
+ const { object } = await this.client.getObject({
7855
+ objectId: this.pythStateId,
7856
+ include: { json: true }
7861
7857
  });
7862
- const content = res.data?.content;
7863
- const json = content && "fields" in content ? content.fields : null;
7858
+ const json = object.json;
7864
7859
  if (!json) {
7865
7860
  throw new Error("Unable to fetch pyth state object");
7866
7861
  }
@@ -7868,21 +7863,16 @@ var PythAdapter = class {
7868
7863
  return this.baseUpdateFee;
7869
7864
  }
7870
7865
  async getPackageId(objectId) {
7871
- const res = await this.client.getObject({
7872
- id: objectId,
7873
- options: { showContent: true }
7866
+ const { object } = await this.client.getObject({
7867
+ objectId,
7868
+ include: { json: true }
7874
7869
  });
7875
- const content = res.data?.content;
7876
- const json = content && "fields" in content ? content.fields : null;
7870
+ const json = object.json;
7877
7871
  if (!json) {
7878
7872
  throw new Error(`Cannot fetch package id for object ${objectId}`);
7879
7873
  }
7880
7874
  if ("upgrade_cap" in json) {
7881
- const upgradeCap = json.upgrade_cap;
7882
- const packageId = upgradeCap?.fields?.package;
7883
- if (typeof packageId === "string") {
7884
- return packageId;
7885
- }
7875
+ return json.upgrade_cap.package;
7886
7876
  }
7887
7877
  throw new Error("upgrade_cap not found");
7888
7878
  }
@@ -7906,19 +7896,20 @@ var PythAdapter = class {
7906
7896
  const { id: tableId, fieldType } = await this.getPriceTableInfo();
7907
7897
  const feedIdBytes = Buffer.from(normalizedFeedId, "hex");
7908
7898
  try {
7909
- const result = await this.client.getDynamicFieldObject({
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({
7910
7904
  parentId: tableId,
7911
7905
  name: {
7912
- type: `${fieldType}::price_identifier::PriceIdentifier`,
7913
- value: { bytes: Array.from(feedIdBytes) }
7906
+ type: fieldType,
7907
+ bcs: bcsBytes
7914
7908
  }
7915
7909
  });
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
- }
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("");
7922
7913
  this.priceFeedObjectIdCache.set(normalizedFeedId, objectId);
7923
7914
  return objectId;
7924
7915
  } catch {
@@ -7929,27 +7920,40 @@ var PythAdapter = class {
7929
7920
  if (this.priceTableInfo !== void 0) {
7930
7921
  return this.priceTableInfo;
7931
7922
  }
7932
- const result = await this.client.getDynamicFieldObject({
7933
- parentId: this.pythStateId,
7934
- name: {
7935
- type: "vector<u8>",
7936
- value: "price_info"
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
+ }
7937
7945
  }
7938
- });
7939
- if (!result.data?.type) {
7940
- throw new Error(
7941
- "Price Table not found, contract may not be initialized"
7942
- );
7946
+ hasNextPage = dynamicFields.hasNextPage;
7947
+ cursor = dynamicFields.cursor;
7943
7948
  }
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;
7949
+ throw new Error(
7950
+ "Price Table not found, contract may not be initialized"
7951
+ );
7948
7952
  }
7949
7953
  extractVaaBytesFromAccumulatorMessage(accumulatorMessage) {
7950
- const trailingPayloadSize = accumulatorMessage.readUint8(6);
7954
+ const trailingPayloadSize = accumulatorMessage.readUInt8(6);
7951
7955
  const vaaSizeOffset = 7 + trailingPayloadSize + 1;
7952
- const vaaSize = accumulatorMessage.readUint16BE(vaaSizeOffset);
7956
+ const vaaSize = accumulatorMessage.readUInt16BE(vaaSizeOffset);
7953
7957
  const vaaOffset = vaaSizeOffset + 2;
7954
7958
  return accumulatorMessage.subarray(vaaOffset, vaaOffset + vaaSize);
7955
7959
  }
@@ -8128,21 +8132,21 @@ async function getOrCreateAccountCap(txb, client, owner) {
8128
8132
  }
8129
8133
  async function getAccountCap(client, owner) {
8130
8134
  const limit = 50;
8131
- let cursor = void 0;
8135
+ let cursor = null;
8132
8136
  while (true) {
8133
- const ownedObjects = await client.getOwnedObjects({
8137
+ const ownedObjects = await client.listOwnedObjects({
8134
8138
  owner,
8135
8139
  cursor,
8136
8140
  limit,
8137
- filter: { StructType: `${DEEPBOOK_PACKAGE_ID}::${DEEPBOOK_CUSTODIAN_V2_MODULE}::AccountCap` }
8141
+ type: `${DEEPBOOK_PACKAGE_ID}::${DEEPBOOK_CUSTODIAN_V2_MODULE}::AccountCap`
8138
8142
  });
8139
- if (ownedObjects.data.length !== 0) {
8140
- return ownedObjects.data[0].data?.objectId ?? null;
8143
+ if (ownedObjects.objects.length !== 0) {
8144
+ return ownedObjects.objects[0].objectId;
8141
8145
  }
8142
8146
  if (!ownedObjects.hasNextPage) {
8143
8147
  break;
8144
8148
  }
8145
- cursor = ownedObjects.nextCursor ?? void 0;
8149
+ cursor = ownedObjects.cursor;
8146
8150
  }
8147
8151
  return null;
8148
8152
  }
@@ -8170,10 +8174,10 @@ function getAggregatorV2Extend2PublishedAt(publishedAt, packages) {
8170
8174
  // src/utils/gas.ts
8171
8175
  var import_bn4 = __toESM(require_bn());
8172
8176
  function extractGasMetrics(result) {
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";
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";
8177
8181
  return {
8178
8182
  computationCost: "0",
8179
8183
  storageCost: "0",
@@ -8891,8 +8895,8 @@ var _AggregatorClient = class _AggregatorClient {
8891
8895
  constructor(params) {
8892
8896
  this.endpoint = params.endpoint ? processEndpoint(params.endpoint) : DEFAULT_ENDPOINT;
8893
8897
  const network = params.env === 1 /* Testnet */ ? "testnet" : "mainnet";
8894
- const rpcUrl = params.env === 1 /* Testnet */ ? "https://fullnode.testnet.sui.io:443" : "https://fullnode.mainnet.sui.io:443";
8895
- this.client = params.client ?? new SuiJsonRpcClient({ network, url: rpcUrl });
8898
+ const grpcUrl = params.env === 1 /* Testnet */ ? "https://fullnode.testnet.sui.io:443" : "https://fullnode.mainnet.sui.io:443";
8899
+ this.client = params.client ?? new SuiGrpcClient({ network, baseUrl: grpcUrl });
8896
8900
  this.signer = params.signer || "";
8897
8901
  this.env = params.env || 0 /* Mainnet */;
8898
8902
  const config2 = _AggregatorClient.CONFIG[this.env];
@@ -8933,13 +8937,13 @@ var _AggregatorClient = class _AggregatorClient {
8933
8937
  }
8934
8938
  async getOneCoinUsedToMerge(coinType) {
8935
8939
  try {
8936
- const gotCoin = await this.client.getCoins({
8940
+ const gotCoin = await this.client.listCoins({
8937
8941
  owner: this.signer,
8938
8942
  coinType,
8939
8943
  limit: 1
8940
8944
  });
8941
- if (gotCoin.data.length === 1) {
8942
- return gotCoin.data[0].coinObjectId;
8945
+ if (gotCoin.objects.length === 1) {
8946
+ return gotCoin.objects[0].objectId;
8943
8947
  }
8944
8948
  return null;
8945
8949
  } catch (error) {
@@ -9413,15 +9417,7 @@ var _AggregatorClient = class _AggregatorClient {
9413
9417
  * @throws Error if input coin amount exceeds maxAmountIn
9414
9418
  */
9415
9419
  async routerSwapWithMaxAmountIn(params) {
9416
- const {
9417
- router,
9418
- inputCoin,
9419
- slippage,
9420
- txb,
9421
- partner,
9422
- cetusDlmmPartner,
9423
- maxAmountIn
9424
- } = params;
9420
+ const { router, inputCoin, slippage, txb, partner, maxAmountIn } = params;
9425
9421
  if (slippage > 1 || slippage < 0) {
9426
9422
  throw new Error(CLIENT_CONFIG.ERRORS.INVALID_SLIPPAGE);
9427
9423
  }
@@ -9456,8 +9452,7 @@ var _AggregatorClient = class _AggregatorClient {
9456
9452
  amountOut.toString(),
9457
9453
  amountLimit.toString(),
9458
9454
  priceInfoObjectIds,
9459
- partner ?? this.partner,
9460
- cetusDlmmPartner ?? this.cetusDlmmPartner
9455
+ partner ?? this.partner
9461
9456
  );
9462
9457
  } else {
9463
9458
  return this.expectOutputSwapV3WithMaxAmountIn(
@@ -9474,14 +9469,7 @@ var _AggregatorClient = class _AggregatorClient {
9474
9469
  // auto build input coin
9475
9470
  // auto merge, transfer or destory target coin.
9476
9471
  async fastRouterSwap(params) {
9477
- const {
9478
- router,
9479
- slippage,
9480
- txb,
9481
- partner,
9482
- cetusDlmmPartner,
9483
- payDeepFeeAmount
9484
- } = params;
9472
+ const { router, slippage, txb, partner, cetusDlmmPartner, payDeepFeeAmount } = params;
9485
9473
  const fromCoinType = router.paths[0].from;
9486
9474
  const targetCoinType = router.paths[router.paths.length - 1].target;
9487
9475
  const byAmountIn = router.byAmountIn;
@@ -9638,7 +9626,7 @@ var _AggregatorClient = class _AggregatorClient {
9638
9626
  }
9639
9627
  }
9640
9628
  async fixableRouterSwapV3(params) {
9641
- const { router, inputCoin, slippage, txb, partner, cetusDlmmPartner } = params;
9629
+ const { router, inputCoin, slippage, txb, partner } = params;
9642
9630
  checkOverlayFeeConfig(this.overlayFeeRate, this.overlayFeeReceiver);
9643
9631
  let overlayFee = 0;
9644
9632
  if (router.byAmountIn) {
@@ -9667,8 +9655,7 @@ var _AggregatorClient = class _AggregatorClient {
9667
9655
  expectedAmountOut.toString(),
9668
9656
  amountLimit.toString(),
9669
9657
  priceInfoObjectIds,
9670
- partner ?? this.partner,
9671
- cetusDlmmPartner ?? this.cetusDlmmPartner
9658
+ partner ?? this.partner
9672
9659
  );
9673
9660
  } else {
9674
9661
  return this.expectOutputSwapV3(
@@ -9705,16 +9692,18 @@ var _AggregatorClient = class _AggregatorClient {
9705
9692
  });
9706
9693
  }
9707
9694
  tx.setSenderIfNotSet(this.signer || "0x0");
9708
- const simulateRes = await this.client.devInspectTransactionBlock({
9709
- sender: this.signer || "0x0",
9710
- transactionBlock: tx
9695
+ const simulateRes = await this.client.simulateTransaction({
9696
+ transaction: tx,
9697
+ include: { events: true, effects: true }
9711
9698
  });
9712
- if (simulateRes.error) {
9713
- throw new Error("Simulation error: " + simulateRes.error);
9699
+ const txResult = simulateRes.Transaction ?? simulateRes.FailedTransaction;
9700
+ if (!txResult || simulateRes.$kind === "FailedTransaction") {
9701
+ const errorMsg = txResult?.status.success === false ? txResult.status.error.message : "Unknown error";
9702
+ throw new Error("Simulation error: " + errorMsg);
9714
9703
  }
9715
- const events = simulateRes.events ?? [];
9704
+ const events = txResult.events ?? [];
9716
9705
  const valueData = events.filter((item) => {
9717
- return item.type.includes("CalculatedSwapResultEvent");
9706
+ return item.eventType.includes("CalculatedSwapResultEvent");
9718
9707
  });
9719
9708
  if (valueData.length === 0 || valueData.length !== pools.length) {
9720
9709
  throw new Error("Simulate event result error");
@@ -9722,7 +9711,7 @@ var _AggregatorClient = class _AggregatorClient {
9722
9711
  let tempMaxAmount = byAmountIn ? new import_bn6.default(0) : new import_bn6.default(U64_MAX);
9723
9712
  let tempIndex = 0;
9724
9713
  for (let i = 0; i < valueData.length; i += 1) {
9725
- const eventJson2 = valueData[i].parsedJson;
9714
+ const eventJson2 = valueData[i].json;
9726
9715
  if (eventJson2?.data?.is_exceed) {
9727
9716
  continue;
9728
9717
  }
@@ -9740,11 +9729,11 @@ var _AggregatorClient = class _AggregatorClient {
9740
9729
  }
9741
9730
  }
9742
9731
  }
9743
- const eventJson = valueData[tempIndex].parsedJson;
9732
+ const eventJson = valueData[tempIndex].json;
9744
9733
  const eventData = eventJson?.data;
9745
9734
  const [decimalA, decimalB] = await Promise.all([
9746
- this.client.getCoinMetadata({ coinType: coinA }).then((res) => res?.decimals ?? null),
9747
- this.client.getCoinMetadata({ coinType: coinB }).then((res) => res?.decimals ?? null)
9735
+ this.client.getCoinMetadata({ coinType: coinA }).then((res) => res.coinMetadata?.decimals ?? null),
9736
+ this.client.getCoinMetadata({ coinType: coinB }).then((res) => res.coinMetadata?.decimals ?? null)
9748
9737
  ]);
9749
9738
  if (decimalA == null || decimalB == null) {
9750
9739
  throw new Error("Cannot get coin decimals");
@@ -9813,9 +9802,9 @@ var _AggregatorClient = class _AggregatorClient {
9813
9802
  }
9814
9803
  async devInspectTransactionBlock(txb) {
9815
9804
  txb.setSenderIfNotSet(this.signer || "0x0");
9816
- const res = await this.client.devInspectTransactionBlock({
9817
- sender: this.signer || "0x0",
9818
- transactionBlock: txb
9805
+ const res = await this.client.simulateTransaction({
9806
+ transaction: txb,
9807
+ include: { events: true, effects: true }
9819
9808
  });
9820
9809
  return res;
9821
9810
  }
@@ -9823,7 +9812,7 @@ var _AggregatorClient = class _AggregatorClient {
9823
9812
  const res = await this.client.signAndExecuteTransaction({
9824
9813
  transaction: txb,
9825
9814
  signer,
9826
- options: { showEffects: true, showEvents: true, showBalanceChanges: true }
9815
+ include: { effects: true, events: true, balanceChanges: true }
9827
9816
  });
9828
9817
  return res;
9829
9818
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cetusprotocol/aggregator-sdk",
3
- "version": "1.5.4",
3
+ "version": "1.5.5",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "main": "dist/index.js",
@@ -22,7 +22,7 @@
22
22
  "typescript": "^5.0.0"
23
23
  },
24
24
  "dependencies": {
25
- "@mysten/sui": "^2.6.0",
25
+ "@mysten/sui": "^2.16.3",
26
26
  "@pythnetwork/hermes-client": "^3.1.0",
27
27
  "bip39": "^3.1.0",
28
28
  "dotenv": "^16.4.5",