@cetusprotocol/aggregator-sdk 0.3.2 → 0.3.4
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 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +51 -9
- package/dist/index.mjs +50 -9
- package/dist/src/api.d.ts +1 -0
- package/dist/src/client.d.ts +1 -0
- package/dist/src/transaction/scallop.d.ts +8 -0
- package/dist/tests/test_data.test.d.ts +3 -0
- package/package.json +1 -1
- package/src/api.ts +2 -1
- package/src/client.ts +10 -4
- package/src/transaction/cetus.ts +3 -2
- package/src/transaction/kriya_v2.ts +0 -2
- package/src/transaction/scallop.ts +62 -0
- package/tests/router.test.ts +9 -5
- package/tests/test_data.test.ts +3 -0
package/dist/index.d.mts
CHANGED
|
@@ -73,6 +73,7 @@ declare const VOLO = "VOLO";
|
|
|
73
73
|
declare const AFSUI = "AFSUI";
|
|
74
74
|
declare const BLUEMOVE = "BLUEMOVE";
|
|
75
75
|
declare const DEEPBOOKV3 = "DEEPBOOKV3";
|
|
76
|
+
declare const SCALLOP = "SCALLOP";
|
|
76
77
|
declare const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
77
78
|
type BuildRouterSwapParams = {
|
|
78
79
|
routers: Router[];
|
|
@@ -202,6 +203,7 @@ type ExtendedDetails = {
|
|
|
202
203
|
turbosFeeType?: string;
|
|
203
204
|
afterSqrtPrice?: string;
|
|
204
205
|
deepbookv3DeepFee?: number;
|
|
206
|
+
scallopScoinTreasury?: string;
|
|
205
207
|
};
|
|
206
208
|
type Path = {
|
|
207
209
|
id: string;
|
|
@@ -263,4 +265,4 @@ declare enum Env {
|
|
|
263
265
|
Testnet = 1
|
|
264
266
|
}
|
|
265
267
|
|
|
266
|
-
export { AFSUI, AFTERMATH, AggregatorClient, type AggregatorResponse, BLUEMOVE, type BuildCoinResult, type BuildFastRouterSwapParams, type BuildRouterSwapParams, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, type DeepbookV3Config, type DeepbookV3ConfigResponse, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWXV3, type FindRouterParams, HAEDAL, KRIYA, KRIYAV3, ONE, type Path, type PreSwapLpChangeParams, type Router, type RouterData, type RouterError, type SwapInPoolsParams, type SwapInPoolsResult, TEN_POW_NINE, TURBOS, TWO, U128, U64_MAX, U64_MAX_BN, VOLO, ZERO, buildInputCoin, checkInvalidSuiAddress, compareCoins, completionCoin, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, extractAddressFromType, extractStructTagFromType, fixSuiObjectId, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -73,6 +73,7 @@ declare const VOLO = "VOLO";
|
|
|
73
73
|
declare const AFSUI = "AFSUI";
|
|
74
74
|
declare const BLUEMOVE = "BLUEMOVE";
|
|
75
75
|
declare const DEEPBOOKV3 = "DEEPBOOKV3";
|
|
76
|
+
declare const SCALLOP = "SCALLOP";
|
|
76
77
|
declare const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
77
78
|
type BuildRouterSwapParams = {
|
|
78
79
|
routers: Router[];
|
|
@@ -202,6 +203,7 @@ type ExtendedDetails = {
|
|
|
202
203
|
turbosFeeType?: string;
|
|
203
204
|
afterSqrtPrice?: string;
|
|
204
205
|
deepbookv3DeepFee?: number;
|
|
206
|
+
scallopScoinTreasury?: string;
|
|
205
207
|
};
|
|
206
208
|
type Path = {
|
|
207
209
|
id: string;
|
|
@@ -263,4 +265,4 @@ declare enum Env {
|
|
|
263
265
|
Testnet = 1
|
|
264
266
|
}
|
|
265
267
|
|
|
266
|
-
export { AFSUI, AFTERMATH, AggregatorClient, type AggregatorResponse, BLUEMOVE, type BuildCoinResult, type BuildFastRouterSwapParams, type BuildRouterSwapParams, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, type DeepbookV3Config, type DeepbookV3ConfigResponse, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWXV3, type FindRouterParams, HAEDAL, KRIYA, KRIYAV3, ONE, type Path, type PreSwapLpChangeParams, type Router, type RouterData, type RouterError, type SwapInPoolsParams, type SwapInPoolsResult, TEN_POW_NINE, TURBOS, TWO, U128, U64_MAX, U64_MAX_BN, VOLO, ZERO, buildInputCoin, checkInvalidSuiAddress, compareCoins, completionCoin, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, extractAddressFromType, extractStructTagFromType, fixSuiObjectId, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -5266,7 +5266,7 @@ var Turbos = class {
|
|
|
5266
5266
|
var Cetus = class {
|
|
5267
5267
|
constructor(env, partner) {
|
|
5268
5268
|
this.globalConfig = env === 0 /* Mainnet */ ? "0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f" : "0x6f4149091a5aea0e818e7243a13adcfb403842d670b9a2089de058512620687a";
|
|
5269
|
-
this.partner =
|
|
5269
|
+
this.partner = partner != null ? partner : env === 0 /* Mainnet */ ? "0x639b5e433da31739e800cd085f356e64cae222966d0f1b11bd9dc76b322ff58b" : "0x8e0b7668a79592f70fbfb1ae0aebaf9e2019a7049783b9a4b6fe7c6ae038b528";
|
|
5270
5270
|
}
|
|
5271
5271
|
flash_swap(client, txb, path, by_amount_in) {
|
|
5272
5272
|
const { direction, from, target } = path;
|
|
@@ -6038,6 +6038,43 @@ var DeepbookV3 = class {
|
|
|
6038
6038
|
}
|
|
6039
6039
|
};
|
|
6040
6040
|
|
|
6041
|
+
// src/transaction/scallop.ts
|
|
6042
|
+
var Scallop = class {
|
|
6043
|
+
constructor(env) {
|
|
6044
|
+
if (env !== 0 /* Mainnet */) {
|
|
6045
|
+
throw new Error("Scallop only supported on mainnet");
|
|
6046
|
+
}
|
|
6047
|
+
this.version = env === 0 /* Mainnet */ ? "0x07871c4b3c847a0f674510d4978d5cf6f960452795e8ff6f189fd2088a3f6ac7" : "0x0";
|
|
6048
|
+
this.market = env === 0 /* Mainnet */ ? "0xa757975255146dc9686aa823b7838b507f315d704f428cbadad2f4ea061939d9" : "0x0";
|
|
6049
|
+
}
|
|
6050
|
+
swap(client, txb, path, inputCoin) {
|
|
6051
|
+
return __async(this, null, function* () {
|
|
6052
|
+
const { direction, from, target } = path;
|
|
6053
|
+
const [func, coinAType, coinBType] = direction ? ["swap_a2b", from, target] : ["swap_b2a", from, target];
|
|
6054
|
+
if (path.extendedDetails == null) {
|
|
6055
|
+
throw new Error("Extended details not supported");
|
|
6056
|
+
} else {
|
|
6057
|
+
if (path.extendedDetails.scallopScoinTreasury == null) {
|
|
6058
|
+
throw new Error("Scallop coin treasury not supported");
|
|
6059
|
+
}
|
|
6060
|
+
}
|
|
6061
|
+
const args = [
|
|
6062
|
+
txb.object(this.version),
|
|
6063
|
+
txb.object(this.market),
|
|
6064
|
+
txb.object(path.extendedDetails.scallopScoinTreasury),
|
|
6065
|
+
inputCoin,
|
|
6066
|
+
txb.object(CLOCK_ADDRESS)
|
|
6067
|
+
];
|
|
6068
|
+
const res = txb.moveCall({
|
|
6069
|
+
target: `${client.publishedAtV2()}::scallop::${func}`,
|
|
6070
|
+
typeArguments: [coinAType, coinBType],
|
|
6071
|
+
arguments: args
|
|
6072
|
+
});
|
|
6073
|
+
return res;
|
|
6074
|
+
});
|
|
6075
|
+
}
|
|
6076
|
+
};
|
|
6077
|
+
|
|
6041
6078
|
// src/client.ts
|
|
6042
6079
|
var CETUS = "CETUS";
|
|
6043
6080
|
var DEEPBOOKV2 = "DEEPBOOK";
|
|
@@ -6052,8 +6089,9 @@ var VOLO = "VOLO";
|
|
|
6052
6089
|
var AFSUI = "AFSUI";
|
|
6053
6090
|
var BLUEMOVE = "BLUEMOVE";
|
|
6054
6091
|
var DEEPBOOKV3 = "DEEPBOOKV3";
|
|
6092
|
+
var SCALLOP = "SCALLOP";
|
|
6055
6093
|
var DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
6056
|
-
var
|
|
6094
|
+
var AggregatorClient8 = class {
|
|
6057
6095
|
constructor(endpoint, signer, client$1, env) {
|
|
6058
6096
|
this.endpoint = endpoint ? processEndpoint(endpoint) : DEFAULT_ENDPOINT;
|
|
6059
6097
|
this.client = client$1 || new client.SuiClient({ url: client.getFullnodeUrl("mainnet") });
|
|
@@ -6311,10 +6349,10 @@ var AggregatorClient7 = class {
|
|
|
6311
6349
|
return "0x0ed287d6c3fe4962d0994ffddc1d19a15fba6a81533f3f0dcc2bbcedebce0637";
|
|
6312
6350
|
}
|
|
6313
6351
|
}
|
|
6314
|
-
// Include deepbookv3
|
|
6352
|
+
// Include deepbookv3, scallop
|
|
6315
6353
|
publishedAtV2() {
|
|
6316
6354
|
if (this.env === 0 /* Mainnet */) {
|
|
6317
|
-
return "
|
|
6355
|
+
return "0xd7fb78f3d8db2d5122d61b001e0692e83a215855177e5c1dc2b32c3d6fffbbbc";
|
|
6318
6356
|
} else {
|
|
6319
6357
|
return "0x0ed287d6c3fe4962d0994ffddc1d19a15fba6a81533f3f0dcc2bbcedebce0637";
|
|
6320
6358
|
}
|
|
@@ -6379,6 +6417,8 @@ var AggregatorClient7 = class {
|
|
|
6379
6417
|
return new Volo(this.env);
|
|
6380
6418
|
case BLUEMOVE:
|
|
6381
6419
|
return new Bluemove(this.env);
|
|
6420
|
+
case SCALLOP:
|
|
6421
|
+
return new Scallop(this.env);
|
|
6382
6422
|
default:
|
|
6383
6423
|
throw new Error(`Unsupported dex ${provider}`);
|
|
6384
6424
|
}
|
|
@@ -6442,18 +6482,19 @@ function parseRouterResponse(data) {
|
|
|
6442
6482
|
routes: data.routes.map((route) => {
|
|
6443
6483
|
return {
|
|
6444
6484
|
path: route.path.map((path) => {
|
|
6445
|
-
var _a, _b, _c, _d;
|
|
6485
|
+
var _a, _b, _c, _d, _e;
|
|
6446
6486
|
let version;
|
|
6447
6487
|
if (path.provider === AFTERMATH) {
|
|
6448
6488
|
version = path.extended_details.aftermath_pool_flatness === 0 ? "v2" : "v3";
|
|
6449
6489
|
}
|
|
6450
6490
|
let extendedDetails;
|
|
6451
|
-
if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS || path.provider === DEEPBOOKV3) {
|
|
6491
|
+
if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS || path.provider === DEEPBOOKV3 || path.provider === SCALLOP) {
|
|
6452
6492
|
extendedDetails = {
|
|
6453
6493
|
aftermathLpSupplyType: (_a = path.extended_details) == null ? void 0 : _a.aftermath_lp_supply_type,
|
|
6454
6494
|
turbosFeeType: (_b = path.extended_details) == null ? void 0 : _b.turbos_fee_type,
|
|
6455
6495
|
afterSqrtPrice: (_c = path.extended_details) == null ? void 0 : _c.after_sqrt_price,
|
|
6456
|
-
deepbookv3DeepFee: (_d = path.extended_details) == null ? void 0 : _d.deepbookv3_deep_fee
|
|
6496
|
+
deepbookv3DeepFee: (_d = path.extended_details) == null ? void 0 : _d.deepbookv3_deep_fee,
|
|
6497
|
+
scallopScoinTreasury: (_e = path.extended_details) == null ? void 0 : _e.scallop_scoin_treasury
|
|
6457
6498
|
};
|
|
6458
6499
|
}
|
|
6459
6500
|
return {
|
|
@@ -6595,7 +6636,7 @@ function getRouter(endpoint, params) {
|
|
|
6595
6636
|
url += `&providers=${providers.join(",")}`;
|
|
6596
6637
|
}
|
|
6597
6638
|
}
|
|
6598
|
-
url += "&v=
|
|
6639
|
+
url += "&v=1000304";
|
|
6599
6640
|
const response = yield fetch(url);
|
|
6600
6641
|
return response;
|
|
6601
6642
|
} catch (error) {
|
|
@@ -6687,7 +6728,7 @@ decimal.js/decimal.mjs:
|
|
|
6687
6728
|
|
|
6688
6729
|
exports.AFSUI = AFSUI;
|
|
6689
6730
|
exports.AFTERMATH = AFTERMATH;
|
|
6690
|
-
exports.AggregatorClient =
|
|
6731
|
+
exports.AggregatorClient = AggregatorClient8;
|
|
6691
6732
|
exports.BLUEMOVE = BLUEMOVE;
|
|
6692
6733
|
exports.CETUS = CETUS;
|
|
6693
6734
|
exports.CLOCK_ADDRESS = CLOCK_ADDRESS;
|
|
@@ -6701,6 +6742,7 @@ exports.HAEDAL = HAEDAL;
|
|
|
6701
6742
|
exports.KRIYA = KRIYA;
|
|
6702
6743
|
exports.KRIYAV3 = KRIYAV3;
|
|
6703
6744
|
exports.ONE = ONE;
|
|
6745
|
+
exports.SCALLOP = SCALLOP;
|
|
6704
6746
|
exports.TEN_POW_NINE = TEN_POW_NINE;
|
|
6705
6747
|
exports.TURBOS = TURBOS;
|
|
6706
6748
|
exports.TWO = TWO;
|
package/dist/index.mjs
CHANGED
|
@@ -5264,7 +5264,7 @@ var Turbos = class {
|
|
|
5264
5264
|
var Cetus = class {
|
|
5265
5265
|
constructor(env, partner) {
|
|
5266
5266
|
this.globalConfig = env === 0 /* Mainnet */ ? "0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f" : "0x6f4149091a5aea0e818e7243a13adcfb403842d670b9a2089de058512620687a";
|
|
5267
|
-
this.partner =
|
|
5267
|
+
this.partner = partner != null ? partner : env === 0 /* Mainnet */ ? "0x639b5e433da31739e800cd085f356e64cae222966d0f1b11bd9dc76b322ff58b" : "0x8e0b7668a79592f70fbfb1ae0aebaf9e2019a7049783b9a4b6fe7c6ae038b528";
|
|
5268
5268
|
}
|
|
5269
5269
|
flash_swap(client, txb, path, by_amount_in) {
|
|
5270
5270
|
const { direction, from, target } = path;
|
|
@@ -6036,6 +6036,43 @@ var DeepbookV3 = class {
|
|
|
6036
6036
|
}
|
|
6037
6037
|
};
|
|
6038
6038
|
|
|
6039
|
+
// src/transaction/scallop.ts
|
|
6040
|
+
var Scallop = class {
|
|
6041
|
+
constructor(env) {
|
|
6042
|
+
if (env !== 0 /* Mainnet */) {
|
|
6043
|
+
throw new Error("Scallop only supported on mainnet");
|
|
6044
|
+
}
|
|
6045
|
+
this.version = env === 0 /* Mainnet */ ? "0x07871c4b3c847a0f674510d4978d5cf6f960452795e8ff6f189fd2088a3f6ac7" : "0x0";
|
|
6046
|
+
this.market = env === 0 /* Mainnet */ ? "0xa757975255146dc9686aa823b7838b507f315d704f428cbadad2f4ea061939d9" : "0x0";
|
|
6047
|
+
}
|
|
6048
|
+
swap(client, txb, path, inputCoin) {
|
|
6049
|
+
return __async(this, null, function* () {
|
|
6050
|
+
const { direction, from, target } = path;
|
|
6051
|
+
const [func, coinAType, coinBType] = direction ? ["swap_a2b", from, target] : ["swap_b2a", from, target];
|
|
6052
|
+
if (path.extendedDetails == null) {
|
|
6053
|
+
throw new Error("Extended details not supported");
|
|
6054
|
+
} else {
|
|
6055
|
+
if (path.extendedDetails.scallopScoinTreasury == null) {
|
|
6056
|
+
throw new Error("Scallop coin treasury not supported");
|
|
6057
|
+
}
|
|
6058
|
+
}
|
|
6059
|
+
const args = [
|
|
6060
|
+
txb.object(this.version),
|
|
6061
|
+
txb.object(this.market),
|
|
6062
|
+
txb.object(path.extendedDetails.scallopScoinTreasury),
|
|
6063
|
+
inputCoin,
|
|
6064
|
+
txb.object(CLOCK_ADDRESS)
|
|
6065
|
+
];
|
|
6066
|
+
const res = txb.moveCall({
|
|
6067
|
+
target: `${client.publishedAtV2()}::scallop::${func}`,
|
|
6068
|
+
typeArguments: [coinAType, coinBType],
|
|
6069
|
+
arguments: args
|
|
6070
|
+
});
|
|
6071
|
+
return res;
|
|
6072
|
+
});
|
|
6073
|
+
}
|
|
6074
|
+
};
|
|
6075
|
+
|
|
6039
6076
|
// src/client.ts
|
|
6040
6077
|
var CETUS = "CETUS";
|
|
6041
6078
|
var DEEPBOOKV2 = "DEEPBOOK";
|
|
@@ -6050,8 +6087,9 @@ var VOLO = "VOLO";
|
|
|
6050
6087
|
var AFSUI = "AFSUI";
|
|
6051
6088
|
var BLUEMOVE = "BLUEMOVE";
|
|
6052
6089
|
var DEEPBOOKV3 = "DEEPBOOKV3";
|
|
6090
|
+
var SCALLOP = "SCALLOP";
|
|
6053
6091
|
var DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
6054
|
-
var
|
|
6092
|
+
var AggregatorClient8 = class {
|
|
6055
6093
|
constructor(endpoint, signer, client, env) {
|
|
6056
6094
|
this.endpoint = endpoint ? processEndpoint(endpoint) : DEFAULT_ENDPOINT;
|
|
6057
6095
|
this.client = client || new SuiClient({ url: getFullnodeUrl("mainnet") });
|
|
@@ -6309,10 +6347,10 @@ var AggregatorClient7 = class {
|
|
|
6309
6347
|
return "0x0ed287d6c3fe4962d0994ffddc1d19a15fba6a81533f3f0dcc2bbcedebce0637";
|
|
6310
6348
|
}
|
|
6311
6349
|
}
|
|
6312
|
-
// Include deepbookv3
|
|
6350
|
+
// Include deepbookv3, scallop
|
|
6313
6351
|
publishedAtV2() {
|
|
6314
6352
|
if (this.env === 0 /* Mainnet */) {
|
|
6315
|
-
return "
|
|
6353
|
+
return "0xd7fb78f3d8db2d5122d61b001e0692e83a215855177e5c1dc2b32c3d6fffbbbc";
|
|
6316
6354
|
} else {
|
|
6317
6355
|
return "0x0ed287d6c3fe4962d0994ffddc1d19a15fba6a81533f3f0dcc2bbcedebce0637";
|
|
6318
6356
|
}
|
|
@@ -6377,6 +6415,8 @@ var AggregatorClient7 = class {
|
|
|
6377
6415
|
return new Volo(this.env);
|
|
6378
6416
|
case BLUEMOVE:
|
|
6379
6417
|
return new Bluemove(this.env);
|
|
6418
|
+
case SCALLOP:
|
|
6419
|
+
return new Scallop(this.env);
|
|
6380
6420
|
default:
|
|
6381
6421
|
throw new Error(`Unsupported dex ${provider}`);
|
|
6382
6422
|
}
|
|
@@ -6440,18 +6480,19 @@ function parseRouterResponse(data) {
|
|
|
6440
6480
|
routes: data.routes.map((route) => {
|
|
6441
6481
|
return {
|
|
6442
6482
|
path: route.path.map((path) => {
|
|
6443
|
-
var _a, _b, _c, _d;
|
|
6483
|
+
var _a, _b, _c, _d, _e;
|
|
6444
6484
|
let version;
|
|
6445
6485
|
if (path.provider === AFTERMATH) {
|
|
6446
6486
|
version = path.extended_details.aftermath_pool_flatness === 0 ? "v2" : "v3";
|
|
6447
6487
|
}
|
|
6448
6488
|
let extendedDetails;
|
|
6449
|
-
if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS || path.provider === DEEPBOOKV3) {
|
|
6489
|
+
if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS || path.provider === DEEPBOOKV3 || path.provider === SCALLOP) {
|
|
6450
6490
|
extendedDetails = {
|
|
6451
6491
|
aftermathLpSupplyType: (_a = path.extended_details) == null ? void 0 : _a.aftermath_lp_supply_type,
|
|
6452
6492
|
turbosFeeType: (_b = path.extended_details) == null ? void 0 : _b.turbos_fee_type,
|
|
6453
6493
|
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
|
|
6494
|
+
deepbookv3DeepFee: (_d = path.extended_details) == null ? void 0 : _d.deepbookv3_deep_fee,
|
|
6495
|
+
scallopScoinTreasury: (_e = path.extended_details) == null ? void 0 : _e.scallop_scoin_treasury
|
|
6455
6496
|
};
|
|
6456
6497
|
}
|
|
6457
6498
|
return {
|
|
@@ -6593,7 +6634,7 @@ function getRouter(endpoint, params) {
|
|
|
6593
6634
|
url += `&providers=${providers.join(",")}`;
|
|
6594
6635
|
}
|
|
6595
6636
|
}
|
|
6596
|
-
url += "&v=
|
|
6637
|
+
url += "&v=1000304";
|
|
6597
6638
|
const response = yield fetch(url);
|
|
6598
6639
|
return response;
|
|
6599
6640
|
} catch (error) {
|
|
@@ -6683,4 +6724,4 @@ decimal.js/decimal.mjs:
|
|
|
6683
6724
|
*)
|
|
6684
6725
|
*/
|
|
6685
6726
|
|
|
6686
|
-
export { AFSUI, AFTERMATH,
|
|
6727
|
+
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 };
|
package/dist/src/api.d.ts
CHANGED
package/dist/src/client.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare const VOLO = "VOLO";
|
|
|
17
17
|
export declare const AFSUI = "AFSUI";
|
|
18
18
|
export declare const BLUEMOVE = "BLUEMOVE";
|
|
19
19
|
export declare const DEEPBOOKV3 = "DEEPBOOKV3";
|
|
20
|
+
export declare const SCALLOP = "SCALLOP";
|
|
20
21
|
export declare const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
21
22
|
export type BuildRouterSwapParams = {
|
|
22
23
|
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 Scallop implements Dex {
|
|
4
|
+
private version;
|
|
5
|
+
private market;
|
|
6
|
+
constructor(env: Env);
|
|
7
|
+
swap(client: AggregatorClient, txb: Transaction, path: Path, inputCoin: TransactionObjectArgument): Promise<TransactionObjectArgument>;
|
|
8
|
+
}
|
|
@@ -11,3 +11,6 @@ export declare const M_VAPOR = "0xa1f2c11169f32165ad4efb4468ec5bdfc880cd66b22094
|
|
|
11
11
|
export declare const M_HASUI = "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI";
|
|
12
12
|
export declare const M_SSWP = "0x361dd589b98e8fcda9a7ee53b85efabef3569d00416640d2faa516e3801d7ffc::TOKEN::TOKEN";
|
|
13
13
|
export declare const M_MICHI = "0x50d796fde5709a97883e29e00bf511d66f2656de958ea0c2ce4c1147cdd20a23::MICHI::MICHI";
|
|
14
|
+
export declare const M_SSUI = "0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI";
|
|
15
|
+
export declare const M_SHaSUI = "0x9a2376943f7d22f88087c259c5889925f332ca4347e669dc37d54c2bf651af3c::scallop_ha_sui::SCALLOP_HA_SUI";
|
|
16
|
+
export declare const M_ETH = "0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH";
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -34,6 +34,7 @@ export type ExtendedDetails = {
|
|
|
34
34
|
turbosFeeType?: string
|
|
35
35
|
afterSqrtPrice?: string
|
|
36
36
|
deepbookv3DeepFee?: number
|
|
37
|
+
scallopScoinTreasury?: string
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
export type Path = {
|
|
@@ -167,7 +168,7 @@ async function getRouter(endpoint: string, params: FindRouterParams) {
|
|
|
167
168
|
}
|
|
168
169
|
|
|
169
170
|
// set newest sdk version
|
|
170
|
-
url += "&v=
|
|
171
|
+
url += "&v=1000304"
|
|
171
172
|
|
|
172
173
|
const response = await fetch(url)
|
|
173
174
|
return response
|
package/src/client.ts
CHANGED
|
@@ -36,7 +36,7 @@ import { Bluemove } from "./transaction/bluemove"
|
|
|
36
36
|
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
40
|
export const CETUS = "CETUS"
|
|
41
41
|
export const DEEPBOOKV2 = "DEEPBOOK"
|
|
42
42
|
export const KRIYA = "KRIYA"
|
|
@@ -50,6 +50,7 @@ export const VOLO = "VOLO"
|
|
|
50
50
|
export const AFSUI = "AFSUI"
|
|
51
51
|
export const BLUEMOVE = "BLUEMOVE"
|
|
52
52
|
export const DEEPBOOKV3 = "DEEPBOOKV3"
|
|
53
|
+
export const SCALLOP = "SCALLOP"
|
|
53
54
|
|
|
54
55
|
export const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2"
|
|
55
56
|
|
|
@@ -374,10 +375,11 @@ export class AggregatorClient {
|
|
|
374
375
|
}
|
|
375
376
|
}
|
|
376
377
|
|
|
377
|
-
// Include deepbookv3
|
|
378
|
+
// Include deepbookv3, scallop
|
|
378
379
|
publishedAtV2(): string {
|
|
379
380
|
if (this.env === Env.Mainnet) {
|
|
380
|
-
return "0x43811be4677f5a5de7bf2dac740c10abddfaa524aee6b18e910eeadda8a2f6ae" // version 1
|
|
381
|
+
// return "0x43811be4677f5a5de7bf2dac740c10abddfaa524aee6b18e910eeadda8a2f6ae" // version 1, deepbookv3
|
|
382
|
+
return "0xd7fb78f3d8db2d5122d61b001e0692e83a215855177e5c1dc2b32c3d6fffbbbc" // version 2, deepbookv3 & scallop
|
|
381
383
|
} else {
|
|
382
384
|
return "0x0ed287d6c3fe4962d0994ffddc1d19a15fba6a81533f3f0dcc2bbcedebce0637"
|
|
383
385
|
}
|
|
@@ -456,6 +458,8 @@ export class AggregatorClient {
|
|
|
456
458
|
return new Volo(this.env)
|
|
457
459
|
case BLUEMOVE:
|
|
458
460
|
return new Bluemove(this.env)
|
|
461
|
+
case SCALLOP:
|
|
462
|
+
return new Scallop(this.env)
|
|
459
463
|
default:
|
|
460
464
|
throw new Error(`Unsupported dex ${provider}`)
|
|
461
465
|
}
|
|
@@ -529,7 +533,8 @@ export function parseRouterResponse(data: any): RouterData {
|
|
|
529
533
|
path.provider === TURBOS ||
|
|
530
534
|
path.provider === AFTERMATH ||
|
|
531
535
|
path.provider === CETUS ||
|
|
532
|
-
path.provider === DEEPBOOKV3
|
|
536
|
+
path.provider === DEEPBOOKV3 ||
|
|
537
|
+
path.provider === SCALLOP
|
|
533
538
|
) {
|
|
534
539
|
extendedDetails = {
|
|
535
540
|
aftermathLpSupplyType:
|
|
@@ -537,6 +542,7 @@ export function parseRouterResponse(data: any): RouterData {
|
|
|
537
542
|
turbosFeeType: path.extended_details?.turbos_fee_type,
|
|
538
543
|
afterSqrtPrice: path.extended_details?.after_sqrt_price,
|
|
539
544
|
deepbookv3DeepFee: path.extended_details?.deepbookv3_deep_fee,
|
|
545
|
+
scallopScoinTreasury: path.extended_details?.scallop_scoin_treasury,
|
|
540
546
|
}
|
|
541
547
|
}
|
|
542
548
|
|
package/src/transaction/cetus.ts
CHANGED
|
@@ -22,9 +22,10 @@ export class Cetus implements Dex {
|
|
|
22
22
|
: "0x6f4149091a5aea0e818e7243a13adcfb403842d670b9a2089de058512620687a"
|
|
23
23
|
|
|
24
24
|
this.partner =
|
|
25
|
-
partner ??
|
|
25
|
+
partner ??
|
|
26
|
+
(env === Env.Mainnet
|
|
26
27
|
? "0x639b5e433da31739e800cd085f356e64cae222966d0f1b11bd9dc76b322ff58b"
|
|
27
|
-
: "0x8e0b7668a79592f70fbfb1ae0aebaf9e2019a7049783b9a4b6fe7c6ae038b528"
|
|
28
|
+
: "0x8e0b7668a79592f70fbfb1ae0aebaf9e2019a7049783b9a4b6fe7c6ae038b528")
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
flash_swap(
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Transaction,
|
|
3
|
+
TransactionObjectArgument,
|
|
4
|
+
} from "@mysten/sui/transactions"
|
|
5
|
+
import { AggregatorClient, CLOCK_ADDRESS, Dex, Env, Path } from ".."
|
|
6
|
+
|
|
7
|
+
export class Scallop implements Dex {
|
|
8
|
+
private version: string
|
|
9
|
+
private market: string
|
|
10
|
+
|
|
11
|
+
constructor(env: Env) {
|
|
12
|
+
if (env !== Env.Mainnet) {
|
|
13
|
+
throw new Error("Scallop only supported on mainnet")
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
this.version = env === Env.Mainnet
|
|
17
|
+
? "0x07871c4b3c847a0f674510d4978d5cf6f960452795e8ff6f189fd2088a3f6ac7"
|
|
18
|
+
: "0x0"
|
|
19
|
+
|
|
20
|
+
this.market =
|
|
21
|
+
env === Env.Mainnet
|
|
22
|
+
? "0xa757975255146dc9686aa823b7838b507f315d704f428cbadad2f4ea061939d9"
|
|
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, coinAType, coinBType] = direction
|
|
35
|
+
? ["swap_a2b", from, target]
|
|
36
|
+
: ["swap_b2a", from, target]
|
|
37
|
+
|
|
38
|
+
if (path.extendedDetails == null) {
|
|
39
|
+
throw new Error("Extended details not supported")
|
|
40
|
+
} else {
|
|
41
|
+
if (path.extendedDetails.scallopScoinTreasury == null) {
|
|
42
|
+
throw new Error("Scallop coin treasury not supported")
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const args = [
|
|
47
|
+
txb.object(this.version),
|
|
48
|
+
txb.object(this.market),
|
|
49
|
+
txb.object(path.extendedDetails.scallopScoinTreasury),
|
|
50
|
+
inputCoin,
|
|
51
|
+
txb.object(CLOCK_ADDRESS),
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
const res = txb.moveCall({
|
|
55
|
+
target: `${client.publishedAtV2()}::scallop::${func}`,
|
|
56
|
+
typeArguments: [coinAType, coinBType],
|
|
57
|
+
arguments: args,
|
|
58
|
+
}) as TransactionObjectArgument
|
|
59
|
+
|
|
60
|
+
return res
|
|
61
|
+
}
|
|
62
|
+
}
|
package/tests/router.test.ts
CHANGED
|
@@ -3,9 +3,12 @@ import dotenv from "dotenv"
|
|
|
3
3
|
import { AggregatorClient } from "~/client"
|
|
4
4
|
import {
|
|
5
5
|
M_CETUS,
|
|
6
|
+
M_ETH,
|
|
6
7
|
M_HASUI,
|
|
7
8
|
M_MICHI,
|
|
8
9
|
M_NAVI,
|
|
10
|
+
M_SHaSUI,
|
|
11
|
+
M_SSUI,
|
|
9
12
|
M_SSWP,
|
|
10
13
|
M_SUI,
|
|
11
14
|
M_USDC,
|
|
@@ -51,7 +54,7 @@ describe("router module", () => {
|
|
|
51
54
|
// const wallet =
|
|
52
55
|
// "0x2a6174f94a2c1d648de290297be27867527a6aaa263a4e0a567c9cd7656d3651"
|
|
53
56
|
const wallet =
|
|
54
|
-
"
|
|
57
|
+
"0xca171941521153181ff729d53489eaae7e99c3f4692884afd7cca61154e4cec4"
|
|
55
58
|
// const wallet =
|
|
56
59
|
// "0xaabf2fedcb36146db164bec930b74a47969c4df98216e049342a3c49b6d11580"
|
|
57
60
|
// const wallet = "0x410456cfc689666936b6bf80fbec958b69499b9f7183ecba07de577c17248a44"
|
|
@@ -66,7 +69,7 @@ describe("router module", () => {
|
|
|
66
69
|
const suiClient = new SuiClient({
|
|
67
70
|
url: "https://cetus-mainnet-rpc.blockvision.org:443/2R8NDfQ1v3UAqVAY8PwWQdB4FIb",
|
|
68
71
|
})
|
|
69
|
-
client = new AggregatorClient(endpoint, wallet, suiClient, Env.
|
|
72
|
+
client = new AggregatorClient(endpoint, wallet, suiClient, Env.Mainnet)
|
|
70
73
|
})
|
|
71
74
|
|
|
72
75
|
test("Get all coins", () => {
|
|
@@ -129,9 +132,9 @@ describe("router module", () => {
|
|
|
129
132
|
|
|
130
133
|
test("Build router tx", async () => {
|
|
131
134
|
const byAmountIn = true
|
|
132
|
-
const amount = "
|
|
133
|
-
const target =
|
|
134
|
-
const from =
|
|
135
|
+
const amount = "18294510"
|
|
136
|
+
const target = M_ETH
|
|
137
|
+
const from = M_SHaSUI
|
|
135
138
|
|
|
136
139
|
const res = await client.findRouters({
|
|
137
140
|
from,
|
|
@@ -140,6 +143,7 @@ describe("router module", () => {
|
|
|
140
143
|
byAmountIn,
|
|
141
144
|
depth: 3,
|
|
142
145
|
providers: [
|
|
146
|
+
"SCALLOP",
|
|
143
147
|
"CETUS",
|
|
144
148
|
// "DEEPBOOKV3",
|
|
145
149
|
// "DEEPBOOK",
|
package/tests/test_data.test.ts
CHANGED
|
@@ -21,3 +21,6 @@ export const M_HASUI =
|
|
|
21
21
|
export const M_SSWP =
|
|
22
22
|
"0x361dd589b98e8fcda9a7ee53b85efabef3569d00416640d2faa516e3801d7ffc::TOKEN::TOKEN"
|
|
23
23
|
export const M_MICHI = "0x50d796fde5709a97883e29e00bf511d66f2656de958ea0c2ce4c1147cdd20a23::MICHI::MICHI"
|
|
24
|
+
export const M_SSUI = "0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI"
|
|
25
|
+
export const M_SHaSUI = "0x9a2376943f7d22f88087c259c5889925f332ca4347e669dc37d54c2bf651af3c::scallop_ha_sui::SCALLOP_HA_SUI"
|
|
26
|
+
export const M_ETH = "0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH"
|