@cetusprotocol/aggregator-sdk 0.3.13 → 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 +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +57 -4
- package/dist/index.mjs +56 -4
- package/dist/src/client.d.ts +1 -0
- package/dist/src/transaction/haedal_pmm.d.ts +9 -0
- package/package.json +1 -1
- package/src/client.ts +10 -2
- package/src/transaction/haedal_pmm.ts +69 -0
- package/tests/router.test.ts +2 -2
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[];
|
|
@@ -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[];
|
|
@@ -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;
|
|
@@ -6141,6 +6142,54 @@ var Bluefin = class {
|
|
|
6141
6142
|
});
|
|
6142
6143
|
}
|
|
6143
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
|
+
};
|
|
6144
6193
|
|
|
6145
6194
|
// src/client.ts
|
|
6146
6195
|
var CETUS = "CETUS";
|
|
@@ -6159,8 +6208,9 @@ var DEEPBOOKV3 = "DEEPBOOKV3";
|
|
|
6159
6208
|
var SCALLOP = "SCALLOP";
|
|
6160
6209
|
var SUILEND = "SUILEND";
|
|
6161
6210
|
var BLUEFIN = "BLUEFIN";
|
|
6211
|
+
var HAEDALPMM = "HAEDALPMM";
|
|
6162
6212
|
var DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
6163
|
-
var
|
|
6213
|
+
var AggregatorClient10 = class {
|
|
6164
6214
|
constructor(endpoint, signer, client$1, env) {
|
|
6165
6215
|
this.endpoint = endpoint ? processEndpoint(endpoint) : DEFAULT_ENDPOINT;
|
|
6166
6216
|
this.client = client$1 || new client.SuiClient({ url: client.getFullnodeUrl("mainnet") });
|
|
@@ -6437,7 +6487,7 @@ var AggregatorClient9 = class {
|
|
|
6437
6487
|
// Include deepbookv3, scallop, bluefin
|
|
6438
6488
|
publishedAtV2() {
|
|
6439
6489
|
if (this.env === 0 /* Mainnet */) {
|
|
6440
|
-
return "
|
|
6490
|
+
return "0x347dd58bbd11cd82c8b386b344729717c04a998da73386e82a239cc196d5706b";
|
|
6441
6491
|
} else {
|
|
6442
6492
|
return "0xabb6a81c8a216828e317719e06125de5bb2cb0fe8f9916ff8c023ca5be224c78";
|
|
6443
6493
|
}
|
|
@@ -6508,6 +6558,8 @@ var AggregatorClient9 = class {
|
|
|
6508
6558
|
return new Suilend(this.env);
|
|
6509
6559
|
case BLUEFIN:
|
|
6510
6560
|
return new Bluefin(this.env);
|
|
6561
|
+
case HAEDALPMM:
|
|
6562
|
+
return new HaedalPmm(this.env, this.client);
|
|
6511
6563
|
default:
|
|
6512
6564
|
throw new Error(`Unsupported dex ${provider}`);
|
|
6513
6565
|
}
|
|
@@ -6577,7 +6629,7 @@ function parseRouterResponse(data) {
|
|
|
6577
6629
|
version = path.extended_details.aftermath_pool_flatness === 0 ? "v2" : "v3";
|
|
6578
6630
|
}
|
|
6579
6631
|
let extendedDetails;
|
|
6580
|
-
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) {
|
|
6581
6633
|
extendedDetails = {
|
|
6582
6634
|
aftermathLpSupplyType: (_a = path.extended_details) == null ? void 0 : _a.aftermath_lp_supply_type,
|
|
6583
6635
|
turbosFeeType: (_b = path.extended_details) == null ? void 0 : _b.turbos_fee_type,
|
|
@@ -6819,7 +6871,7 @@ decimal.js/decimal.mjs:
|
|
|
6819
6871
|
|
|
6820
6872
|
exports.AFSUI = AFSUI;
|
|
6821
6873
|
exports.AFTERMATH = AFTERMATH;
|
|
6822
|
-
exports.AggregatorClient =
|
|
6874
|
+
exports.AggregatorClient = AggregatorClient10;
|
|
6823
6875
|
exports.BLUEFIN = BLUEFIN;
|
|
6824
6876
|
exports.BLUEMOVE = BLUEMOVE;
|
|
6825
6877
|
exports.CETUS = CETUS;
|
|
@@ -6831,6 +6883,7 @@ exports.Env = Env;
|
|
|
6831
6883
|
exports.FLOWXV2 = FLOWXV2;
|
|
6832
6884
|
exports.FLOWXV3 = FLOWXV3;
|
|
6833
6885
|
exports.HAEDAL = HAEDAL;
|
|
6886
|
+
exports.HAEDALPMM = HAEDALPMM;
|
|
6834
6887
|
exports.KRIYA = KRIYA;
|
|
6835
6888
|
exports.KRIYAV3 = KRIYAV3;
|
|
6836
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;
|
|
@@ -6139,6 +6140,54 @@ var Bluefin = class {
|
|
|
6139
6140
|
});
|
|
6140
6141
|
}
|
|
6141
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
|
+
};
|
|
6142
6191
|
|
|
6143
6192
|
// src/client.ts
|
|
6144
6193
|
var CETUS = "CETUS";
|
|
@@ -6157,8 +6206,9 @@ var DEEPBOOKV3 = "DEEPBOOKV3";
|
|
|
6157
6206
|
var SCALLOP = "SCALLOP";
|
|
6158
6207
|
var SUILEND = "SUILEND";
|
|
6159
6208
|
var BLUEFIN = "BLUEFIN";
|
|
6209
|
+
var HAEDALPMM = "HAEDALPMM";
|
|
6160
6210
|
var DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
6161
|
-
var
|
|
6211
|
+
var AggregatorClient10 = class {
|
|
6162
6212
|
constructor(endpoint, signer, client, env) {
|
|
6163
6213
|
this.endpoint = endpoint ? processEndpoint(endpoint) : DEFAULT_ENDPOINT;
|
|
6164
6214
|
this.client = client || new SuiClient({ url: getFullnodeUrl("mainnet") });
|
|
@@ -6435,7 +6485,7 @@ var AggregatorClient9 = class {
|
|
|
6435
6485
|
// Include deepbookv3, scallop, bluefin
|
|
6436
6486
|
publishedAtV2() {
|
|
6437
6487
|
if (this.env === 0 /* Mainnet */) {
|
|
6438
|
-
return "
|
|
6488
|
+
return "0x347dd58bbd11cd82c8b386b344729717c04a998da73386e82a239cc196d5706b";
|
|
6439
6489
|
} else {
|
|
6440
6490
|
return "0xabb6a81c8a216828e317719e06125de5bb2cb0fe8f9916ff8c023ca5be224c78";
|
|
6441
6491
|
}
|
|
@@ -6506,6 +6556,8 @@ var AggregatorClient9 = class {
|
|
|
6506
6556
|
return new Suilend(this.env);
|
|
6507
6557
|
case BLUEFIN:
|
|
6508
6558
|
return new Bluefin(this.env);
|
|
6559
|
+
case HAEDALPMM:
|
|
6560
|
+
return new HaedalPmm(this.env, this.client);
|
|
6509
6561
|
default:
|
|
6510
6562
|
throw new Error(`Unsupported dex ${provider}`);
|
|
6511
6563
|
}
|
|
@@ -6575,7 +6627,7 @@ function parseRouterResponse(data) {
|
|
|
6575
6627
|
version = path.extended_details.aftermath_pool_flatness === 0 ? "v2" : "v3";
|
|
6576
6628
|
}
|
|
6577
6629
|
let extendedDetails;
|
|
6578
|
-
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) {
|
|
6579
6631
|
extendedDetails = {
|
|
6580
6632
|
aftermathLpSupplyType: (_a = path.extended_details) == null ? void 0 : _a.aftermath_lp_supply_type,
|
|
6581
6633
|
turbosFeeType: (_b = path.extended_details) == null ? void 0 : _b.turbos_fee_type,
|
|
@@ -6815,4 +6867,4 @@ decimal.js/decimal.mjs:
|
|
|
6815
6867
|
*)
|
|
6816
6868
|
*/
|
|
6817
6869
|
|
|
6818
|
-
export { AFSUI, AFTERMATH,
|
|
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/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
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"
|
|
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:
|
|
@@ -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
|
@@ -111,7 +111,7 @@ describe("router module", () => {
|
|
|
111
111
|
test("Build router tx", async () => {
|
|
112
112
|
const byAmountIn = true
|
|
113
113
|
const amount = "3574839"
|
|
114
|
-
const target = "
|
|
114
|
+
const target = "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC"
|
|
115
115
|
const from = "0x2::sui::SUI"
|
|
116
116
|
|
|
117
117
|
const res = await client.findRouters({
|
|
@@ -120,7 +120,7 @@ describe("router module", () => {
|
|
|
120
120
|
amount: new BN(amount),
|
|
121
121
|
byAmountIn,
|
|
122
122
|
depth: 3,
|
|
123
|
-
providers: ["
|
|
123
|
+
providers: ["HAEDALPMM"],
|
|
124
124
|
})
|
|
125
125
|
|
|
126
126
|
if (res != null) {
|