@cetusprotocol/aggregator-sdk 0.0.0-experimental-20241216120506 → 0.0.0-experimental-20241217105030

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,7 +76,6 @@ 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";
80
79
  declare const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
81
80
  type BuildRouterSwapParams = {
82
81
  routers: Router[];
@@ -270,4 +269,4 @@ declare enum Env {
270
269
  Testnet = 1
271
270
  }
272
271
 
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 };
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 };
package/dist/index.d.ts CHANGED
@@ -76,7 +76,6 @@ 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";
80
79
  declare const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
81
80
  type BuildRouterSwapParams = {
82
81
  routers: Router[];
@@ -270,4 +269,4 @@ declare enum Env {
270
269
  Testnet = 1
271
270
  }
272
271
 
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 };
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 };
package/dist/index.js CHANGED
@@ -3,7 +3,6 @@
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');
7
6
 
8
7
  var __create = Object.create;
9
8
  var __defProp = Object.defineProperty;
@@ -6139,52 +6138,6 @@ var Bluefin = class {
6139
6138
  });
6140
6139
  }
6141
6140
  };
6142
- var HaedalPmm = class {
6143
- constructor(env, suiClient) {
6144
- if (env === 1 /* Testnet */) {
6145
- this.connection = new pythSuiJs.SuiPriceServiceConnection("https://hermes-beta.pyth.network");
6146
- const wormholeStateId = "0x31358d198147da50db32eda2562951d53973a0c0ad5ed738e9b17d88b213d790";
6147
- const pythStateId = "0x243759059f4c3111179da5878c12f68d612c21a8d54d85edc86164bb18be1c7c";
6148
- this.pythClient = new pythSuiJs.SuiPythClient(suiClient, pythStateId, wormholeStateId);
6149
- } else {
6150
- this.connection = new pythSuiJs.SuiPriceServiceConnection("https://hermes.pyth.network");
6151
- throw new Error("Haedal pmm is not supported on mainnet");
6152
- }
6153
- }
6154
- swap(client, txb, path, inputCoin) {
6155
- return __async(this, null, function* () {
6156
- const { direction, from, target } = path;
6157
- const [func, coinAType, coinBType] = direction ? ["swap_a2b", from, target] : ["swap_b2a", target, from];
6158
- let basePriceSeed;
6159
- let quotePriceSeed;
6160
- if (path.extendedDetails == null) {
6161
- throw new Error("Extended details not supported haedal pmm");
6162
- } else {
6163
- if (!path.extendedDetails.haedalPmmBasePriceSeed || !path.extendedDetails.haedalPmmQuotePriceSeed) {
6164
- throw new Error("Base price seed or quote price seed not supported");
6165
- }
6166
- basePriceSeed = path.extendedDetails.haedalPmmBasePriceSeed;
6167
- quotePriceSeed = path.extendedDetails.haedalPmmQuotePriceSeed;
6168
- }
6169
- const priceIDs = [basePriceSeed, quotePriceSeed];
6170
- const priceUpdateData = yield this.connection.getPriceFeedsUpdateData(priceIDs);
6171
- const priceInfoObjectIds = yield this.pythClient.updatePriceFeeds(txb, priceUpdateData, priceIDs);
6172
- const args = [
6173
- txb.object(path.id),
6174
- txb.object(priceInfoObjectIds[0]),
6175
- txb.object(priceInfoObjectIds[1]),
6176
- inputCoin,
6177
- txb.object(CLOCK_ADDRESS)
6178
- ];
6179
- const res = txb.moveCall({
6180
- target: `${client.publishedAtV2()}::haedal_pmm::${func}`,
6181
- typeArguments: [coinAType, coinBType],
6182
- arguments: args
6183
- });
6184
- return res;
6185
- });
6186
- }
6187
- };
6188
6141
 
6189
6142
  // src/client.ts
6190
6143
  var CETUS = "CETUS";
@@ -6203,9 +6156,8 @@ var DEEPBOOKV3 = "DEEPBOOKV3";
6203
6156
  var SCALLOP = "SCALLOP";
