@cetusprotocol/aggregator-sdk 0.3.21 → 0.3.23

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/bun.lockb CHANGED
Binary file
package/dist/index.d.mts CHANGED
@@ -131,10 +131,13 @@ declare class AggregatorClient {
131
131
  client: SuiClient;
132
132
  env: Env;
133
133
  private allCoins;
134
+ private pythConnections;
135
+ private pythClient;
136
+ private static readonly CONFIG;
134
137
  constructor(endpoint?: string, signer?: string, client?: SuiClient, env?: Env);
135
138
  getCoins(coinType: string, refresh?: boolean): Promise<CoinAsset[]>;
136
139
  findRouters(params: FindRouterParams): Promise<RouterData | null>;
137
- expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument, packages?: Map<string, string>): Promise<TransactionObjectArgument>;
140
+ expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, pythPriceIDs: Map<string, string>, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument, packages?: Map<string, string>): Promise<TransactionObjectArgument>;
138
141
  expectOutputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], partner?: string, packages?: Map<string, string>): Promise<TransactionObjectArgument>;
139
142
  swapInPools(params: SwapInPoolsParams): Promise<SwapInPoolsResult | null>;
140
143
  routerSwap(params: BuildRouterSwapParams | BuildRouterSwapParamsV2): Promise<TransactionObjectArgument>;
@@ -144,12 +147,14 @@ declare class AggregatorClient {
144
147
  deepbookv3DeepFeeType(): string;
145
148
  transferOrDestoryCoin(txb: Transaction, coin: TransactionObjectArgument, coinType: string, aggregatorV2PublishedAt: string): void;
146
149
  checkCoinThresholdAndMergeCoin(txb: Transaction, coins: TransactionObjectArgument[], coinType: string, amountLimit: BN, aggregatorV2PublishedAt: string): TransactionObjectArgument;
147
- newDex(provider: string, partner?: string): Dex;
150
+ newDex(provider: string, pythPriceIDs: Map<string, string>, partner?: string): Dex;
148
151
  signAndExecuteTransaction(txb: Transaction, signer: Signer): Promise<_mysten_sui_client.SuiTransactionBlockResponse>;
149
152
  devInspectTransactionBlock(txb: Transaction): Promise<_mysten_sui_client.DevInspectResults>;
150
153
  sendTransaction(txb: Transaction, signer: Signer): Promise<_mysten_sui_client.SuiTransactionBlockResponse>;
151
154
  getDeepbookV3Config(): Promise<DeepbookV3Config | null>;
155
+ updatePythPriceIDs(priceIDs: string[], txb: Transaction): Promise<Map<string, string>>;
152
156
  }
157
+ declare function findPythPriceIDs(routes: Router[]): string[];
153
158
  declare function parseRouterResponse(data: any, byAmountIn: boolean): RouterData;
154
159
 
155
160
  declare const CLOCK_ADDRESS = "0x0000000000000000000000000000000000000000000000000000000000000006";
@@ -293,4 +298,4 @@ declare enum Env {
293
298
  Testnet = 1
294
299
  }
295
300
 
