@cetusprotocol/aggregator-sdk 0.3.0 → 0.3.2
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 +46 -4
- package/dist/index.d.ts +46 -4
- package/dist/index.js +156 -25
- package/dist/index.mjs +145 -24
- package/dist/src/api.d.ts +20 -0
- package/dist/src/client.d.ts +10 -3
- package/dist/src/transaction/deepbook_v3.d.ts +12 -0
- package/dist/src/transaction/index.d.ts +1 -1
- package/dist/src/utils/api.d.ts +1 -0
- package/dist/src/utils/index.d.ts +3 -0
- package/dist/tests/test_data.test.d.ts +4 -0
- package/package.json +1 -1
- package/src/api.ts +40 -7
- package/src/client.ts +87 -15
- package/src/transaction/afsui.ts +0 -1
- package/src/transaction/aftermath.ts +0 -2
- package/src/transaction/deepbook_v2.ts +0 -1
- package/src/transaction/deepbook_v3.ts +58 -0
- package/src/transaction/index.ts +2 -1
- package/src/transaction/swap.ts +6 -0
- package/src/transaction/volo.ts +0 -1
- package/src/utils/api.ts +6 -0
- package/src/utils/coin.ts +2 -2
- package/src/utils/index.ts +3 -0
- package/test.json +5 -0
- package/tests/router.test.ts +37 -46
- package/tests/test_data.test.ts +4 -0
package/dist/index.d.mts
CHANGED
|
@@ -72,6 +72,8 @@ declare const HAEDAL = "HAEDAL";
|
|
|
72
72
|
declare const VOLO = "VOLO";
|
|
73
73
|
declare const AFSUI = "AFSUI";
|
|
74
74
|
declare const BLUEMOVE = "BLUEMOVE";
|
|
75
|
+
declare const DEEPBOOKV3 = "DEEPBOOKV3";
|
|
76
|
+
declare const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
75
77
|
type BuildRouterSwapParams = {
|
|
76
78
|
routers: Router[];
|
|
77
79
|
byAmountIn: boolean;
|
|
@@ -79,6 +81,7 @@ type BuildRouterSwapParams = {
|
|
|
79
81
|
slippage: number;
|
|
80
82
|
txb: Transaction;
|
|
81
83
|
partner?: string;
|
|
84
|
+
deepbookv3DeepFee?: TransactionObjectArgument;
|
|
82
85
|
};
|
|
83
86
|
type BuildFastRouterSwapParams = {
|
|
84
87
|
routers: Router[];
|
|
@@ -88,6 +91,7 @@ type BuildFastRouterSwapParams = {
|
|
|
88
91
|
partner?: string;
|
|
89
92
|
isMergeTragetCoin?: boolean;
|
|
90
93
|
refreshAllCoins?: boolean;
|
|
94
|
+
payDeepFeeAmount?: number;
|
|
91
95
|
};
|
|
92
96
|
interface SwapInPoolsParams {
|
|
93
97
|
from: string;
|
|
@@ -106,27 +110,30 @@ declare class AggregatorClient {
|
|
|
106
110
|
client: SuiClient;
|
|
107
111
|
env: Env;
|
|
108
112
|
private allCoins;
|
|
109
|
-
constructor(endpoint
|
|
113
|
+
constructor(endpoint?: string, signer?: string, client?: SuiClient, env?: Env);
|
|
110
114
|
getAllCoins(): Promise<CoinAsset[]>;
|
|
111
115
|
findRouters(params: FindRouterParams): Promise<RouterData | null>;
|
|
112
|
-
expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, partner?: string): Promise<TransactionObjectArgument>;
|
|
116
|
+
expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
|
|
113
117
|
expectOutputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], partner?: string): Promise<TransactionObjectArgument>;
|
|
114
118
|
swapInPools(params: SwapInPoolsParams): Promise<SwapInPoolsResult | null>;
|
|
115
119
|
routerSwap(params: BuildRouterSwapParams): Promise<TransactionObjectArgument>;
|
|
116
120
|
fastRouterSwap(params: BuildFastRouterSwapParams): Promise<void>;
|
|
117
121
|
publishedAt(): string;
|
|
122
|
+
publishedAtV2(): string;
|
|
123
|
+
deepbookv3DeepFeeType(): string;
|
|
118
124
|
transferOrDestoryCoin(txb: Transaction, coin: TransactionObjectArgument, coinType: string): void;
|
|
119
125
|
checkCoinThresholdAndMergeCoin(txb: Transaction, coins: TransactionObjectArgument[], coinType: string, amountLimit: BN): TransactionObjectArgument;
|
|
120
126
|
newDex(provider: string, partner?: string): Dex;
|
|
121
127
|
signAndExecuteTransaction(txb: Transaction, signer: Signer): Promise<_mysten_sui_client.SuiTransactionBlockResponse>;
|
|
122
128
|
devInspectTransactionBlock(txb: Transaction): Promise<_mysten_sui_client.DevInspectResults>;
|
|
123
129
|
sendTransaction(txb: Transaction, signer: Signer): Promise<_mysten_sui_client.SuiTransactionBlockResponse>;
|
|
130
|
+
getDeepbookV3Config(): Promise<DeepbookV3Config | null>;
|
|
124
131
|
}
|
|
125
132
|
declare function parseRouterResponse(data: any): RouterData;
|
|
126
133
|
|
|
127
134
|
declare const CLOCK_ADDRESS = "0x0000000000000000000000000000000000000000000000000000000000000006";
|
|
128
135
|
interface Dex {
|
|
129
|
-
swap(client: AggregatorClient, ptb: Transaction, path: Path, inputCoin: TransactionObjectArgument): Promise<TransactionObjectArgument>;
|
|
136
|
+
swap(client: AggregatorClient, ptb: Transaction, path: Path, inputCoin: TransactionObjectArgument, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
|
|
130
137
|
}
|
|
131
138
|
|
|
132
139
|
declare function isSortedSymbols(symbolX: string, symbolY: string): boolean;
|
|
@@ -148,6 +155,21 @@ declare function createTarget(packageName: string, moduleName: string, functionN
|
|
|
148
155
|
declare const dealWithFastRouterSwapParamsForMsafe: (data: any) => any;
|
|
149
156
|
declare const restituteMsafeFastRouterSwapParams: (data: any) => any;
|
|
150
157
|
|
|
158
|
+
declare function processEndpoint(endpoint: string): string;
|
|
159
|
+
|
|
160
|
+
declare function completionCoin(s: string): string;
|
|
161
|
+
declare function compareCoins(coinA: string, coinB: string): boolean;
|
|
162
|
+
declare function mintZeroCoin(txb: Transaction, coinType: string): TransactionObjectArgument;
|
|
163
|
+
type BuildCoinResult = {
|
|
164
|
+
targetCoin: TransactionObjectArgument;
|
|
165
|
+
isMintZeroCoin: boolean;
|
|
166
|
+
targetCoinAmount: number;
|
|
167
|
+
};
|
|
168
|
+
declare function buildInputCoin(txb: Transaction, allCoins: CoinAsset[], amount: bigint, coinType: string): BuildCoinResult;
|
|
169
|
+
|
|
170
|
+
declare function printTransaction(tx: Transaction, isPrint?: boolean): Promise<void>;
|
|
171
|
+
declare function checkInvalidSuiAddress(address: string): boolean;
|
|
172
|
+
|
|
151
173
|
declare const ZERO: BN;
|
|
152
174
|
declare const ONE: BN;
|
|
153
175
|
declare const TWO: BN;
|
|
@@ -179,6 +201,7 @@ type ExtendedDetails = {
|
|
|
179
201
|
aftermathLpSupplyType?: string;
|
|
180
202
|
turbosFeeType?: string;
|
|
181
203
|
afterSqrtPrice?: string;
|
|
204
|
+
deepbookv3DeepFee?: number;
|
|
182
205
|
};
|
|
183
206
|
type Path = {
|
|
184
207
|
id: string;
|
|
@@ -207,6 +230,7 @@ type RouterData = {
|
|
|
207
230
|
amountOut: BN;
|
|
208
231
|
routes: Router[];
|
|
209
232
|
insufficientLiquidity: boolean;
|
|
233
|
+
totalDeepFee?: number;
|
|
210
234
|
error?: RouterError;
|
|
211
235
|
};
|
|
212
236
|
type AggregatorResponse = {
|
|
@@ -215,10 +239,28 @@ type AggregatorResponse = {
|
|
|
215
239
|
data: RouterData;
|
|
216
240
|
};
|
|
217
241
|
declare function getRouterResult(endpoint: string, params: FindRouterParams): Promise<RouterData | null>;
|
|
242
|
+
type DeepbookV3Config = {
|
|
243
|
+
id: string;
|
|
244
|
+
is_alternative_payment: boolean;
|
|
245
|
+
alternative_payment_amount: number;
|
|
246
|
+
trade_cap: string;
|
|
247
|
+
balance_manager: string;
|
|
248
|
+
deep_fee_vault: number;
|
|
249
|
+
whitelist: number;
|
|
250
|
+
package_version: 0;
|
|
251
|
+
last_updated_time: number;
|
|
252
|
+
whitelist_pools: string[];
|
|
253
|
+
};
|
|
254
|
+
type DeepbookV3ConfigResponse = {
|
|
255
|
+
code: number;
|
|
256
|
+
msg: string;
|
|
257
|
+
data: DeepbookV3Config;
|
|
258
|
+
};
|
|
259
|
+
declare function getDeepbookV3Config(endpoint: string): Promise<DeepbookV3ConfigResponse | null>;
|
|
218
260
|
|
|
219
261
|
declare enum Env {
|
|
220
262
|
Mainnet = 0,
|
|
221
263
|
Testnet = 1
|
|
222
264
|
}
|
|
223
265
|
|
|
224
|
-
export { AFSUI, AFTERMATH, AggregatorClient, type AggregatorResponse, BLUEMOVE, type BuildFastRouterSwapParams, type BuildRouterSwapParams, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWXV3, type FindRouterParams, HAEDAL, KRIYA, KRIYAV3, ONE, type Path, type PreSwapLpChangeParams, type Router, type RouterData, type RouterError, type SwapInPoolsParams, type SwapInPoolsResult, TEN_POW_NINE, TURBOS, TWO, U128, U64_MAX, U64_MAX_BN, VOLO, ZERO, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, extractAddressFromType, extractStructTagFromType, fixSuiObjectId, getRouterResult, isSortedSymbols, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, restituteMsafeFastRouterSwapParams };
|
|
266
|
+
export { AFSUI, AFTERMATH, AggregatorClient, type AggregatorResponse, 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, 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
|
@@ -72,6 +72,8 @@ declare const HAEDAL = "HAEDAL";
|
|
|
72
72
|
declare const VOLO = "VOLO";
|
|
73
73
|
declare const AFSUI = "AFSUI";
|
|
74
74
|
declare const BLUEMOVE = "BLUEMOVE";
|
|
75
|
+
declare const DEEPBOOKV3 = "DEEPBOOKV3";
|
|
76
|
+
declare const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
75
77
|
type BuildRouterSwapParams = {
|
|
76
78
|
routers: Router[];
|
|
77
79
|
byAmountIn: boolean;
|
|
@@ -79,6 +81,7 @@ type BuildRouterSwapParams = {
|
|
|
79
81
|
slippage: number;
|
|
80
82
|
txb: Transaction;
|
|
81
83
|
partner?: string;
|
|
84
|
+
deepbookv3DeepFee?: TransactionObjectArgument;
|
|
82
85
|
};
|
|
83
86
|
type BuildFastRouterSwapParams = {
|
|
84
87
|
routers: Router[];
|
|
@@ -88,6 +91,7 @@ type BuildFastRouterSwapParams = {
|
|
|
88
91
|
partner?: string;
|
|
89
92
|
isMergeTragetCoin?: boolean;
|
|
90
93
|
refreshAllCoins?: boolean;
|
|
94
|
+
payDeepFeeAmount?: number;
|
|
91
95
|
};
|
|
92
96
|
interface SwapInPoolsParams {
|
|
93
97
|
from: string;
|
|
@@ -106,27 +110,30 @@ declare class AggregatorClient {
|
|
|
106
110
|
client: SuiClient;
|
|
107
111
|
env: Env;
|
|
108
112
|
private allCoins;
|
|
109
|
-
constructor(endpoint
|
|
113
|
+
constructor(endpoint?: string, signer?: string, client?: SuiClient, env?: Env);
|
|
110
114
|
getAllCoins(): Promise<CoinAsset[]>;
|
|
111
115
|
findRouters(params: FindRouterParams): Promise<RouterData | null>;
|
|
112
|
-
expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, partner?: string): Promise<TransactionObjectArgument>;
|
|
116
|
+
expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
|
|
113
117
|
expectOutputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], partner?: string): Promise<TransactionObjectArgument>;
|
|
114
118
|
swapInPools(params: SwapInPoolsParams): Promise<SwapInPoolsResult | null>;
|
|
115
119
|
routerSwap(params: BuildRouterSwapParams): Promise<TransactionObjectArgument>;
|
|
116
120
|
fastRouterSwap(params: BuildFastRouterSwapParams): Promise<void>;
|
|
117
121
|
publishedAt(): string;
|
|
122
|
+
publishedAtV2(): string;
|
|
123
|
+
deepbookv3DeepFeeType(): string;
|
|
118
124
|
transferOrDestoryCoin(txb: Transaction, coin: TransactionObjectArgument, coinType: string): void;
|
|
119
125
|
checkCoinThresholdAndMergeCoin(txb: Transaction, coins: TransactionObjectArgument[], coinType: string, amountLimit: BN): TransactionObjectArgument;
|
|
120
126
|
newDex(provider: string, partner?: string): Dex;
|
|
121
127
|
signAndExecuteTransaction(txb: Transaction, signer: Signer): Promise<_mysten_sui_client.SuiTransactionBlockResponse>;
|
|
122
128
|
devInspectTransactionBlock(txb: Transaction): Promise<_mysten_sui_client.DevInspectResults>;
|
|
123
129
|
sendTransaction(txb: Transaction, signer: Signer): Promise<_mysten_sui_client.SuiTransactionBlockResponse>;
|
|
130
|
+
getDeepbookV3Config(): Promise<DeepbookV3Config | null>;
|
|
124
131
|
}
|
|
125
132
|
declare function parseRouterResponse(data: any): RouterData;
|
|
126
133
|
|
|
127
134
|
declare const CLOCK_ADDRESS = "0x0000000000000000000000000000000000000000000000000000000000000006";
|
|
128
135
|
interface Dex {
|
|
129
|
-
swap(client: AggregatorClient, ptb: Transaction, path: Path, inputCoin: TransactionObjectArgument): Promise<TransactionObjectArgument>;
|
|
136
|
+
swap(client: AggregatorClient, ptb: Transaction, path: Path, inputCoin: TransactionObjectArgument, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
|
|
130
137
|
}
|
|
131
138
|
|
|
132
139
|
declare function isSortedSymbols(symbolX: string, symbolY: string): boolean;
|
|
@@ -148,6 +155,21 @@ declare function createTarget(packageName: string, moduleName: string, functionN
|
|
|
148
155
|
declare const dealWithFastRouterSwapParamsForMsafe: (data: any) => any;
|
|
149
156
|
declare const restituteMsafeFastRouterSwapParams: (data: any) => any;
|
|
150
157
|
|
|
158
|
+
declare function processEndpoint(endpoint: string): string;
|
|
159
|
+
|
|
160
|
+
declare function completionCoin(s: string): string;
|
|
161
|
+
declare function compareCoins(coinA: string, coinB: string): boolean;
|
|
162
|
+
declare function mintZeroCoin(txb: Transaction, coinType: string): TransactionObjectArgument;
|
|
163
|
+
type BuildCoinResult = {
|
|
164
|
+
targetCoin: TransactionObjectArgument;
|
|
165
|
+
isMintZeroCoin: boolean;
|
|
166
|
+
targetCoinAmount: number;
|
|
167
|
+
};
|
|
168
|
+
declare function buildInputCoin(txb: Transaction, allCoins: CoinAsset[], amount: bigint, coinType: string): BuildCoinResult;
|
|
169
|
+
|
|
170
|
+
declare function printTransaction(tx: Transaction, isPrint?: boolean): Promise<void>;
|
|
171
|
+
declare function checkInvalidSuiAddress(address: string): boolean;
|
|
172
|
+
|
|
151
173
|
declare const ZERO: BN;
|
|
152
174
|
declare const ONE: BN;
|
|
153
175
|
declare const TWO: BN;
|
|
@@ -179,6 +201,7 @@ type ExtendedDetails = {
|
|
|
179
201
|
aftermathLpSupplyType?: string;
|
|
180
202
|
turbosFeeType?: string;
|
|
181
203
|
afterSqrtPrice?: string;
|
|
204
|
+
deepbookv3DeepFee?: number;
|
|
182
205
|
};
|
|
183
206
|
type Path = {
|
|
184
207
|
id: string;
|
|
@@ -207,6 +230,7 @@ type RouterData = {
|
|
|
207
230
|
amountOut: BN;
|
|
208
231
|
routes: Router[];
|
|
209
232
|
insufficientLiquidity: boolean;
|
|
233
|
+
totalDeepFee?: number;
|
|
210
234
|
error?: RouterError;
|
|
211
235
|
};
|
|
212
236
|
type AggregatorResponse = {
|
|
@@ -215,10 +239,28 @@ type AggregatorResponse = {
|
|
|
215
239
|
data: RouterData;
|
|
216
240
|
};
|
|
217
241
|
declare function getRouterResult(endpoint: string, params: FindRouterParams): Promise<RouterData | null>;
|
|
242
|
+
type DeepbookV3Config = {
|
|
243
|
+
id: string;
|
|
244
|
+
is_alternative_payment: boolean;
|
|
245
|
+
alternative_payment_amount: number;
|
|
246
|
+
trade_cap: string;
|
|
247
|
+
balance_manager: string;
|
|
248
|
+
deep_fee_vault: number;
|
|
249
|
+
whitelist: number;
|
|
250
|
+
package_version: 0;
|
|
251
|
+
last_updated_time: number;
|
|
252
|
+
whitelist_pools: string[];
|
|
253
|
+
};
|
|
254
|
+
type DeepbookV3ConfigResponse = {
|
|
255
|
+
code: number;
|
|
256
|
+
msg: string;
|
|
257
|
+
data: DeepbookV3Config;
|
|
258
|
+
};
|
|
259
|
+
declare function getDeepbookV3Config(endpoint: string): Promise<DeepbookV3ConfigResponse | null>;
|
|
218
260
|
|
|
219
261
|
declare enum Env {
|
|
220
262
|
Mainnet = 0,
|
|
221
263
|
Testnet = 1
|
|
222
264
|
}
|
|
223
265
|
|
|
224
|
-
export { AFSUI, AFTERMATH, AggregatorClient, type AggregatorResponse, BLUEMOVE, type BuildFastRouterSwapParams, type BuildRouterSwapParams, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWXV3, type FindRouterParams, HAEDAL, KRIYA, KRIYAV3, ONE, type Path, type PreSwapLpChangeParams, type Router, type RouterData, type RouterError, type SwapInPoolsParams, type SwapInPoolsResult, TEN_POW_NINE, TURBOS, TWO, U128, U64_MAX, U64_MAX_BN, VOLO, ZERO, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, extractAddressFromType, extractStructTagFromType, fixSuiObjectId, getRouterResult, isSortedSymbols, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, restituteMsafeFastRouterSwapParams };
|
|
266
|
+
export { AFSUI, AFTERMATH, AggregatorClient, type AggregatorResponse, 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, 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
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var client = require('@mysten/sui/client');
|
|
3
4
|
var utils = require('@mysten/sui/utils');
|
|
4
5
|
var transactions = require('@mysten/sui/transactions');
|
|
5
6
|
|
|
@@ -5676,8 +5677,8 @@ function buildInputCoin(txb, allCoins, amount, coinType) {
|
|
|
5676
5677
|
let totalCoinBalance = CoinUtils.calculateTotalBalance(usedCoinAsests);
|
|
5677
5678
|
if (totalCoinBalance < amount) {
|
|
5678
5679
|
throw new AggregateError(
|
|
5679
|
-
"Insufficient balance when build merge coin",
|
|
5680
|
-
"InsufficientBalance" /* InsufficientBalance */
|
|
5680
|
+
"Insufficient balance when build merge coin, coinType: " + coinType,
|
|
5681
|
+
"InsufficientBalance" /* InsufficientBalance */ + coinType
|
|
5681
5682
|
);
|
|
5682
5683
|
}
|
|
5683
5684
|
if (CoinUtils.isSuiCoin(coinType)) {
|
|
@@ -5714,6 +5715,16 @@ function buildInputCoin(txb, allCoins, amount, coinType) {
|
|
|
5714
5715
|
}
|
|
5715
5716
|
|
|
5716
5717
|
// src/utils/transaction.ts
|
|
5718
|
+
function printTransaction(tx, isPrint = true) {
|
|
5719
|
+
return __async(this, null, function* () {
|
|
5720
|
+
console.log(`inputs`, tx.getData().inputs);
|
|
5721
|
+
tx.getData().commands.forEach((item, index) => {
|
|
5722
|
+
if (isPrint) {
|
|
5723
|
+
console.log(`transaction ${index}: `, JSON.stringify(item, null, 2));
|
|
5724
|
+
}
|
|
5725
|
+
});
|
|
5726
|
+
});
|
|
5727
|
+
}
|
|
5717
5728
|
function checkInvalidSuiAddress(address) {
|
|
5718
5729
|
if (!address.startsWith("0x") || address.length !== 66) {
|
|
5719
5730
|
return false;
|
|
@@ -5765,6 +5776,8 @@ function swapInPools(client, params, sender) {
|
|
|
5765
5776
|
const coinA = direction ? fromCoin : targetCoin;
|
|
5766
5777
|
const coinB = direction ? targetCoin : fromCoin;
|
|
5767
5778
|
const typeArguments = [coinA, coinB];
|
|
5779
|
+
console.log("typeArguments", typeArguments);
|
|
5780
|
+
console.log("pools", pools);
|
|
5768
5781
|
for (let i = 0; i < pools.length; i++) {
|
|
5769
5782
|
const args = [
|
|
5770
5783
|
tx.object(pools[i]),
|
|
@@ -5789,6 +5802,7 @@ function swapInPools(client, params, sender) {
|
|
|
5789
5802
|
sender
|
|
5790
5803
|
});
|
|
5791
5804
|
if (simulateRes.error != null) {
|
|
5805
|
+
console.log("simulateRes.error", simulateRes.error);
|
|
5792
5806
|
throw new AggregateError(
|
|
5793
5807
|
"Aggregator package not set",
|
|
5794
5808
|
"SimulateError" /* SimulateError */
|
|
@@ -5992,6 +6006,38 @@ var Bluemove = class {
|
|
|
5992
6006
|
}
|
|
5993
6007
|
};
|
|
5994
6008
|
|
|
6009
|
+
// src/transaction/deepbook_v3.ts
|
|
6010
|
+
var DeepbookV3 = class {
|
|
6011
|
+
constructor(env) {
|
|
6012
|
+
this.deepbookV3Config = env === 0 /* Mainnet */ ? "0xe4099d0cda04f3aa80028fac91a9b3dbe50d08f2ff42aa2c29473926e34ca48c" : "0xe19b5d072346cae83a037d4e3c8492068a74410a74e5830b3a68012db38296aa";
|
|
6013
|
+
}
|
|
6014
|
+
swap(client, txb, path, inputCoin, deepbookv3DeepFee) {
|
|
6015
|
+
return __async(this, null, function* () {
|
|
6016
|
+
const { direction, from, target } = path;
|
|
6017
|
+
const [func, coinAType, coinBType] = direction ? ["swap_a2b", from, target] : ["swap_b2a", target, from];
|
|
6018
|
+
let deepFee;
|
|
6019
|
+
if (deepbookv3DeepFee) {
|
|
6020
|
+
deepFee = deepbookv3DeepFee;
|
|
6021
|
+
} else {
|
|
6022
|
+
deepFee = mintZeroCoin(txb, client.deepbookv3DeepFeeType());
|
|
6023
|
+
}
|
|
6024
|
+
const args = [
|
|
6025
|
+
txb.object(this.deepbookV3Config),
|
|
6026
|
+
txb.object(path.id),
|
|
6027
|
+
inputCoin,
|
|
6028
|
+
deepFee,
|
|
6029
|
+
txb.object(CLOCK_ADDRESS)
|
|
6030
|
+
];
|
|
6031
|
+
const res = txb.moveCall({
|
|
6032
|
+
target: `${client.publishedAtV2()}::deepbookv3::${func}`,
|
|
6033
|
+
typeArguments: [coinAType, coinBType],
|
|
6034
|
+
arguments: args
|
|
6035
|
+
});
|
|
6036
|
+
return res;
|
|
6037
|
+
});
|
|
6038
|
+
}
|
|
6039
|
+
};
|
|
6040
|
+
|
|
5995
6041
|
// src/client.ts
|
|
5996
6042
|
var CETUS = "CETUS";
|
|
5997
6043
|
var DEEPBOOKV2 = "DEEPBOOK";
|
|
@@ -6005,16 +6051,21 @@ var HAEDAL = "HAEDAL";
|
|
|
6005
6051
|
var VOLO = "VOLO";
|
|
6006
6052
|
var AFSUI = "AFSUI";
|
|
6007
6053
|
var BLUEMOVE = "BLUEMOVE";
|
|
6008
|
-
var
|
|
6009
|
-
|
|
6010
|
-
|
|
6011
|
-
|
|
6012
|
-
this.
|
|
6013
|
-
this.
|
|
6054
|
+
var DEEPBOOKV3 = "DEEPBOOKV3";
|
|
6055
|
+
var DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
6056
|
+
var AggregatorClient7 = class {
|
|
6057
|
+
constructor(endpoint, signer, client$1, env) {
|
|
6058
|
+
this.endpoint = endpoint ? processEndpoint(endpoint) : DEFAULT_ENDPOINT;
|
|
6059
|
+
this.client = client$1 || new client.SuiClient({ url: client.getFullnodeUrl("mainnet") });
|
|
6060
|
+
this.signer = signer || "";
|
|
6061
|
+
this.env = env || 0 /* Mainnet */;
|
|
6014
6062
|
this.allCoins = [];
|
|
6015
6063
|
}
|
|
6016
6064
|
getAllCoins() {
|
|
6017
6065
|
return __async(this, null, function* () {
|
|
6066
|
+
if (this.signer === "") {
|
|
6067
|
+
throw new Error("Signer is required, but not provided.");
|
|
6068
|
+
}
|
|
6018
6069
|
let cursor = null;
|
|
6019
6070
|
let limit = 50;
|
|
6020
6071
|
const allCoins = [];
|
|
@@ -6044,7 +6095,7 @@ var AggregatorClient6 = class {
|
|
|
6044
6095
|
return getRouterResult(this.endpoint, params);
|
|
6045
6096
|
});
|
|
6046
6097
|
}
|
|
6047
|
-
expectInputSwap(txb, inputCoin, routers, amountOutLimit, partner) {
|
|
6098
|
+
expectInputSwap(txb, inputCoin, routers, amountOutLimit, partner, deepbookv3DeepFee) {
|
|
6048
6099
|
return __async(this, null, function* () {
|
|
6049
6100
|
if (routers.length === 0) {
|
|
6050
6101
|
throw new Error("No router found");
|
|
@@ -6061,7 +6112,7 @@ var AggregatorClient6 = class {
|
|
|
6061
6112
|
let nextCoin = inputCoins[i];
|
|
6062
6113
|
for (const path of routers[i].path) {
|
|
6063
6114
|
const dex = this.newDex(path.provider, partner);
|
|
6064
|
-
nextCoin = yield dex.swap(this, txb, path, nextCoin);
|
|
6115
|
+
nextCoin = yield dex.swap(this, txb, path, nextCoin, deepbookv3DeepFee);
|
|
6065
6116
|
}
|
|
6066
6117
|
outputCoins.push(nextCoin);
|
|
6067
6118
|
}
|
|
@@ -6137,7 +6188,7 @@ var AggregatorClient6 = class {
|
|
|
6137
6188
|
}
|
|
6138
6189
|
routerSwap(params) {
|
|
6139
6190
|
return __async(this, null, function* () {
|
|
6140
|
-
const { routers, inputCoin, slippage, byAmountIn, txb, partner } = params;
|
|
6191
|
+
const { routers, inputCoin, slippage, byAmountIn, txb, partner, deepbookv3DeepFee } = params;
|
|
6141
6192
|
const amountIn = routers.reduce(
|
|
6142
6193
|
(acc, router) => acc.add(router.amountIn),
|
|
6143
6194
|
new import_bn5.default(0)
|
|
@@ -6157,7 +6208,8 @@ var AggregatorClient6 = class {
|
|
|
6157
6208
|
inputCoin,
|
|
6158
6209
|
routers,
|
|
6159
6210
|
new import_bn5.default(amountLimit),
|
|
6160
|
-
partner
|
|
6211
|
+
partner,
|
|
6212
|
+
deepbookv3DeepFee
|
|
6161
6213
|
);
|
|
6162
6214
|
return targetCoin2;
|
|
6163
6215
|
}
|
|
@@ -6185,7 +6237,8 @@ var AggregatorClient6 = class {
|
|
|
6185
6237
|
txb,
|
|
6186
6238
|
partner,
|
|
6187
6239
|
isMergeTragetCoin,
|
|
6188
|
-
refreshAllCoins
|
|
6240
|
+
refreshAllCoins,
|
|
6241
|
+
payDeepFeeAmount
|
|
6189
6242
|
} = params;
|
|
6190
6243
|
if (refreshAllCoins || this.allCoins.length === 0) {
|
|
6191
6244
|
this.allCoins = yield this.getAllCoins();
|
|
@@ -6212,13 +6265,23 @@ var AggregatorClient6 = class {
|
|
|
6212
6265
|
BigInt(amount.toString()),
|
|
6213
6266
|
fromCoinType
|
|
6214
6267
|
);
|
|
6268
|
+
let deepCoin;
|
|
6269
|
+
if (payDeepFeeAmount && payDeepFeeAmount > 0) {
|
|
6270
|
+
deepCoin = buildInputCoin(
|
|
6271
|
+
txb,
|
|
6272
|
+
this.allCoins,
|
|
6273
|
+
BigInt(payDeepFeeAmount),
|
|
6274
|
+
this.deepbookv3DeepFeeType()
|
|
6275
|
+
).targetCoin;
|
|
6276
|
+
}
|
|
6215
6277
|
const targetCoin = yield this.routerSwap({
|
|
6216
6278
|
routers,
|
|
6217
6279
|
inputCoin: buildFromCoinRes.targetCoin,
|
|
6218
6280
|
slippage,
|
|
6219
6281
|
byAmountIn,
|
|
6220
6282
|
txb,
|
|
6221
|
-
partner
|
|
6283
|
+
partner,
|
|
6284
|
+
deepbookv3DeepFee: deepCoin
|
|
6222
6285
|
});
|
|
6223
6286
|
if (isMergeTragetCoin) {
|
|
6224
6287
|
const targetCoinRes = buildInputCoin(
|
|
@@ -6240,11 +6303,27 @@ var AggregatorClient6 = class {
|
|
|
6240
6303
|
}
|
|
6241
6304
|
});
|
|
6242
6305
|
}
|
|
6306
|
+
// Include cetus、deepbookv2、flowxv2 & v3、kriyav2 & v3、turbos、aftermath、haedal、afsui、volo、bluemove
|
|
6243
6307
|
publishedAt() {
|
|
6244
6308
|
if (this.env === 0 /* Mainnet */) {
|
|
6245
|
-
return "
|
|
6309
|
+
return "0xf98ed029af555e4a103febf26243dc33ac09a7ea1b2da7e414c728b25b729086";
|
|
6310
|
+
} else {
|
|
6311
|
+
return "0x0ed287d6c3fe4962d0994ffddc1d19a15fba6a81533f3f0dcc2bbcedebce0637";
|
|
6312
|
+
}
|
|
6313
|
+
}
|
|
6314
|
+
// Include deepbookv3
|
|
6315
|
+
publishedAtV2() {
|
|
6316
|
+
if (this.env === 0 /* Mainnet */) {
|
|
6317
|
+
return "0x43811be4677f5a5de7bf2dac740c10abddfaa524aee6b18e910eeadda8a2f6ae";
|
|
6246
6318
|
} else {
|
|
6247
|
-
return "
|
|
6319
|
+
return "0x0ed287d6c3fe4962d0994ffddc1d19a15fba6a81533f3f0dcc2bbcedebce0637";
|
|
6320
|
+
}
|
|
6321
|
+
}
|
|
6322
|
+
deepbookv3DeepFeeType() {
|
|
6323
|
+
if (this.env === 0 /* Mainnet */) {
|
|
6324
|
+
return "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP";
|
|
6325
|
+
} else {
|
|
6326
|
+
return "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP";
|
|
6248
6327
|
}
|
|
6249
6328
|
}
|
|
6250
6329
|
transferOrDestoryCoin(txb, coin, coinType) {
|
|
@@ -6278,6 +6357,8 @@ var AggregatorClient6 = class {
|
|
|
6278
6357
|
return new Cetus(this.env, partner);
|
|
6279
6358
|
case DEEPBOOKV2:
|
|
6280
6359
|
return new DeepbookV2(this.env);
|
|
6360
|
+
case DEEPBOOKV3:
|
|
6361
|
+
return new DeepbookV3(this.env);
|
|
6281
6362
|
case KRIYA:
|
|
6282
6363
|
return new KriyaV2(this.env);
|
|
6283
6364
|
case KRIYAV3:
|
|
@@ -6335,26 +6416,44 @@ var AggregatorClient6 = class {
|
|
|
6335
6416
|
return res;
|
|
6336
6417
|
});
|
|
6337
6418
|
}
|
|
6419
|
+
getDeepbookV3Config() {
|
|
6420
|
+
return __async(this, null, function* () {
|
|
6421
|
+
const res = yield getDeepbookV3Config(this.endpoint);
|
|
6422
|
+
if (res) {
|
|
6423
|
+
return res.data;
|
|
6424
|
+
}
|
|
6425
|
+
return null;
|
|
6426
|
+
});
|
|
6427
|
+
}
|
|
6338
6428
|
};
|
|
6339
6429
|
function parseRouterResponse(data) {
|
|
6340
|
-
|
|
6430
|
+
let totalDeepFee = 0;
|
|
6431
|
+
for (const route of data.routes) {
|
|
6432
|
+
for (const path of route.path) {
|
|
6433
|
+
if (path.extended_details && path.extended_details.deepbookv3_deep_fee) {
|
|
6434
|
+
totalDeepFee += Number(path.extended_details.deepbookv3_deep_fee);
|
|
6435
|
+
}
|
|
6436
|
+
}
|
|
6437
|
+
}
|
|
6438
|
+
let routerData = {
|
|
6341
6439
|
amountIn: new import_bn5.default(data.amount_in.toString()),
|
|
6342
6440
|
amountOut: new import_bn5.default(data.amount_out.toString()),
|
|
6343
6441
|
insufficientLiquidity: false,
|
|
6344
6442
|
routes: data.routes.map((route) => {
|
|
6345
6443
|
return {
|
|
6346
6444
|
path: route.path.map((path) => {
|
|
6347
|
-
var _a, _b, _c;
|
|
6445
|
+
var _a, _b, _c, _d;
|
|
6348
6446
|
let version;
|
|
6349
6447
|
if (path.provider === AFTERMATH) {
|
|
6350
6448
|
version = path.extended_details.aftermath_pool_flatness === 0 ? "v2" : "v3";
|
|
6351
6449
|
}
|
|
6352
6450
|
let extendedDetails;
|
|
6353
|
-
if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS) {
|
|
6451
|
+
if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS || path.provider === DEEPBOOKV3) {
|
|
6354
6452
|
extendedDetails = {
|
|
6355
6453
|
aftermathLpSupplyType: (_a = path.extended_details) == null ? void 0 : _a.aftermath_lp_supply_type,
|
|
6356
6454
|
turbosFeeType: (_b = path.extended_details) == null ? void 0 : _b.turbos_fee_type,
|
|
6357
|
-
afterSqrtPrice: (_c = path.extended_details) == null ? void 0 : _c.after_sqrt_price
|
|
6455
|
+
afterSqrtPrice: (_c = path.extended_details) == null ? void 0 : _c.after_sqrt_price,
|
|
6456
|
+
deepbookv3DeepFee: (_d = path.extended_details) == null ? void 0 : _d.deepbookv3_deep_fee
|
|
6358
6457
|
};
|
|
6359
6458
|
}
|
|
6360
6459
|
return {
|
|
@@ -6374,8 +6473,10 @@ function parseRouterResponse(data) {
|
|
|
6374
6473
|
amountOut: new import_bn5.default(route.amount_out.toString()),
|
|
6375
6474
|
initialPrice: new decimal_default(route.initial_price.toString())
|
|
6376
6475
|
};
|
|
6377
|
-
})
|
|
6476
|
+
}),
|
|
6477
|
+
totalDeepFee
|
|
6378
6478
|
};
|
|
6479
|
+
return routerData;
|
|
6379
6480
|
}
|
|
6380
6481
|
|
|
6381
6482
|
// src/transaction/index.ts
|
|
@@ -6406,6 +6507,14 @@ var restituteMsafeFastRouterSwapParams = (data) => {
|
|
|
6406
6507
|
return result;
|
|
6407
6508
|
};
|
|
6408
6509
|
|
|
6510
|
+
// src/utils/api.ts
|
|
6511
|
+
function processEndpoint(endpoint) {
|
|
6512
|
+
if (endpoint.endsWith("/find_routes")) {
|
|
6513
|
+
return endpoint.replace("/find_routes", "");
|
|
6514
|
+
}
|
|
6515
|
+
return endpoint;
|
|
6516
|
+
}
|
|
6517
|
+
|
|
6409
6518
|
// src/api.ts
|
|
6410
6519
|
function getRouterResult(endpoint, params) {
|
|
6411
6520
|
return __async(this, null, function* () {
|
|
@@ -6468,7 +6577,7 @@ function getRouter(endpoint, params) {
|
|
|
6468
6577
|
} = params;
|
|
6469
6578
|
const fromCoin = completionCoin(from);
|
|
6470
6579
|
const targetCoin = completionCoin(target);
|
|
6471
|
-
let url = `${endpoint}?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`;
|
|
6580
|
+
let url = `${endpoint}/find_routes?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`;
|
|
6472
6581
|
if (depth) {
|
|
6473
6582
|
url += `&depth=${depth}`;
|
|
6474
6583
|
}
|
|
@@ -6486,6 +6595,7 @@ function getRouter(endpoint, params) {
|
|
|
6486
6595
|
url += `&providers=${providers.join(",")}`;
|
|
6487
6596
|
}
|
|
6488
6597
|
}
|
|
6598
|
+
url += "&v=1000302";
|
|
6489
6599
|
const response = yield fetch(url);
|
|
6490
6600
|
return response;
|
|
6491
6601
|
} catch (error) {
|
|
@@ -6510,7 +6620,7 @@ function postRouterWithLiquidityChanges(endpoint, params) {
|
|
|
6510
6620
|
} = params;
|
|
6511
6621
|
const fromCoin = completionCoin(from);
|
|
6512
6622
|
const targetCoin = completionCoin(target);
|
|
6513
|
-
const url = `${endpoint}`;
|
|
6623
|
+
const url = `${endpoint}/find_routes`;
|
|
6514
6624
|
const providersStr = providers == null ? void 0 : providers.join(",");
|
|
6515
6625
|
const requestData = {
|
|
6516
6626
|
from: fromCoin,
|
|
@@ -6529,7 +6639,6 @@ function postRouterWithLiquidityChanges(endpoint, params) {
|
|
|
6529
6639
|
delta_liquidity: change.deltaLiquidity
|
|
6530
6640
|
}))
|
|
6531
6641
|
};
|
|
6532
|
-
console.log("requestData", JSON.stringify(requestData, null, 2));
|
|
6533
6642
|
try {
|
|
6534
6643
|
const response = yield fetch(url, {
|
|
6535
6644
|
method: "POST",
|
|
@@ -6545,6 +6654,18 @@ function postRouterWithLiquidityChanges(endpoint, params) {
|
|
|
6545
6654
|
}
|
|
6546
6655
|
});
|
|
6547
6656
|
}
|
|
6657
|
+
function getDeepbookV3Config(endpoint) {
|
|
6658
|
+
return __async(this, null, function* () {
|
|
6659
|
+
const url = `${endpoint}/deepbookv3_config`;
|
|
6660
|
+
try {
|
|
6661
|
+
const response = yield fetch(url);
|
|
6662
|
+
return response.json();
|
|
6663
|
+
} catch (error) {
|
|
6664
|
+
console.error("Error:", error);
|
|
6665
|
+
return null;
|
|
6666
|
+
}
|
|
6667
|
+
});
|
|
6668
|
+
}
|
|
6548
6669
|
|
|
6549
6670
|
// src/index.ts
|
|
6550
6671
|
var Env = /* @__PURE__ */ ((Env2) => {
|
|
@@ -6566,11 +6687,13 @@ decimal.js/decimal.mjs:
|
|
|
6566
6687
|
|
|
6567
6688
|
exports.AFSUI = AFSUI;
|
|
6568
6689
|
exports.AFTERMATH = AFTERMATH;
|
|
6569
|
-
exports.AggregatorClient =
|
|
6690
|
+
exports.AggregatorClient = AggregatorClient7;
|
|
6570
6691
|
exports.BLUEMOVE = BLUEMOVE;
|
|
6571
6692
|
exports.CETUS = CETUS;
|
|
6572
6693
|
exports.CLOCK_ADDRESS = CLOCK_ADDRESS;
|
|
6573
6694
|
exports.DEEPBOOKV2 = DEEPBOOKV2;
|
|
6695
|
+
exports.DEEPBOOKV3 = DEEPBOOKV3;
|
|
6696
|
+
exports.DEFAULT_ENDPOINT = DEFAULT_ENDPOINT;
|
|
6574
6697
|
exports.Env = Env;
|
|
6575
6698
|
exports.FLOWXV2 = FLOWXV2;
|
|
6576
6699
|
exports.FLOWXV3 = FLOWXV3;
|
|
@@ -6586,15 +6709,23 @@ exports.U64_MAX = U64_MAX;
|
|
|
6586
6709
|
exports.U64_MAX_BN = U64_MAX_BN;
|
|
6587
6710
|
exports.VOLO = VOLO;
|
|
6588
6711
|
exports.ZERO = ZERO;
|
|
6712
|
+
exports.buildInputCoin = buildInputCoin;
|
|
6713
|
+
exports.checkInvalidSuiAddress = checkInvalidSuiAddress;
|
|
6714
|
+
exports.compareCoins = compareCoins;
|
|
6715
|
+
exports.completionCoin = completionCoin;
|
|
6589
6716
|
exports.composeType = composeType;
|
|
6590
6717
|
exports.createTarget = createTarget;
|
|
6591
6718
|
exports.dealWithFastRouterSwapParamsForMsafe = dealWithFastRouterSwapParamsForMsafe;
|
|
6592
6719
|
exports.extractAddressFromType = extractAddressFromType;
|
|
6593
6720
|
exports.extractStructTagFromType = extractStructTagFromType;
|
|
6594
6721
|
exports.fixSuiObjectId = fixSuiObjectId;
|
|
6722
|
+
exports.getDeepbookV3Config = getDeepbookV3Config;
|
|
6595
6723
|
exports.getRouterResult = getRouterResult;
|
|
6596
6724
|
exports.isSortedSymbols = isSortedSymbols;
|
|
6725
|
+
exports.mintZeroCoin = mintZeroCoin;
|
|
6597
6726
|
exports.normalizeCoinType = normalizeCoinType;
|
|
6598
6727
|
exports.parseRouterResponse = parseRouterResponse;
|
|
6599
6728
|
exports.patchFixSuiObjectId = patchFixSuiObjectId;
|
|
6729
|
+
exports.printTransaction = printTransaction;
|
|
6730
|
+
exports.processEndpoint = processEndpoint;
|
|
6600
6731
|
exports.restituteMsafeFastRouterSwapParams = restituteMsafeFastRouterSwapParams;
|