@cetusprotocol/aggregator-sdk 0.3.21 → 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
@@ -6170,19 +6170,14 @@ var Bluefin = class {
6170
6170
  });
6171
6171
  }
6172
6172
  };
6173
+
6174
+ // src/transaction/haedal_pmm.ts
6173
6175
  var HaedalPmm = class {
6174
- constructor(env, suiClient) {
6176
+ constructor(env, pythPriceIDs) {
6175
6177
  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);
6178
+ throw new Error("HaedalPmm is not supported on testnet");
6185
6179
  }
6180
+ this.pythPriceIDs = pythPriceIDs;
6186
6181
  }
6187
6182
  swap(client, txb, path, inputCoin, packages) {
6188
6183
  return __async(this, null, function* () {
@@ -6199,17 +6194,24 @@ var HaedalPmm = class {
6199
6194
  basePriceSeed = path.extendedDetails.haedalPmmBasePriceSeed;
6200
6195
  quotePriceSeed = path.extendedDetails.haedalPmmQuotePriceSeed;
6201
6196
  }
6202
- const priceIDs = [basePriceSeed, quotePriceSeed];
6203
- const priceUpdateData = yield this.connection.getPriceFeedsUpdateData(priceIDs);
6204
- 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
+ }
6205
6204
  const args = [
6206
6205
  txb.object(path.id),
6207
- txb.object(priceInfoObjectIds[0]),
6208
- txb.object(priceInfoObjectIds[1]),
6206
+ txb.object(basePriceInfoObjectId),
6207
+ txb.object(quotePriceInfoObjectId),
6209
6208
  inputCoin,
6210
6209
  txb.object(CLOCK_ADDRESS)
6211
6210
  ];
6212
- const publishedAt = getAggregatorV2ExtendPublishedAt(client.publishedAtV2Extend(), packages);
6211
+ const publishedAt = getAggregatorV2ExtendPublishedAt(
6212
+ client.publishedAtV2Extend(),
6213
+ packages
6214
+ );
6213
6215
  const res = txb.moveCall({
6214
6216
  target: `${publishedAt}::haedalpmm::${func}`,
6215
6217
  typeArguments: [coinAType, coinBType],
@@ -6247,8 +6249,6 @@ var Alphafi = class {
6247
6249
  });
6248
6250
  }
6249
6251
  };
6250
-
6251
- // src/client.ts
6252
6252
  var CETUS = "CETUS";
6253
6253
  var DEEPBOOKV2 = "DEEPBOOK";
6254
6254
  var KRIYA = "KRIYA";
@@ -6275,13 +6275,20 @@ function isBuilderRouterSwapParams(params) {
6275
6275
  function isBuilderFastRouterSwapParams(params) {
6276
6276
  return Array.isArray(params.routers);
6277
6277
  }
6278
- var AggregatorClient19 = class {
6278
+ var _AggregatorClient = class _AggregatorClient {
6279
6279
  constructor(endpoint, signer, client$1, env) {
6280
6280
  this.endpoint = endpoint ? processEndpoint(endpoint) : DEFAULT_ENDPOINT;
6281
6281
  this.client = client$1 || new client.SuiClient({ url: client.getFullnodeUrl("mainnet") });
6282
6282
  this.signer = signer || "";
6283
6283
  this.env = env || 0 /* Mainnet */;
6284
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
+ );
6285
6292
  }
6286
6293
  getCoins(coinType, refresh = true) {
6287
6294
  return __async(this, null, function* () {
@@ -6325,7 +6332,7 @@ var AggregatorClient19 = class {
6325
6332
  return getRouterResult(this.endpoint, params);
6326
6333
  });
6327
6334
  }
6328
- expectInputSwap(txb, inputCoin, routers, amountOutLimit, partner, deepbookv3DeepFee, packages) {
6335
+ expectInputSwap(txb, inputCoin, routers, amountOutLimit, pythPriceIDs, partner, deepbookv3DeepFee, packages) {
6329
6336
  return __async(this, null, function* () {
6330
6337
  if (routers.length === 0) {
6331
6338
  throw new Error("No router found");
@@ -6341,13 +6348,28 @@ var AggregatorClient19 = class {
6341
6348
  }
6342
6349
  let nextCoin = inputCoins[i];
6343
6350
  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);
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
+ );
6346
6360
  }
6347
6361
  outputCoins.push(nextCoin);
6348
6362
  }
6349
- const aggregatorV2PublishedAt = getAggregatorV2PublishedAt(this.publishedAtV2(), packages);
6350
- 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
+ );
6351
6373
  const mergedTargetCointhis = this.checkCoinThresholdAndMergeCoin(
6352
6374
  txb,
6353
6375
  outputCoins,
@@ -6364,7 +6386,10 @@ var AggregatorClient19 = class {
6364
6386
  const receipts = [];
6365
6387
  const targetCoins = [];
6366
6388
  const dex = new Cetus(this.env, partner);
6367
- const aggregatorV2PublishedAt = getAggregatorV2PublishedAt(this.publishedAtV2(), packages);
6389
+ const aggregatorV2PublishedAt = getAggregatorV2PublishedAt(
6390
+ this.publishedAtV2(),
6391
+ packages
6392
+ );
6368
6393
  for (let i = 0; i < routers.length; i++) {
6369
6394
  const router = routers[i];
6370
6395
  for (let j = router.path.length - 1; j >= 0; j--) {
@@ -6387,7 +6412,12 @@ var AggregatorClient19 = class {
6387
6412
  if (j === 0) {
6388
6413
  inputCoin = repayResult;
6389
6414
  } else {
6390
- this.transferOrDestoryCoin(txb, repayResult, path.from, aggregatorV2PublishedAt);
6415
+ this.transferOrDestoryCoin(
6416
+ txb,
6417
+ repayResult,
6418
+ path.from,
6419
+ aggregatorV2PublishedAt
6420
+ );
6391
6421
  }
6392
6422
  if (j === router.path.length - 1) {
6393
6423
  targetCoins.push(nextRepayCoin);
@@ -6395,7 +6425,12 @@ var AggregatorClient19 = class {
6395
6425
  }
6396
6426
  }
6397
6427
  const inputCoinType = routers[0].path[0].from;
6398
- this.transferOrDestoryCoin(txb, inputCoin, inputCoinType, aggregatorV2PublishedAt);
6428
+ this.transferOrDestoryCoin(
6429
+ txb,
6430
+ inputCoin,
6431
+ inputCoinType,
6432
+ aggregatorV2PublishedAt
6433
+ );
6399
6434
  if (targetCoins.length > 1) {
6400
6435
  const vec = txb.makeMoveVec({ elements: targetCoins.slice(1) });
6401
6436
  txb.moveCall({
@@ -6421,14 +6456,7 @@ var AggregatorClient19 = class {
6421
6456
  }
6422
6457
  routerSwap(params) {
6423
6458
  return __async(this, null, function* () {
6424
- const {
6425
- routers,
6426
- inputCoin,
6427
- slippage,
6428
- txb,
6429
- partner,
6430
- deepbookv3DeepFee
6431
- } = params;
6459
+ const { routers, inputCoin, slippage, txb, partner, deepbookv3DeepFee } = params;
6432
6460
  const routerData = Array.isArray(routers) ? routers : routers.routes;
6433
6461
  const byAmountIn = isBuilderRouterSwapParams(params) ? params.byAmountIn : params.routers.byAmountIn;
6434
6462
  const amountIn = routerData.reduce(
@@ -6446,13 +6474,19 @@ var AggregatorClient19 = class {
6446
6474
  );
6447
6475
  const packages = isBuilderRouterSwapParams(params) ? void 0 : params.routers.packages;
6448
6476
  console.log("packages11", packages);
6449
- 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();
6450
6483
  if (byAmountIn) {
6451
6484
  const targetCoin2 = yield this.expectInputSwap(
6452
6485
  txb,
6453
6486
  inputCoin,
6454
6487
  routerData,
6455
6488
  amountLimit,
6489
+ priceInfoObjectIds,
6456
6490
  partner,
6457
6491
  deepbookv3DeepFee,
6458
6492
  packages
@@ -6462,7 +6496,12 @@ var AggregatorClient19 = class {
6462
6496
  const splitedInputCoins = txb.splitCoins(inputCoin, [
6463
6497
  amountLimit.toString()
6464
6498
  ]);
6465
- 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
+ );
6466
6505
  const targetCoin = yield this.expectOutputSwap(
6467
6506
  txb,
6468
6507
  splitedInputCoins[0],
@@ -6548,7 +6587,10 @@ var AggregatorClient19 = class {
6548
6587
  targetCoinType
6549
6588
  );
6550
6589
  const packages = isBuilderFastRouterSwapParams(params) ? void 0 : params.routers.packages;
6551
- const aggregatorV2PublishedAt = getAggregatorV2PublishedAt(this.publishedAtV2(), packages);
6590
+ const aggregatorV2PublishedAt = getAggregatorV2PublishedAt(
6591
+ this.publishedAtV2(),
6592
+ packages
6593
+ );
6552
6594
  txb.mergeCoins(targetCoinRes.targetCoin, [targetCoin]);
6553
6595
  if (targetCoinRes.isMintZeroCoin) {
6554
6596
  this.transferOrDestoryCoin(
@@ -6609,7 +6651,7 @@ var AggregatorClient19 = class {
6609
6651
  });
6610
6652
  return targetCoin;
6611
6653
  }
6612
- newDex(provider, partner) {
6654
+ newDex(provider, pythPriceIDs, partner) {
6613
6655
  switch (provider) {
6614
6656
  case CETUS:
6615
6657
  return new Cetus(this.env, partner);
@@ -6646,7 +6688,7 @@ var AggregatorClient19 = class {
6646
6688
  case BLUEFIN:
6647
6689
  return new Bluefin(this.env);
6648
6690
  case HAEDALPMM:
6649
- return new HaedalPmm(this.env, this.client);
6691
+ return new HaedalPmm(this.env, pythPriceIDs);
6650
6692
  case ALPHAFI:
6651
6693
  return new Alphafi(this.env);
6652
6694
  default:
@@ -6695,7 +6737,82 @@ var AggregatorClient19 = class {
6695
6737
  return null;
6696
6738
  });
6697
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
+ }
6698
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
+ }
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
+ }
6699
6816
  function parseRouterResponse(data, byAmountIn) {
6700
6817
  let totalDeepFee = 0;
6701
6818
  for (const route of data.routes) {
@@ -6920,7 +7037,7 @@ function getRouter(endpoint, params) {
6920
7037
  url += `&providers=${providers.join(",")}`;
6921
7038
  }
6922
7039
  }
6923
- url += "&v=1000321";
7040
+ url += "&v=1000322";
6924
7041
  const response = yield fetch(url);
6925
7042
  return response;
6926
7043
  } catch (error) {
@@ -7051,6 +7168,7 @@ exports.createTarget = createTarget;
7051
7168
  exports.dealWithFastRouterSwapParamsForMsafe = dealWithFastRouterSwapParamsForMsafe;
7052
7169
  exports.extractAddressFromType = extractAddressFromType;
7053
7170
  exports.extractStructTagFromType = extractStructTagFromType;
7171
+ exports.findPythPriceIDs = findPythPriceIDs;
7054
7172
  exports.fixSuiObjectId = fixSuiObjectId;
7055
7173
  exports.getAggregatorV2ExtendPublishedAt = getAggregatorV2ExtendPublishedAt;
7056
7174
  exports.getAggregatorV2PublishedAt = getAggregatorV2PublishedAt;