@cetusprotocol/aggregator-sdk 0.3.12 → 0.3.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -76,6 +76,7 @@ declare const DEEPBOOKV3 = "DEEPBOOKV3";
76
76
  declare const SCALLOP = "SCALLOP";
77
77
  declare const SUILEND = "SUILEND";
78
78
  declare const BLUEFIN = "BLUEFIN";
79
+ declare const HAEDALPMM = "HAEDALPMM";
79
80
  declare const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
80
81
  type BuildRouterSwapParams = {
81
82
  routers: Router[];
@@ -216,8 +217,8 @@ type Path = {
216
217
  from: string;
217
218
  target: string;
218
219
  feeRate: number;
219
- amountIn: number;
220
- amountOut: number;
220
+ amountIn: string;
221
+ amountOut: string;
221
222
  version?: string;
222
223
  extendedDetails?: ExtendedDetails;
223
224
  };
@@ -269,4 +270,4 @@ declare enum Env {
269
270
  Testnet = 1
270
271
  }
271
272
 
272
- export { AFSUI, AFTERMATH, AggregatorClient, type AggregatorResponse, BLUEFIN, BLUEMOVE, type BuildCoinResult, type BuildFastRouterSwapParams, type BuildRouterSwapParams, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, type DeepbookV3Config, type DeepbookV3ConfigResponse, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWXV3, type FindRouterParams, HAEDAL, KRIYA, KRIYAV3, ONE, type Path, type PreSwapLpChangeParams, type Router, type RouterData, type RouterError, SCALLOP, 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, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
273
+ export { AFSUI, AFTERMATH, AggregatorClient, type AggregatorResponse, BLUEFIN, BLUEMOVE, type BuildCoinResult, type BuildFastRouterSwapParams, type BuildRouterSwapParams, 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, 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, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
package/dist/index.d.ts CHANGED
@@ -76,6 +76,7 @@ declare const DEEPBOOKV3 = "DEEPBOOKV3";
76
76
  declare const SCALLOP = "SCALLOP";
77
77
  declare const SUILEND = "SUILEND";
78
78
  declare const BLUEFIN = "BLUEFIN";
79
+ declare const HAEDALPMM = "HAEDALPMM";
79
80
  declare const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
80
81
  type BuildRouterSwapParams = {
81
82
  routers: Router[];
@@ -216,8 +217,8 @@ type Path = {
216
217
  from: string;
217
218
  target: string;
218
219
  feeRate: number;
219
- amountIn: number;
220
- amountOut: number;
220
+ amountIn: string;
221
+ amountOut: string;
221
222
  version?: string;
222
223
  extendedDetails?: ExtendedDetails;
223
224
  };
@@ -269,4 +270,4 @@ declare enum Env {
269
270
  Testnet = 1
270
271
  }
271
272
 
272
- export { AFSUI, AFTERMATH, AggregatorClient, type AggregatorResponse, BLUEFIN, BLUEMOVE, type BuildCoinResult, type BuildFastRouterSwapParams, type BuildRouterSwapParams, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, type DeepbookV3Config, type DeepbookV3ConfigResponse, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWXV3, type FindRouterParams, HAEDAL, KRIYA, KRIYAV3, ONE, type Path, type PreSwapLpChangeParams, type Router, type RouterData, type RouterError, SCALLOP, 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, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
273
+ export { AFSUI, AFTERMATH, AggregatorClient, type AggregatorResponse, BLUEFIN, BLUEMOVE, type BuildCoinResult, type BuildFastRouterSwapParams, type BuildRouterSwapParams, 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, 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, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@
3
3
  var client = require('@mysten/sui/client');
4
4
  var utils = require('@mysten/sui/utils');
5
5
  var transactions = require('@mysten/sui/transactions');
6
+ var pythSuiJs = require('@pythnetwork/pyth-sui-js');
6
7
 
7
8
  var __create = Object.create;
8
9
  var __defProp = Object.defineProperty;
@@ -4998,9 +4999,7 @@ var Aftermath = class {
4998
4999
  this.referrealVault = "0x35d35b0e5b177593d8c3a801462485572fc30861e6ce96a55af6dc4730709278";
4999
5000
  }
5000
5001
  amountLimit(exportAmountOut) {
5001
- return Number(
5002
- new import_bn.default(exportAmountOut).mul(new import_bn.default(this.slippage)).div(new import_bn.default("1000000000000000000")).toString()
5003
- );
5002
+ return new import_bn.default(exportAmountOut).mul(new import_bn.default(this.slippage)).div(new import_bn.default("1000000000000000000")).toString();
5004
5003
  }
5005
5004
  swap(client, txb, path, inputCoin) {
5006
5005
  return __async(this, null, function* () {
@@ -5847,6 +5846,7 @@ function swapInPools(client, params, sender, env) {
5847
5846
  }
5848
5847
  }
5849
5848
  const event = valueData[tempIndex].parsedJson.data;
5849
+ console.log("event", JSON.stringify(event, null, 2));
5850
5850
  const currentSqrtPrice = event.step_results[0].current_sqrt_price;
5851
5851
  const [decimalA, decimalB] = yield Promise.all([
5852
5852
  client.getCoinMetadata({ coinType: coinA }).then((metadata) => metadata == null ? void 0 : metadata.decimals),
@@ -5863,9 +5863,13 @@ function swapInPools(client, params, sender, env) {
5863
5863
  decimalA,
5864
5864
  decimalB
5865
5865
  );
5866
+ const feeRate = Number(event.fee_rate) / 1e6;
5867
+ const pureAmountIn = new import_bn4.BN((_b = event.amount_in) != null ? _b : 0);
5868
+ const feeAmount = new import_bn4.BN((_c = event.fee_amount) != null ? _c : 0);
5869
+ const amountIn = pureAmountIn.add(feeAmount);
5866
5870
  const routeData = {
5867
- amountIn: new import_bn4.BN((_b = event.amount_in) != null ? _b : 0),
5868
- amountOut: new import_bn4.BN((_c = event.amount_out) != null ? _c : 0),
5871
+ amountIn,
5872
+ amountOut: new import_bn4.BN((_d = event.amount_out) != null ? _d : 0),
5869
5873
  routes: [
5870
5874
  {
5871
5875
  path: [
@@ -5875,7 +5879,7 @@ function swapInPools(client, params, sender, env) {
5875
5879
  provider: "CETUS",
5876
5880
  from: fromCoin,
5877
5881
  target: targetCoin,
5878
- feeRate: event.fee_rate,
5882
+ feeRate,
5879
5883
  amountIn: event.amount_in,
5880
5884
  amountOut: event.amount_out,
5881
5885
  extendedDetails: {
@@ -5883,7 +5887,7 @@ function swapInPools(client, params, sender, env) {
5883
5887
  }
5884
5888
  }
5885
5889
  ],
5886
- amountIn: new import_bn4.BN((_d = event.amount_in) != null ? _d : 0),
5890
+ amountIn,
5887
5891
  amountOut: new import_bn4.BN((_e = event.amount_out) != null ? _e : 0),
5888
5892
  initialPrice
5889
5893
  }
@@ -6138,6 +6142,54 @@ var Bluefin = class {
6138
6142
  });
6139
6143
  }
6140
6144
  };
6145
+ var HaedalPmm = class {
6146
+ constructor(env, suiClient) {
6147
+ if (env === 1 /* Testnet */) {
6148
+ this.connection = new pythSuiJs.SuiPriceServiceConnection("https://hermes-beta.pyth.network");
6149
+ const wormholeStateId = "0x31358d198147da50db32eda2562951d53973a0c0ad5ed738e9b17d88b213d790";
6150
+ const pythStateId = "0x243759059f4c3111179da5878c12f68d612c21a8d54d85edc86164bb18be1c7c";
6151
+ this.pythClient = new pythSuiJs.SuiPythClient(suiClient, pythStateId, wormholeStateId);
6152
+ } else {
6153
+ this.connection = new pythSuiJs.SuiPriceServiceConnection("https://hermes.pyth.network");
6154
+ const wormholeStateId = "0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c";
6155
+ const pythStateId = "0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8";
6156
+ this.pythClient = new pythSuiJs.SuiPythClient(suiClient, pythStateId, wormholeStateId);
6157
+ }
6158
+ }
6159
+ swap(client, txb, path, inputCoin) {
6160
+ return __async(this, null, function* () {
6161
+ const { direction, from, target } = path;
6162
+ const [func, coinAType, coinBType] = direction ? ["swap_a2b", from, target] : ["swap_b2a", target, from];
6163
+ let basePriceSeed;
6164
+ let quotePriceSeed;
6165
+ if (path.extendedDetails == null) {
6166
+ throw new Error("Extended details not supported haedal pmm");
6167
+ } else {
6168
+ if (!path.extendedDetails.haedalPmmBasePriceSeed || !path.extendedDetails.haedalPmmQuotePriceSeed) {
6169
+ throw new Error("Base price seed or quote price seed not supported");
6170
+ }
6171
+ basePriceSeed = path.extendedDetails.haedalPmmBasePriceSeed;
6172
+ quotePriceSeed = path.extendedDetails.haedalPmmQuotePriceSeed;
6173
+ }
6174
+ const priceIDs = [basePriceSeed, quotePriceSeed];
6175
+ const priceUpdateData = yield this.connection.getPriceFeedsUpdateData(priceIDs);
6176
+ const priceInfoObjectIds = yield this.pythClient.updatePriceFeeds(txb, priceUpdateData, priceIDs);
6177
+ const args = [
6178
+ txb.object(path.id),
6179
+ txb.object(priceInfoObjectIds[0]),
6180
+ txb.object(priceInfoObjectIds[1]),
6181
+ inputCoin,
6182
+ txb.object(CLOCK_ADDRESS)
6183
+ ];
6184
+ const res = txb.moveCall({
6185
+ target: `${client.publishedAtV2()}::haedalpmm::${func}`,
6186
+ typeArguments: [coinAType, coinBType],
6187
+ arguments: args
6188
+ });
6189
+ return res;
6190
+ });
6191
+ }
6192
+ };
6141
6193
 
6142
6194
  // src/client.ts
6143
6195
  var CETUS = "CETUS";
@@ -6156,8 +6208,9 @@ var DEEPBOOKV3 = "DEEPBOOKV3";
6156
6208
  var SCALLOP = "SCALLOP";
6157
6209
  var SUILEND = "SUILEND";
6158
6210
  var BLUEFIN = "BLUEFIN";
6211
+ var HAEDALPMM = "HAEDALPMM";
6159
6212
  var DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
6160
- var AggregatorClient9 = class {
6213
+ var AggregatorClient10 = class {
6161
6214
  constructor(endpoint, signer, client$1, env) {
6162
6215
  this.endpoint = endpoint ? processEndpoint(endpoint) : DEFAULT_ENDPOINT;
6163
6216
  this.client = client$1 || new client.SuiClient({ url: client.getFullnodeUrl("mainnet") });
@@ -6434,7 +6487,7 @@ var AggregatorClient9 = class {
6434
6487
  // Include deepbookv3, scallop, bluefin
6435
6488
  publishedAtV2() {
6436
6489
  if (this.env === 0 /* Mainnet */) {
6437
- return "0x81ade554cb24a7564ca43a4bfb7381b08d9e5c5f375162c95215b696ab903502";
6490
+ return "0x347dd58bbd11cd82c8b386b344729717c04a998da73386e82a239cc196d5706b";
6438
6491
  } else {
6439
6492
  return "0xabb6a81c8a216828e317719e06125de5bb2cb0fe8f9916ff8c023ca5be224c78";
6440
6493
  }
@@ -6505,6 +6558,8 @@ var AggregatorClient9 = class {
6505
6558
  return new Suilend(this.env);
6506
6559
  case BLUEFIN:
6507
6560
  return new Bluefin(this.env);
6561
+ case HAEDALPMM:
6562
+ return new HaedalPmm(this.env, this.client);
6508
6563
  default:
6509
6564
  throw new Error(`Unsupported dex ${provider}`);
6510
6565
  }
@@ -6574,7 +6629,7 @@ function parseRouterResponse(data) {
6574
6629
  version = path.extended_details.aftermath_pool_flatness === 0 ? "v2" : "v3";
6575
6630
  }
6576
6631
  let extendedDetails;
6577
- if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS || path.provider === DEEPBOOKV3 || path.provider === SCALLOP) {
6632
+ if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS || path.provider === DEEPBOOKV3 || path.provider === SCALLOP || path.provider === HAEDALPMM) {
6578
6633
  extendedDetails = {
6579
6634
  aftermathLpSupplyType: (_a = path.extended_details) == null ? void 0 : _a.aftermath_lp_supply_type,
6580
6635
  turbosFeeType: (_b = path.extended_details) == null ? void 0 : _b.turbos_fee_type,
@@ -6816,7 +6871,7 @@ decimal.js/decimal.mjs:
6816
6871
 
6817
6872
  exports.AFSUI = AFSUI;
6818
6873
  exports.AFTERMATH = AFTERMATH;
6819
- exports.AggregatorClient = AggregatorClient9;
6874
+ exports.AggregatorClient = AggregatorClient10;
6820
6875
  exports.BLUEFIN = BLUEFIN;
6821
6876
  exports.BLUEMOVE = BLUEMOVE;
6822
6877
  exports.CETUS = CETUS;
@@ -6828,6 +6883,7 @@ exports.Env = Env;
6828
6883
  exports.FLOWXV2 = FLOWXV2;
6829
6884
  exports.FLOWXV3 = FLOWXV3;
6830
6885
  exports.HAEDAL = HAEDAL;
6886
+ exports.HAEDALPMM = HAEDALPMM;
6831
6887
  exports.KRIYA = KRIYA;
6832
6888
  exports.KRIYAV3 = KRIYAV3;
6833
6889
  exports.ONE = ONE;
package/dist/index.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import { SuiClient, getFullnodeUrl } from '@mysten/sui/client';
2
2
  import { normalizeSuiObjectId, SUI_FRAMEWORK_ADDRESS } from '@mysten/sui/utils';
3
3
  import { Transaction } from '@mysten/sui/transactions';
4
+ import { SuiPriceServiceConnection, SuiPythClient } from '@pythnetwork/pyth-sui-js';
4
5
 
5
6
  var __create = Object.create;
6
7
  var __defProp = Object.defineProperty;
@@ -4996,9 +4997,7 @@ var Aftermath = class {
4996
4997
  this.referrealVault = "0x35d35b0e5b177593d8c3a801462485572fc30861e6ce96a55af6dc4730709278";
4997
4998
  }
4998
4999
  amountLimit(exportAmountOut) {
4999
- return Number(
5000
- new import_bn.default(exportAmountOut).mul(new import_bn.default(this.slippage)).div(new import_bn.default("1000000000000000000")).toString()
5001
- );
5000
+ return new import_bn.default(exportAmountOut).mul(new import_bn.default(this.slippage)).div(new import_bn.default("1000000000000000000")).toString();
5002
5001
  }
5003
5002
  swap(client, txb, path, inputCoin) {
5004
5003
  return __async(this, null, function* () {
@@ -5845,6 +5844,7 @@ function swapInPools(client, params, sender, env) {
5845
5844
  }
5846
5845
  }
5847
5846
  const event = valueData[tempIndex].parsedJson.data;
5847
+ console.log("event", JSON.stringify(event, null, 2));
5848
5848
  const currentSqrtPrice = event.step_results[0].current_sqrt_price;
5849
5849
  const [decimalA, decimalB] = yield Promise.all([
5850
5850
  client.getCoinMetadata({ coinType: coinA }).then((metadata) => metadata == null ? void 0 : metadata.decimals),
@@ -5861,9 +5861,13 @@ function swapInPools(client, params, sender, env) {
5861
5861
  decimalA,
5862
5862
  decimalB
5863
5863
  );
5864
+ const feeRate = Number(event.fee_rate) / 1e6;
5865
+ const pureAmountIn = new import_bn4.BN((_b = event.amount_in) != null ? _b : 0);
5866
+ const feeAmount = new import_bn4.BN((_c = event.fee_amount) != null ? _c : 0);
5867
+ const amountIn = pureAmountIn.add(feeAmount);
5864
5868
  const routeData = {
5865
- amountIn: new import_bn4.BN((_b = event.amount_in) != null ? _b : 0),
5866
- amountOut: new import_bn4.BN((_c = event.amount_out) != null ? _c : 0),
5869
+ amountIn,
5870
+ amountOut: new import_bn4.BN((_d = event.amount_out) != null ? _d : 0),
5867
5871
  routes: [
5868
5872
  {
5869
5873
  path: [
@@ -5873,7 +5877,7 @@ function swapInPools(client, params, sender, env) {
5873
5877
  provider: "CETUS",
5874
5878
  from: fromCoin,
5875
5879
  target: targetCoin,
5876
- feeRate: event.fee_rate,
5880
+ feeRate,
5877
5881
  amountIn: event.amount_in,
5878
5882
  amountOut: event.amount_out,
5879
5883
  extendedDetails: {
@@ -5881,7 +5885,7 @@ function swapInPools(client, params, sender, env) {
5881
5885
  }
5882
5886
  }
5883
5887
  ],
5884
- amountIn: new import_bn4.BN((_d = event.amount_in) != null ? _d : 0),
5888
+ amountIn,
5885
5889
  amountOut: new import_bn4.BN((_e = event.amount_out) != null ? _e : 0),
5886
5890
  initialPrice
5887
5891
  }
@@ -6136,6 +6140,54 @@ var Bluefin = class {
6136
6140
  });
6137
6141
  }
6138
6142
  };
6143
+ var HaedalPmm = class {
6144
+ constructor(env, suiClient) {
6145
+ if (env === 1 /* Testnet */) {
6146
+ this.connection = new SuiPriceServiceConnection("https://hermes-beta.pyth.network");
6147
+ const wormholeStateId = "0x31358d198147da50db32eda2562951d53973a0c0ad5ed738e9b17d88b213d790";
6148
+ const pythStateId = "0x243759059f4c3111179da5878c12f68d612c21a8d54d85edc86164bb18be1c7c";
6149
+ this.pythClient = new SuiPythClient(suiClient, pythStateId, wormholeStateId);
6150
+ } else {
6151
+ this.connection = new SuiPriceServiceConnection("https://hermes.pyth.network");
6152
+ const wormholeStateId = "0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c";
6153
+ const pythStateId = "0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8";
6154
+ this.pythClient = new SuiPythClient(suiClient, pythStateId, wormholeStateId);
6155
+ }
6156
+ }
6157
+ swap(client, txb, path, inputCoin) {
6158
+ return __async(this, null, function* () {
6159
+ const { direction, from, target } = path;
6160
+ const [func, coinAType, coinBType] = direction ? ["swap_a2b", from, target] : ["swap_b2a", target, from];
6161
+ let basePriceSeed;
6162
+ let quotePriceSeed;
6163
+ if (path.extendedDetails == null) {
6164
+ throw new Error("Extended details not supported haedal pmm");
6165
+ } else {
6166
+ if (!path.extendedDetails.haedalPmmBasePriceSeed || !path.extendedDetails.haedalPmmQuotePriceSeed) {
6167
+ throw new Error("Base price seed or quote price seed not supported");
6168
+ }
6169
+ basePriceSeed = path.extendedDetails.haedalPmmBasePriceSeed;
6170
+ quotePriceSeed = path.extendedDetails.haedalPmmQuotePriceSeed;
6171
+ }
6172
+ const priceIDs = [basePriceSeed, quotePriceSeed];
6173
+ const priceUpdateData = yield this.connection.getPriceFeedsUpdateData(priceIDs);
6174
+ const priceInfoObjectIds = yield this.pythClient.updatePriceFeeds(txb, priceUpdateData, priceIDs);
6175
+ const args = [
6176
+ txb.object(path.id),
6177
+ txb.object(priceInfoObjectIds[0]),
6178
+ txb.object(priceInfoObjectIds[1]),
6179
+ inputCoin,
6180
+ txb.object(CLOCK_ADDRESS)
6181
+ ];
6182
+ const res = txb.moveCall({
6183
+ target: `${client.publishedAtV2()}::haedalpmm::${func}`,
6184
+ typeArguments: [coinAType, coinBType],
6185
+ arguments: args
6186
+ });
6187
+ return res;
6188
+ });
6189
+ }
6190
+ };
6139
6191
 
6140
6192
  // src/client.ts
6141
6193
  var CETUS = "CETUS";
@@ -6154,8 +6206,9 @@ var DEEPBOOKV3 = "DEEPBOOKV3";
6154
6206
  var SCALLOP = "SCALLOP";
6155
6207
  var SUILEND = "SUILEND";
6156
6208
  var BLUEFIN = "BLUEFIN";
6209
+ var HAEDALPMM = "HAEDALPMM";
6157
6210
  var DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
6158
- var AggregatorClient9 = class {
6211
+ var AggregatorClient10 = class {
6159
6212
  constructor(endpoint, signer, client, env) {
6160
6213
  this.endpoint = endpoint ? processEndpoint(endpoint) : DEFAULT_ENDPOINT;
6161
6214
  this.client = client || new SuiClient({ url: getFullnodeUrl("mainnet") });
@@ -6432,7 +6485,7 @@ var AggregatorClient9 = class {
6432
6485
  // Include deepbookv3, scallop, bluefin
6433
6486
  publishedAtV2() {
6434
6487
  if (this.env === 0 /* Mainnet */) {
6435
- return "0x81ade554cb24a7564ca43a4bfb7381b08d9e5c5f375162c95215b696ab903502";
6488
+ return "0x347dd58bbd11cd82c8b386b344729717c04a998da73386e82a239cc196d5706b";
6436
6489
  } else {
6437
6490
  return "0xabb6a81c8a216828e317719e06125de5bb2cb0fe8f9916ff8c023ca5be224c78";
6438
6491
  }
@@ -6503,6 +6556,8 @@ var AggregatorClient9 = class {
6503
6556
  return new Suilend(this.env);
6504
6557
  case BLUEFIN:
6505
6558
  return new Bluefin(this.env);
6559
+ case HAEDALPMM:
6560
+ return new HaedalPmm(this.env, this.client);
6506
6561
  default:
6507
6562
  throw new Error(`Unsupported dex ${provider}`);
6508
6563
  }
@@ -6572,7 +6627,7 @@ function parseRouterResponse(data) {
6572
6627
  version = path.extended_details.aftermath_pool_flatness === 0 ? "v2" : "v3";
6573
6628
  }
6574
6629
  let extendedDetails;
6575
- if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS || path.provider === DEEPBOOKV3 || path.provider === SCALLOP) {
6630
+ if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS || path.provider === DEEPBOOKV3 || path.provider === SCALLOP || path.provider === HAEDALPMM) {
6576
6631
  extendedDetails = {
6577
6632
  aftermathLpSupplyType: (_a = path.extended_details) == null ? void 0 : _a.aftermath_lp_supply_type,
6578
6633
  turbosFeeType: (_b = path.extended_details) == null ? void 0 : _b.turbos_fee_type,
@@ -6812,4 +6867,4 @@ decimal.js/decimal.mjs:
6812
6867
  *)
6813
6868
  */
6814
6869
 
6815
- export { AFSUI, AFTERMATH, AggregatorClient9 as AggregatorClient, BLUEFIN, BLUEMOVE, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, Env, FLOWXV2, FLOWXV3, HAEDAL, KRIYA, KRIYAV3, ONE, SCALLOP, SUILEND, TEN_POW_NINE, TURBOS, TWO, U128, U64_MAX, U64_MAX_BN, VOLO, ZERO, buildInputCoin, checkInvalidSuiAddress, compareCoins, completionCoin, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, extractAddressFromType, extractStructTagFromType, fixSuiObjectId, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
6870
+ export { AFSUI, AFTERMATH, AggregatorClient10 as AggregatorClient, BLUEFIN, BLUEMOVE, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, Env, FLOWXV2, FLOWXV3, HAEDAL, HAEDALPMM, KRIYA, KRIYAV3, ONE, SCALLOP, SUILEND, TEN_POW_NINE, TURBOS, TWO, U128, U64_MAX, U64_MAX_BN, VOLO, ZERO, buildInputCoin, checkInvalidSuiAddress, compareCoins, completionCoin, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, extractAddressFromType, extractStructTagFromType, fixSuiObjectId, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
package/dist/src/api.d.ts CHANGED
@@ -35,8 +35,8 @@ export type Path = {
35
35
  from: string;
36
36
  target: string;
37
37
  feeRate: number;
38
- amountIn: number;
39
- amountOut: number;
38
+ amountIn: string;
39
+ amountOut: string;
40
40
  version?: string;
41
41
  extendedDetails?: ExtendedDetails;
42
42
  };
@@ -20,6 +20,7 @@ export declare const DEEPBOOKV3 = "DEEPBOOKV3";
20
20
  export declare const SCALLOP = "SCALLOP";
21
21
  export declare const SUILEND = "SUILEND";
22
22
  export declare const BLUEFIN = "BLUEFIN";
23
+ export declare const HAEDALPMM = "HAEDALPMM";
23
24
  export declare const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
24
25
  export type BuildRouterSwapParams = {
25
26
  routers: Router[];
@@ -8,6 +8,6 @@ export declare class Aftermath implements Dex {
8
8
  private insuranceFund;
9
9
  private referrealVault;
10
10
  constructor(env: Env);
11
- amountLimit(exportAmountOut: number): number;
11
+ amountLimit(exportAmountOut: string): string;
12
12
  swap(client: AggregatorClient, txb: Transaction, path: Path, inputCoin: TransactionObjectArgument): Promise<TransactionObjectArgument>;
13
13
  }
@@ -0,0 +1,9 @@
1
+ import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
2
+ import { AggregatorClient, Dex, Env, Path } from "..";
3
+ import { SuiClient } from "@mysten/sui/client";
4
+ export declare class HaedalPmm implements Dex {
5
+ private connection;
6
+ private pythClient;
7
+ constructor(env: Env, suiClient: SuiClient);
8
+ swap(client: AggregatorClient, txb: Transaction, path: Path, inputCoin: TransactionObjectArgument): Promise<TransactionObjectArgument>;
9
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cetusprotocol/aggregator-sdk",
3
- "version": "0.3.12",
3
+ "version": "0.3.14",
4
4
  "sideEffects": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/api.ts CHANGED
@@ -46,8 +46,8 @@ export type Path = {
46
46
  from: string
47
47
  target: string
48
48
  feeRate: number
49
- amountIn: number
50
- amountOut: number
49
+ amountIn: string
50
+ amountOut: string
51
51
  version?: string
52
52
  extendedDetails?: ExtendedDetails
53
53
  }
package/src/client.ts CHANGED
@@ -39,6 +39,8 @@ import { DeepbookV3 } from "./transaction/deepbook_v3"
39
39
  import { Scallop } from "./transaction/scallop"
40
40
  import { Suilend } from "./transaction/suilend"
41
41
  import { Bluefin } from "./transaction/bluefin"
42
+ import { HaedalPmm } from "./transaction/haedal_pmm"
43
+
42
44
 
43
45
  export const CETUS = "CETUS"
44
46
  export const DEEPBOOKV2 = "DEEPBOOK"
@@ -56,6 +58,7 @@ export const DEEPBOOKV3 = "DEEPBOOKV3"
56
58
  export const SCALLOP = "SCALLOP"
57
59
  export const SUILEND = "SUILEND"
58
60
  export const BLUEFIN = "BLUEFIN"
61
+ export const HAEDALPMM = "HAEDALPMM"
59
62
  export const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2"
60
63
 
61
64
  export type BuildRouterSwapParams = {
@@ -417,7 +420,9 @@ export class AggregatorClient {
417
420
  // return "0x6d70ffa7aa3f924c3f0b573d27d29895a0ee666aaff821073f75cb14af7fd01a" // version 3, deepbookv3 & scallop
418
421
  // return "0x16d9418726c26d8cb4ce8c9dd75917fa9b1c7bf47d38d7a1a22603135f0f2a56" // version 4, add suilend
419
422
  // return "0x3b6d71bdeb8ce5b06febfd3cfc29ecd60d50da729477c8b8038ecdae34541b91" // version 5, add bluefin
420
- return "0x81ade554cb24a7564ca43a4bfb7381b08d9e5c5f375162c95215b696ab903502" // version 6, force upgrade scallop
423
+ // return "0x81ade554cb24a7564ca43a4bfb7381b08d9e5c5f375162c95215b696ab903502" // version 6, force upgrade scallop
424
+ return "0x347dd58bbd11cd82c8b386b344729717c04a998da73386e82a239cc196d5706b"
425
+ // return "0x20d4f23a1d119c6887cea9b036035e57ae90b4cb3d7a0acb94dfed72a9095fb7" // pre
421
426
  } else {
422
427
  return "0xabb6a81c8a216828e317719e06125de5bb2cb0fe8f9916ff8c023ca5be224c78"
423
428
  }
@@ -502,6 +507,8 @@ export class AggregatorClient {
502
507
  return new Suilend(this.env)
503
508
  case BLUEFIN:
504
509
  return new Bluefin(this.env)
510
+ case HAEDALPMM:
511
+ return new HaedalPmm(this.env, this.client)
505
512
  default:
506
513
  throw new Error(`Unsupported dex ${provider}`)
507
514
  }
@@ -576,7 +583,8 @@ export function parseRouterResponse(data: any): RouterData {
576
583
  path.provider === AFTERMATH ||
577
584
  path.provider === CETUS ||
578
585
  path.provider === DEEPBOOKV3 ||
579
- path.provider === SCALLOP
586
+ path.provider === SCALLOP ||
587
+ path.provider === HAEDALPMM
580
588
  ) {
581
589
  extendedDetails = {
582
590
  aftermathLpSupplyType:
@@ -31,13 +31,11 @@ export class Aftermath implements Dex {
31
31
  "0x35d35b0e5b177593d8c3a801462485572fc30861e6ce96a55af6dc4730709278"
32
32
  }
33
33
 
34
- amountLimit(exportAmountOut: number): number {
35
- return Number(
36
- new BN(exportAmountOut)
37
- .mul(new BN(this.slippage))
38
- .div(new BN("1000000000000000000"))
39
- .toString()
40
- )
34
+ amountLimit(exportAmountOut: string): string {
35
+ return new BN(exportAmountOut)
36
+ .mul(new BN(this.slippage))
37
+ .div(new BN("1000000000000000000"))
38
+ .toString()
41
39
  }
42
40
 
43
41
  async swap(
@@ -0,0 +1,69 @@
1
+ import {
2
+ Transaction,
3
+ TransactionArgument,
4
+ TransactionObjectArgument,
5
+ } from "@mysten/sui/transactions"
6
+ import { AggregatorClient, CLOCK_ADDRESS, Dex, Env, Path } from ".."
7
+ import { SuiPriceServiceConnection, SuiPythClient } from "@pythnetwork/pyth-sui-js"
8
+ import { SuiClient } from "@mysten/sui/client"
9
+
10
+ export class HaedalPmm implements Dex {
11
+ private connection: SuiPriceServiceConnection
12
+ private pythClient: SuiPythClient
13
+
14
+ constructor(env: Env, suiClient: SuiClient) {
15
+ if (env === Env.Testnet) {
16
+ this.connection = new SuiPriceServiceConnection("https://hermes-beta.pyth.network")
17
+ const wormholeStateId = "0x31358d198147da50db32eda2562951d53973a0c0ad5ed738e9b17d88b213d790";
18
+ const pythStateId = "0x243759059f4c3111179da5878c12f68d612c21a8d54d85edc86164bb18be1c7c";
19
+ this.pythClient = new SuiPythClient(suiClient, pythStateId, wormholeStateId)
20
+ } else {
21
+ this.connection = new SuiPriceServiceConnection("https://hermes.pyth.network")
22
+ const wormholeStateId = "0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c";
23
+ const pythStateId = "0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8";
24
+ this.pythClient = new SuiPythClient(suiClient, pythStateId, wormholeStateId)
25
+ }
26
+ }
27
+
28
+ async swap(
29
+ client: AggregatorClient,
30
+ txb: Transaction,
31
+ path: Path,
32
+ inputCoin: TransactionObjectArgument
33
+ ): Promise<TransactionObjectArgument> {
34
+ const { direction, from, target } = path
35
+ const [func, coinAType, coinBType] = direction
36
+ ? ["swap_a2b", from, target]
37
+ : ["swap_b2a", target, from]
38
+
39
+ let basePriceSeed: string
40
+ let quotePriceSeed: string
41
+
42
+ if (path.extendedDetails == null) {
43
+ throw new Error("Extended details not supported haedal pmm")
44
+ } else {
45
+ if (!path.extendedDetails.haedalPmmBasePriceSeed || !path.extendedDetails.haedalPmmQuotePriceSeed) {
46
+ throw new Error("Base price seed or quote price seed not supported")
47
+ }
48
+ basePriceSeed = path.extendedDetails.haedalPmmBasePriceSeed
49
+ quotePriceSeed = path.extendedDetails.haedalPmmQuotePriceSeed
50
+ }
51
+
52
+ const priceIDs = [basePriceSeed, quotePriceSeed]
53
+ const priceUpdateData = await this.connection.getPriceFeedsUpdateData(priceIDs);
54
+ const priceInfoObjectIds = await this.pythClient.updatePriceFeeds(txb, priceUpdateData, priceIDs);
55
+ const args = [
56
+ txb.object(path.id),
57
+ txb.object(priceInfoObjectIds[0]),
58
+ txb.object(priceInfoObjectIds[1]),
59
+ inputCoin,
60
+ txb.object(CLOCK_ADDRESS),
61
+ ]
62
+ const res = txb.moveCall({
63
+ target: `${client.publishedAtV2()}::haedalpmm::${func}`,
64
+ typeArguments: [coinAType, coinBType],
65
+ arguments: args,
66
+ }) as TransactionArgument
67
+ return res
68
+ }
69
+ }
@@ -99,6 +99,8 @@ export async function swapInPools(
99
99
 
100
100
  const event = valueData[tempIndex].parsedJson.data
101
101
 
102
+ console.log("event", JSON.stringify(event, null, 2))
103
+
102
104
  const currentSqrtPrice = event.step_results[0].current_sqrt_price
103
105
 
104
106
  const [decimalA, decimalB] = await Promise.all([
@@ -122,8 +124,13 @@ export async function swapInPools(
122
124
  decimalB!
123
125
  )
124
126
 
127
+ const feeRate = Number(event.fee_rate) / 1000000
128
+ const pureAmountIn = new BN(event.amount_in ?? 0)
129
+ const feeAmount = new BN(event.fee_amount ?? 0)
130
+ const amountIn = pureAmountIn.add(feeAmount)
131
+
125
132
  const routeData = {
126
- amountIn: new BN(event.amount_in ?? 0),
133
+ amountIn: amountIn,
127
134
  amountOut: new BN(event.amount_out ?? 0),
128
135
  routes: [
129
136
  {
@@ -134,7 +141,7 @@ export async function swapInPools(
134
141
  provider: "CETUS",
135
142
  from: fromCoin,
136
143
  target: targetCoin,
137
- feeRate: event.fee_rate,
144
+ feeRate,
138
145
  amountIn: event.amount_in,
139
146
  amountOut: event.amount_out,
140
147
  extendedDetails: {
@@ -142,7 +149,7 @@ export async function swapInPools(
142
149
  },
143
150
  },
144
151
  ],
145
- amountIn: new BN(event.amount_in ?? 0),
152
+ amountIn: amountIn,
146
153
  amountOut: new BN(event.amount_out ?? 0),
147
154
  initialPrice,
148
155
  },
@@ -33,8 +33,9 @@ describe("router module", () => {
33
33
  keypair = buildTestAccount()
34
34
  }
35
35
 
36
- const wallet = keypair.getPublicKey().toSuiAddress()
37
- console.log("wallet: ", wallet)
36
+ // const wallet = keypair.getPublicKey().toSuiAddress()
37
+ // console.log("wallet: ", wallet)
38
+ const wallet = "0x326ce9894f08dcaa337fa232641cc34db957aec9ff6614c1186bc9a7508df0bb"
38
39
 
39
40
  const endpoint = aggregatorURL
40
41
 
@@ -56,8 +57,8 @@ describe("router module", () => {
56
57
  const byAmountIn = true
57
58
 
58
59
  const res: any = await client.swapInPools({
59
- from: testData.M_USDC,
60
- target: testData.M_SUI,
60
+ from: testData.M_SUI,
61
+ target: testData.M_USDC,
61
62
  amount: new BN(amount),
62
63
  byAmountIn,
63
64
  pools: [
@@ -65,10 +66,12 @@ describe("router module", () => {
65
66
  ],
66
67
  })
67
68
 
68
- console.log("res", res)
69
-
70
69
  if (res != null) {
71
70
  console.log(JSON.stringify(res, null, 2))
71
+
72
+ console.log("amount in", res.routeData.amountIn.toString())
73
+ console.log("amount out", res.routeData.amountOut.toString())
74
+
72
75
  const txb = new Transaction()
73
76
  await client.fastRouterSwap({
74
77
  routers: res.routeData.routes,
@@ -108,7 +111,7 @@ describe("router module", () => {
108
111
  test("Build router tx", async () => {
109
112
  const byAmountIn = true
110
113
  const amount = "3574839"
111
- const target = "0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI"
114
+ const target = "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC"
112
115
  const from = "0x2::sui::SUI"
113
116
 
114
117
  const res = await client.findRouters({
@@ -117,7 +120,7 @@ describe("router module", () => {
117
120
  amount: new BN(amount),
118
121
  byAmountIn,
119
122
  depth: 3,
120
- providers: ["SCALLOP"],
123
+ providers: ["HAEDALPMM"],
121
124
  })
122
125
 
123
126
  if (res != null) {