@cetusprotocol/aggregator-sdk 0.3.15 → 0.3.17
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/README.md +1 -1
- package/dist/index.js +23 -4
- package/dist/index.mjs +23 -4
- package/dist/src/errors.d.ts +2 -1
- package/package.json +1 -1
- package/src/api.ts +18 -2
- package/src/client.ts +2 -1
- package/src/errors.ts +3 -0
- package/src/utils/coin.ts +5 -1
- package/tests/router.test.ts +27 -7
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -5621,6 +5621,8 @@ function getAggregatorServerErrorMessage(code) {
|
|
|
5621
5621
|
return "No router";
|
|
5622
5622
|
case 10003 /* InsufficientLiquidity */:
|
|
5623
5623
|
return "Insufficient Liquidity";
|
|
5624
|
+
case 10004 /* HoneyPot */:
|
|
5625
|
+
return "Target token is detected as a HoneyPot scam";
|
|
5624
5626
|
default:
|
|
5625
5627
|
return "Unknown error";
|
|
5626
5628
|
}
|
|
@@ -5706,8 +5708,11 @@ function buildInputCoin(txb, allCoins, amount, coinType) {
|
|
|
5706
5708
|
mergedCoin.map((coin) => txb.object(coin))
|
|
5707
5709
|
);
|
|
5708
5710
|
}
|
|
5711
|
+
const targetCoin = txb.splitCoins(txb.object(masterCoin), [
|
|
5712
|
+
txb.pure.u64(amount.toString())
|
|
5713
|
+
]);
|
|
5709
5714
|
return {
|
|
5710
|
-
targetCoin
|
|
5715
|
+
targetCoin,
|
|
5711
5716
|
isMintZeroCoin: false,
|
|
5712
5717
|
targetCoinAmount: Number(amount.toString())
|
|
5713
5718
|
};
|
|
@@ -6479,7 +6484,7 @@ var AggregatorClient10 = class {
|
|
|
6479
6484
|
// Include cetus、deepbookv2、flowxv2 & v3、kriyav2 & v3、turbos、aftermath、haedal、afsui、volo、bluemove
|
|
6480
6485
|
publishedAt() {
|
|
6481
6486
|
if (this.env === 0 /* Mainnet */) {
|
|
6482
|
-
return "
|
|
6487
|
+
return "0x3fb42ddf908af45f9fc3c59eab227888ff24ba2e137b3b55bf80920fd47e11af";
|
|
6483
6488
|
} else {
|
|
6484
6489
|
return "0x52eae33adeb44de55cfb3f281d4cc9e02d976181c0952f5323648b5717b33934";
|
|
6485
6490
|
}
|
|
@@ -6726,11 +6731,25 @@ function getRouterResult(endpoint, params) {
|
|
|
6726
6731
|
};
|
|
6727
6732
|
}
|
|
6728
6733
|
const data = yield response.json();
|
|
6734
|
+
const insufficientLiquidity = data.msg === "liquidity is not enough";
|
|
6735
|
+
if (data.msg && data.msg.indexOf("HoneyPot scam") > -1) {
|
|
6736
|
+
return {
|
|
6737
|
+
amountIn: ZERO,
|
|
6738
|
+
amountOut: ZERO,
|
|
6739
|
+
routes: [],
|
|
6740
|
+
insufficientLiquidity,
|
|
6741
|
+
error: {
|
|
6742
|
+
code: 10004 /* HoneyPot */,
|
|
6743
|
+
msg: getAggregatorServerErrorMessage(
|
|
6744
|
+
10004 /* HoneyPot */
|
|
6745
|
+
)
|
|
6746
|
+
}
|
|
6747
|
+
};
|
|
6748
|
+
}
|
|
6729
6749
|
if (data.data != null) {
|
|
6730
6750
|
const res = parseRouterResponse(data.data);
|
|
6731
6751
|
return res;
|
|
6732
6752
|
}
|
|
6733
|
-
const insufficientLiquidity = data.msg === "liquidity is not enough";
|
|
6734
6753
|
return {
|
|
6735
6754
|
amountIn: ZERO,
|
|
6736
6755
|
amountOut: ZERO,
|
|
@@ -6779,7 +6798,7 @@ function getRouter(endpoint, params) {
|
|
|
6779
6798
|
url += `&providers=${providers.join(",")}`;
|
|
6780
6799
|
}
|
|
6781
6800
|
}
|
|
6782
|
-
url += "&v=
|
|
6801
|
+
url += "&v=1000317";
|
|
6783
6802
|
const response = yield fetch(url);
|
|
6784
6803
|
return response;
|
|
6785
6804
|
} catch (error) {
|
package/dist/index.mjs
CHANGED
|
@@ -5619,6 +5619,8 @@ function getAggregatorServerErrorMessage(code) {
|
|
|
5619
5619
|
return "No router";
|
|
5620
5620
|
case 10003 /* InsufficientLiquidity */:
|
|
5621
5621
|
return "Insufficient Liquidity";
|
|
5622
|
+
case 10004 /* HoneyPot */:
|
|
5623
|
+
return "Target token is detected as a HoneyPot scam";
|
|
5622
5624
|
default:
|
|
5623
5625
|
return "Unknown error";
|
|
5624
5626
|
}
|
|
@@ -5704,8 +5706,11 @@ function buildInputCoin(txb, allCoins, amount, coinType) {
|
|
|
5704
5706
|
mergedCoin.map((coin) => txb.object(coin))
|
|
5705
5707
|
);
|
|
5706
5708
|
}
|
|
5709
|
+
const targetCoin = txb.splitCoins(txb.object(masterCoin), [
|
|
5710
|
+
txb.pure.u64(amount.toString())
|
|
5711
|
+
]);
|
|
5707
5712
|
return {
|
|
5708
|
-
targetCoin
|
|
5713
|
+
targetCoin,
|
|
5709
5714
|
isMintZeroCoin: false,
|
|
5710
5715
|
targetCoinAmount: Number(amount.toString())
|
|
5711
5716
|
};
|
|
@@ -6477,7 +6482,7 @@ var AggregatorClient10 = class {
|
|
|
6477
6482
|
// Include cetus、deepbookv2、flowxv2 & v3、kriyav2 & v3、turbos、aftermath、haedal、afsui、volo、bluemove
|
|
6478
6483
|
publishedAt() {
|
|
6479
6484
|
if (this.env === 0 /* Mainnet */) {
|
|
6480
|
-
return "
|
|
6485
|
+
return "0x3fb42ddf908af45f9fc3c59eab227888ff24ba2e137b3b55bf80920fd47e11af";
|
|
6481
6486
|
} else {
|
|
6482
6487
|
return "0x52eae33adeb44de55cfb3f281d4cc9e02d976181c0952f5323648b5717b33934";
|
|
6483
6488
|
}
|
|
@@ -6724,11 +6729,25 @@ function getRouterResult(endpoint, params) {
|
|
|
6724
6729
|
};
|
|
6725
6730
|
}
|
|
6726
6731
|
const data = yield response.json();
|
|
6732
|
+
const insufficientLiquidity = data.msg === "liquidity is not enough";
|
|
6733
|
+
if (data.msg && data.msg.indexOf("HoneyPot scam") > -1) {
|
|
6734
|
+
return {
|
|
6735
|
+
amountIn: ZERO,
|
|
6736
|
+
amountOut: ZERO,
|
|
6737
|
+
routes: [],
|
|
6738
|
+
insufficientLiquidity,
|
|
6739
|
+
error: {
|
|
6740
|
+
code: 10004 /* HoneyPot */,
|
|
6741
|
+
msg: getAggregatorServerErrorMessage(
|
|
6742
|
+
10004 /* HoneyPot */
|
|
6743
|
+
)
|
|
6744
|
+
}
|
|
6745
|
+
};
|
|
6746
|
+
}
|
|
6727
6747
|
if (data.data != null) {
|
|
6728
6748
|
const res = parseRouterResponse(data.data);
|
|
6729
6749
|
return res;
|
|
6730
6750
|
}
|
|
6731
|
-
const insufficientLiquidity = data.msg === "liquidity is not enough";
|
|
6732
6751
|
return {
|
|
6733
6752
|
amountIn: ZERO,
|
|
6734
6753
|
amountOut: ZERO,
|
|
@@ -6777,7 +6796,7 @@ function getRouter(endpoint, params) {
|
|
|
6777
6796
|
url += `&providers=${providers.join(",")}`;
|
|
6778
6797
|
}
|
|
6779
6798
|
}
|
|
6780
|
-
url += "&v=
|
|
6799
|
+
url += "&v=1000317";
|
|
6781
6800
|
const response = yield fetch(url);
|
|
6782
6801
|
return response;
|
|
6783
6802
|
} catch (error) {
|
package/dist/src/errors.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ export declare enum AggregatorServerErrorCode {
|
|
|
33
33
|
CalculateError = 10000,
|
|
34
34
|
NumberTooLarge = 10001,
|
|
35
35
|
NoRouter = 10002,
|
|
36
|
-
InsufficientLiquidity = 10003
|
|
36
|
+
InsufficientLiquidity = 10003,
|
|
37
|
+
HoneyPot = 10004
|
|
37
38
|
}
|
|
38
39
|
export declare function getAggregatorServerErrorMessage(code: AggregatorServerErrorCode): string;
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -109,11 +109,27 @@ export async function getRouterResult(
|
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
const data = await response.json()
|
|
112
|
+
const insufficientLiquidity = data.msg === "liquidity is not enough"
|
|
113
|
+
|
|
114
|
+
if(data.msg && data.msg.indexOf('HoneyPot scam')>-1){
|
|
115
|
+
return {
|
|
116
|
+
amountIn: ZERO,
|
|
117
|
+
amountOut: ZERO,
|
|
118
|
+
routes: [],
|
|
119
|
+
insufficientLiquidity,
|
|
120
|
+
error: {
|
|
121
|
+
code: AggregatorServerErrorCode.HoneyPot,
|
|
122
|
+
msg: getAggregatorServerErrorMessage(
|
|
123
|
+
AggregatorServerErrorCode.HoneyPot
|
|
124
|
+
),
|
|
125
|
+
},
|
|
126
|
+
}
|
|
127
|
+
}
|
|
112
128
|
if (data.data != null) {
|
|
113
129
|
const res = parseRouterResponse(data.data)
|
|
114
130
|
return res
|
|
115
131
|
}
|
|
116
|
-
|
|
132
|
+
|
|
117
133
|
|
|
118
134
|
return {
|
|
119
135
|
amountIn: ZERO,
|
|
@@ -170,7 +186,7 @@ async function getRouter(endpoint: string, params: FindRouterParams) {
|
|
|
170
186
|
}
|
|
171
187
|
|
|
172
188
|
// set newest sdk version
|
|
173
|
-
url += "&v=
|
|
189
|
+
url += "&v=1000317"
|
|
174
190
|
|
|
175
191
|
const response = await fetch(url)
|
|
176
192
|
return response
|
package/src/client.ts
CHANGED
|
@@ -406,7 +406,8 @@ export class AggregatorClient {
|
|
|
406
406
|
// Include cetus、deepbookv2、flowxv2 & v3、kriyav2 & v3、turbos、aftermath、haedal、afsui、volo、bluemove
|
|
407
407
|
publishedAt(): string {
|
|
408
408
|
if (this.env === Env.Mainnet) {
|
|
409
|
-
return "
|
|
409
|
+
return "0x3fb42ddf908af45f9fc3c59eab227888ff24ba2e137b3b55bf80920fd47e11af" // version 6
|
|
410
|
+
// return "0x807c6697636bafa674dcf67570a1a95c3cc35dd9a44614558ef8ef9ed4aa83ad" // pre
|
|
410
411
|
} else {
|
|
411
412
|
// return "0x0ed287d6c3fe4962d0994ffddc1d19a15fba6a81533f3f0dcc2bbcedebce0637" // version 2
|
|
412
413
|
return "0x52eae33adeb44de55cfb3f281d4cc9e02d976181c0952f5323648b5717b33934"
|
package/src/errors.ts
CHANGED
|
@@ -51,6 +51,7 @@ export enum AggregatorServerErrorCode {
|
|
|
51
51
|
NumberTooLarge = 10001,
|
|
52
52
|
NoRouter = 10002,
|
|
53
53
|
InsufficientLiquidity = 10003,
|
|
54
|
+
HoneyPot = 10004
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
export function getAggregatorServerErrorMessage(
|
|
@@ -65,6 +66,8 @@ export function getAggregatorServerErrorMessage(
|
|
|
65
66
|
return "No router"
|
|
66
67
|
case AggregatorServerErrorCode.InsufficientLiquidity:
|
|
67
68
|
return "Insufficient Liquidity"
|
|
69
|
+
case AggregatorServerErrorCode.HoneyPot:
|
|
70
|
+
return "Target token is detected as a HoneyPot scam"
|
|
68
71
|
default:
|
|
69
72
|
return "Unknown error"
|
|
70
73
|
}
|
package/src/utils/coin.ts
CHANGED
|
@@ -116,8 +116,12 @@ export function buildInputCoin(
|
|
|
116
116
|
)
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
const targetCoin = txb.splitCoins(txb.object(masterCoin), [
|
|
120
|
+
txb.pure.u64(amount.toString()),
|
|
121
|
+
])
|
|
122
|
+
|
|
119
123
|
return {
|
|
120
|
-
targetCoin
|
|
124
|
+
targetCoin,
|
|
121
125
|
isMintZeroCoin: false,
|
|
122
126
|
targetCoinAmount: Number(amount.toString()),
|
|
123
127
|
}
|
package/tests/router.test.ts
CHANGED
|
@@ -33,9 +33,9 @@ describe("router module", () => {
|
|
|
33
33
|
keypair = buildTestAccount()
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const wallet = "
|
|
36
|
+
const wallet = keypair.getPublicKey().toSuiAddress()
|
|
37
|
+
console.log("wallet: ", wallet)
|
|
38
|
+
// const wallet = "0x02e39bddb06f617112595378fef741f523fbf22ea188cca99ecb61a9904dda2a"
|
|
39
39
|
|
|
40
40
|
const endpoint = aggregatorURL
|
|
41
41
|
|
|
@@ -110,9 +110,9 @@ describe("router module", () => {
|
|
|
110
110
|
|
|
111
111
|
test("Build router tx", async () => {
|
|
112
112
|
const byAmountIn = true
|
|
113
|
-
const amount = "
|
|
114
|
-
const target = "
|
|
115
|
-
const from = "
|
|
113
|
+
const amount = "30000000"
|
|
114
|
+
const target = "0x375f70cf2ae4c00bf37117d0c85a2c71545e6ee05c4a5c7d282cd66a4504b068::usdt::USDT"
|
|
115
|
+
const from = "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC"
|
|
116
116
|
|
|
117
117
|
const res = await client.findRouters({
|
|
118
118
|
from,
|
|
@@ -120,7 +120,7 @@ describe("router module", () => {
|
|
|
120
120
|
amount: new BN(amount),
|
|
121
121
|
byAmountIn,
|
|
122
122
|
depth: 3,
|
|
123
|
-
providers: ["
|
|
123
|
+
// providers: ["HAEDAL"],
|
|
124
124
|
})
|
|
125
125
|
|
|
126
126
|
if (res != null) {
|
|
@@ -345,4 +345,24 @@ describe("router module", () => {
|
|
|
345
345
|
const config = await client.getDeepbookV3Config()
|
|
346
346
|
console.log("config", config)
|
|
347
347
|
}, 60000)
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
test("Find router", async () => {
|
|
351
|
+
const amount = "4239267610000000000"
|
|
352
|
+
const res = await client.findRouters({
|
|
353
|
+
from: '0x2::sui::SUI',
|
|
354
|
+
target: '0x188c6239bda71ba5751990cc0271e91b6362c67bccf7aa381e018db7fe39c6d7::BUILD::BUILD',
|
|
355
|
+
amount: new BN(amount),
|
|
356
|
+
byAmountIn: true,
|
|
357
|
+
depth: 3,
|
|
358
|
+
splitCount: 1,
|
|
359
|
+
providers: ["CETUS"],
|
|
360
|
+
})
|
|
361
|
+
|
|
362
|
+
if (res != null) {
|
|
363
|
+
console.log(JSON.stringify(res, null, 2))
|
|
364
|
+
}
|
|
365
|
+
console.log("amount in", res?.amountIn.toString())
|
|
366
|
+
console.log("amount out", res?.amountOut.toString())
|
|
367
|
+
})
|
|
348
368
|
})
|