@cetusprotocol/aggregator-sdk 0.3.31 → 0.3.32
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 +34 -19
- package/dist/index.mjs +34 -19
- package/dist/src/errors.d.ts +2 -1
- package/dist/tests/router/scallop.test.d.ts +2 -0
- package/package.json +1 -1
- package/src/api.ts +8 -5
- package/src/client.ts +2 -1
- package/src/errors.ts +4 -1
- package/src/utils/msafe.ts +27 -17
- package/tests/router/scallop.test.ts +127 -0
package/dist/index.js
CHANGED
|
@@ -5633,6 +5633,8 @@ function getAggregatorServerErrorMessage(code) {
|
|
|
5633
5633
|
return "Insufficient Liquidity";
|
|
5634
5634
|
case 10004 /* HoneyPot */:
|
|
5635
5635
|
return "Target token is detected as a HoneyPot scam";
|
|
5636
|
+
case 10005 /* RateLimitExceeded */:
|
|
5637
|
+
return "Too many requests. Please try again later";
|
|
5636
5638
|
default:
|
|
5637
5639
|
return "Unknown error";
|
|
5638
5640
|
}
|
|
@@ -6792,7 +6794,7 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
6792
6794
|
// Include deepbookv3, scallop, bluefin
|
|
6793
6795
|
publishedAtV2Extend() {
|
|
6794
6796
|
if (this.env === 0 /* Mainnet */) {
|
|
6795
|
-
return "
|
|
6797
|
+
return "0xf57be4b9f9036034b1c5484d299d8fb68d5f43862d6afe8886d67db293dfc4bc";
|
|
6796
6798
|
} else {
|
|
6797
6799
|
return "0xabb6a81c8a216828e317719e06125de5bb2cb0fe8f9916ff8c023ca5be224c78";
|
|
6798
6800
|
}
|
|
@@ -7102,23 +7104,34 @@ function getAggregatorV2ExtendPublishedAt(aggregatorV2ExtendPublishedAt, package
|
|
|
7102
7104
|
// src/utils/msafe.ts
|
|
7103
7105
|
var import_bn6 = __toESM(require_bn());
|
|
7104
7106
|
var dealWithFastRouterSwapParamsForMsafe = (data) => {
|
|
7105
|
-
|
|
7106
|
-
|
|
7107
|
-
|
|
7108
|
-
|
|
7109
|
-
|
|
7110
|
-
|
|
7111
|
-
|
|
7107
|
+
var _a, _b, _c;
|
|
7108
|
+
const result = __spreadProps(__spreadValues({}, data), {
|
|
7109
|
+
amountIn: (_a = data == null ? void 0 : data.amountIn) == null ? void 0 : _a.toString(),
|
|
7110
|
+
amountOut: (_b = data == null ? void 0 : data.amountIn) == null ? void 0 : _b.toString(),
|
|
7111
|
+
routes: (_c = data == null ? void 0 : data.routes) == null ? void 0 : _c.map((item) => {
|
|
7112
|
+
var _a2, _b2, _c2;
|
|
7113
|
+
return __spreadProps(__spreadValues({}, item), {
|
|
7114
|
+
amountIn: (_a2 = item == null ? void 0 : item.amountIn) == null ? void 0 : _a2.toString(),
|
|
7115
|
+
amountOut: (_b2 = item == null ? void 0 : item.amountOut) == null ? void 0 : _b2.toString(),
|
|
7116
|
+
initialPrice: (_c2 = item == null ? void 0 : item.initialPrice) == null ? void 0 : _c2.toString()
|
|
7117
|
+
});
|
|
7118
|
+
})
|
|
7112
7119
|
});
|
|
7113
7120
|
return result;
|
|
7114
7121
|
};
|
|
7115
7122
|
var restituteMsafeFastRouterSwapParams = (data) => {
|
|
7116
|
-
|
|
7117
|
-
|
|
7118
|
-
|
|
7119
|
-
|
|
7120
|
-
|
|
7121
|
-
|
|
7123
|
+
var _a;
|
|
7124
|
+
const result = __spreadProps(__spreadValues({}, data), {
|
|
7125
|
+
amountIn: new import_bn6.default(data == null ? void 0 : data.amountIn),
|
|
7126
|
+
amountOut: new import_bn6.default(data == null ? void 0 : data.amountIn),
|
|
7127
|
+
routes: (_a = data == null ? void 0 : data.routes) == null ? void 0 : _a.map((item) => {
|
|
7128
|
+
var _a2;
|
|
7129
|
+
return __spreadProps(__spreadValues({}, item), {
|
|
7130
|
+
amountIn: new import_bn6.default(item == null ? void 0 : item.amountIn),
|
|
7131
|
+
amountOut: new import_bn6.default(item == null ? void 0 : item.amountOut),
|
|
7132
|
+
initialPrice: new decimal_default((_a2 = item == null ? void 0 : item.initialPrice) == null ? void 0 : _a2.toString())
|
|
7133
|
+
});
|
|
7134
|
+
})
|
|
7122
7135
|
});
|
|
7123
7136
|
return result;
|
|
7124
7137
|
};
|
|
@@ -7132,7 +7145,7 @@ function processEndpoint(endpoint) {
|
|
|
7132
7145
|
}
|
|
7133
7146
|
|
|
7134
7147
|
// src/api.ts
|
|
7135
|
-
var SDK_VERSION =
|
|
7148
|
+
var SDK_VERSION = 1000332;
|
|
7136
7149
|
function getRouterResult(endpoint, params) {
|
|
7137
7150
|
return __async(this, null, function* () {
|
|
7138
7151
|
let response;
|
|
@@ -7145,6 +7158,10 @@ function getRouterResult(endpoint, params) {
|
|
|
7145
7158
|
return null;
|
|
7146
7159
|
}
|
|
7147
7160
|
if (!response.ok) {
|
|
7161
|
+
let errorCode = 10001 /* NumberTooLarge */;
|
|
7162
|
+
if (response.status === 429) {
|
|
7163
|
+
errorCode = 10005 /* RateLimitExceeded */;
|
|
7164
|
+
}
|
|
7148
7165
|
return {
|
|
7149
7166
|
amountIn: ZERO,
|
|
7150
7167
|
amountOut: ZERO,
|
|
@@ -7152,10 +7169,8 @@ function getRouterResult(endpoint, params) {
|
|
|
7152
7169
|
byAmountIn: params.byAmountIn,
|
|
7153
7170
|
insufficientLiquidity: false,
|
|
7154
7171
|
error: {
|
|
7155
|
-
code:
|
|
7156
|
-
msg: getAggregatorServerErrorMessage(
|
|
7157
|
-
10001 /* NumberTooLarge */
|
|
7158
|
-
)
|
|
7172
|
+
code: errorCode,
|
|
7173
|
+
msg: getAggregatorServerErrorMessage(errorCode)
|
|
7159
7174
|
}
|
|
7160
7175
|
};
|
|
7161
7176
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -5631,6 +5631,8 @@ function getAggregatorServerErrorMessage(code) {
|
|
|
5631
5631
|
return "Insufficient Liquidity";
|
|
5632
5632
|
case 10004 /* HoneyPot */:
|
|
5633
5633
|
return "Target token is detected as a HoneyPot scam";
|
|
5634
|
+
case 10005 /* RateLimitExceeded */:
|
|
5635
|
+
return "Too many requests. Please try again later";
|
|
5634
5636
|
default:
|
|
5635
5637
|
return "Unknown error";
|
|
5636
5638
|
}
|
|
@@ -6790,7 +6792,7 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
6790
6792
|
// Include deepbookv3, scallop, bluefin
|
|
6791
6793
|
publishedAtV2Extend() {
|
|
6792
6794
|
if (this.env === 0 /* Mainnet */) {
|
|
6793
|
-
return "
|
|
6795
|
+
return "0xf57be4b9f9036034b1c5484d299d8fb68d5f43862d6afe8886d67db293dfc4bc";
|
|
6794
6796
|
} else {
|
|
6795
6797
|
return "0xabb6a81c8a216828e317719e06125de5bb2cb0fe8f9916ff8c023ca5be224c78";
|
|
6796
6798
|
}
|
|
@@ -7100,23 +7102,34 @@ function getAggregatorV2ExtendPublishedAt(aggregatorV2ExtendPublishedAt, package
|
|
|
7100
7102
|
// src/utils/msafe.ts
|
|
7101
7103
|
var import_bn6 = __toESM(require_bn());
|
|
7102
7104
|
var dealWithFastRouterSwapParamsForMsafe = (data) => {
|
|
7103
|
-
|
|
7104
|
-
|
|
7105
|
-
|
|
7106
|
-
|
|
7107
|
-
|
|
7108
|
-
|
|
7109
|
-
|
|
7105
|
+
var _a, _b, _c;
|
|
7106
|
+
const result = __spreadProps(__spreadValues({}, data), {
|
|
7107
|
+
amountIn: (_a = data == null ? void 0 : data.amountIn) == null ? void 0 : _a.toString(),
|
|
7108
|
+
amountOut: (_b = data == null ? void 0 : data.amountIn) == null ? void 0 : _b.toString(),
|
|
7109
|
+
routes: (_c = data == null ? void 0 : data.routes) == null ? void 0 : _c.map((item) => {
|
|
7110
|
+
var _a2, _b2, _c2;
|
|
7111
|
+
return __spreadProps(__spreadValues({}, item), {
|
|
7112
|
+
amountIn: (_a2 = item == null ? void 0 : item.amountIn) == null ? void 0 : _a2.toString(),
|
|
7113
|
+
amountOut: (_b2 = item == null ? void 0 : item.amountOut) == null ? void 0 : _b2.toString(),
|
|
7114
|
+
initialPrice: (_c2 = item == null ? void 0 : item.initialPrice) == null ? void 0 : _c2.toString()
|
|
7115
|
+
});
|
|
7116
|
+
})
|
|
7110
7117
|
});
|
|
7111
7118
|
return result;
|
|
7112
7119
|
};
|
|
7113
7120
|
var restituteMsafeFastRouterSwapParams = (data) => {
|
|
7114
|
-
|
|
7115
|
-
|
|
7116
|
-
|
|
7117
|
-
|
|
7118
|
-
|
|
7119
|
-
|
|
7121
|
+
var _a;
|
|
7122
|
+
const result = __spreadProps(__spreadValues({}, data), {
|
|
7123
|
+
amountIn: new import_bn6.default(data == null ? void 0 : data.amountIn),
|
|
7124
|
+
amountOut: new import_bn6.default(data == null ? void 0 : data.amountIn),
|
|
7125
|
+
routes: (_a = data == null ? void 0 : data.routes) == null ? void 0 : _a.map((item) => {
|
|
7126
|
+
var _a2;
|
|
7127
|
+
return __spreadProps(__spreadValues({}, item), {
|
|
7128
|
+
amountIn: new import_bn6.default(item == null ? void 0 : item.amountIn),
|
|
7129
|
+
amountOut: new import_bn6.default(item == null ? void 0 : item.amountOut),
|
|
7130
|
+
initialPrice: new decimal_default((_a2 = item == null ? void 0 : item.initialPrice) == null ? void 0 : _a2.toString())
|
|
7131
|
+
});
|
|
7132
|
+
})
|
|
7120
7133
|
});
|
|
7121
7134
|
return result;
|
|
7122
7135
|
};
|
|
@@ -7130,7 +7143,7 @@ function processEndpoint(endpoint) {
|
|
|
7130
7143
|
}
|
|
7131
7144
|
|
|
7132
7145
|
// src/api.ts
|
|
7133
|
-
var SDK_VERSION =
|
|
7146
|
+
var SDK_VERSION = 1000332;
|
|
7134
7147
|
function getRouterResult(endpoint, params) {
|
|
7135
7148
|
return __async(this, null, function* () {
|
|
7136
7149
|
let response;
|
|
@@ -7143,6 +7156,10 @@ function getRouterResult(endpoint, params) {
|
|
|
7143
7156
|
return null;
|
|
7144
7157
|
}
|
|
7145
7158
|
if (!response.ok) {
|
|
7159
|
+
let errorCode = 10001 /* NumberTooLarge */;
|
|
7160
|
+
if (response.status === 429) {
|
|
7161
|
+
errorCode = 10005 /* RateLimitExceeded */;
|
|
7162
|
+
}
|
|
7146
7163
|
return {
|
|
7147
7164
|
amountIn: ZERO,
|
|
7148
7165
|
amountOut: ZERO,
|
|
@@ -7150,10 +7167,8 @@ function getRouterResult(endpoint, params) {
|
|
|
7150
7167
|
byAmountIn: params.byAmountIn,
|
|
7151
7168
|
insufficientLiquidity: false,
|
|
7152
7169
|
error: {
|
|
7153
|
-
code:
|
|
7154
|
-
msg: getAggregatorServerErrorMessage(
|
|
7155
|
-
10001 /* NumberTooLarge */
|
|
7156
|
-
)
|
|
7170
|
+
code: errorCode,
|
|
7171
|
+
msg: getAggregatorServerErrorMessage(errorCode)
|
|
7157
7172
|
}
|
|
7158
7173
|
};
|
|
7159
7174
|
}
|
package/dist/src/errors.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ export declare enum AggregatorServerErrorCode {
|
|
|
34
34
|
NumberTooLarge = 10001,
|
|
35
35
|
NoRouter = 10002,
|
|
36
36
|
InsufficientLiquidity = 10003,
|
|
37
|
-
HoneyPot = 10004
|
|
37
|
+
HoneyPot = 10004,
|
|
38
|
+
RateLimitExceeded = 10005
|
|
38
39
|
}
|
|
39
40
|
export declare function getAggregatorServerErrorMessage(code: AggregatorServerErrorCode): string;
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from "./errors"
|
|
9
9
|
import { parseRouterResponse } from "./client"
|
|
10
10
|
|
|
11
|
-
const SDK_VERSION =
|
|
11
|
+
const SDK_VERSION = 1000332
|
|
12
12
|
|
|
13
13
|
export interface FindRouterParams {
|
|
14
14
|
from: string
|
|
@@ -120,6 +120,11 @@ export async function getRouterResult(
|
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
if (!response.ok) {
|
|
123
|
+
let errorCode = AggregatorServerErrorCode.NumberTooLarge
|
|
124
|
+
if (response.status === 429) {
|
|
125
|
+
errorCode = AggregatorServerErrorCode.RateLimitExceeded
|
|
126
|
+
}
|
|
127
|
+
|
|
123
128
|
return {
|
|
124
129
|
amountIn: ZERO,
|
|
125
130
|
amountOut: ZERO,
|
|
@@ -127,10 +132,8 @@ export async function getRouterResult(
|
|
|
127
132
|
byAmountIn: params.byAmountIn,
|
|
128
133
|
insufficientLiquidity: false,
|
|
129
134
|
error: {
|
|
130
|
-
code:
|
|
131
|
-
msg: getAggregatorServerErrorMessage(
|
|
132
|
-
AggregatorServerErrorCode.NumberTooLarge
|
|
133
|
-
),
|
|
135
|
+
code: errorCode,
|
|
136
|
+
msg: getAggregatorServerErrorMessage(errorCode),
|
|
134
137
|
},
|
|
135
138
|
}
|
|
136
139
|
}
|
package/src/client.ts
CHANGED
|
@@ -610,7 +610,8 @@ export class AggregatorClient {
|
|
|
610
610
|
// return "0x347dd58bbd11cd82c8b386b344729717c04a998da73386e82a239cc196d5706b" // version 7
|
|
611
611
|
// return "0xf2fcea41dc217385019828375764fa06d9bd25e8e4726ba1962680849fb8d613" // version 8
|
|
612
612
|
// return "0xa2d8a4279d69d8fec04b2fea8852d0d467d3cc0d39c5890180d439ae7a9953ed" // version 9
|
|
613
|
-
return "0x34ef25b60b51f9d07cd9b7dc5b08dfdf26c7b0ff00c57bb17454c161fa6b6b83" // version 10
|
|
613
|
+
// return "0x34ef25b60b51f9d07cd9b7dc5b08dfdf26c7b0ff00c57bb17454c161fa6b6b83" // version 10
|
|
614
|
+
return "0xf57be4b9f9036034b1c5484d299d8fb68d5f43862d6afe8886d67db293dfc4bc" // version 11
|
|
614
615
|
} else {
|
|
615
616
|
return "0xabb6a81c8a216828e317719e06125de5bb2cb0fe8f9916ff8c023ca5be224c78"
|
|
616
617
|
}
|
package/src/errors.ts
CHANGED
|
@@ -51,7 +51,8 @@ export enum AggregatorServerErrorCode {
|
|
|
51
51
|
NumberTooLarge = 10001,
|
|
52
52
|
NoRouter = 10002,
|
|
53
53
|
InsufficientLiquidity = 10003,
|
|
54
|
-
HoneyPot = 10004
|
|
54
|
+
HoneyPot = 10004,
|
|
55
|
+
RateLimitExceeded = 10005,
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
export function getAggregatorServerErrorMessage(
|
|
@@ -68,6 +69,8 @@ export function getAggregatorServerErrorMessage(
|
|
|
68
69
|
return "Insufficient Liquidity"
|
|
69
70
|
case AggregatorServerErrorCode.HoneyPot:
|
|
70
71
|
return "Target token is detected as a HoneyPot scam"
|
|
72
|
+
case AggregatorServerErrorCode.RateLimitExceeded:
|
|
73
|
+
return "Too many requests. Please try again later"
|
|
71
74
|
default:
|
|
72
75
|
return "Unknown error"
|
|
73
76
|
}
|
package/src/utils/msafe.ts
CHANGED
|
@@ -3,28 +3,38 @@ import BN from 'bn.js'
|
|
|
3
3
|
import Decimal from "decimal.js"
|
|
4
4
|
|
|
5
5
|
export const dealWithFastRouterSwapParamsForMsafe = (data: any) => {
|
|
6
|
-
const result =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
const result = {
|
|
7
|
+
...data,
|
|
8
|
+
amountIn: data?.amountIn?.toString(),
|
|
9
|
+
amountOut: data?.amountIn?.toString(),
|
|
10
|
+
routes: data?.routes?.map((item:any) => {
|
|
11
|
+
return {
|
|
12
|
+
...item,
|
|
13
|
+
amountIn: item?.amountIn?.toString(),
|
|
14
|
+
amountOut: item?.amountOut?.toString(),
|
|
15
|
+
initialPrice: item?.initialPrice?.toString()
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
}
|
|
14
19
|
|
|
15
20
|
return result
|
|
16
21
|
}
|
|
17
22
|
|
|
18
23
|
|
|
19
24
|
export const restituteMsafeFastRouterSwapParams = (data: any) => {
|
|
20
|
-
const result =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
const result = {
|
|
26
|
+
...data,
|
|
27
|
+
amountIn: new BN(data?.amountIn),
|
|
28
|
+
amountOut: new BN(data?.amountIn),
|
|
29
|
+
routes: data?.routes?.map((item:any) => {
|
|
30
|
+
return {
|
|
31
|
+
...item,
|
|
32
|
+
amountIn: new BN(item?.amountIn),
|
|
33
|
+
amountOut: new BN(item?.amountOut),
|
|
34
|
+
initialPrice: new Decimal(item?.initialPrice?.toString())
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
}
|
|
28
38
|
|
|
29
39
|
return result
|
|
30
|
-
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { describe, test } from "@jest/globals"
|
|
2
|
+
import dotenv from "dotenv"
|
|
3
|
+
import { AggregatorClient } from "~/client"
|
|
4
|
+
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519"
|
|
5
|
+
import { printTransaction } from "~/utils/transaction"
|
|
6
|
+
import BN from "bn.js"
|
|
7
|
+
import { fromB64 } from "@mysten/sui/utils"
|
|
8
|
+
import { SuiClient } from "@mysten/sui/client"
|
|
9
|
+
import { Env } from "~/index"
|
|
10
|
+
import { Transaction } from "@mysten/sui/transactions"
|
|
11
|
+
|
|
12
|
+
dotenv.config()
|
|
13
|
+
|
|
14
|
+
export function buildTestAccount(): Ed25519Keypair {
|
|
15
|
+
const mnemonics = process.env.SUI_WALLET_MNEMONICS || ""
|
|
16
|
+
const testAccountObject = Ed25519Keypair.deriveKeypair(mnemonics)
|
|
17
|
+
return testAccountObject
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe("Test scallop provider", () => {
|
|
21
|
+
let client: AggregatorClient
|
|
22
|
+
let keypair: Ed25519Keypair
|
|
23
|
+
|
|
24
|
+
const T_HASUI = "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
|
|
25
|
+
const T_SHASUI = "0x9a2376943f7d22f88087c259c5889925f332ca4347e669dc37d54c2bf651af3c::scallop_ha_sui::SCALLOP_HA_SUI"
|
|
26
|
+
|
|
27
|
+
const T_SUI = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI"
|
|
28
|
+
const T_SSUI = "0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI"
|
|
29
|
+
|
|
30
|
+
beforeAll(() => {
|
|
31
|
+
const fullNodeURL = process.env.SUI_RPC!
|
|
32
|
+
const aggregatorURL = process.env.CETUS_AGGREGATOR!
|
|
33
|
+
const secret = process.env.SUI_WALLET_SECRET!
|
|
34
|
+
|
|
35
|
+
if (secret) {
|
|
36
|
+
keypair = Ed25519Keypair.fromSecretKey(fromB64(secret).slice(1, 33))
|
|
37
|
+
} else {
|
|
38
|
+
keypair = buildTestAccount()
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// const wallet = keypair.getPublicKey().toSuiAddress()
|
|
42
|
+
const wallet =
|
|
43
|
+
"0xf077fa7f67b1f2d417bbe977b3cbc113b078907f74e04120f623b87b23e93963"
|
|
44
|
+
|
|
45
|
+
console.log("wallet: ", wallet)
|
|
46
|
+
|
|
47
|
+
const endpoint = aggregatorURL
|
|
48
|
+
|
|
49
|
+
const suiClient = new SuiClient({
|
|
50
|
+
url: fullNodeURL,
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
client = new AggregatorClient(endpoint, wallet, suiClient, Env.Mainnet)
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
test("Find Routers", async () => {
|
|
57
|
+
const amounts = ["1000", "1000000", "100000000", "5000000000", "1000000000000000000000000000"]
|
|
58
|
+
|
|
59
|
+
while (true) {
|
|
60
|
+
const res = await client.findRouters({
|
|
61
|
+
from: T_SUI,
|
|
62
|
+
target: T_SSUI,
|
|
63
|
+
amount: new BN("1000000000000000000000000000"),
|
|
64
|
+
byAmountIn: true,
|
|
65
|
+
depth: 3,
|
|
66
|
+
splitCount: 1,
|
|
67
|
+
providers: ["SCALLOP"],
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
if (res != null) {
|
|
71
|
+
console.log(JSON.stringify(res, null, 2))
|
|
72
|
+
}
|
|
73
|
+
console.log("amount in", res?.amountIn.toString())
|
|
74
|
+
console.log("amount out", res?.amountOut.toString())
|
|
75
|
+
}
|
|
76
|
+
}, 6000000)
|
|
77
|
+
|
|
78
|
+
test("Build Router TX", async () => {
|
|
79
|
+
const amount = "10000000"
|
|
80
|
+
|
|
81
|
+
const res = await client.findRouters({
|
|
82
|
+
from: T_HASUI,
|
|
83
|
+
target: T_SHASUI,
|
|
84
|
+
amount: new BN(amount),
|
|
85
|
+
byAmountIn: true,
|
|
86
|
+
depth: 3,
|
|
87
|
+
providers: ["SCALLOP"],
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
console.log("amount in", res?.amountIn.toString())
|
|
91
|
+
console.log("amount out", res?.amountOut.toString())
|
|
92
|
+
|
|
93
|
+
const txb = new Transaction()
|
|
94
|
+
|
|
95
|
+
if (res != null) {
|
|
96
|
+
console.log(JSON.stringify(res, null, 2))
|
|
97
|
+
await client.fastRouterSwap({
|
|
98
|
+
routers: res,
|
|
99
|
+
txb,
|
|
100
|
+
slippage: 0.01,
|
|
101
|
+
refreshAllCoins: true,
|
|
102
|
+
payDeepFeeAmount: 0,
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
txb.setSender(client.signer)
|
|
106
|
+
const buildTxb = await txb.build({ client: client.client })
|
|
107
|
+
// const buildTxb = await txb.getData()
|
|
108
|
+
|
|
109
|
+
console.log("buildTxb", buildTxb)
|
|
110
|
+
|
|
111
|
+
printTransaction(txb)
|
|
112
|
+
|
|
113
|
+
let result = await client.devInspectTransactionBlock(txb)
|
|
114
|
+
console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
|
|
115
|
+
for (const event of result.events) {
|
|
116
|
+
console.log("event", JSON.stringify(event, null, 2))
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (result.effects.status.status === "success") {
|
|
120
|
+
const result = await client.signAndExecuteTransaction(txb, keypair)
|
|
121
|
+
console.log("result", result)
|
|
122
|
+
} else {
|
|
123
|
+
console.log("result", result)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}, 600000)
|
|
127
|
+
})
|