@cetusprotocol/aggregator-sdk 0.0.0-experimental-20241209175110 → 0.0.0-experimental-20241216203328
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 +0 -0
- package/dist/index.d.mts +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +62 -7
- package/dist/index.mjs +61 -7
- package/dist/src/api.d.ts +3 -1
- package/dist/src/client.d.ts +1 -0
- package/dist/src/transaction/haedal_pmm.d.ts +9 -0
- package/package.json +2 -1
- package/src/api.ts +3 -1
- package/src/client.ts +13 -4
- package/src/transaction/haedal_pmm.ts +69 -0
- package/tests/router.test.ts +3 -9
package/bun.lockb
CHANGED
|
Binary file
|
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[];
|
|
@@ -206,6 +207,8 @@ type ExtendedDetails = {
|
|
|
206
207
|
afterSqrtPrice?: string;
|
|
207
208
|
deepbookv3DeepFee?: number;
|
|
208
209
|
scallopScoinTreasury?: string;
|
|
210
|
+
haedalPmmBasePriceSeed?: string;
|
|
211
|
+
haedalPmmQuotePriceSeed?: string;
|
|
209
212
|
};
|
|
210
213
|
type Path = {
|
|
211
214
|
id: string;
|
|
@@ -216,8 +219,8 @@ type Path = {
|
|
|
216
219
|
feeRate: number;
|
|
217
220
|
amountIn: number;
|
|
218
221
|
amountOut: number;
|
|
219
|
-
extendedDetails?: ExtendedDetails;
|
|
220
222
|
version?: string;
|
|
223
|
+
extendedDetails?: ExtendedDetails;
|
|
221
224
|
};
|
|
222
225
|
type Router = {
|
|
223
226
|
path: Path[];
|
|
@@ -267,4 +270,4 @@ declare enum Env {
|
|
|
267
270
|
Testnet = 1
|
|
268
271
|
}
|
|
269
272
|
|
|
270
|
-
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[];
|
|
@@ -206,6 +207,8 @@ type ExtendedDetails = {
|
|
|
206
207
|
afterSqrtPrice?: string;
|
|
207
208
|
deepbookv3DeepFee?: number;
|
|
208
209
|
scallopScoinTreasury?: string;
|
|
210
|
+
haedalPmmBasePriceSeed?: string;
|
|
211
|
+
haedalPmmQuotePriceSeed?: string;
|
|
209
212
|
};
|
|
210
213
|
type Path = {
|
|
211
214
|
id: string;
|
|
@@ -216,8 +219,8 @@ type Path = {
|
|
|
216
219
|
feeRate: number;
|
|
217
220
|
amountIn: number;
|
|
218
221
|
amountOut: number;
|
|
219
|
-
extendedDetails?: ExtendedDetails;
|
|
220
222
|
version?: string;
|
|
223
|
+
extendedDetails?: ExtendedDetails;
|
|
221
224
|
};
|
|
222
225
|
type Router = {
|
|
223
226
|
path: Path[];
|
|
@@ -267,4 +270,4 @@ declare enum Env {
|
|
|
267
270
|
Testnet = 1
|
|
268
271
|
}
|
|
269
272
|
|
|
270
|
-
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;
|
|
@@ -6138,6 +6139,54 @@ var Bluefin = class {
|
|
|
6138
6139
|
});
|
|
6139
6140
|
}
|
|
6140
6141
|
};
|
|
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
|
+
const wormholeStateId = "0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c";
|
|
6152
|
+
const pythStateId = "0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8";
|
|
6153
|
+
this.pythClient = new pythSuiJs.SuiPythClient(suiClient, pythStateId, wormholeStateId);
|
|
6154
|
+
}
|
|
6155
|
+
}
|
|
6156
|
+
swap(client, txb, path, inputCoin) {
|
|
6157
|
+
return __async(this, null, function* () {
|
|
6158
|
+
const { direction, from, target } = path;
|
|
6159
|
+
const [func, coinAType, coinBType] = direction ? ["swap_a2b", from, target] : ["swap_b2a", target, from];
|
|
6160
|
+
let basePriceSeed;
|
|
6161
|
+
let quotePriceSeed;
|
|
6162
|
+
if (path.extendedDetails == null) {
|
|
6163
|
+
throw new Error("Extended details not supported haedal pmm");
|
|
6164
|
+
} else {
|
|
6165
|
+
if (!path.extendedDetails.haedalPmmBasePriceSeed || !path.extendedDetails.haedalPmmQuotePriceSeed) {
|
|
6166
|
+
throw new Error("Base price seed or quote price seed not supported");
|
|
6167
|
+
}
|
|
6168
|
+
basePriceSeed = path.extendedDetails.haedalPmmBasePriceSeed;
|
|
6169
|
+
quotePriceSeed = path.extendedDetails.haedalPmmQuotePriceSeed;
|
|
6170
|
+
}
|
|
6171
|
+
const priceIDs = [basePriceSeed, quotePriceSeed];
|
|
6172
|
+
const priceUpdateData = yield this.connection.getPriceFeedsUpdateData(priceIDs);
|
|
6173
|
+
const priceInfoObjectIds = yield this.pythClient.updatePriceFeeds(txb, priceUpdateData, priceIDs);
|
|
6174
|
+
const args = [
|
|
6175
|
+
txb.object(path.id),
|
|
6176
|
+
txb.object(priceInfoObjectIds[0]),
|
|
6177
|
+
txb.object(priceInfoObjectIds[1]),
|
|
6178
|
+
inputCoin,
|
|
6179
|
+
txb.object(CLOCK_ADDRESS)
|
|
6180
|
+
];
|
|
6181
|
+
const res = txb.moveCall({
|
|
6182
|
+
target: `${client.publishedAtV2()}::haedalpmm::${func}`,
|
|
6183
|
+
typeArguments: [coinAType, coinBType],
|
|
6184
|
+
arguments: args
|
|
6185
|
+
});
|
|
6186
|
+
return res;
|
|
6187
|
+
});
|
|
6188
|
+
}
|
|
6189
|
+
};
|
|
6141
6190
|
|
|
6142
6191
|
// src/client.ts
|
|
6143
6192
|
var CETUS = "CETUS";
|
|
@@ -6156,8 +6205,9 @@ var DEEPBOOKV3 = "DEEPBOOKV3";
|
|
|
6156
6205
|
var SCALLOP = "SCALLOP";
|
|
6157
6206
|
var SUILEND = "SUILEND";
|
|
6158
6207
|
var BLUEFIN = "BLUEFIN";
|
|
6208
|
+
var HAEDALPMM = "HAEDALPMM";
|
|
6159
6209
|
var DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
6160
|
-
var
|
|
6210
|
+
var AggregatorClient10 = class {
|
|
6161
6211
|
constructor(endpoint, signer, client$1, env) {
|
|
6162
6212
|
this.endpoint = endpoint ? processEndpoint(endpoint) : DEFAULT_ENDPOINT;
|
|
6163
6213
|
this.client = client$1 || new client.SuiClient({ url: client.getFullnodeUrl("mainnet") });
|
|
@@ -6434,9 +6484,9 @@ var AggregatorClient9 = class {
|
|
|
6434
6484
|
// Include deepbookv3, scallop, bluefin
|
|
6435
6485
|
publishedAtV2() {
|
|
6436
6486
|
if (this.env === 0 /* Mainnet */) {
|
|
6437
|
-
return "
|
|
6487
|
+
return "0x0d1db90786844fac861cead35d66f954df4e940d32a4c9dcba3544d942ea0806";
|
|
6438
6488
|
} else {
|
|
6439
|
-
return "
|
|
6489
|
+
return "0xabb6a81c8a216828e317719e06125de5bb2cb0fe8f9916ff8c023ca5be224c78";
|
|
6440
6490
|
}
|
|
6441
6491
|
}
|
|
6442
6492
|
deepbookv3DeepFeeType() {
|
|
@@ -6505,6 +6555,8 @@ var AggregatorClient9 = class {
|
|
|
6505
6555
|
return new Suilend(this.env);
|
|
6506
6556
|
case BLUEFIN:
|
|
6507
6557
|
return new Bluefin(this.env);
|
|
6558
|
+
case HAEDALPMM:
|
|
6559
|
+
return new HaedalPmm(this.env, this.client);
|
|
6508
6560
|
default:
|
|
6509
6561
|
throw new Error(`Unsupported dex ${provider}`);
|
|
6510
6562
|
}
|
|
@@ -6568,19 +6620,21 @@ function parseRouterResponse(data) {
|
|
|
6568
6620
|
routes: data.routes.map((route) => {
|
|
6569
6621
|
return {
|
|
6570
6622
|
path: route.path.map((path) => {
|
|
6571
|
-
var _a, _b, _c, _d, _e;
|
|
6623
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
6572
6624
|
let version;
|
|
6573
6625
|
if (path.provider === AFTERMATH) {
|
|
6574
6626
|
version = path.extended_details.aftermath_pool_flatness === 0 ? "v2" : "v3";
|
|
6575
6627
|
}
|
|
6576
6628
|
let extendedDetails;
|
|
6577
|
-
if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS || path.provider === DEEPBOOKV3 || path.provider === SCALLOP) {
|
|
6629
|
+
if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS || path.provider === DEEPBOOKV3 || path.provider === SCALLOP || path.provider === HAEDALPMM) {
|
|
6578
6630
|
extendedDetails = {
|
|
6579
6631
|
aftermathLpSupplyType: (_a = path.extended_details) == null ? void 0 : _a.aftermath_lp_supply_type,
|
|
6580
6632
|
turbosFeeType: (_b = path.extended_details) == null ? void 0 : _b.turbos_fee_type,
|
|
6581
6633
|
afterSqrtPrice: (_c = path.extended_details) == null ? void 0 : _c.after_sqrt_price,
|
|
6582
6634
|
deepbookv3DeepFee: (_d = path.extended_details) == null ? void 0 : _d.deepbookv3_deep_fee,
|
|
6583
|
-
scallopScoinTreasury: (_e = path.extended_details) == null ? void 0 : _e.scallop_scoin_treasury
|
|
6635
|
+
scallopScoinTreasury: (_e = path.extended_details) == null ? void 0 : _e.scallop_scoin_treasury,
|
|
6636
|
+
haedalPmmBasePriceSeed: (_f = path.extended_details) == null ? void 0 : _f.haedal_pmm_base_price_seed,
|
|
6637
|
+
haedalPmmQuotePriceSeed: (_g = path.extended_details) == null ? void 0 : _g.haedal_pmm_quote_price_seed
|
|
6584
6638
|
};
|
|
6585
6639
|
}
|
|
6586
6640
|
return {
|
|
@@ -6814,7 +6868,7 @@ decimal.js/decimal.mjs:
|
|
|
6814
6868
|
|
|
6815
6869
|
exports.AFSUI = AFSUI;
|
|
6816
6870
|
exports.AFTERMATH = AFTERMATH;
|
|
6817
|
-
exports.AggregatorClient =
|
|
6871
|
+
exports.AggregatorClient = AggregatorClient10;
|
|
6818
6872
|
exports.BLUEFIN = BLUEFIN;
|
|
6819
6873
|
exports.BLUEMOVE = BLUEMOVE;
|
|
6820
6874
|
exports.CETUS = CETUS;
|
|
@@ -6826,6 +6880,7 @@ exports.Env = Env;
|
|
|
6826
6880
|
exports.FLOWXV2 = FLOWXV2;
|
|
6827
6881
|
exports.FLOWXV3 = FLOWXV3;
|
|
6828
6882
|
exports.HAEDAL = HAEDAL;
|
|
6883
|
+
exports.HAEDALPMM = HAEDALPMM;
|
|
6829
6884
|
exports.KRIYA = KRIYA;
|
|
6830
6885
|
exports.KRIYAV3 = KRIYAV3;
|
|
6831
6886
|
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;
|
|
@@ -6136,6 +6137,54 @@ var Bluefin = class {
|
|
|
6136
6137
|
});
|
|
6137
6138
|
}
|
|
6138
6139
|
};
|
|
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
|
+
const wormholeStateId = "0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c";
|
|
6150
|
+
const pythStateId = "0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8";
|
|
6151
|
+
this.pythClient = new SuiPythClient(suiClient, pythStateId, wormholeStateId);
|
|
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()}::haedalpmm::${func}`,
|
|
6181
|
+
typeArguments: [coinAType, coinBType],
|
|
6182
|
+
arguments: args
|
|
6183
|
+
});
|
|
6184
|
+
return res;
|
|
6185
|
+
});
|
|
6186
|
+
}
|
|
6187
|
+
};
|
|
6139
6188
|
|
|
6140
6189
|
// src/client.ts
|
|
6141
6190
|
var CETUS = "CETUS";
|
|
@@ -6154,8 +6203,9 @@ var DEEPBOOKV3 = "DEEPBOOKV3";
|
|
|
6154
6203
|
var SCALLOP = "SCALLOP";
|
|
6155
6204
|
var SUILEND = "SUILEND";
|
|
6156
6205
|
var BLUEFIN = "BLUEFIN";
|
|
6206
|
+
var HAEDALPMM = "HAEDALPMM";
|
|
6157
6207
|
var DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
6158
|
-
var
|
|
6208
|
+
var AggregatorClient10 = class {
|
|
6159
6209
|
constructor(endpoint, signer, client, env) {
|
|
6160
6210
|
this.endpoint = endpoint ? processEndpoint(endpoint) : DEFAULT_ENDPOINT;
|
|
6161
6211
|
this.client = client || new SuiClient({ url: getFullnodeUrl("mainnet") });
|
|
@@ -6432,9 +6482,9 @@ var AggregatorClient9 = class {
|
|
|
6432
6482
|
// Include deepbookv3, scallop, bluefin
|
|
6433
6483
|
publishedAtV2() {
|
|
6434
6484
|
if (this.env === 0 /* Mainnet */) {
|
|
6435
|
-
return "
|
|
6485
|
+
return "0x0d1db90786844fac861cead35d66f954df4e940d32a4c9dcba3544d942ea0806";
|
|
6436
6486
|
} else {
|
|
6437
|
-
return "
|
|
6487
|
+
return "0xabb6a81c8a216828e317719e06125de5bb2cb0fe8f9916ff8c023ca5be224c78";
|
|
6438
6488
|
}
|
|
6439
6489
|
}
|
|
6440
6490
|
deepbookv3DeepFeeType() {
|
|
@@ -6503,6 +6553,8 @@ var AggregatorClient9 = class {
|
|
|
6503
6553
|
return new Suilend(this.env);
|
|
6504
6554
|
case BLUEFIN:
|
|
6505
6555
|
return new Bluefin(this.env);
|
|
6556
|
+
case HAEDALPMM:
|
|
6557
|
+
return new HaedalPmm(this.env, this.client);
|
|
6506
6558
|
default:
|
|
6507
6559
|
throw new Error(`Unsupported dex ${provider}`);
|
|
6508
6560
|
}
|
|
@@ -6566,19 +6618,21 @@ function parseRouterResponse(data) {
|
|
|
6566
6618
|
routes: data.routes.map((route) => {
|
|
6567
6619
|
return {
|
|
6568
6620
|
path: route.path.map((path) => {
|
|
6569
|
-
var _a, _b, _c, _d, _e;
|
|
6621
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
6570
6622
|
let version;
|
|
6571
6623
|
if (path.provider === AFTERMATH) {
|
|
6572
6624
|
version = path.extended_details.aftermath_pool_flatness === 0 ? "v2" : "v3";
|
|
6573
6625
|
}
|
|
6574
6626
|
let extendedDetails;
|
|
6575
|
-
if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS || path.provider === DEEPBOOKV3 || path.provider === SCALLOP) {
|
|
6627
|
+
if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS || path.provider === DEEPBOOKV3 || path.provider === SCALLOP || path.provider === HAEDALPMM) {
|
|
6576
6628
|
extendedDetails = {
|
|
6577
6629
|
aftermathLpSupplyType: (_a = path.extended_details) == null ? void 0 : _a.aftermath_lp_supply_type,
|
|
6578
6630
|
turbosFeeType: (_b = path.extended_details) == null ? void 0 : _b.turbos_fee_type,
|
|
6579
6631
|
afterSqrtPrice: (_c = path.extended_details) == null ? void 0 : _c.after_sqrt_price,
|
|
6580
6632
|
deepbookv3DeepFee: (_d = path.extended_details) == null ? void 0 : _d.deepbookv3_deep_fee,
|
|
6581
|
-
scallopScoinTreasury: (_e = path.extended_details) == null ? void 0 : _e.scallop_scoin_treasury
|
|
6633
|
+
scallopScoinTreasury: (_e = path.extended_details) == null ? void 0 : _e.scallop_scoin_treasury,
|
|
6634
|
+
haedalPmmBasePriceSeed: (_f = path.extended_details) == null ? void 0 : _f.haedal_pmm_base_price_seed,
|
|
6635
|
+
haedalPmmQuotePriceSeed: (_g = path.extended_details) == null ? void 0 : _g.haedal_pmm_quote_price_seed
|
|
6582
6636
|
};
|
|
6583
6637
|
}
|
|
6584
6638
|
return {
|
|
@@ -6810,4 +6864,4 @@ decimal.js/decimal.mjs:
|
|
|
6810
6864
|
*)
|
|
6811
6865
|
*/
|
|
6812
6866
|
|
|
6813
|
-
export { AFSUI, AFTERMATH,
|
|
6867
|
+
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
|
@@ -25,6 +25,8 @@ export type ExtendedDetails = {
|
|
|
25
25
|
afterSqrtPrice?: string;
|
|
26
26
|
deepbookv3DeepFee?: number;
|
|
27
27
|
scallopScoinTreasury?: string;
|
|
28
|
+
haedalPmmBasePriceSeed?: string;
|
|
29
|
+
haedalPmmQuotePriceSeed?: string;
|
|
28
30
|
};
|
|
29
31
|
export type Path = {
|
|
30
32
|
id: string;
|
|
@@ -35,8 +37,8 @@ export type Path = {
|
|
|
35
37
|
feeRate: number;
|
|
36
38
|
amountIn: number;
|
|
37
39
|
amountOut: number;
|
|
38
|
-
extendedDetails?: ExtendedDetails;
|
|
39
40
|
version?: string;
|
|
41
|
+
extendedDetails?: ExtendedDetails;
|
|
40
42
|
};
|
|
41
43
|
export type Router = {
|
|
42
44
|
path: Path[];
|
package/dist/src/client.d.ts
CHANGED
|
@@ -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[];
|
|
@@ -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.0.0-experimental-
|
|
3
|
+
"version": "0.0.0-experimental-20241216203328",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"@babel/preset-typescript": "^7.24.1",
|
|
29
29
|
"@jest/globals": "^29.7.0",
|
|
30
30
|
"@mysten/sui": "^1.6.0",
|
|
31
|
+
"@pythnetwork/pyth-sui-js": "^2.1.0",
|
|
31
32
|
"@types/jest": "^29.5.12",
|
|
32
33
|
"@types/node": "^20.12.12",
|
|
33
34
|
"babel-jest": "^29.7.0",
|
package/src/api.ts
CHANGED
|
@@ -35,6 +35,8 @@ export type ExtendedDetails = {
|
|
|
35
35
|
afterSqrtPrice?: string
|
|
36
36
|
deepbookv3DeepFee?: number
|
|
37
37
|
scallopScoinTreasury?: string
|
|
38
|
+
haedalPmmBasePriceSeed?: string
|
|
39
|
+
haedalPmmQuotePriceSeed?: string
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
export type Path = {
|
|
@@ -46,8 +48,8 @@ export type Path = {
|
|
|
46
48
|
feeRate: number
|
|
47
49
|
amountIn: number
|
|
48
50
|
amountOut: number
|
|
49
|
-
extendedDetails?: ExtendedDetails
|
|
50
51
|
version?: string
|
|
52
|
+
extendedDetails?: ExtendedDetails
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
export type Router = {
|
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
|
+
import { TsJestCompiler } from "ts-jest"
|
|
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 = {
|
|
@@ -415,10 +418,11 @@ export class AggregatorClient {
|
|
|
415
418
|
if (this.env === Env.Mainnet) {
|
|
416
419
|
// return "0x43811be4677f5a5de7bf2dac740c10abddfaa524aee6b18e910eeadda8a2f6ae" // version 1, deepbookv3
|
|
417
420
|
// return "0x6d70ffa7aa3f924c3f0b573d27d29895a0ee666aaff821073f75cb14af7fd01a" // version 3, deepbookv3 & scallop
|
|
418
|
-
// return "0x16d9418726c26d8cb4ce8c9dd75917fa9b1c7bf47d38d7a1a22603135f0f2a56" // version 4 add suilend
|
|
419
|
-
return "
|
|
421
|
+
// return "0x16d9418726c26d8cb4ce8c9dd75917fa9b1c7bf47d38d7a1a22603135f0f2a56" // version 4, add suilend
|
|
422
|
+
// return "0x3b6d71bdeb8ce5b06febfd3cfc29ecd60d50da729477c8b8038ecdae34541b91" // version 5, add bluefin
|
|
423
|
+
return "0x0d1db90786844fac861cead35d66f954df4e940d32a4c9dcba3544d942ea0806" // pre
|
|
420
424
|
} else {
|
|
421
|
-
return "
|
|
425
|
+
return "0xabb6a81c8a216828e317719e06125de5bb2cb0fe8f9916ff8c023ca5be224c78"
|
|
422
426
|
}
|
|
423
427
|
}
|
|
424
428
|
|
|
@@ -501,6 +505,8 @@ export class AggregatorClient {
|
|
|
501
505
|
return new Suilend(this.env)
|
|
502
506
|
case BLUEFIN:
|
|
503
507
|
return new Bluefin(this.env)
|
|
508
|
+
case HAEDALPMM:
|
|
509
|
+
return new HaedalPmm(this.env, this.client)
|
|
504
510
|
default:
|
|
505
511
|
throw new Error(`Unsupported dex ${provider}`)
|
|
506
512
|
}
|
|
@@ -575,7 +581,8 @@ export function parseRouterResponse(data: any): RouterData {
|
|
|
575
581
|
path.provider === AFTERMATH ||
|
|
576
582
|
path.provider === CETUS ||
|
|
577
583
|
path.provider === DEEPBOOKV3 ||
|
|
578
|
-
path.provider === SCALLOP
|
|
584
|
+
path.provider === SCALLOP ||
|
|
585
|
+
path.provider === HAEDALPMM
|
|
579
586
|
) {
|
|
580
587
|
extendedDetails = {
|
|
581
588
|
aftermathLpSupplyType:
|
|
@@ -585,6 +592,8 @@ export function parseRouterResponse(data: any): RouterData {
|
|
|
585
592
|
deepbookv3DeepFee: path.extended_details?.deepbookv3_deep_fee,
|
|
586
593
|
scallopScoinTreasury:
|
|
587
594
|
path.extended_details?.scallop_scoin_treasury,
|
|
595
|
+
haedalPmmBasePriceSeed: path.extended_details?.haedal_pmm_base_price_seed,
|
|
596
|
+
haedalPmmQuotePriceSeed: path.extended_details?.haedal_pmm_quote_price_seed,
|
|
588
597
|
}
|
|
589
598
|
}
|
|
590
599
|
|
|
@@ -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
|
+
}
|
package/tests/router.test.ts
CHANGED
|
@@ -36,16 +36,11 @@ describe("router module", () => {
|
|
|
36
36
|
const wallet = keypair.getPublicKey().toSuiAddress()
|
|
37
37
|
console.log("wallet: ", wallet)
|
|
38
38
|
|
|
39
|
-
// // const endpoint =
|
|
40
|
-
// // "https://api-sui-cloudfront.cetus.zone/router_v2/find_routes"
|
|
41
39
|
const endpoint = aggregatorURL
|
|
42
40
|
|
|
43
41
|
const suiClient = new SuiClient({
|
|
44
42
|
url: fullNodeURL,
|
|
45
43
|
})
|
|
46
|
-
// const suiClient = new SuiClient({
|
|
47
|
-
// url: "https://fullnode.testnet.sui.io:443",
|
|
48
|
-
// })
|
|
49
44
|
|
|
50
45
|
client = new AggregatorClient(endpoint, wallet, suiClient, Env.Mainnet)
|
|
51
46
|
})
|
|
@@ -112,9 +107,9 @@ describe("router module", () => {
|
|
|
112
107
|
|
|
113
108
|
test("Build router tx", async () => {
|
|
114
109
|
const byAmountIn = true
|
|
115
|
-
const amount = "
|
|
110
|
+
const amount = "3574839"
|
|
111
|
+
const target = "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC"
|
|
116
112
|
const from = "0x2::sui::SUI"
|
|
117
|
-
const target = "0x83556891f4a0f233ce7b05cfe7f957d4020492a34f5405b2cb9377d060bef4bf::spring_sui::SPRING_SUI"
|
|
118
113
|
|
|
119
114
|
const res = await client.findRouters({
|
|
120
115
|
from,
|
|
@@ -122,7 +117,7 @@ describe("router module", () => {
|
|
|
122
117
|
amount: new BN(amount),
|
|
123
118
|
byAmountIn,
|
|
124
119
|
depth: 3,
|
|
125
|
-
providers: ["
|
|
120
|
+
providers: ["HAEDALPMM"],
|
|
126
121
|
})
|
|
127
122
|
|
|
128
123
|
if (res != null) {
|
|
@@ -154,7 +149,6 @@ describe("router module", () => {
|
|
|
154
149
|
for (const event of result.events) {
|
|
155
150
|
console.log("event", JSON.stringify(event, null, 2))
|
|
156
151
|
}
|
|
157
|
-
console.log("txb", )
|
|
158
152
|
|
|
159
153
|
// if (result.effects.status.status === "success") {
|
|
160
154
|
// // console.log("Sim exec transaction success")
|