@cetusprotocol/aggregator-sdk 0.3.20 → 0.3.22

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
@@ -5936,10 +5936,7 @@ var Haedal = class {
5936
5936
  swap(client, txb, path, inputCoin, packages) {
5937
5937
  return __async(this, null, function* () {
5938
5938
  const { direction } = path;
5939
- if (!direction) {
5940
- throw new Error("Haedal not support b2a swap");
5941
- }
5942
- const func = "swap_a2b";
5939
+ const func = direction ? "swap_a2b" : "swap_b2a";
5943
5940
  const args = [txb.object(path.id), txb.object("0x5"), inputCoin];
5944
5941
  const publishedAt = getAggregatorV2PublishedAt(client.publishedAtV2(), packages);
5945
5942
  const res = txb.moveCall({
@@ -6173,19 +6170,14 @@ var Bluefin = class {
6173
6170
  });
6174
6171
  }
6175
6172
  };
6173
+
6174
+ // src/transaction/haedal_pmm.ts
6176
6175
  var HaedalPmm = class {
6177
- constructor(env, suiClient) {
6176
+ constructor(env, pythPriceIDs) {
6178
6177
  if (env === 1 /* Testnet */) {
6179
- this.connection = new pythSuiJs.SuiPriceServiceConnection("https://hermes-beta.pyth.network");
6180
- const wormholeStateId = "0x31358d198147da50db32eda2562951d53973a0c0ad5ed738e9b17d88b213d790";
6181
- const pythStateId = "0x243759059f4c3111179da5878c12f68d612c21a8d54d85edc86164bb18be1c7c";
6182
- this.pythClient = new pythSuiJs.SuiPythClient(suiClient, pythStateId, wormholeStateId);
6183
- } else {
6184
- this.connection = new pythSuiJs.SuiPriceServiceConnection("https://hermes.pyth.network");
6185
- const wormholeStateId = "0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c";
6186
- const pythStateId = "0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8";
6187
- this.pythClient = new pythSuiJs.SuiPythClient(suiClient, pythStateId, wormholeStateId);
6178
+ throw new Error("HaedalPmm is not supported on testnet");
6188
6179
  }
6180
+ this.pythPriceIDs = pythPriceIDs;
6189
6181
  }
6190
6182
  swap(client, txb, path, inputCoin, packages) {
6191
6183
  return __async(this, null, function* () {
@@ -6202,17 +6194,24 @@ var HaedalPmm = class {
6202
6194
  basePriceSeed = path.extendedDetails.haedalPmmBasePriceSeed;
6203
6195
  quotePriceSeed = path.extendedDetails.haedalPmmQuotePriceSeed;
6204
6196
  }
6205
- const priceIDs = [basePriceSeed, quotePriceSeed];
6206
- const priceUpdateData = yield this.connection.getPriceFeedsUpdateData(priceIDs);
6207
- const priceInfoObjectIds = yield this.pythClient.updatePriceFeeds(txb, priceUpdateData, priceIDs);
6197
+ const basePriceInfoObjectId = this.pythPriceIDs.get(basePriceSeed);
6198
+ const quotePriceInfoObjectId = this.pythPriceIDs.get(quotePriceSeed);
6199
+ if (!basePriceInfoObjectId || !quotePriceInfoObjectId) {
6200
+ throw new Error(
6201
+ "Base price info object id or quote price info object id not found"
6202
+ );
6203
+ }
6208
6204
  const args = [
6209
6205
  txb.object(path.id),
6210
- txb.object(priceInfoObjectIds[0]),
6211
- txb.object(priceInfoObjectIds[1]),
6206
+ txb.object(basePriceInfoObjectId),
6207
+ txb.object(quotePriceInfoObjectId),
6212
6208
  inputCoin,
6213
6209
  txb.object(CLOCK_ADDRESS)
6214
6210
  ];
6215
- const publishedAt = getAggregatorV2ExtendPublishedAt(client.publishedAtV2Extend(), packages);
6211
+ const publishedAt = getAggregatorV2ExtendPublishedAt(
6212
+ client.publishedAtV2Extend(),
6213
+ packages
6214
+ );
6216
6215
  const res = txb.moveCall({
6217
6216
  target: `${publishedAt}::haedalpmm::${func}`,
6218
6217
  typeArguments: [coinAType, coinBType],
@@ -6250,8 +6249,6 @@ var Alphafi = class {
6250
6249
  });
6251
6250
  }
6252
6251
  };
6253
-
6254
- // src/client.ts
6255
6252
  var CETUS = "CETUS";
6256
6253
  var DEEPBOOKV2 = "DEEPBOOK";
6257
6254
  var KRIYA = "KRIYA";
@@ -6278,13 +6275,20 @@ function isBuilderRouterSwapParams(params) {
6278
6275
  function isBuilderFastRouterSwapParams(params) {
6279
6276
  return Array.isArray(params.routers);
6280
6277
  }
6281
- var AggregatorClient19 = class {
6278
+ var _AggregatorClient = class _AggregatorClient {
6282
6279
  constructor(endpoint, signer, client$1, env) {
6283
6280
  this.endpoint = endpoint ? processEndpoint(endpoint) : DEFAULT_ENDPOINT;
6284
6281
  this.client = client$1 || new client.SuiClient({ url: client.getFullnodeUrl("mainnet") });
6285
6282
  this.signer = signer || "";
6286
6283
  this.env = env || 0 /* Mainnet */;
6287
6284
  this.allCoins = /* @__PURE__ */ new Map();
6285
+ const config2 = _AggregatorClient.CONFIG[this.env];
6286
+ this.pythConnections = config2.connections;
6287
+ this.pythClient = new pythSuiJs.SuiPythClient(
6288
+ this.client,
6289
+ config2.pythStateId,
6290
+ config2.wormholeStateId
6291
+ );
6288
6292
  }
6289
6293
  getCoins(coinType, refresh = true) {
6290
6294
  return __async(this, null, function* () {
@@ -6328,7 +6332,7 @@ var AggregatorClient19 = class {
6328
6332
  return getRouterResult(this.endpoint, params);
6329
6333
  });
6330
6334
  }
6331
- expectInputSwap(txb, inputCoin, routers, amountOutLimit, partner, deepbookv3DeepFee, packages) {
6335
+ expectInputSwap(txb, inputCoin, routers, amountOutLimit, pythPriceIDs, partner, deepbookv3DeepFee, packages) {
6332
6336
  return __async(this, null, function* () {
6333
6337
  if (routers.length === 0) {
6334
6338
  throw new Error("No router found");
@@ -6344,13 +6348,28 @@ var AggregatorClient19 = class {
6344
6348
  }
6345
6349
  let nextCoin = inputCoins[i];
6346
6350
  for (const path of routers[i].path) {
6347
- const dex = this.newDex(path.provider, partner);
6348
- nextCoin = yield dex.swap(this, txb, path, nextCoin, packages, deepbookv3DeepFee);
6351
+ const dex = this.newDex(path.provider, pythPriceIDs, partner);
6352
+ nextCoin = yield dex.swap(
6353
+ this,
6354
+ txb,
6355
+ path,
6356
+ nextCoin,
6357
+ packages,
6358
+ deepbookv3DeepFee
6359
+ );
6349
6360
  }
6350
6361
  outputCoins.push(nextCoin);
6351
6362
  }
6352
- const aggregatorV2PublishedAt = getAggregatorV2PublishedAt(this.publishedAtV2(), packages);
6353
- this.transferOrDestoryCoin(txb, inputCoin, inputCoinType, this.publishedAtV2());
6363
+ const aggregatorV2PublishedAt = getAggregatorV2PublishedAt(
6364
+ this.publishedAtV2(),
6365
+ packages
6366
+ );
6367
+ this.transferOrDestoryCoin(
6368
+ txb,
6369
+ inputCoin,
6370
+ inputCoinType,
6371
+ this.publishedAtV2()
6372
+ );
6354
6373
  const mergedTargetCointhis = this.checkCoinThresholdAndMergeCoin(
6355
6374
  txb,
6356
6375
  outputCoins,
@@ -6367,7 +6386,10 @@ var AggregatorClient19 = class {
6367
6386
  const receipts = [];
6368
6387
  const targetCoins = [];
6369
6388
  const dex = new Cetus(this.env, partner);
6370
- const aggregatorV2PublishedAt = getAggregatorV2PublishedAt(this.publishedAtV2(), packages);
6389
+ const aggregatorV2PublishedAt = getAggregatorV2PublishedAt(
6390
+ this.publishedAtV2(),
6391
+ packages
6392
+ );
6371
6393
  for (let i = 0; i < routers.length; i++) {
6372
6394
  const router = routers[i];
6373
6395
  for (let j = router.path.length - 1; j >= 0; j--) {
@@ -6390,7 +6412,12 @@ var AggregatorClient19 = class {
6390
6412
  if (j === 0) {
6391
6413
  inputCoin = repayResult;
6392
6414
  } else {
6393
- this.transferOrDestoryCoin(txb, repayResult, path.from, aggregatorV2PublishedAt);
6415
+ this.transferOrDestoryCoin(
6416
+ txb,
6417
+ repayResult,
6418
+ path.from,
6419
+ aggregatorV2PublishedAt
6420
+ );
6394
6421
  }
6395
6422
  if (j === router.path.length - 1) {
6396
6423
  targetCoins.push(nextRepayCoin);
@@ -6398,7 +6425,12 @@ var AggregatorClient19 = class {
6398
6425
  }
6399
6426
  }
6400
6427
  const inputCoinType = routers[0].path[0].from;
6401
- this.transferOrDestoryCoin(txb, inputCoin, inputCoinType, aggregatorV2PublishedAt);
6428
+ this.transferOrDestoryCoin(
6429
+ txb,
6430
+ inputCoin,
6431
+ inputCoinType,
6432
+ aggregatorV2PublishedAt
6433
+ );
6402
6434
  if (targetCoins.length > 1) {
6403
6435
  const vec = txb.makeMoveVec({ elements: targetCoins.slice(1) });
6404
6436
  txb.moveCall({
@@ -6424,14 +6456,7 @@ var AggregatorClient19 = class {
6424
6456
  }
6425
6457
  routerSwap(params) {
6426
6458
  return __async(this, null, function* () {
6427
- const {
6428
- routers,
6429
- inputCoin,
6430
- slippage,
6431
- txb,
6432
- partner,
6433
- deepbookv3DeepFee
6434
- } = params;
6459
+ const { routers, inputCoin, slippage, txb, partner, deepbookv3DeepFee } = params;
6435
6460
  const routerData = Array.isArray(routers) ? routers : routers.routes;
6436
6461
  const byAmountIn = isBuilderRouterSwapParams(params) ? params.byAmountIn : params.routers.byAmountIn;
6437
6462
  const amountIn = routerData.reduce(
@@ -6449,13 +6474,19 @@ var AggregatorClient19 = class {
6449
6474
  );
6450
6475
  const packages = isBuilderRouterSwapParams(params) ? void 0 : params.routers.packages;
6451
6476
  console.log("packages11", packages);
6452
- const aggregatorV2PublishedAt = getAggregatorV2PublishedAt(this.publishedAtV2(), packages);
6477
+ const aggregatorV2PublishedAt = getAggregatorV2PublishedAt(
6478
+ this.publishedAtV2(),
6479
+ packages
6480
+ );
6481
+ const priceIDs = findPythPriceIDs(routerData);
6482
+ const priceInfoObjectIds = priceIDs.length > 0 ? yield this.updatePythPriceIDs(priceIDs, txb) : /* @__PURE__ */ new Map();
6453
6483
  if (byAmountIn) {
6454
6484
  const targetCoin2 = yield this.expectInputSwap(
6455
6485
  txb,
6456
6486
  inputCoin,
6457
6487
  routerData,
6458
6488
  amountLimit,
6489
+ priceInfoObjectIds,
6459
6490
  partner,
6460
6491
  deepbookv3DeepFee,
6461
6492
  packages
@@ -6465,7 +6496,12 @@ var AggregatorClient19 = class {
6465
6496
  const splitedInputCoins = txb.splitCoins(inputCoin, [
6466
6497
  amountLimit.toString()
6467
6498
  ]);
6468
- this.transferOrDestoryCoin(txb, inputCoin, routerData[0].path[0].from, aggregatorV2PublishedAt);
6499
+ this.transferOrDestoryCoin(
6500
+ txb,
6501
+ inputCoin,
6502
+ routerData[0].path[0].from,
6503
+ aggregatorV2PublishedAt
6504
+ );
6469
6505
  const targetCoin = yield this.expectOutputSwap(
6470
6506
  txb,
6471
6507
  splitedInputCoins[0],
@@ -6551,7 +6587,10 @@ var AggregatorClient19 = class {
6551
6587
  targetCoinType
6552
6588
  );
6553
6589
  const packages = isBuilderFastRouterSwapParams(params) ? void 0 : params.routers.packages;
6554
- const aggregatorV2PublishedAt = getAggregatorV2PublishedAt(this.publishedAtV2(), packages);
6590
+ const aggregatorV2PublishedAt = getAggregatorV2PublishedAt(
6591
+ this.publishedAtV2(),
6592
+ packages
6593
+ );
6555
6594
  txb.mergeCoins(targetCoinRes.targetCoin, [targetCoin]);
6556
6595
  if (targetCoinRes.isMintZeroCoin) {
6557
6596
  this.transferOrDestoryCoin(
@@ -6567,7 +6606,7 @@ var AggregatorClient19 = class {
6567
6606
  // Include cetus、deepbookv2、flowxv2 & v3、kriyav2 & v3、turbos、aftermath、haedal、afsui、volo、bluemove
6568
6607
  publishedAtV2() {
6569
6608
  if (this.env === 0 /* Mainnet */) {
6570
- return "0x3fb42ddf908af45f9fc3c59eab227888ff24ba2e137b3b55bf80920fd47e11af";
6609
+ return "0xf9c6f78322ed667909e05f6b42b2f5a67af6297503c905335e02a15148e9440d";
6571
6610
  } else {
6572
6611
  return "0x52eae33adeb44de55cfb3f281d4cc9e02d976181c0952f5323648b5717b33934";
6573
6612
  }
@@ -6612,7 +6651,7 @@ var AggregatorClient19 = class {
6612
6651
  });
6613
6652
  return targetCoin;
6614
6653
  }
6615
- newDex(provider, partner) {
6654
+ newDex(provider, pythPriceIDs, partner) {
6616
6655
  switch (provider) {
6617
6656
  case CETUS:
6618
6657
  return new Cetus(this.env, partner);
@@ -6649,7 +6688,7 @@ var AggregatorClient19 = class {
6649
6688
  case BLUEFIN:
6650
6689
  return new Bluefin(this.env);
6651
6690
  case HAEDALPMM:
6652
- return new HaedalPmm(this.env, this.client);
6691
+ return new HaedalPmm(this.env, pythPriceIDs);
6653
6692
  case ALPHAFI:
6654
6693
  return new Alphafi(this.env);
6655
6694
  default:
@@ -6698,7 +6737,82 @@ var AggregatorClient19 = class {
6698
6737
  return null;
6699
6738
  });
6700
6739
  }
6740
+ updatePythPriceIDs(priceIDs, txb) {
6741
+ return __async(this, null, function* () {
6742
+ let priceUpdateData = null;
6743
+ let lastError = null;
6744
+ for (const connection of this.pythConnections) {
6745
+ try {
6746
+ priceUpdateData = yield connection.getPriceFeedsUpdateData(priceIDs);
6747
+ break;
6748
+ } catch (e) {
6749
+ lastError = e;
6750
+ console.log("Error: ", e);
6751
+ continue;
6752
+ }
6753
+ }
6754
+ if (priceUpdateData == null) {
6755
+ throw new Error(
6756
+ `No pyth price seeds update data found: ${lastError == null ? void 0 : lastError.message}`
6757
+ );
6758
+ }
6759
+ let priceInfoObjectIds = [];
6760
+ try {
6761
+ priceInfoObjectIds = yield this.pythClient.updatePriceFeeds(
6762
+ txb,
6763
+ priceUpdateData,
6764
+ priceIDs
6765
+ );
6766
+ } catch (e) {
6767
+ throw new Error(`Failed to update price feeds: ${e}`);
6768
+ }
6769
+ let priceInfoObjectIdsMap = /* @__PURE__ */ new Map();
6770
+ for (let i = 0; i < priceIDs.length; i++) {
6771
+ priceInfoObjectIdsMap.set(priceIDs[i], priceInfoObjectIds[i]);
6772
+ }
6773
+ return priceInfoObjectIdsMap;
6774
+ });
6775
+ }
6776
+ };
6777
+ _AggregatorClient.CONFIG = {
6778
+ [1 /* Testnet */]: {
6779
+ connections: [
6780
+ new pythSuiJs.SuiPriceServiceConnection("https://hermes-beta.pyth.network")
6781
+ ],
6782
+ wormholeStateId: "0x31358d198147da50db32eda2562951d53973a0c0ad5ed738e9b17d88b213d790",
6783
+ pythStateId: "0x243759059f4c3111179da5878c12f68d612c21a8d54d85edc86164bb18be1c7c"
6784
+ },
6785
+ [0 /* Mainnet */]: {
6786
+ connections: [
6787
+ new pythSuiJs.SuiPriceServiceConnection(
6788
+ "https://cetus.liquify.com/api=X9LTVPQD7Y3R5N2A/hermes",
6789
+ {
6790
+ timeout: 3e3
6791
+ }
6792
+ ),
6793
+ new pythSuiJs.SuiPriceServiceConnection("https://hermes.pyth.network", {
6794
+ timeout: 3e3
6795
+ })
6796
+ ],
6797
+ wormholeStateId: "0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c",
6798
+ pythStateId: "0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8"
6799
+ }
6701
6800
  };
6801
+ var AggregatorClient19 = _AggregatorClient;
6802
+ function findPythPriceIDs(routes) {
6803
+ const priceIDs = /* @__PURE__ */ new Set();
6804
+ for (const route of routes) {
6805
+ for (const path of route.path) {
6806
+ if (path.provider === HAEDALPMM) {
6807
+ if (path.extendedDetails && path.extendedDetails.haedalPmmBasePriceSeed && path.extendedDetails.haedalPmmQuotePriceSeed) {
6808
+ priceIDs.add(path.extendedDetails.haedalPmmBasePriceSeed);
6809
+ priceIDs.add(path.extendedDetails.haedalPmmQuotePriceSeed);
6810
+ }
6811
+ }
6812
+ }
6813
+ }
6814
+ return Array.from(priceIDs);
6815
+ }
6702
6816
  function parseRouterResponse(data, byAmountIn) {
6703
6817
  let totalDeepFee = 0;
6704
6818
  for (const route of data.routes) {
@@ -6923,7 +7037,7 @@ function getRouter(endpoint, params) {
6923
7037
  url += `&providers=${providers.join(",")}`;
6924
7038
  }
6925
7039
  }
6926
- url += "&v=1000320";
7040
+ url += "&v=1000322";
6927
7041
  const response = yield fetch(url);
6928
7042
  return response;
6929
7043
  } catch (error) {
@@ -7054,6 +7168,7 @@ exports.createTarget = createTarget;
7054
7168
  exports.dealWithFastRouterSwapParamsForMsafe = dealWithFastRouterSwapParamsForMsafe;
7055
7169
  exports.extractAddressFromType = extractAddressFromType;
7056
7170
  exports.extractStructTagFromType = extractStructTagFromType;
7171
+ exports.findPythPriceIDs = findPythPriceIDs;
7057
7172
  exports.fixSuiObjectId = fixSuiObjectId;
7058
7173
  exports.getAggregatorV2ExtendPublishedAt = getAggregatorV2ExtendPublishedAt;
7059
7174
  exports.getAggregatorV2PublishedAt = getAggregatorV2PublishedAt;