6204
6157
  var SUILEND = "SUILEND";
6205
6158
  var BLUEFIN = "BLUEFIN";
6206
- var HAEDALPMM = "HAEDALPMM";
6207
6159
  var DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
6208
- var AggregatorClient10 = class {
6160
+ var AggregatorClient9 = class {
6209
6161
  constructor(endpoint, signer, client$1, env) {
6210
6162
  this.endpoint = endpoint ? processEndpoint(endpoint) : DEFAULT_ENDPOINT;
6211
6163
  this.client = client$1 || new client.SuiClient({ url: client.getFullnodeUrl("mainnet") });
@@ -6553,8 +6505,6 @@ var AggregatorClient10 = class {
6553
6505
  return new Suilend(this.env);
6554
6506
  case BLUEFIN:
6555
6507
  return new Bluefin(this.env);
6556
- case HAEDALPMM:
6557
- return new HaedalPmm(this.env, this.client);
6558
6508
  default:
6559
6509
  throw new Error(`Unsupported dex ${provider}`);
6560
6510
  }
@@ -6624,7 +6574,7 @@ function parseRouterResponse(data) {
6624
6574
  version = path.extended_details.aftermath_pool_flatness === 0 ? "v2" : "v3";
6625
6575
  }
6626
6576
  let extendedDetails;
6627
- if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS || path.provider === DEEPBOOKV3 || path.provider === SCALLOP || path.provider === HAEDALPMM) {
6577
+ if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS || path.provider === DEEPBOOKV3 || path.provider === SCALLOP) {
6628
6578
  extendedDetails = {
6629
6579
  aftermathLpSupplyType: (_a = path.extended_details) == null ? void 0 : _a.aftermath_lp_supply_type,
6630
6580
  turbosFeeType: (_b = path.extended_details) == null ? void 0 : _b.turbos_fee_type,
@@ -6866,7 +6816,7 @@ decimal.js/decimal.mjs:
6866
6816
 
6867
6817
  exports.AFSUI = AFSUI;
6868
6818
  exports.AFTERMATH = AFTERMATH;
6869
- exports.AggregatorClient = AggregatorClient10;
6819
+ exports.AggregatorClient = AggregatorClient9;
6870
6820
  exports.BLUEFIN = BLUEFIN;
6871
6821
  exports.BLUEMOVE = BLUEMOVE;
6872
6822
  exports.CETUS = CETUS;
@@ -6878,7 +6828,6 @@ exports.Env = Env;
6878
6828
  exports.FLOWXV2 = FLOWXV2;
6879
6829
  exports.FLOWXV3 = FLOWXV3;
6880
6830
  exports.HAEDAL = HAEDAL;
6881
- exports.HAEDALPMM = HAEDALPMM;
6882
6831
  exports.KRIYA = KRIYA;
6883
6832
  exports.KRIYAV3 = KRIYAV3;
6884
6833
  exports.ONE = ONE;
package/dist/index.mjs CHANGED
@@ -1,7 +1,6 @@
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';
5
4
 
6
5
  var __create = Object.create;
7
6
  var __defProp = Object.defineProperty;
@@ -6137,52 +6136,6 @@ var Bluefin = class {
6137
6136
  });
6138
6137
  }
6139
6138
  };
6140
- var HaedalPmm = class {
6141
- constructor(env, suiClient) {
6142
- if (env === 1 /* Testnet */) {
6143
- this.connection = new SuiPriceServiceConnection("https://hermes-beta.pyth.network");
6144
- const wormholeStateId = "0x31358d198147da50db32eda2562951d53973a0c0ad5ed738e9b17d88b213d790";
6145
- const pythStateId = "0x243759059f4c3111179da5878c12f68d612c21a8d54d85edc86164bb18be1c7c";
6146
- this.pythClient = new SuiPythClient(suiClient, pythStateId, wormholeStateId);
6147
- } else {
6148
- this.connection = new SuiPriceServiceConnection("https://hermes.pyth.network");
6149
- throw new Error("Haedal pmm is not supported on mainnet");
6150
- }
6151
- }
6152
- swap(client, txb, path, inputCoin) {
6153
- return __async(this, null, function* () {
6154
- const { direction, from, target } = path;
6155
- const [func, coinAType, coinBType] = direction ? ["swap_a2b", from, target] : ["swap_b2a", target, from];
6156
- let basePriceSeed;
6157
- let quotePriceSeed;
6158
- if (path.extendedDetails == null) {
6159
- throw new Error("Extended details not supported haedal pmm");
6160
- } else {
6161
- if (!path.extendedDetails.haedalPmmBasePriceSeed || !path.extendedDetails.haedalPmmQuotePriceSeed) {
6162
- throw new Error("Base price seed or quote price seed not supported");
6163
- }
6164
- basePriceSeed = path.extendedDetails.haedalPmmBasePriceSeed;
6165
- quotePriceSeed = path.extendedDetails.haedalPmmQuotePriceSeed;
6166
- }
6167
- const priceIDs = [basePriceSeed, quotePriceSeed];
6168
- const priceUpdateData = yield this.connection.getPriceFeedsUpdateData(priceIDs);
6169
- const priceInfoObjectIds = yield this.pythClient.updatePriceFeeds(txb, priceUpdateData, priceIDs);
6170
- const args = [
6171
- txb.object(path.id),
6172
- txb.object(priceInfoObjectIds[0]),
6173
- txb.object(priceInfoObjectIds[1]),
6174
- inputCoin,
6175
- txb.object(CLOCK_ADDRESS)
6176
- ];
6177
- const res = txb.moveCall({
6178
- target: `${client.publishedAtV2()}::haedal_pmm::${func}`,
6179
- typeArguments: [coinAType, coinBType],
6180
- arguments: args
6181
- });
6182
- return res;
6183
- });
6184
- }
6185
- };
6186
6139
 
6187
6140
  // src/client.ts
6188
6141
  var CETUS = "CETUS";
@@ -6201,9 +6154,8 @@ var DEEPBOOKV3 = "DEEPBOOKV3";
6201
6154
  var SCALLOP = "SCALLOP";
6202
6155
  var SUILEND = "SUILEND";
6203
6156
  var BLUEFIN = "BLUEFIN";
6204
- var HAEDALPMM = "HAEDALPMM";
6205
6157
  var DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
6206
- var AggregatorClient10 = class {
6158
+ var AggregatorClient9 = class {
6207
6159
  constructor(endpoint, signer, client, env) {
6208
6160
  this.endpoint = endpoint ? processEndpoint(endpoint) : DEFAULT_ENDPOINT;
6209
6161
  this.client = client || new SuiClient({ url: getFullnodeUrl("mainnet") });
@@ -6551,8 +6503,6 @@ var AggregatorClient10 = class {
6551
6503
  return new Suilend(this.env);
6552
6504
  case BLUEFIN:
6553
6505
  return new Bluefin(this.env);
6554
- case HAEDALPMM:
6555
- return new HaedalPmm(this.env, this.client);
6556
6506
  default:
6557
6507
  throw new Error(`Unsupported dex ${provider}`);
6558
6508
  }
@@ -6622,7 +6572,7 @@ function parseRouterResponse(data) {
6622
6572
  version = path.extended_details.aftermath_pool_flatness === 0 ? "v2" : "v3";
6623
6573
  }
6624
6574
  let extendedDetails;
6625
- if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS || path.provider === DEEPBOOKV3 || path.provider === SCALLOP || path.provider === HAEDALPMM) {
6575
+ if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS || path.provider === DEEPBOOKV3 || path.provider === SCALLOP) {
6626
6576
  extendedDetails = {
6627
6577
  aftermathLpSupplyType: (_a = path.extended_details) == null ? void 0 : _a.aftermath_lp_supply_type,
6628
6578
  turbosFeeType: (_b = path.extended_details) == null ? void 0 : _b.turbos_fee_type,
@@ -6862,4 +6812,4 @@ decimal.js/decimal.mjs:
6862
6812
  *)
6863
6813
  */
6864
6814
 
6865
- 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 };
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 };
@@ -20,7 +20,6 @@ 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";
24
23
  export declare const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
25
24
  export type BuildRouterSwapParams = {
26
25
  routers: Router[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cetusprotocol/aggregator-sdk",
3
- "version": "0.0.0-experimental-20241216120506",
3
+ "version": "0.0.0-experimental-20241217105030",
4
4
  "sideEffects": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/client.ts CHANGED
@@ -39,8 +39,6 @@ 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
- import { TsJestCompiler } from "ts-jest"
44
42
 
45
43
  export const CETUS = "CETUS"
46
44
  export const DEEPBOOKV2 = "DEEPBOOK"
@@ -58,7 +56,6 @@ export const DEEPBOOKV3 = "DEEPBOOKV3"
58
56
  export const SCALLOP = "SCALLOP"
59
57
  export const SUILEND = "SUILEND"
60
58
  export const BLUEFIN = "BLUEFIN"
61
- export const HAEDALPMM = "HAEDALPMM"
62
59
  export const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2"
63
60
 
64
61
  export type BuildRouterSwapParams = {
@@ -505,8 +502,6 @@ export class AggregatorClient {
505
502
  return new Suilend(this.env)
506
503
  case BLUEFIN:
507
504
  return new Bluefin(this.env)
508
- case HAEDALPMM:
509
- return new HaedalPmm(this.env, this.client)
510
505
  default:
511
506
  throw new Error(`Unsupported dex ${provider}`)
512
507
  }
@@ -581,8 +576,7 @@ export function parseRouterResponse(data: any): RouterData {
581
576
  path.provider === AFTERMATH ||
582
577
  path.provider === CETUS ||
583
578
  path.provider === DEEPBOOKV3 ||
584
- path.provider === SCALLOP ||
585
- path.provider === HAEDALPMM
579
+ path.provider === SCALLOP
586
580
  ) {
587
581
  extendedDetails = {
588
582
  aftermathLpSupplyType:
@@ -1,9 +0,0 @@
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
- }
@@ -1,67 +0,0 @@
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
- throw new Error("Haedal pmm is not supported on mainnet")
23
- }
24
- }
25
-
26
- async swap(
27
- client: AggregatorClient,
28
- txb: Transaction,
29
- path: Path,
30
- inputCoin: TransactionObjectArgument
31
- ): Promise<TransactionObjectArgument> {
32
- const { direction, from, target } = path
33
- const [func, coinAType, coinBType] = direction
34
- ? ["swap_a2b", from, target]
35
- : ["swap_b2a", target, from]
36
-
37
- let basePriceSeed: string
38
- let quotePriceSeed: string
39
-
40
- if (path.extendedDetails == null) {
41
- throw new Error("Extended details not supported haedal pmm")
42
- } else {
43
- if (!path.extendedDetails.haedalPmmBasePriceSeed || !path.extendedDetails.haedalPmmQuotePriceSeed) {
44
- throw new Error("Base price seed or quote price seed not supported")
45
- }
46
- basePriceSeed = path.extendedDetails.haedalPmmBasePriceSeed
47
- quotePriceSeed = path.extendedDetails.haedalPmmQuotePriceSeed
48
- }
49
-
50
- const priceIDs = [basePriceSeed, quotePriceSeed]
51
- const priceUpdateData = await this.connection.getPriceFeedsUpdateData(priceIDs);
52
- const priceInfoObjectIds = await this.pythClient.updatePriceFeeds(txb, priceUpdateData, priceIDs);
53
- const args = [
54
- txb.object(path.id),
55
- txb.object(priceInfoObjectIds[0]),
56
- txb.object(priceInfoObjectIds[1]),
57
- inputCoin,
58
- txb.object(CLOCK_ADDRESS),
59
- ]
60
- const res = txb.moveCall({
61
- target: `${client.publishedAtV2()}::haedal_pmm::${func}`,
62
- typeArguments: [coinAType, coinBType],
63
- arguments: args,
64
- }) as TransactionArgument
65
- return res
66
- }
67
- }