aftermath-ts-sdk 1.2.63 → 1.2.64-docs.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/README.md +61 -27
- package/dist/general/dynamicGas/dynamicGas.d.ts +34 -0
- package/dist/general/dynamicGas/dynamicGas.d.ts.map +1 -1
- package/dist/general/dynamicGas/dynamicGas.js +34 -0
- package/dist/general/dynamicGas/dynamicGasTypes.d.ts +25 -0
- package/dist/general/dynamicGas/dynamicGasTypes.d.ts.map +1 -1
- package/dist/general/prices/prices.d.ts +73 -0
- package/dist/general/prices/prices.d.ts.map +1 -1
- package/dist/general/prices/prices.js +73 -0
- package/dist/general/providers/aftermath.d.ts +106 -25
- package/dist/general/providers/aftermath.d.ts.map +1 -1
- package/dist/general/providers/aftermath.js +108 -27
- package/dist/general/providers/aftermathApi.d.ts +127 -8
- package/dist/general/providers/aftermathApi.d.ts.map +1 -1
- package/dist/general/providers/aftermathApi.js +132 -12
- package/dist/general/types/castingTypes.d.ts +0 -7
- package/dist/general/types/castingTypes.d.ts.map +1 -1
- package/dist/general/types/castingTypes.js +6 -0
- package/dist/general/types/generalTypes.d.ts +228 -7
- package/dist/general/types/generalTypes.d.ts.map +1 -1
- package/dist/general/types/suiTypes.d.ts +0 -16
- package/dist/general/types/suiTypes.d.ts.map +1 -1
- package/dist/general/types/suiTypes.js +3 -25
- package/dist/general/utils/casting.d.ts +159 -3
- package/dist/general/utils/casting.d.ts.map +1 -1
- package/dist/general/utils/casting.js +162 -16
- package/dist/general/utils/fixedUtils.d.ts +89 -2
- package/dist/general/utils/fixedUtils.d.ts.map +1 -1
- package/dist/general/utils/fixedUtils.js +81 -4
- package/dist/general/utils/helpers.d.ts +320 -9
- package/dist/general/utils/helpers.d.ts.map +1 -1
- package/dist/general/utils/helpers.js +350 -89
- package/dist/general/utils/iFixedUtils.d.ts +64 -0
- package/dist/general/utils/iFixedUtils.d.ts.map +1 -1
- package/dist/general/utils/iFixedUtils.js +64 -0
- package/dist/general/wallet/wallet.d.ts +75 -0
- package/dist/general/wallet/wallet.d.ts.map +1 -1
- package/dist/general/wallet/wallet.js +75 -5
- package/dist/packages/auth/auth.d.ts +113 -0
- package/dist/packages/auth/auth.d.ts.map +1 -1
- package/dist/packages/auth/auth.js +129 -15
- package/dist/packages/auth/authTypes.d.ts +66 -0
- package/dist/packages/auth/authTypes.d.ts.map +1 -1
- package/dist/packages/coin/api/coinApi.d.ts.map +1 -1
- package/dist/packages/coin/api/coinApi.js +28 -20
- package/dist/packages/coin/coin.d.ts +250 -0
- package/dist/packages/coin/coin.d.ts.map +1 -1
- package/dist/packages/coin/coin.js +238 -14
- package/dist/packages/coin/coinTypes.d.ts +93 -0
- package/dist/packages/coin/coinTypes.d.ts.map +1 -1
- package/dist/packages/dca/dca.d.ts +124 -35
- package/dist/packages/dca/dca.d.ts.map +1 -1
- package/dist/packages/dca/dca.js +127 -37
- package/dist/packages/dca/dcaTypes.d.ts +213 -28
- package/dist/packages/dca/dcaTypes.d.ts.map +1 -1
- package/dist/packages/farms/farms.d.ts +184 -1
- package/dist/packages/farms/farms.d.ts.map +1 -1
- package/dist/packages/farms/farms.js +185 -11
- package/dist/packages/farms/farmsStakedPosition.d.ts +140 -6
- package/dist/packages/farms/farmsStakedPosition.d.ts.map +1 -1
- package/dist/packages/farms/farmsStakedPosition.js +189 -144
- package/dist/packages/farms/farmsStakingPool.d.ts +161 -1
- package/dist/packages/farms/farmsStakingPool.d.ts.map +1 -1
- package/dist/packages/farms/farmsStakingPool.js +176 -70
- package/dist/packages/farms/farmsTypes.d.ts +283 -2
- package/dist/packages/farms/farmsTypes.d.ts.map +1 -1
- package/dist/packages/farms/farmsTypes.js +18 -0
- package/dist/packages/limitOrders/limitOrders.d.ts +108 -21
- package/dist/packages/limitOrders/limitOrders.d.ts.map +1 -1
- package/dist/packages/limitOrders/limitOrders.js +110 -22
- package/dist/packages/limitOrders/limitOrdersTypes.d.ts +142 -0
- package/dist/packages/limitOrders/limitOrdersTypes.d.ts.map +1 -1
- package/dist/packages/multisig/multisig.d.ts +33 -4
- package/dist/packages/multisig/multisig.d.ts.map +1 -1
- package/dist/packages/multisig/multisig.js +33 -4
- package/dist/packages/multisig/multisigTypes.d.ts +17 -0
- package/dist/packages/multisig/multisigTypes.d.ts.map +1 -1
- package/dist/packages/perpetuals/api/perpetualsApi.d.ts.map +1 -1
- package/dist/packages/pools/pool.d.ts +327 -85
- package/dist/packages/pools/pool.d.ts.map +1 -1
- package/dist/packages/pools/pool.js +333 -91
- package/dist/packages/pools/pools.d.ts +299 -37
- package/dist/packages/pools/pools.d.ts.map +1 -1
- package/dist/packages/pools/pools.js +306 -52
- package/dist/packages/pools/poolsTypes.d.ts +273 -8
- package/dist/packages/pools/poolsTypes.d.ts.map +1 -1
- package/dist/packages/referralVault/referralVault.d.ts +37 -0
- package/dist/packages/referralVault/referralVault.d.ts.map +1 -1
- package/dist/packages/referralVault/referralVault.js +37 -0
- package/dist/packages/router/router.d.ts +213 -17
- package/dist/packages/router/router.d.ts.map +1 -1
- package/dist/packages/router/router.js +214 -18
- package/dist/packages/router/routerTypes.d.ts +198 -14
- package/dist/packages/router/routerTypes.d.ts.map +1 -1
- package/dist/packages/staking/staking.d.ts +301 -43
- package/dist/packages/staking/staking.d.ts.map +1 -1
- package/dist/packages/staking/staking.js +308 -51
- package/dist/packages/staking/stakingTypes.d.ts +426 -6
- package/dist/packages/staking/stakingTypes.d.ts.map +1 -1
- package/dist/packages/staking/stakingTypes.js +19 -0
- package/dist/packages/sui/sui.d.ts +39 -0
- package/dist/packages/sui/sui.d.ts.map +1 -1
- package/dist/packages/sui/sui.js +39 -0
- package/dist/packages/userData/userData.d.ts +66 -12
- package/dist/packages/userData/userData.d.ts.map +1 -1
- package/dist/packages/userData/userData.js +66 -12
- package/dist/packages/userData/userDataTypes.d.ts +19 -0
- package/dist/packages/userData/userDataTypes.d.ts.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +0 -1
- package/package.json +1 -1
- package/dist/general/historicalData/historicalData.d.ts +0 -15
- package/dist/general/historicalData/historicalData.d.ts.map +0 -1
- package/dist/general/historicalData/historicalData.js +0 -45
- package/dist/general/historicalData/historicalDataTypes.d.ts +0 -10
- package/dist/general/historicalData/historicalDataTypes.d.ts.map +0 -1
- package/dist/general/historicalData/historicalDataTypes.js +0 -2
|
@@ -3,111 +3,259 @@ import { Caller } from "../../general/utils/caller";
|
|
|
3
3
|
import { Transaction } from "@mysten/sui/transactions";
|
|
4
4
|
import { AftermathApi } from "../../general/providers";
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* The `Pool` class encapsulates all the functionality needed to interact
|
|
7
|
+
* with a specific AMM pool on the Aftermath platform. It allows you to
|
|
8
|
+
* calculate trade amounts, deposit/withdraw amounts, fetch transactions,
|
|
9
|
+
* and retrieve on-chain statistics and event data.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const afSdk = new Aftermath("MAINNET");
|
|
14
|
+
* await afSdk.init(); // initialize provider
|
|
15
|
+
*
|
|
16
|
+
* const pools = afSdk.Pools();
|
|
17
|
+
* const pool = await pools.getPool({ objectId: "0x..." });
|
|
18
|
+
*
|
|
19
|
+
* const stats = await pool.getStats();
|
|
20
|
+
* const tradeTx = await pool.getTradeTransaction({
|
|
21
|
+
* walletAddress: "0x...",
|
|
22
|
+
* coinInType: "0x2::sui::SUI",
|
|
23
|
+
* coinInAmount: BigInt(1e9),
|
|
24
|
+
* coinOutType: "0x<yourCoin>",
|
|
25
|
+
* slippage: 0.01,
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
8
28
|
*/
|
|
9
29
|
export declare class Pool extends Caller {
|
|
10
30
|
readonly pool: PoolObject;
|
|
11
31
|
private readonly Provider?;
|
|
12
32
|
/**
|
|
13
|
-
*
|
|
33
|
+
* Internal margin of error used in trade calculations to prevent
|
|
34
|
+
* exceeding maximum allowed percentages of pool balances.
|
|
14
35
|
*/
|
|
15
36
|
private static readonly constants;
|
|
16
37
|
/**
|
|
17
|
-
*
|
|
38
|
+
* An optional cached object containing statistical data about the pool
|
|
39
|
+
* (volume, fees, APR, etc.).
|
|
18
40
|
*/
|
|
19
41
|
stats: PoolStats | undefined;
|
|
20
42
|
/**
|
|
21
|
-
* Creates a new instance of the Pool class.
|
|
22
|
-
*
|
|
23
|
-
* @param
|
|
24
|
-
* @param
|
|
43
|
+
* Creates a new instance of the `Pool` class for on-chain interaction.
|
|
44
|
+
*
|
|
45
|
+
* @param pool - The fetched `PoolObject` from Aftermath API or on-chain query.
|
|
46
|
+
* @param config - Optional caller configuration (e.g., network, access token).
|
|
47
|
+
* @param Provider - An optional `AftermathApi` instance for advanced transaction usage.
|
|
25
48
|
*/
|
|
26
49
|
constructor(pool: PoolObject, config?: CallerConfig, Provider?: AftermathApi | undefined);
|
|
27
50
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* @
|
|
51
|
+
* Builds or fetches a deposit transaction to add liquidity to this pool.
|
|
52
|
+
* The resulting `Transaction` can be signed and submitted by the user.
|
|
53
|
+
*
|
|
54
|
+
* @param inputs - The deposit parameters including coin amounts, slippage, etc.
|
|
55
|
+
* @returns A `Transaction` to deposit funds into the pool.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const depositTx = await pool.getDepositTransaction({
|
|
60
|
+
* walletAddress: "0x...",
|
|
61
|
+
* amountsIn: { "0x<coin>": BigInt(1000000) },
|
|
62
|
+
* slippage: 0.01,
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
32
65
|
*/
|
|
33
66
|
getDepositTransaction(inputs: ApiPoolDepositBody): Promise<Transaction>;
|
|
34
67
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* @param
|
|
38
|
-
* @returns
|
|
68
|
+
* Builds or fetches a withdrawal transaction to remove liquidity from this pool.
|
|
69
|
+
*
|
|
70
|
+
* @param inputs - The parameters specifying how much LP is burned, desired coins out, slippage, etc.
|
|
71
|
+
* @returns A `Transaction` to withdraw funds from the pool.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const withdrawTx = await pool.getWithdrawTransaction({
|
|
76
|
+
* walletAddress: "0x...",
|
|
77
|
+
* amountsOutDirection: {
|
|
78
|
+
* "0x<coin>": BigInt(500000),
|
|
79
|
+
* },
|
|
80
|
+
* lpCoinAmount: BigInt(1000000),
|
|
81
|
+
* slippage: 0.01,
|
|
82
|
+
* });
|
|
83
|
+
* ```
|
|
39
84
|
*/
|
|
40
85
|
getWithdrawTransaction(inputs: ApiPoolWithdrawBody): Promise<Transaction>;
|
|
41
86
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* @
|
|
87
|
+
* Builds or fetches a transaction to withdraw all coin types from this pool,
|
|
88
|
+
* effectively "burning" an LP position in exchange for multiple coin outputs.
|
|
89
|
+
*
|
|
90
|
+
* @param inputs - The parameters specifying how much LP to burn.
|
|
91
|
+
* @returns A `Transaction` to withdraw all coins from the pool in proportion.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* const allCoinWithdrawTx = await pool.getAllCoinWithdrawTransaction({
|
|
96
|
+
* walletAddress: "0x...",
|
|
97
|
+
* lpCoinAmount: BigInt(500000),
|
|
98
|
+
* });
|
|
99
|
+
* ```
|
|
46
100
|
*/
|
|
47
101
|
getAllCoinWithdrawTransaction(inputs: ApiPoolAllCoinWithdrawBody): Promise<Transaction>;
|
|
48
102
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* @param
|
|
52
|
-
* @returns
|
|
103
|
+
* Builds or fetches a trade transaction to swap between two coin types in this pool.
|
|
104
|
+
*
|
|
105
|
+
* @param inputs - The trade parameters including coin in/out, amounts, slippage, etc.
|
|
106
|
+
* @returns A `Transaction` that can be signed and executed for the swap.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* const tradeTx = await pool.getTradeTransaction({
|
|
111
|
+
* walletAddress: "0x...",
|
|
112
|
+
* coinInType: "0x<coinA>",
|
|
113
|
+
* coinInAmount: BigInt(1000000),
|
|
114
|
+
* coinOutType: "0x<coinB>",
|
|
115
|
+
* slippage: 0.005,
|
|
116
|
+
* });
|
|
117
|
+
* ```
|
|
53
118
|
*/
|
|
54
119
|
getTradeTransaction(inputs: ApiPoolTradeBody): Promise<Transaction>;
|
|
120
|
+
/**
|
|
121
|
+
* Builds a transaction to update the DAO fee percentage for this pool,
|
|
122
|
+
* if it has a DAO fee configured. The user must own the appropriate
|
|
123
|
+
* `daoFeePoolOwnerCap`.
|
|
124
|
+
*
|
|
125
|
+
* @param inputs - Includes user wallet, `daoFeePoolOwnerCapId`, and the new fee percentage.
|
|
126
|
+
* @returns A `Transaction` that can be signed to update the DAO fee on chain.
|
|
127
|
+
* @throws If this pool has no DAO fee configuration.
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* const tx = await pool.getUpdateDaoFeeTransaction({
|
|
132
|
+
* walletAddress: "0x...",
|
|
133
|
+
* daoFeePoolOwnerCapId: "0x<capId>",
|
|
134
|
+
* newFeePercentage: 0.01, // 1%
|
|
135
|
+
* });
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
55
138
|
getUpdateDaoFeeTransaction(inputs: {
|
|
56
139
|
walletAddress: SuiAddress;
|
|
57
140
|
daoFeePoolOwnerCapId: ObjectId;
|
|
58
141
|
newFeePercentage: Percentage;
|
|
59
142
|
}): Promise<Transaction>;
|
|
143
|
+
/**
|
|
144
|
+
* Builds a transaction to update the DAO fee recipient for this pool,
|
|
145
|
+
* if it has a DAO fee configured. The user must own the appropriate
|
|
146
|
+
* `daoFeePoolOwnerCap`.
|
|
147
|
+
*
|
|
148
|
+
* @param inputs - Includes user wallet, `daoFeePoolOwnerCapId`, and the new fee recipient.
|
|
149
|
+
* @returns A `Transaction` that can be signed to update the DAO fee recipient on chain.
|
|
150
|
+
* @throws If this pool has no DAO fee configuration.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* const tx = await pool.getUpdateDaoFeeRecipientTransaction({
|
|
155
|
+
* walletAddress: "0x...",
|
|
156
|
+
* daoFeePoolOwnerCapId: "0x<capId>",
|
|
157
|
+
* newFeeRecipient: "0x<recipient>",
|
|
158
|
+
* });
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
60
161
|
getUpdateDaoFeeRecipientTransaction(inputs: {
|
|
61
162
|
walletAddress: SuiAddress;
|
|
62
163
|
daoFeePoolOwnerCapId: ObjectId;
|
|
63
164
|
newFeeRecipient: SuiAddress;
|
|
64
165
|
}): Promise<Transaction>;
|
|
65
166
|
/**
|
|
66
|
-
* Fetches
|
|
67
|
-
*
|
|
68
|
-
*
|
|
167
|
+
* Fetches comprehensive pool statistics (volume, TVL, fees, APR, etc.) from the Aftermath API.
|
|
168
|
+
* Also caches the result in `this.stats`.
|
|
169
|
+
*
|
|
170
|
+
* @returns A promise resolving to `PoolStats` object.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* const stats = await pool.getStats();
|
|
175
|
+
* console.log(stats.volume, stats.fees, stats.apr);
|
|
176
|
+
* ```
|
|
69
177
|
*/
|
|
70
178
|
getStats(): Promise<PoolStats>;
|
|
71
179
|
/**
|
|
72
|
-
*
|
|
73
|
-
*
|
|
180
|
+
* Caches the provided stats object into `this.stats`.
|
|
181
|
+
*
|
|
182
|
+
* @param stats - The `PoolStats` object to store.
|
|
74
183
|
*/
|
|
75
184
|
setStats(stats: PoolStats): void;
|
|
76
185
|
/**
|
|
77
|
-
* Fetches
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* @param
|
|
81
|
-
* @returns
|
|
186
|
+
* Fetches an array of volume data points for a specified timeframe.
|
|
187
|
+
* This is often used for charting or historical references.
|
|
188
|
+
*
|
|
189
|
+
* @param inputs - Contains a `timeframe` key, such as `"1D"` or `"1W"`.
|
|
190
|
+
* @returns A promise resolving to an array of `PoolDataPoint`.
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```typescript
|
|
194
|
+
* const volumeData = await pool.getVolumeData({ timeframe: "1D" });
|
|
195
|
+
* console.log(volumeData); // e.g. [{ time: 1686000000, value: 123.45 }, ...]
|
|
196
|
+
* ```
|
|
82
197
|
*/
|
|
83
198
|
getVolumeData(inputs: {
|
|
84
199
|
timeframe: PoolGraphDataTimeframeKey;
|
|
85
200
|
}): Promise<PoolDataPoint[]>;
|
|
86
201
|
/**
|
|
87
|
-
* Fetches
|
|
88
|
-
*
|
|
89
|
-
* @param
|
|
90
|
-
* @
|
|
91
|
-
*
|
|
202
|
+
* Fetches an array of fee data points for a specified timeframe.
|
|
203
|
+
*
|
|
204
|
+
* @param inputs - Contains a `timeframe` key, e.g., `"1D"` or `"1W"`.
|
|
205
|
+
* @returns A promise resolving to an array of `PoolDataPoint`.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```typescript
|
|
209
|
+
* const feeData = await pool.getFeeData({ timeframe: "1D" });
|
|
210
|
+
* console.log(feeData);
|
|
211
|
+
* ```
|
|
92
212
|
*/
|
|
93
213
|
getFeeData(inputs: {
|
|
94
214
|
timeframe: PoolGraphDataTimeframeKey;
|
|
95
215
|
}): Promise<PoolDataPoint[]>;
|
|
96
216
|
/**
|
|
97
|
-
* Retrieves the
|
|
98
|
-
*
|
|
217
|
+
* Retrieves the 24-hour volume for this specific pool.
|
|
218
|
+
*
|
|
219
|
+
* @returns A promise resolving to a number (volume in 24h).
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```typescript
|
|
223
|
+
* const vol24h = await pool.getVolume24hrs();
|
|
224
|
+
* console.log("Pool 24h Volume:", vol24h);
|
|
225
|
+
* ```
|
|
99
226
|
*/
|
|
100
227
|
getVolume24hrs: () => Promise<number>;
|
|
228
|
+
/**
|
|
229
|
+
* Fetches user interaction events (deposit/withdraw) with this pool, optionally paginated.
|
|
230
|
+
*
|
|
231
|
+
* @param inputs - Includes user `walletAddress` and optional pagination fields.
|
|
232
|
+
* @returns A promise that resolves to `PoolDepositEvent | PoolWithdrawEvent` objects with a cursor if more exist.
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* ```typescript
|
|
236
|
+
* const events = await pool.getInteractionEvents({ walletAddress: "0x...", limit: 10 });
|
|
237
|
+
* console.log(events.events, events.nextCursor);
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
101
240
|
getInteractionEvents(inputs: ApiIndexerEventsBody & {
|
|
102
241
|
walletAddress: SuiAddress;
|
|
103
242
|
}): Promise<IndexerEventsWithCursor<PoolDepositEvent | PoolWithdrawEvent>>;
|
|
104
243
|
/**
|
|
105
|
-
* Calculates the spot price for
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
* @param
|
|
109
|
-
* @
|
|
110
|
-
*
|
|
244
|
+
* Calculates the instantaneous spot price for swapping from `coinInType`
|
|
245
|
+
* to `coinOutType` within this pool. Optionally includes fees in the price.
|
|
246
|
+
*
|
|
247
|
+
* @param inputs - Object specifying input coin, output coin, and a boolean for `withFees`.
|
|
248
|
+
* @returns The numerical spot price (float).
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```typescript
|
|
252
|
+
* const price = pool.getSpotPrice({
|
|
253
|
+
* coinInType: "0x<coinA>",
|
|
254
|
+
* coinOutType: "0x<coinB>",
|
|
255
|
+
* withFees: true,
|
|
256
|
+
* });
|
|
257
|
+
* console.log("Spot Price:", price);
|
|
258
|
+
* ```
|
|
111
259
|
*/
|
|
112
260
|
getSpotPrice: (inputs: {
|
|
113
261
|
coinInType: CoinType;
|
|
@@ -115,13 +263,22 @@ export declare class Pool extends Caller {
|
|
|
115
263
|
withFees?: boolean;
|
|
116
264
|
}) => number;
|
|
117
265
|
/**
|
|
118
|
-
* Calculates
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
* @param
|
|
123
|
-
* @
|
|
124
|
-
* @
|
|
266
|
+
* Calculates how much output coin you would receive when trading
|
|
267
|
+
* a given input coin and amount in this pool, factoring in protocol
|
|
268
|
+
* and optional DAO fees.
|
|
269
|
+
*
|
|
270
|
+
* @param inputs - Includes `coinInType`, `coinInAmount`, and `coinOutType`.
|
|
271
|
+
* @returns A bigint representing how many output coins you'd get.
|
|
272
|
+
* @throws Error if the trade amount is too large relative to the pool balance.
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* ```typescript
|
|
276
|
+
* const amountOut = pool.getTradeAmountOut({
|
|
277
|
+
* coinInType: "0x<coinA>",
|
|
278
|
+
* coinInAmount: BigInt(1000000),
|
|
279
|
+
* coinOutType: "0x<coinB>",
|
|
280
|
+
* });
|
|
281
|
+
* ```
|
|
125
282
|
*/
|
|
126
283
|
getTradeAmountOut: (inputs: {
|
|
127
284
|
coinInType: CoinType;
|
|
@@ -130,13 +287,21 @@ export declare class Pool extends Caller {
|
|
|
130
287
|
referral?: boolean;
|
|
131
288
|
}) => Balance;
|
|
132
289
|
/**
|
|
133
|
-
* Calculates
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
* @param
|
|
137
|
-
* @
|
|
138
|
-
* @
|
|
139
|
-
*
|
|
290
|
+
* Calculates how much input coin is required to obtain a certain output coin amount
|
|
291
|
+
* from this pool, factoring in fees.
|
|
292
|
+
*
|
|
293
|
+
* @param inputs - Includes `coinInType`, desired `coinOutAmount`, and `coinOutType`.
|
|
294
|
+
* @returns A bigint representing the needed input amount.
|
|
295
|
+
* @throws Error if the desired output is too large relative to pool balances.
|
|
296
|
+
*
|
|
297
|
+
* @example
|
|
298
|
+
* ```typescript
|
|
299
|
+
* const amountIn = pool.getTradeAmountIn({
|
|
300
|
+
* coinInType: "0x<coinA>",
|
|
301
|
+
* coinOutAmount: BigInt(1000000),
|
|
302
|
+
* coinOutType: "0x<coinB>"
|
|
303
|
+
* });
|
|
304
|
+
* ```
|
|
140
305
|
*/
|
|
141
306
|
getTradeAmountIn: (inputs: {
|
|
142
307
|
coinInType: CoinType;
|
|
@@ -145,11 +310,19 @@ export declare class Pool extends Caller {
|
|
|
145
310
|
referral?: boolean;
|
|
146
311
|
}) => Balance;
|
|
147
312
|
/**
|
|
148
|
-
* Calculates
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
* @param
|
|
152
|
-
* @returns
|
|
313
|
+
* Calculates how many LP tokens you receive for providing liquidity
|
|
314
|
+
* in specific coin amounts. Also returns a ratio for reference.
|
|
315
|
+
*
|
|
316
|
+
* @param inputs - Contains the amounts in for each coin in the pool.
|
|
317
|
+
* @returns An object with `lpAmountOut` and `lpRatio`.
|
|
318
|
+
*
|
|
319
|
+
* @example
|
|
320
|
+
* ```typescript
|
|
321
|
+
* const depositCalc = pool.getDepositLpAmountOut({
|
|
322
|
+
* amountsIn: { "0x<coinA>": BigInt(1000000), "0x<coinB>": BigInt(500000) },
|
|
323
|
+
* });
|
|
324
|
+
* console.log(depositCalc.lpAmountOut, depositCalc.lpRatio);
|
|
325
|
+
* ```
|
|
153
326
|
*/
|
|
154
327
|
getDepositLpAmountOut: (inputs: {
|
|
155
328
|
amountsIn: CoinsToBalance;
|
|
@@ -159,59 +332,128 @@ export declare class Pool extends Caller {
|
|
|
159
332
|
lpRatio: number;
|
|
160
333
|
};
|
|
161
334
|
/**
|
|
162
|
-
* Calculates
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
* @param
|
|
166
|
-
* @
|
|
167
|
-
*
|
|
335
|
+
* Calculates how many coins a user will receive when withdrawing a specific ratio or LP amount.
|
|
336
|
+
* This method is used in multi-coin withdrawals where you specify how much of each coin you want.
|
|
337
|
+
*
|
|
338
|
+
* @param inputs - The LP ratio and an object specifying direction amounts for each coin.
|
|
339
|
+
* @returns A `CoinsToBalance` object with final amounts out, factoring in DAO fees.
|
|
340
|
+
*
|
|
341
|
+
* @example
|
|
342
|
+
* ```typescript
|
|
343
|
+
* const outAmounts = pool.getWithdrawAmountsOut({
|
|
344
|
+
* lpRatio: 0.1,
|
|
345
|
+
* amountsOutDirection: { "0x<coinA>": BigInt(500000) },
|
|
346
|
+
* });
|
|
347
|
+
* console.log(outAmounts);
|
|
348
|
+
* ```
|
|
168
349
|
*/
|
|
169
350
|
getWithdrawAmountsOut: (inputs: {
|
|
170
351
|
lpRatio: number;
|
|
171
352
|
amountsOutDirection: CoinsToBalance;
|
|
172
353
|
referral?: boolean;
|
|
173
354
|
}) => CoinsToBalance;
|
|
355
|
+
/**
|
|
356
|
+
* A simplified multi-coin withdraw approach: calculates all outputs by proportion of the
|
|
357
|
+
* user's LP share among selected coin types. Useful for approximate or "blind" all-coin out logic.
|
|
358
|
+
*
|
|
359
|
+
* @param inputs - Contains the `lpCoinAmountIn` to burn, and which coin types to receive.
|
|
360
|
+
* @returns A record mapping coin type => final amounts out.
|
|
361
|
+
*/
|
|
174
362
|
getWithdrawAmountsOutSimple: (inputs: {
|
|
175
363
|
lpCoinAmountIn: Balance;
|
|
176
364
|
coinTypesOut: CoinType[];
|
|
177
365
|
referral?: boolean;
|
|
178
366
|
}) => CoinsToBalance;
|
|
179
367
|
/**
|
|
180
|
-
* Calculates
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
* @param
|
|
184
|
-
* @returns
|
|
368
|
+
* Calculates how many coins you get when withdrawing **all** coin types from the pool,
|
|
369
|
+
* given a ratio. This is typically used for proportionate withdrawal.
|
|
370
|
+
*
|
|
371
|
+
* @param inputs - Includes `lpRatio`, the portion of your LP to burn (0 < ratio < 1).
|
|
372
|
+
* @returns A record of coin type => amounts out, after factoring in any fees.
|
|
373
|
+
*
|
|
374
|
+
* @example
|
|
375
|
+
* ```typescript
|
|
376
|
+
* const allOut = pool.getAllCoinWithdrawAmountsOut({ lpRatio: 0.1 });
|
|
377
|
+
* console.log(allOut); // amounts for each coin
|
|
378
|
+
* ```
|
|
185
379
|
*/
|
|
186
380
|
getAllCoinWithdrawAmountsOut: (inputs: {
|
|
187
381
|
lpRatio: number;
|
|
188
382
|
referral?: boolean;
|
|
189
383
|
}) => CoinsToBalance;
|
|
190
384
|
/**
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
* @
|
|
385
|
+
* For multi-coin withdraw, calculates the ratio of how much LP you are burning
|
|
386
|
+
* relative to the total supply. e.g. if user burns 100 of 1000 supply => ratio 0.1.
|
|
387
|
+
*
|
|
388
|
+
* @param inputs - Contains the `lpCoinAmountIn` to burn.
|
|
389
|
+
* @returns A float ratio (0 < ratio < 1).
|
|
195
390
|
*/
|
|
196
391
|
getMultiCoinWithdrawLpRatio: (inputs: {
|
|
197
392
|
lpCoinAmountIn: bigint;
|
|
198
393
|
}) => number;
|
|
199
394
|
/**
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
* @
|
|
395
|
+
* For an all-coin withdraw, calculates the ratio of how much LP is burned
|
|
396
|
+
* relative to total supply. e.g. if user burns 50 of 200 supply => ratio 0.25.
|
|
397
|
+
*
|
|
398
|
+
* @param inputs - Contains the `lpCoinAmountIn`.
|
|
399
|
+
* @returns A float ratio, typically 0 < ratio < 1.
|
|
204
400
|
*/
|
|
205
401
|
getAllCoinWithdrawLpRatio: (inputs: {
|
|
206
402
|
lpCoinAmountIn: bigint;
|
|
207
403
|
}) => number;
|
|
404
|
+
/**
|
|
405
|
+
* Returns an array of coin types in ascending lexicographic order
|
|
406
|
+
* for the coins contained in this pool.
|
|
407
|
+
*
|
|
408
|
+
* @returns An array of coin type strings.
|
|
409
|
+
*/
|
|
208
410
|
coins: () => CoinType[];
|
|
411
|
+
/**
|
|
412
|
+
* Returns an array of `PoolCoin` objects, one for each coin in this pool,
|
|
413
|
+
* sorted lexicographically by coin type.
|
|
414
|
+
*
|
|
415
|
+
* @returns An array of `PoolCoin`.
|
|
416
|
+
*/
|
|
209
417
|
poolCoins: () => PoolCoin[];
|
|
418
|
+
/**
|
|
419
|
+
* Returns an array of `[CoinType, PoolCoin]` pairs, sorted by coin type.
|
|
420
|
+
*
|
|
421
|
+
* @returns An array of coin-type => `PoolCoin` pairs.
|
|
422
|
+
*/
|
|
210
423
|
poolCoinEntries: () => [CoinType, PoolCoin][];
|
|
424
|
+
/**
|
|
425
|
+
* Returns the current DAO fee percentage, if configured (0 < fee <= 100%).
|
|
426
|
+
*
|
|
427
|
+
* @returns A decimal fraction representing the fee (e.g., 0.01 = 1%) or `undefined`.
|
|
428
|
+
*/
|
|
211
429
|
daoFeePercentage: () => Percentage | undefined;
|
|
430
|
+
/**
|
|
431
|
+
* Returns the Sui address that currently receives the DAO fee portion of
|
|
432
|
+
* pool trades, or `undefined` if no DAO fee is configured.
|
|
433
|
+
*
|
|
434
|
+
* @returns The DAO fee recipient address.
|
|
435
|
+
*/
|
|
212
436
|
daoFeeRecipient: () => SuiAddress | undefined;
|
|
437
|
+
/**
|
|
438
|
+
* Applies the DAO fee (if present) to a given `amount`, effectively reducing
|
|
439
|
+
* that amount by the fee fraction. e.g. if fee is 2%, it returns 98% of the input.
|
|
440
|
+
*
|
|
441
|
+
* @param inputs - Contains `amount` as a bigint.
|
|
442
|
+
* @returns The post-fee amount as a bigint.
|
|
443
|
+
*/
|
|
213
444
|
private getAmountWithDAOFee;
|
|
445
|
+
/**
|
|
446
|
+
* The inverse operation of `getAmountWithDAOFee`, used in internal calculations
|
|
447
|
+
* when we need to back out how much input was needed prior to the fee cut.
|
|
448
|
+
*
|
|
449
|
+
* @param inputs - Contains `amount` as a bigint.
|
|
450
|
+
* @returns The pre-fee amount as a bigint.
|
|
451
|
+
*/
|
|
214
452
|
private getAmountWithoutDAOFee;
|
|
453
|
+
/**
|
|
454
|
+
* Provides an instance of the Pools provider from `AftermathApi`.
|
|
455
|
+
* Throws an error if not defined.
|
|
456
|
+
*/
|
|
215
457
|
private useProvider;
|
|
216
458
|
}
|
|
217
459
|
//# sourceMappingURL=pool.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../../../src/packages/pools/pool.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACnB,OAAO,EACP,QAAQ,EACR,cAAc,EACd,aAAa,EACb,yBAAyB,EACzB,UAAU,EACV,SAAS,EAET,gBAAgB,EAChB,iBAAiB,EAGjB,0BAA0B,EAC1B,oBAAoB,EACpB,uBAAuB,EACvB,UAAU,EACV,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAGpD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD
|
|
1
|
+
{"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../../../src/packages/pools/pool.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACnB,OAAO,EACP,QAAQ,EACR,cAAc,EACd,aAAa,EACb,yBAAyB,EACzB,UAAU,EACV,SAAS,EAET,gBAAgB,EAChB,iBAAiB,EAGjB,0BAA0B,EAC1B,oBAAoB,EACpB,uBAAuB,EACvB,UAAU,EACV,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAGpD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;;;;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