@cetusprotocol/aggregator-sdk 0.3.9 → 0.3.11
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 +47 -6
- package/dist/index.mjs +46 -6
- package/dist/src/client.d.ts +1 -0
- package/dist/src/math.d.ts +1 -0
- package/dist/src/transaction/bluefin.d.ts +7 -0
- package/package.json +1 -1
- package/src/client.ts +10 -5
- package/src/math.ts +19 -0
- package/src/transaction/bluefin.ts +43 -0
- package/tests/router.test.ts +15 -21
package/dist/index.d.mts
CHANGED
|
@@ -75,6 +75,7 @@ declare const BLUEMOVE = "BLUEMOVE";
|
|
|
75
75
|
declare const DEEPBOOKV3 = "DEEPBOOKV3";
|
|
76
76
|
declare const SCALLOP = "SCALLOP";
|
|
77
77
|
declare const SUILEND = "SUILEND";
|
|
78
|
+
declare const BLUEFIN = "BLUEFIN";
|
|
78
79
|
declare const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
79
80
|
type BuildRouterSwapParams = {
|
|
80
81
|
routers: Router[];
|
|
@@ -266,4 +267,4 @@ declare enum Env {
|
|
|
266
267
|
Testnet = 1
|
|
267
268
|
}
|
|
268
269
|
|
|
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 };
|
|
270
|
+
export { AFSUI, AFTERMATH, AggregatorClient, type AggregatorResponse, BLUEFIN, BLUEMOVE, type BuildCoinResult, type BuildFastRouterSwapParams, type BuildRouterSwapParams, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, type DeepbookV3Config, type DeepbookV3ConfigResponse, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWXV3, type FindRouterParams, HAEDAL, KRIYA, KRIYAV3, ONE, type Path, type PreSwapLpChangeParams, type Router, type RouterData, type RouterError, SCALLOP, SUILEND, type SwapInPoolsParams, type SwapInPoolsResult, TEN_POW_NINE, TURBOS, TWO, U128, U64_MAX, U64_MAX_BN, VOLO, ZERO, buildInputCoin, checkInvalidSuiAddress, compareCoins, completionCoin, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, extractAddressFromType, extractStructTagFromType, fixSuiObjectId, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
|
package/dist/index.d.ts
CHANGED
|
@@ -75,6 +75,7 @@ declare const BLUEMOVE = "BLUEMOVE";
|
|
|
75
75
|
declare const DEEPBOOKV3 = "DEEPBOOKV3";
|
|
76
76
|
declare const SCALLOP = "SCALLOP";
|
|
77
77
|
declare const SUILEND = "SUILEND";
|
|
78
|
+
declare const BLUEFIN = "BLUEFIN";
|
|
78
79
|
declare const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
79
80
|
type BuildRouterSwapParams = {
|
|
80
81
|
routers: Router[];
|
|
@@ -266,4 +267,4 @@ declare enum Env {
|
|
|
266
267
|
Testnet = 1
|
|
267
268
|
}
|
|
268
269
|
|
|
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 };
|
|
270
|
+
export { AFSUI, AFTERMATH, AggregatorClient, type AggregatorResponse, BLUEFIN, BLUEMOVE, type BuildCoinResult, type BuildFastRouterSwapParams, type BuildRouterSwapParams, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, type DeepbookV3Config, type DeepbookV3ConfigResponse, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWXV3, type FindRouterParams, HAEDAL, KRIYA, KRIYAV3, ONE, type Path, type PreSwapLpChangeParams, type Router, type RouterData, type RouterError, SCALLOP, SUILEND, type SwapInPoolsParams, type SwapInPoolsResult, TEN_POW_NINE, TURBOS, TWO, U128, U64_MAX, U64_MAX_BN, VOLO, ZERO, buildInputCoin, checkInvalidSuiAddress, compareCoins, completionCoin, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, extractAddressFromType, extractStructTagFromType, fixSuiObjectId, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
|
package/dist/index.js
CHANGED
|
@@ -5758,6 +5758,15 @@ function CalculateAmountLimit(expectAmount, byAmountIn, slippage) {
|
|
|
5758
5758
|
}
|
|
5759
5759
|
return Number(amountLimit.toString());
|
|
5760
5760
|
}
|
|
5761
|
+
function CalculateAmountLimitBN(expectAmount, byAmountIn, slippage) {
|
|
5762
|
+
let amountLimit = ZERO;
|
|
5763
|
+
if (byAmountIn) {
|
|
5764
|
+
amountLimit = expectAmount.mul(new import_bn3.default(TEN_POW_NINE - slippage * TEN_POW_NINE)).div(new import_bn3.default(TEN_POW_NINE));
|
|
5765
|
+
} else {
|
|
5766
|
+
amountLimit = expectAmount.mul(new import_bn3.default(TEN_POW_NINE + slippage * TEN_POW_NINE)).div(new import_bn3.default(TEN_POW_NINE));
|
|
5767
|
+
}
|
|
5768
|
+
return amountLimit;
|
|
5769
|
+
}
|
|
5761
5770
|
function sqrtPriceX64ToPrice(sqrtPriceStr, decimalsA, decimalsB) {
|
|
5762
5771
|
const sqrtPriceX64 = new decimal_default(sqrtPriceStr).mul(decimal_default.pow(2, -64));
|
|
5763
5772
|
return sqrtPriceX64.pow(2).mul(decimal_default.pow(10, decimalsA - decimalsB));
|
|
@@ -6102,6 +6111,34 @@ var Suilend = class {
|
|
|
6102
6111
|
}
|
|
6103
6112
|
};
|
|
6104
6113
|
|
|
6114
|
+
// src/transaction/bluefin.ts
|
|
6115
|
+
var Bluefin = class {
|
|
6116
|
+
constructor(env) {
|
|
6117
|
+
if (env !== 0 /* Mainnet */) {
|
|
6118
|
+
throw new Error("Bluefin only supported on mainnet");
|
|
6119
|
+
}
|
|
6120
|
+
this.globalConfig = "0x03db251ba509a8d5d8777b6338836082335d93eecbdd09a11e190a1cff51c352";
|
|
6121
|
+
}
|
|
6122
|
+
swap(client, txb, path, inputCoin) {
|
|
6123
|
+
return __async(this, null, function* () {
|
|
6124
|
+
const { direction, from, target } = path;
|
|
6125
|
+
const [func, coinAType, coinBType] = direction ? ["swap_a2b", from, target] : ["swap_b2a", target, from];
|
|
6126
|
+
const args = [
|
|
6127
|
+
txb.object(this.globalConfig),
|
|
6128
|
+
txb.object(path.id),
|
|
6129
|
+
inputCoin,
|
|
6130
|
+
txb.object(CLOCK_ADDRESS)
|
|
6131
|
+
];
|
|
6132
|
+
const res = txb.moveCall({
|
|
6133
|
+
target: `${client.publishedAtV2()}::bluefin::${func}`,
|
|
6134
|
+
typeArguments: [coinAType, coinBType],
|
|
6135
|
+
arguments: args
|
|
6136
|
+
});
|
|
6137
|
+
return res;
|
|
6138
|
+
});
|
|
6139
|
+
}
|
|
6140
|
+
};
|
|
6141
|
+
|
|
6105
6142
|
// src/client.ts
|
|
6106
6143
|
var CETUS = "CETUS";
|
|
6107
6144
|
var DEEPBOOKV2 = "DEEPBOOK";
|
|
@@ -6118,8 +6155,9 @@ var BLUEMOVE = "BLUEMOVE";
|
|
|
6118
6155
|
var DEEPBOOKV3 = "DEEPBOOKV3";
|
|
6119
6156
|
var SCALLOP = "SCALLOP";
|
|
6120
6157
|
var SUILEND = "SUILEND";
|
|
6158
|
+
var BLUEFIN = "BLUEFIN";
|
|
6121
6159
|
var DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
6122
|
-
var
|
|
6160
|
+
var AggregatorClient9 = class {
|
|
6123
6161
|
constructor(endpoint, signer, client$1, env) {
|
|
6124
6162
|
this.endpoint = endpoint ? processEndpoint(endpoint) : DEFAULT_ENDPOINT;
|
|
6125
6163
|
this.client = client$1 || new client.SuiClient({ url: client.getFullnodeUrl("mainnet") });
|
|
@@ -6279,7 +6317,7 @@ var AggregatorClient8 = class {
|
|
|
6279
6317
|
(acc, router) => acc.add(router.amountOut),
|
|
6280
6318
|
new import_bn5.default(0)
|
|
6281
6319
|
);
|
|
6282
|
-
const amountLimit =
|
|
6320
|
+
const amountLimit = CalculateAmountLimitBN(
|
|
6283
6321
|
byAmountIn ? amountOut : amountIn,
|
|
6284
6322
|
byAmountIn,
|
|
6285
6323
|
slippage
|
|
@@ -6289,7 +6327,7 @@ var AggregatorClient8 = class {
|
|
|
6289
6327
|
txb,
|
|
6290
6328
|
inputCoin,
|
|
6291
6329
|
routers,
|
|
6292
|
-
|
|
6330
|
+
amountLimit,
|
|
6293
6331
|
partner,
|
|
6294
6332
|
deepbookv3DeepFee
|
|
6295
6333
|
);
|
|
@@ -6393,10 +6431,10 @@ var AggregatorClient8 = class {
|
|
|
6393
6431
|
return "0x52eae33adeb44de55cfb3f281d4cc9e02d976181c0952f5323648b5717b33934";
|
|
6394
6432
|
}
|
|
6395
6433
|
}
|
|
6396
|
-
// Include deepbookv3, scallop
|
|
6434
|
+
// Include deepbookv3, scallop, bluefin
|
|
6397
6435
|
publishedAtV2() {
|
|
6398
6436
|
if (this.env === 0 /* Mainnet */) {
|
|
6399
|
-
return "
|
|
6437
|
+
return "0x3b6d71bdeb8ce5b06febfd3cfc29ecd60d50da729477c8b8038ecdae34541b91";
|
|
6400
6438
|
} else {
|
|
6401
6439
|
return "0xfd8a73ef0a4b928da9c27fc287dc37c1ca64df71da8e8eac7ca9ece55eb5f448";
|
|
6402
6440
|
}
|
|
@@ -6465,6 +6503,8 @@ var AggregatorClient8 = class {
|
|
|
6465
6503
|
return new Scallop(this.env);
|
|
6466
6504
|
case SUILEND:
|
|
6467
6505
|
return new Suilend(this.env);
|
|
6506
|
+
case BLUEFIN:
|
|
6507
|
+
return new Bluefin(this.env);
|
|
6468
6508
|
default:
|
|
6469
6509
|
throw new Error(`Unsupported dex ${provider}`);
|
|
6470
6510
|
}
|
|
@@ -6774,7 +6814,8 @@ decimal.js/decimal.mjs:
|
|
|
6774
6814
|
|
|
6775
6815
|
exports.AFSUI = AFSUI;
|
|
6776
6816
|
exports.AFTERMATH = AFTERMATH;
|
|
6777
|
-
exports.AggregatorClient =
|
|
6817
|
+
exports.AggregatorClient = AggregatorClient9;
|
|
6818
|
+
exports.BLUEFIN = BLUEFIN;
|
|
6778
6819
|
exports.BLUEMOVE = BLUEMOVE;
|
|
6779
6820
|
exports.CETUS = CETUS;
|
|
6780
6821
|
exports.CLOCK_ADDRESS = CLOCK_ADDRESS;
|
package/dist/index.mjs
CHANGED
|
@@ -5756,6 +5756,15 @@ function CalculateAmountLimit(expectAmount, byAmountIn, slippage) {
|
|
|
5756
5756
|
}
|
|
5757
5757
|
return Number(amountLimit.toString());
|
|
5758
5758
|
}
|
|
5759
|
+
function CalculateAmountLimitBN(expectAmount, byAmountIn, slippage) {
|
|
5760
|
+
let amountLimit = ZERO;
|
|
5761
|
+
if (byAmountIn) {
|
|
5762
|
+
amountLimit = expectAmount.mul(new import_bn3.default(TEN_POW_NINE - slippage * TEN_POW_NINE)).div(new import_bn3.default(TEN_POW_NINE));
|
|
5763
|
+
} else {
|
|
5764
|
+
amountLimit = expectAmount.mul(new import_bn3.default(TEN_POW_NINE + slippage * TEN_POW_NINE)).div(new import_bn3.default(TEN_POW_NINE));
|
|
5765
|
+
}
|
|
5766
|
+
return amountLimit;
|
|
5767
|
+
}
|
|
5759
5768
|
function sqrtPriceX64ToPrice(sqrtPriceStr, decimalsA, decimalsB) {
|
|
5760
5769
|
const sqrtPriceX64 = new decimal_default(sqrtPriceStr).mul(decimal_default.pow(2, -64));
|
|
5761
5770
|
return sqrtPriceX64.pow(2).mul(decimal_default.pow(10, decimalsA - decimalsB));
|
|
@@ -6100,6 +6109,34 @@ var Suilend = class {
|
|
|
6100
6109
|
}
|
|
6101
6110
|
};
|
|
6102
6111
|
|
|
6112
|
+
// src/transaction/bluefin.ts
|
|
6113
|
+
var Bluefin = class {
|
|
6114
|
+
constructor(env) {
|
|
6115
|
+
if (env !== 0 /* Mainnet */) {
|
|
6116
|
+
throw new Error("Bluefin only supported on mainnet");
|
|
6117
|
+
}
|
|
6118
|
+
this.globalConfig = "0x03db251ba509a8d5d8777b6338836082335d93eecbdd09a11e190a1cff51c352";
|
|
6119
|
+
}
|
|
6120
|
+
swap(client, txb, path, inputCoin) {
|
|
6121
|
+
return __async(this, null, function* () {
|
|
6122
|
+
const { direction, from, target } = path;
|
|
6123
|
+
const [func, coinAType, coinBType] = direction ? ["swap_a2b", from, target] : ["swap_b2a", target, from];
|
|
6124
|
+
const args = [
|
|
6125
|
+
txb.object(this.globalConfig),
|
|
6126
|
+
txb.object(path.id),
|
|
6127
|
+
inputCoin,
|
|
6128
|
+
txb.object(CLOCK_ADDRESS)
|
|
6129
|
+
];
|
|
6130
|
+
const res = txb.moveCall({
|
|
6131
|
+
target: `${client.publishedAtV2()}::bluefin::${func}`,
|
|
6132
|
+
typeArguments: [coinAType, coinBType],
|
|
6133
|
+
arguments: args
|
|
6134
|
+
});
|
|
6135
|
+
return res;
|
|
6136
|
+
});
|
|
6137
|
+
}
|
|
6138
|
+
};
|
|
6139
|
+
|
|
6103
6140
|
// src/client.ts
|
|
6104
6141
|
var CETUS = "CETUS";
|
|
6105
6142
|
var DEEPBOOKV2 = "DEEPBOOK";
|
|
@@ -6116,8 +6153,9 @@ var BLUEMOVE = "BLUEMOVE";
|
|
|
6116
6153
|
var DEEPBOOKV3 = "DEEPBOOKV3";
|
|
6117
6154
|
var SCALLOP = "SCALLOP";
|
|
6118
6155
|
var SUILEND = "SUILEND";
|
|
6156
|
+
var BLUEFIN = "BLUEFIN";
|
|
6119
6157
|
var DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
6120
|
-
var
|
|
6158
|
+
var AggregatorClient9 = class {
|
|
6121
6159
|
constructor(endpoint, signer, client, env) {
|
|
6122
6160
|
this.endpoint = endpoint ? processEndpoint(endpoint) : DEFAULT_ENDPOINT;
|
|
6123
6161
|
this.client = client || new SuiClient({ url: getFullnodeUrl("mainnet") });
|
|
@@ -6277,7 +6315,7 @@ var AggregatorClient8 = class {
|
|
|
6277
6315
|
(acc, router) => acc.add(router.amountOut),
|
|
6278
6316
|
new import_bn5.default(0)
|
|
6279
6317
|
);
|
|
6280
|
-
const amountLimit =
|
|
6318
|
+
const amountLimit = CalculateAmountLimitBN(
|
|
6281
6319
|
byAmountIn ? amountOut : amountIn,
|
|
6282
6320
|
byAmountIn,
|
|
6283
6321
|
slippage
|
|
@@ -6287,7 +6325,7 @@ var AggregatorClient8 = class {
|
|
|
6287
6325
|
txb,
|
|
6288
6326
|
inputCoin,
|
|
6289
6327
|
routers,
|
|
6290
|
-
|
|
6328
|
+
amountLimit,
|
|
6291
6329
|
partner,
|
|
6292
6330
|
deepbookv3DeepFee
|
|
6293
6331
|
);
|
|
@@ -6391,10 +6429,10 @@ var AggregatorClient8 = class {
|
|
|
6391
6429
|
return "0x52eae33adeb44de55cfb3f281d4cc9e02d976181c0952f5323648b5717b33934";
|
|
6392
6430
|
}
|
|
6393
6431
|
}
|
|
6394
|
-
// Include deepbookv3, scallop
|
|
6432
|
+
// Include deepbookv3, scallop, bluefin
|
|
6395
6433
|
publishedAtV2() {
|
|
6396
6434
|
if (this.env === 0 /* Mainnet */) {
|
|
6397
|
-
return "
|
|
6435
|
+
return "0x3b6d71bdeb8ce5b06febfd3cfc29ecd60d50da729477c8b8038ecdae34541b91";
|
|
6398
6436
|
} else {
|
|
6399
6437
|
return "0xfd8a73ef0a4b928da9c27fc287dc37c1ca64df71da8e8eac7ca9ece55eb5f448";
|
|
6400
6438
|
}
|
|
@@ -6463,6 +6501,8 @@ var AggregatorClient8 = class {
|
|
|
6463
6501
|
return new Scallop(this.env);
|
|
6464
6502
|
case SUILEND:
|
|
6465
6503
|
return new Suilend(this.env);
|
|
6504
|
+
case BLUEFIN:
|
|
6505
|
+
return new Bluefin(this.env);
|
|
6466
6506
|
default:
|
|
6467
6507
|
throw new Error(`Unsupported dex ${provider}`);
|
|
6468
6508
|
}
|
|
@@ -6770,4 +6810,4 @@ decimal.js/decimal.mjs:
|
|
|
6770
6810
|
*)
|
|
6771
6811
|
*/
|
|
6772
6812
|
|
|
6773
|
-
export { AFSUI, AFTERMATH,
|
|
6813
|
+
export { AFSUI, AFTERMATH, AggregatorClient9 as AggregatorClient, BLUEFIN, 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
|
@@ -19,6 +19,7 @@ export declare const BLUEMOVE = "BLUEMOVE";
|
|
|
19
19
|
export declare const DEEPBOOKV3 = "DEEPBOOKV3";
|
|
20
20
|
export declare const SCALLOP = "SCALLOP";
|
|
21
21
|
export declare const SUILEND = "SUILEND";
|
|
22
|
+
export declare const BLUEFIN = "BLUEFIN";
|
|
22
23
|
export declare const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
23
24
|
export type BuildRouterSwapParams = {
|
|
24
25
|
routers: Router[];
|
package/dist/src/math.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import BN from "bn.js";
|
|
2
2
|
import Decimal from "decimal.js";
|
|
3
3
|
export declare function CalculateAmountLimit(expectAmount: BN, byAmountIn: boolean, slippage: number): number;
|
|
4
|
+
export declare function CalculateAmountLimitBN(expectAmount: BN, byAmountIn: boolean, slippage: number): BN;
|
|
4
5
|
export declare function GetDefaultSqrtPriceLimit(a2b: boolean): BN;
|
|
5
6
|
export declare function sqrtPriceX64ToPrice(sqrtPriceStr: string, decimalsA: number, decimalsB: number): Decimal;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
2
|
+
import { AggregatorClient, Dex, Env, Path } from "..";
|
|
3
|
+
export declare class Bluefin implements Dex {
|
|
4
|
+
private globalConfig;
|
|
5
|
+
constructor(env: Env);
|
|
6
|
+
swap(client: AggregatorClient, txb: Transaction, path: Path, inputCoin: TransactionObjectArgument): Promise<TransactionObjectArgument>;
|
|
7
|
+
}
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -28,7 +28,7 @@ import { FlowxV3 } from "./transaction/flowx_v3"
|
|
|
28
28
|
import { Turbos } from "./transaction/turbos"
|
|
29
29
|
import { Cetus } from "./transaction/cetus"
|
|
30
30
|
import { swapInPools } from "./transaction/swap"
|
|
31
|
-
import { CalculateAmountLimit } from "./math"
|
|
31
|
+
import { CalculateAmountLimit, CalculateAmountLimitBN } from "./math"
|
|
32
32
|
import { Haedal } from "./transaction/haedal"
|
|
33
33
|
import { Afsui } from "./transaction/afsui"
|
|
34
34
|
import { Volo } from "./transaction/volo"
|
|
@@ -38,6 +38,7 @@ import { buildInputCoin } from "./utils/coin"
|
|
|
38
38
|
import { DeepbookV3 } from "./transaction/deepbook_v3"
|
|
39
39
|
import { Scallop } from "./transaction/scallop"
|
|
40
40
|
import { Suilend } from "./transaction/suilend"
|
|
41
|
+
import { Bluefin } from "./transaction/bluefin"
|
|
41
42
|
|
|
42
43
|
export const CETUS = "CETUS"
|
|
43
44
|
export const DEEPBOOKV2 = "DEEPBOOK"
|
|
@@ -54,6 +55,7 @@ export const BLUEMOVE = "BLUEMOVE"
|
|
|
54
55
|
export const DEEPBOOKV3 = "DEEPBOOKV3"
|
|
55
56
|
export const SCALLOP = "SCALLOP"
|
|
56
57
|
export const SUILEND = "SUILEND"
|
|
58
|
+
export const BLUEFIN = "BLUEFIN"
|
|
57
59
|
export const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2"
|
|
58
60
|
|
|
59
61
|
export type BuildRouterSwapParams = {
|
|
@@ -284,7 +286,7 @@ export class AggregatorClient {
|
|
|
284
286
|
(acc, router) => acc.add(router.amountOut),
|
|
285
287
|
new BN(0)
|
|
286
288
|
)
|
|
287
|
-
const amountLimit =
|
|
289
|
+
const amountLimit = CalculateAmountLimitBN(
|
|
288
290
|
byAmountIn ? amountOut : amountIn,
|
|
289
291
|
byAmountIn,
|
|
290
292
|
slippage
|
|
@@ -295,7 +297,7 @@ export class AggregatorClient {
|
|
|
295
297
|
txb,
|
|
296
298
|
inputCoin,
|
|
297
299
|
routers,
|
|
298
|
-
|
|
300
|
+
amountLimit,
|
|
299
301
|
partner,
|
|
300
302
|
deepbookv3DeepFee
|
|
301
303
|
)
|
|
@@ -408,12 +410,13 @@ export class AggregatorClient {
|
|
|
408
410
|
}
|
|
409
411
|
}
|
|
410
412
|
|
|
411
|
-
// Include deepbookv3, scallop
|
|
413
|
+
// Include deepbookv3, scallop, bluefin
|
|
412
414
|
publishedAtV2(): string {
|
|
413
415
|
if (this.env === Env.Mainnet) {
|
|
414
416
|
// return "0x43811be4677f5a5de7bf2dac740c10abddfaa524aee6b18e910eeadda8a2f6ae" // version 1, deepbookv3
|
|
415
417
|
// return "0x6d70ffa7aa3f924c3f0b573d27d29895a0ee666aaff821073f75cb14af7fd01a" // version 3, deepbookv3 & scallop
|
|
416
|
-
return "0x16d9418726c26d8cb4ce8c9dd75917fa9b1c7bf47d38d7a1a22603135f0f2a56" // version 4 add suilend
|
|
418
|
+
// return "0x16d9418726c26d8cb4ce8c9dd75917fa9b1c7bf47d38d7a1a22603135f0f2a56" // version 4, add suilend
|
|
419
|
+
return "0x3b6d71bdeb8ce5b06febfd3cfc29ecd60d50da729477c8b8038ecdae34541b91" // version 5, add bluefin
|
|
417
420
|
} else {
|
|
418
421
|
return "0xfd8a73ef0a4b928da9c27fc287dc37c1ca64df71da8e8eac7ca9ece55eb5f448"
|
|
419
422
|
}
|
|
@@ -496,6 +499,8 @@ export class AggregatorClient {
|
|
|
496
499
|
return new Scallop(this.env)
|
|
497
500
|
case SUILEND:
|
|
498
501
|
return new Suilend(this.env)
|
|
502
|
+
case BLUEFIN:
|
|
503
|
+
return new Bluefin(this.env)
|
|
499
504
|
default:
|
|
500
505
|
throw new Error(`Unsupported dex ${provider}`)
|
|
501
506
|
}
|
package/src/math.ts
CHANGED
|
@@ -26,6 +26,25 @@ export function CalculateAmountLimit(
|
|
|
26
26
|
return Number(amountLimit.toString())
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
export function CalculateAmountLimitBN(
|
|
30
|
+
expectAmount: BN,
|
|
31
|
+
byAmountIn: boolean,
|
|
32
|
+
slippage: number
|
|
33
|
+
): BN {
|
|
34
|
+
let amountLimit = ZERO
|
|
35
|
+
if (byAmountIn) {
|
|
36
|
+
amountLimit = expectAmount
|
|
37
|
+
.mul(new BN(TEN_POW_NINE - slippage * TEN_POW_NINE))
|
|
38
|
+
.div(new BN(TEN_POW_NINE))
|
|
39
|
+
} else {
|
|
40
|
+
amountLimit = expectAmount
|
|
41
|
+
.mul(new BN(TEN_POW_NINE + slippage * TEN_POW_NINE))
|
|
42
|
+
.div(new BN(TEN_POW_NINE))
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return amountLimit
|
|
46
|
+
}
|
|
47
|
+
|
|
29
48
|
const MAX_SQER_PRICE_X64 = "79226673515401279992447579055"
|
|
30
49
|
const MIN_SQER_PRICE_X64 = "4295048016"
|
|
31
50
|
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Transaction,
|
|
3
|
+
TransactionArgument,
|
|
4
|
+
TransactionObjectArgument,
|
|
5
|
+
} from "@mysten/sui/transactions"
|
|
6
|
+
import { AggregatorClient, CLOCK_ADDRESS, Dex, Env, Path } from ".."
|
|
7
|
+
|
|
8
|
+
export class Bluefin implements Dex {
|
|
9
|
+
private globalConfig: string
|
|
10
|
+
|
|
11
|
+
constructor(env: Env) {
|
|
12
|
+
if (env !== Env.Mainnet) {
|
|
13
|
+
throw new Error("Bluefin only supported on mainnet")
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
this.globalConfig =
|
|
17
|
+
"0x03db251ba509a8d5d8777b6338836082335d93eecbdd09a11e190a1cff51c352"
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async swap(
|
|
21
|
+
client: AggregatorClient,
|
|
22
|
+
txb: Transaction,
|
|
23
|
+
path: Path,
|
|
24
|
+
inputCoin: TransactionObjectArgument
|
|
25
|
+
): Promise<TransactionObjectArgument> {
|
|
26
|
+
const { direction, from, target } = path
|
|
27
|
+
const [func, coinAType, coinBType] = direction
|
|
28
|
+
? ["swap_a2b", from, target]
|
|
29
|
+
: ["swap_b2a", target, from]
|
|
30
|
+
const args = [
|
|
31
|
+
txb.object(this.globalConfig),
|
|
32
|
+
txb.object(path.id),
|
|
33
|
+
inputCoin,
|
|
34
|
+
txb.object(CLOCK_ADDRESS),
|
|
35
|
+
]
|
|
36
|
+
const res = txb.moveCall({
|
|
37
|
+
target: `${client.publishedAtV2()}::bluefin::${func}`,
|
|
38
|
+
typeArguments: [coinAType, coinBType],
|
|
39
|
+
arguments: args,
|
|
40
|
+
}) as TransactionArgument
|
|
41
|
+
return res
|
|
42
|
+
}
|
|
43
|
+
}
|
package/tests/router.test.ts
CHANGED
|
@@ -112,9 +112,9 @@ describe("router module", () => {
|
|
|
112
112
|
|
|
113
113
|
test("Build router tx", async () => {
|
|
114
114
|
const byAmountIn = true
|
|
115
|
-
const amount = "
|
|
115
|
+
const amount = "1000000000"
|
|
116
116
|
const from = "0x2::sui::SUI"
|
|
117
|
-
const target = "
|
|
117
|
+
const target = "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN"
|
|
118
118
|
|
|
119
119
|
const res = await client.findRouters({
|
|
120
120
|
from,
|
|
@@ -122,17 +122,7 @@ describe("router module", () => {
|
|
|
122
122
|
amount: new BN(amount),
|
|
123
123
|
byAmountIn,
|
|
124
124
|
depth: 3,
|
|
125
|
-
providers: [
|
|
126
|
-
"SUILEND",
|
|
127
|
-
// "CETUS",
|
|
128
|
-
// "DEEPBOOKV3",
|
|
129
|
-
// "DEEPBOOK",
|
|
130
|
-
// "AFTERMATH",
|
|
131
|
-
// "FLOWX",
|
|
132
|
-
// "KRIYA",
|
|
133
|
-
// "KRIYAV3",
|
|
134
|
-
// "TURBOS",
|
|
135
|
-
],
|
|
125
|
+
providers: ["BLUEFIN"],
|
|
136
126
|
})
|
|
137
127
|
|
|
138
128
|
if (res != null) {
|
|
@@ -152,7 +142,7 @@ describe("router module", () => {
|
|
|
152
142
|
txb,
|
|
153
143
|
slippage: 0.01,
|
|
154
144
|
isMergeTragetCoin: false,
|
|
155
|
-
partner: "0x1f5fa5c820f40d43fc47815ad06d95e40a1942ff72a732a92e8ef4aa8cde70a5",
|
|
145
|
+
// partner: "0x1f5fa5c820f40d43fc47815ad06d95e40a1942ff72a732a92e8ef4aa8cde70a5",
|
|
156
146
|
refreshAllCoins: true,
|
|
157
147
|
payDeepFeeAmount: 0,
|
|
158
148
|
})
|
|
@@ -161,14 +151,18 @@ describe("router module", () => {
|
|
|
161
151
|
|
|
162
152
|
let result = await client.devInspectTransactionBlock(txb)
|
|
163
153
|
console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
// console.log("Sim exec transaction success")
|
|
167
|
-
const result = await client.signAndExecuteTransaction(txb, keypair)
|
|
168
|
-
console.log("result", result)
|
|
169
|
-
} else {
|
|
170
|
-
console.log("result", result)
|
|
154
|
+
for (const event of result.events) {
|
|
155
|
+
console.log("event", JSON.stringify(event, null, 2))
|
|
171
156
|
}
|
|
157
|
+
console.log("txb", )
|
|
158
|
+
|
|
159
|
+
// if (result.effects.status.status === "success") {
|
|
160
|
+
// // console.log("Sim exec transaction success")
|
|
161
|
+
// const result = await client.signAndExecuteTransaction(txb, keypair)
|
|
162
|
+
// console.log("result", result)
|
|
163
|
+
// } else {
|
|
164
|
+
// console.log("result", result)
|
|
165
|
+
// }
|
|
172
166
|
}
|
|
173
167
|
}, 600000)
|
|
174
168
|
|