@cetusprotocol/aggregator-sdk 0.0.0-experimental-20241209175110 → 0.0.0-experimental-20241216120506
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 +60 -7
- package/dist/index.mjs +59 -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 +67 -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,52 @@ 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
|
+
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
|
+
};
|
|
6141
6188
|
|
|
6142
6189
|
// src/client.ts
|
|
6143
6190
|
var CETUS = "CETUS";
|
|
@@ -6156,8 +6203,9 @@ var DEEPBOOKV3 = "DEEPBOOKV3";
|
|
|
6156
6203
|
var SCALLOP = "SCALLOP";
|
|
6157
6204
|
var SUILEND = "SUILEND";
|
|
6158
6205
|
var BLUEFIN = "BLUEFIN";
|
|
6206
|
+
var HAEDALPMM = "HAEDALPMM";
|
|
6159
6207
|
var DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
6160
|
-
var
|
|
6208
|
+
var AggregatorClient10 = class {
|
|
6161
6209
|
constructor(endpoint, signer, client$1, env) {
|
|
6162
6210
|
this.endpoint = endpoint ? processEndpoint(endpoint) : DEFAULT_ENDPOINT;
|
|
6163
6211
|
this.client = client$1 || new client.SuiClient({ url: client.getFullnodeUrl("mainnet") });
|
|
@@ -6434,9 +6482,9 @@ var AggregatorClient9 = class {
|
|
|
6434
6482
|
// Include deepbookv3, scallop, bluefin
|
|
6435
6483
|
publishedAtV2() {
|
|
6436
6484
|
if (this.env === 0 /* Mainnet */) {
|
|
6437
|
-
return "
|
|
6485
|
+
return "0x0d1db90786844fac861cead35d66f954df4e940d32a4c9dcba3544d942ea0806";
|
|
6438
6486
|
} else {
|
|
6439
|
-
return "
|
|
6487
|
+
return "0xabb6a81c8a216828e317719e06125de5bb2cb0fe8f9916ff8c023ca5be224c78";
|
|
6440
6488
|
}
|
|
6441
6489
|
}
|
|
6442
6490
|
deepbookv3DeepFeeType() {
|
|
@@ -6505,6 +6553,8 @@ var AggregatorClient9 = class {
|
|
|
6505
6553
|
return new Suilend(this.env);
|
|
6506
6554
|
case BLUEFIN:
|
|
6507
6555
|
return new Bluefin(this.env);
|
|
6556
|
+
case HAEDALPMM:
|
|
6557
|
+
return new HaedalPmm(this.env, this.client);
|
|
6508
6558
|
default:
|
|
6509
6559
|
throw new Error(`Unsupported dex ${provider}`);
|
|
6510
6560
|
}
|
|
@@ -6568,19 +6618,21 @@ function parseRouterResponse(data) {
|
|
|
6568
6618
|
routes: data.routes.map((route) => {
|
|
6569
6619
|
return {
|
|
6570
6620
|
path: route.path.map((path) => {
|
|
6571
|
-
var _a, _b, _c, _d, _e;
|
|
6621
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
6572
6622
|
let version;
|
|
6573
6623
|
if (path.provider === AFTERMATH) {
|
|
6574
6624
|
version = path.extended_details.aftermath_pool_flatness === 0 ? "v2" : "v3";
|
|
6575
6625
|
}
|
|
6576
6626
|
let extendedDetails;
|
|
6577
|
-
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) {
|
|
6578
6628
|
extendedDetails = {
|
|
6579
6629
|
aftermathLpSupplyType: (_a = path.extended_details) == null ? void 0 : _a.aftermath_lp_supply_type,
|
|
6580
6630
|
turbosFeeType: (_b = path.extended_details) == null ? void 0 : _b.turbos_fee_type,
|
|
6581
6631
|
afterSqrtPrice: (_c = path.extended_details) == null ? void 0 : _c.after_sqrt_price,
|
|
6582
6632
|
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
|
|
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
|
|
6584
6636
|
};
|
|
6585
6637
|
}
|
|
6586
6638
|
return {
|
|
@@ -6814,7 +6866,7 @@ decimal.js/decimal.mjs:
|
|
|
6814
6866
|
|
|
6815
6867
|
exports.AFSUI = AFSUI;
|
|
6816
6868
|
exports.AFTERMATH = AFTERMATH;
|
|
6817
|
-
exports.AggregatorClient =
|
|
6869
|
+
exports.AggregatorClient = AggregatorClient10;
|
|
6818
6870
|
exports.BLUEFIN = BLUEFIN;
|
|
6819
6871
|
exports.BLUEMOVE = BLUEMOVE;
|
|
6820
6872
|
exports.CETUS = CETUS;
|
|
@@ -6826,6 +6878,7 @@ exports.Env = Env;
|
|
|
6826
6878
|
exports.FLOWXV2 = FLOWXV2;
|
|
6827
6879
|
exports.FLOWXV3 = FLOWXV3;
|
|
6828
6880
|
exports.HAEDAL = HAEDAL;
|
|
6881
|
+
exports.HAEDALPMM = HAEDALPMM;
|
|
6829
6882
|
exports.KRIYA = KRIYA;
|
|
6830
6883
|
exports.KRIYAV3 = KRIYAV3;
|
|
6831
6884
|
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,52 @@ 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
|
+
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
|
+
};
|
|
6139
6186
|
|
|
6140
6187
|
// src/client.ts
|
|
6141
6188
|
var CETUS = "CETUS";
|
|
@@ -6154,8 +6201,9 @@ var DEEPBOOKV3 = "DEEPBOOKV3";
|
|
|
6154
6201
|
var SCALLOP = "SCALLOP";
|
|
6155
6202
|
var SUILEND = "SUILEND";
|
|
6156
6203
|
var BLUEFIN = "BLUEFIN";
|
|
6204
|
+
var HAEDALPMM = "HAEDALPMM";
|
|
6157
6205
|
var DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
6158
|
-
var
|
|
6206
|
+
var AggregatorClient10 = class {
|
|
6159
6207
|
constructor(endpoint, signer, client, env) {
|
|
6160
6208
|
this.endpoint = endpoint ? processEndpoint(endpoint) : DEFAULT_ENDPOINT;
|
|
6161
6209
|
this.client = client || new SuiClient({ url: getFullnodeUrl("mainnet") });
|
|
@@ -6432,9 +6480,9 @@ var AggregatorClient9 = class {
|
|
|
6432
6480
|
// Include deepbookv3, scallop, bluefin
|
|
6433
6481
|
publishedAtV2() {
|
|
6434
6482
|
if (this.env === 0 /* Mainnet */) {
|
|
6435
|
-
return "
|
|
6483
|
+
return "0x0d1db90786844fac861cead35d66f954df4e940d32a4c9dcba3544d942ea0806";
|
|
6436
6484
|
} else {
|
|
6437
|
-
return "
|
|
6485
|
+
return "0xabb6a81c8a216828e317719e06125de5bb2cb0fe8f9916ff8c023ca5be224c78";
|
|
6438
6486
|
}
|
|
6439
6487
|
}
|
|
6440
6488
|
deepbookv3DeepFeeType() {
|
|
@@ -6503,6 +6551,8 @@ var AggregatorClient9 = class {
|
|
|
6503
6551
|
return new Suilend(this.env);
|
|
6504
6552
|
case BLUEFIN:
|
|
6505
6553
|
return new Bluefin(this.env);
|
|
6554
|
+
case HAEDALPMM:
|
|
6555
|
+
return new HaedalPmm(this.env, this.client);
|
|
6506
6556
|
default:
|
|
6507
6557
|
throw new Error(`Unsupported dex ${provider}`);
|
|
6508
6558
|
}
|
|
@@ -6566,19 +6616,21 @@ function parseRouterResponse(data) {
|
|
|
6566
6616
|
routes: data.routes.map((route) => {
|
|
6567
6617
|
return {
|
|
6568
6618
|
path: route.path.map((path) => {
|
|
6569
|
-
var _a, _b, _c, _d, _e;
|
|
6619
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
6570
6620
|
let version;
|
|
6571
6621
|
if (path.provider === AFTERMATH) {
|
|
6572
6622
|
version = path.extended_details.aftermath_pool_flatness === 0 ? "v2" : "v3";
|
|
6573
6623
|
}
|
|
6574
6624
|
let extendedDetails;
|
|
6575
|
-
if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS || path.provider === DEEPBOOKV3 || path.provider === SCALLOP) {
|
|
6625
|
+
if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS || path.provider === DEEPBOOKV3 || path.provider === SCALLOP || path.provider === HAEDALPMM) {
|
|
6576
6626
|
extendedDetails = {
|
|
6577
6627
|
aftermathLpSupplyType: (_a = path.extended_details) == null ? void 0 : _a.aftermath_lp_supply_type,
|
|
6578
6628
|
turbosFeeType: (_b = path.extended_details) == null ? void 0 : _b.turbos_fee_type,
|
|
6579
6629
|
afterSqrtPrice: (_c = path.extended_details) == null ? void 0 : _c.after_sqrt_price,
|
|
6580
6630
|
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
|
|
6631
|
+
scallopScoinTreasury: (_e = path.extended_details) == null ? void 0 : _e.scallop_scoin_treasury,
|
|
6632
|
+
haedalPmmBasePriceSeed: (_f = path.extended_details) == null ? void 0 : _f.haedal_pmm_base_price_seed,
|
|
6633
|
+
haedalPmmQuotePriceSeed: (_g = path.extended_details) == null ? void 0 : _g.haedal_pmm_quote_price_seed
|
|
6582
6634
|
};
|
|
6583
6635
|
}
|
|
6584
6636
|
return {
|
|
@@ -6810,4 +6862,4 @@ decimal.js/decimal.mjs:
|
|
|
6810
6862
|
*)
|
|
6811
6863
|
*/
|
|
6812
6864
|
|
|
6813
|
-
export { AFSUI, AFTERMATH,
|
|
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 };
|
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-20241216120506",
|
|
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,67 @@
|
|
|
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
|
+
}
|
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 = "0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI"
|
|
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: ["SCALLOP"],
|
|
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")
|