@cetusprotocol/aggregator-sdk 1.5.0 → 1.5.1

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
 
@@ -3416,7 +3416,7 @@ var AGGREGATOR_V3_CONFIG = {
3416
3416
  };
3417
3417
 
3418
3418
  // src/api.ts
3419
- var SDK_VERSION = 1010500;
3419
+ var SDK_VERSION = 1010501;
3420
3420
  function parseRouterResponse(data, byAmountIn) {
3421
3421
  let packages = /* @__PURE__ */ new Map();
3422
3422
  if (data.packages) {
@@ -7857,11 +7857,12 @@ var PythAdapter = class {
7857
7857
  if (this.baseUpdateFee !== void 0) {
7858
7858
  return this.baseUpdateFee;
7859
7859
  }
7860
- const { object } = await this.client.getObject({
7861
- objectId: this.pythStateId,
7862
- include: { json: true }
7860
+ const res = await this.client.getObject({
7861
+ id: this.pythStateId,
7862
+ options: { showContent: true }
7863
7863
  });
7864
- const json = object.json;
7864
+ const content = res.data?.content;
7865
+ const json = content && "fields" in content ? content.fields : null;
7865
7866
  if (!json) {
7866
7867
  throw new Error("Unable to fetch pyth state object");
7867
7868
  }
@@ -7869,16 +7870,21 @@ var PythAdapter = class {
7869
7870
  return this.baseUpdateFee;
7870
7871
  }
7871
7872
  async getPackageId(objectId) {
7872
- const { object } = await this.client.getObject({
7873
- objectId,
7874
- include: { json: true }
7873
+ const res = await this.client.getObject({
7874
+ id: objectId,
7875
+ options: { showContent: true }
7875
7876
  });
7876
- const json = object.json;
7877
+ const content = res.data?.content;
7878
+ const json = content && "fields" in content ? content.fields : null;
7877
7879
  if (!json) {
7878
7880
  throw new Error(`Cannot fetch package id for object ${objectId}`);
7879
7881
  }
7880
7882
  if ("upgrade_cap" in json) {
7881
- return json.upgrade_cap.package;
7883
+ const upgradeCap = json.upgrade_cap;
7884
+ const packageId = upgradeCap?.fields?.package;
7885
+ if (typeof packageId === "string") {
7886
+ return packageId;
7887
+ }
7882
7888
  }
7883
7889
  throw new Error("upgrade_cap not found");
7884
7890
  }
@@ -7902,20 +7908,19 @@ var PythAdapter = class {
7902
7908
  const { id: tableId, fieldType } = await this.getPriceTableInfo();
7903
7909
  const feedIdBytes = Buffer.from(normalizedFeedId, "hex");
7904
7910
  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({
7911
+ const result = await this.client.getDynamicFieldObject({
7910
7912
  parentId: tableId,
7911
7913
  name: {
7912
- type: fieldType,
7913
- bcs: bcsBytes
7914
+ type: `${fieldType}::price_identifier::PriceIdentifier`,
7915
+ value: { bytes: Array.from(feedIdBytes) }
7914
7916
  }
7915
7917
  });
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("");
7918
+ const content = result.data?.content;
7919
+ const json = content && "fields" in content ? content.fields : null;
7920
+ const objectId = typeof json?.value === "string" ? json.value : void 0;
7921
+ if (!objectId) {
7922
+ return void 0;
7923
+ }
7919
7924
  this.priceFeedObjectIdCache.set(normalizedFeedId, objectId);
7920
7925
  return objectId;
7921
7926
  } catch {
@@ -7926,35 +7931,22 @@ var PythAdapter = class {
7926
7931
  if (this.priceTableInfo !== void 0) {
7927
7932
  return this.priceTableInfo;
7928
7933
  }
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
- }
7934
+ const result = await this.client.getDynamicFieldObject({
7935
+ parentId: this.pythStateId,
7936
+ name: {
7937
+ type: "vector<u8>",
7938
+ value: "price_info"
7951
7939
  }
7952
- hasNextPage = dynamicFields.hasNextPage;
7953
- cursor = dynamicFields.cursor;
7940
+ });
7941
+ if (!result.data?.type) {
7942
+ throw new Error(
7943
+ "Price Table not found, contract may not be initialized"
7944
+ );
7954
7945
  }
7955
- throw new Error(
7956
- "Price Table not found, contract may not be initialized"
7957
- );
7946
+ let type = result.data.type.replace("0x2::table::Table<", "");
7947
+ type = type.replace("::price_identifier::PriceIdentifier, 0x2::object::ID>", "");
7948
+ this.priceTableInfo = { id: result.data.objectId, fieldType: type };
7949
+ return this.priceTableInfo;
7958
7950
  }
7959
7951
  extractVaaBytesFromAccumulatorMessage(accumulatorMessage) {
7960
7952
  const trailingPayloadSize = accumulatorMessage.readUint8(6);
@@ -8138,21 +8130,21 @@ async function getOrCreateAccountCap(txb, client, owner) {
8138
8130
  }
8139
8131
  async function getAccountCap(client, owner) {
8140
8132
  const limit = 50;
8141
- let cursor = null;
8133
+ let cursor = void 0;
8142
8134
  while (true) {
8143
- const ownedObjects = await client.listOwnedObjects({
8135
+ const ownedObjects = await client.getOwnedObjects({
8144
8136
  owner,
8145
8137
  cursor,
8146
8138
  limit,
8147
- type: `${DEEPBOOK_PACKAGE_ID}::${DEEPBOOK_CUSTODIAN_V2_MODULE}::AccountCap`
8139
+ filter: { StructType: `${DEEPBOOK_PACKAGE_ID}::${DEEPBOOK_CUSTODIAN_V2_MODULE}::AccountCap` }
8148
8140
  });
8149
- if (ownedObjects.objects.length !== 0) {
8150
- return ownedObjects.objects[0].objectId;
8141
+ if (ownedObjects.data.length !== 0) {
8142
+ return ownedObjects.data[0].data?.objectId ?? null;
8151
8143
  }
8152
8144
  if (!ownedObjects.hasNextPage) {
8153
8145
  break;
8154
8146
  }
8155
- cursor = ownedObjects.cursor;
8147
+ cursor = ownedObjects.nextCursor ?? void 0;
8156
8148
  }
8157
8149
  return null;
8158
8150
  }
@@ -8180,10 +8172,10 @@ function getAggregatorV2Extend2PublishedAt(publishedAt, packages) {
8180
8172
  // src/utils/gas.ts
8181
8173
  var import_bn4 = __toESM(require_bn());
8182
8174
  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";
8175
+ const effects = result.effects;
8176
+ const isSuccess = !result.error && effects.status.status === "success";
8177
+ if (!isSuccess) {
8178
+ const errorMsg = result.error ?? effects.status.error ?? "Unknown error";
8187
8179
  return {
8188
8180
  computationCost: "0",
8189
8181
  storageCost: "0",
@@ -8846,8 +8838,8 @@ var _AggregatorClient = class _AggregatorClient {
8846
8838
  constructor(params) {
8847
8839
  this.endpoint = params.endpoint ? processEndpoint(params.endpoint) : DEFAULT_ENDPOINT;
8848
8840
  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 });
8841
+ const rpcUrl = params.env === 1 /* Testnet */ ? "https://fullnode.testnet.sui.io:443" : "https://fullnode.mainnet.sui.io:443";
8842
+ this.client = params.client ?? new jsonRpc.SuiJsonRpcClient({ network, url: rpcUrl });
8851
8843
  this.signer = params.signer || "";
8852
8844
  this.env = params.env || 0 /* Mainnet */;
8853
8845
  const config2 = _AggregatorClient.CONFIG[this.env];
@@ -8888,13 +8880,13 @@ var _AggregatorClient = class _AggregatorClient {
8888
8880
  }
8889
8881
  async getOneCoinUsedToMerge(coinType) {
8890
8882
  try {
8891
- const gotCoin = await this.client.listCoins({
8883
+ const gotCoin = await this.client.getCoins({
8892
8884
  owner: this.signer,
8893
8885
  coinType,
8894
8886
  limit: 1
8895
8887
  });
8896
- if (gotCoin.objects.length === 1) {
8897
- return gotCoin.objects[0].objectId;
8888
+ if (gotCoin.data.length === 1) {
8889
+ return gotCoin.data[0].coinObjectId;
8898
8890
  }
8899
8891
  return null;
8900
8892
  } catch (error) {
@@ -9639,18 +9631,16 @@ var _AggregatorClient = class _AggregatorClient {
9639
9631
  });
9640
9632
  }
9641
9633
  tx.setSenderIfNotSet(this.signer || "0x0");
9642
- const simulateRes = await this.client.simulateTransaction({
9643
- transaction: tx,
9644
- include: { events: true, effects: true }
9634
+ const simulateRes = await this.client.devInspectTransactionBlock({
9635
+ sender: this.signer || "0x0",
9636
+ transactionBlock: tx
9645
9637
  });
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);
9638
+ if (simulateRes.error) {
9639
+ throw new Error("Simulation error: " + simulateRes.error);
9650
9640
  }
9651
- const events = txResult.events ?? [];
9641
+ const events = simulateRes.events ?? [];
9652
9642
  const valueData = events.filter((item) => {
9653
- return item.eventType.includes("CalculatedSwapResultEvent");
9643
+ return item.type.includes("CalculatedSwapResultEvent");
9654
9644
  });
9655
9645
  if (valueData.length === 0 || valueData.length !== pools.length) {
9656
9646
  throw new Error("Simulate event result error");
@@ -9658,7 +9648,7 @@ var _AggregatorClient = class _AggregatorClient {
9658
9648
  let tempMaxAmount = byAmountIn ? new import_bn6.default(0) : new import_bn6.default(U64_MAX);
9659
9649
  let tempIndex = 0;
9660
9650
  for (let i = 0; i < valueData.length; i += 1) {
9661
- const eventJson2 = valueData[i].json;
9651
+ const eventJson2 = valueData[i].parsedJson;
9662
9652
  if (eventJson2?.data?.is_exceed) {
9663
9653
  continue;
9664
9654
  }
@@ -9676,11 +9666,11 @@ var _AggregatorClient = class _AggregatorClient {
9676
9666
  }
9677
9667
  }
9678
9668
  }
9679
- const eventJson = valueData[tempIndex].json;
9669
+ const eventJson = valueData[tempIndex].parsedJson;
9680
9670
  const eventData = eventJson?.data;
9681
9671
  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)
9672
+ this.client.getCoinMetadata({ coinType: coinA }).then((res) => res?.decimals ?? null),
9673
+ this.client.getCoinMetadata({ coinType: coinB }).then((res) => res?.decimals ?? null)
9684
9674
  ]);
9685
9675
  if (decimalA == null || decimalB == null) {
9686
9676
  throw new Error("Cannot get coin decimals");
@@ -9749,9 +9739,9 @@ var _AggregatorClient = class _AggregatorClient {
9749
9739
  }
9750
9740
  async devInspectTransactionBlock(txb) {
9751
9741
  txb.setSenderIfNotSet(this.signer || "0x0");
9752
- const res = await this.client.simulateTransaction({
9753
- transaction: txb,
9754
- include: { events: true, effects: true }
9742
+ const res = await this.client.devInspectTransactionBlock({
9743
+ sender: this.signer || "0x0",
9744
+ transactionBlock: txb
9755
9745
  });
9756
9746
  return res;
9757
9747
  }
@@ -9759,7 +9749,7 @@ var _AggregatorClient = class _AggregatorClient {
9759
9749
  const res = await this.client.signAndExecuteTransaction({
9760
9750
  transaction: txb,
9761
9751
  signer,
9762
- include: { effects: true, events: true, balanceChanges: true }
9752
+ options: { showEffects: true, showEvents: true, showBalanceChanges: true }
9763
9753
  });
9764
9754
  return res;
9765
9755
  }
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>;
@@ -403,7 +403,7 @@ declare function getProvidersIncluding(includeProviders: string[]): string[];
403
403
  type AggregatorClientParams = {
404
404
  endpoint?: string;
405
405
  signer?: string;
406
- client?: SuiGrpcClient;
406
+ client?: SuiJsonRpcClient;
407
407
  env?: Env;
408
408
  pythUrls?: string[];
409
409
  apiKey?: string;
@@ -415,7 +415,7 @@ type AggregatorClientParams = {
415
415
  declare class AggregatorClient {
416
416
  endpoint: string;
417
417
  signer: string;
418
- client: SuiGrpcClient;
418
+ client: SuiJsonRpcClient;
419
419
  env: Env;
420
420
  apiKey: string;
421
421
  protected pythAdapter: PythAdapter;
@@ -457,15 +457,8 @@ declare class AggregatorClient {
457
457
  fixableRouterSwapV3(params: BuildRouterSwapParamsV3): Promise<TransactionObjectArgument>;
458
458
  swapInPools(params: SwapInPoolsParams): Promise<SwapInPoolsResultV3>;
459
459
  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
- }>>;
460
+ devInspectTransactionBlock(txb: Transaction): Promise<_mysten_sui_jsonRpc.DevInspectResults>;
461
+ sendTransaction(txb: Transaction, signer: Signer): Promise<_mysten_sui_jsonRpc.SuiTransactionBlockResponse>;
469
462
  }
470
463
 
471
464
  /**
@@ -498,7 +491,7 @@ type GetOrCreateAccountCapResult = {
498
491
  accountCap: TransactionObjectArgument;
499
492
  isCreate: boolean;
500
493
  };
501
- declare function getOrCreateAccountCap(txb: Transaction, client: SuiGrpcClient, owner: string): Promise<GetOrCreateAccountCapResult>;
494
+ declare function getOrCreateAccountCap(txb: Transaction, client: SuiJsonRpcClient, owner: string): Promise<GetOrCreateAccountCapResult>;
502
495
 
503
496
  /**
504
497
  * Represents a SUI address, which is a string.
@@ -648,67 +641,23 @@ interface Dex {
648
641
  }
649
642
 
650
643
  /**
651
- * Matches the shape of SuiClientTypes.SimulateTransactionResult with effects included.
644
+ * Matches the shape of DevInspectResults from JSON-RPC.
652
645
  * Using a local type so gas.ts can be used without importing the full SDK.
653
646
  */
654
647
  type SimulateTransactionResult = {
655
- $kind: 'Transaction' | 'FailedTransaction';
656
- Transaction?: {
648
+ effects: {
657
649
  status: {
658
- success: true;
659
- error: null;
660
- } | {
661
- success: false;
662
- error: {
663
- message: string;
664
- };
650
+ status: 'success' | 'failure';
651
+ error?: string;
665
652
  };
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?: {
685
- status: {
686
- success: true;
687
- error: null;
688
- } | {
689
- success: false;
690
- error: {
691
- message: string;
692
- };
693
- };
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
- };
653
+ gasUsed: {
654
+ computationCost: string;
655
+ storageCost: string;
656
+ storageRebate: string;
657
+ nonRefundableStorageFee: string;
710
658
  };
711
659
  };
660
+ error?: string | null;
712
661
  };
713
662
  interface GasMetrics {
714
663
  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>;
@@ -403,7 +403,7 @@ declare function getProvidersIncluding(includeProviders: string[]): string[];
403
403
  type AggregatorClientParams = {
404
404
  endpoint?: string;
405
405
  signer?: string;
406
- client?: SuiGrpcClient;
406
+ client?: SuiJsonRpcClient;
407
407
  env?: Env;
408
408
  pythUrls?: string[];
409
409
  apiKey?: string;
@@ -415,7 +415,7 @@ type AggregatorClientParams = {
415
415
  declare class AggregatorClient {
416
416
  endpoint: string;
417
417
  signer: string;
418
- client: SuiGrpcClient;
418
+ client: SuiJsonRpcClient;
419
419
  env: Env;
420
420
  apiKey: string;
421
421
  protected pythAdapter: PythAdapter;
@@ -457,15 +457,8 @@ declare class AggregatorClient {
457
457
  fixableRouterSwapV3(params: BuildRouterSwapParamsV3): Promise<TransactionObjectArgument>;
458
458
  swapInPools(params: SwapInPoolsParams): Promise<SwapInPoolsResultV3>;
459
459
  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
- }>>;
460
+ devInspectTransactionBlock(txb: Transaction): Promise<_mysten_sui_jsonRpc.DevInspectResults>;
461
+ sendTransaction(txb: Transaction, signer: Signer): Promise<_mysten_sui_jsonRpc.SuiTransactionBlockResponse>;
469
462
  }
470
463
 
471
464
  /**
@@ -498,7 +491,7 @@ type GetOrCreateAccountCapResult = {
498
491
  accountCap: TransactionObjectArgument;
499
492
  isCreate: boolean;
500
493
  };
501
- declare function getOrCreateAccountCap(txb: Transaction, client: SuiGrpcClient, owner: string): Promise<GetOrCreateAccountCapResult>;
494
+ declare function getOrCreateAccountCap(txb: Transaction, client: SuiJsonRpcClient, owner: string): Promise<GetOrCreateAccountCapResult>;
502
495
 
503
496
  /**
504
497
  * Represents a SUI address, which is a string.
@@ -648,67 +641,23 @@ interface Dex {
648
641
  }
649
642
 
650
643
  /**
651
- * Matches the shape of SuiClientTypes.SimulateTransactionResult with effects included.
644
+ * Matches the shape of DevInspectResults from JSON-RPC.
652
645
  * Using a local type so gas.ts can be used without importing the full SDK.
653
646
  */
654
647
  type SimulateTransactionResult = {
655
- $kind: 'Transaction' | 'FailedTransaction';
656
- Transaction?: {
648
+ effects: {
657
649
  status: {
658
- success: true;
659
- error: null;
660
- } | {
661
- success: false;
662
- error: {
663
- message: string;
664
- };
650
+ status: 'success' | 'failure';
651
+ error?: string;
665
652
  };
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?: {
685
- status: {
686
- success: true;
687
- error: null;
688
- } | {
689
- success: false;
690
- error: {
691
- message: string;
692
- };
693
- };
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
- };
653
+ gasUsed: {
654
+ computationCost: string;
655
+ storageCost: string;
656
+ storageRebate: string;
657
+ nonRefundableStorageFee: string;
710
658
  };
711
659
  };
660
+ error?: string | null;
712
661
  };
713
662
  interface GasMetrics {
714
663
  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
 
@@ -3410,7 +3410,7 @@ var AGGREGATOR_V3_CONFIG = {
3410
3410
  };
3411
3411
 
3412
3412
  // src/api.ts
3413
- var SDK_VERSION = 1010500;
3413
+ var SDK_VERSION = 1010501;
3414
3414
  function parseRouterResponse(data, byAmountIn) {
3415
3415
  let packages = /* @__PURE__ */ new Map();
3416
3416
  if (data.packages) {
@@ -7851,11 +7851,12 @@ var PythAdapter = class {
7851
7851
  if (this.baseUpdateFee !== void 0) {
7852
7852
  return this.baseUpdateFee;
7853
7853
  }
7854
- const { object } = await this.client.getObject({
7855
- objectId: this.pythStateId,
7856
- include: { json: true }
7854
+ const res = await this.client.getObject({
7855
+ id: this.pythStateId,
7856
+ options: { showContent: true }
7857
7857
  });
7858
- const json = object.json;
7858
+ const content = res.data?.content;
7859
+ const json = content && "fields" in content ? content.fields : null;
7859
7860
  if (!json) {
7860
7861
  throw new Error("Unable to fetch pyth state object");
7861
7862
  }
@@ -7863,16 +7864,21 @@ var PythAdapter = class {
7863
7864
  return this.baseUpdateFee;
7864
7865
  }
7865
7866
  async getPackageId(objectId) {
7866
- const { object } = await this.client.getObject({
7867
- objectId,
7868
- include: { json: true }
7867
+ const res = await this.client.getObject({
7868
+ id: objectId,
7869
+ options: { showContent: true }
7869
7870
  });
7870
- const json = object.json;
7871
+ const content = res.data?.content;
7872
+ const json = content && "fields" in content ? content.fields : null;
7871
7873
  if (!json) {
7872
7874
  throw new Error(`Cannot fetch package id for object ${objectId}`);
7873
7875
  }
7874
7876
  if ("upgrade_cap" in json) {
7875
- return json.upgrade_cap.package;
7877
+ const upgradeCap = json.upgrade_cap;
7878
+ const packageId = upgradeCap?.fields?.package;
7879
+ if (typeof packageId === "string") {
7880
+ return packageId;
7881
+ }
7876
7882
  }
7877
7883
  throw new Error("upgrade_cap not found");
7878
7884
  }
@@ -7896,20 +7902,19 @@ var PythAdapter = class {
7896
7902
  const { id: tableId, fieldType } = await this.getPriceTableInfo();
7897
7903
  const feedIdBytes = Buffer.from(normalizedFeedId, "hex");
7898
7904
  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({
7905
+ const result = await this.client.getDynamicFieldObject({
7904
7906
  parentId: tableId,
7905
7907
  name: {
7906
- type: fieldType,
7907
- bcs: bcsBytes
7908
+ type: `${fieldType}::price_identifier::PriceIdentifier`,
7909
+ value: { bytes: Array.from(feedIdBytes) }
7908
7910
  }
7909
7911
  });
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("");
7912
+ const content = result.data?.content;
7913
+ const json = content && "fields" in content ? content.fields : null;
7914
+ const objectId = typeof json?.value === "string" ? json.value : void 0;
7915
+ if (!objectId) {
7916
+ return void 0;
7917
+ }
7913
7918
  this.priceFeedObjectIdCache.set(normalizedFeedId, objectId);
7914
7919
  return objectId;
7915
7920
  } catch {
@@ -7920,35 +7925,22 @@ var PythAdapter = class {
7920
7925
  if (this.priceTableInfo !== void 0) {
7921
7926
  return this.priceTableInfo;
7922
7927
  }
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
- }
7928
+ const result = await this.client.getDynamicFieldObject({
7929
+ parentId: this.pythStateId,
7930
+ name: {
7931
+ type: "vector<u8>",
7932
+ value: "price_info"
7945
7933
  }
7946
- hasNextPage = dynamicFields.hasNextPage;
7947
- cursor = dynamicFields.cursor;
7934
+ });
7935
+ if (!result.data?.type) {
7936
+ throw new Error(
7937
+ "Price Table not found, contract may not be initialized"
7938
+ );
7948
7939
  }
7949
- throw new Error(
7950
- "Price Table not found, contract may not be initialized"
7951
- );
7940
+ let type = result.data.type.replace("0x2::table::Table<", "");
7941
+ type = type.replace("::price_identifier::PriceIdentifier, 0x2::object::ID>", "");
7942
+ this.priceTableInfo = { id: result.data.objectId, fieldType: type };
7943
+ return this.priceTableInfo;
7952
7944
  }
7953
7945
  extractVaaBytesFromAccumulatorMessage(accumulatorMessage) {
7954
7946
  const trailingPayloadSize = accumulatorMessage.readUint8(6);
@@ -8132,21 +8124,21 @@ async function getOrCreateAccountCap(txb, client, owner) {
8132
8124
  }
8133
8125
  async function getAccountCap(client, owner) {
8134
8126
  const limit = 50;
8135
- let cursor = null;
8127
+ let cursor = void 0;
8136
8128
  while (true) {
8137
- const ownedObjects = await client.listOwnedObjects({
8129
+ const ownedObjects = await client.getOwnedObjects({
8138
8130
  owner,
8139
8131
  cursor,
8140
8132
  limit,
8141
- type: `${DEEPBOOK_PACKAGE_ID}::${DEEPBOOK_CUSTODIAN_V2_MODULE}::AccountCap`
8133
+ filter: { StructType: `${DEEPBOOK_PACKAGE_ID}::${DEEPBOOK_CUSTODIAN_V2_MODULE}::AccountCap` }
8142
8134
  });
8143
- if (ownedObjects.objects.length !== 0) {
8144
- return ownedObjects.objects[0].objectId;
8135
+ if (ownedObjects.data.length !== 0) {
8136
+ return ownedObjects.data[0].data?.objectId ?? null;
8145
8137
  }
8146
8138
  if (!ownedObjects.hasNextPage) {
8147
8139
  break;
8148
8140
  }
8149
- cursor = ownedObjects.cursor;
8141
+ cursor = ownedObjects.nextCursor ?? void 0;
8150
8142
  }
8151
8143
  return null;
8152
8144
  }
@@ -8174,10 +8166,10 @@ function getAggregatorV2Extend2PublishedAt(publishedAt, packages) {
8174
8166
  // src/utils/gas.ts
8175
8167
  var import_bn4 = __toESM(require_bn());
8176
8168
  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";
8169
+ const effects = result.effects;
8170
+ const isSuccess = !result.error && effects.status.status === "success";
8171
+ if (!isSuccess) {
8172
+ const errorMsg = result.error ?? effects.status.error ?? "Unknown error";
8181
8173
  return {
8182
8174
  computationCost: "0",
8183
8175
  storageCost: "0",
@@ -8840,8 +8832,8 @@ var _AggregatorClient = class _AggregatorClient {
8840
8832
  constructor(params) {
8841
8833
  this.endpoint = params.endpoint ? processEndpoint(params.endpoint) : DEFAULT_ENDPOINT;
8842
8834
  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 });
8835
+ const rpcUrl = params.env === 1 /* Testnet */ ? "https://fullnode.testnet.sui.io:443" : "https://fullnode.mainnet.sui.io:443";
8836
+ this.client = params.client ?? new SuiJsonRpcClient({ network, url: rpcUrl });
8845
8837
  this.signer = params.signer || "";
8846
8838
  this.env = params.env || 0 /* Mainnet */;
8847
8839
  const config2 = _AggregatorClient.CONFIG[this.env];
@@ -8882,13 +8874,13 @@ var _AggregatorClient = class _AggregatorClient {
8882
8874
  }
8883
8875
  async getOneCoinUsedToMerge(coinType) {
8884
8876
  try {
8885
- const gotCoin = await this.client.listCoins({
8877
+ const gotCoin = await this.client.getCoins({
8886
8878
  owner: this.signer,
8887
8879
  coinType,
8888
8880
  limit: 1
8889
8881
  });
8890
- if (gotCoin.objects.length === 1) {
8891
- return gotCoin.objects[0].objectId;
8882
+ if (gotCoin.data.length === 1) {
8883
+ return gotCoin.data[0].coinObjectId;
8892
8884
  }
8893
8885
  return null;
8894
8886
  } catch (error) {
@@ -9633,18 +9625,16 @@ var _AggregatorClient = class _AggregatorClient {
9633
9625
  });
9634
9626
  }
9635
9627
  tx.setSenderIfNotSet(this.signer || "0x0");
9636
- const simulateRes = await this.client.simulateTransaction({
9637
- transaction: tx,
9638
- include: { events: true, effects: true }
9628
+ const simulateRes = await this.client.devInspectTransactionBlock({
9629
+ sender: this.signer || "0x0",
9630
+ transactionBlock: tx
9639
9631
  });
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);
9632
+ if (simulateRes.error) {
9633
+ throw new Error("Simulation error: " + simulateRes.error);
9644
9634
  }
9645
- const events = txResult.events ?? [];
9635
+ const events = simulateRes.events ?? [];
9646
9636
  const valueData = events.filter((item) => {
9647
- return item.eventType.includes("CalculatedSwapResultEvent");
9637
+ return item.type.includes("CalculatedSwapResultEvent");
9648
9638
  });
9649
9639
  if (valueData.length === 0 || valueData.length !== pools.length) {
9650
9640
  throw new Error("Simulate event result error");
@@ -9652,7 +9642,7 @@ var _AggregatorClient = class _AggregatorClient {
9652
9642
  let tempMaxAmount = byAmountIn ? new import_bn6.default(0) : new import_bn6.default(U64_MAX);
9653
9643
  let tempIndex = 0;
9654
9644
  for (let i = 0; i < valueData.length; i += 1) {
9655
- const eventJson2 = valueData[i].json;
9645
+ const eventJson2 = valueData[i].parsedJson;
9656
9646
  if (eventJson2?.data?.is_exceed) {
9657
9647
  continue;
9658
9648
  }
@@ -9670,11 +9660,11 @@ var _AggregatorClient = class _AggregatorClient {
9670
9660
  }
9671
9661
  }
9672
9662
  }
9673
- const eventJson = valueData[tempIndex].json;
9663
+ const eventJson = valueData[tempIndex].parsedJson;
9674
9664
  const eventData = eventJson?.data;
9675
9665
  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)
9666
+ this.client.getCoinMetadata({ coinType: coinA }).then((res) => res?.decimals ?? null),
9667
+ this.client.getCoinMetadata({ coinType: coinB }).then((res) => res?.decimals ?? null)
9678
9668
  ]);
9679
9669
  if (decimalA == null || decimalB == null) {
9680
9670
  throw new Error("Cannot get coin decimals");
@@ -9743,9 +9733,9 @@ var _AggregatorClient = class _AggregatorClient {
9743
9733
  }
9744
9734
  async devInspectTransactionBlock(txb) {
9745
9735
  txb.setSenderIfNotSet(this.signer || "0x0");
9746
- const res = await this.client.simulateTransaction({
9747
- transaction: txb,
9748
- include: { events: true, effects: true }
9736
+ const res = await this.client.devInspectTransactionBlock({
9737
+ sender: this.signer || "0x0",
9738
+ transactionBlock: txb
9749
9739
  });
9750
9740
  return res;
9751
9741
  }
@@ -9753,7 +9743,7 @@ var _AggregatorClient = class _AggregatorClient {
9753
9743
  const res = await this.client.signAndExecuteTransaction({
9754
9744
  transaction: txb,
9755
9745
  signer,
9756
- include: { effects: true, events: true, balanceChanges: true }
9746
+ options: { showEffects: true, showEvents: true, showBalanceChanges: true }
9757
9747
  });
9758
9748
  return res;
9759
9749
  }
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.1",
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",