@cetusprotocol/aggregator-sdk 0.0.0-experimental-20241010160019 → 0.0.0-experimental-20241011205228
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 +3 -25
- package/dist/index.d.ts +3 -25
- package/dist/index.js +17 -104
- package/dist/index.mjs +17 -101
- package/dist/src/api.d.ts +0 -15
- package/dist/src/client.d.ts +2 -7
- package/dist/src/transaction/index.d.ts +1 -1
- package/dist/src/utils/index.d.ts +0 -1
- package/dist/tests/test_data.test.d.ts +0 -1
- package/package.json +1 -1
- package/src/api.ts +7 -32
- package/src/client.ts +10 -44
- package/src/transaction/afsui.ts +1 -0
- package/src/transaction/aftermath.ts +2 -0
- package/src/transaction/deepbook_v2.ts +1 -0
- package/src/transaction/index.ts +1 -2
- package/src/utils/index.ts +0 -1
- package/tests/router.test.ts +26 -26
- package/tests/test_data.test.ts +0 -1
- package/dist/src/transaction/deepbook_v3.d.ts +0 -13
- package/dist/src/utils/api.d.ts +0 -1
- package/src/transaction/deepbook_v3.ts +0 -68
- package/src/utils/api.ts +0 -6
- package/test.json +0 -5
package/dist/index.mjs
CHANGED
|
@@ -5990,45 +5990,6 @@ var Bluemove = class {
|
|
|
5990
5990
|
}
|
|
5991
5991
|
};
|
|
5992
5992
|
|
|
5993
|
-
// src/transaction/deepbook_v3.ts
|
|
5994
|
-
var DeepbookV3 = class {
|
|
5995
|
-
constructor(env) {
|
|
5996
|
-
this.deepbookV3Config = env === 0 /* Mainnet */ ? "0x0" : "0xe19b5d072346cae83a037d4e3c8492068a74410a74e5830b3a68012db38296aa";
|
|
5997
|
-
this.deepCoinType = env === 0 /* Mainnet */ ? "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP" : "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP";
|
|
5998
|
-
}
|
|
5999
|
-
swap(client, txb, path, inputCoin, deepbookv3DeepFee) {
|
|
6000
|
-
return __async(this, null, function* () {
|
|
6001
|
-
var _a, _b, _c;
|
|
6002
|
-
const { direction, from, target } = path;
|
|
6003
|
-
const [func, coinAType, coinBType] = direction ? ["swap_a2b", from, target] : ["swap_b2a", target, from];
|
|
6004
|
-
let deepFee;
|
|
6005
|
-
if (deepbookv3DeepFee) {
|
|
6006
|
-
if (((_a = path.extendedDetails) == null ? void 0 : _a.deepbookv3DeepFee) && ((_b = path.extendedDetails) == null ? void 0 : _b.deepbookv3DeepFee) > 0) {
|
|
6007
|
-
const splitAmounts = [(_c = path.extendedDetails) == null ? void 0 : _c.deepbookv3DeepFee];
|
|
6008
|
-
deepFee = txb.splitCoins(deepbookv3DeepFee, splitAmounts)[0];
|
|
6009
|
-
} else {
|
|
6010
|
-
deepFee = mintZeroCoin(txb, this.deepCoinType);
|
|
6011
|
-
}
|
|
6012
|
-
} else {
|
|
6013
|
-
deepFee = mintZeroCoin(txb, this.deepCoinType);
|
|
6014
|
-
}
|
|
6015
|
-
const args = [
|
|
6016
|
-
txb.object(this.deepbookV3Config),
|
|
6017
|
-
txb.object(path.id),
|
|
6018
|
-
inputCoin,
|
|
6019
|
-
deepFee,
|
|
6020
|
-
txb.object(CLOCK_ADDRESS)
|
|
6021
|
-
];
|
|
6022
|
-
const res = txb.moveCall({
|
|
6023
|
-
target: `${client.publishedAt()}::deepbookv3::${func}`,
|
|
6024
|
-
typeArguments: [coinAType, coinBType],
|
|
6025
|
-
arguments: args
|
|
6026
|
-
});
|
|
6027
|
-
return res;
|
|
6028
|
-
});
|
|
6029
|
-
}
|
|
6030
|
-
};
|
|
6031
|
-
|
|
6032
5993
|
// src/client.ts
|
|
6033
5994
|
var CETUS = "CETUS";
|
|
6034
5995
|
var DEEPBOOKV2 = "DEEPBOOK";
|
|
@@ -6042,10 +6003,9 @@ var HAEDAL = "HAEDAL";
|
|
|
6042
6003
|
var VOLO = "VOLO";
|
|
6043
6004
|
var AFSUI = "AFSUI";
|
|
6044
6005
|
var BLUEMOVE = "BLUEMOVE";
|
|
6045
|
-
var
|
|
6046
|
-
var AggregatorClient7 = class {
|
|
6006
|
+
var AggregatorClient6 = class {
|
|
6047
6007
|
constructor(endpoint, signer, client, env) {
|
|
6048
|
-
this.endpoint =
|
|
6008
|
+
this.endpoint = endpoint;
|
|
6049
6009
|
this.client = client;
|
|
6050
6010
|
this.signer = signer;
|
|
6051
6011
|
this.env = env;
|
|
@@ -6082,7 +6042,7 @@ var AggregatorClient7 = class {
|
|
|
6082
6042
|
return getRouterResult(this.endpoint, params);
|
|
6083
6043
|
});
|
|
6084
6044
|
}
|
|
6085
|
-
expectInputSwap(txb, inputCoin, routers, amountOutLimit, partner
|
|
6045
|
+
expectInputSwap(txb, inputCoin, routers, amountOutLimit, partner) {
|
|
6086
6046
|
return __async(this, null, function* () {
|
|
6087
6047
|
if (routers.length === 0) {
|
|
6088
6048
|
throw new Error("No router found");
|
|
@@ -6099,14 +6059,11 @@ var AggregatorClient7 = class {
|
|
|
6099
6059
|
let nextCoin = inputCoins[i];
|
|
6100
6060
|
for (const path of routers[i].path) {
|
|
6101
6061
|
const dex = this.newDex(path.provider, partner);
|
|
6102
|
-
nextCoin = yield dex.swap(this, txb, path, nextCoin
|
|
6062
|
+
nextCoin = yield dex.swap(this, txb, path, nextCoin);
|
|
6103
6063
|
}
|
|
6104
6064
|
outputCoins.push(nextCoin);
|
|
6105
6065
|
}
|
|
6106
6066
|
this.transferOrDestoryCoin(txb, inputCoin, inputCoinType);
|
|
6107
|
-
if (deepbookv3DeepFee) {
|
|
6108
|
-
this.transferOrDestoryCoin(txb, deepbookv3DeepFee, this.deepbookv3DeepFeeType());
|
|
6109
|
-
}
|
|
6110
6067
|
const mergedTargetCointhis = this.checkCoinThresholdAndMergeCoin(
|
|
6111
6068
|
txb,
|
|
6112
6069
|
outputCoins,
|
|
@@ -6178,7 +6135,7 @@ var AggregatorClient7 = class {
|
|
|
6178
6135
|
}
|
|
6179
6136
|
routerSwap(params) {
|
|
6180
6137
|
return __async(this, null, function* () {
|
|
6181
|
-
const { routers, inputCoin, slippage, byAmountIn, txb, partner
|
|
6138
|
+
const { routers, inputCoin, slippage, byAmountIn, txb, partner } = params;
|
|
6182
6139
|
const amountIn = routers.reduce(
|
|
6183
6140
|
(acc, router) => acc.add(router.amountIn),
|
|
6184
6141
|
new import_bn5.default(0)
|
|
@@ -6198,8 +6155,7 @@ var AggregatorClient7 = class {
|
|
|
6198
6155
|
inputCoin,
|
|
6199
6156
|
routers,
|
|
6200
6157
|
new import_bn5.default(amountLimit),
|
|
6201
|
-
partner
|
|
6202
|
-
deepbookv3DeepFee
|
|
6158
|
+
partner
|
|
6203
6159
|
);
|
|
6204
6160
|
return targetCoin2;
|
|
6205
6161
|
}
|
|
@@ -6227,8 +6183,7 @@ var AggregatorClient7 = class {
|
|
|
6227
6183
|
txb,
|
|
6228
6184
|
partner,
|
|
6229
6185
|
isMergeTragetCoin,
|
|
6230
|
-
refreshAllCoins
|
|
6231
|
-
deepbookv3DeepFee
|
|
6186
|
+
refreshAllCoins
|
|
6232
6187
|
} = params;
|
|
6233
6188
|
if (refreshAllCoins || this.allCoins.length === 0) {
|
|
6234
6189
|
this.allCoins = yield this.getAllCoins();
|
|
@@ -6261,8 +6216,7 @@ var AggregatorClient7 = class {
|
|
|
6261
6216
|
slippage,
|
|
6262
6217
|
byAmountIn,
|
|
6263
6218
|
txb,
|
|
6264
|
-
partner
|
|
6265
|
-
deepbookv3DeepFee
|
|
6219
|
+
partner
|
|
6266
6220
|
});
|
|
6267
6221
|
if (isMergeTragetCoin) {
|
|
6268
6222
|
const targetCoinRes = buildInputCoin(
|
|
@@ -6286,16 +6240,9 @@ var AggregatorClient7 = class {
|
|
|
6286
6240
|
}
|
|
6287
6241
|
publishedAt() {
|
|
6288
6242
|
if (this.env === 0 /* Mainnet */) {
|
|
6289
|
-
return "
|
|
6290
|
-
} else {
|
|
6291
|
-
return "0xf92cdec6c2d73a12d8afa8dd41199b3e95b621272bbc655996539cd30de6a462";
|
|
6292
|
-
}
|
|
6293
|
-
}
|
|
6294
|
-
deepbookv3DeepFeeType() {
|
|
6295
|
-
if (this.env === 0 /* Mainnet */) {
|
|
6296
|
-
return "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP";
|
|
6243
|
+
return "0x7eb2f30d541c06fa7bcf26444845df56361647df0e778b82e5707fb26754c398";
|
|
6297
6244
|
} else {
|
|
6298
|
-
return "
|
|
6245
|
+
return "0x6cbaa3e9fbe902d90191b12f315932bc58079cba422bafbd4b4369f80e61f595";
|
|
6299
6246
|
}
|
|
6300
6247
|
}
|
|
6301
6248
|
transferOrDestoryCoin(txb, coin, coinType) {
|
|
@@ -6329,8 +6276,6 @@ var AggregatorClient7 = class {
|
|
|
6329
6276
|
return new Cetus(this.env, partner);
|
|
6330
6277
|
case DEEPBOOKV2:
|
|
6331
6278
|
return new DeepbookV2(this.env);
|
|
6332
|
-
case DEEPBOOKV3:
|
|
6333
|
-
return new DeepbookV3(this.env);
|
|
6334
6279
|
case KRIYA:
|
|
6335
6280
|
return new KriyaV2(this.env);
|
|
6336
6281
|
case KRIYAV3:
|
|
@@ -6388,15 +6333,6 @@ var AggregatorClient7 = class {
|
|
|
6388
6333
|
return res;
|
|
6389
6334
|
});
|
|
6390
6335
|
}
|
|
6391
|
-
getDeepbookV3Config() {
|
|
6392
|
-
return __async(this, null, function* () {
|
|
6393
|
-
const res = yield getDeepbookV3Config(this.endpoint);
|
|
6394
|
-
if (res) {
|
|
6395
|
-
return res.data;
|
|
6396
|
-
}
|
|
6397
|
-
return null;
|
|
6398
|
-
});
|
|
6399
|
-
}
|
|
6400
6336
|
};
|
|
6401
6337
|
function parseRouterResponse(data) {
|
|
6402
6338
|
return {
|
|
@@ -6406,18 +6342,17 @@ function parseRouterResponse(data) {
|
|
|
6406
6342
|
routes: data.routes.map((route) => {
|
|
6407
6343
|
return {
|
|
6408
6344
|
path: route.path.map((path) => {
|
|
6409
|
-
var _a, _b, _c
|
|
6345
|
+
var _a, _b, _c;
|
|
6410
6346
|
let version;
|
|
6411
6347
|
if (path.provider === AFTERMATH) {
|
|
6412
6348
|
version = path.extended_details.aftermath_pool_flatness === 0 ? "v2" : "v3";
|
|
6413
6349
|
}
|
|
6414
6350
|
let extendedDetails;
|
|
6415
|
-
if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS
|
|
6351
|
+
if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS) {
|
|
6416
6352
|
extendedDetails = {
|
|
6417
6353
|
aftermathLpSupplyType: (_a = path.extended_details) == null ? void 0 : _a.aftermath_lp_supply_type,
|
|
6418
6354
|
turbosFeeType: (_b = path.extended_details) == null ? void 0 : _b.turbos_fee_type,
|
|
6419
|
-
afterSqrtPrice: (_c = path.extended_details) == null ? void 0 : _c.after_sqrt_price
|
|
6420
|
-
deepbookv3DeepFee: (_d = path.extended_details) == null ? void 0 : _d.deepbookv3_deep_fee
|
|
6355
|
+
afterSqrtPrice: (_c = path.extended_details) == null ? void 0 : _c.after_sqrt_price
|
|
6421
6356
|
};
|
|
6422
6357
|
}
|
|
6423
6358
|
return {
|
|
@@ -6469,14 +6404,6 @@ var restituteMsafeFastRouterSwapParams = (data) => {
|
|
|
6469
6404
|
return result;
|
|
6470
6405
|
};
|
|
6471
6406
|
|
|
6472
|
-
// src/utils/api.ts
|
|
6473
|
-
function processEndpoint(endpoint) {
|
|
6474
|
-
if (endpoint.endsWith("/find_routes")) {
|
|
6475
|
-
return endpoint.replace("/find_routes", "");
|
|
6476
|
-
}
|
|
6477
|
-
return endpoint;
|
|
6478
|
-
}
|
|
6479
|
-
|
|
6480
6407
|
// src/api.ts
|
|
6481
6408
|
function getRouterResult(endpoint, params) {
|
|
6482
6409
|
return __async(this, null, function* () {
|
|
@@ -6539,7 +6466,7 @@ function getRouter(endpoint, params) {
|
|
|
6539
6466
|
} = params;
|
|
6540
6467
|
const fromCoin = completionCoin(from);
|
|
6541
6468
|
const targetCoin = completionCoin(target);
|
|
6542
|
-
let url = `${endpoint}
|
|
6469
|
+
let url = `${endpoint}?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`;
|
|
6543
6470
|
if (depth) {
|
|
6544
6471
|
url += `&depth=${depth}`;
|
|
6545
6472
|
}
|
|
@@ -6581,7 +6508,7 @@ function postRouterWithLiquidityChanges(endpoint, params) {
|
|
|
6581
6508
|
} = params;
|
|
6582
6509
|
const fromCoin = completionCoin(from);
|
|
6583
6510
|
const targetCoin = completionCoin(target);
|
|
6584
|
-
const url = `${endpoint}
|
|
6511
|
+
const url = `${endpoint}`;
|
|
6585
6512
|
const providersStr = providers == null ? void 0 : providers.join(",");
|
|
6586
6513
|
const requestData = {
|
|
6587
6514
|
from: fromCoin,
|
|
@@ -6600,6 +6527,7 @@ function postRouterWithLiquidityChanges(endpoint, params) {
|
|
|
6600
6527
|
delta_liquidity: change.deltaLiquidity
|
|
6601
6528
|
}))
|
|
6602
6529
|
};
|
|
6530
|
+
console.log("requestData", JSON.stringify(requestData, null, 2));
|
|
6603
6531
|
try {
|
|
6604
6532
|
const response = yield fetch(url, {
|
|
6605
6533
|
method: "POST",
|
|
@@ -6615,18 +6543,6 @@ function postRouterWithLiquidityChanges(endpoint, params) {
|
|
|
6615
6543
|
}
|
|
6616
6544
|
});
|
|
6617
6545
|
}
|
|
6618
|
-
function getDeepbookV3Config(endpoint) {
|
|
6619
|
-
return __async(this, null, function* () {
|
|
6620
|
-
const url = `${endpoint}/deepbookv3_config`;
|
|
6621
|
-
try {
|
|
6622
|
-
const response = yield fetch(url);
|
|
6623
|
-
return response.json();
|
|
6624
|
-
} catch (error) {
|
|
6625
|
-
console.error("Error:", error);
|
|
6626
|
-
return null;
|
|
6627
|
-
}
|
|
6628
|
-
});
|
|
6629
|
-
}
|
|
6630
6546
|
|
|
6631
6547
|
// src/index.ts
|
|
6632
6548
|
var Env = /* @__PURE__ */ ((Env2) => {
|
|
@@ -6646,4 +6562,4 @@ decimal.js/decimal.mjs:
|
|
|
6646
6562
|
*)
|
|
6647
6563
|
*/
|
|
6648
6564
|
|
|
6649
|
-
export { AFSUI, AFTERMATH,
|
|
6565
|
+
export { AFSUI, AFTERMATH, AggregatorClient6 as AggregatorClient, BLUEMOVE, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, Env, FLOWXV2, FLOWXV3, HAEDAL, KRIYA, KRIYAV3, ONE, 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 };
|
package/dist/src/api.d.ts
CHANGED
|
@@ -23,7 +23,6 @@ export type ExtendedDetails = {
|
|
|
23
23
|
aftermathLpSupplyType?: string;
|
|
24
24
|
turbosFeeType?: string;
|
|
25
25
|
afterSqrtPrice?: string;
|
|
26
|
-
deepbookv3DeepFee?: number;
|
|
27
26
|
};
|
|
28
27
|
export type Path = {
|
|
29
28
|
id: string;
|
|
@@ -60,17 +59,3 @@ export type AggregatorResponse = {
|
|
|
60
59
|
data: RouterData;
|
|
61
60
|
};
|
|
62
61
|
export declare function getRouterResult(endpoint: string, params: FindRouterParams): Promise<RouterData | null>;
|
|
63
|
-
export type DeepbookV3Config = {
|
|
64
|
-
id: string;
|
|
65
|
-
is_alternative_payment: boolean;
|
|
66
|
-
deep_fee_vault: number;
|
|
67
|
-
whitelist: number;
|
|
68
|
-
whitelist_pools: string[];
|
|
69
|
-
last_updated_time: number;
|
|
70
|
-
};
|
|
71
|
-
export type DeepbookV3ConfigResponse = {
|
|
72
|
-
code: number;
|
|
73
|
-
msg: string;
|
|
74
|
-
data: DeepbookV3Config;
|
|
75
|
-
};
|
|
76
|
-
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
|
|
5
|
+
import { Dex, Env, FindRouterParams, Router, RouterData } from ".";
|
|
6
6
|
import { CoinAsset } from "./types/sui";
|
|
7
7
|
export declare const CETUS = "CETUS";
|
|
8
8
|
export declare const DEEPBOOKV2 = "DEEPBOOK";
|
|
@@ -16,7 +16,6 @@ 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
19
|
export type BuildRouterSwapParams = {
|
|
21
20
|
routers: Router[];
|
|
22
21
|
byAmountIn: boolean;
|
|
@@ -24,7 +23,6 @@ export type BuildRouterSwapParams = {
|
|
|
24
23
|
slippage: number;
|
|
25
24
|
txb: Transaction;
|
|
26
25
|
partner?: string;
|
|
27
|
-
deepbookv3DeepFee?: TransactionObjectArgument;
|
|
28
26
|
};
|
|
29
27
|
export type BuildFastRouterSwapParams = {
|
|
30
28
|
routers: Router[];
|
|
@@ -34,7 +32,6 @@ export type BuildFastRouterSwapParams = {
|
|
|
34
32
|
partner?: string;
|
|
35
33
|
isMergeTragetCoin?: boolean;
|
|
36
34
|
refreshAllCoins?: boolean;
|
|
37
|
-
deepbookv3DeepFee?: TransactionObjectArgument;
|
|
38
35
|
};
|
|
39
36
|
export interface SwapInPoolsParams {
|
|
40
37
|
from: string;
|
|
@@ -56,19 +53,17 @@ export declare class AggregatorClient {
|
|
|
56
53
|
constructor(endpoint: string, signer: string, client: SuiClient, env: Env);
|
|
57
54
|
getAllCoins(): Promise<CoinAsset[]>;
|
|
58
55
|
findRouters(params: FindRouterParams): Promise<RouterData | null>;
|
|
59
|
-
expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, partner?: string
|
|
56
|
+
expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, partner?: string): Promise<TransactionObjectArgument>;
|
|
60
57
|
expectOutputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], partner?: string): Promise<TransactionObjectArgument>;
|
|
61
58
|
swapInPools(params: SwapInPoolsParams): Promise<SwapInPoolsResult | null>;
|
|
62
59
|
routerSwap(params: BuildRouterSwapParams): Promise<TransactionObjectArgument>;
|
|
63
60
|
fastRouterSwap(params: BuildFastRouterSwapParams): Promise<void>;
|
|
64
61
|
publishedAt(): string;
|
|
65
|
-
deepbookv3DeepFeeType(): string;
|
|
66
62
|
transferOrDestoryCoin(txb: Transaction, coin: TransactionObjectArgument, coinType: string): void;
|
|
67
63
|
checkCoinThresholdAndMergeCoin(txb: Transaction, coins: TransactionObjectArgument[], coinType: string, amountLimit: BN): TransactionObjectArgument;
|
|
68
64
|
newDex(provider: string, partner?: string): Dex;
|
|
69
65
|
signAndExecuteTransaction(txb: Transaction, signer: Signer): Promise<import("@mysten/sui/client").SuiTransactionBlockResponse>;
|
|
70
66
|
devInspectTransactionBlock(txb: Transaction): Promise<import("@mysten/sui/client").DevInspectResults>;
|
|
71
67
|
sendTransaction(txb: Transaction, signer: Signer): Promise<import("@mysten/sui/client").SuiTransactionBlockResponse>;
|
|
72
|
-
getDeepbookV3Config(): Promise<DeepbookV3Config | null>;
|
|
73
68
|
}
|
|
74
69
|
export declare function parseRouterResponse(data: any): RouterData;
|
|
@@ -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
|
|
5
|
+
swap(client: AggregatorClient, ptb: Transaction, path: Path, inputCoin: TransactionObjectArgument): Promise<TransactionObjectArgument>;
|
|
6
6
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export declare const T_USDC = "";
|
|
2
|
-
export declare const T_DEEP = "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP";
|
|
3
2
|
export declare const M_USDC = "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN";
|
|
4
3
|
export declare const M_CETUS = "0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS";
|
|
5
4
|
export declare const M_NAVI = "0xa99b8952d4f7d947ea77fe0ecdcc9e5fc0bcab2841d6e2a5aa00c3044e5544b5::navx::NAVX";
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -33,7 +33,6 @@ export type ExtendedDetails = {
|
|
|
33
33
|
aftermathLpSupplyType?: string
|
|
34
34
|
turbosFeeType?: string
|
|
35
35
|
afterSqrtPrice?: string
|
|
36
|
-
deepbookv3DeepFee?: number
|
|
37
36
|
}
|
|
38
37
|
|
|
39
38
|
export type Path = {
|
|
@@ -141,7 +140,7 @@ async function getRouter(endpoint: string, params: FindRouterParams) {
|
|
|
141
140
|
const fromCoin = completionCoin(from)
|
|
142
141
|
const targetCoin = completionCoin(target)
|
|
143
142
|
|
|
144
|
-
let url = `${endpoint}
|
|
143
|
+
let url = `${endpoint}?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`
|
|
145
144
|
|
|
146
145
|
if (depth) {
|
|
147
146
|
url += `&depth=${depth}`
|
|
@@ -192,8 +191,11 @@ async function postRouterWithLiquidityChanges(
|
|
|
192
191
|
|
|
193
192
|
const fromCoin = completionCoin(from)
|
|
194
193
|
const targetCoin = completionCoin(target)
|
|
195
|
-
|
|
194
|
+
|
|
195
|
+
const url = `${endpoint}`
|
|
196
|
+
|
|
196
197
|
const providersStr = providers?.join(",")
|
|
198
|
+
|
|
197
199
|
const requestData = {
|
|
198
200
|
from: fromCoin,
|
|
199
201
|
target: targetCoin,
|
|
@@ -212,6 +214,8 @@ async function postRouterWithLiquidityChanges(
|
|
|
212
214
|
})),
|
|
213
215
|
}
|
|
214
216
|
|
|
217
|
+
console.log("requestData", JSON.stringify(requestData, null, 2))
|
|
218
|
+
|
|
215
219
|
try {
|
|
216
220
|
const response = await fetch(url, {
|
|
217
221
|
method: "POST",
|
|
@@ -227,32 +231,3 @@ async function postRouterWithLiquidityChanges(
|
|
|
227
231
|
return null
|
|
228
232
|
}
|
|
229
233
|
}
|
|
230
|
-
|
|
231
|
-
export type DeepbookV3Config = {
|
|
232
|
-
id: string
|
|
233
|
-
is_alternative_payment: boolean
|
|
234
|
-
deep_fee_vault: number
|
|
235
|
-
whitelist: number
|
|
236
|
-
whitelist_pools: string[]
|
|
237
|
-
// unix timestamp in seconds
|
|
238
|
-
last_updated_time: number
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
export type DeepbookV3ConfigResponse = {
|
|
242
|
-
code: number
|
|
243
|
-
msg: string
|
|
244
|
-
data: DeepbookV3Config
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
export async function getDeepbookV3Config(
|
|
248
|
-
endpoint: string
|
|
249
|
-
): Promise<DeepbookV3ConfigResponse | null> {
|
|
250
|
-
const url = `${endpoint}/deepbookv3_config`
|
|
251
|
-
try {
|
|
252
|
-
const response = await fetch(url)
|
|
253
|
-
return response.json() as Promise<DeepbookV3ConfigResponse>
|
|
254
|
-
} catch (error) {
|
|
255
|
-
console.error("Error:", error)
|
|
256
|
-
return null
|
|
257
|
-
}
|
|
258
|
-
}
|
package/src/client.ts
CHANGED
|
@@ -15,10 +15,6 @@ import {
|
|
|
15
15
|
getRouterResult,
|
|
16
16
|
Router,
|
|
17
17
|
RouterData,
|
|
18
|
-
getDeepbookV3Config,
|
|
19
|
-
DeepbookV3ConfigResponse,
|
|
20
|
-
processEndpoint,
|
|
21
|
-
DeepbookV3Config,
|
|
22
18
|
} from "."
|
|
23
19
|
import { Aftermath } from "./transaction/aftermath"
|
|
24
20
|
import { DeepbookV2 } from "./transaction/deepbook_v2"
|
|
@@ -36,7 +32,6 @@ import { Volo } from "./transaction/volo"
|
|
|
36
32
|
import { Bluemove } from "./transaction/bluemove"
|
|
37
33
|
import { CoinAsset } from "./types/sui"
|
|
38
34
|
import { buildInputCoin } from "./utils/coin"
|
|
39
|
-
import { DeepbookV3 } from "./transaction/deepbook_v3"
|
|
40
35
|
|
|
41
36
|
export const CETUS = "CETUS"
|
|
42
37
|
export const DEEPBOOKV2 = "DEEPBOOK"
|
|
@@ -50,7 +45,6 @@ export const HAEDAL = "HAEDAL"
|
|
|
50
45
|
export const VOLO = "VOLO"
|
|
51
46
|
export const AFSUI = "AFSUI"
|
|
52
47
|
export const BLUEMOVE = "BLUEMOVE"
|
|
53
|
-
export const DEEPBOOKV3 = "DEEPBOOKV3"
|
|
54
48
|
|
|
55
49
|
export type BuildRouterSwapParams = {
|
|
56
50
|
routers: Router[]
|
|
@@ -59,7 +53,6 @@ export type BuildRouterSwapParams = {
|
|
|
59
53
|
slippage: number
|
|
60
54
|
txb: Transaction
|
|
61
55
|
partner?: string
|
|
62
|
-
deepbookv3DeepFee?: TransactionObjectArgument
|
|
63
56
|
}
|
|
64
57
|
|
|
65
58
|
export type BuildFastRouterSwapParams = {
|
|
@@ -70,7 +63,6 @@ export type BuildFastRouterSwapParams = {
|
|
|
70
63
|
partner?: string
|
|
71
64
|
isMergeTragetCoin?: boolean
|
|
72
65
|
refreshAllCoins?: boolean
|
|
73
|
-
deepbookv3DeepFee?: TransactionObjectArgument
|
|
74
66
|
}
|
|
75
67
|
|
|
76
68
|
export interface SwapInPoolsParams {
|
|
@@ -94,7 +86,7 @@ export class AggregatorClient {
|
|
|
94
86
|
private allCoins: CoinAsset[]
|
|
95
87
|
|
|
96
88
|
constructor(endpoint: string, signer: string, client: SuiClient, env: Env) {
|
|
97
|
-
this.endpoint =
|
|
89
|
+
this.endpoint = endpoint
|
|
98
90
|
this.client = client
|
|
99
91
|
this.signer = signer
|
|
100
92
|
this.env = env
|
|
@@ -135,8 +127,7 @@ export class AggregatorClient {
|
|
|
135
127
|
inputCoin: TransactionObjectArgument,
|
|
136
128
|
routers: Router[],
|
|
137
129
|
amountOutLimit: BN,
|
|
138
|
-
partner?: string
|
|
139
|
-
deepbookv3DeepFee?: TransactionObjectArgument,
|
|
130
|
+
partner?: string
|
|
140
131
|
) {
|
|
141
132
|
if (routers.length === 0) {
|
|
142
133
|
throw new Error("No router found")
|
|
@@ -153,15 +144,12 @@ export class AggregatorClient {
|
|
|
153
144
|
let nextCoin = inputCoins[i] as TransactionObjectArgument
|
|
154
145
|
for (const path of routers[i].path) {
|
|
155
146
|
const dex = this.newDex(path.provider, partner)
|
|
156
|
-
nextCoin = await dex.swap(this, txb, path, nextCoin
|
|
147
|
+
nextCoin = await dex.swap(this, txb, path, nextCoin)
|
|
157
148
|
}
|
|
158
149
|
|
|
159
150
|
outputCoins.push(nextCoin)
|
|
160
151
|
}
|
|
161
152
|
this.transferOrDestoryCoin(txb, inputCoin, inputCoinType)
|
|
162
|
-
if (deepbookv3DeepFee) {
|
|
163
|
-
this.transferOrDestoryCoin(txb, deepbookv3DeepFee, this.deepbookv3DeepFeeType())
|
|
164
|
-
}
|
|
165
153
|
const mergedTargetCointhis = this.checkCoinThresholdAndMergeCoin(
|
|
166
154
|
txb,
|
|
167
155
|
outputCoins,
|
|
@@ -241,7 +229,7 @@ export class AggregatorClient {
|
|
|
241
229
|
async routerSwap(
|
|
242
230
|
params: BuildRouterSwapParams
|
|
243
231
|
): Promise<TransactionObjectArgument> {
|
|
244
|
-
const { routers, inputCoin, slippage, byAmountIn, txb, partner
|
|
232
|
+
const { routers, inputCoin, slippage, byAmountIn, txb, partner } = params
|
|
245
233
|
const amountIn = routers.reduce(
|
|
246
234
|
(acc, router) => acc.add(router.amountIn),
|
|
247
235
|
new BN(0)
|
|
@@ -262,8 +250,7 @@ export class AggregatorClient {
|
|
|
262
250
|
inputCoin,
|
|
263
251
|
routers,
|
|
264
252
|
new BN(amountLimit),
|
|
265
|
-
partner
|
|
266
|
-
deepbookv3DeepFee
|
|
253
|
+
partner
|
|
267
254
|
)
|
|
268
255
|
return targetCoin
|
|
269
256
|
}
|
|
@@ -293,7 +280,6 @@ export class AggregatorClient {
|
|
|
293
280
|
partner,
|
|
294
281
|
isMergeTragetCoin,
|
|
295
282
|
refreshAllCoins,
|
|
296
|
-
deepbookv3DeepFee,
|
|
297
283
|
} = params
|
|
298
284
|
if (refreshAllCoins || this.allCoins.length === 0) {
|
|
299
285
|
this.allCoins = await this.getAllCoins()
|
|
@@ -327,7 +313,6 @@ export class AggregatorClient {
|
|
|
327
313
|
byAmountIn,
|
|
328
314
|
txb,
|
|
329
315
|
partner,
|
|
330
|
-
deepbookv3DeepFee,
|
|
331
316
|
})
|
|
332
317
|
|
|
333
318
|
if (isMergeTragetCoin) {
|
|
@@ -352,17 +337,10 @@ export class AggregatorClient {
|
|
|
352
337
|
|
|
353
338
|
publishedAt(): string {
|
|
354
339
|
if (this.env === Env.Mainnet) {
|
|
355
|
-
return "0x764b8132a94d35abc9dfd91b23a0757b2a717d5ecb04c03098794aa2a508db91"
|
|
340
|
+
// return "0x764b8132a94d35abc9dfd91b23a0757b2a717d5ecb04c03098794aa2a508db91"
|
|
341
|
+
return "0x7eb2f30d541c06fa7bcf26444845df56361647df0e778b82e5707fb26754c398"
|
|
356
342
|
} else {
|
|
357
|
-
return "
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
deepbookv3DeepFeeType(): string {
|
|
362
|
-
if (this.env === Env.Mainnet) {
|
|
363
|
-
return "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP"
|
|
364
|
-
} else {
|
|
365
|
-
return "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP"
|
|
343
|
+
return "0x6cbaa3e9fbe902d90191b12f315932bc58079cba422bafbd4b4369f80e61f595"
|
|
366
344
|
}
|
|
367
345
|
}
|
|
368
346
|
|
|
@@ -395,7 +373,7 @@ export class AggregatorClient {
|
|
|
395
373
|
targetCoin = coins[0]
|
|
396
374
|
}
|
|
397
375
|
|
|
398
|
-
txb.moveCall({
|
|
376
|
+
const res = txb.moveCall({
|
|
399
377
|
target: `${this.publishedAt()}::utils::check_coin_threshold`,
|
|
400
378
|
typeArguments: [coinType],
|
|
401
379
|
arguments: [targetCoin, txb.pure.u64(amountLimit.toString())],
|
|
@@ -409,8 +387,6 @@ export class AggregatorClient {
|
|
|
409
387
|
return new Cetus(this.env, partner)
|
|
410
388
|
case DEEPBOOKV2:
|
|
411
389
|
return new DeepbookV2(this.env)
|
|
412
|
-
case DEEPBOOKV3:
|
|
413
|
-
return new DeepbookV3(this.env)
|
|
414
390
|
case KRIYA:
|
|
415
391
|
return new KriyaV2(this.env)
|
|
416
392
|
case KRIYAV3:
|
|
@@ -466,14 +442,6 @@ export class AggregatorClient {
|
|
|
466
442
|
})
|
|
467
443
|
return res
|
|
468
444
|
}
|
|
469
|
-
|
|
470
|
-
async getDeepbookV3Config(): Promise<DeepbookV3Config | null> {
|
|
471
|
-
const res = await getDeepbookV3Config(this.endpoint)
|
|
472
|
-
if (res) {
|
|
473
|
-
return res.data
|
|
474
|
-
}
|
|
475
|
-
return null
|
|
476
|
-
}
|
|
477
445
|
}
|
|
478
446
|
|
|
479
447
|
export function parseRouterResponse(data: any): RouterData {
|
|
@@ -494,15 +462,13 @@ export function parseRouterResponse(data: any): RouterData {
|
|
|
494
462
|
if (
|
|
495
463
|
path.provider === TURBOS ||
|
|
496
464
|
path.provider === AFTERMATH ||
|
|
497
|
-
path.provider === CETUS
|
|
498
|
-
path.provider === DEEPBOOKV3
|
|
465
|
+
path.provider === CETUS
|
|
499
466
|
) {
|
|
500
467
|
extendedDetails = {
|
|
501
468
|
aftermathLpSupplyType:
|
|
502
469
|
path.extended_details?.aftermath_lp_supply_type,
|
|
503
470
|
turbosFeeType: path.extended_details?.turbos_fee_type,
|
|
504
471
|
afterSqrtPrice: path.extended_details?.after_sqrt_price,
|
|
505
|
-
deepbookv3DeepFee: path.extended_details?.deepbookv3_deep_fee,
|
|
506
472
|
}
|
|
507
473
|
}
|
|
508
474
|
|
package/src/transaction/afsui.ts
CHANGED
package/src/transaction/index.ts
CHANGED
|
@@ -12,7 +12,6 @@ export interface Dex {
|
|
|
12
12
|
client: AggregatorClient,
|
|
13
13
|
ptb: Transaction,
|
|
14
14
|
path: Path,
|
|
15
|
-
inputCoin: TransactionObjectArgument
|
|
16
|
-
deepbookv3DeepFee?: TransactionObjectArgument
|
|
15
|
+
inputCoin: TransactionObjectArgument
|
|
17
16
|
): Promise<TransactionObjectArgument>
|
|
18
17
|
}
|
package/src/utils/index.ts
CHANGED