@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.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SuiClient, getFullnodeUrl } from '@mysten/sui/client';
|
|
1
2
|
import { normalizeSuiObjectId, SUI_FRAMEWORK_ADDRESS } from '@mysten/sui/utils';
|
|
2
3
|
import { Transaction } from '@mysten/sui/transactions';
|
|
3
4
|
|
|
@@ -5674,8 +5675,8 @@ function buildInputCoin(txb, allCoins, amount, coinType) {
|
|
|
5674
5675
|
let totalCoinBalance = CoinUtils.calculateTotalBalance(usedCoinAsests);
|
|
5675
5676
|
if (totalCoinBalance < amount) {
|
|
5676
5677
|
throw new AggregateError(
|
|
5677
|
-
"Insufficient balance when build merge coin",
|
|
5678
|
-
"InsufficientBalance" /* InsufficientBalance */
|
|
5678
|
+
"Insufficient balance when build merge coin, coinType: " + coinType,
|
|
5679
|
+
"InsufficientBalance" /* InsufficientBalance */ + coinType
|
|
5679
5680
|
);
|
|
5680
5681
|
}
|
|
5681
5682
|
if (CoinUtils.isSuiCoin(coinType)) {
|
|
@@ -5712,6 +5713,16 @@ function buildInputCoin(txb, allCoins, amount, coinType) {
|
|
|
5712
5713
|
}
|
|
5713
5714
|
|
|
5714
5715
|
// src/utils/transaction.ts
|
|
5716
|
+
function printTransaction(tx, isPrint = true) {
|
|
5717
|
+
return __async(this, null, function* () {
|
|
5718
|
+
console.log(`inputs`, tx.getData().inputs);
|
|
5719
|
+
tx.getData().commands.forEach((item, index) => {
|
|
5720
|
+
if (isPrint) {
|
|
5721
|
+
console.log(`transaction ${index}: `, JSON.stringify(item, null, 2));
|
|
5722
|
+
}
|
|
5723
|
+
});
|
|
5724
|
+
});
|
|
5725
|
+
}
|
|
5715
5726
|
function checkInvalidSuiAddress(address) {
|
|
5716
5727
|
if (!address.startsWith("0x") || address.length !== 66) {
|
|
5717
5728
|
return false;
|
|
@@ -5763,6 +5774,8 @@ function swapInPools(client, params, sender) {
|
|
|
5763
5774
|
const coinA = direction ? fromCoin : targetCoin;
|
|
5764
5775
|
const coinB = direction ? targetCoin : fromCoin;
|
|
5765
5776
|
const typeArguments = [coinA, coinB];
|
|
5777
|
+
console.log("typeArguments", typeArguments);
|
|
5778
|
+
console.log("pools", pools);
|
|
5766
5779
|
for (let i = 0; i < pools.length; i++) {
|
|
5767
5780
|
const args = [
|
|
5768
5781
|
tx.object(pools[i]),
|
|
@@ -5787,6 +5800,7 @@ function swapInPools(client, params, sender) {
|
|
|
5787
5800
|
sender
|
|
5788
5801
|
});
|
|
5789
5802
|
if (simulateRes.error != null) {
|
|
5803
|
+
console.log("simulateRes.error", simulateRes.error);
|
|
5790
5804
|
throw new AggregateError(
|
|
5791
5805
|
"Aggregator package not set",
|
|
5792
5806
|
"SimulateError" /* SimulateError */
|
|
@@ -5990,6 +6004,38 @@ var Bluemove = class {
|
|
|
5990
6004
|
}
|
|
5991
6005
|
};
|
|
5992
6006
|
|
|
6007
|
+
// src/transaction/deepbook_v3.ts
|
|
6008
|
+
var DeepbookV3 = class {
|
|
6009
|
+
constructor(env) {
|
|
6010
|
+
this.deepbookV3Config = env === 0 /* Mainnet */ ? "0xe4099d0cda04f3aa80028fac91a9b3dbe50d08f2ff42aa2c29473926e34ca48c" : "0xe19b5d072346cae83a037d4e3c8492068a74410a74e5830b3a68012db38296aa";
|
|
6011
|
+
}
|
|
6012
|
+
swap(client, txb, path, inputCoin, deepbookv3DeepFee) {
|
|
6013
|
+
return __async(this, null, function* () {
|
|
6014
|
+
const { direction, from, target } = path;
|
|
6015
|
+
const [func, coinAType, coinBType] = direction ? ["swap_a2b", from, target] : ["swap_b2a", target, from];
|
|
6016
|
+
let deepFee;
|
|
6017
|
+
if (deepbookv3DeepFee) {
|
|
6018
|
+
deepFee = deepbookv3DeepFee;
|
|
6019
|
+
} else {
|
|
6020
|
+
deepFee = mintZeroCoin(txb, client.deepbookv3DeepFeeType());
|
|
6021
|
+
}
|
|
6022
|
+
const args = [
|
|
6023
|
+
txb.object(this.deepbookV3Config),
|
|
6024
|
+
txb.object(path.id),
|
|
6025
|
+
inputCoin,
|
|
6026
|
+
deepFee,
|
|
6027
|
+
txb.object(CLOCK_ADDRESS)
|
|
6028
|
+
];
|
|
6029
|
+
const res = txb.moveCall({
|
|
6030
|
+
target: `${client.publishedAtV2()}::deepbookv3::${func}`,
|
|
6031
|
+
typeArguments: [coinAType, coinBType],
|
|
6032
|
+
arguments: args
|
|
6033
|
+
});
|
|
6034
|
+
return res;
|
|
6035
|
+
});
|
|
6036
|
+
}
|
|
6037
|
+
};
|
|
6038
|
+
|
|
5993
6039
|
// src/client.ts
|
|
5994
6040
|
var CETUS = "CETUS";
|
|
5995
6041
|
var DEEPBOOKV2 = "DEEPBOOK";
|
|
@@ -6003,16 +6049,21 @@ var HAEDAL = "HAEDAL";
|
|
|
6003
6049
|
var VOLO = "VOLO";
|
|
6004
6050
|
var AFSUI = "AFSUI";
|
|
6005
6051
|
var BLUEMOVE = "BLUEMOVE";
|
|
6006
|
-
var
|
|
6052
|
+
var DEEPBOOKV3 = "DEEPBOOKV3";
|
|
6053
|
+
var DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
6054
|
+
var AggregatorClient7 = class {
|
|
6007
6055
|
constructor(endpoint, signer, client, env) {
|
|
6008
|
-
this.endpoint = endpoint;
|
|
6009
|
-
this.client = client;
|
|
6010
|
-
this.signer = signer;
|
|
6011
|
-
this.env = env
|
|
6056
|
+
this.endpoint = endpoint ? processEndpoint(endpoint) : DEFAULT_ENDPOINT;
|
|
6057
|
+
this.client = client || new SuiClient({ url: getFullnodeUrl("mainnet") });
|
|
6058
|
+
this.signer = signer || "";
|
|
6059
|
+
this.env = env || 0 /* Mainnet */;
|
|
6012
6060
|
this.allCoins = [];
|
|
6013
6061
|
}
|
|
6014
6062
|
getAllCoins() {
|
|
6015
6063
|
return __async(this, null, function* () {
|
|
6064
|
+
if (this.signer === "") {
|
|
6065
|
+
throw new Error("Signer is required, but not provided.");
|
|
6066
|
+
}
|
|
6016
6067
|
let cursor = null;
|
|
6017
6068
|
let limit = 50;
|
|
6018
6069
|
const allCoins = [];
|
|
@@ -6042,7 +6093,7 @@ var AggregatorClient6 = class {
|
|
|
6042
6093
|
return getRouterResult(this.endpoint, params);
|
|
6043
6094
|
});
|
|
6044
6095
|
}
|
|
6045
|
-
expectInputSwap(txb, inputCoin, routers, amountOutLimit, partner) {
|
|
6096
|
+
expectInputSwap(txb, inputCoin, routers, amountOutLimit, partner, deepbookv3DeepFee) {
|
|
6046
6097
|
return __async(this, null, function* () {
|
|
6047
6098
|
if (routers.length === 0) {
|
|
6048
6099
|
throw new Error("No router found");
|
|
@@ -6059,7 +6110,7 @@ var AggregatorClient6 = class {
|
|
|
6059
6110
|
let nextCoin = inputCoins[i];
|
|
6060
6111
|
for (const path of routers[i].path) {
|
|
6061
6112
|
const dex = this.newDex(path.provider, partner);
|
|
6062
|
-
nextCoin = yield dex.swap(this, txb, path, nextCoin);
|
|
6113
|
+
nextCoin = yield dex.swap(this, txb, path, nextCoin, deepbookv3DeepFee);
|
|
6063
6114
|
}
|
|
6064
6115
|
outputCoins.push(nextCoin);
|
|
6065
6116
|
}
|
|
@@ -6135,7 +6186,7 @@ var AggregatorClient6 = class {
|
|
|
6135
6186
|
}
|
|
6136
6187
|
routerSwap(params) {
|
|
6137
6188
|
return __async(this, null, function* () {
|
|
6138
|
-
const { routers, inputCoin, slippage, byAmountIn, txb, partner } = params;
|
|
6189
|
+
const { routers, inputCoin, slippage, byAmountIn, txb, partner, deepbookv3DeepFee } = params;
|
|
6139
6190
|
const amountIn = routers.reduce(
|
|
6140
6191
|
(acc, router) => acc.add(router.amountIn),
|
|
6141
6192
|
new import_bn5.default(0)
|
|
@@ -6155,7 +6206,8 @@ var AggregatorClient6 = class {
|
|
|
6155
6206
|
inputCoin,
|
|
6156
6207
|
routers,
|
|
6157
6208
|
new import_bn5.default(amountLimit),
|
|
6158
|
-
partner
|
|
6209
|
+
partner,
|
|
6210
|
+
deepbookv3DeepFee
|
|
6159
6211
|
);
|
|
6160
6212
|
return targetCoin2;
|
|
6161
6213
|
}
|
|
@@ -6183,7 +6235,8 @@ var AggregatorClient6 = class {
|
|
|
6183
6235
|
txb,
|
|
6184
6236
|
partner,
|
|
6185
6237
|
isMergeTragetCoin,
|
|
6186
|
-
refreshAllCoins
|
|
6238
|
+
refreshAllCoins,
|
|
6239
|
+
payDeepFeeAmount
|
|
6187
6240
|
} = params;
|
|
6188
6241
|
if (refreshAllCoins || this.allCoins.length === 0) {
|
|
6189
6242
|
this.allCoins = yield this.getAllCoins();
|
|
@@ -6210,13 +6263,23 @@ var AggregatorClient6 = class {
|
|
|
6210
6263
|
BigInt(amount.toString()),
|
|
6211
6264
|
fromCoinType
|
|
6212
6265
|
);
|
|
6266
|
+
let deepCoin;
|
|
6267
|
+
if (payDeepFeeAmount && payDeepFeeAmount > 0) {
|
|
6268
|
+
deepCoin = buildInputCoin(
|
|
6269
|
+
txb,
|
|
6270
|
+
this.allCoins,
|
|
6271
|
+
BigInt(payDeepFeeAmount),
|
|
6272
|
+
this.deepbookv3DeepFeeType()
|
|
6273
|
+
).targetCoin;
|
|
6274
|
+
}
|
|
6213
6275
|
const targetCoin = yield this.routerSwap({
|
|
6214
6276
|
routers,
|
|
6215
6277
|
inputCoin: buildFromCoinRes.targetCoin,
|
|
6216
6278
|
slippage,
|
|
6217
6279
|
byAmountIn,
|
|
6218
6280
|
txb,
|
|
6219
|
-
partner
|
|
6281
|
+
partner,
|
|
6282
|
+
deepbookv3DeepFee: deepCoin
|
|
6220
6283
|
});
|
|
6221
6284
|
if (isMergeTragetCoin) {
|
|
6222
6285
|
const targetCoinRes = buildInputCoin(
|
|
@@ -6238,11 +6301,27 @@ var AggregatorClient6 = class {
|
|
|
6238
6301
|
}
|
|
6239
6302
|
});
|
|
6240
6303
|
}
|
|
6304
|
+
// Include cetus、deepbookv2、flowxv2 & v3、kriyav2 & v3、turbos、aftermath、haedal、afsui、volo、bluemove
|
|
6241
6305
|
publishedAt() {
|
|
6242
6306
|
if (this.env === 0 /* Mainnet */) {
|
|
6243
|
-
return "
|
|
6307
|
+
return "0xf98ed029af555e4a103febf26243dc33ac09a7ea1b2da7e414c728b25b729086";
|
|
6308
|
+
} else {
|
|
6309
|
+
return "0x0ed287d6c3fe4962d0994ffddc1d19a15fba6a81533f3f0dcc2bbcedebce0637";
|
|
6310
|
+
}
|
|
6311
|
+
}
|
|
6312
|
+
// Include deepbookv3
|
|
6313
|
+
publishedAtV2() {
|
|
6314
|
+
if (this.env === 0 /* Mainnet */) {
|
|
6315
|
+
return "0x43811be4677f5a5de7bf2dac740c10abddfaa524aee6b18e910eeadda8a2f6ae";
|
|
6244
6316
|
} else {
|
|
6245
|
-
return "
|
|
6317
|
+
return "0x0ed287d6c3fe4962d0994ffddc1d19a15fba6a81533f3f0dcc2bbcedebce0637";
|
|
6318
|
+
}
|
|
6319
|
+
}
|
|
6320
|
+
deepbookv3DeepFeeType() {
|
|
6321
|
+
if (this.env === 0 /* Mainnet */) {
|
|
6322
|
+
return "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP";
|
|
6323
|
+
} else {
|
|
6324
|
+
return "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP";
|
|
6246
6325
|
}
|
|
6247
6326
|
}
|
|
6248
6327
|
transferOrDestoryCoin(txb, coin, coinType) {
|
|
@@ -6276,6 +6355,8 @@ var AggregatorClient6 = class {
|
|
|
6276
6355
|
return new Cetus(this.env, partner);
|
|
6277
6356
|
case DEEPBOOKV2:
|
|
6278
6357
|
return new DeepbookV2(this.env);
|
|
6358
|
+
case DEEPBOOKV3:
|
|
6359
|
+
return new DeepbookV3(this.env);
|
|
6279
6360
|
case KRIYA:
|
|
6280
6361
|
return new KriyaV2(this.env);
|
|
6281
6362
|
case KRIYAV3:
|
|
@@ -6333,26 +6414,44 @@ var AggregatorClient6 = class {
|
|
|
6333
6414
|
return res;
|
|
6334
6415
|
});
|
|
6335
6416
|
}
|
|
6417
|
+
getDeepbookV3Config() {
|
|
6418
|
+
return __async(this, null, function* () {
|
|
6419
|
+
const res = yield getDeepbookV3Config(this.endpoint);
|
|
6420
|
+
if (res) {
|
|
6421
|
+
return res.data;
|
|
6422
|
+
}
|
|
6423
|
+
return null;
|
|
6424
|
+
});
|
|
6425
|
+
}
|
|
6336
6426
|
};
|
|
6337
6427
|
function parseRouterResponse(data) {
|
|
6338
|
-
|
|
6428
|
+
let totalDeepFee = 0;
|
|
6429
|
+
for (const route of data.routes) {
|
|
6430
|
+
for (const path of route.path) {
|
|
6431
|
+
if (path.extended_details && path.extended_details.deepbookv3_deep_fee) {
|
|
6432
|
+
totalDeepFee += Number(path.extended_details.deepbookv3_deep_fee);
|
|
6433
|
+
}
|
|
6434
|
+
}
|
|
6435
|
+
}
|
|
6436
|
+
let routerData = {
|
|
6339
6437
|
amountIn: new import_bn5.default(data.amount_in.toString()),
|
|
6340
6438
|
amountOut: new import_bn5.default(data.amount_out.toString()),
|
|
6341
6439
|
insufficientLiquidity: false,
|
|
6342
6440
|
routes: data.routes.map((route) => {
|
|
6343
6441
|
return {
|
|
6344
6442
|
path: route.path.map((path) => {
|
|
6345
|
-
var _a, _b, _c;
|
|
6443
|
+
var _a, _b, _c, _d;
|
|
6346
6444
|
let version;
|
|
6347
6445
|
if (path.provider === AFTERMATH) {
|
|
6348
6446
|
version = path.extended_details.aftermath_pool_flatness === 0 ? "v2" : "v3";
|
|
6349
6447
|
}
|
|
6350
6448
|
let extendedDetails;
|
|
6351
|
-
if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS) {
|
|
6449
|
+
if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS || path.provider === DEEPBOOKV3) {
|
|
6352
6450
|
extendedDetails = {
|
|
6353
6451
|
aftermathLpSupplyType: (_a = path.extended_details) == null ? void 0 : _a.aftermath_lp_supply_type,
|
|
6354
6452
|
turbosFeeType: (_b = path.extended_details) == null ? void 0 : _b.turbos_fee_type,
|
|
6355
|
-
afterSqrtPrice: (_c = path.extended_details) == null ? void 0 : _c.after_sqrt_price
|
|
6453
|
+
afterSqrtPrice: (_c = path.extended_details) == null ? void 0 : _c.after_sqrt_price,
|
|
6454
|
+
deepbookv3DeepFee: (_d = path.extended_details) == null ? void 0 : _d.deepbookv3_deep_fee
|
|
6356
6455
|
};
|
|
6357
6456
|
}
|
|
6358
6457
|
return {
|
|
@@ -6372,8 +6471,10 @@ function parseRouterResponse(data) {
|
|
|
6372
6471
|
amountOut: new import_bn5.default(route.amount_out.toString()),
|
|
6373
6472
|
initialPrice: new decimal_default(route.initial_price.toString())
|
|
6374
6473
|
};
|
|
6375
|
-
})
|
|
6474
|
+
}),
|
|
6475
|
+
totalDeepFee
|
|
6376
6476
|
};
|
|
6477
|
+
return routerData;
|
|
6377
6478
|
}
|
|
6378
6479
|
|
|
6379
6480
|
// src/transaction/index.ts
|
|
@@ -6404,6 +6505,14 @@ var restituteMsafeFastRouterSwapParams = (data) => {
|
|
|
6404
6505
|
return result;
|
|
6405
6506
|
};
|
|
6406
6507
|
|
|
6508
|
+
// src/utils/api.ts
|
|
6509
|
+
function processEndpoint(endpoint) {
|
|
6510
|
+
if (endpoint.endsWith("/find_routes")) {
|
|
6511
|
+
return endpoint.replace("/find_routes", "");
|
|
6512
|
+
}
|
|
6513
|
+
return endpoint;
|
|
6514
|
+
}
|
|
6515
|
+
|
|
6407
6516
|
// src/api.ts
|
|
6408
6517
|
function getRouterResult(endpoint, params) {
|
|
6409
6518
|
return __async(this, null, function* () {
|
|
@@ -6466,7 +6575,7 @@ function getRouter(endpoint, params) {
|
|
|
6466
6575
|
} = params;
|
|
6467
6576
|
const fromCoin = completionCoin(from);
|
|
6468
6577
|
const targetCoin = completionCoin(target);
|
|
6469
|
-
let url = `${endpoint}?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`;
|
|
6578
|
+
let url = `${endpoint}/find_routes?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`;
|
|
6470
6579
|
if (depth) {
|
|
6471
6580
|
url += `&depth=${depth}`;
|
|
6472
6581
|
}
|
|
@@ -6484,6 +6593,7 @@ function getRouter(endpoint, params) {
|
|
|
6484
6593
|
url += `&providers=${providers.join(",")}`;
|
|
6485
6594
|
}
|
|
6486
6595
|
}
|
|
6596
|
+
url += "&v=1000302";
|
|
6487
6597
|
const response = yield fetch(url);
|
|
6488
6598
|
return response;
|
|
6489
6599
|
} catch (error) {
|
|
@@ -6508,7 +6618,7 @@ function postRouterWithLiquidityChanges(endpoint, params) {
|
|
|
6508
6618
|
} = params;
|
|
6509
6619
|
const fromCoin = completionCoin(from);
|
|
6510
6620
|
const targetCoin = completionCoin(target);
|
|
6511
|
-
const url = `${endpoint}`;
|
|
6621
|
+
const url = `${endpoint}/find_routes`;
|
|
6512
6622
|
const providersStr = providers == null ? void 0 : providers.join(",");
|
|
6513
6623
|
const requestData = {
|
|
6514
6624
|
from: fromCoin,
|
|
@@ -6527,7 +6637,6 @@ function postRouterWithLiquidityChanges(endpoint, params) {
|
|
|
6527
6637
|
delta_liquidity: change.deltaLiquidity
|
|
6528
6638
|
}))
|
|
6529
6639
|
};
|
|
6530
|
-
console.log("requestData", JSON.stringify(requestData, null, 2));
|
|
6531
6640
|
try {
|
|
6532
6641
|
const response = yield fetch(url, {
|
|
6533
6642
|
method: "POST",
|
|
@@ -6543,6 +6652,18 @@ function postRouterWithLiquidityChanges(endpoint, params) {
|
|
|
6543
6652
|
}
|
|
6544
6653
|
});
|
|
6545
6654
|
}
|
|
6655
|
+
function getDeepbookV3Config(endpoint) {
|
|
6656
|
+
return __async(this, null, function* () {
|
|
6657
|
+
const url = `${endpoint}/deepbookv3_config`;
|
|
6658
|
+
try {
|
|
6659
|
+
const response = yield fetch(url);
|
|
6660
|
+
return response.json();
|
|
6661
|
+
} catch (error) {
|
|
6662
|
+
console.error("Error:", error);
|
|
6663
|
+
return null;
|
|
6664
|
+
}
|
|
6665
|
+
});
|
|
6666
|
+
}
|
|
6546
6667
|
|
|
6547
6668
|
// src/index.ts
|
|
6548
6669
|
var Env = /* @__PURE__ */ ((Env2) => {
|
|
@@ -6562,4 +6683,4 @@ decimal.js/decimal.mjs:
|
|
|
6562
6683
|
*)
|
|
6563
6684
|
*/
|
|
6564
6685
|
|
|
6565
|
-
export { AFSUI, AFTERMATH,
|
|
6686
|
+
export { AFSUI, AFTERMATH, AggregatorClient7 as AggregatorClient, BLUEMOVE, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, Env, FLOWXV2, FLOWXV3, HAEDAL, KRIYA, KRIYAV3, ONE, 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/api.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export type ExtendedDetails = {
|
|
|
23
23
|
aftermathLpSupplyType?: string;
|
|
24
24
|
turbosFeeType?: string;
|
|
25
25
|
afterSqrtPrice?: string;
|
|
26
|
+
deepbookv3DeepFee?: number;
|
|
26
27
|
};
|
|
27
28
|
export type Path = {
|
|
28
29
|
id: string;
|
|
@@ -51,6 +52,7 @@ export type RouterData = {
|
|
|
51
52
|
amountOut: BN;
|
|
52
53
|
routes: Router[];
|
|
53
54
|
insufficientLiquidity: boolean;
|
|
55
|
+
totalDeepFee?: number;
|
|
54
56
|
error?: RouterError;
|
|
55
57
|
};
|
|
56
58
|
export type AggregatorResponse = {
|
|
@@ -59,3 +61,21 @@ export type AggregatorResponse = {
|
|
|
59
61
|
data: RouterData;
|
|
60
62
|
};
|
|
61
63
|
export declare function getRouterResult(endpoint: string, params: FindRouterParams): Promise<RouterData | null>;
|
|
64
|
+
export type DeepbookV3Config = {
|
|
65
|
+
id: string;
|
|
66
|
+
is_alternative_payment: boolean;
|
|
67
|
+
alternative_payment_amount: number;
|
|
68
|
+
trade_cap: string;
|
|
69
|
+
balance_manager: string;
|
|
70
|
+
deep_fee_vault: number;
|
|
71
|
+
whitelist: number;
|
|
72
|
+
package_version: 0;
|
|
73
|
+
last_updated_time: number;
|
|
74
|
+
whitelist_pools: string[];
|
|
75
|
+
};
|
|
76
|
+
export type DeepbookV3ConfigResponse = {
|
|
77
|
+
code: number;
|
|
78
|
+
msg: string;
|
|
79
|
+
data: DeepbookV3Config;
|
|
80
|
+
};
|
|
81
|
+
export declare function getDeepbookV3Config(endpoint: string): Promise<DeepbookV3ConfigResponse | null>;
|
package/dist/src/client.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { SuiClient } from "@mysten/sui/client";
|
|
|
2
2
|
import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
3
3
|
import { Signer } from "@mysten/sui/cryptography";
|
|
4
4
|
import BN from "bn.js";
|
|
5
|
-
import { Dex, Env, FindRouterParams, Router, RouterData } from ".";
|
|
5
|
+
import { Dex, Env, FindRouterParams, Router, RouterData, DeepbookV3Config } from ".";
|
|
6
6
|
import { CoinAsset } from "./types/sui";
|
|
7
7
|
export declare const CETUS = "CETUS";
|
|
8
8
|
export declare const DEEPBOOKV2 = "DEEPBOOK";
|
|
@@ -16,6 +16,8 @@ export declare const HAEDAL = "HAEDAL";
|
|
|
16
16
|
export declare const VOLO = "VOLO";
|
|
17
17
|
export declare const AFSUI = "AFSUI";
|
|
18
18
|
export declare const BLUEMOVE = "BLUEMOVE";
|
|
19
|
+
export declare const DEEPBOOKV3 = "DEEPBOOKV3";
|
|
20
|
+
export declare const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
19
21
|
export type BuildRouterSwapParams = {
|
|
20
22
|
routers: Router[];
|
|
21
23
|
byAmountIn: boolean;
|
|
@@ -23,6 +25,7 @@ export type BuildRouterSwapParams = {
|
|
|
23
25
|
slippage: number;
|
|
24
26
|
txb: Transaction;
|
|
25
27
|
partner?: string;
|
|
28
|
+
deepbookv3DeepFee?: TransactionObjectArgument;
|
|
26
29
|
};
|
|
27
30
|
export type BuildFastRouterSwapParams = {
|
|
28
31
|
routers: Router[];
|
|
@@ -32,6 +35,7 @@ export type BuildFastRouterSwapParams = {
|
|
|
32
35
|
partner?: string;
|
|
33
36
|
isMergeTragetCoin?: boolean;
|
|
34
37
|
refreshAllCoins?: boolean;
|
|
38
|
+
payDeepFeeAmount?: number;
|
|
35
39
|
};
|
|
36
40
|
export interface SwapInPoolsParams {
|
|
37
41
|
from: string;
|
|
@@ -50,20 +54,23 @@ export declare class AggregatorClient {
|
|
|
50
54
|
client: SuiClient;
|
|
51
55
|
env: Env;
|
|
52
56
|
private allCoins;
|
|
53
|
-
constructor(endpoint
|
|
57
|
+
constructor(endpoint?: string, signer?: string, client?: SuiClient, env?: Env);
|
|
54
58
|
getAllCoins(): Promise<CoinAsset[]>;
|
|
55
59
|
findRouters(params: FindRouterParams): Promise<RouterData | null>;
|
|
56
|
-
expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, partner?: string): Promise<TransactionObjectArgument>;
|
|
60
|
+
expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
|
|
57
61
|
expectOutputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], partner?: string): Promise<TransactionObjectArgument>;
|
|
58
62
|
swapInPools(params: SwapInPoolsParams): Promise<SwapInPoolsResult | null>;
|
|
59
63
|
routerSwap(params: BuildRouterSwapParams): Promise<TransactionObjectArgument>;
|
|
60
64
|
fastRouterSwap(params: BuildFastRouterSwapParams): Promise<void>;
|
|
61
65
|
publishedAt(): string;
|
|
66
|
+
publishedAtV2(): string;
|
|
67
|
+
deepbookv3DeepFeeType(): string;
|
|
62
68
|
transferOrDestoryCoin(txb: Transaction, coin: TransactionObjectArgument, coinType: string): void;
|
|
63
69
|
checkCoinThresholdAndMergeCoin(txb: Transaction, coins: TransactionObjectArgument[], coinType: string, amountLimit: BN): TransactionObjectArgument;
|
|
64
70
|
newDex(provider: string, partner?: string): Dex;
|
|
65
71
|
signAndExecuteTransaction(txb: Transaction, signer: Signer): Promise<import("@mysten/sui/client").SuiTransactionBlockResponse>;
|
|
66
72
|
devInspectTransactionBlock(txb: Transaction): Promise<import("@mysten/sui/client").DevInspectResults>;
|
|
67
73
|
sendTransaction(txb: Transaction, signer: Signer): Promise<import("@mysten/sui/client").SuiTransactionBlockResponse>;
|
|
74
|
+
getDeepbookV3Config(): Promise<DeepbookV3Config | null>;
|
|
68
75
|
}
|
|
69
76
|
export declare function parseRouterResponse(data: any): RouterData;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Transaction, TransactionArgument, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
2
|
+
import { AggregatorClient, Dex, Env, Path } from "..";
|
|
3
|
+
export type CetusFlashSwapResult = {
|
|
4
|
+
targetCoin: TransactionObjectArgument;
|
|
5
|
+
flashReceipt: TransactionObjectArgument;
|
|
6
|
+
payAmount: TransactionArgument;
|
|
7
|
+
};
|
|
8
|
+
export declare class DeepbookV3 implements Dex {
|
|
9
|
+
private deepbookV3Config;
|
|
10
|
+
constructor(env: Env);
|
|
11
|
+
swap(client: AggregatorClient, txb: Transaction, path: Path, inputCoin: TransactionObjectArgument, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
|
|
12
|
+
}
|
|
@@ -2,5 +2,5 @@ import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions
|
|
|
2
2
|
import { AggregatorClient, Path } from "..";
|
|
3
3
|
export declare const CLOCK_ADDRESS = "0x0000000000000000000000000000000000000000000000000000000000000006";
|
|
4
4
|
export interface Dex {
|
|
5
|
-
swap(client: AggregatorClient, ptb: Transaction, path: Path, inputCoin: TransactionObjectArgument): Promise<TransactionObjectArgument>;
|
|
5
|
+
swap(client: AggregatorClient, ptb: Transaction, path: Path, inputCoin: TransactionObjectArgument, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
|
|
6
6
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function processEndpoint(endpoint: string): string;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export declare const T_USDC = "";
|
|
2
|
+
export declare const T_DEEP = "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP";
|
|
3
|
+
export declare const T_DBUSDC = "0xf7152c05930480cd740d7311b5b8b45c6f488e3a53a11c3f74a6fac36a52e0d7::DBUSDC::DBUSDC";
|
|
4
|
+
export declare const T_DBUSDT = "0xf7152c05930480cd740d7311b5b8b45c6f488e3a53a11c3f74a6fac36a52e0d7::DBUSDT::DBUSDT";
|
|
2
5
|
export declare const M_USDC = "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN";
|
|
3
6
|
export declare const M_CETUS = "0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS";
|
|
4
7
|
export declare const M_NAVI = "0xa99b8952d4f7d947ea77fe0ecdcc9e5fc0bcab2841d6e2a5aa00c3044e5544b5::navx::NAVX";
|
|
@@ -7,3 +10,4 @@ export declare const M_VSUI = "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2
|
|
|
7
10
|
export declare const M_VAPOR = "0xa1f2c11169f32165ad4efb4468ec5bdfc880cd66b22094024b32ab7b76d14d30::vapor::VAPOR";
|
|
8
11
|
export declare const M_HASUI = "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI";
|
|
9
12
|
export declare const M_SSWP = "0x361dd589b98e8fcda9a7ee53b85efabef3569d00416640d2faa516e3801d7ffc::TOKEN::TOKEN";
|
|
13
|
+
export declare const M_MICHI = "0x50d796fde5709a97883e29e00bf511d66f2656de958ea0c2ce4c1147cdd20a23::MICHI::MICHI";
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -33,6 +33,7 @@ export type ExtendedDetails = {
|
|
|
33
33
|
aftermathLpSupplyType?: string
|
|
34
34
|
turbosFeeType?: string
|
|
35
35
|
afterSqrtPrice?: string
|
|
36
|
+
deepbookv3DeepFee?: number
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
export type Path = {
|
|
@@ -65,6 +66,7 @@ export type RouterData = {
|
|
|
65
66
|
amountOut: BN
|
|
66
67
|
routes: Router[]
|
|
67
68
|
insufficientLiquidity: boolean
|
|
69
|
+
totalDeepFee?: number
|
|
68
70
|
error?: RouterError
|
|
69
71
|
}
|
|
70
72
|
|
|
@@ -140,7 +142,7 @@ async function getRouter(endpoint: string, params: FindRouterParams) {
|
|
|
140
142
|
const fromCoin = completionCoin(from)
|
|
141
143
|
const targetCoin = completionCoin(target)
|
|
142
144
|
|
|
143
|
-
let url = `${endpoint}?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`
|
|
145
|
+
let url = `${endpoint}/find_routes?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`
|
|
144
146
|
|
|
145
147
|
if (depth) {
|
|
146
148
|
url += `&depth=${depth}`
|
|
@@ -164,6 +166,9 @@ async function getRouter(endpoint: string, params: FindRouterParams) {
|
|
|
164
166
|
}
|
|
165
167
|
}
|
|
166
168
|
|
|
169
|
+
// set newest sdk version
|
|
170
|
+
url += "&v=1000302"
|
|
171
|
+
|
|
167
172
|
const response = await fetch(url)
|
|
168
173
|
return response
|
|
169
174
|
} catch (error) {
|
|
@@ -191,11 +196,8 @@ async function postRouterWithLiquidityChanges(
|
|
|
191
196
|
|
|
192
197
|
const fromCoin = completionCoin(from)
|
|
193
198
|
const targetCoin = completionCoin(target)
|
|
194
|
-
|
|
195
|
-
const url = `${endpoint}`
|
|
196
|
-
|
|
199
|
+
const url = `${endpoint}/find_routes`
|
|
197
200
|
const providersStr = providers?.join(",")
|
|
198
|
-
|
|
199
201
|
const requestData = {
|
|
200
202
|
from: fromCoin,
|
|
201
203
|
target: targetCoin,
|
|
@@ -214,8 +216,6 @@ async function postRouterWithLiquidityChanges(
|
|
|
214
216
|
})),
|
|
215
217
|
}
|
|
216
218
|
|
|
217
|
-
console.log("requestData", JSON.stringify(requestData, null, 2))
|
|
218
|
-
|
|
219
219
|
try {
|
|
220
220
|
const response = await fetch(url, {
|
|
221
221
|
method: "POST",
|
|
@@ -231,3 +231,36 @@ async function postRouterWithLiquidityChanges(
|
|
|
231
231
|
return null
|
|
232
232
|
}
|
|
233
233
|
}
|
|
234
|
+
|
|
235
|
+
export type DeepbookV3Config = {
|
|
236
|
+
id: string
|
|
237
|
+
is_alternative_payment: boolean
|
|
238
|
+
alternative_payment_amount: number
|
|
239
|
+
trade_cap: string
|
|
240
|
+
balance_manager: string
|
|
241
|
+
deep_fee_vault: number
|
|
242
|
+
whitelist: number
|
|
243
|
+
package_version: 0
|
|
244
|
+
// unix timestamp in seconds
|
|
245
|
+
last_updated_time: number
|
|
246
|
+
whitelist_pools: string[]
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export type DeepbookV3ConfigResponse = {
|
|
250
|
+
code: number
|
|
251
|
+
msg: string
|
|
252
|
+
data: DeepbookV3Config
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export async function getDeepbookV3Config(
|
|
256
|
+
endpoint: string
|
|
257
|
+
): Promise<DeepbookV3ConfigResponse | null> {
|
|
258
|
+
const url = `${endpoint}/deepbookv3_config`
|
|
259
|
+
try {
|
|
260
|
+
const response = await fetch(url)
|
|
261
|
+
return response.json() as Promise<DeepbookV3ConfigResponse>
|
|
262
|
+
} catch (error) {
|
|
263
|
+
console.error("Error:", error)
|
|
264
|
+
return null
|
|
265
|
+
}
|
|
266
|
+
}
|