@cetusprotocol/aggregator-sdk 0.3.7 → 0.3.8
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.cjs +43 -3
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +43 -4
- package/dist/src/client.d.ts +1 -0
- package/dist/src/transaction/suilend.d.ts +8 -0
- package/package.json +1 -1
- package/src/api.ts +2 -2
- package/src/client.ts +30 -9
- package/src/transaction/suilend.ts +52 -0
- package/tests/router.test.ts +4 -4
package/dist/index.cjs
CHANGED
|
@@ -6074,6 +6074,34 @@ var Scallop = class {
|
|
|
6074
6074
|
}
|
|
6075
6075
|
};
|
|
6076
6076
|
|
|
6077
|
+
// src/transaction/suilend.ts
|
|
6078
|
+
var Suilend = class {
|
|
6079
|
+
constructor(env) {
|
|
6080
|
+
if (env !== 0 /* Mainnet */) {
|
|
6081
|
+
throw new Error("Suilend only supported on mainnet");
|
|
6082
|
+
}
|
|
6083
|
+
this.liquid_staking_pool = env === 0 /* Mainnet */ ? "0x15eda7330c8f99c30e430b4d82fd7ab2af3ead4ae17046fcb224aa9bad394f6b" : "0x0";
|
|
6084
|
+
this.sui_system_state = env === 0 /* Mainnet */ ? "0x0000000000000000000000000000000000000000000000000000000000000005" : "0x0";
|
|
6085
|
+
}
|
|
6086
|
+
swap(client, txb, path, inputCoin) {
|
|
6087
|
+
return __async(this, null, function* () {
|
|
6088
|
+
const { direction, from, target } = path;
|
|
6089
|
+
const [func, springCoinType] = direction ? ["swap_a2b", target] : ["swap_b2a", from];
|
|
6090
|
+
const args = [
|
|
6091
|
+
txb.object(this.liquid_staking_pool),
|
|
6092
|
+
txb.object(this.sui_system_state),
|
|
6093
|
+
inputCoin
|
|
6094
|
+
];
|
|
6095
|
+
const res = txb.moveCall({
|
|
6096
|
+
target: `${client.publishedAtV2()}::suilend::${func}`,
|
|
6097
|
+
typeArguments: [springCoinType],
|
|
6098
|
+
arguments: args
|
|
6099
|
+
});
|
|
6100
|
+
return res;
|
|
6101
|
+
});
|
|
6102
|
+
}
|
|
6103
|
+
};
|
|
6104
|
+
|
|
6077
6105
|
// src/client.ts
|
|
6078
6106
|
var CETUS = "CETUS";
|
|
6079
6107
|
var DEEPBOOKV2 = "DEEPBOOK";
|
|
@@ -6089,6 +6117,7 @@ var AFSUI = "AFSUI";
|
|
|
6089
6117
|
var BLUEMOVE = "BLUEMOVE";
|
|
6090
6118
|
var DEEPBOOKV3 = "DEEPBOOKV3";
|
|
6091
6119
|
var SCALLOP = "SCALLOP";
|
|
6120
|
+
var SUILEND = "SUILEND";
|
|
6092
6121
|
var DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
6093
6122
|
var AggregatorClient8 = class {
|
|
6094
6123
|
constructor(endpoint, signer, client$1, env) {
|
|
@@ -6233,7 +6262,15 @@ var AggregatorClient8 = class {
|
|
|
6233
6262
|
}
|
|
6234
6263
|
routerSwap(params) {
|
|
6235
6264
|
return __async(this, null, function* () {
|
|
6236
|
-
const {
|
|
6265
|
+
const {
|
|
6266
|
+
routers,
|
|
6267
|
+
inputCoin,
|
|
6268
|
+
slippage,
|
|
6269
|
+
byAmountIn,
|
|
6270
|
+
txb,
|
|
6271
|
+
partner,
|
|
6272
|
+
deepbookv3DeepFee
|
|
6273
|
+
} = params;
|
|
6237
6274
|
const amountIn = routers.reduce(
|
|
6238
6275
|
(acc, router) => acc.add(router.amountIn),
|
|
6239
6276
|
new import_bn5.default(0)
|
|
@@ -6359,7 +6396,7 @@ var AggregatorClient8 = class {
|
|
|
6359
6396
|
// Include deepbookv3, scallop
|
|
6360
6397
|
publishedAtV2() {
|
|
6361
6398
|
if (this.env === 0 /* Mainnet */) {
|
|
6362
|
-
return "
|
|
6399
|
+
return "0x16d9418726c26d8cb4ce8c9dd75917fa9b1c7bf47d38d7a1a22603135f0f2a56";
|
|
6363
6400
|
} else {
|
|
6364
6401
|
return "0xfd8a73ef0a4b928da9c27fc287dc37c1ca64df71da8e8eac7ca9ece55eb5f448";
|
|
6365
6402
|
}
|
|
@@ -6426,6 +6463,8 @@ var AggregatorClient8 = class {
|
|
|
6426
6463
|
return new Bluemove(this.env);
|
|
6427
6464
|
case SCALLOP:
|
|
6428
6465
|
return new Scallop(this.env);
|
|
6466
|
+
case SUILEND:
|
|
6467
|
+
return new Suilend(this.env);
|
|
6429
6468
|
default:
|
|
6430
6469
|
throw new Error(`Unsupported dex ${provider}`);
|
|
6431
6470
|
}
|
|
@@ -6643,7 +6682,7 @@ function getRouter(endpoint, params) {
|
|
|
6643
6682
|
url += `&providers=${providers.join(",")}`;
|
|
6644
6683
|
}
|
|
6645
6684
|
}
|
|
6646
|
-
url += "&v=
|
|
6685
|
+
url += "&v=1000307";
|
|
6647
6686
|
const response = yield fetch(url);
|
|
6648
6687
|
return response;
|
|
6649
6688
|
} catch (error) {
|
|
@@ -6750,6 +6789,7 @@ exports.KRIYA = KRIYA;
|
|
|
6750
6789
|
exports.KRIYAV3 = KRIYAV3;
|
|
6751
6790
|
exports.ONE = ONE;
|
|
6752
6791
|
exports.SCALLOP = SCALLOP;
|
|
6792
|
+
exports.SUILEND = SUILEND;
|
|
6753
6793
|
exports.TEN_POW_NINE = TEN_POW_NINE;
|
|
6754
6794
|
exports.TURBOS = TURBOS;
|
|
6755
6795
|
exports.TWO = TWO;
|
package/dist/index.d.cts
CHANGED
|
@@ -74,6 +74,7 @@ declare const AFSUI = "AFSUI";
|
|
|
74
74
|
declare const BLUEMOVE = "BLUEMOVE";
|
|
75
75
|
declare const DEEPBOOKV3 = "DEEPBOOKV3";
|
|
76
76
|
declare const SCALLOP = "SCALLOP";
|
|
77
|
+
declare const SUILEND = "SUILEND";
|
|
77
78
|
declare const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
78
79
|
type BuildRouterSwapParams = {
|
|
79
80
|
routers: Router[];
|
|
@@ -265,4 +266,4 @@ declare enum Env {
|
|
|
265
266
|
Testnet = 1
|
|
266
267
|
}
|
|
267
268
|
|
|
268
|
-
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, SCALLOP, 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 };
|
|
269
|
+
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, 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
|
@@ -74,6 +74,7 @@ declare const AFSUI = "AFSUI";
|
|
|
74
74
|
declare const BLUEMOVE = "BLUEMOVE";
|
|
75
75
|
declare const DEEPBOOKV3 = "DEEPBOOKV3";
|
|
76
76
|
declare const SCALLOP = "SCALLOP";
|
|
77
|
+
declare const SUILEND = "SUILEND";
|
|
77
78
|
declare const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
78
79
|
type BuildRouterSwapParams = {
|
|
79
80
|
routers: Router[];
|
|
@@ -265,4 +266,4 @@ declare enum Env {
|
|
|
265
266
|
Testnet = 1
|
|
266
267
|
}
|
|
267
268
|
|
|
268
|
-
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, SCALLOP, 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 };
|
|
269
|
+
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, 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
|
@@ -6072,6 +6072,34 @@ var Scallop = class {
|
|
|
6072
6072
|
}
|
|
6073
6073
|
};
|
|
6074
6074
|
|
|
6075
|
+
// src/transaction/suilend.ts
|
|
6076
|
+
var Suilend = class {
|
|
6077
|
+
constructor(env) {
|
|
6078
|
+
if (env !== 0 /* Mainnet */) {
|
|
6079
|
+
throw new Error("Suilend only supported on mainnet");
|
|
6080
|
+
}
|
|
6081
|
+
this.liquid_staking_pool = env === 0 /* Mainnet */ ? "0x15eda7330c8f99c30e430b4d82fd7ab2af3ead4ae17046fcb224aa9bad394f6b" : "0x0";
|
|
6082
|
+
this.sui_system_state = env === 0 /* Mainnet */ ? "0x0000000000000000000000000000000000000000000000000000000000000005" : "0x0";
|
|
6083
|
+
}
|
|
6084
|
+
swap(client, txb, path, inputCoin) {
|
|
6085
|
+
return __async(this, null, function* () {
|
|
6086
|
+
const { direction, from, target } = path;
|
|
6087
|
+
const [func, springCoinType] = direction ? ["swap_a2b", target] : ["swap_b2a", from];
|
|
6088
|
+
const args = [
|
|
6089
|
+
txb.object(this.liquid_staking_pool),
|
|
6090
|
+
txb.object(this.sui_system_state),
|
|
6091
|
+
inputCoin
|
|
6092
|
+
];
|
|
6093
|
+
const res = txb.moveCall({
|
|
6094
|
+
target: `${client.publishedAtV2()}::suilend::${func}`,
|
|
6095
|
+
typeArguments: [springCoinType],
|
|
6096
|
+
arguments: args
|
|
6097
|
+
});
|
|
6098
|
+
return res;
|
|
6099
|
+
});
|
|
6100
|
+
}
|
|
6101
|
+
};
|
|
6102
|
+
|
|
6075
6103
|
// src/client.ts
|
|
6076
6104
|
var CETUS = "CETUS";
|
|
6077
6105
|
var DEEPBOOKV2 = "DEEPBOOK";
|
|
@@ -6087,6 +6115,7 @@ var AFSUI = "AFSUI";
|
|
|
6087
6115
|
var BLUEMOVE = "BLUEMOVE";
|
|
6088
6116
|
var DEEPBOOKV3 = "DEEPBOOKV3";
|
|
6089
6117
|
var SCALLOP = "SCALLOP";
|
|
6118
|
+
var SUILEND = "SUILEND";
|
|
6090
6119
|
var DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
6091
6120
|
var AggregatorClient8 = class {
|
|
6092
6121
|
constructor(endpoint, signer, client, env) {
|
|
@@ -6231,7 +6260,15 @@ var AggregatorClient8 = class {
|
|
|
6231
6260
|
}
|
|
6232
6261
|
routerSwap(params) {
|
|
6233
6262
|
return __async(this, null, function* () {
|
|
6234
|
-
const {
|
|
6263
|
+
const {
|
|
6264
|
+
routers,
|
|
6265
|
+
inputCoin,
|
|
6266
|
+
slippage,
|
|
6267
|
+
byAmountIn,
|
|
6268
|
+
txb,
|
|
6269
|
+
partner,
|
|
6270
|
+
deepbookv3DeepFee
|
|
6271
|
+
} = params;
|
|
6235
6272
|
const amountIn = routers.reduce(
|
|
6236
6273
|
(acc, router) => acc.add(router.amountIn),
|
|
6237
6274
|
new import_bn5.default(0)
|
|
@@ -6357,7 +6394,7 @@ var AggregatorClient8 = class {
|
|
|
6357
6394
|
// Include deepbookv3, scallop
|
|
6358
6395
|
publishedAtV2() {
|
|
6359
6396
|
if (this.env === 0 /* Mainnet */) {
|
|
6360
|
-
return "
|
|
6397
|
+
return "0x16d9418726c26d8cb4ce8c9dd75917fa9b1c7bf47d38d7a1a22603135f0f2a56";
|
|
6361
6398
|
} else {
|
|
6362
6399
|
return "0xfd8a73ef0a4b928da9c27fc287dc37c1ca64df71da8e8eac7ca9ece55eb5f448";
|
|
6363
6400
|
}
|
|
@@ -6424,6 +6461,8 @@ var AggregatorClient8 = class {
|
|
|
6424
6461
|
return new Bluemove(this.env);
|
|
6425
6462
|
case SCALLOP:
|
|
6426
6463
|
return new Scallop(this.env);
|
|
6464
|
+
case SUILEND:
|
|
6465
|
+
return new Suilend(this.env);
|
|
6427
6466
|
default:
|
|
6428
6467
|
throw new Error(`Unsupported dex ${provider}`);
|
|
6429
6468
|
}
|
|
@@ -6641,7 +6680,7 @@ function getRouter(endpoint, params) {
|
|
|
6641
6680
|
url += `&providers=${providers.join(",")}`;
|
|
6642
6681
|
}
|
|
6643
6682
|
}
|
|
6644
|
-
url += "&v=
|
|
6683
|
+
url += "&v=1000307";
|
|
6645
6684
|
const response = yield fetch(url);
|
|
6646
6685
|
return response;
|
|
6647
6686
|
} catch (error) {
|
|
@@ -6731,4 +6770,4 @@ decimal.js/decimal.mjs:
|
|
|
6731
6770
|
*)
|
|
6732
6771
|
*/
|
|
6733
6772
|
|
|
6734
|
-
export { AFSUI, AFTERMATH, AggregatorClient8 as AggregatorClient, BLUEMOVE, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, Env, FLOWXV2, FLOWXV3, HAEDAL, KRIYA, KRIYAV3, ONE, SCALLOP, 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 };
|
|
6773
|
+
export { AFSUI, AFTERMATH, AggregatorClient8 as AggregatorClient, BLUEMOVE, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, Env, FLOWXV2, FLOWXV3, HAEDAL, 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
|
@@ -18,6 +18,7 @@ export declare const AFSUI = "AFSUI";
|
|
|
18
18
|
export declare const BLUEMOVE = "BLUEMOVE";
|
|
19
19
|
export declare const DEEPBOOKV3 = "DEEPBOOKV3";
|
|
20
20
|
export declare const SCALLOP = "SCALLOP";
|
|
21
|
+
export declare const SUILEND = "SUILEND";
|
|
21
22
|
export declare const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
22
23
|
export type BuildRouterSwapParams = {
|
|
23
24
|
routers: Router[];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
2
|
+
import { AggregatorClient, Dex, Env, Path } from "..";
|
|
3
|
+
export declare class Suilend implements Dex {
|
|
4
|
+
private liquid_staking_pool;
|
|
5
|
+
private sui_system_state;
|
|
6
|
+
constructor(env: Env);
|
|
7
|
+
swap(client: AggregatorClient, txb: Transaction, path: Path, inputCoin: TransactionObjectArgument): Promise<TransactionObjectArgument>;
|
|
8
|
+
}
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -168,7 +168,7 @@ async function getRouter(endpoint: string, params: FindRouterParams) {
|
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
// set newest sdk version
|
|
171
|
-
url += "&v=
|
|
171
|
+
url += "&v=1000307"
|
|
172
172
|
|
|
173
173
|
const response = await fetch(url)
|
|
174
174
|
return response
|
|
@@ -238,7 +238,7 @@ export type DeepbookV3Config = {
|
|
|
238
238
|
is_alternative_payment: boolean
|
|
239
239
|
alternative_payment_amount: number
|
|
240
240
|
trade_cap: string
|
|
241
|
-
balance_manager: string
|
|
241
|
+
balance_manager: string
|
|
242
242
|
deep_fee_vault: number
|
|
243
243
|
whitelist: number
|
|
244
244
|
package_version: 0
|
package/src/client.ts
CHANGED
|
@@ -37,6 +37,8 @@ import { CoinAsset } from "./types/sui"
|
|
|
37
37
|
import { buildInputCoin } from "./utils/coin"
|
|
38
38
|
import { DeepbookV3 } from "./transaction/deepbook_v3"
|
|
39
39
|
import { Scallop } from "./transaction/scallop"
|
|
40
|
+
import { Suilend } from "./transaction/suilend"
|
|
41
|
+
|
|
40
42
|
export const CETUS = "CETUS"
|
|
41
43
|
export const DEEPBOOKV2 = "DEEPBOOK"
|
|
42
44
|
export const KRIYA = "KRIYA"
|
|
@@ -51,7 +53,7 @@ export const AFSUI = "AFSUI"
|
|
|
51
53
|
export const BLUEMOVE = "BLUEMOVE"
|
|
52
54
|
export const DEEPBOOKV3 = "DEEPBOOKV3"
|
|
53
55
|
export const SCALLOP = "SCALLOP"
|
|
54
|
-
|
|
56
|
+
export const SUILEND = "SUILEND"
|
|
55
57
|
export const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2"
|
|
56
58
|
|
|
57
59
|
export type BuildRouterSwapParams = {
|
|
@@ -97,15 +99,23 @@ export class AggregatorClient {
|
|
|
97
99
|
public env: Env
|
|
98
100
|
private allCoins: Map<string, CoinAsset[]>
|
|
99
101
|
|
|
100
|
-
constructor(
|
|
102
|
+
constructor(
|
|
103
|
+
endpoint?: string,
|
|
104
|
+
signer?: string,
|
|
105
|
+
client?: SuiClient,
|
|
106
|
+
env?: Env
|
|
107
|
+
) {
|
|
101
108
|
this.endpoint = endpoint ? processEndpoint(endpoint) : DEFAULT_ENDPOINT
|
|
102
|
-
this.client = client || new SuiClient({url: getFullnodeUrl(
|
|
109
|
+
this.client = client || new SuiClient({ url: getFullnodeUrl("mainnet") })
|
|
103
110
|
this.signer = signer || ""
|
|
104
111
|
this.env = env || Env.Mainnet
|
|
105
112
|
this.allCoins = new Map<string, CoinAsset[]>()
|
|
106
113
|
}
|
|
107
114
|
|
|
108
|
-
async getCoins(
|
|
115
|
+
async getCoins(
|
|
116
|
+
coinType: string,
|
|
117
|
+
refresh: boolean = true
|
|
118
|
+
): Promise<CoinAsset[]> {
|
|
109
119
|
if (this.signer === "") {
|
|
110
120
|
throw new Error("Signer is required, but not provided.")
|
|
111
121
|
}
|
|
@@ -155,7 +165,7 @@ export class AggregatorClient {
|
|
|
155
165
|
routers: Router[],
|
|
156
166
|
amountOutLimit: BN,
|
|
157
167
|
partner?: string,
|
|
158
|
-
deepbookv3DeepFee?: TransactionObjectArgument
|
|
168
|
+
deepbookv3DeepFee?: TransactionObjectArgument
|
|
159
169
|
) {
|
|
160
170
|
if (routers.length === 0) {
|
|
161
171
|
throw new Error("No router found")
|
|
@@ -257,7 +267,15 @@ export class AggregatorClient {
|
|
|
257
267
|
async routerSwap(
|
|
258
268
|
params: BuildRouterSwapParams
|
|
259
269
|
): Promise<TransactionObjectArgument> {
|
|
260
|
-
const {
|
|
270
|
+
const {
|
|
271
|
+
routers,
|
|
272
|
+
inputCoin,
|
|
273
|
+
slippage,
|
|
274
|
+
byAmountIn,
|
|
275
|
+
txb,
|
|
276
|
+
partner,
|
|
277
|
+
deepbookv3DeepFee,
|
|
278
|
+
} = params
|
|
261
279
|
const amountIn = routers.reduce(
|
|
262
280
|
(acc, router) => acc.add(router.amountIn),
|
|
263
281
|
new BN(0)
|
|
@@ -314,7 +332,6 @@ export class AggregatorClient {
|
|
|
314
332
|
|
|
315
333
|
const fromCoinType = routers[0].path[0].from
|
|
316
334
|
|
|
317
|
-
|
|
318
335
|
let fromCoins = await this.getCoins(fromCoinType, refreshAllCoins)
|
|
319
336
|
|
|
320
337
|
const targetCoinType = routers[0].path[routers[0].path.length - 1].target
|
|
@@ -395,7 +412,8 @@ export class AggregatorClient {
|
|
|
395
412
|
publishedAtV2(): string {
|
|
396
413
|
if (this.env === Env.Mainnet) {
|
|
397
414
|
// return "0x43811be4677f5a5de7bf2dac740c10abddfaa524aee6b18e910eeadda8a2f6ae" // version 1, deepbookv3
|
|
398
|
-
return "0x6d70ffa7aa3f924c3f0b573d27d29895a0ee666aaff821073f75cb14af7fd01a" // version 3, deepbookv3 & scallop
|
|
415
|
+
// return "0x6d70ffa7aa3f924c3f0b573d27d29895a0ee666aaff821073f75cb14af7fd01a" // version 3, deepbookv3 & scallop
|
|
416
|
+
return "0x16d9418726c26d8cb4ce8c9dd75917fa9b1c7bf47d38d7a1a22603135f0f2a56" // version 4 add suilend
|
|
399
417
|
} else {
|
|
400
418
|
return "0xfd8a73ef0a4b928da9c27fc287dc37c1ca64df71da8e8eac7ca9ece55eb5f448"
|
|
401
419
|
}
|
|
@@ -476,6 +494,8 @@ export class AggregatorClient {
|
|
|
476
494
|
return new Bluemove(this.env)
|
|
477
495
|
case SCALLOP:
|
|
478
496
|
return new Scallop(this.env)
|
|
497
|
+
case SUILEND:
|
|
498
|
+
return new Suilend(this.env)
|
|
479
499
|
default:
|
|
480
500
|
throw new Error(`Unsupported dex ${provider}`)
|
|
481
501
|
}
|
|
@@ -558,7 +578,8 @@ export function parseRouterResponse(data: any): RouterData {
|
|
|
558
578
|
turbosFeeType: path.extended_details?.turbos_fee_type,
|
|
559
579
|
afterSqrtPrice: path.extended_details?.after_sqrt_price,
|
|
560
580
|
deepbookv3DeepFee: path.extended_details?.deepbookv3_deep_fee,
|
|
561
|
-
scallopScoinTreasury:
|
|
581
|
+
scallopScoinTreasury:
|
|
582
|
+
path.extended_details?.scallop_scoin_treasury,
|
|
562
583
|
}
|
|
563
584
|
}
|
|
564
585
|
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Transaction,
|
|
3
|
+
TransactionObjectArgument,
|
|
4
|
+
} from "@mysten/sui/transactions"
|
|
5
|
+
import { AggregatorClient, CLOCK_ADDRESS, Dex, Env, Path } from ".."
|
|
6
|
+
|
|
7
|
+
export class Suilend implements Dex {
|
|
8
|
+
private liquid_staking_pool: string
|
|
9
|
+
private sui_system_state: string
|
|
10
|
+
|
|
11
|
+
constructor(env: Env) {
|
|
12
|
+
if (env !== Env.Mainnet) {
|
|
13
|
+
throw new Error("Suilend only supported on mainnet")
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
this.liquid_staking_pool = env === Env.Mainnet
|
|
17
|
+
? "0x15eda7330c8f99c30e430b4d82fd7ab2af3ead4ae17046fcb224aa9bad394f6b"
|
|
18
|
+
: "0x0"
|
|
19
|
+
|
|
20
|
+
this.sui_system_state =
|
|
21
|
+
env === Env.Mainnet
|
|
22
|
+
? "0x0000000000000000000000000000000000000000000000000000000000000005"
|
|
23
|
+
: "0x0"
|
|
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
|
+
|
|
34
|
+
const [func, springCoinType] = direction
|
|
35
|
+
? ["swap_a2b", target]
|
|
36
|
+
: ["swap_b2a", from]
|
|
37
|
+
|
|
38
|
+
const args = [
|
|
39
|
+
txb.object(this.liquid_staking_pool),
|
|
40
|
+
txb.object(this.sui_system_state),
|
|
41
|
+
inputCoin,
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
const res = txb.moveCall({
|
|
45
|
+
target: `${client.publishedAtV2()}::suilend::${func}`,
|
|
46
|
+
typeArguments: [springCoinType],
|
|
47
|
+
arguments: args,
|
|
48
|
+
}) as TransactionObjectArgument
|
|
49
|
+
|
|
50
|
+
return res
|
|
51
|
+
}
|
|
52
|
+
}
|
package/tests/router.test.ts
CHANGED
|
@@ -113,8 +113,8 @@ describe("router module", () => {
|
|
|
113
113
|
test("Build router tx", async () => {
|
|
114
114
|
const byAmountIn = true
|
|
115
115
|
const amount = "320000"
|
|
116
|
-
const
|
|
117
|
-
const
|
|
116
|
+
const from = "0x2::sui::SUI"
|
|
117
|
+
const target = "0x83556891f4a0f233ce7b05cfe7f957d4020492a34f5405b2cb9377d060bef4bf::spring_sui::SPRING_SUI"
|
|
118
118
|
|
|
119
119
|
const res = await client.findRouters({
|
|
120
120
|
from,
|
|
@@ -123,8 +123,8 @@ describe("router module", () => {
|
|
|
123
123
|
byAmountIn,
|
|
124
124
|
depth: 3,
|
|
125
125
|
providers: [
|
|
126
|
-
"
|
|
127
|
-
"CETUS",
|
|
126
|
+
"SUILEND",
|
|
127
|
+
// "CETUS",
|
|
128
128
|
// "DEEPBOOKV3",
|
|
129
129
|
// "DEEPBOOK",
|
|
130
130
|
// "AFTERMATH",
|