@cetusprotocol/aggregator-sdk 0.3.11 → 0.3.13
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/bun.lockb +0 -0
- package/dist/index.d.mts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +17 -12
- package/dist/index.mjs +17 -12
- package/dist/src/api.d.ts +5 -3
- package/dist/src/transaction/aftermath.d.ts +1 -1
- package/package.json +2 -1
- package/src/api.ts +6 -4
- package/src/client.ts +5 -2
- package/src/transaction/aftermath.ts +5 -7
- package/src/transaction/swap.ts +10 -3
- package/tests/router.test.ts +12 -15
package/bun.lockb
CHANGED
|
Binary file
|
package/dist/index.d.mts
CHANGED
|
@@ -206,6 +206,8 @@ type ExtendedDetails = {
|
|
|
206
206
|
afterSqrtPrice?: string;
|
|
207
207
|
deepbookv3DeepFee?: number;
|
|
208
208
|
scallopScoinTreasury?: string;
|
|
209
|
+
haedalPmmBasePriceSeed?: string;
|
|
210
|
+
haedalPmmQuotePriceSeed?: string;
|
|
209
211
|
};
|
|
210
212
|
type Path = {
|
|
211
213
|
id: string;
|
|
@@ -214,10 +216,10 @@ type Path = {
|
|
|
214
216
|
from: string;
|
|
215
217
|
target: string;
|
|
216
218
|
feeRate: number;
|
|
217
|
-
amountIn:
|
|
218
|
-
amountOut:
|
|
219
|
-
extendedDetails?: ExtendedDetails;
|
|
219
|
+
amountIn: string;
|
|
220
|
+
amountOut: string;
|
|
220
221
|
version?: string;
|
|
222
|
+
extendedDetails?: ExtendedDetails;
|
|
221
223
|
};
|
|
222
224
|
type Router = {
|
|
223
225
|
path: Path[];
|
package/dist/index.d.ts
CHANGED
|
@@ -206,6 +206,8 @@ type ExtendedDetails = {
|
|
|
206
206
|
afterSqrtPrice?: string;
|
|
207
207
|
deepbookv3DeepFee?: number;
|
|
208
208
|
scallopScoinTreasury?: string;
|
|
209
|
+
haedalPmmBasePriceSeed?: string;
|
|
210
|
+
haedalPmmQuotePriceSeed?: string;
|
|
209
211
|
};
|
|
210
212
|
type Path = {
|
|
211
213
|
id: string;
|
|
@@ -214,10 +216,10 @@ type Path = {
|
|
|
214
216
|
from: string;
|
|
215
217
|
target: string;
|
|
216
218
|
feeRate: number;
|
|
217
|
-
amountIn:
|
|
218
|
-
amountOut:
|
|
219
|
-
extendedDetails?: ExtendedDetails;
|
|
219
|
+
amountIn: string;
|
|
220
|
+
amountOut: string;
|
|
220
221
|
version?: string;
|
|
222
|
+
extendedDetails?: ExtendedDetails;
|
|
221
223
|
};
|
|
222
224
|
type Router = {
|
|
223
225
|
path: Path[];
|
package/dist/index.js
CHANGED
|
@@ -4998,9 +4998,7 @@ var Aftermath = class {
|
|
|
4998
4998
|
this.referrealVault = "0x35d35b0e5b177593d8c3a801462485572fc30861e6ce96a55af6dc4730709278";
|
|
4999
4999
|
}
|
|
5000
5000
|
amountLimit(exportAmountOut) {
|
|
5001
|
-
return
|
|
5002
|
-
new import_bn.default(exportAmountOut).mul(new import_bn.default(this.slippage)).div(new import_bn.default("1000000000000000000")).toString()
|
|
5003
|
-
);
|
|
5001
|
+
return new import_bn.default(exportAmountOut).mul(new import_bn.default(this.slippage)).div(new import_bn.default("1000000000000000000")).toString();
|
|
5004
5002
|
}
|
|
5005
5003
|
swap(client, txb, path, inputCoin) {
|
|
5006
5004
|
return __async(this, null, function* () {
|
|
@@ -5847,6 +5845,7 @@ function swapInPools(client, params, sender, env) {
|
|
|
5847
5845
|
}
|
|
5848
5846
|
}
|
|
5849
5847
|
const event = valueData[tempIndex].parsedJson.data;
|
|
5848
|
+
console.log("event", JSON.stringify(event, null, 2));
|
|
5850
5849
|
const currentSqrtPrice = event.step_results[0].current_sqrt_price;
|
|
5851
5850
|
const [decimalA, decimalB] = yield Promise.all([
|
|
5852
5851
|
client.getCoinMetadata({ coinType: coinA }).then((metadata) => metadata == null ? void 0 : metadata.decimals),
|
|
@@ -5863,9 +5862,13 @@ function swapInPools(client, params, sender, env) {
|
|
|
5863
5862
|
decimalA,
|
|
5864
5863
|
decimalB
|
|
5865
5864
|
);
|
|
5865
|
+
const feeRate = Number(event.fee_rate) / 1e6;
|
|
5866
|
+
const pureAmountIn = new import_bn4.BN((_b = event.amount_in) != null ? _b : 0);
|
|
5867
|
+
const feeAmount = new import_bn4.BN((_c = event.fee_amount) != null ? _c : 0);
|
|
5868
|
+
const amountIn = pureAmountIn.add(feeAmount);
|
|
5866
5869
|
const routeData = {
|
|
5867
|
-
amountIn
|
|
5868
|
-
amountOut: new import_bn4.BN((
|
|
5870
|
+
amountIn,
|
|
5871
|
+
amountOut: new import_bn4.BN((_d = event.amount_out) != null ? _d : 0),
|
|
5869
5872
|
routes: [
|
|
5870
5873
|
{
|
|
5871
5874
|
path: [
|
|
@@ -5875,7 +5878,7 @@ function swapInPools(client, params, sender, env) {
|
|
|
5875
5878
|
provider: "CETUS",
|
|
5876
5879
|
from: fromCoin,
|
|
5877
5880
|
target: targetCoin,
|
|
5878
|
-
feeRate
|
|
5881
|
+
feeRate,
|
|
5879
5882
|
amountIn: event.amount_in,
|
|
5880
5883
|
amountOut: event.amount_out,
|
|
5881
5884
|
extendedDetails: {
|
|
@@ -5883,7 +5886,7 @@ function swapInPools(client, params, sender, env) {
|
|
|
5883
5886
|
}
|
|
5884
5887
|
}
|
|
5885
5888
|
],
|
|
5886
|
-
amountIn
|
|
5889
|
+
amountIn,
|
|
5887
5890
|
amountOut: new import_bn4.BN((_e = event.amount_out) != null ? _e : 0),
|
|
5888
5891
|
initialPrice
|
|
5889
5892
|
}
|
|
@@ -6434,9 +6437,9 @@ var AggregatorClient9 = class {
|
|
|
6434
6437
|
// Include deepbookv3, scallop, bluefin
|
|
6435
6438
|
publishedAtV2() {
|
|
6436
6439
|
if (this.env === 0 /* Mainnet */) {
|
|
6437
|
-
return "
|
|
6440
|
+
return "0x81ade554cb24a7564ca43a4bfb7381b08d9e5c5f375162c95215b696ab903502";
|
|
6438
6441
|
} else {
|
|
6439
|
-
return "
|
|
6442
|
+
return "0xabb6a81c8a216828e317719e06125de5bb2cb0fe8f9916ff8c023ca5be224c78";
|
|
6440
6443
|
}
|
|
6441
6444
|
}
|
|
6442
6445
|
deepbookv3DeepFeeType() {
|
|
@@ -6568,7 +6571,7 @@ function parseRouterResponse(data) {
|
|
|
6568
6571
|
routes: data.routes.map((route) => {
|
|
6569
6572
|
return {
|
|
6570
6573
|
path: route.path.map((path) => {
|
|
6571
|
-
var _a, _b, _c, _d, _e;
|
|
6574
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
6572
6575
|
let version;
|
|
6573
6576
|
if (path.provider === AFTERMATH) {
|
|
6574
6577
|
version = path.extended_details.aftermath_pool_flatness === 0 ? "v2" : "v3";
|
|
@@ -6580,7 +6583,9 @@ function parseRouterResponse(data) {
|
|
|
6580
6583
|
turbosFeeType: (_b = path.extended_details) == null ? void 0 : _b.turbos_fee_type,
|
|
6581
6584
|
afterSqrtPrice: (_c = path.extended_details) == null ? void 0 : _c.after_sqrt_price,
|
|
6582
6585
|
deepbookv3DeepFee: (_d = path.extended_details) == null ? void 0 : _d.deepbookv3_deep_fee,
|
|
6583
|
-
scallopScoinTreasury: (_e = path.extended_details) == null ? void 0 : _e.scallop_scoin_treasury
|
|
6586
|
+
scallopScoinTreasury: (_e = path.extended_details) == null ? void 0 : _e.scallop_scoin_treasury,
|
|
6587
|
+
haedalPmmBasePriceSeed: (_f = path.extended_details) == null ? void 0 : _f.haedal_pmm_base_price_seed,
|
|
6588
|
+
haedalPmmQuotePriceSeed: (_g = path.extended_details) == null ? void 0 : _g.haedal_pmm_quote_price_seed
|
|
6584
6589
|
};
|
|
6585
6590
|
}
|
|
6586
6591
|
return {
|
|
@@ -6722,7 +6727,7 @@ function getRouter(endpoint, params) {
|
|
|
6722
6727
|
url += `&providers=${providers.join(",")}`;
|
|
6723
6728
|
}
|
|
6724
6729
|
}
|
|
6725
|
-
url += "&v=
|
|
6730
|
+
url += "&v=1000312";
|
|
6726
6731
|
const response = yield fetch(url);
|
|
6727
6732
|
return response;
|
|
6728
6733
|
} catch (error) {
|
package/dist/index.mjs
CHANGED
|
@@ -4996,9 +4996,7 @@ var Aftermath = class {
|
|
|
4996
4996
|
this.referrealVault = "0x35d35b0e5b177593d8c3a801462485572fc30861e6ce96a55af6dc4730709278";
|
|
4997
4997
|
}
|
|
4998
4998
|
amountLimit(exportAmountOut) {
|
|
4999
|
-
return
|
|
5000
|
-
new import_bn.default(exportAmountOut).mul(new import_bn.default(this.slippage)).div(new import_bn.default("1000000000000000000")).toString()
|
|
5001
|
-
);
|
|
4999
|
+
return new import_bn.default(exportAmountOut).mul(new import_bn.default(this.slippage)).div(new import_bn.default("1000000000000000000")).toString();
|
|
5002
5000
|
}
|
|
5003
5001
|
swap(client, txb, path, inputCoin) {
|
|
5004
5002
|
return __async(this, null, function* () {
|
|
@@ -5845,6 +5843,7 @@ function swapInPools(client, params, sender, env) {
|
|
|
5845
5843
|
}
|
|
5846
5844
|
}
|
|
5847
5845
|
const event = valueData[tempIndex].parsedJson.data;
|
|
5846
|
+
console.log("event", JSON.stringify(event, null, 2));
|
|
5848
5847
|
const currentSqrtPrice = event.step_results[0].current_sqrt_price;
|
|
5849
5848
|
const [decimalA, decimalB] = yield Promise.all([
|
|
5850
5849
|
client.getCoinMetadata({ coinType: coinA }).then((metadata) => metadata == null ? void 0 : metadata.decimals),
|
|
@@ -5861,9 +5860,13 @@ function swapInPools(client, params, sender, env) {
|
|
|
5861
5860
|
decimalA,
|
|
5862
5861
|
decimalB
|
|
5863
5862
|
);
|
|
5863
|
+
const feeRate = Number(event.fee_rate) / 1e6;
|
|
5864
|
+
const pureAmountIn = new import_bn4.BN((_b = event.amount_in) != null ? _b : 0);
|
|
5865
|
+
const feeAmount = new import_bn4.BN((_c = event.fee_amount) != null ? _c : 0);
|
|
5866
|
+
const amountIn = pureAmountIn.add(feeAmount);
|
|
5864
5867
|
const routeData = {
|
|
5865
|
-
amountIn
|
|
5866
|
-
amountOut: new import_bn4.BN((
|
|
5868
|
+
amountIn,
|
|
5869
|
+
amountOut: new import_bn4.BN((_d = event.amount_out) != null ? _d : 0),
|
|
5867
5870
|
routes: [
|
|
5868
5871
|
{
|
|
5869
5872
|
path: [
|
|
@@ -5873,7 +5876,7 @@ function swapInPools(client, params, sender, env) {
|
|
|
5873
5876
|
provider: "CETUS",
|
|
5874
5877
|
from: fromCoin,
|
|
5875
5878
|
target: targetCoin,
|
|
5876
|
-
feeRate
|
|
5879
|
+
feeRate,
|
|
5877
5880
|
amountIn: event.amount_in,
|
|
5878
5881
|
amountOut: event.amount_out,
|
|
5879
5882
|
extendedDetails: {
|
|
@@ -5881,7 +5884,7 @@ function swapInPools(client, params, sender, env) {
|
|
|
5881
5884
|
}
|
|
5882
5885
|
}
|
|
5883
5886
|
],
|
|
5884
|
-
amountIn
|
|
5887
|
+
amountIn,
|
|
5885
5888
|
amountOut: new import_bn4.BN((_e = event.amount_out) != null ? _e : 0),
|
|
5886
5889
|
initialPrice
|
|
5887
5890
|
}
|
|
@@ -6432,9 +6435,9 @@ var AggregatorClient9 = class {
|
|
|
6432
6435
|
// Include deepbookv3, scallop, bluefin
|
|
6433
6436
|
publishedAtV2() {
|
|
6434
6437
|
if (this.env === 0 /* Mainnet */) {
|
|
6435
|
-
return "
|
|
6438
|
+
return "0x81ade554cb24a7564ca43a4bfb7381b08d9e5c5f375162c95215b696ab903502";
|
|
6436
6439
|
} else {
|
|
6437
|
-
return "
|
|
6440
|
+
return "0xabb6a81c8a216828e317719e06125de5bb2cb0fe8f9916ff8c023ca5be224c78";
|
|
6438
6441
|
}
|
|
6439
6442
|
}
|
|
6440
6443
|
deepbookv3DeepFeeType() {
|
|
@@ -6566,7 +6569,7 @@ function parseRouterResponse(data) {
|
|
|
6566
6569
|
routes: data.routes.map((route) => {
|
|
6567
6570
|
return {
|
|
6568
6571
|
path: route.path.map((path) => {
|
|
6569
|
-
var _a, _b, _c, _d, _e;
|
|
6572
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
6570
6573
|
let version;
|
|
6571
6574
|
if (path.provider === AFTERMATH) {
|
|
6572
6575
|
version = path.extended_details.aftermath_pool_flatness === 0 ? "v2" : "v3";
|
|
@@ -6578,7 +6581,9 @@ function parseRouterResponse(data) {
|
|
|
6578
6581
|
turbosFeeType: (_b = path.extended_details) == null ? void 0 : _b.turbos_fee_type,
|
|
6579
6582
|
afterSqrtPrice: (_c = path.extended_details) == null ? void 0 : _c.after_sqrt_price,
|
|
6580
6583
|
deepbookv3DeepFee: (_d = path.extended_details) == null ? void 0 : _d.deepbookv3_deep_fee,
|
|
6581
|
-
scallopScoinTreasury: (_e = path.extended_details) == null ? void 0 : _e.scallop_scoin_treasury
|
|
6584
|
+
scallopScoinTreasury: (_e = path.extended_details) == null ? void 0 : _e.scallop_scoin_treasury,
|
|
6585
|
+
haedalPmmBasePriceSeed: (_f = path.extended_details) == null ? void 0 : _f.haedal_pmm_base_price_seed,
|
|
6586
|
+
haedalPmmQuotePriceSeed: (_g = path.extended_details) == null ? void 0 : _g.haedal_pmm_quote_price_seed
|
|
6582
6587
|
};
|
|
6583
6588
|
}
|
|
6584
6589
|
return {
|
|
@@ -6720,7 +6725,7 @@ function getRouter(endpoint, params) {
|
|
|
6720
6725
|
url += `&providers=${providers.join(",")}`;
|
|
6721
6726
|
}
|
|
6722
6727
|
}
|
|
6723
|
-
url += "&v=
|
|
6728
|
+
url += "&v=1000312";
|
|
6724
6729
|
const response = yield fetch(url);
|
|
6725
6730
|
return response;
|
|
6726
6731
|
} catch (error) {
|
package/dist/src/api.d.ts
CHANGED
|
@@ -25,6 +25,8 @@ export type ExtendedDetails = {
|
|
|
25
25
|
afterSqrtPrice?: string;
|
|
26
26
|
deepbookv3DeepFee?: number;
|
|
27
27
|
scallopScoinTreasury?: string;
|
|
28
|
+
haedalPmmBasePriceSeed?: string;
|
|
29
|
+
haedalPmmQuotePriceSeed?: string;
|
|
28
30
|
};
|
|
29
31
|
export type Path = {
|
|
30
32
|
id: string;
|
|
@@ -33,10 +35,10 @@ export type Path = {
|
|
|
33
35
|
from: string;
|
|
34
36
|
target: string;
|
|
35
37
|
feeRate: number;
|
|
36
|
-
amountIn:
|
|
37
|
-
amountOut:
|
|
38
|
-
extendedDetails?: ExtendedDetails;
|
|
38
|
+
amountIn: string;
|
|
39
|
+
amountOut: string;
|
|
39
40
|
version?: string;
|
|
41
|
+
extendedDetails?: ExtendedDetails;
|
|
40
42
|
};
|
|
41
43
|
export type Router = {
|
|
42
44
|
path: Path[];
|
|
@@ -8,6 +8,6 @@ export declare class Aftermath implements Dex {
|
|
|
8
8
|
private insuranceFund;
|
|
9
9
|
private referrealVault;
|
|
10
10
|
constructor(env: Env);
|
|
11
|
-
amountLimit(exportAmountOut:
|
|
11
|
+
amountLimit(exportAmountOut: string): string;
|
|
12
12
|
swap(client: AggregatorClient, txb: Transaction, path: Path, inputCoin: TransactionObjectArgument): Promise<TransactionObjectArgument>;
|
|
13
13
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cetusprotocol/aggregator-sdk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.13",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"@babel/preset-typescript": "^7.24.1",
|
|
29
29
|
"@jest/globals": "^29.7.0",
|
|
30
30
|
"@mysten/sui": "^1.6.0",
|
|
31
|
+
"@pythnetwork/pyth-sui-js": "^2.1.0",
|
|
31
32
|
"@types/jest": "^29.5.12",
|
|
32
33
|
"@types/node": "^20.12.12",
|
|
33
34
|
"babel-jest": "^29.7.0",
|
package/src/api.ts
CHANGED
|
@@ -35,6 +35,8 @@ export type ExtendedDetails = {
|
|
|
35
35
|
afterSqrtPrice?: string
|
|
36
36
|
deepbookv3DeepFee?: number
|
|
37
37
|
scallopScoinTreasury?: string
|
|
38
|
+
haedalPmmBasePriceSeed?: string
|
|
39
|
+
haedalPmmQuotePriceSeed?: string
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
export type Path = {
|
|
@@ -44,10 +46,10 @@ export type Path = {
|
|
|
44
46
|
from: string
|
|
45
47
|
target: string
|
|
46
48
|
feeRate: number
|
|
47
|
-
amountIn:
|
|
48
|
-
amountOut:
|
|
49
|
-
extendedDetails?: ExtendedDetails
|
|
49
|
+
amountIn: string
|
|
50
|
+
amountOut: string
|
|
50
51
|
version?: string
|
|
52
|
+
extendedDetails?: ExtendedDetails
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
export type Router = {
|
|
@@ -168,7 +170,7 @@ async function getRouter(endpoint: string, params: FindRouterParams) {
|
|
|
168
170
|
}
|
|
169
171
|
|
|
170
172
|
// set newest sdk version
|
|
171
|
-
url += "&v=
|
|
173
|
+
url += "&v=1000312"
|
|
172
174
|
|
|
173
175
|
const response = await fetch(url)
|
|
174
176
|
return response
|
package/src/client.ts
CHANGED
|
@@ -416,9 +416,10 @@ export class AggregatorClient {
|
|
|
416
416
|
// return "0x43811be4677f5a5de7bf2dac740c10abddfaa524aee6b18e910eeadda8a2f6ae" // version 1, deepbookv3
|
|
417
417
|
// return "0x6d70ffa7aa3f924c3f0b573d27d29895a0ee666aaff821073f75cb14af7fd01a" // version 3, deepbookv3 & scallop
|
|
418
418
|
// return "0x16d9418726c26d8cb4ce8c9dd75917fa9b1c7bf47d38d7a1a22603135f0f2a56" // version 4, add suilend
|
|
419
|
-
return "0x3b6d71bdeb8ce5b06febfd3cfc29ecd60d50da729477c8b8038ecdae34541b91"
|
|
419
|
+
// return "0x3b6d71bdeb8ce5b06febfd3cfc29ecd60d50da729477c8b8038ecdae34541b91" // version 5, add bluefin
|
|
420
|
+
return "0x81ade554cb24a7564ca43a4bfb7381b08d9e5c5f375162c95215b696ab903502" // version 6, force upgrade scallop
|
|
420
421
|
} else {
|
|
421
|
-
return "
|
|
422
|
+
return "0xabb6a81c8a216828e317719e06125de5bb2cb0fe8f9916ff8c023ca5be224c78"
|
|
422
423
|
}
|
|
423
424
|
}
|
|
424
425
|
|
|
@@ -585,6 +586,8 @@ export function parseRouterResponse(data: any): RouterData {
|
|
|
585
586
|
deepbookv3DeepFee: path.extended_details?.deepbookv3_deep_fee,
|
|
586
587
|
scallopScoinTreasury:
|
|
587
588
|
path.extended_details?.scallop_scoin_treasury,
|
|
589
|
+
haedalPmmBasePriceSeed: path.extended_details?.haedal_pmm_base_price_seed,
|
|
590
|
+
haedalPmmQuotePriceSeed: path.extended_details?.haedal_pmm_quote_price_seed,
|
|
588
591
|
}
|
|
589
592
|
}
|
|
590
593
|
|
|
@@ -31,13 +31,11 @@ export class Aftermath implements Dex {
|
|
|
31
31
|
"0x35d35b0e5b177593d8c3a801462485572fc30861e6ce96a55af6dc4730709278"
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
amountLimit(exportAmountOut:
|
|
35
|
-
return
|
|
36
|
-
new BN(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
.toString()
|
|
40
|
-
)
|
|
34
|
+
amountLimit(exportAmountOut: string): string {
|
|
35
|
+
return new BN(exportAmountOut)
|
|
36
|
+
.mul(new BN(this.slippage))
|
|
37
|
+
.div(new BN("1000000000000000000"))
|
|
38
|
+
.toString()
|
|
41
39
|
}
|
|
42
40
|
|
|
43
41
|
async swap(
|
package/src/transaction/swap.ts
CHANGED
|
@@ -99,6 +99,8 @@ export async function swapInPools(
|
|
|
99
99
|
|
|
100
100
|
const event = valueData[tempIndex].parsedJson.data
|
|
101
101
|
|
|
102
|
+
console.log("event", JSON.stringify(event, null, 2))
|
|
103
|
+
|
|
102
104
|
const currentSqrtPrice = event.step_results[0].current_sqrt_price
|
|
103
105
|
|
|
104
106
|
const [decimalA, decimalB] = await Promise.all([
|
|
@@ -122,8 +124,13 @@ export async function swapInPools(
|
|
|
122
124
|
decimalB!
|
|
123
125
|
)
|
|
124
126
|
|
|
127
|
+
const feeRate = Number(event.fee_rate) / 1000000
|
|
128
|
+
const pureAmountIn = new BN(event.amount_in ?? 0)
|
|
129
|
+
const feeAmount = new BN(event.fee_amount ?? 0)
|
|
130
|
+
const amountIn = pureAmountIn.add(feeAmount)
|
|
131
|
+
|
|
125
132
|
const routeData = {
|
|
126
|
-
amountIn:
|
|
133
|
+
amountIn: amountIn,
|
|
127
134
|
amountOut: new BN(event.amount_out ?? 0),
|
|
128
135
|
routes: [
|
|
129
136
|
{
|
|
@@ -134,7 +141,7 @@ export async function swapInPools(
|
|
|
134
141
|
provider: "CETUS",
|
|
135
142
|
from: fromCoin,
|
|
136
143
|
target: targetCoin,
|
|
137
|
-
feeRate
|
|
144
|
+
feeRate,
|
|
138
145
|
amountIn: event.amount_in,
|
|
139
146
|
amountOut: event.amount_out,
|
|
140
147
|
extendedDetails: {
|
|
@@ -142,7 +149,7 @@ export async function swapInPools(
|
|
|
142
149
|
},
|
|
143
150
|
},
|
|
144
151
|
],
|
|
145
|
-
amountIn:
|
|
152
|
+
amountIn: amountIn,
|
|
146
153
|
amountOut: new BN(event.amount_out ?? 0),
|
|
147
154
|
initialPrice,
|
|
148
155
|
},
|
package/tests/router.test.ts
CHANGED
|
@@ -33,19 +33,15 @@ describe("router module", () => {
|
|
|
33
33
|
keypair = buildTestAccount()
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
const wallet = keypair.getPublicKey().toSuiAddress()
|
|
37
|
-
console.log("wallet: ", wallet)
|
|
36
|
+
// const wallet = keypair.getPublicKey().toSuiAddress()
|
|
37
|
+
// console.log("wallet: ", wallet)
|
|
38
|
+
const wallet = "0x326ce9894f08dcaa337fa232641cc34db957aec9ff6614c1186bc9a7508df0bb"
|
|
38
39
|
|
|
39
|
-
// // const endpoint =
|
|
40
|
-
// // "https://api-sui-cloudfront.cetus.zone/router_v2/find_routes"
|
|
41
40
|
const endpoint = aggregatorURL
|
|
42
41
|
|
|
43
42
|
const suiClient = new SuiClient({
|
|
44
43
|
url: fullNodeURL,
|
|
45
44
|
})
|
|
46
|
-
// const suiClient = new SuiClient({
|
|
47
|
-
// url: "https://fullnode.testnet.sui.io:443",
|
|
48
|
-
// })
|
|
49
45
|
|
|
50
46
|
client = new AggregatorClient(endpoint, wallet, suiClient, Env.Mainnet)
|
|
51
47
|
})
|
|
@@ -61,8 +57,8 @@ describe("router module", () => {
|
|
|
61
57
|
const byAmountIn = true
|
|
62
58
|
|
|
63
59
|
const res: any = await client.swapInPools({
|
|
64
|
-
from: testData.
|
|
65
|
-
target: testData.
|
|
60
|
+
from: testData.M_SUI,
|
|
61
|
+
target: testData.M_USDC,
|
|
66
62
|
amount: new BN(amount),
|
|
67
63
|
byAmountIn,
|
|
68
64
|
pools: [
|
|
@@ -70,10 +66,12 @@ describe("router module", () => {
|
|
|
70
66
|
],
|
|
71
67
|
})
|
|
72
68
|
|
|
73
|
-
console.log("res", res)
|
|
74
|
-
|
|
75
69
|
if (res != null) {
|
|
76
70
|
console.log(JSON.stringify(res, null, 2))
|
|
71
|
+
|
|
72
|
+
console.log("amount in", res.routeData.amountIn.toString())
|
|
73
|
+
console.log("amount out", res.routeData.amountOut.toString())
|
|
74
|
+
|
|
77
75
|
const txb = new Transaction()
|
|
78
76
|
await client.fastRouterSwap({
|
|
79
77
|
routers: res.routeData.routes,
|
|
@@ -112,9 +110,9 @@ describe("router module", () => {
|
|
|
112
110
|
|
|
113
111
|
test("Build router tx", async () => {
|
|
114
112
|
const byAmountIn = true
|
|
115
|
-
const amount = "
|
|
113
|
+
const amount = "3574839"
|
|
114
|
+
const target = "0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI"
|
|
116
115
|
const from = "0x2::sui::SUI"
|
|
117
|
-
const target = "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN"
|
|
118
116
|
|
|
119
117
|
const res = await client.findRouters({
|
|
120
118
|
from,
|
|
@@ -122,7 +120,7 @@ describe("router module", () => {
|
|
|
122
120
|
amount: new BN(amount),
|
|
123
121
|
byAmountIn,
|
|
124
122
|
depth: 3,
|
|
125
|
-
providers: ["
|
|
123
|
+
providers: ["SCALLOP"],
|
|
126
124
|
})
|
|
127
125
|
|
|
128
126
|
if (res != null) {
|
|
@@ -154,7 +152,6 @@ describe("router module", () => {
|
|
|
154
152
|
for (const event of result.events) {
|
|
155
153
|
console.log("event", JSON.stringify(event, null, 2))
|
|
156
154
|
}
|
|
157
|
-
console.log("txb", )
|
|
158
155
|
|
|
159
156
|
// if (result.effects.status.status === "success") {
|
|
160
157
|
// // console.log("Sim exec transaction success")
|