@cetusprotocol/aggregator-sdk 0.0.0-experimental-20240719182939

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.
Files changed (66) hide show
  1. package/.env.example +4 -0
  2. package/README.md +0 -0
  3. package/bun.lockb +0 -0
  4. package/dist/index.d.mts +267 -0
  5. package/dist/index.d.ts +267 -0
  6. package/dist/index.js +6824 -0
  7. package/dist/index.mjs +6745 -0
  8. package/dist/src/client.d.ts +88 -0
  9. package/dist/src/config.d.ts +26 -0
  10. package/dist/src/const.d.ts +75 -0
  11. package/dist/src/errors.d.ts +31 -0
  12. package/dist/src/index.d.ts +5 -0
  13. package/dist/src/math.d.ts +5 -0
  14. package/dist/src/test_data.test.d.ts +8 -0
  15. package/dist/src/transaction/aftermath.d.ts +24 -0
  16. package/dist/src/transaction/cetus.d.ts +39 -0
  17. package/dist/src/transaction/common.d.ts +12 -0
  18. package/dist/src/transaction/deepbook.d.ts +21 -0
  19. package/dist/src/transaction/flowx.d.ts +20 -0
  20. package/dist/src/transaction/index.d.ts +1 -0
  21. package/dist/src/transaction/kriya.d.ts +21 -0
  22. package/dist/src/transaction/router.d.ts +6 -0
  23. package/dist/src/transaction/swap.d.ts +5 -0
  24. package/dist/src/transaction/turbos.d.ts +22 -0
  25. package/dist/src/types/CoinAssist.d.ts +122 -0
  26. package/dist/src/types/sui.d.ts +112 -0
  27. package/dist/src/utils/account_cap.d.ts +7 -0
  28. package/dist/src/utils/coin.d.ts +4 -0
  29. package/dist/src/utils/coin.spec.d.ts +1 -0
  30. package/dist/src/utils/contracts.d.ts +16 -0
  31. package/dist/src/utils/index.d.ts +1 -0
  32. package/dist/src/utils/transaction.d.ts +3 -0
  33. package/dist/tests/router.test.d.ts +2 -0
  34. package/dist/tests/wallet.test.d.ts +1 -0
  35. package/jest.config.mjs +13 -0
  36. package/package.json +41 -0
  37. package/src/client.ts +393 -0
  38. package/src/config.ts +65 -0
  39. package/src/const.ts +126 -0
  40. package/src/errors.ts +44 -0
  41. package/src/index.ts +5 -0
  42. package/src/math.ts +37 -0
  43. package/src/test_data.test.ts +17 -0
  44. package/src/transaction/aftermath.ts +142 -0
  45. package/src/transaction/cetus.ts +281 -0
  46. package/src/transaction/common.ts +169 -0
  47. package/src/transaction/deepbook.ts +126 -0
  48. package/src/transaction/flowx.ts +97 -0
  49. package/src/transaction/index.ts +1 -0
  50. package/src/transaction/kriya.ts +77 -0
  51. package/src/transaction/router.ts +341 -0
  52. package/src/transaction/swap.ts +164 -0
  53. package/src/transaction/turbos.ts +114 -0
  54. package/src/types/CoinAssist.ts +217 -0
  55. package/src/types/sui.ts +148 -0
  56. package/src/utils/account_cap.ts +62 -0
  57. package/src/utils/coin.spec.ts +10 -0
  58. package/src/utils/coin.ts +61 -0
  59. package/src/utils/contracts.ts +136 -0
  60. package/src/utils/index.ts +1 -0
  61. package/src/utils/transaction.ts +20 -0
  62. package/tests/router.test.ts +255 -0
  63. package/tests/wallet.test.ts +21 -0
  64. package/tsconfig.json +22 -0
  65. package/tsup.config.ts +23 -0
  66. package/version.mjs +28 -0
