@cetusprotocol/aggregator-sdk 0.3.19 → 0.3.21
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.js +27 -20
- package/dist/index.mjs +27 -20
- package/package.json +1 -1
- package/src/api.ts +1 -1
- package/src/client.ts +3 -2
- package/src/transaction/haedal.ts +1 -4
- package/src/utils/msafe.ts +27 -18
- package/tests/router.test.ts +4 -4
package/dist/index.js
CHANGED
|
@@ -5936,10 +5936,7 @@ var Haedal = class {
|
|
|
5936
5936
|
swap(client, txb, path, inputCoin, packages) {
|
|
5937
5937
|
return __async(this, null, function* () {
|
|
5938
5938
|
const { direction } = path;
|
|
5939
|
-
|
|
5940
|
-
throw new Error("Haedal not support b2a swap");
|
|
5941
|
-
}
|
|
5942
|
-
const func = "swap_a2b";
|
|
5939
|
+
const func = direction ? "swap_a2b" : "swap_b2a";
|
|
5943
5940
|
const args = [txb.object(path.id), txb.object("0x5"), inputCoin];
|
|
5944
5941
|
const publishedAt = getAggregatorV2PublishedAt(client.publishedAtV2(), packages);
|
|
5945
5942
|
const res = txb.moveCall({
|
|
@@ -6567,7 +6564,7 @@ var AggregatorClient19 = class {
|
|
|
6567
6564
|
// Include cetus、deepbookv2、flowxv2 & v3、kriyav2 & v3、turbos、aftermath、haedal、afsui、volo、bluemove
|
|
6568
6565
|
publishedAtV2() {
|
|
6569
6566
|
if (this.env === 0 /* Mainnet */) {
|
|
6570
|
-
return "
|
|
6567
|
+
return "0xf9c6f78322ed667909e05f6b42b2f5a67af6297503c905335e02a15148e9440d";
|
|
6571
6568
|
} else {
|
|
6572
6569
|
return "0x52eae33adeb44de55cfb3f281d4cc9e02d976181c0952f5323648b5717b33934";
|
|
6573
6570
|
}
|
|
@@ -6786,24 +6783,34 @@ function getAggregatorV2ExtendPublishedAt(aggregatorV2ExtendPublishedAt, package
|
|
|
6786
6783
|
// src/utils/msafe.ts
|
|
6787
6784
|
var import_bn6 = __toESM(require_bn());
|
|
6788
6785
|
var dealWithFastRouterSwapParamsForMsafe = (data) => {
|
|
6789
|
-
|
|
6790
|
-
|
|
6791
|
-
|
|
6792
|
-
|
|
6793
|
-
|
|
6794
|
-
|
|
6795
|
-
|
|
6786
|
+
var _a, _b, _c;
|
|
6787
|
+
const result = __spreadProps(__spreadValues({}, data), {
|
|
6788
|
+
amountIn: (_a = data == null ? void 0 : data.amountIn) == null ? void 0 : _a.toString(),
|
|
6789
|
+
amountOut: (_b = data == null ? void 0 : data.amountIn) == null ? void 0 : _b.toString(),
|
|
6790
|
+
routes: (_c = data == null ? void 0 : data.routes) == null ? void 0 : _c.map((item) => {
|
|
6791
|
+
var _a2, _b2, _c2;
|
|
6792
|
+
return __spreadProps(__spreadValues({}, item), {
|
|
6793
|
+
amountIn: (_a2 = item == null ? void 0 : item.amountIn) == null ? void 0 : _a2.toString(),
|
|
6794
|
+
amountOut: (_b2 = item == null ? void 0 : item.amountOut) == null ? void 0 : _b2.toString(),
|
|
6795
|
+
initialPrice: (_c2 = item == null ? void 0 : item.initialPrice) == null ? void 0 : _c2.toString()
|
|
6796
|
+
});
|
|
6797
|
+
})
|
|
6796
6798
|
});
|
|
6797
6799
|
return result;
|
|
6798
6800
|
};
|
|
6799
6801
|
var restituteMsafeFastRouterSwapParams = (data) => {
|
|
6800
|
-
|
|
6801
|
-
|
|
6802
|
-
|
|
6803
|
-
|
|
6804
|
-
|
|
6805
|
-
|
|
6806
|
-
|
|
6802
|
+
var _a;
|
|
6803
|
+
const result = __spreadProps(__spreadValues({}, data), {
|
|
6804
|
+
amountIn: new import_bn6.default(data == null ? void 0 : data.amountIn),
|
|
6805
|
+
amountOut: new import_bn6.default(data == null ? void 0 : data.amountIn),
|
|
6806
|
+
routes: (_a = data == null ? void 0 : data.routes) == null ? void 0 : _a.map((item) => {
|
|
6807
|
+
var _a2;
|
|
6808
|
+
return __spreadProps(__spreadValues({}, item), {
|
|
6809
|
+
amountIn: new import_bn6.default(item == null ? void 0 : item.amountIn),
|
|
6810
|
+
amountOut: new import_bn6.default(item == null ? void 0 : item.amountOut),
|
|
6811
|
+
initialPrice: new decimal_default((_a2 = item == null ? void 0 : item.initialPrice) == null ? void 0 : _a2.toString())
|
|
6812
|
+
});
|
|
6813
|
+
})
|
|
6807
6814
|
});
|
|
6808
6815
|
return result;
|
|
6809
6816
|
};
|
|
@@ -6913,7 +6920,7 @@ function getRouter(endpoint, params) {
|
|
|
6913
6920
|
url += `&providers=${providers.join(",")}`;
|
|
6914
6921
|
}
|
|
6915
6922
|
}
|
|
6916
|
-
url += "&v=
|
|
6923
|
+
url += "&v=1000321";
|
|
6917
6924
|
const response = yield fetch(url);
|
|
6918
6925
|
return response;
|
|
6919
6926
|
} catch (error) {
|
package/dist/index.mjs
CHANGED
|
@@ -5934,10 +5934,7 @@ var Haedal = class {
|
|
|
5934
5934
|
swap(client, txb, path, inputCoin, packages) {
|
|
5935
5935
|
return __async(this, null, function* () {
|
|
5936
5936
|
const { direction } = path;
|
|
5937
|
-
|
|
5938
|
-
throw new Error("Haedal not support b2a swap");
|
|
5939
|
-
}
|
|
5940
|
-
const func = "swap_a2b";
|
|
5937
|
+
const func = direction ? "swap_a2b" : "swap_b2a";
|
|
5941
5938
|
const args = [txb.object(path.id), txb.object("0x5"), inputCoin];
|
|
5942
5939
|
const publishedAt = getAggregatorV2PublishedAt(client.publishedAtV2(), packages);
|
|
5943
5940
|
const res = txb.moveCall({
|
|
@@ -6565,7 +6562,7 @@ var AggregatorClient19 = class {
|
|
|
6565
6562
|
// Include cetus、deepbookv2、flowxv2 & v3、kriyav2 & v3、turbos、aftermath、haedal、afsui、volo、bluemove
|
|
6566
6563
|
publishedAtV2() {
|
|
6567
6564
|
if (this.env === 0 /* Mainnet */) {
|
|
6568
|
-
return "
|
|
6565
|
+
return "0xf9c6f78322ed667909e05f6b42b2f5a67af6297503c905335e02a15148e9440d";
|
|
6569
6566
|
} else {
|
|
6570
6567
|
return "0x52eae33adeb44de55cfb3f281d4cc9e02d976181c0952f5323648b5717b33934";
|
|
6571
6568
|
}
|
|
@@ -6784,24 +6781,34 @@ function getAggregatorV2ExtendPublishedAt(aggregatorV2ExtendPublishedAt, package
|
|
|
6784
6781
|
// src/utils/msafe.ts
|
|
6785
6782
|
var import_bn6 = __toESM(require_bn());
|
|
6786
6783
|
var dealWithFastRouterSwapParamsForMsafe = (data) => {
|
|
6787
|
-
|
|
6788
|
-
|
|
6789
|
-
|
|
6790
|
-
|
|
6791
|
-
|
|
6792
|
-
|
|
6793
|
-
|
|
6784
|
+
var _a, _b, _c;
|
|
6785
|
+
const result = __spreadProps(__spreadValues({}, data), {
|
|
6786
|
+
amountIn: (_a = data == null ? void 0 : data.amountIn) == null ? void 0 : _a.toString(),
|
|
6787
|
+
amountOut: (_b = data == null ? void 0 : data.amountIn) == null ? void 0 : _b.toString(),
|
|
6788
|
+
routes: (_c = data == null ? void 0 : data.routes) == null ? void 0 : _c.map((item) => {
|
|
6789
|
+
var _a2, _b2, _c2;
|
|
6790
|
+
return __spreadProps(__spreadValues({}, item), {
|
|
6791
|
+
amountIn: (_a2 = item == null ? void 0 : item.amountIn) == null ? void 0 : _a2.toString(),
|
|
6792
|
+
amountOut: (_b2 = item == null ? void 0 : item.amountOut) == null ? void 0 : _b2.toString(),
|
|
6793
|
+
initialPrice: (_c2 = item == null ? void 0 : item.initialPrice) == null ? void 0 : _c2.toString()
|
|
6794
|
+
});
|
|
6795
|
+
})
|
|
6794
6796
|
});
|
|
6795
6797
|
return result;
|
|
6796
6798
|
};
|
|
6797
6799
|
var restituteMsafeFastRouterSwapParams = (data) => {
|
|
6798
|
-
|
|
6799
|
-
|
|
6800
|
-
|
|
6801
|
-
|
|
6802
|
-
|
|
6803
|
-
|
|
6804
|
-
|
|
6800
|
+
var _a;
|
|
6801
|
+
const result = __spreadProps(__spreadValues({}, data), {
|
|
6802
|
+
amountIn: new import_bn6.default(data == null ? void 0 : data.amountIn),
|
|
6803
|
+
amountOut: new import_bn6.default(data == null ? void 0 : data.amountIn),
|
|
6804
|
+
routes: (_a = data == null ? void 0 : data.routes) == null ? void 0 : _a.map((item) => {
|
|
6805
|
+
var _a2;
|
|
6806
|
+
return __spreadProps(__spreadValues({}, item), {
|
|
6807
|
+
amountIn: new import_bn6.default(item == null ? void 0 : item.amountIn),
|
|
6808
|
+
amountOut: new import_bn6.default(item == null ? void 0 : item.amountOut),
|
|
6809
|
+
initialPrice: new decimal_default((_a2 = item == null ? void 0 : item.initialPrice) == null ? void 0 : _a2.toString())
|
|
6810
|
+
});
|
|
6811
|
+
})
|
|
6805
6812
|
});
|
|
6806
6813
|
return result;
|
|
6807
6814
|
};
|
|
@@ -6911,7 +6918,7 @@ function getRouter(endpoint, params) {
|
|
|
6911
6918
|
url += `&providers=${providers.join(",")}`;
|
|
6912
6919
|
}
|
|
6913
6920
|
}
|
|
6914
|
-
url += "&v=
|
|
6921
|
+
url += "&v=1000321";
|
|
6915
6922
|
const response = yield fetch(url);
|
|
6916
6923
|
return response;
|
|
6917
6924
|
} catch (error) {
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
package/src/client.ts
CHANGED
|
@@ -479,9 +479,10 @@ export class AggregatorClient {
|
|
|
479
479
|
// Include cetus、deepbookv2、flowxv2 & v3、kriyav2 & v3、turbos、aftermath、haedal、afsui、volo、bluemove
|
|
480
480
|
publishedAtV2(): string {
|
|
481
481
|
if (this.env === Env.Mainnet) {
|
|
482
|
-
return "0x3fb42ddf908af45f9fc3c59eab227888ff24ba2e137b3b55bf80920fd47e11af" // version 6
|
|
482
|
+
// return "0x3fb42ddf908af45f9fc3c59eab227888ff24ba2e137b3b55bf80920fd47e11af" // version 6
|
|
483
483
|
// return "0x4069913c4953297b7f08f67f6722e3b04aa5ab2976b4e1b8a456b81590b34ab4"
|
|
484
|
-
|
|
484
|
+
return "0xf9c6f78322ed667909e05f6b42b2f5a67af6297503c905335e02a15148e9440d"
|
|
485
|
+
// return "0x803db8dfcc86fc1afbc7d2212bd14ec9690978ddebea0d590e01147d6b17aa06" // pre
|
|
485
486
|
} else {
|
|
486
487
|
// return "0x0ed287d6c3fe4962d0994ffddc1d19a15fba6a81533f3f0dcc2bbcedebce0637" // version 2
|
|
487
488
|
return "0x52eae33adeb44de55cfb3f281d4cc9e02d976181c0952f5323648b5717b33934"
|
|
@@ -19,10 +19,7 @@ export class Haedal implements Dex {
|
|
|
19
19
|
packages?: Map<string, string>
|
|
20
20
|
): Promise<TransactionObjectArgument> {
|
|
21
21
|
const { direction } = path
|
|
22
|
-
|
|
23
|
-
throw new Error("Haedal not support b2a swap")
|
|
24
|
-
}
|
|
25
|
-
const func = "swap_a2b"
|
|
22
|
+
const func = direction ? "swap_a2b" : "swap_b2a"
|
|
26
23
|
const args = [txb.object(path.id), txb.object("0x5"), inputCoin]
|
|
27
24
|
const publishedAt = getAggregatorV2PublishedAt(client.publishedAtV2(), packages)
|
|
28
25
|
const res = txb.moveCall({
|
package/src/utils/msafe.ts
CHANGED
|
@@ -3,29 +3,38 @@ import BN from 'bn.js'
|
|
|
3
3
|
import Decimal from "decimal.js"
|
|
4
4
|
|
|
5
5
|
export const dealWithFastRouterSwapParamsForMsafe = (data: any) => {
|
|
6
|
-
|
|
6
|
+
const result = {
|
|
7
|
+
...data,
|
|
8
|
+
amountIn: data?.amountIn?.toString(),
|
|
9
|
+
amountOut: data?.amountIn?.toString(),
|
|
10
|
+
routes: data?.routes?.map((item:any) => {
|
|
7
11
|
return {
|
|
8
|
-
...
|
|
9
|
-
amountIn:
|
|
10
|
-
amountOut:
|
|
11
|
-
initialPrice:
|
|
12
|
-
path: route.path
|
|
12
|
+
...item,
|
|
13
|
+
amountIn: item?.amountIn?.toString(),
|
|
14
|
+
amountOut: item?.amountOut?.toString(),
|
|
15
|
+
initialPrice: item?.initialPrice?.toString()
|
|
13
16
|
}
|
|
14
17
|
})
|
|
15
|
-
|
|
16
|
-
return result
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
return result
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
export const restituteMsafeFastRouterSwapParams = (data: any) => {
|
|
25
|
+
const result = {
|
|
26
|
+
...data,
|
|
27
|
+
amountIn: new BN(data?.amountIn),
|
|
28
|
+
amountOut: new BN(data?.amountIn),
|
|
29
|
+
routes: data?.routes?.map((item:any) => {
|
|
21
30
|
return {
|
|
22
|
-
...
|
|
23
|
-
amountIn: new BN(
|
|
24
|
-
amountOut: new BN(
|
|
25
|
-
initialPrice: new Decimal(
|
|
26
|
-
path: route.path
|
|
31
|
+
...item,
|
|
32
|
+
amountIn: new BN(item?.amountIn),
|
|
33
|
+
amountOut: new BN(item?.amountOut),
|
|
34
|
+
initialPrice: new Decimal(item?.initialPrice?.toString())
|
|
27
35
|
}
|
|
28
36
|
})
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return result
|
|
40
|
+
}
|
package/tests/router.test.ts
CHANGED
|
@@ -35,7 +35,6 @@ describe("router module", () => {
|
|
|
35
35
|
|
|
36
36
|
const wallet = keypair.getPublicKey().toSuiAddress()
|
|
37
37
|
console.log("wallet: ", wallet)
|
|
38
|
-
// const wallet = "0x02e39bddb06f617112595378fef741f523fbf22ea188cca99ecb61a9904dda2a"
|
|
39
38
|
|
|
40
39
|
const endpoint = aggregatorURL
|
|
41
40
|
|
|
@@ -109,8 +108,8 @@ describe("router module", () => {
|
|
|
109
108
|
|
|
110
109
|
test("Build router tx", async () => {
|
|
111
110
|
const byAmountIn = true
|
|
112
|
-
const amount = "
|
|
113
|
-
const from = "
|
|
111
|
+
const amount = "1000000000"
|
|
112
|
+
const from = "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
|
|
114
113
|
const target = "0x2::sui::SUI"
|
|
115
114
|
|
|
116
115
|
const res = await client.findRouters({
|
|
@@ -119,7 +118,8 @@ describe("router module", () => {
|
|
|
119
118
|
amount: new BN(amount),
|
|
120
119
|
byAmountIn,
|
|
121
120
|
depth: 3,
|
|
122
|
-
providers: ["
|
|
121
|
+
providers: ["HAEDAL"],
|
|
122
|
+
splitCount: 1,
|
|
123
123
|
})
|
|
124
124
|
|
|
125
125
|
if (res != null) {
|