@cetusprotocol/aggregator-sdk 0.0.8 → 0.1.0
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 +98 -102
- package/dist/index.d.ts +98 -102
- package/dist/index.js +1228 -1552
- package/dist/index.mjs +1215 -1539
- package/dist/src/api.d.ts +53 -0
- package/dist/src/client.d.ts +38 -65
- package/dist/src/const.d.ts +0 -9
- package/dist/src/index.d.ts +9 -5
- package/dist/src/transaction/afsui.d.ts +10 -0
- package/dist/src/transaction/aftermath.d.ts +13 -24
- package/dist/src/transaction/cetus.d.ts +9 -33
- package/dist/src/transaction/deepbook_v2.d.ts +14 -0
- package/dist/src/transaction/flowx_v2.d.ts +7 -0
- package/dist/src/transaction/haedal.d.ts +6 -0
- package/dist/src/transaction/index.d.ts +6 -1
- package/dist/src/transaction/kriya_v2.d.ts +6 -0
- package/dist/src/transaction/kriya_v3.d.ts +7 -0
- package/dist/src/transaction/swap.d.ts +1 -2
- package/dist/src/transaction/turbos.d.ts +7 -22
- package/dist/src/transaction/volo.d.ts +8 -0
- package/dist/src/utils/coin.d.ts +9 -0
- package/dist/{src → tests}/test_data.test.d.ts +1 -0
- package/package.json +2 -2
- package/src/api.ts +144 -0
- package/src/client.ts +295 -239
- package/src/const.ts +0 -13
- package/src/index.ts +10 -5
- package/src/transaction/afsui.ts +60 -0
- package/src/transaction/aftermath.ts +71 -124
- package/src/transaction/cetus.ts +87 -258
- package/src/transaction/deepbook_v2.ts +122 -0
- package/src/transaction/flowx_v2.ts +42 -0
- package/src/transaction/haedal.ts +41 -0
- package/src/transaction/index.ts +17 -1
- package/src/transaction/kriya_v2.ts +38 -0
- package/src/transaction/kriya_v3.ts +46 -0
- package/src/transaction/swap.ts +17 -24
- package/src/transaction/turbos.ts +40 -99
- package/src/transaction/volo.ts +52 -0
- package/src/utils/coin.ts +91 -6
- package/src/utils/transaction.ts +1 -1
- package/tests/router.test.ts +123 -73
- package/{src → tests}/test_data.test.ts +2 -0
- package/dist/src/config.d.ts +0 -26
- package/dist/src/transaction/common.d.ts +0 -12
- package/dist/src/transaction/deepbook.d.ts +0 -21
- package/dist/src/transaction/flowx.d.ts +0 -20
- package/dist/src/transaction/kriya.d.ts +0 -21
- package/dist/src/transaction/router.d.ts +0 -6
- package/dist/src/utils/account_cap.d.ts +0 -7
- package/src/config.ts +0 -65
- package/src/transaction/common.ts +0 -169
- package/src/transaction/deepbook.ts +0 -126
- package/src/transaction/flowx.ts +0 -97
- package/src/transaction/kriya.ts +0 -77
- package/src/transaction/router.ts +0 -339
- package/src/utils/account_cap.ts +0 -62
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import BN from "bn.js";
|
|
2
|
+
import Decimal from "decimal.js";
|
|
3
|
+
export interface FindRouterParams {
|
|
4
|
+
from: string;
|
|
5
|
+
target: string;
|
|
6
|
+
amount: BN;
|
|
7
|
+
byAmountIn: boolean;
|
|
8
|
+
depth?: number;
|
|
9
|
+
splitAlgorithm?: string;
|
|
10
|
+
splitFactor?: number;
|
|
11
|
+
splitCount?: number;
|
|
12
|
+
providers?: string[];
|
|
13
|
+
}
|
|
14
|
+
export type ExtendedDetails = {
|
|
15
|
+
aftermathPoolFlatness?: number;
|
|
16
|
+
aftermathLpSupplyType?: string;
|
|
17
|
+
turbosFeeType?: string;
|
|
18
|
+
};
|
|
19
|
+
export type Path = {
|
|
20
|
+
id: string;
|
|
21
|
+
direction: boolean;
|
|
22
|
+
provider: string;
|
|
23
|
+
from: string;
|
|
24
|
+
target: string;
|
|
25
|
+
feeRate: number;
|
|
26
|
+
amountIn: number;
|
|
27
|
+
amountOut: number;
|
|
28
|
+
extendedDetails?: ExtendedDetails;
|
|
29
|
+
version?: string;
|
|
30
|
+
};
|
|
31
|
+
export type Router = {
|
|
32
|
+
path: Path[];
|
|
33
|
+
amountIn: BN;
|
|
34
|
+
amountOut: BN;
|
|
35
|
+
initialPrice: Decimal;
|
|
36
|
+
};
|
|
37
|
+
export type RouterError = {
|
|
38
|
+
code: number;
|
|
39
|
+
msg: string;
|
|
40
|
+
};
|
|
41
|
+
export type RouterData = {
|
|
42
|
+
amountIn: BN;
|
|
43
|
+
amountOut: BN;
|
|
44
|
+
routes: Router[];
|
|
45
|
+
insufficientLiquidity: boolean;
|
|
46
|
+
error?: RouterError;
|
|
47
|
+
};
|
|
48
|
+
export type AggregatorResponse = {
|
|
49
|
+
code: number;
|
|
50
|
+
msg: string;
|
|
51
|
+
data: RouterData;
|
|
52
|
+
};
|
|
53
|
+
export declare function getRouterResult(endpoint: string, params: FindRouterParams): Promise<RouterData | null>;
|
package/dist/src/client.d.ts
CHANGED
|
@@ -1,71 +1,36 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import { Transaction } from "@mysten/sui/transactions";
|
|
5
|
-
import { Signer } from "@mysten/sui/dist/cjs/cryptography";
|
|
1
|
+
import { SuiClient } from "@mysten/sui/client";
|
|
2
|
+
import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
3
|
+
import { Signer } from "@mysten/sui/cryptography";
|
|
6
4
|
import BN from "bn.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
amountIn: number;
|
|
20
|
-
amountOut: number;
|
|
21
|
-
extendedDetails?: ExtendedDetails;
|
|
22
|
-
version?: string;
|
|
23
|
-
};
|
|
24
|
-
export type Router = {
|
|
25
|
-
path: Path[];
|
|
26
|
-
amountIn: BN;
|
|
27
|
-
amountOut: BN;
|
|
28
|
-
initialPrice: Decimal;
|
|
29
|
-
};
|
|
30
|
-
export type RouterError = {
|
|
31
|
-
code: number;
|
|
32
|
-
msg: string;
|
|
33
|
-
};
|
|
34
|
-
export type RouterData = {
|
|
35
|
-
amountIn: BN;
|
|
36
|
-
amountOut: BN;
|
|
37
|
-
routes: Router[];
|
|
38
|
-
insufficientLiquidity: boolean;
|
|
39
|
-
error?: RouterError;
|
|
40
|
-
};
|
|
41
|
-
export type AggregatorResponse = {
|
|
42
|
-
code: number;
|
|
43
|
-
msg: string;
|
|
44
|
-
data: RouterData;
|
|
45
|
-
};
|
|
5
|
+
import { Dex, Env, FindRouterParams, Router, RouterData } from ".";
|
|
6
|
+
import { CoinAsset } from "./types/sui";
|
|
7
|
+
export declare const CETUS = "CETUS";
|
|
8
|
+
export declare const DEEPBOOKV2 = "DEEPBOOK";
|
|
9
|
+
export declare const KRIYA = "KRIYA";
|
|
10
|
+
export declare const FLOWXV2 = "FLOWX";
|
|
11
|
+
export declare const KRIYAV3 = "KRIYAV3";
|
|
12
|
+
export declare const TURBOS = "TURBOS";
|
|
13
|
+
export declare const AFTERMATH = "AFTERMATH";
|
|
14
|
+
export declare const HAEDAL = "HAEDAL";
|
|
15
|
+
export declare const VOLO = "VOLO";
|
|
16
|
+
export declare const AFSUI = "AFSUI";
|
|
46
17
|
export type BuildRouterSwapParams = {
|
|
47
18
|
routers: Router[];
|
|
48
|
-
amountIn: BN;
|
|
49
|
-
amountOut: BN;
|
|
50
19
|
byAmountIn: boolean;
|
|
20
|
+
inputCoin: TransactionObjectArgument;
|
|
51
21
|
slippage: number;
|
|
52
|
-
|
|
53
|
-
|
|
22
|
+
txb: Transaction;
|
|
23
|
+
partner?: string;
|
|
24
|
+
};
|
|
25
|
+
export type BuildFastRouterSwapParams = {
|
|
26
|
+
routers: Router[];
|
|
27
|
+
byAmountIn: boolean;
|
|
28
|
+
slippage: number;
|
|
29
|
+
txb: Transaction;
|
|
54
30
|
partner?: string;
|
|
55
31
|
isMergeTragetCoin?: boolean;
|
|
56
32
|
refreshAllCoins?: boolean;
|
|
57
33
|
};
|
|
58
|
-
export interface FindRouterParams {
|
|
59
|
-
from: string;
|
|
60
|
-
target: string;
|
|
61
|
-
amount: BN;
|
|
62
|
-
byAmountIn: boolean;
|
|
63
|
-
depth: number | null;
|
|
64
|
-
splitAlgorithm: string | null;
|
|
65
|
-
splitFactor: number | null;
|
|
66
|
-
splitCount: number | null;
|
|
67
|
-
providers: string[] | null;
|
|
68
|
-
}
|
|
69
34
|
export interface SwapInPoolsParams {
|
|
70
35
|
from: string;
|
|
71
36
|
target: string;
|
|
@@ -78,15 +43,23 @@ export interface SwapInPoolsResult {
|
|
|
78
43
|
routeData?: RouterData;
|
|
79
44
|
}
|
|
80
45
|
export declare class AggregatorClient {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
46
|
+
endpoint: string;
|
|
47
|
+
signer: string;
|
|
48
|
+
client: SuiClient;
|
|
49
|
+
env: Env;
|
|
84
50
|
private allCoins;
|
|
85
|
-
constructor(
|
|
51
|
+
constructor(endpoint: string, signer: string, client: SuiClient, env: Env);
|
|
86
52
|
getAllCoins(): Promise<CoinAsset[]>;
|
|
87
|
-
|
|
53
|
+
findRouters(params: FindRouterParams): Promise<RouterData | null>;
|
|
54
|
+
expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, partner?: string): Promise<TransactionObjectArgument>;
|
|
55
|
+
expectOutputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], partner?: string): Promise<TransactionObjectArgument>;
|
|
88
56
|
swapInPools(params: SwapInPoolsParams): Promise<SwapInPoolsResult | null>;
|
|
89
|
-
routerSwap(params: BuildRouterSwapParams): Promise<
|
|
57
|
+
routerSwap(params: BuildRouterSwapParams): Promise<TransactionObjectArgument>;
|
|
58
|
+
fastRouterSwap(params: BuildFastRouterSwapParams): Promise<void>;
|
|
59
|
+
publishedAt(): string;
|
|
60
|
+
transferOrDestoryCoin(txb: Transaction, coin: TransactionObjectArgument, coinType: string): void;
|
|
61
|
+
checkCoinThresholdAndMergeCoin(txb: Transaction, coins: TransactionObjectArgument[], coinType: string, amountLimit: BN): TransactionObjectArgument;
|
|
62
|
+
newDex(provider: string, partner?: string): Dex;
|
|
90
63
|
signAndExecuteTransaction(txb: Transaction, signer: Signer): Promise<import("@mysten/sui/client").SuiTransactionBlockResponse>;
|
|
91
64
|
devInspectTransactionBlock(txb: Transaction): Promise<import("@mysten/sui/client").DevInspectResults>;
|
|
92
65
|
sendTransaction(txb: Transaction, signer: Signer): Promise<import("@mysten/sui/client").SuiTransactionBlockResponse>;
|
package/dist/src/const.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import BN from "bn.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* The address representing the clock in the system.
|
|
4
4
|
*/
|
|
5
|
-
export declare const CLOCK_ADDRESS = "0x0000000000000000000000000000000000000000000000000000000000000006";
|
|
6
5
|
/**
|
|
7
6
|
* The address for CoinInfo module.
|
|
8
7
|
*/
|
|
@@ -12,14 +11,6 @@ export declare const CoinInfoAddress = "0x1::coin::CoinInfo";
|
|
|
12
11
|
*/
|
|
13
12
|
export declare const CoinStoreAddress = "0x1::coin::CoinStore";
|
|
14
13
|
export declare const SuiZeroCoinFn = "0x2::coin::zero";
|
|
15
|
-
export declare const AGGREGATOR = "aggregator";
|
|
16
|
-
export declare const CETUS_DEX = "CETUS";
|
|
17
|
-
export declare const DEEPBOOK_DEX = "DEEPBOOK";
|
|
18
|
-
export declare const KRIYA_DEX = "KRIYA";
|
|
19
|
-
export declare const FLOWX_AMM = "FLOWX";
|
|
20
|
-
export declare const TURBOS_DEX = "TURBOS";
|
|
21
|
-
export declare const AFTERMATH_AMM = "AFTERMATH";
|
|
22
|
-
export declare const INTEGRATE = "integrate";
|
|
23
14
|
export declare const CETUS_MODULE = "cetus";
|
|
24
15
|
export declare const DEEPBOOK_MODULE = "deepbook";
|
|
25
16
|
export declare const KRIYA_MODULE = "kriya";
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
1
|
+
export * from "./client";
|
|
2
|
+
export * from "./transaction";
|
|
3
|
+
export * from "./utils";
|
|
4
|
+
export * from "./const";
|
|
5
|
+
export * from "./api";
|
|
6
|
+
export declare enum Env {
|
|
7
|
+
Mainnet = 0,
|
|
8
|
+
Testnet = 1
|
|
9
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
2
|
+
import { AggregatorClient, Dex, Env, Path } from "..";
|
|
3
|
+
export declare class Afsui implements Dex {
|
|
4
|
+
private stakedSuiVault;
|
|
5
|
+
private safe;
|
|
6
|
+
private referVault;
|
|
7
|
+
private validator;
|
|
8
|
+
constructor(env: Env);
|
|
9
|
+
swap(client: AggregatorClient, txb: Transaction, path: Path, inputCoin: TransactionObjectArgument): Promise<TransactionObjectArgument>;
|
|
10
|
+
}
|
|
@@ -1,24 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
coinBType: string;
|
|
15
|
-
slippage: number;
|
|
16
|
-
lpSupplyType: string;
|
|
17
|
-
};
|
|
18
|
-
export type AftermathSwapResult = {
|
|
19
|
-
targetCoin: TransactionObjectArgument;
|
|
20
|
-
amountIn: TransactionArgument;
|
|
21
|
-
amountOut: TransactionArgument;
|
|
22
|
-
txb: Transaction;
|
|
23
|
-
};
|
|
24
|
-
export declare function AftermathAmmSwapMovecall(swapParams: AftermathSwapParams, txb: Transaction, config: AggregatorConfig): Promise<AftermathSwapResult>;
|
|
1
|
+
import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
2
|
+
import { AggregatorClient, Dex, Env, Path } from "..";
|
|
3
|
+
export declare class Aftermath implements Dex {
|
|
4
|
+
private slippage;
|
|
5
|
+
private poolRegistry;
|
|
6
|
+
private protocolFeeVault;
|
|
7
|
+
private treasury;
|
|
8
|
+
private insuranceFund;
|
|
9
|
+
private referrealVault;
|
|
10
|
+
constructor(env: Env);
|
|
11
|
+
amountLimit(exportAmountOut: number): number;
|
|
12
|
+
swap(client: AggregatorClient, txb: Transaction, path: Path, inputCoin: TransactionObjectArgument): Promise<TransactionObjectArgument>;
|
|
13
|
+
}
|
|
@@ -1,39 +1,15 @@
|
|
|
1
1
|
import { Transaction, TransactionArgument, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
2
|
-
import {
|
|
3
|
-
import BN from "bn.js";
|
|
4
|
-
export type CetusSwapParams = {
|
|
5
|
-
poolId: string;
|
|
6
|
-
amount: TransactionArgument;
|
|
7
|
-
amountLimit: string;
|
|
8
|
-
a2b: boolean;
|
|
9
|
-
byAmountIn: boolean;
|
|
10
|
-
sqrtPriceLimit: BN;
|
|
11
|
-
partner?: string;
|
|
12
|
-
coinAType: string;
|
|
13
|
-
coinBType: string;
|
|
14
|
-
};
|
|
2
|
+
import { AggregatorClient, Dex, Env, Path } from "..";
|
|
15
3
|
export type CetusFlashSwapResult = {
|
|
16
4
|
targetCoin: TransactionObjectArgument;
|
|
17
5
|
flashReceipt: TransactionObjectArgument;
|
|
18
6
|
payAmount: TransactionArgument;
|
|
19
|
-
swapedAmount: TransactionArgument;
|
|
20
|
-
txb: Transaction;
|
|
21
|
-
};
|
|
22
|
-
export declare function cetusFlashSwapMovecall(swapParams: CetusSwapParams, txb: Transaction, config: AggregatorConfig): CetusFlashSwapResult;
|
|
23
|
-
export type repayParams = {
|
|
24
|
-
poolId: string;
|
|
25
|
-
a2b: boolean;
|
|
26
|
-
coinA?: TransactionObjectArgument;
|
|
27
|
-
coinB?: TransactionObjectArgument;
|
|
28
|
-
receipt: TransactionObjectArgument;
|
|
29
|
-
coinAType: string;
|
|
30
|
-
coinBType: string;
|
|
31
|
-
partner?: string;
|
|
32
|
-
};
|
|
33
|
-
export type SwapResult = {
|
|
34
|
-
repayTargetCoin: TransactionObjectArgument;
|
|
35
|
-
nextInputAmount?: TransactionArgument;
|
|
36
|
-
flashTargetCoin?: TransactionObjectArgument;
|
|
37
7
|
};
|
|
38
|
-
export declare
|
|
39
|
-
|
|
8
|
+
export declare class Cetus implements Dex {
|
|
9
|
+
private globalConfig;
|
|
10
|
+
private partner;
|
|
11
|
+
constructor(env: Env, partner?: string);
|
|
12
|
+
flash_swap(client: AggregatorClient, txb: Transaction, path: Path, by_amount_in: boolean): CetusFlashSwapResult;
|
|
13
|
+
repay_flash_swap(client: AggregatorClient, txb: Transaction, path: Path, inputCoin: TransactionObjectArgument, receipt: TransactionArgument): TransactionObjectArgument;
|
|
14
|
+
swap(client: AggregatorClient, txb: Transaction, path: Path, inputCoin: TransactionObjectArgument): Promise<TransactionObjectArgument>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
2
|
+
import { AggregatorClient, Dex, Env, Path } from "..";
|
|
3
|
+
import { SuiClient } from "@mysten/sui/client";
|
|
4
|
+
type GetOrCreateAccountCapResult = {
|
|
5
|
+
accountCap: TransactionObjectArgument;
|
|
6
|
+
isCreate: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare class DeepbookV2 implements Dex {
|
|
9
|
+
constructor(env: Env);
|
|
10
|
+
getAccountCap(client: SuiClient, owner: string): Promise<string | null>;
|
|
11
|
+
getOrCreateAccountCap(txb: Transaction, client: SuiClient, owner: string): Promise<GetOrCreateAccountCapResult>;
|
|
12
|
+
swap(client: AggregatorClient, txb: Transaction, path: Path, inputCoin: TransactionObjectArgument): Promise<TransactionObjectArgument>;
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
2
|
+
import { AggregatorClient, Dex, Env, Path } from "..";
|
|
3
|
+
export declare class FlowxV2 implements Dex {
|
|
4
|
+
private container;
|
|
5
|
+
constructor(env: Env);
|
|
6
|
+
swap(client: AggregatorClient, txb: Transaction, path: Path, inputCoin: TransactionObjectArgument): Promise<TransactionObjectArgument>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
2
|
+
import { AggregatorClient, Dex, Env, Path } from "..";
|
|
3
|
+
export declare class Haedal implements Dex {
|
|
4
|
+
constructor(env: Env);
|
|
5
|
+
swap(client: AggregatorClient, txb: Transaction, path: Path, inputCoin: TransactionObjectArgument): Promise<TransactionObjectArgument>;
|
|
6
|
+
}
|
|
@@ -1 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
2
|
+
import { AggregatorClient, Path } from "..";
|
|
3
|
+
export declare const CLOCK_ADDRESS = "0x0000000000000000000000000000000000000000000000000000000000000006";
|
|
4
|
+
export interface Dex {
|
|
5
|
+
swap(client: AggregatorClient, ptb: Transaction, path: Path, inputCoin: TransactionObjectArgument): Promise<TransactionObjectArgument>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
2
|
+
import { AggregatorClient, Dex, Env, Path } from "..";
|
|
3
|
+
export declare class KriyaV2 implements Dex {
|
|
4
|
+
constructor(env: Env);
|
|
5
|
+
swap(client: AggregatorClient, txb: Transaction, path: Path, inputCoin: TransactionObjectArgument): Promise<TransactionObjectArgument>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
2
|
+
import { AggregatorClient, Dex, Env, Path } from "..";
|
|
3
|
+
export declare class KriyaV3 implements Dex {
|
|
4
|
+
private version;
|
|
5
|
+
constructor(env: Env);
|
|
6
|
+
swap(client: AggregatorClient, txb: Transaction, path: Path, inputCoin: TransactionObjectArgument): Promise<TransactionObjectArgument>;
|
|
7
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { SwapInPoolsParams } from "~/client";
|
|
2
|
-
import { AggregatorConfig } from "~/config";
|
|
3
2
|
import { SwapInPoolsResult } from "..";
|
|
4
3
|
import { SuiClient } from "@mysten/sui/client";
|
|
5
|
-
export declare function swapInPools(client: SuiClient, params: SwapInPoolsParams,
|
|
4
|
+
export declare function swapInPools(client: SuiClient, params: SwapInPoolsParams, sender: string): Promise<SwapInPoolsResult>;
|
|
@@ -1,22 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
byAmountIn: boolean;
|
|
9
|
-
coinA?: TransactionObjectArgument;
|
|
10
|
-
coinB?: TransactionObjectArgument;
|
|
11
|
-
useFullInputCoinAmount: boolean;
|
|
12
|
-
coinAType: string;
|
|
13
|
-
coinBType: string;
|
|
14
|
-
feeType: string;
|
|
15
|
-
};
|
|
16
|
-
export type TurbosSwapResult = {
|
|
17
|
-
targetCoin: TransactionObjectArgument;
|
|
18
|
-
amountIn: TransactionArgument;
|
|
19
|
-
amountOut: TransactionArgument;
|
|
20
|
-
txb: Transaction;
|
|
21
|
-
};
|
|
22
|
-
export declare function turbosClmmSwapMovecall(swapParams: TurbosSwapParams, txb: Transaction, config: AggregatorConfig): Promise<TurbosSwapResult>;
|
|
1
|
+
import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
2
|
+
import { AggregatorClient, Dex, Env, Path } from "..";
|
|
3
|
+
export declare class Turbos implements Dex {
|
|
4
|
+
private versioned;
|
|
5
|
+
constructor(env: Env);
|
|
6
|
+
swap(client: AggregatorClient, txb: Transaction, path: Path, inputCoin: TransactionObjectArgument): Promise<TransactionObjectArgument>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
2
|
+
import { AggregatorClient, Dex, Env, Path } from "..";
|
|
3
|
+
export declare class Volo implements Dex {
|
|
4
|
+
private nativePool;
|
|
5
|
+
private metadata;
|
|
6
|
+
constructor(env: Env);
|
|
7
|
+
swap(client: AggregatorClient, txb: Transaction, path: Path, inputCoin: TransactionObjectArgument): Promise<TransactionObjectArgument>;
|
|
8
|
+
}
|
package/dist/src/utils/coin.d.ts
CHANGED
|
@@ -1,2 +1,11 @@
|
|
|
1
|
+
import { CoinAsset } from "../types/sui";
|
|
2
|
+
import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
1
3
|
export declare function completionCoin(s: string): string;
|
|
2
4
|
export declare function compareCoins(coinA: string, coinB: string): boolean;
|
|
5
|
+
export declare function mintZeroCoin(txb: Transaction, coinType: string): TransactionObjectArgument;
|
|
6
|
+
export type BuildCoinResult = {
|
|
7
|
+
targetCoin: TransactionObjectArgument;
|
|
8
|
+
isMintZeroCoin: boolean;
|
|
9
|
+
targetCoinAmount: number;
|
|
10
|
+
};
|
|
11
|
+
export declare function buildInputCoin(txb: Transaction, allCoins: CoinAsset[], amount: bigint, coinType: string): BuildCoinResult;
|
|
@@ -6,3 +6,4 @@ export declare const M_SUI = "0x2::sui::SUI";
|
|
|
6
6
|
export declare const M_VSUI = "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT";
|
|
7
7
|
export declare const M_VAPOR = "0xa1f2c11169f32165ad4efb4468ec5bdfc880cd66b22094024b32ab7b76d14d30::vapor::VAPOR";
|
|
8
8
|
export declare const M_HASUI = "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI";
|
|
9
|
+
export declare const M_SSWP = "0x361dd589b98e8fcda9a7ee53b85efabef3569d00416640d2faa516e3801d7ffc::TOKEN::TOKEN";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cetusprotocol/aggregator-sdk",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"@babel/preset-env": "^7.24.5",
|
|
28
28
|
"@babel/preset-typescript": "^7.24.1",
|
|
29
29
|
"@jest/globals": "^29.7.0",
|
|
30
|
-
"@mysten/sui": "^1.0
|
|
30
|
+
"@mysten/sui": "^1.6.0",
|
|
31
31
|
"@types/jest": "^29.5.12",
|
|
32
32
|
"@types/node": "^20.12.12",
|
|
33
33
|
"babel-jest": "^29.7.0",
|
package/src/api.ts
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import BN from "bn.js"
|
|
2
|
+
import Decimal from "decimal.js"
|
|
3
|
+
import { completionCoin } from "~/utils/coin"
|
|
4
|
+
import { ZERO } from "./const"
|
|
5
|
+
import {
|
|
6
|
+
AggregatorServerErrorCode,
|
|
7
|
+
getAggregatorServerErrorMessage,
|
|
8
|
+
} from "./errors"
|
|
9
|
+
import { parseRouterResponse } from "./client"
|
|
10
|
+
|
|
11
|
+
export interface FindRouterParams {
|
|
12
|
+
from: string
|
|
13
|
+
target: string
|
|
14
|
+
amount: BN
|
|
15
|
+
byAmountIn: boolean
|
|
16
|
+
depth?: number
|
|
17
|
+
splitAlgorithm?: string
|
|
18
|
+
splitFactor?: number
|
|
19
|
+
splitCount?: number
|
|
20
|
+
providers?: string[]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type ExtendedDetails = {
|
|
24
|
+
aftermathPoolFlatness?: number
|
|
25
|
+
aftermathLpSupplyType?: string
|
|
26
|
+
turbosFeeType?: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type Path = {
|
|
30
|
+
id: string
|
|
31
|
+
direction: boolean
|
|
32
|
+
provider: string
|
|
33
|
+
from: string
|
|
34
|
+
target: string
|
|
35
|
+
feeRate: number
|
|
36
|
+
amountIn: number
|
|
37
|
+
amountOut: number
|
|
38
|
+
extendedDetails?: ExtendedDetails
|
|
39
|
+
version?: string
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type Router = {
|
|
43
|
+
path: Path[]
|
|
44
|
+
amountIn: BN
|
|
45
|
+
amountOut: BN
|
|
46
|
+
initialPrice: Decimal
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type RouterError = {
|
|
50
|
+
code: number
|
|
51
|
+
msg: string
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type RouterData = {
|
|
55
|
+
amountIn: BN
|
|
56
|
+
amountOut: BN
|
|
57
|
+
routes: Router[]
|
|
58
|
+
insufficientLiquidity: boolean
|
|
59
|
+
error?: RouterError
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export type AggregatorResponse = {
|
|
63
|
+
code: number
|
|
64
|
+
msg: string
|
|
65
|
+
data: RouterData
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export async function getRouterResult(
|
|
69
|
+
endpoint: string,
|
|
70
|
+
params: FindRouterParams
|
|
71
|
+
): Promise<RouterData | null> {
|
|
72
|
+
const {
|
|
73
|
+
from,
|
|
74
|
+
target,
|
|
75
|
+
amount,
|
|
76
|
+
byAmountIn,
|
|
77
|
+
depth,
|
|
78
|
+
splitAlgorithm,
|
|
79
|
+
splitFactor,
|
|
80
|
+
splitCount,
|
|
81
|
+
providers,
|
|
82
|
+
} = params
|
|
83
|
+
const fromCoin = completionCoin(from)
|
|
84
|
+
const targetCoin = completionCoin(target)
|
|
85
|
+
|
|
86
|
+
let url = `${endpoint}?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`
|
|
87
|
+
|
|
88
|
+
if (depth) {
|
|
89
|
+
url += `&depth=${depth}`
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (splitAlgorithm) {
|
|
93
|
+
url += `&split_algorithm=${splitAlgorithm}`
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (splitFactor) {
|
|
97
|
+
url += `&split_factor=${splitFactor}`
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (splitCount) {
|
|
101
|
+
url += `&split_count=${splitCount}`
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (providers) {
|
|
105
|
+
if (providers.length > 0) {
|
|
106
|
+
url += `&providers=${providers.join(",")}`
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const response = await fetch(url)
|
|
111
|
+
if (!response.ok) {
|
|
112
|
+
return {
|
|
113
|
+
amountIn: ZERO,
|
|
114
|
+
amountOut: ZERO,
|
|
115
|
+
routes: [],
|
|
116
|
+
insufficientLiquidity: false,
|
|
117
|
+
error: {
|
|
118
|
+
code: AggregatorServerErrorCode.NumberTooLarge,
|
|
119
|
+
msg: getAggregatorServerErrorMessage(
|
|
120
|
+
AggregatorServerErrorCode.NumberTooLarge
|
|
121
|
+
),
|
|
122
|
+
},
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const data = await response.json()
|
|
126
|
+
if (data.data != null) {
|
|
127
|
+
const res = parseRouterResponse(data.data)
|
|
128
|
+
return res
|
|
129
|
+
}
|
|
130
|
+
const insufficientLiquidity = data.msg === "liquidity is not enough"
|
|
131
|
+
|
|
132
|
+
return {
|
|
133
|
+
amountIn: ZERO,
|
|
134
|
+
amountOut: ZERO,
|
|
135
|
+
routes: [],
|
|
136
|
+
insufficientLiquidity,
|
|
137
|
+
error: {
|
|
138
|
+
code: AggregatorServerErrorCode.InsufficientLiquidity,
|
|
139
|
+
msg: getAggregatorServerErrorMessage(
|
|
140
|
+
AggregatorServerErrorCode.InsufficientLiquidity
|
|
141
|
+
),
|
|
142
|
+
},
|
|
143
|
+
}
|
|
144
|
+
}
|