@@ -0,0 +1,88 @@
1
+ import type { AggregatorConfig } from "./config";
2
+ import Decimal from "decimal.js";
3
+ import { CoinAsset } from "./types/sui";
4
+ import { Transaction } from "@mysten/sui/transactions";
5
+ import { Signer } from "@mysten/sui/dist/cjs/cryptography";
6
+ import BN from "bn.js";
7
+ export type ExtendedDetails = {
8
+ aftermathPoolFlatness?: number;
9
+ aftermathLpSupplyType?: string;
10
+ turbosFeeType?: string;
11
+ };
12
+ export type Path = {
13
+ id: string;
14
+ a2b: boolean;
15
+ provider: string;
16
+ from: string;
17
+ target: string;
18
+ feeRate: number;
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 RouterData = {
31
+ amountIn: BN;
32
+ amountOut: BN;
33
+ routes: Router[];
34
+ insufficientLiquidity: boolean;
35
+ };
36
+ export type AggregatorResponse = {
37
+ code: number;
38
+ msg: string;
39
+ data: RouterData;
40
+ };
41
+ export type BuildRouterSwapParams = {
42
+ routers: Router[];
43
+ amountIn: BN;
44
+ amountOut: BN;
45
+ byAmountIn: boolean;
46
+ slippage: number;
47
+ fromCoinType: string;
48
+ targetCoinType: string;
49
+ partner?: string;
50
+ isMergeTragetCoin?: boolean;
51
+ refreshAllCoins?: boolean;
52
+ };
53
+ export interface FindRouterParams {
54
+ from: string;
55
+ target: string;
56
+ amount: BN;
57
+ byAmountIn: boolean;
58
+ depth: number | null;
59
+ splitAlgorithm: string | null;
60
+ splitFactor: number | null;
61
+ splitCount: number | null;
62
+ providers: string[] | null;
63
+ }
64
+ export interface SwapInPoolsParams {
65
+ from: string;
66
+ target: string;
67
+ amount: BN;
68
+ byAmountIn: boolean;
69
+ pools: string[];
70
+ }
71
+ export interface SwapInPoolsResult {
72
+ isExceed: boolean;
73
+ routeData?: RouterData;
74
+ }
75
+ export declare class AggregatorClient {
76
+ private config;
77
+ private wallet;
78
+ private client;
79
+ private allCoins;
80
+ constructor(config: AggregatorConfig);
81
+ getAllCoins(): Promise<CoinAsset[]>;
82
+ findRouter(fromRouterParams: FindRouterParams): Promise<RouterData | null>;
83
+ swapInPools(params: SwapInPoolsParams): Promise<SwapInPoolsResult | null>;
84
+ routerSwap(params: BuildRouterSwapParams): Promise<Transaction>;
85
+ signAndExecuteTransaction(txb: Transaction, signer: Signer): Promise<import("@mysten/sui/client").SuiTransactionBlockResponse>;
86
+ devInspectTransactionBlock(txb: Transaction, signer: Signer): Promise<import("@mysten/sui/client").DevInspectResults>;
87
+ sendTransaction(txb: Transaction, signer: Signer): Promise<import("@mysten/sui/client").SuiTransactionBlockResponse>;
88
+ }
@@ -0,0 +1,26 @@
1
+ export type Package = {
2
+ packageName: string;
3
+ packageId: string;
4
+ publishedAt: string;
5
+ };
6
+ export declare enum ENV {
7
+ MAINNET = 0,
8
+ TESTNET = 1
9
+ }
10
+ export declare class AggregatorConfig {
11
+ private aggregatorUrl;
12
+ private fullNodeUrl;
13
+ private wallet;
14
+ private packages;
15
+ private env;
16
+ constructor(aggregatorUrl: string, fullNodeUrl: string, wallet: string, packages: Package[], env: ENV);
17
+ getAggregatorUrl(): string;
18
+ getFullNodeUrl(): string;
19
+ getWallet(): string;
20
+ getENV(): ENV;
21
+ getPackages(): Package[];
22
+ getPackage(packageName: string): Package | undefined;
23
+ addPackage(newPackage: Package): void;
24
+ removePackageById(packageId: string): void;
25
+ findPackageById(packageId: string): Package | undefined;
26
+ }
@@ -0,0 +1,75 @@
1
+ import BN from "bn.js";
2
+ /**
3
+ * The address representing the clock in the system.
4
+ */
5
+ export declare const CLOCK_ADDRESS = "0x0000000000000000000000000000000000000000000000000000000000000006";
6
+ /**
7
+ * The address for CoinInfo module.
8
+ */
9
+ export declare const CoinInfoAddress = "0x1::coin::CoinInfo";
10
+ /**
11
+ * The address for CoinStore module.
12
+ */
13
+ export declare const CoinStoreAddress = "0x1::coin::CoinStore";
14
+ 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
+ export declare const CETUS_MODULE = "cetus";
24
+ export declare const DEEPBOOK_MODULE = "deepbook";
25
+ export declare const KRIYA_MODULE = "kriya";
26
+ export declare const UTILS_MODULE = "utils";
27
+ export declare const POOL_MODULT = "pool";
28
+ export declare const PAY_MODULE = "pay";
29
+ export declare const FLOWX_AMM_MODULE = "flowx_amm";
30
+ export declare const TURBOS_MODULE = "turbos";
31
+ export declare const AFTERMATH_MODULE = "aftermath";
32
+ export declare const DEEPBOOK_CUSTODIAN_V2_MODULE = "custodian_v2";
33
+ export declare const DEEPBOOK_CLOB_V2_MODULE = "clob_v2";
34
+ export declare const FlashSwapFunc = "flash_swap";
35
+ export declare const FlashSwapWithPartnerFunc = "flash_swap_with_partner";
36
+ export declare const RepayFalshSwapFunc = "repay_flash_swap";
37
+ export declare const RepayFlashSwapWithPartnerFunc = "repay_flash_swap_with_partner";
38
+ export declare const FlashSwapA2BFunc = "flash_swap_a2b";
39
+ export declare const FlashSwapB2AFunc = "flash_swap_b2a";
40
+ export declare const FlashSwapWithPartnerA2BFunc = "flash_swap_with_partner_a2b";
41
+ export declare const FlashSwapWithPartnerB2AFunc = "flash_swap_with_partner_b2a";
42
+ export declare const REPAY_FLASH_SWAP_A2B_FUNC = "repay_flash_swap_a2b";
43
+ export declare const REPAY_FLASH_SWAP_B2A_FUNC = "repay_flash_swap_b2a";
44
+ export declare const REPAY_FLASH_SWAP_WITH_PARTNER_A2B_FUNC = "repay_flash_swap_with_partner_a2b";
45
+ export declare const REPAY_FLASH_SWAP_WITH_PARTNER_B2A_FUNC = "repay_flash_swap_with_partner_b2a";
46
+ export declare const SWAP_A2B_FUNC = "swap_a2b";
47
+ export declare const SWAP_B2A_FUNC = "swap_b2a";
48
+ export declare const TRANSFER_OR_DESTORY_COIN_FUNC = "transfer_or_destroy_coin";
49
+ export declare const CHECK_COINS_THRESHOLD_FUNC = "check_coins_threshold";
50
+ export declare const JOIN_FUNC = "join_vec";
51
+ export declare const TRANSFER_ACCOUNT_CAP = "transfer_account_cap";
52
+ export declare const DEEPBOOK_PACKAGE_ID = "0x000000000000000000000000000000000000000000000000000000000000dee9";
53
+ export declare const DEEPBOOK_PUBLISHED_AT = "0x000000000000000000000000000000000000000000000000000000000000dee9";
54
+ export declare const CETUS_PUBLISHED_AT = "0x70968826ad1b4ba895753f634b0aea68d0672908ca1075a2abdf0fc9e0b2fc6a";
55
+ export declare const MAINNET_CETUS_GLOBAL_CONFIG_ID = "0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f";
56
+ export declare const TESTNET_CETUS_GLOBAL_CONFIG_ID = "0x6f4149091a5aea0e818e7243a13adcfb403842d670b9a2089de058512620687a";
57
+ export declare const ZERO: BN;
58
+ export declare const ONE: BN;
59
+ export declare const TWO: BN;
60
+ export declare const U128: BN;
61
+ export declare const U64_MAX_BN: BN;
62
+ export declare const U64_MAX = "18446744073709551615";
63
+ export declare const MAINNET_FLOWX_AMM_CONTAINER_ID = "0xb65dcbf63fd3ad5d0ebfbf334780dc9f785eff38a4459e37ab08fa79576ee511";
64
+ export declare const TESTNET_FLOWX_AMM_CONTAINER_ID = "";
65
+ export declare const TURBOS_VERSIONED = "0xf1cf0e81048df168ebeb1b8030fad24b3e0b53ae827c25053fff0779c1445b6f";
66
+ export declare const MAINNET_AFTERMATH_REGISTRY_ID = "0xfcc774493db2c45c79f688f88d28023a3e7d98e4ee9f48bbf5c7990f651577ae";
67
+ export declare const TESTNET_AFTERMATH_REGISTRY_ID = "";
68
+ export declare const MAINNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID = "0xf194d9b1bcad972e45a7dd67dd49b3ee1e3357a00a50850c52cd51bb450e13b4";
69
+ export declare const TESTNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID = "";
70
+ export declare const MAINNET_AFTERMATH_TREASURY_ID = "0x28e499dff5e864a2eafe476269a4f5035f1c16f338da7be18b103499abf271ce";
71
+ export declare const TESTNET_AFTERMATH_TREASURY_ID = "";
72
+ export declare const MAINNET_AFTERMATH_INSURANCE_FUND_ID = "0xf0c40d67b078000e18032334c3325c47b9ec9f3d9ae4128be820d54663d14e3b";
73
+ export declare const TESTNET_AFTERMATH_INSURANCE_FUND_ID = "";
74
+ export declare const MAINNET_AFTERMATH_REFERRAL_VAULT_ID = "0x35d35b0e5b177593d8c3a801462485572fc30861e6ce96a55af6dc4730709278";
75
+ export declare const TESTNET_AFTERMATH_REFERRAL_VAULT_ID = "";
@@ -0,0 +1,31 @@
1
+ export declare enum TypesErrorCode {
2
+ InvalidType = "InvalidType"
3
+ }
4
+ export declare enum ConfigErrorCode {
5
+ MissAggregatorPackage = "MissAggregatorPackage",
6
+ MissGlobalConfig = "MissGlobalConfig",
7
+ InvalidWallet = "InvalidWallet",
8
+ SimulateError = "SimulateError"
9
+ }
10
+ export declare enum TransactionErrorCode {
11
+ InsufficientBalance = "InsufficientBalance",
12
+ SimulateEventError = "simulateEventError",
13
+ CannotGetDecimals = "CannotGetDecimals",
14
+ MissCoinA = "MissCoinA",
15
+ MissCoinB = "MissCoinB",
16
+ MissTurbosFeeType = "MissTurbosFeeType",
17
+ MissAftermathLpSupplyType = "MissAftermathLpSupplyType"
18
+ }
19
+ export type AggregatorErrorCode = TypesErrorCode;
20
+ /**
21
+ * AggregatorError is a custom error class that extends the built-in Error class. It is used to represent errors that occur during aggregation operations.
22
+ * The key functionality of this code includes:
23
+ * - Defining the AggregatorError class that represents an error during aggregation. It includes a message property and an optional errorCode property.
24
+ * - Providing a static method isAggregatorErrorCode() that checks if a given error instance is an instance of AggregatorError and has a specific error code.
25
+ */
26
+ export declare class AggregatorError extends Error {
27
+ message: string;
28
+ errorCode?: AggregatorErrorCode;
29
+ constructor(message: string, errorCode?: AggregatorErrorCode);
30
+ static isAggregatorErrorCode(e: any, code: AggregatorErrorCode): boolean;
31
+ }
@@ -0,0 +1,5 @@
1
+ export * from './client';
2
+ export * from './transaction';
3
+ export * from './config';
4
+ export * from './utils';
5
+ export * from './const';
@@ -0,0 +1,5 @@
1
+ import BN from "bn.js";
2
+ import Decimal from "decimal.js";
3
+ export declare function CalculateAmountLimit(expectAmount: BN, byAmountIn: boolean, slippage: number): number;
4
+ export declare function GetDefaultSqrtPriceLimit(a2b: boolean): BN;
5
+ export declare function sqrtPriceX64ToPrice(sqrtPriceStr: string, decimalsA: number, decimalsB: number): Decimal;
@@ -0,0 +1,8 @@
1
+ export declare const T_USDC = "";
2
+ export declare const M_USDC = "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN";
3
+ export declare const M_CETUS = "0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS";
4
+ export declare const M_NAVI = "0xa99b8952d4f7d947ea77fe0ecdcc9e5fc0bcab2841d6e2a5aa00c3044e5544b5::navx::NAVX";
5
+ export declare const M_SUI = "0x2::sui::SUI";
6
+ export declare const M_VSUI = "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT";
7
+ export declare const M_VAPOR = "0xa1f2c11169f32165ad4efb4468ec5bdfc880cd66b22094024b32ab7b76d14d30::vapor::VAPOR";
8
+ export declare const M_HASUI = "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI";
@@ -0,0 +1,24 @@
1
+ import { TransactionArgument, Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
2
+ import { AggregatorConfig } from "../config";
3
+ export type AftermathSwapParams = {
4
+ poolId: string;
5
+ amount: TransactionArgument;
6
+ amountOut: number;
7
+ amountLimit: number;
8
+ a2b: boolean;
9
+ byAmountIn: boolean;
10
+ coinA?: TransactionObjectArgument;
11
+ coinB?: TransactionObjectArgument;
12
+ useFullInputCoinAmount: boolean;
13
+ coinAType: string;
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>;
@@ -0,0 +1,39 @@
1
+ import { Transaction, TransactionArgument, TransactionObjectArgument } from "@mysten/sui/transactions";
2
+ import { AggregatorConfig } from "../config";
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
+ };
15
+ export type CetusFlashSwapResult = {
16
+ targetCoin: TransactionObjectArgument;
17
+ flashReceipt: TransactionObjectArgument;
18
+ 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
+ };
38
+ export declare function cetusRepayFlashSwapMovecall(repayParams: repayParams, txb: Transaction, config: AggregatorConfig): Promise<SwapResult>;
39
+ export declare function cetusSwapWithOutLimit(swapParams: CetusSwapParams, fromCoin: TransactionObjectArgument, txb: Transaction, config: AggregatorConfig): Promise<SwapResult>;
@@ -0,0 +1,12 @@
1
+ import { CoinAsset } from "../types/sui";
2
+ import { AggregatorConfig } from "../config";
3
+ import { Transaction, TransactionArgument, TransactionObjectArgument } from "@mysten/sui/transactions";
4
+ export declare function mintZeroCoin(txb: Transaction, coinType: string): TransactionObjectArgument;
5
+ export type BuildCoinResult = {
6
+ targetCoin: TransactionObjectArgument;
7
+ isMintZeroCoin: boolean;
8
+ targetCoinAmount: number;
9
+ };
10
+ export declare function buildInputCoin(txb: Transaction, allCoins: CoinAsset[], amount: bigint, coinType: string): BuildCoinResult;
11
+ export declare function transferOrDestoryCoin(txb: Transaction, coinObject: TransactionObjectArgument, coinType: string, config: AggregatorConfig): void;
12
+ export declare function checkCoinThresholdAndMergeCoin(txb: Transaction, coins: TransactionObjectArgument[], coinType: string, amountLimit: number, config: AggregatorConfig): TransactionArgument;
@@ -0,0 +1,21 @@
1
+ import { TransactionArgument, Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
2
+ import { AggregatorConfig } from "../config";
3
+ import { SuiClient } from "@mysten/sui/client";
4
+ export type DeepbookSwapParams = {
5
+ poolId: string;
6
+ a2b: boolean;
7
+ amount: TransactionArgument;
8
+ amountLimit: number;
9
+ coinA?: TransactionObjectArgument;
10
+ coinB?: TransactionObjectArgument;
11
+ useFullInputCoinAmount: boolean;
12
+ coinAType: string;
13
+ coinBType: string;
14
+ };
15
+ export type DeepbookSwapResult = {
16
+ targetCoin: TransactionObjectArgument;
17
+ amountIn: TransactionArgument;
18
+ amountOut: TransactionArgument;
19
+ txb: Transaction;
20
+ };
21
+ export declare function deepbookSwapMovecall(swapParams: DeepbookSwapParams, client: SuiClient, txb: Transaction, config: AggregatorConfig): Promise<DeepbookSwapResult>;
@@ -0,0 +1,20 @@
1
+ import { TransactionArgument, Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
2
+ import { AggregatorConfig } from "../config";
3
+ export type FlowxSwapParams = {
4
+ amount: TransactionArgument;
5
+ amountLimit: number;
6
+ a2b: boolean;
7
+ byAmountIn: boolean;
8
+ coinA?: TransactionObjectArgument;
9
+ coinB?: TransactionObjectArgument;
10
+ useFullInputCoinAmount: boolean;
11
+ coinAType: string;
12
+ coinBType: string;
13
+ };
14
+ export type FlowxSwapResult = {
15
+ targetCoin: TransactionObjectArgument;
16
+ amountIn: TransactionArgument;
17
+ amountOut: TransactionArgument;
18
+ txb: Transaction;
19
+ };
20
+ export declare function flowxAmmSwapMovecall(swapParams: FlowxSwapParams, txb: Transaction, config: AggregatorConfig): Promise<FlowxSwapResult>;
@@ -0,0 +1 @@
1
+ export * from "./router";
@@ -0,0 +1,21 @@
1
+ import { TransactionArgument, Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
2
+ import { AggregatorConfig } from "../config";
3
+ export type KriyaSwapParams = {
4
+ poolId: string;
5
+ amount: TransactionArgument;
6
+ amountLimit: number;
7
+ a2b: boolean;
8
+ byAmountIn: boolean;
9
+ coinA?: TransactionObjectArgument;
10
+ coinB?: TransactionObjectArgument;
11
+ useFullInputCoinAmount: boolean;
12
+ coinAType: string;
13
+ coinBType: string;
14
+ };
15
+ export type KriyaSwapResult = {
16
+ targetCoin: TransactionObjectArgument;
17
+ amountIn: TransactionArgument;
18
+ amountOut: TransactionArgument;
19
+ txb: Transaction;
20
+ };
21
+ export declare function kriyaSwapMovecall(swapParams: KriyaSwapParams, txb: Transaction, config: AggregatorConfig): Promise<KriyaSwapResult>;
@@ -0,0 +1,6 @@
1
+ import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
2
+ import type { BuildRouterSwapParams } from "../client";
3
+ import { AggregatorConfig } from "../config";
4
+ import { SuiClient } from "@mysten/sui/client";
5
+ export declare function expectInputRouterSwap(client: SuiClient, params: BuildRouterSwapParams, txb: Transaction, fromCoin: TransactionObjectArgument, config: AggregatorConfig, partner?: string): Promise<TransactionObjectArgument[]>;
6
+ export declare function expectOutputRouterSwap(params: BuildRouterSwapParams, txb: Transaction, fromCoin: TransactionObjectArgument, config: AggregatorConfig, partner?: string): Promise<TransactionObjectArgument[]>;
@@ -0,0 +1,5 @@
1
+ import { SwapInPoolsParams } from "~/client";
2
+ import { AggregatorConfig } from "~/config";
3
+ import { SwapInPoolsResult } from "..";
4
+ import { SuiClient } from "@mysten/sui/client";
5
+ export declare function swapInPools(client: SuiClient, params: SwapInPoolsParams, config: AggregatorConfig): Promise<SwapInPoolsResult>;
@@ -0,0 +1,22 @@
1
+ import { TransactionArgument, Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
2
+ import { AggregatorConfig } from "../config";
3
+ export type TurbosSwapParams = {
4
+ poolId: string;
5
+ amount: TransactionArgument;
6
+ amountLimit: number;
7
+ a2b: boolean;
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 turbosSwapMovecall(swapParams: TurbosSwapParams, txb: Transaction, config: AggregatorConfig): Promise<TurbosSwapResult>;
@@ -0,0 +1,122 @@
1
+ import type { SuiMoveObject } from '@mysten/sui/client';
2
+ import type { CoinAsset, SuiAddress } from './sui';
3
+ export declare const DEFAULT_GAS_BUDGET_FOR_SPLIT = 1000;
4
+ export declare const DEFAULT_GAS_BUDGET_FOR_MERGE = 500;
5
+ export declare const DEFAULT_GAS_BUDGET_FOR_TRANSFER = 100;
6
+ export declare const DEFAULT_GAS_BUDGET_FOR_TRANSFER_SUI = 100;
7
+ export declare const DEFAULT_GAS_BUDGET_FOR_STAKE = 1000;
8
+ export declare const GAS_TYPE_ARG = "0x2::sui::SUI";
9
+ export declare const GAS_TYPE_ARG_LONG = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI";
10
+ export declare const GAS_SYMBOL = "SUI";
11
+ export declare const DEFAULT_NFT_TRANSFER_GAS_FEE = 450;
12
+ export declare const SUI_SYSTEM_STATE_OBJECT_ID = "0x0000000000000000000000000000000000000005";
13
+ /**
14
+ * This class provides helper methods for working with coins.
15
+ */
16
+ export declare class CoinUtils {
17
+ /**
18
+ * Get the coin type argument from a SuiMoveObject.
19
+ *
20
+ * @param obj The SuiMoveObject to get the coin type argument from.
21
+ * @returns The coin type argument, or null if it is not found.
22
+ */
23
+ static getCoinTypeArg(obj: SuiMoveObject): string | null;
24
+ /**
25
+ * Get whether a SuiMoveObject is a SUI coin.
26
+ *
27
+ * @param obj The SuiMoveObject to check.
28
+ * @returns Whether the SuiMoveObject is a SUI coin.
29
+ */
30
+ static isSUI(obj: SuiMoveObject): boolean;
31
+ /**
32
+ * Get the coin symbol from a coin type argument.
33
+ *
34
+ * @param coinTypeArg The coin type argument to get the symbol from.
35
+ * @returns The coin symbol.
36
+ */
37
+ static getCoinSymbol(coinTypeArg: string): string;
38
+ /**
39
+ * Get the balance of a SuiMoveObject.
40
+ *
41
+ * @param obj The SuiMoveObject to get the balance from.
42
+ * @returns The balance of the SuiMoveObject.
43
+ */
44
+ static getBalance(obj: SuiMoveObject): bigint;
45
+ /**
46
+ * Get the total balance of a list of CoinAsset objects for a given coin address.
47
+ *
48
+ * @param objs The list of CoinAsset objects to get the total balance for.
49
+ * @param coinAddress The coin address to get the total balance for.
50
+ * @returns The total balance of the CoinAsset objects for the given coin address.
51
+ */
52
+ static totalBalance(objs: CoinAsset[], coinAddress: SuiAddress): bigint;
53
+ /**
54
+ * Get the ID of a SuiMoveObject.
55
+ *
56
+ * @param obj The SuiMoveObject to get the ID from.
57
+ * @returns The ID of the SuiMoveObject.
58
+ */
59
+ static getID(obj: SuiMoveObject): string;
60
+ /**
61
+ * Get the coin type from a coin type argument.
62
+ *
63
+ * @param coinTypeArg The coin type argument to get the coin type from.
64
+ * @returns The coin type.
65
+ */
66
+ static getCoinTypeFromArg(coinTypeArg: string): string;
67
+ /**
68
+ * Get the CoinAsset objects for a given coin type.
69
+ *
70
+ * @param coinType The coin type to get the CoinAsset objects for.
71
+ * @param allSuiObjects The list of all SuiMoveObjects.
72
+ * @returns The CoinAsset objects for the given coin type.
73
+ */
74
+ static getCoinAssets(coinType: string, allSuiObjects: CoinAsset[]): CoinAsset[];
75
+ /**
76
+ * Get whether a coin address is a SUI coin.
77
+ *
78
+ * @param coinAddress The coin address to check.
79
+ * @returns Whether the coin address is a SUI coin.
80
+ */
81
+ static isSuiCoin(coinAddress: SuiAddress): boolean;
82
+ /**
83
+ * Select the CoinAsset objects from a list of CoinAsset objects that have a balance greater than or equal to a given amount.
84
+ *
85
+ * @param coins The list of CoinAsset objects to select from.
86
+ * @param amount The amount to select CoinAsset objects with a balance greater than or equal to.
87
+ * @param exclude A list of CoinAsset objects to exclude from the selection.
88
+ * @returns The CoinAsset objects that have a balance greater than or equal to the given amount.
89
+ */
90
+ static selectCoinObjectIdGreaterThanOrEqual(coins: CoinAsset[], amount: bigint, exclude?: string[]): {
91
+ objectArray: string[];
92
+ remainCoins: CoinAsset[];
93
+ amountArray: string[];
94
+ };
95
+ /**
96
+ * Select the CoinAsset objects from a list of CoinAsset objects that have a balance greater than or equal to a given amount.
97
+ *
98
+ * @param coins The list of CoinAsset objects to select from.
99
+ * @param amount The amount to select CoinAsset objects with a balance greater than or equal to.
100
+ * @param exclude A list of CoinAsset objects to exclude from the selection.
101
+ * @returns The CoinAsset objects that have a balance greater than or equal to the given amount.
102
+ */
103
+ static selectCoinAssetGreaterThanOrEqual(coins: CoinAsset[], amount: bigint, exclude?: string[]): {
104
+ selectedCoins: CoinAsset[];
105
+ remainingCoins: CoinAsset[];
106
+ };
107
+ /**
108
+ * Sort the CoinAsset objects by their balance.
109
+ *
110
+ * @param coins The CoinAsset objects to sort.
111
+ * @returns The sorted CoinAsset objects.
112
+ */
113
+ static sortByBalance(coins: CoinAsset[]): CoinAsset[];
114
+ static sortByBalanceDes(coins: CoinAsset[]): CoinAsset[];
115
+ /**
116
+ * Calculate the total balance of a list of CoinAsset objects.
117
+ *
118
+ * @param coins The list of CoinAsset objects to calculate the total balance for.
119
+ * @returns The total balance of the CoinAsset objects.
120
+ */
121
+ static calculateTotalBalance(coins: CoinAsset[]): bigint;
122
+ }
@@ -0,0 +1,112 @@
1
+ import type { TransactionArgument } from '@mysten/sui/transactions';
2
+ import Decimal from 'decimal.js';
3
+ /**
4
+ * Represents a SUI address, which is a string.
5
+ */
6
+ export type SuiAddress = string;
7
+ /**
8
+ * Represents a SUI object identifier, which is a string.
9
+ */
10
+ export type SuiObjectIdType = string;
11
+ /**
12
+ * Represents a BigNumber, which can be a Decimal.Value, number, or string.
13
+ */
14
+ export type BigNumber = Decimal.Value | number | string;
15
+ /**
16
+ * Represents a SUI resource, which can be of any type.
17
+ */
18
+ export type SuiResource = any;
19
+ /**
20
+ * Represents a Non-Fungible Token (NFT) with associated metadata.
21
+ */
22
+ export type NFT = {
23
+ /**
24
+ * The address or identifier of the creator of the NFT.
25
+ */
26
+ creator: string;
27
+ /**
28
+ * A description providing additional information about the NFT.
29
+ */
30
+ description: string;
31
+ /**
32
+ * The URL to the image representing the NFT visually.
33
+ */
34
+ image_url: string;
35
+ /**
36
+ * A link associated with the NFT, providing more details or interactions.
37
+ */
38
+ link: string;
39
+ /**
40
+ * The name or title of the NFT.
41
+ */
42
+ name: string;
43
+ /**
44
+ * The URL to the project or collection associated with the NFT.
45
+ */
46
+ project_url: string;
47
+ };
48
+ /**
49
+ * Represents a SUI struct tag.
50
+ */
51
+ export type SuiStructTag = {
52
+ /**
53
+ * The full address of the struct.
54
+ */
55
+ full_address: string;
56
+ /**
57
+ * The source address of the struct.
58
+ */
59
+ source_address: string;
60
+ /**
61
+ * The address of the struct.
62
+ */
63
+ address: SuiAddress;
64
+ /**
65
+ * The module to which the struct belongs.
66
+ */
67
+ module: string;
68
+ /**
69
+ * The name of the struct.
70
+ */
71
+ name: string;
72
+ /**
73
+ * An array of type arguments (SUI addresses) for the struct.
74
+ */
75
+ type_arguments: SuiAddress[];
76
+ };
77
+ /**
78
+ * Represents basic SUI data types.
79
+ */
80
+ export type SuiBasicTypes = 'address' | 'bool' | 'u8' | 'u16' | 'u32' | 'u64' | 'u128' | 'u256';
81
+ /**
82
+ * Represents a SUI transaction argument, which can be of various types.
83
+ */
84
+ export type SuiTxArg = TransactionArgument | string | number | bigint | boolean;
85
+ /**
86
+ * Represents input types for SUI data.
87
+ */
88
+ export type SuiInputTypes = 'object' | SuiBasicTypes;
89
+ /**
90
+ * Gets the default SUI input type based on the provided value.
91
+ * @param value - The value to determine the default input type for.
92
+ * @returns The default SUI input type.
93
+ * @throws Error if the type of the value is unknown.
94
+ */
95
+ export declare const getDefaultSuiInputType: (value: any) => SuiInputTypes;
96
+ /**
97
+ * Represents a coin asset with address, object ID, and balance information.
98
+ */
99
+ export type CoinAsset = {
100
+ /**
101
+ * The address type of the coin asset.
102
+ */
103
+ coinAddress: SuiAddress;
104
+ /**
105
+ * The object identifier of the coin asset.
106
+ */
107
+ coinObjectId: SuiObjectIdType;
108
+ /**
109
+ * The balance amount of the coin asset.
110
+ */
111
+ balance: bigint;
112
+ };