@cetusprotocol/aggregator-sdk 0.1.2 → 0.2.1
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 +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +234 -174
- package/dist/index.mjs +231 -174
- package/dist/src/client.d.ts +1 -0
- package/dist/src/transaction/flowx_v3.d.ts +8 -0
- package/dist/src/utils/index.d.ts +1 -0
- package/dist/src/utils/msafe.d.ts +2 -0
- package/package.json +1 -1
- package/src/client.ts +4 -0
- package/src/transaction/flowx_v3.ts +50 -0
- package/src/transaction/haedal.ts +0 -7
- package/src/utils/index.ts +1 -0
- package/src/utils/msafe.ts +31 -0
- package/tests/router.test.ts +7 -8
package/dist/src/client.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export declare const CETUS = "CETUS";
|
|
|
8
8
|
export declare const DEEPBOOKV2 = "DEEPBOOK";
|
|
9
9
|
export declare const KRIYA = "KRIYA";
|
|
10
10
|
export declare const FLOWXV2 = "FLOWX";
|
|
11
|
+
export declare const FLOWXV3 = "FLOWXV3";
|
|
11
12
|
export declare const KRIYAV3 = "KRIYAV3";
|
|
12
13
|
export declare const TURBOS = "TURBOS";
|
|
13
14
|
export declare const AFTERMATH = "AFTERMATH";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
2
|
+
import { AggregatorClient, Dex, Env, Path } from "..";
|
|
3
|
+
export declare class FlowxV3 implements Dex {
|
|
4
|
+
private versioned;
|
|
5
|
+
private poolRegistry;
|
|
6
|
+
constructor(env: Env);
|
|
7
|
+
swap(client: AggregatorClient, txb: Transaction, path: Path, inputCoin: TransactionObjectArgument): Promise<TransactionObjectArgument>;
|
|
8
|
+
}
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -30,11 +30,13 @@ import { KriyaV3 } from "./transaction/kriya_v3"
|
|
|
30
30
|
import { Haedal } from "./transaction/haedal"
|
|
31
31
|
import { Afsui } from "./transaction/afsui"
|
|
32
32
|
import { Volo } from "./transaction/volo"
|
|
33
|
+
import { FlowxV3 } from "./transaction/flowx_v3"
|
|
33
34
|
|
|
34
35
|
export const CETUS = "CETUS"
|
|
35
36
|
export const DEEPBOOKV2 = "DEEPBOOK"
|
|
36
37
|
export const KRIYA = "KRIYA"
|
|
37
38
|
export const FLOWXV2 = "FLOWX"
|
|
39
|
+
export const FLOWXV3 = "FLOWXV3"
|
|
38
40
|
export const KRIYAV3 = "KRIYAV3"
|
|
39
41
|
export const TURBOS = "TURBOS"
|
|
40
42
|
export const AFTERMATH = "AFTERMATH"
|
|
@@ -388,6 +390,8 @@ export class AggregatorClient {
|
|
|
388
390
|
return new KriyaV3(this.env)
|
|
389
391
|
case FLOWXV2:
|
|
390
392
|
return new FlowxV2(this.env)
|
|
393
|
+
case FLOWXV3:
|
|
394
|
+
return new FlowxV3(this.env)
|
|
391
395
|
case TURBOS:
|
|
392
396
|
return new Turbos(this.env)
|
|
393
397
|
case AFTERMATH:
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Transaction,
|
|
3
|
+
TransactionObjectArgument,
|
|
4
|
+
} from "@mysten/sui/transactions"
|
|
5
|
+
import { AggregatorClient, CLOCK_ADDRESS, Dex, Env, Path } from ".."
|
|
6
|
+
|
|
7
|
+
export class FlowxV3 implements Dex {
|
|
8
|
+
private versioned: string
|
|
9
|
+
private poolRegistry: string
|
|
10
|
+
|
|
11
|
+
constructor(env: Env) {
|
|
12
|
+
if (env !== Env.Mainnet) {
|
|
13
|
+
throw new Error("Flowx clmm only supported on mainnet")
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
this.versioned =
|
|
17
|
+
"0x67624a1533b5aff5d0dfcf5e598684350efd38134d2d245f475524c03a64e656"
|
|
18
|
+
this.poolRegistry =
|
|
19
|
+
"0x27565d24a4cd51127ac90e4074a841bbe356cca7bf5759ddc14a975be1632abc"
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async swap(
|
|
23
|
+
client: AggregatorClient,
|
|
24
|
+
txb: Transaction,
|
|
25
|
+
path: Path,
|
|
26
|
+
inputCoin: TransactionObjectArgument
|
|
27
|
+
): Promise<TransactionObjectArgument> {
|
|
28
|
+
const { direction, from, target } = path
|
|
29
|
+
|
|
30
|
+
const [func, coinAType, coinBType] = direction
|
|
31
|
+
? ["swap_a2b", from, target]
|
|
32
|
+
: ["swap_b2a", target, from]
|
|
33
|
+
|
|
34
|
+
const args = [
|
|
35
|
+
txb.object(this.poolRegistry),
|
|
36
|
+
txb.pure.u64(path.feeRate * 1000000),
|
|
37
|
+
inputCoin,
|
|
38
|
+
txb.object(this.versioned),
|
|
39
|
+
txb.object(CLOCK_ADDRESS),
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
const res = txb.moveCall({
|
|
43
|
+
target: `${client.publishedAt()}::flowx_clmm::${func}`,
|
|
44
|
+
typeArguments: [coinAType, coinBType],
|
|
45
|
+
arguments: args,
|
|
46
|
+
}) as TransactionObjectArgument
|
|
47
|
+
|
|
48
|
+
return res
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
TransactionObjectArgument,
|
|
4
4
|
} from "@mysten/sui/transactions"
|
|
5
5
|
import { AggregatorClient, Dex, Env, Path } from ".."
|
|
6
|
-
import { SUI_SYSTEM_ADDRESS } from "@mysten/sui/utils"
|
|
7
6
|
|
|
8
7
|
export class Haedal implements Dex {
|
|
9
8
|
constructor(env: Env) {
|
|
@@ -19,17 +18,11 @@ export class Haedal implements Dex {
|
|
|
19
18
|
inputCoin: TransactionObjectArgument
|
|
20
19
|
): Promise<TransactionObjectArgument> {
|
|
21
20
|
const { direction } = path
|
|
22
|
-
|
|
23
21
|
if (!direction) {
|
|
24
22
|
throw new Error("Haedal not support b2a swap")
|
|
25
23
|
}
|
|
26
|
-
|
|
27
24
|
const func = "swap_a2b"
|
|
28
|
-
|
|
29
|
-
console.log("haedal path id", path.id)
|
|
30
|
-
|
|
31
25
|
const args = [txb.object(path.id), txb.object("0x5"), inputCoin]
|
|
32
|
-
|
|
33
26
|
const res = txb.moveCall({
|
|
34
27
|
target: `${client.publishedAt()}::haedal::${func}`,
|
|
35
28
|
typeArguments: [],
|
package/src/utils/index.ts
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
|
|
2
|
+
import BN from 'bn.js'
|
|
3
|
+
import Decimal from "decimal.js"
|
|
4
|
+
|
|
5
|
+
export const dealWithFastRouterSwapParamsForMsafe = (data: any) => {
|
|
6
|
+
const result =data.map((route: any) => {
|
|
7
|
+
return {
|
|
8
|
+
...route,
|
|
9
|
+
amountIn: route.amountIn.toString(),
|
|
10
|
+
amountOut: route.amountOut.toString(),
|
|
11
|
+
initialPrice: route.initialPrice.toString(),
|
|
12
|
+
path: route.path
|
|
13
|
+
}
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
return result
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const restituteMsafeFastRouterSwapParams = (data: any) => {
|
|
20
|
+
const result =data.map((route: any) => {
|
|
21
|
+
return {
|
|
22
|
+
...route,
|
|
23
|
+
amountIn: new BN(route.amountIn),
|
|
24
|
+
amountOut: new BN(route.amountOut),
|
|
25
|
+
initialPrice: new Decimal(route.initialPrice.toString()),
|
|
26
|
+
path: route.path
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
return result
|
|
31
|
+
}
|
package/tests/router.test.ts
CHANGED
|
@@ -33,14 +33,14 @@ describe("router module", () => {
|
|
|
33
33
|
keypair = buildTestAccount()
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
const wallet = keypair.getPublicKey().toSuiAddress()
|
|
36
|
+
// const wallet = keypair.getPublicKey().toSuiAddress()
|
|
37
37
|
|
|
38
38
|
// console.log("wallet", wallet, "\n", wallet.toString())
|
|
39
39
|
|
|
40
|
+
const wallet =
|
|
41
|
+
"0xfba94aa36e93ccc7d84a6a57040fc51983223f1b522a8d0be3c3bf2c98977ebb"
|
|
40
42
|
// const wallet =
|
|
41
|
-
//
|
|
42
|
-
// const wallet =
|
|
43
|
-
// "0xa459702162b73204eed77420d93d9453b7a7b893a0edea1e268607cf7fa76e03"
|
|
43
|
+
// "0xa459702162b73204eed77420d93d9453b7a7b893a0edea1e268607cf7fa76e03"
|
|
44
44
|
// const wallet =
|
|
45
45
|
// "0xaabf2fedcb36146db164bec930b74a47969c4df98216e049342a3c49b6d11580"
|
|
46
46
|
// const wallet = "0x410456cfc689666936b6bf80fbec958b69499b9f7183ecba07de577c17248a44"
|
|
@@ -77,7 +77,7 @@ describe("router module", () => {
|
|
|
77
77
|
})
|
|
78
78
|
|
|
79
79
|
test("Downgrade swap in route", async () => {
|
|
80
|
-
const amount =
|
|
80
|
+
const amount = 100000
|
|
81
81
|
const byAmountIn = false
|
|
82
82
|
|
|
83
83
|
const res: any = await client.swapInPools({
|
|
@@ -139,8 +139,7 @@ describe("router module", () => {
|
|
|
139
139
|
// const target =
|
|
140
140
|
// "0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc::afsui::AFSUI"
|
|
141
141
|
|
|
142
|
-
const target =
|
|
143
|
-
"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT"
|
|
142
|
+
const target = M_USDC
|
|
144
143
|
|
|
145
144
|
const res = await client.findRouters({
|
|
146
145
|
from,
|
|
@@ -156,7 +155,7 @@ describe("router module", () => {
|
|
|
156
155
|
// "KRIYA",
|
|
157
156
|
// "KRIYAV3",
|
|
158
157
|
// "TURBOS",
|
|
159
|
-
"
|
|
158
|
+
"FLOWXV3",
|
|
160
159
|
],
|
|
161
160
|
})
|
|
162
161
|
|