296
- export { AFSUI, AFTERMATH, AGGREGATOR_V2, AGGREGATOR_V2_EXTEND, ALPHAFI, AggregatorClient, type AggregatorResponse, BLUEFIN, BLUEMOVE, type BuildCoinResult, type BuildFastRouterSwapParams, type BuildFastRouterSwapParamsV2, type BuildRouterSwapParams, type BuildRouterSwapParamsV2, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, type DeepbookV3Config, type DeepbookV3ConfigResponse, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWXV3, type FindRouterParams, HAEDAL, HAEDALPMM, KRIYA, KRIYAV3, ONE, type Path, type PreSwapLpChangeParams, type Router, type RouterData, type RouterError, SCALLOP, SPRINGSUI, SUILEND, type SwapInPoolsParams, type SwapInPoolsResult, TEN_POW_NINE, TURBOS, TWO, U128, U64_MAX, U64_MAX_BN, VOLO, ZERO, buildInputCoin, checkInvalidSuiAddress, compareCoins, completionCoin, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, extractAddressFromType, extractStructTagFromType, fixSuiObjectId, getAggregatorV2ExtendPublishedAt, getAggregatorV2PublishedAt, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
301
+ export { AFSUI, AFTERMATH, AGGREGATOR_V2, AGGREGATOR_V2_EXTEND, ALPHAFI, AggregatorClient, type AggregatorResponse, BLUEFIN, BLUEMOVE, type BuildCoinResult, type BuildFastRouterSwapParams, type BuildFastRouterSwapParamsV2, type BuildRouterSwapParams, type BuildRouterSwapParamsV2, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, type DeepbookV3Config, type DeepbookV3ConfigResponse, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWXV3, type FindRouterParams, HAEDAL, HAEDALPMM, KRIYA, KRIYAV3, ONE, type Path, type PreSwapLpChangeParams, type Router, type RouterData, type RouterError, SCALLOP, SPRINGSUI, SUILEND, type SwapInPoolsParams, type SwapInPoolsResult, TEN_POW_NINE, TURBOS, TWO, U128, U64_MAX, U64_MAX_BN, VOLO, ZERO, buildInputCoin, checkInvalidSuiAddress, compareCoins, completionCoin, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, extractAddressFromType, extractStructTagFromType, findPythPriceIDs, fixSuiObjectId, getAggregatorV2ExtendPublishedAt, getAggregatorV2PublishedAt, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
package/dist/index.d.ts CHANGED
@@ -131,10 +131,13 @@ declare class AggregatorClient {
131
131
  client: SuiClient;
132
132
  env: Env;
133
133
  private allCoins;
134
+ private pythConnections;
135
+ private pythClient;
136
+ private static readonly CONFIG;
134
137
  constructor(endpoint?: string, signer?: string, client?: SuiClient, env?: Env);
135
138
  getCoins(coinType: string, refresh?: boolean): Promise<CoinAsset[]>;
136
139
  findRouters(params: FindRouterParams): Promise<RouterData | null>;
137
- expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument, packages?: Map<string, string>): Promise<TransactionObjectArgument>;
140
+ expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, pythPriceIDs: Map<string, string>, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument, packages?: Map<string, string>): Promise<TransactionObjectArgument>;
138
141
  expectOutputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], partner?: string, packages?: Map<string, string>): Promise<TransactionObjectArgument>;
139
142
  swapInPools(params: SwapInPoolsParams): Promise<SwapInPoolsResult | null>;
140
143
  routerSwap(params: BuildRouterSwapParams | BuildRouterSwapParamsV2): Promise<TransactionObjectArgument>;
@@ -144,12 +147,14 @@ declare class AggregatorClient {
144
147
  deepbookv3DeepFeeType(): string;
145
148
  transferOrDestoryCoin(txb: Transaction, coin: TransactionObjectArgument, coinType: string, aggregatorV2PublishedAt: string): void;
146
149
  checkCoinThresholdAndMergeCoin(txb: Transaction, coins: TransactionObjectArgument[], coinType: string, amountLimit: BN, aggregatorV2PublishedAt: string): TransactionObjectArgument;
147
- newDex(provider: string, partner?: string): Dex;
150
+ newDex(provider: string, pythPriceIDs: Map<string, string>, partner?: string): Dex;
148
151
  signAndExecuteTransaction(txb: Transaction, signer: Signer): Promise<_mysten_sui_client.SuiTransactionBlockResponse>;
149
152
  devInspectTransactionBlock(txb: Transaction): Promise<_mysten_sui_client.DevInspectResults>;
150
153
  sendTransaction(txb: Transaction, signer: Signer): Promise<_mysten_sui_client.SuiTransactionBlockResponse>;
151
154
  getDeepbookV3Config(): Promise<DeepbookV3Config | null>;
155
+ updatePythPriceIDs(priceIDs: string[], txb: Transaction): Promise<Map<string, string>>;
152
156
  }
157
+ declare function findPythPriceIDs(routes: Router[]): string[];
153
158
  declare function parseRouterResponse(data: any, byAmountIn: boolean): RouterData;
154
159
 
