@cetusprotocol/aggregator-sdk 0.3.12 → 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/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +10 -7
- package/dist/index.mjs +10 -7
- package/dist/src/api.d.ts +2 -2
- package/dist/src/transaction/aftermath.d.ts +1 -1
- package/package.json +1 -1
- package/src/api.ts +2 -2
- package/src/transaction/aftermath.ts +5 -7
- package/src/transaction/swap.ts +10 -3
- package/tests/router.test.ts +9 -6
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
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
|
}
|
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
|
}
|
package/dist/src/api.d.ts
CHANGED
|
@@ -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
package/src/api.ts
CHANGED
|
@@ -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,8 +33,9 @@ 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
40
|
const endpoint = aggregatorURL
|
|
40
41
|
|
|
@@ -56,8 +57,8 @@ describe("router module", () => {
|
|
|
56
57
|
const byAmountIn = true
|
|
57
58
|
|
|
58
59
|
const res: any = await client.swapInPools({
|
|
59
|
-
from: testData.
|
|
60
|
-
target: testData.
|
|
60
|
+
from: testData.M_SUI,
|
|
61
|
+
target: testData.M_USDC,
|
|
61
62
|
amount: new BN(amount),
|
|
62
63
|
byAmountIn,
|
|
63
64
|
pools: [
|
|
@@ -65,10 +66,12 @@ describe("router module", () => {
|
|
|
65
66
|
],
|
|
66
67
|
})
|
|
67
68
|
|
|
68
|
-
console.log("res", res)
|
|
69
|
-
|
|
70
69
|
if (res != null) {
|
|
71
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
|
+
|
|
72
75
|
const txb = new Transaction()
|
|
73
76
|
await client.fastRouterSwap({
|
|
74
77
|
routers: res.routeData.routes,
|