@cetusprotocol/aggregator-sdk 1.1.2 → 1.1.4
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/.claude/settings.local.json +41 -0
- package/dist/index.d.mts +6 -3
- package/dist/index.d.ts +6 -3
- package/dist/index.js +86 -52
- package/dist/index.mjs +86 -52
- package/package.json +2 -2
- package/.github/workflows/test.yml +0 -152
- package/.vscode/settings.json +0 -8
- package/CLAUDE.md +0 -101
- package/benchmark-results/benchmark-results-2025-07-17T12-03-15-563Z.csv +0 -3
- package/benchmark-results/benchmark-results-2025-07-17T12-03-15-563Z.json +0 -56
- package/benchmark-results/benchmark-results-2025-07-17T12-03-34-148Z.csv +0 -3
- package/benchmark-results/benchmark-results-2025-07-17T12-03-34-148Z.json +0 -56
- package/benchmark-results/benchmark-results-2025-07-21T03-31-59-263Z.csv +0 -21
- package/benchmark-results/benchmark-results-2025-07-21T03-31-59-263Z.json +0 -444
- package/benchmark-results/benchmark-results-2025-07-21T07-54-54-916Z.csv +0 -21
- package/benchmark-results/benchmark-results-2025-07-21T07-54-54-916Z.json +0 -503
- package/benchmark-results/error-report-2025-07-17T12-03-34-148Z.md +0 -18
- package/benchmark-results/error-report-2025-07-21T03-31-59-263Z.md +0 -18
- package/benchmark-results/error-report-2025-07-21T07-54-54-916Z.md +0 -18
- package/benchmark-results/gas-analysis-report-2025-07-17T12-03-15-563Z.md +0 -80
- package/benchmark-results/gas-analysis-report-2025-07-17T12-03-34-148Z.md +0 -80
- package/benchmark-results/gas-analysis-report-2025-07-21T03-31-59-263Z.md +0 -296
- package/benchmark-results/gas-analysis-report-2025-07-21T07-54-54-916Z.md +0 -323
- package/docs/Cetus_Aggregator_V3_/346/216/245/345/217/243/346/226/207/346/241/243.md +0 -706
- package/docs/REFACTOR.md +0 -24
- package/docs//350/267/257/345/276/204/346/213/223/346/211/221/346/216/222/345/272/217.md +0 -208
- package/script/copy-to-sui-aggregator.sh +0 -85
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"permissions": {
|
|
3
|
+
"allow": [
|
|
4
|
+
"mcp__ide__executeCode",
|
|
5
|
+
"Bash(node:*)",
|
|
6
|
+
"Bash(rm:*)",
|
|
7
|
+
"Bash(npm install:*)",
|
|
8
|
+
"Bash(npm run:*)",
|
|
9
|
+
"Bash(grep:*)",
|
|
10
|
+
"Bash(git add:*)",
|
|
11
|
+
"Bash(bun test:*)",
|
|
12
|
+
"Bash(bun run:*)",
|
|
13
|
+
"Bash(find:*)",
|
|
14
|
+
"Bash(mkdir:*)",
|
|
15
|
+
"Bash(mv:*)",
|
|
16
|
+
"Bash(git commit:*)",
|
|
17
|
+
"Bash(ls:*)",
|
|
18
|
+
"Bash(NODE_ENV=development bun test tests/aggregatorv3/router/sort.test.ts --verbose)",
|
|
19
|
+
"Bash(npx tsc:*)",
|
|
20
|
+
"mcp__ide__getDiagnostics",
|
|
21
|
+
"Bash(for:*)",
|
|
22
|
+
"Bash(do)",
|
|
23
|
+
"Bash(if grep -q \"import.*ENV\" \"$file\")",
|
|
24
|
+
"Bash(then)",
|
|
25
|
+
"Bash(sed:*)",
|
|
26
|
+
"Bash(echo \"Updated: $file\")",
|
|
27
|
+
"Bash(fi)",
|
|
28
|
+
"Bash(done)",
|
|
29
|
+
"Bash(if grep -q \"import.*Env\" \"$file\")",
|
|
30
|
+
"Bash(git reset:*)",
|
|
31
|
+
"Bash(cp:*)",
|
|
32
|
+
"WebFetch(domain:docs.blockvision.org)",
|
|
33
|
+
"Bash(git restore:*)",
|
|
34
|
+
"Bash(bun tsc:*)",
|
|
35
|
+
"Bash(git checkout:*)",
|
|
36
|
+
"Bash(do echo \"=== $file ===\")",
|
|
37
|
+
"Bash(true)"
|
|
38
|
+
],
|
|
39
|
+
"deny": []
|
|
40
|
+
}
|
|
41
|
+
}
|
package/dist/index.d.mts
CHANGED
|
@@ -107,7 +107,7 @@ type RouterDataV3 = {
|
|
|
107
107
|
byAmountIn: boolean;
|
|
108
108
|
paths: Path[];
|
|
109
109
|
insufficientLiquidity: boolean;
|
|
110
|
-
deviationRatio
|
|
110
|
+
deviationRatio: number;
|
|
111
111
|
packages?: Map<string, string>;
|
|
112
112
|
totalDeepFee?: number;
|
|
113
113
|
error?: RouterError;
|
|
@@ -309,6 +309,7 @@ declare class AggregatorClient {
|
|
|
309
309
|
constructor(params: AggregatorClientParams);
|
|
310
310
|
newPythClients(pythUrls: string[]): SuiPriceServiceConnection[];
|
|
311
311
|
deepbookv3DeepFeeType(): string;
|
|
312
|
+
getDeepbookV3Config(): Promise<DeepbookV3ConfigResponse | null>;
|
|
312
313
|
getOneCoinUsedToMerge(coinType: string): Promise<string | null>;
|
|
313
314
|
findRouters(params: FindRouterParams): Promise<RouterDataV3 | null>;
|
|
314
315
|
executeFlexibleInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routerData: RouterDataV3, expectedAmountOut: string, amountLimit: string, pythPriceIDs: Map<string, string>, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument, packages?: Map<string, string>): Promise<void>;
|
|
@@ -678,8 +679,9 @@ declare const DEEPBOOK_V3_DEEP_FEE_TYPES: {
|
|
|
678
679
|
declare const CLIENT_CONFIG: {
|
|
679
680
|
readonly DEFAULT_PYTH_URL: "https://hermes.pyth.network";
|
|
680
681
|
readonly PYTH_TIMEOUT: 3000;
|
|
681
|
-
readonly
|
|
682
|
+
readonly MAX_OVERLAY_FEE_RATE_PARAMS: 0.1;
|
|
682
683
|
readonly FEE_RATE_MULTIPLIER: 1000000;
|
|
684
|
+
readonly MAX_FEE_RATE: 100000;
|
|
683
685
|
readonly DEFAULT_OVERLAY_FEE_RECEIVER: "0x0";
|
|
684
686
|
readonly ERRORS: {
|
|
685
687
|
readonly SIGNER_REQUIRED: "Signer is required, but not provided.";
|
|
@@ -692,6 +694,7 @@ declare const CLIENT_CONFIG: {
|
|
|
692
694
|
readonly QUOTE_ID_REQUIRED: "Quote ID is required";
|
|
693
695
|
readonly AGGREGATOR_V3_PACKAGE_REQUIRED: "Aggregator V3 package is required";
|
|
694
696
|
readonly PACKAGES_REQUIRED: "Packages are required";
|
|
697
|
+
readonly OVERLAY_FEE_RECEIVER_REQUIRED: "Overlay fee rate is set, but overlay fee receiver is not set";
|
|
695
698
|
};
|
|
696
699
|
};
|
|
697
700
|
declare const AGGREGATOR_V3_CONFIG: {
|
|
@@ -791,7 +794,7 @@ declare const GAS_TYPE_ARG = "0x2::sui::SUI";
|
|
|
791
794
|
declare const GAS_TYPE_ARG_LONG = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI";
|
|
792
795
|
declare const GAS_SYMBOL = "SUI";
|
|
793
796
|
declare const DEFAULT_NFT_TRANSFER_GAS_FEE = 450;
|
|
794
|
-
declare const SUI_SYSTEM_STATE_OBJECT_ID = "
|
|
797
|
+
declare const SUI_SYSTEM_STATE_OBJECT_ID = "0x0000000000000000000000000000000000000000000000000000000000000005";
|
|
795
798
|
/**
|
|
796
799
|
* This class provides helper methods for working with coins.
|
|
797
800
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -107,7 +107,7 @@ type RouterDataV3 = {
|
|
|
107
107
|
byAmountIn: boolean;
|
|
108
108
|
paths: Path[];
|
|
109
109
|
insufficientLiquidity: boolean;
|
|
110
|
-
deviationRatio
|
|
110
|
+
deviationRatio: number;
|
|
111
111
|
packages?: Map<string, string>;
|
|
112
112
|
totalDeepFee?: number;
|
|
113
113
|
error?: RouterError;
|
|
@@ -309,6 +309,7 @@ declare class AggregatorClient {
|
|
|
309
309
|
constructor(params: AggregatorClientParams);
|
|
310
310
|
newPythClients(pythUrls: string[]): SuiPriceServiceConnection[];
|
|
311
311
|
deepbookv3DeepFeeType(): string;
|
|
312
|
+
getDeepbookV3Config(): Promise<DeepbookV3ConfigResponse | null>;
|
|
312
313
|
getOneCoinUsedToMerge(coinType: string): Promise<string | null>;
|
|
313
314
|
findRouters(params: FindRouterParams): Promise<RouterDataV3 | null>;
|
|
314
315
|
executeFlexibleInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routerData: RouterDataV3, expectedAmountOut: string, amountLimit: string, pythPriceIDs: Map<string, string>, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument, packages?: Map<string, string>): Promise<void>;
|
|
@@ -678,8 +679,9 @@ declare const DEEPBOOK_V3_DEEP_FEE_TYPES: {
|
|
|
678
679
|
declare const CLIENT_CONFIG: {
|
|
679
680
|
readonly DEFAULT_PYTH_URL: "https://hermes.pyth.network";
|
|
680
681
|
readonly PYTH_TIMEOUT: 3000;
|
|
681
|
-
readonly
|
|
682
|
+
readonly MAX_OVERLAY_FEE_RATE_PARAMS: 0.1;
|
|
682
683
|
readonly FEE_RATE_MULTIPLIER: 1000000;
|
|
684
|
+
readonly MAX_FEE_RATE: 100000;
|
|
683
685
|
readonly DEFAULT_OVERLAY_FEE_RECEIVER: "0x0";
|
|
684
686
|
readonly ERRORS: {
|
|
685
687
|
readonly SIGNER_REQUIRED: "Signer is required, but not provided.";
|
|
@@ -692,6 +694,7 @@ declare const CLIENT_CONFIG: {
|
|
|
692
694
|
readonly QUOTE_ID_REQUIRED: "Quote ID is required";
|
|
693
695
|
readonly AGGREGATOR_V3_PACKAGE_REQUIRED: "Aggregator V3 package is required";
|
|
694
696
|
readonly PACKAGES_REQUIRED: "Packages are required";
|
|
697
|
+
readonly OVERLAY_FEE_RECEIVER_REQUIRED: "Overlay fee rate is set, but overlay fee receiver is not set";
|
|
695
698
|
};
|
|
696
699
|
};
|
|
697
700
|
declare const AGGREGATOR_V3_CONFIG: {
|
|
@@ -791,7 +794,7 @@ declare const GAS_TYPE_ARG = "0x2::sui::SUI";
|
|
|
791
794
|
declare const GAS_TYPE_ARG_LONG = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI";
|
|
792
795
|
declare const GAS_SYMBOL = "SUI";
|
|
793
796
|
declare const DEFAULT_NFT_TRANSFER_GAS_FEE = 450;
|
|
794
|
-
declare const SUI_SYSTEM_STATE_OBJECT_ID = "
|
|
797
|
+
declare const SUI_SYSTEM_STATE_OBJECT_ID = "0x0000000000000000000000000000000000000000000000000000000000000005";
|
|
795
798
|
/**
|
|
796
799
|
* This class provides helper methods for working with coins.
|
|
797
800
|
*/
|
package/dist/index.js
CHANGED
|
@@ -2999,7 +2999,7 @@ var GAS_TYPE_ARG = "0x2::sui::SUI";
|
|
|
2999
2999
|
var GAS_TYPE_ARG_LONG = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI";
|
|
3000
3000
|
var GAS_SYMBOL = "SUI";
|
|
3001
3001
|
var DEFAULT_NFT_TRANSFER_GAS_FEE = 450;
|
|
3002
|
-
var SUI_SYSTEM_STATE_OBJECT_ID = "
|
|
3002
|
+
var SUI_SYSTEM_STATE_OBJECT_ID = "0x0000000000000000000000000000000000000000000000000000000000000005";
|
|
3003
3003
|
var CoinUtils = class _CoinUtils {
|
|
3004
3004
|
/**
|
|
3005
3005
|
* Get the coin type argument from a SuiMoveObject.
|
|
@@ -3107,10 +3107,18 @@ var CoinUtils = class _CoinUtils {
|
|
|
3107
3107
|
* @returns The CoinAsset objects that have a balance greater than or equal to the given amount.
|
|
3108
3108
|
*/
|
|
3109
3109
|
static selectCoinObjectIdGreaterThanOrEqual(coins, amount, exclude = []) {
|
|
3110
|
-
const selectedResult = _CoinUtils.selectCoinAssetGreaterThanOrEqual(
|
|
3111
|
-
|
|
3110
|
+
const selectedResult = _CoinUtils.selectCoinAssetGreaterThanOrEqual(
|
|
3111
|
+
coins,
|
|
3112
|
+
amount,
|
|
3113
|
+
exclude
|
|
3114
|
+
);
|
|
3115
|
+
const objectArray = selectedResult.selectedCoins.map(
|
|
3116
|
+
(item) => item.coinObjectId
|
|
3117
|
+
);
|
|
3112
3118
|
const remainCoins = selectedResult.remainingCoins;
|
|
3113
|
-
const amountArray = selectedResult.selectedCoins.map(
|
|
3119
|
+
const amountArray = selectedResult.selectedCoins.map(
|
|
3120
|
+
(item) => item.balance.toString()
|
|
3121
|
+
);
|
|
3114
3122
|
return { objectArray, remainCoins, amountArray };
|
|
3115
3123
|
}
|
|
3116
3124
|
/**
|
|
@@ -3122,7 +3130,9 @@ var CoinUtils = class _CoinUtils {
|
|
|
3122
3130
|
* @returns The CoinAsset objects that have a balance greater than or equal to the given amount.
|
|
3123
3131
|
*/
|
|
3124
3132
|
static selectCoinAssetGreaterThanOrEqual(coins, amount, exclude = []) {
|
|
3125
|
-
const sortedCoins = _CoinUtils.sortByBalance(
|
|
3133
|
+
const sortedCoins = _CoinUtils.sortByBalance(
|
|
3134
|
+
coins.filter((c) => !exclude.includes(c.coinObjectId))
|
|
3135
|
+
);
|
|
3126
3136
|
const total = _CoinUtils.calculateTotalBalance(sortedCoins);
|
|
3127
3137
|
if (total < amount) {
|
|
3128
3138
|
return { selectedCoins: [], remainingCoins: sortedCoins };
|
|
@@ -3135,9 +3145,13 @@ var CoinUtils = class _CoinUtils {
|
|
|
3135
3145
|
const remainingCoins = [...sortedCoins];
|
|
3136
3146
|
while (sum2 < total) {
|
|
3137
3147
|
const target = amount - sum2;
|
|
3138
|
-
const coinWithSmallestSufficientBalanceIndex = remainingCoins.findIndex(
|
|
3148
|
+
const coinWithSmallestSufficientBalanceIndex = remainingCoins.findIndex(
|
|
3149
|
+
(c) => c.balance >= target
|
|
3150
|
+
);
|
|
3139
3151
|
if (coinWithSmallestSufficientBalanceIndex !== -1) {
|
|
3140
|
-
selectedCoins.push(
|
|
3152
|
+
selectedCoins.push(
|
|
3153
|
+
remainingCoins[coinWithSmallestSufficientBalanceIndex]
|
|
3154
|
+
);
|
|
3141
3155
|
remainingCoins.splice(coinWithSmallestSufficientBalanceIndex, 1);
|
|
3142
3156
|
break;
|
|
3143
3157
|
}
|
|
@@ -3147,7 +3161,10 @@ var CoinUtils = class _CoinUtils {
|
|
|
3147
3161
|
sum2 += coinWithLargestBalance.balance;
|
|
3148
3162
|
}
|
|
3149
3163
|
}
|
|
3150
|
-
return {
|
|
3164
|
+
return {
|
|
3165
|
+
selectedCoins: _CoinUtils.sortByBalance(selectedCoins),
|
|
3166
|
+
remainingCoins: _CoinUtils.sortByBalance(remainingCoins)
|
|
3167
|
+
};
|
|
3151
3168
|
}
|
|
3152
3169
|
/**
|
|
3153
3170
|
* Sort the CoinAsset objects by their balance.
|
|
@@ -3156,10 +3173,14 @@ var CoinUtils = class _CoinUtils {
|
|
|
3156
3173
|
* @returns The sorted CoinAsset objects.
|
|
3157
3174
|
*/
|
|
3158
3175
|
static sortByBalance(coins) {
|
|
3159
|
-
return coins.sort(
|
|
3176
|
+
return coins.sort(
|
|
3177
|
+
(a, b) => a.balance < b.balance ? -1 : a.balance > b.balance ? 1 : 0
|
|
3178
|
+
);
|
|
3160
3179
|
}
|
|
3161
3180
|
static sortByBalanceDes(coins) {
|
|
3162
|
-
return coins.sort(
|
|
3181
|
+
return coins.sort(
|
|
3182
|
+
(a, b) => a.balance > b.balance ? -1 : a.balance < b.balance ? 0 : 1
|
|
3183
|
+
);
|
|
3163
3184
|
}
|
|
3164
3185
|
/**
|
|
3165
3186
|
* Calculate the total balance of a list of CoinAsset objects.
|
|
@@ -3397,8 +3418,9 @@ var DEEPBOOK_V3_DEEP_FEE_TYPES = {
|
|
|
3397
3418
|
var CLIENT_CONFIG = {
|
|
3398
3419
|
DEFAULT_PYTH_URL: "https://hermes.pyth.network",
|
|
3399
3420
|
PYTH_TIMEOUT: 3e3,
|
|
3400
|
-
|
|
3421
|
+
MAX_OVERLAY_FEE_RATE_PARAMS: 0.1,
|
|
3401
3422
|
FEE_RATE_MULTIPLIER: 1e6,
|
|
3423
|
+
MAX_FEE_RATE: 1e5,
|
|
3402
3424
|
DEFAULT_OVERLAY_FEE_RECEIVER: "0x0",
|
|
3403
3425
|
// Error Messages
|
|
3404
3426
|
ERRORS: {
|
|
@@ -3411,7 +3433,8 @@ var CLIENT_CONFIG = {
|
|
|
3411
3433
|
PYTH_UNAVAILABLE: "All Pyth price nodes are unavailable. Cannot fetch price data. Please switch to or add new available Pyth nodes",
|
|
3412
3434
|
QUOTE_ID_REQUIRED: "Quote ID is required",
|
|
3413
3435
|
AGGREGATOR_V3_PACKAGE_REQUIRED: "Aggregator V3 package is required",
|
|
3414
|
-
PACKAGES_REQUIRED: "Packages are required"
|
|
3436
|
+
PACKAGES_REQUIRED: "Packages are required",
|
|
3437
|
+
OVERLAY_FEE_RECEIVER_REQUIRED: "Overlay fee rate is set, but overlay fee receiver is not set"
|
|
3415
3438
|
}
|
|
3416
3439
|
};
|
|
3417
3440
|
var AGGREGATOR_V3_CONFIG = {
|
|
@@ -3426,7 +3449,7 @@ var AGGREGATOR_V3_CONFIG = {
|
|
|
3426
3449
|
};
|
|
3427
3450
|
|
|
3428
3451
|
// src/api.ts
|
|
3429
|
-
var SDK_VERSION =
|
|
3452
|
+
var SDK_VERSION = 1010104;
|
|
3430
3453
|
function parseRouterResponse(data, byAmountIn) {
|
|
3431
3454
|
let packages = /* @__PURE__ */ new Map();
|
|
3432
3455
|
if (data.packages) {
|
|
@@ -3444,6 +3467,7 @@ function parseRouterResponse(data, byAmountIn) {
|
|
|
3444
3467
|
amountOut: new import_bn2.default(data.amount_out.toString()),
|
|
3445
3468
|
byAmountIn,
|
|
3446
3469
|
insufficientLiquidity: false,
|
|
3470
|
+
deviationRatio: data.deviation_ratio,
|
|
3447
3471
|
packages,
|
|
3448
3472
|
paths: data.paths.map((path) => ({
|
|
3449
3473
|
id: path.id,
|
|
@@ -6695,7 +6719,7 @@ var SpringsuiRouter = class {
|
|
|
6695
6719
|
const args = [
|
|
6696
6720
|
swapContext,
|
|
6697
6721
|
txb.object(swapData.poolId),
|
|
6698
|
-
txb.object(
|
|
6722
|
+
txb.object(SUI_SYSTEM_STATE_OBJECT_ID),
|
|
6699
6723
|
txb.pure.u64(swapData.amountIn),
|
|
6700
6724
|
txb.pure.bool(swapData.direction)
|
|
6701
6725
|
];
|
|
@@ -7377,8 +7401,7 @@ var VoloRouter = class {
|
|
|
7377
7401
|
swapContext,
|
|
7378
7402
|
txb.object(this.stakePool),
|
|
7379
7403
|
txb.object(this.metadata),
|
|
7380
|
-
txb.object(
|
|
7381
|
-
// SuiSystemState
|
|
7404
|
+
txb.object(SUI_SYSTEM_STATE_OBJECT_ID),
|
|
7382
7405
|
txb.pure.bool(swapData.direction),
|
|
7383
7406
|
txb.pure.u64(swapData.amountIn)
|
|
7384
7407
|
];
|
|
@@ -7429,8 +7452,7 @@ var AfsuiRouter = class {
|
|
|
7429
7452
|
swapContext,
|
|
7430
7453
|
txb.object(this.stakedSuiVault),
|
|
7431
7454
|
txb.object(this.safe),
|
|
7432
|
-
txb.object(
|
|
7433
|
-
// SuiSystemState
|
|
7455
|
+
txb.object(SUI_SYSTEM_STATE_OBJECT_ID),
|
|
7434
7456
|
txb.object(this.referVault),
|
|
7435
7457
|
txb.object(this.validator),
|
|
7436
7458
|
txb.pure.bool(swapData.direction),
|
|
@@ -7475,8 +7497,7 @@ var HaedalRouter = class {
|
|
|
7475
7497
|
const args = [
|
|
7476
7498
|
swapContext,
|
|
7477
7499
|
txb.object(swapData.poolId),
|
|
7478
|
-
txb.object(
|
|
7479
|
-
// SuiSystemState
|
|
7500
|
+
txb.object(SUI_SYSTEM_STATE_OBJECT_ID),
|
|
7480
7501
|
txb.pure.bool(swapData.direction),
|
|
7481
7502
|
txb.pure.u64(swapData.amountIn)
|
|
7482
7503
|
];
|
|
@@ -8235,7 +8256,7 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
8235
8256
|
this.apiKey = params.apiKey || "";
|
|
8236
8257
|
this.partner = params.partner;
|
|
8237
8258
|
if (params.overlayFeeRate) {
|
|
8238
|
-
if (params.overlayFeeRate > 0 && params.overlayFeeRate <= CLIENT_CONFIG.
|
|
8259
|
+
if (params.overlayFeeRate > 0 && params.overlayFeeRate <= CLIENT_CONFIG.MAX_OVERLAY_FEE_RATE_PARAMS) {
|
|
8239
8260
|
this.overlayFeeRate = params.overlayFeeRate * AGGREGATOR_V3_CONFIG.FEE_DENOMINATOR;
|
|
8240
8261
|
if (this.overlayFeeRate > AGGREGATOR_V3_CONFIG.MAX_FEE_RATE) {
|
|
8241
8262
|
throw new Error(
|
|
@@ -8266,6 +8287,11 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
8266
8287
|
return DEEPBOOK_V3_DEEP_FEE_TYPES.Testnet;
|
|
8267
8288
|
}
|
|
8268
8289
|
}
|
|
8290
|
+
getDeepbookV3Config() {
|
|
8291
|
+
return __async(this, null, function* () {
|
|
8292
|
+
return yield getDeepbookV3Config(this.endpoint);
|
|
8293
|
+
});
|
|
8294
|
+
}
|
|
8269
8295
|
getOneCoinUsedToMerge(coinType) {
|
|
8270
8296
|
return __async(this, null, function* () {
|
|
8271
8297
|
try {
|
|
@@ -8516,20 +8542,22 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
8516
8542
|
}
|
|
8517
8543
|
routerSwap(params) {
|
|
8518
8544
|
return __async(this, null, function* () {
|
|
8519
|
-
const { router, inputCoin, slippage, txb,
|
|
8545
|
+
const { router, inputCoin, slippage, txb, partner } = params;
|
|
8520
8546
|
if (slippage > 1 || slippage < 0) {
|
|
8521
8547
|
throw new Error(CLIENT_CONFIG.ERRORS.INVALID_SLIPPAGE);
|
|
8522
8548
|
}
|
|
8549
|
+
if (!params.router.packages || !params.router.packages.get(PACKAGE_NAMES.AGGREGATOR_V3)) {
|
|
8550
|
+
throw new Error(CLIENT_CONFIG.ERRORS.PACKAGES_REQUIRED);
|
|
8551
|
+
}
|
|
8523
8552
|
const byAmountIn = params.router.byAmountIn;
|
|
8524
8553
|
const amountIn = router.amountIn;
|
|
8525
8554
|
const amountOut = router.amountOut;
|
|
8555
|
+
checkOverlayFeeConfig(this.overlayFeeRate, this.overlayFeeReceiver);
|
|
8526
8556
|
let overlayFee = new import_bn6.default(0);
|
|
8527
|
-
if (
|
|
8528
|
-
|
|
8529
|
-
|
|
8530
|
-
|
|
8531
|
-
overlayFee = amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6));
|
|
8532
|
-
}
|
|
8557
|
+
if (byAmountIn) {
|
|
8558
|
+
overlayFee = amountOut.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6));
|
|
8559
|
+
} else {
|
|
8560
|
+
overlayFee = amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6));
|
|
8533
8561
|
}
|
|
8534
8562
|
const expectedAmountOut = byAmountIn ? amountOut.sub(overlayFee) : amountOut;
|
|
8535
8563
|
const expectedAmountIn = byAmountIn ? amountIn : amountIn.add(overlayFee);
|
|
@@ -8538,9 +8566,6 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
8538
8566
|
byAmountIn,
|
|
8539
8567
|
slippage
|
|
8540
8568
|
);
|
|
8541
|
-
if (!params.router.packages || !params.router.packages.get(PACKAGE_NAMES.AGGREGATOR_V3)) {
|
|
8542
|
-
throw new Error(CLIENT_CONFIG.ERRORS.PACKAGES_REQUIRED);
|
|
8543
|
-
}
|
|
8544
8569
|
const priceIDs = findPythPriceIDs(router.paths);
|
|
8545
8570
|
const priceInfoObjectIds = priceIDs.length > 0 ? yield this.updatePythPriceIDs(priceIDs, txb) : /* @__PURE__ */ new Map();
|
|
8546
8571
|
if (byAmountIn) {
|
|
@@ -8573,17 +8598,16 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
8573
8598
|
const fromCoinType = router.paths[0].from;
|
|
8574
8599
|
const targetCoinType = router.paths[router.paths.length - 1].target;
|
|
8575
8600
|
const byAmountIn = router.byAmountIn;
|
|
8601
|
+
checkOverlayFeeConfig(this.overlayFeeRate, this.overlayFeeReceiver);
|
|
8576
8602
|
let overlayFee = 0;
|
|
8577
|
-
if (
|
|
8578
|
-
|
|
8579
|
-
|
|
8580
|
-
|
|
8581
|
-
|
|
8582
|
-
|
|
8583
|
-
|
|
8584
|
-
|
|
8585
|
-
);
|
|
8586
|
-
}
|
|
8603
|
+
if (byAmountIn) {
|
|
8604
|
+
overlayFee = Number(
|
|
8605
|
+
router.amountOut.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
|
|
8606
|
+
);
|
|
8607
|
+
} else {
|
|
8608
|
+
overlayFee = Number(
|
|
8609
|
+
router.amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
|
|
8610
|
+
);
|
|
8587
8611
|
}
|
|
8588
8612
|
const expectedAmountOut = byAmountIn ? router.amountOut.sub(new import_bn6.default(overlayFee)) : router.amountOut;
|
|
8589
8613
|
const expectedAmountIn = byAmountIn ? router.amountIn : router.amountIn.add(new import_bn6.default(overlayFee));
|
|
@@ -8635,18 +8659,17 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
8635
8659
|
}
|
|
8636
8660
|
fixableRouterSwapV3(params) {
|
|
8637
8661
|
return __async(this, null, function* () {
|
|
8638
|
-
const { router, inputCoin, slippage, txb,
|
|
8662
|
+
const { router, inputCoin, slippage, txb, partner } = params;
|
|
8663
|
+
checkOverlayFeeConfig(this.overlayFeeRate, this.overlayFeeReceiver);
|
|
8639
8664
|
let overlayFee = 0;
|
|
8640
|
-
if (
|
|
8641
|
-
|
|
8642
|
-
|
|
8643
|
-
|
|
8644
|
-
|
|
8645
|
-
|
|
8646
|
-
|
|
8647
|
-
|
|
8648
|
-
);
|
|
8649
|
-
}
|
|
8665
|
+
if (router.byAmountIn) {
|
|
8666
|
+
overlayFee = Number(
|
|
8667
|
+
router.amountOut.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
|
|
8668
|
+
);
|
|
8669
|
+
} else {
|
|
8670
|
+
overlayFee = Number(
|
|
8671
|
+
router.amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
|
|
8672
|
+
);
|
|
8650
8673
|
}
|
|
8651
8674
|
const expectedAmountOut = router.byAmountIn ? router.amountOut.sub(new import_bn6.default(overlayFee)) : router.amountOut;
|
|
8652
8675
|
const expectedAmountIn = router.byAmountIn ? router.amountIn : router.amountIn.add(new import_bn6.default(overlayFee));
|
|
@@ -8755,6 +8778,7 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
8755
8778
|
const routeData = {
|
|
8756
8779
|
amountIn,
|
|
8757
8780
|
amountOut: new import_bn6.default((_d = event.amount_out) != null ? _d : 0),
|
|
8781
|
+
deviationRatio: 0,
|
|
8758
8782
|
paths: [
|
|
8759
8783
|
{
|
|
8760
8784
|
id: pools[tempIndex],
|
|
@@ -8872,6 +8896,16 @@ function recordFirstCoinIndex(paths) {
|
|
|
8872
8896
|
}
|
|
8873
8897
|
return newCoinRecord;
|
|
8874
8898
|
}
|
|
8899
|
+
function checkOverlayFeeConfig(overlayFeeRate, overlayFeeReceiver) {
|
|
8900
|
+
if (overlayFeeRate > CLIENT_CONFIG.MAX_FEE_RATE) {
|
|
8901
|
+
throw new Error(CLIENT_CONFIG.ERRORS.INVALID_OVERLAY_FEE_RATE);
|
|
8902
|
+
}
|
|
8903
|
+
if (overlayFeeReceiver === "0x0" && overlayFeeRate > 0) {
|
|
8904
|
+
throw new Error(
|
|
8905
|
+
CLIENT_CONFIG.ERRORS.OVERLAY_FEE_RECEIVER_REQUIRED
|
|
8906
|
+
);
|
|
8907
|
+
}
|
|
8908
|
+
}
|
|
8875
8909
|
|
|
8876
8910
|
// src/types/sui.ts
|
|
8877
8911
|
var getDefaultSuiInputType = (value) => {
|