155
160
  declare const CLOCK_ADDRESS = "0x0000000000000000000000000000000000000000000000000000000000000006";
@@ -293,4 +298,4 @@ declare enum Env {
293
298
  Testnet = 1
294
299
  }
295
300
 
296
- export { AFSUI, AFTERMATH, AGGREGATOR_V2, AGGREGATOR_V2_EXTEND, ALPHAFI, AggregatorClient, type AggregatorResponse, BLUEFIN, BLUEMOVE, type BuildCoinResult, type BuildFastRouterSwapParams, type BuildFastRouterSwapParamsV2, type BuildRouterSwapParams, type BuildRouterSwapParamsV2, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, type DeepbookV3Config, type DeepbookV3ConfigResponse, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWXV3, type FindRouterParams, HAEDAL, HAEDALPMM, KRIYA, KRIYAV3, ONE, type Path, type PreSwapLpChangeParams, type Router, type RouterData, type RouterError, SCALLOP, SPRINGSUI, SUILEND, type SwapInPoolsParams, type SwapInPoolsResult, TEN_POW_NINE, TURBOS, TWO, U128, U64_MAX, U64_MAX_BN, VOLO, ZERO, buildInputCoin, checkInvalidSuiAddress, compareCoins, completionCoin, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, extractAddressFromType, extractStructTagFromType, fixSuiObjectId, getAggregatorV2ExtendPublishedAt, getAggregatorV2PublishedAt, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
301
+ export { AFSUI, AFTERMATH, AGGREGATOR_V2, AGGREGATOR_V2_EXTEND, ALPHAFI, AggregatorClient, type AggregatorResponse, BLUEFIN, BLUEMOVE, type BuildCoinResult, type BuildFastRouterSwapParams, type BuildFastRouterSwapParamsV2, type BuildRouterSwapParams, type BuildRouterSwapParamsV2, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, type DeepbookV3Config, type DeepbookV3ConfigResponse, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWXV3, type FindRouterParams, HAEDAL, HAEDALPMM, KRIYA, KRIYAV3, ONE, type Path, type PreSwapLpChangeParams, type Router, type RouterData, type RouterError, SCALLOP, SPRINGSUI, SUILEND, type SwapInPoolsParams, type SwapInPoolsResult, TEN_POW_NINE, TURBOS, TWO, U128, U64_MAX, U64_MAX_BN, VOLO, ZERO, buildInputCoin, checkInvalidSuiAddress, compareCoins, completionCoin, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, extractAddressFromType, extractStructTagFromType, findPythPriceIDs, fixSuiObjectId, getAggregatorV2ExtendPublishedAt, getAggregatorV2PublishedAt, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
package/dist/index.js CHANGED
@@ -5803,11 +5803,10 @@ function swapInPools(client, params, sender, env) {
5803
5803
  const targetCoin = completionCoin(target);
5804
5804
  const tx = new transactions.Transaction();
5805
5805
  const direction = compareCoins(fromCoin, targetCoin);
5806
- const integratePublishedAt = env === 0 /* Mainnet */ ? "0x3a5aa90ffa33d09100d7b6941ea1c0ffe6ab66e77062ddd26320c1b073aabb10" : "0x19dd42e05fa6c9988a60d30686ee3feb776672b5547e328d6dab16563da65293";
5806
+ const integratePublishedAt = env === 0 /* Mainnet */ ? "0x2d8c2e0fc6dd25b0214b3fa747e0fd27fd54608142cd2e4f64c1cd350cc4add4" : "0x4f920e1ef6318cfba77e20a0538a419a5a504c14230169438b99aba485db40a6";
5807
5807
  const coinA = direction ? fromCoin : targetCoin;
5808
5808
  const coinB = direction ? targetCoin : fromCoin;
5809
5809
  const typeArguments = [coinA, coinB];
5810
- console.log("typeArguments", typeArguments, integratePublishedAt);
5811
5810
  for (let i = 0; i < pools.length; i++) {
5812
5811
  const args = [
5813
5812
  tx.object(pools[i]),
@@ -5827,7 +5826,6 @@ function swapInPools(client, params, sender, env) {
5827
5826
  "InvalidWallet" /* InvalidWallet */
5828
5827
  );
5829
5828
  }
5830
- printTransaction(tx);
5831
5829
  const simulateRes = yield client.devInspectTransactionBlock({
5832
5830
  transactionBlock: tx,
5833
5831
  sender
@@ -5869,7 +5867,6 @@ function swapInPools(client, params, sender, env) {
5869
5867
  }
5870
5868
  }
5871
5869
  const event = valueData[tempIndex].parsedJson.data;
5872
- console.log("event", JSON.stringify(event, null, 2));
5873
5870
  const currentSqrtPrice = event.step_results[0].current_sqrt_price;
5874
5871
  const [decimalA, decimalB] = yield Promise.all([
5875
5872
  client.getCoinMetadata({ coinType: coinA }).then((metadata) => metadata == null ? void 0 : metadata.decimals),
@@ -6170,19 +6167,14 @@ var Bluefin = class {
6170
6167
  });
6171
6168
  }
6172
6169
  };
6170
+
6171
+ // src/transaction/haedal_pmm.ts
6173
6172
  var HaedalPmm = class {
6174
- constructor(env, suiClient) {
6173
+ constructor(env, pythPriceIDs) {
6175
6174
  if (env === 1 /* Testnet */) {
6176
- this.connection = new pythSuiJs.SuiPriceServiceConnection("https://hermes-beta.pyth.network");
6177
- const wormholeStateId = "0x31358d198147da50db32eda2562951d53973a0c0ad5ed738e9b17d88b213d790";
6178
- const pythStateId = "0x243759059f4c3111179da5878c12f68d612c21a8d54d85edc86164bb18be1c7c";
6179
- this.pythClient = new pythSuiJs.SuiPythClient(suiClient, pythStateId, wormholeStateId);
6180
- } else {
6181
- this.connection = new pythSuiJs.SuiPriceServiceConnection("https://hermes.pyth.network");
6182
- const wormholeStateId = "0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c";
6183
- const pythStateId = "0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8";
6184
- this.pythClient = new pythSuiJs.SuiPythClient(suiClient, pythStateId, wormholeStateId);
6175
+ throw new Error("HaedalPmm is not supported on testnet");
6185
6176
  }
6177
+ this.pythPriceIDs = pythPriceIDs;
6186
6178
  }
6187
6179
  swap(client, txb, path, inputCoin, packages) {
6188
6180
  return __async(this, null, function* () {
@@ -6199,17 +6191,24 @@ var HaedalPmm = class {
6199
6191
  basePriceSeed = path.extendedDetails.haedalPmmBasePriceSeed;
6200
6192
  quotePriceSeed = path.extendedDetails.haedalPmmQuotePriceSeed;
6201
6193
  }
6202
- const priceIDs = [basePriceSeed, quotePriceSeed];
6203
- const priceUpdateData = yield this.connection.getPriceFeedsUpdateData(priceIDs);
6204
- const priceInfoObjectIds = yield this.pythClient.updatePriceFeeds(txb, priceUpdateData, priceIDs);
6194
+ const basePriceInfoObjectId = this.pythPriceIDs.get(basePriceSeed);
6195
+ const quotePriceInfoObjectId = this.pythPriceIDs.get(quotePriceSeed);
6196
+ if (!basePriceInfoObjectId || !quotePriceInfoObjectId) {
6197
+ throw new Error(
6198
+ "Base price info object id or quote price info object id not found"
6199
+ );
6200
+ }
6205
6201
  const args = [
6206
6202
  txb.object(path.id),
6207
- txb.object(priceInfoObjectIds[0]),
6208
- txb.object(priceInfoObjectIds[1]),
6203
+ txb.object(basePriceInfoObjectId),
6204
+ txb.object(quotePriceInfoObjectId),
6209
6205
  inputCoin,
6210
6206
  txb.object(CLOCK_ADDRESS)
6211
6207
  ];
6212
- const publishedAt = getAggregatorV2ExtendPublishedAt(client.publishedAtV2Extend(), packages);
6208
+ const publishedAt = getAggregatorV2ExtendPublishedAt(
6209
+ client.publishedAtV2Extend(),
6210
+ packages
6211
+ );
6213
6212
  const res = txb.moveCall({
6214
6213
  target: `${publishedAt}::haedalpmm::${func}`,
6215
6214
  typeArguments: [coinAType, coinBType],
@@ -6247,8 +6246,6 @@ var Alphafi = class {
6247
6246
  });
6248
6247
  }
6249
6248
  };
6250
-
6251
- // src/client.ts
6252
6249
  var CETUS = "CETUS";
6253
6250
  var DEEPBOOKV2 = "DEEPBOOK";
6254
6251
  var KRIYA = "KRIYA";
@@ -6275,13 +6272,20 @@ function isBuilderRouterSwapParams(params) {
6275
6272
  function isBuilderFastRouterSwapParams(params) {
6276
6273
  return Array.isArray(params.routers);
6277
6274
  }
6278
- var AggregatorClient19 = class {
6275
+ var _AggregatorClient = class _AggregatorClient {
6279
6276
  constructor(endpoint, signer, client$1, env) {
6280
6277
  this.endpoint = endpoint ? processEndpoint(endpoint) : DEFAULT_ENDPOINT;
6281
6278
  this.client = client$1 || new client.SuiClient({ url: client.getFullnodeUrl("mainnet") });
6282
6279
  this.signer = signer || "";
6283
6280
  this.env = env || 0 /* Mainnet */;
6284
6281
  this.allCoins = /* @__PURE__ */ new Map();
6282
+ const config2 = _AggregatorClient.CONFIG[this.env];
6283
+ this.pythConnections = config2.connections;
6284
+ this.pythClient = new pythSuiJs.SuiPythClient(
6285
+ this.client,
6286
+ config2.pythStateId,
6287
+ config2.wormholeStateId
6288
+ );
6285
6289
  }
6286
6290
  getCoins(coinType, refresh = true) {
6287
6291
  return __async(this, null, function* () {
@@ -6325,7 +6329,7 @@ var AggregatorClient19 = class {
6325
6329
  return getRouterResult(this.endpoint, params);
6326
6330
  });
6327
6331
  }
6328
- expectInputSwap(txb, inputCoin, routers, amountOutLimit, partner, deepbookv3DeepFee, packages) {
6332
+ expectInputSwap(txb, inputCoin, routers, amountOutLimit, pythPriceIDs, partner, deepbookv3DeepFee, packages) {
6329
6333
  return __async(this, null, function* () {
6330
6334
  if (routers.length === 0) {
6331
6335
  throw new Error("No router found");
@@ -6341,13 +6345,28 @@ var AggregatorClient19 = class {
6341
6345
  }
6342
6346
  let nextCoin = inputCoins[i];
6343
6347
  for (const path of routers[i].path) {
6344
- const dex = this.newDex(path.provider, partner);
6345
- nextCoin = yield dex.swap(this, txb, path, nextCoin, packages, deepbookv3DeepFee);
6348
+ const dex = this.newDex(path.provider, pythPriceIDs, partner);
6349
+ nextCoin = yield dex.swap(
6350
+ this,
6351
+ txb,
6352
+ path,
6353
+ nextCoin,
6354
+ packages,
6355
+ deepbookv3DeepFee
6356
+ );
6346
6357
  }
6347
6358
  outputCoins.push(nextCoin);
6348
6359
  }
6349
- const aggregatorV2PublishedAt = getAggregatorV2PublishedAt(this.publishedAtV2(), packages);
6350
- this.transferOrDestoryCoin(txb, inputCoin, inputCoinType, this.publishedAtV2());
6360
+ const aggregatorV2PublishedAt = getAggregatorV2PublishedAt(
6361
+ this.publishedAtV2(),
6362
+ packages
6363
+ );
6364
+ this.transferOrDestoryCoin(
6365
+ txb,
6366
+ inputCoin,
6367
+ inputCoinType,
6368
+ this.publishedAtV2()
6369
+ );
6351
6370
  const mergedTargetCointhis = this.checkCoinThresholdAndMergeCoin(
6352
6371
  txb,
6353
6372
  outputCoins,
@@ -6364,7 +6383,10 @@ var AggregatorClient19 = class {
6364
6383
  const receipts = [];
6365
6384
  const targetCoins = [];
6366
6385
  const dex = new Cetus(this.env, partner);
6367
- const aggregatorV2PublishedAt = getAggregatorV2PublishedAt(this.publishedAtV2(), packages);
6386
+ const aggregatorV2PublishedAt = getAggregatorV2PublishedAt(
6387
+ this.publishedAtV2(),
6388
+ packages
6389
+ );
6368
6390
  for (let i = 0; i < routers.length; i++) {
6369
6391
  const router = routers[i];
6370
6392
  for (let j = router.path.length - 1; j >= 0; j--) {
@@ -6387,7 +6409,12 @@ var AggregatorClient19 = class {
6387
6409
  if (j === 0) {
6388
6410
  inputCoin = repayResult;
6389
6411
  } else {
6390
- this.transferOrDestoryCoin(txb, repayResult, path.from, aggregatorV2PublishedAt);
6412
+ this.transferOrDestoryCoin(
6413
+ txb,
6414
+ repayResult,
6415
+ path.from,
6416
+ aggregatorV2PublishedAt
6417
+ );
6391
6418
  }
6392
6419
  if (j === router.path.length - 1) {
6393
6420
  targetCoins.push(nextRepayCoin);
@@ -6395,7 +6422,12 @@ var AggregatorClient19 = class {
6395
6422
  }
6396
6423
  }
6397
6424
  const inputCoinType = routers[0].path[0].from;
6398
- this.transferOrDestoryCoin(txb, inputCoin, inputCoinType, aggregatorV2PublishedAt);
6425
+ this.transferOrDestoryCoin(
6426
+ txb,
6427
+ inputCoin,
6428
+ inputCoinType,
6429
+ aggregatorV2PublishedAt
6430
+ );
6399
6431
  if (targetCoins.length > 1) {
6400
6432
  const vec = txb.makeMoveVec({ elements: targetCoins.slice(1) });
6401
6433
  txb.moveCall({
@@ -6421,14 +6453,7 @@ var AggregatorClient19 = class {
6421
6453
  }
6422
6454
  routerSwap(params) {
6423
6455
  return __async(this, null, function* () {
6424
- const {
6425
- routers,
6426
- inputCoin,
6427
- slippage,
6428
- txb,
6429
- partner,
6430
- deepbookv3DeepFee
6431
- } = params;
6456
+ const { routers, inputCoin, slippage, txb, partner, deepbookv3DeepFee } = params;
6432
6457
  const routerData = Array.isArray(routers) ? routers : routers.routes;
6433
6458
  const byAmountIn = isBuilderRouterSwapParams(params) ? params.byAmountIn : params.routers.byAmountIn;
6434
6459
  const amountIn = routerData.reduce(
@@ -6445,14 +6470,19 @@ var AggregatorClient19 = class {
6445
6470
  slippage
6446
6471
  );
6447
6472
  const packages = isBuilderRouterSwapParams(params) ? void 0 : params.routers.packages;
6448
- console.log("packages11", packages);
6449
- const aggregatorV2PublishedAt = getAggregatorV2PublishedAt(this.publishedAtV2(), packages);
6473
+ const aggregatorV2PublishedAt = getAggregatorV2PublishedAt(
6474
+ this.publishedAtV2(),
6475
+ packages
6476
+ );
6477
+ const priceIDs = findPythPriceIDs(routerData);
6478
+ const priceInfoObjectIds = priceIDs.length > 0 ? yield this.updatePythPriceIDs(priceIDs, txb) : /* @__PURE__ */ new Map();
6450
6479
  if (byAmountIn) {
6451
6480
  const targetCoin2 = yield this.expectInputSwap(
6452
6481
  txb,
6453
6482
  inputCoin,
6454
6483
  routerData,
6455
6484
  amountLimit,
6485
+ priceInfoObjectIds,
6456
6486
  partner,
6457
6487
  deepbookv3DeepFee,
6458
6488
  packages
@@ -6462,7 +6492,12 @@ var AggregatorClient19 = class {
6462
6492
  const splitedInputCoins = txb.splitCoins(inputCoin, [
6463
6493
  amountLimit.toString()
6464
6494
  ]);
6465
- this.transferOrDestoryCoin(txb, inputCoin, routerData[0].path[0].from, aggregatorV2PublishedAt);
6495
+ this.transferOrDestoryCoin(
6496
+ txb,
6497
+ inputCoin,
6498
+ routerData[0].path[0].from,
6499
+ aggregatorV2PublishedAt
6500
+ );
6466
6501
  const targetCoin = yield this.expectOutputSwap(
6467
6502
  txb,
6468
6503
  splitedInputCoins[0],
@@ -6548,7 +6583,10 @@ var AggregatorClient19 = class {
6548
6583
  targetCoinType
6549
6584
  );
6550
6585
  const packages = isBuilderFastRouterSwapParams(params) ? void 0 : params.routers.packages;
6551
- const aggregatorV2PublishedAt = getAggregatorV2PublishedAt(this.publishedAtV2(), packages);
6586
+ const aggregatorV2PublishedAt = getAggregatorV2PublishedAt(
6587
+ this.publishedAtV2(),
6588
+ packages
6589
+ );
6552
6590
  txb.mergeCoins(targetCoinRes.targetCoin, [targetCoin]);
6553
6591
  if (targetCoinRes.isMintZeroCoin) {
6554
6592
  this.transferOrDestoryCoin(
@@ -6564,7 +6602,7 @@ var AggregatorClient19 = class {
6564
6602
  // Include cetus、deepbookv2、flowxv2 & v3、kriyav2 & v3、turbos、aftermath、haedal、afsui、volo、bluemove
6565
6603
  publishedAtV2() {
6566
6604
  if (this.env === 0 /* Mainnet */) {
6567
- return "0xf9c6f78322ed667909e05f6b42b2f5a67af6297503c905335e02a15148e9440d";
6605
+ return "0x2485feb9d42c7c3bcb8ecde555ad40f1b073d9fb4faf354fa2d30a0b183a23ce";
6568
6606
  } else {
6569
6607
  return "0x52eae33adeb44de55cfb3f281d4cc9e02d976181c0952f5323648b5717b33934";
6570
6608
  }
@@ -6609,7 +6647,7 @@ var AggregatorClient19 = class {
6609
6647
  });
6610
6648
  return targetCoin;
6611
6649
  }
6612
- newDex(provider, partner) {
6650
+ newDex(provider, pythPriceIDs, partner) {
6613
6651
  switch (provider) {
6614
6652
  case CETUS:
6615
6653
  return new Cetus(this.env, partner);
@@ -6646,7 +6684,7 @@ var AggregatorClient19 = class {
6646
6684
  case BLUEFIN:
6647
6685
  return new Bluefin(this.env);
6648
6686
  case HAEDALPMM:
6649
- return new HaedalPmm(this.env, this.client);
6687
+ return new HaedalPmm(this.env, pythPriceIDs);
6650
6688
  case ALPHAFI:
6651
6689
  return new Alphafi(this.env);
6652
6690
  default:
@@ -6695,7 +6733,82 @@ var AggregatorClient19 = class {
6695
6733
  return null;
6696
6734
  });
6697
6735
  }
6736
+ updatePythPriceIDs(priceIDs, txb) {
6737
+ return __async(this, null, function* () {
6738
+ let priceUpdateData = null;
6739
+ let lastError = null;
6740
+ for (const connection of this.pythConnections) {
6741
+ try {
6742
+ priceUpdateData = yield connection.getPriceFeedsUpdateData(priceIDs);
6743
+ break;
6744
+ } catch (e) {
6745
+ lastError = e;
6746
+ console.log("Error: ", e);
6747
+ continue;
6748
+ }
6749
+ }
6750
+ if (priceUpdateData == null) {
6751
+ throw new Error(
6752
+ `No pyth price seeds update data found: ${lastError == null ? void 0 : lastError.message}`
6753
+ );
6754
+ }
6755
+ let priceInfoObjectIds = [];
6756
+ try {
6757
+ priceInfoObjectIds = yield this.pythClient.updatePriceFeeds(
6758
+ txb,
6759
+ priceUpdateData,
6760
+ priceIDs
6761
+ );
6762
+ } catch (e) {
6763
+ throw new Error(`Failed to update price feeds: ${e}`);
6764
+ }
6765
+ let priceInfoObjectIdsMap = /* @__PURE__ */ new Map();
6766
+ for (let i = 0; i < priceIDs.length; i++) {
6767
+ priceInfoObjectIdsMap.set(priceIDs[i], priceInfoObjectIds[i]);
6768
+ }
6769
+ return priceInfoObjectIdsMap;
6770
+ });
6771
+ }
6698
6772
  };
6773
+ _AggregatorClient.CONFIG = {
6774
+ [1 /* Testnet */]: {
6775
+ connections: [
6776
+ new pythSuiJs.SuiPriceServiceConnection("https://hermes-beta.pyth.network")
6777
+ ],
6778
+ wormholeStateId: "0x31358d198147da50db32eda2562951d53973a0c0ad5ed738e9b17d88b213d790",
6779
+ pythStateId: "0x243759059f4c3111179da5878c12f68d612c21a8d54d85edc86164bb18be1c7c"
6780
+ },
6781
+ [0 /* Mainnet */]: {
6782
+ connections: [
6783
+ new pythSuiJs.SuiPriceServiceConnection(
6784
+ "https://cetus.liquify.com/api=X9LTVPQD7Y3R5N2A/hermes",
6785
+ {
6786
+ timeout: 3e3
6787
+ }
6788
+ ),
6789
+ new pythSuiJs.SuiPriceServiceConnection("https://hermes.pyth.network", {
6790
+ timeout: 3e3
6791
+ })
6792
+ ],
6793
+ wormholeStateId: "0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c",
6794
+ pythStateId: "0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8"
6795
+ }
6796
+ };
6797
+ var AggregatorClient19 = _AggregatorClient;
6798
+ function findPythPriceIDs(routes) {
6799
+ const priceIDs = /* @__PURE__ */ new Set();
6800
+ for (const route of routes) {
6801
+ for (const path of route.path) {
6802
+ if (path.provider === HAEDALPMM) {
6803
+ if (path.extendedDetails && path.extendedDetails.haedalPmmBasePriceSeed && path.extendedDetails.haedalPmmQuotePriceSeed) {
6804
+ priceIDs.add(path.extendedDetails.haedalPmmBasePriceSeed);
6805
+ priceIDs.add(path.extendedDetails.haedalPmmQuotePriceSeed);
6806
+ }
6807
+ }
6808
+ }
6809
+ }
6810
+ return Array.from(priceIDs);
6811
+ }
6699
6812
  function parseRouterResponse(data, byAmountIn) {
6700
6813
  let totalDeepFee = 0;
6701
6814
  for (const route of data.routes) {
@@ -6920,7 +7033,7 @@ function getRouter(endpoint, params) {
6920
7033
  url += `&providers=${providers.join(",")}`;
6921
7034
  }
6922
7035
  }
6923
- url += "&v=1000321";
7036
+ url += "&v=1000323";
6924
7037
  const response = yield fetch(url);
6925
7038
  return response;
6926
7039
  } catch (error) {
@@ -7051,6 +7164,7 @@ exports.createTarget = createTarget;
7051
7164
  exports.dealWithFastRouterSwapParamsForMsafe = dealWithFastRouterSwapParamsForMsafe;
7052
7165
  exports.extractAddressFromType = extractAddressFromType;
7053
7166
  exports.extractStructTagFromType = extractStructTagFromType;
7167
+ exports.findPythPriceIDs = findPythPriceIDs;
7054
7168
  exports.fixSuiObjectId = fixSuiObjectId;
7055
7169
  exports.getAggregatorV2ExtendPublishedAt = getAggregatorV2ExtendPublishedAt;
7056
7170
  exports.getAggregatorV2PublishedAt = getAggregatorV2PublishedAt;