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
|
@@ -17,14 +17,23 @@ const caller_1 = require("../../general/utils/caller");
|
|
|
17
17
|
const helpers_1 = require("../../general/utils/helpers");
|
|
18
18
|
const fixedUtils_1 = require("../../general/utils/fixedUtils");
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
20
|
+
* The `Pools` class provides a high-level interface for interacting with
|
|
21
|
+
* Aftermath Finance liquidity pools. It allows fetching individual or multiple
|
|
22
|
+
* pools, managing liquidity pool tokens (LP tokens), and creating new pools
|
|
23
|
+
* if you have the required privileges.
|
|
21
24
|
*
|
|
22
25
|
* @example
|
|
23
|
-
* ```
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* const
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const afSdk = new Aftermath("MAINNET");
|
|
28
|
+
* await afSdk.init(); // initialize provider
|
|
29
|
+
*
|
|
30
|
+
* const pools = afSdk.Pools();
|
|
31
|
+
*
|
|
32
|
+
* // Fetch a single pool
|
|
33
|
+
* const pool = await pools.getPool({ objectId: "0x<poolId>" });
|
|
34
|
+
*
|
|
35
|
+
* // Fetch multiple pools
|
|
36
|
+
* const poolArray = await pools.getPools({ objectIds: ["0x<id1>", "0x<id2>"] });
|
|
28
37
|
* ```
|
|
29
38
|
*/
|
|
30
39
|
class Pools extends caller_1.Caller {
|
|
@@ -32,10 +41,10 @@ class Pools extends caller_1.Caller {
|
|
|
32
41
|
// Constructor
|
|
33
42
|
// =========================================================================
|
|
34
43
|
/**
|
|
35
|
-
* Creates `Pools`
|
|
44
|
+
* Creates a new `Pools` instance for querying and managing AMM pools on Aftermath.
|
|
36
45
|
*
|
|
37
|
-
* @param
|
|
38
|
-
* @
|
|
46
|
+
* @param config - Optional configuration object specifying network or access token.
|
|
47
|
+
* @param Provider - An optional `AftermathApi` instance providing advanced transaction building.
|
|
39
48
|
*/
|
|
40
49
|
constructor(config, Provider) {
|
|
41
50
|
super(config, "pools");
|
|
@@ -44,30 +53,30 @@ class Pools extends caller_1.Caller {
|
|
|
44
53
|
// Inspections
|
|
45
54
|
// =========================================================================
|
|
46
55
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* @
|
|
50
|
-
* @
|
|
56
|
+
* Retrieves the on-chain pool object ID corresponding to a specific LP coin type.
|
|
57
|
+
*
|
|
58
|
+
* @param inputs - Contains the `lpCoinType` string.
|
|
59
|
+
* @returns The pool object ID if it exists.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const poolId = await pools.getPoolObjectIdForLpCoinType({
|
|
64
|
+
* lpCoinType: "0x<lpCoinType>"
|
|
65
|
+
* });
|
|
66
|
+
* console.log(poolId);
|
|
67
|
+
* ```
|
|
51
68
|
*/
|
|
52
69
|
this.getPoolObjectIdForLpCoinType = (inputs) => {
|
|
53
70
|
return this.getPoolObjectIdsForLpCoinTypes({
|
|
54
71
|
lpCoinTypes: [inputs.lpCoinType],
|
|
55
72
|
});
|
|
56
73
|
};
|
|
57
|
-
this.getPoolObjectIdsForLpCoinTypes = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
58
|
-
// TODO: handle this case
|
|
59
|
-
// if (
|
|
60
|
-
// inputs.lpCoinTypes.some(
|
|
61
|
-
// (lpCoinType) => !Pools.isPossibleLpCoinType({ lpCoinType })
|
|
62
|
-
// )
|
|
63
|
-
// )
|
|
64
|
-
// throw new Error("invalid lp coin type");
|
|
65
|
-
return this.fetchApi("pool-object-ids", inputs);
|
|
66
|
-
});
|
|
67
74
|
/**
|
|
68
|
-
* Checks if
|
|
69
|
-
*
|
|
70
|
-
*
|
|
75
|
+
* Checks if a given coin type is recognized as an LP coin.
|
|
76
|
+
* Internally calls `getPoolObjectIdForLpCoinType`.
|
|
77
|
+
*
|
|
78
|
+
* @param inputs - Contains the `lpCoinType` to check.
|
|
79
|
+
* @returns `true` if the coin is an LP token, `false` otherwise.
|
|
71
80
|
*/
|
|
72
81
|
this.isLpCoinType = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
73
82
|
try {
|
|
@@ -79,8 +88,15 @@ class Pools extends caller_1.Caller {
|
|
|
79
88
|
}
|
|
80
89
|
});
|
|
81
90
|
/**
|
|
82
|
-
* Retrieves the total volume in the last 24 hours.
|
|
83
|
-
*
|
|
91
|
+
* Retrieves the total volume across all pools in the last 24 hours.
|
|
92
|
+
*
|
|
93
|
+
* @returns A promise resolving to a numeric volume (e.g., in USD).
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const totalVol24 = await pools.getTotalVolume24hrs();
|
|
98
|
+
* console.log("Protocol-wide 24h volume:", totalVol24);
|
|
99
|
+
* ```
|
|
84
100
|
*/
|
|
85
101
|
this.getTotalVolume24hrs = () => __awaiter(this, void 0, void 0, function* () {
|
|
86
102
|
return this.fetchApi("volume-24hrs");
|
|
@@ -88,6 +104,10 @@ class Pools extends caller_1.Caller {
|
|
|
88
104
|
// =========================================================================
|
|
89
105
|
// Private Helpers
|
|
90
106
|
// =========================================================================
|
|
107
|
+
/**
|
|
108
|
+
* Provides a typed reference to the `Pools` part of the `AftermathApi`,
|
|
109
|
+
* throwing an error if not defined.
|
|
110
|
+
*/
|
|
91
111
|
this.useProvider = () => {
|
|
92
112
|
var _b;
|
|
93
113
|
const provider = (_b = this.Provider) === null || _b === void 0 ? void 0 : _b.Pools();
|
|
@@ -103,10 +123,16 @@ class Pools extends caller_1.Caller {
|
|
|
103
123
|
// Pool Class
|
|
104
124
|
// =========================================================================
|
|
105
125
|
/**
|
|
106
|
-
*
|
|
126
|
+
* Fetches a single pool by its on-chain `objectId` and returns a new `Pool` instance.
|
|
127
|
+
*
|
|
128
|
+
* @param inputs - An object containing `objectId`.
|
|
129
|
+
* @returns A promise that resolves to a `Pool` instance.
|
|
107
130
|
*
|
|
108
|
-
* @
|
|
109
|
-
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* const pool = await pools.getPool({ objectId: "0x<poolId>" });
|
|
134
|
+
* console.log(pool.pool.lpCoinType, pool.pool.name);
|
|
135
|
+
* ```
|
|
110
136
|
*/
|
|
111
137
|
getPool(inputs) {
|
|
112
138
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -115,10 +141,16 @@ class Pools extends caller_1.Caller {
|
|
|
115
141
|
});
|
|
116
142
|
}
|
|
117
143
|
/**
|
|
118
|
-
*
|
|
144
|
+
* Fetches multiple pools by their on-chain `objectIds` and returns an array of `Pool` instances.
|
|
119
145
|
*
|
|
120
|
-
* @param
|
|
121
|
-
* @returns
|
|
146
|
+
* @param inputs - An object containing an array of `objectIds`.
|
|
147
|
+
* @returns A promise that resolves to an array of `Pool` instances.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```typescript
|
|
151
|
+
* const poolArray = await pools.getPools({ objectIds: ["0x<id1>", "0x<id2>"] });
|
|
152
|
+
* console.log(poolArray.length);
|
|
153
|
+
* ```
|
|
122
154
|
*/
|
|
123
155
|
getPools(inputs) {
|
|
124
156
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -129,8 +161,15 @@ class Pools extends caller_1.Caller {
|
|
|
129
161
|
});
|
|
130
162
|
}
|
|
131
163
|
/**
|
|
132
|
-
* Retrieves all pools
|
|
133
|
-
*
|
|
164
|
+
* Retrieves all pools recognized by the Aftermath API, returning an array of `Pool` objects.
|
|
165
|
+
*
|
|
166
|
+
* @returns An array of `Pool` instances.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* const allPools = await pools.getAllPools();
|
|
171
|
+
* console.log(allPools.map(p => p.pool.name));
|
|
172
|
+
* ```
|
|
134
173
|
*/
|
|
135
174
|
getAllPools() {
|
|
136
175
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -138,6 +177,19 @@ class Pools extends caller_1.Caller {
|
|
|
138
177
|
return pools.map((pool) => new pool_1.Pool(pool, this.config, this.Provider));
|
|
139
178
|
});
|
|
140
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
* Fetches information about all owned LP coins for a given wallet address.
|
|
182
|
+
* This indicates the user's liquidity positions across multiple pools.
|
|
183
|
+
*
|
|
184
|
+
* @param inputs - An object containing the `walletAddress`.
|
|
185
|
+
* @returns A `PoolLpInfo` object summarizing the user's LP balances.
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* const lpCoins = await pools.getOwnedLpCoins({ walletAddress: "0x<address>" });
|
|
190
|
+
* console.log(lpCoins);
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
141
193
|
getOwnedLpCoins(inputs) {
|
|
142
194
|
return __awaiter(this, void 0, void 0, function* () {
|
|
143
195
|
return this.fetchApi("owned-lp-coins", inputs);
|
|
@@ -147,9 +199,19 @@ class Pools extends caller_1.Caller {
|
|
|
147
199
|
// Transactions
|
|
148
200
|
// =========================================================================
|
|
149
201
|
/**
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
202
|
+
* Constructs or fetches a transaction to publish a new LP coin package,
|
|
203
|
+
* typically used by advanced users or devs establishing new liquidity pools.
|
|
204
|
+
*
|
|
205
|
+
* @param inputs - Includes the user `walletAddress` and the `lpCoinDecimals`.
|
|
206
|
+
* @returns A transaction object (or data) that can be signed and published to Sui.
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```typescript
|
|
210
|
+
* const publishTx = await pools.getPublishLpCoinTransaction({
|
|
211
|
+
* walletAddress: "0x<address>",
|
|
212
|
+
* lpCoinDecimals: 9
|
|
213
|
+
* });
|
|
214
|
+
* ```
|
|
153
215
|
*/
|
|
154
216
|
getPublishLpCoinTransaction(inputs) {
|
|
155
217
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -157,30 +219,112 @@ class Pools extends caller_1.Caller {
|
|
|
157
219
|
});
|
|
158
220
|
}
|
|
159
221
|
/**
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
222
|
+
* Constructs a transaction to create a brand new pool on-chain, given coin types,
|
|
223
|
+
* initial weights, fees, and possible DAO fee info.
|
|
224
|
+
*
|
|
225
|
+
* @param inputs - The body describing how to form the new pool.
|
|
226
|
+
* @returns A transaction object that can be signed and executed.
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```typescript
|
|
230
|
+
* const createPoolTx = await pools.getCreatePoolTransaction({
|
|
231
|
+
* walletAddress: "0x<address>",
|
|
232
|
+
* lpCoinType: "0x<lpCoin>",
|
|
233
|
+
* lpCoinMetadata: {
|
|
234
|
+
* name: "MyPool LP",
|
|
235
|
+
* symbol: "MYPLP"
|
|
236
|
+
* },
|
|
237
|
+
* coinsInfo: [
|
|
238
|
+
* {
|
|
239
|
+
* coinType: "0x<coinA>",
|
|
240
|
+
* weight: 0.5,
|
|
241
|
+
* decimals: 9,
|
|
242
|
+
* tradeFeeIn: 0.003,
|
|
243
|
+
* initialDeposit: 1_000_000_000n
|
|
244
|
+
* },
|
|
245
|
+
* // ...
|
|
246
|
+
* ],
|
|
247
|
+
* poolName: "My Weighted Pool",
|
|
248
|
+
* createPoolCapId: "0x<capId>",
|
|
249
|
+
* respectDecimals: true,
|
|
250
|
+
* });
|
|
251
|
+
* ```
|
|
163
252
|
*/
|
|
164
253
|
getCreatePoolTransaction(inputs) {
|
|
165
254
|
return __awaiter(this, void 0, void 0, function* () {
|
|
166
255
|
return this.fetchApiTransaction("transactions/create-pool", inputs);
|
|
167
256
|
});
|
|
168
257
|
}
|
|
258
|
+
/**
|
|
259
|
+
* Retrieves multiple pool object IDs given an array of LP coin types.
|
|
260
|
+
* If a given LP coin type has no associated pool, it might return `undefined`.
|
|
261
|
+
*
|
|
262
|
+
* @param inputs - Contains an array of `lpCoinTypes`.
|
|
263
|
+
* @returns An array of `ObjectId | undefined` of matching length.
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* ```typescript
|
|
267
|
+
* const poolIds = await pools.getPoolObjectIdsForLpCoinTypes({
|
|
268
|
+
* lpCoinTypes: ["0x<lpCoinA>", "0x<lpCoinB>"]
|
|
269
|
+
* });
|
|
270
|
+
* console.log(poolIds);
|
|
271
|
+
* ```
|
|
272
|
+
*/
|
|
273
|
+
getPoolObjectIdsForLpCoinTypes(inputs) {
|
|
274
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
275
|
+
return this.fetchApi("pool-object-ids", inputs);
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Retrieves the total value locked (TVL) across all or specific pool IDs.
|
|
280
|
+
*
|
|
281
|
+
* @param inputs - Optionally provide an array of specific `poolIds`. If omitted, returns global TVL.
|
|
282
|
+
* @returns A promise resolving to a numeric TVL (e.g., in USD).
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* ```typescript
|
|
286
|
+
* const allTvl = await pools.getTVL();
|
|
287
|
+
* const subsetTvl = await pools.getTVL({ poolIds: ["0x<id1>", "0x<id2>"] });
|
|
288
|
+
* ```
|
|
289
|
+
*/
|
|
169
290
|
getTVL(inputs) {
|
|
170
291
|
return __awaiter(this, void 0, void 0, function* () {
|
|
171
292
|
return this.fetchApi("tvl", inputs !== null && inputs !== void 0 ? inputs : {});
|
|
172
293
|
});
|
|
173
294
|
}
|
|
174
295
|
/**
|
|
175
|
-
* Fetches
|
|
176
|
-
*
|
|
177
|
-
*
|
|
296
|
+
* Fetches an array of `PoolStats` objects for a given set of pools,
|
|
297
|
+
* including volume, fees, TVL, and other metrics.
|
|
298
|
+
*
|
|
299
|
+
* @param inputs - Must include an array of `poolIds`.
|
|
300
|
+
* @returns An array of `PoolStats` in matching order.
|
|
301
|
+
*
|
|
302
|
+
* @example
|
|
303
|
+
* ```typescript
|
|
304
|
+
* const stats = await pools.getPoolsStats({ poolIds: ["0x<id1>", "0x<id2>"] });
|
|
305
|
+
* console.log(stats[0].volume, stats[1].tvl);
|
|
306
|
+
* ```
|
|
178
307
|
*/
|
|
179
308
|
getPoolsStats(inputs) {
|
|
180
309
|
return __awaiter(this, void 0, void 0, function* () {
|
|
181
310
|
return this.fetchApi("stats", inputs);
|
|
182
311
|
});
|
|
183
312
|
}
|
|
313
|
+
/**
|
|
314
|
+
* Returns all DAO fee pool owner capabilities owned by a particular user.
|
|
315
|
+
* This is used to see which pools' DAO fees the user can update.
|
|
316
|
+
*
|
|
317
|
+
* @param inputs - An object with user `walletAddress`.
|
|
318
|
+
* @returns Data about each `DaoFeePoolOwnerCapObject` the user owns.
|
|
319
|
+
*
|
|
320
|
+
* @example
|
|
321
|
+
* ```typescript
|
|
322
|
+
* const daoCaps = await pools.getOwnedDaoFeePoolOwnerCaps({
|
|
323
|
+
* walletAddress: "0x<address>"
|
|
324
|
+
* });
|
|
325
|
+
* console.log(daoCaps);
|
|
326
|
+
* ```
|
|
327
|
+
*/
|
|
184
328
|
getOwnedDaoFeePoolOwnerCaps(inputs) {
|
|
185
329
|
return __awaiter(this, void 0, void 0, function* () {
|
|
186
330
|
return this.useProvider().fetchOwnedDaoFeePoolOwnerCaps(inputs);
|
|
@@ -189,6 +333,22 @@ class Pools extends caller_1.Caller {
|
|
|
189
333
|
// =========================================================================
|
|
190
334
|
// Events
|
|
191
335
|
// =========================================================================
|
|
336
|
+
/**
|
|
337
|
+
* Fetches user-specific interaction events (deposits, withdrawals) across pools,
|
|
338
|
+
* optionally with pagination.
|
|
339
|
+
*
|
|
340
|
+
* @param inputs - An object containing `walletAddress`, plus optional pagination (`cursor`, `limit`).
|
|
341
|
+
* @returns An event set with a cursor for further queries if available.
|
|
342
|
+
*
|
|
343
|
+
* @example
|
|
344
|
+
* ```typescript
|
|
345
|
+
* const userEvents = await pools.getInteractionEvents({
|
|
346
|
+
* walletAddress: "0x...",
|
|
347
|
+
* limit: 10,
|
|
348
|
+
* });
|
|
349
|
+
* console.log(userEvents.events, userEvents.nextCursor);
|
|
350
|
+
* ```
|
|
351
|
+
*/
|
|
192
352
|
getInteractionEvents(inputs) {
|
|
193
353
|
return __awaiter(this, void 0, void 0, function* () {
|
|
194
354
|
return this.fetchApiIndexerEvents("interaction-events-by-user", inputs);
|
|
@@ -201,40 +361,105 @@ _a = Pools;
|
|
|
201
361
|
// Constants
|
|
202
362
|
// =========================================================================
|
|
203
363
|
/**
|
|
204
|
-
*
|
|
364
|
+
* Static constants relevant to the pool logic, such as protocol fees,
|
|
365
|
+
* referral percentages, and bounds for trading/withdrawal percentages.
|
|
205
366
|
*/
|
|
206
367
|
Pools.constants = {
|
|
207
|
-
|
|
368
|
+
/**
|
|
369
|
+
* Protocol fee structure: `totalProtocol` is the fraction of trades
|
|
370
|
+
* that is taken as a fee, which is split among `treasury`, `insuranceFund`,
|
|
371
|
+
* and `devWallet` in the given proportions.
|
|
372
|
+
*/
|
|
208
373
|
feePercentages: {
|
|
374
|
+
/**
|
|
375
|
+
* The total fraction (as a decimal) of trades charged by the protocol.
|
|
376
|
+
* e.g., 0.00005 => 0.005%.
|
|
377
|
+
*/
|
|
209
378
|
totalProtocol: 0.00005,
|
|
210
|
-
|
|
379
|
+
/**
|
|
380
|
+
* The fraction of `totalProtocol` allocated to the treasury.
|
|
381
|
+
*/
|
|
211
382
|
treasury: 0.5,
|
|
383
|
+
/**
|
|
384
|
+
* The fraction of `totalProtocol` allocated to the insurance fund.
|
|
385
|
+
*/
|
|
212
386
|
insuranceFund: 0.3,
|
|
213
|
-
|
|
387
|
+
/**
|
|
388
|
+
* The fraction of `totalProtocol` allocated to the dev wallet.
|
|
389
|
+
*/
|
|
390
|
+
devWallet: 0.2,
|
|
214
391
|
},
|
|
392
|
+
/**
|
|
393
|
+
* Referral fee structures, applying a discount/rebate to the user and
|
|
394
|
+
* referrer, taken from the treasury portion of protocol fees.
|
|
395
|
+
*/
|
|
215
396
|
referralPercentages: {
|
|
216
|
-
|
|
397
|
+
/**
|
|
398
|
+
* The fraction of the treasury portion that discounts the user's fee.
|
|
399
|
+
*/
|
|
217
400
|
discount: 0.05,
|
|
218
|
-
|
|
401
|
+
/**
|
|
402
|
+
* The fraction of the treasury portion that acts as a rebate to the referrer.
|
|
403
|
+
*/
|
|
404
|
+
rebate: 0.05,
|
|
219
405
|
},
|
|
406
|
+
/**
|
|
407
|
+
* Various bounds used to prevent extreme trades or invalid pool configurations.
|
|
408
|
+
*/
|
|
220
409
|
bounds: {
|
|
410
|
+
/**
|
|
411
|
+
* Maximum number of distinct coins allowed in a single pool.
|
|
412
|
+
*/
|
|
221
413
|
maxCoinsInPool: 8,
|
|
414
|
+
/**
|
|
415
|
+
* Maximum fraction (decimal) of a pool's balance that can be traded at once.
|
|
416
|
+
*/
|
|
222
417
|
maxTradePercentageOfPoolBalance: 0.3,
|
|
418
|
+
/**
|
|
419
|
+
* Maximum fraction (decimal) of a pool's balance that can be withdrawn at once.
|
|
420
|
+
*/
|
|
223
421
|
maxWithdrawPercentageOfPoolBalance: 0.3,
|
|
422
|
+
/**
|
|
423
|
+
* Minimum and maximum swap fees (0.01% to 10%).
|
|
424
|
+
*/
|
|
224
425
|
minSwapFee: 0.0001,
|
|
225
426
|
maxSwapFee: 0.1,
|
|
427
|
+
/**
|
|
428
|
+
* Minimum and maximum coin weight for weighted pools (1% to 99%).
|
|
429
|
+
*/
|
|
226
430
|
minWeight: 0.01,
|
|
227
431
|
maxWeight: 0.99,
|
|
432
|
+
/**
|
|
433
|
+
* Minimum and maximum DAO fee (0% to 100%).
|
|
434
|
+
*/
|
|
228
435
|
minDaoFee: 0,
|
|
229
|
-
maxDaoFee: 1,
|
|
436
|
+
maxDaoFee: 1,
|
|
230
437
|
},
|
|
438
|
+
/**
|
|
439
|
+
* Default parameter(s) used in the absence of explicit user or code settings.
|
|
440
|
+
*/
|
|
231
441
|
defaults: {
|
|
442
|
+
/**
|
|
443
|
+
* Default decimals for LP coins if none are specified.
|
|
444
|
+
*/
|
|
232
445
|
lpCoinDecimals: 9,
|
|
233
446
|
},
|
|
234
447
|
};
|
|
235
448
|
// =========================================================================
|
|
236
449
|
// Fees
|
|
237
450
|
// =========================================================================
|
|
451
|
+
/**
|
|
452
|
+
* Returns how much coin remains **after** applying the protocol fees
|
|
453
|
+
* (and referral discount if `withReferral` is `true`).
|
|
454
|
+
*
|
|
455
|
+
* @param inputs - The original `amount` and an optional referral flag.
|
|
456
|
+
* @returns The post-fee (net) amount as a bigint.
|
|
457
|
+
*
|
|
458
|
+
* @example
|
|
459
|
+
* ```typescript
|
|
460
|
+
* const netAmount = Pools.getAmountWithProtocolFees({ amount: 1_000_000n });
|
|
461
|
+
* ```
|
|
462
|
+
*/
|
|
238
463
|
Pools.getAmountWithProtocolFees = (inputs) => {
|
|
239
464
|
const referralDiscount = inputs.withReferral
|
|
240
465
|
? _a.constants.feePercentages.totalProtocol *
|
|
@@ -246,6 +471,14 @@ Pools.getAmountWithProtocolFees = (inputs) => {
|
|
|
246
471
|
(_a.constants.feePercentages.totalProtocol -
|
|
247
472
|
referralDiscount))));
|
|
248
473
|
};
|
|
474
|
+
/**
|
|
475
|
+
* The inverse calculation: given a net amount (post-fees), figure out
|
|
476
|
+
* the original gross amount. Used when we already have fees subtracted
|
|
477
|
+
* but need to restore an original quantity.
|
|
478
|
+
*
|
|
479
|
+
* @param inputs - The net `amount` after fees, plus an optional referral flag.
|
|
480
|
+
* @returns The original gross amount as a bigint.
|
|
481
|
+
*/
|
|
249
482
|
Pools.getAmountWithoutProtocolFees = (inputs) => {
|
|
250
483
|
const referralDiscount = inputs.withReferral
|
|
251
484
|
? _a.constants.feePercentages.totalProtocol *
|
|
@@ -258,10 +491,24 @@ Pools.getAmountWithoutProtocolFees = (inputs) => {
|
|
|
258
491
|
(_a.constants.feePercentages.totalProtocol -
|
|
259
492
|
referralDiscount)))));
|
|
260
493
|
};
|
|
494
|
+
/**
|
|
495
|
+
* A helper to transform a user-provided slippage fraction, e.g. 0.01,
|
|
496
|
+
* into a 1 - slippage format, if needed for certain math operations.
|
|
497
|
+
*
|
|
498
|
+
* @param slippage - The decimal fraction of slippage tolerance, e.g. 0.01 => 1%.
|
|
499
|
+
* @returns A big integer representing `1 - slippage` in a fixed context.
|
|
500
|
+
*/
|
|
261
501
|
Pools.normalizeInvertSlippage = (slippage) => fixedUtils_1.FixedUtils.directUncast(1 - slippage);
|
|
262
502
|
// =========================================================================
|
|
263
503
|
// Display
|
|
264
504
|
// =========================================================================
|
|
505
|
+
/**
|
|
506
|
+
* Produces a user-friendly string for an LP coin type, e.g. "Sui Coin LP"
|
|
507
|
+
* by analyzing the coin type symbol. Typically used in UIs or logs.
|
|
508
|
+
*
|
|
509
|
+
* @param lpCoinType - The coin type for the LP token.
|
|
510
|
+
* @returns A string representation for display, e.g. "Af_lp_abc" => "Abc LP".
|
|
511
|
+
*/
|
|
265
512
|
Pools.displayLpCoinType = (lpCoinType) => coin_1.Coin.getCoinTypeSymbol(lpCoinType)
|
|
266
513
|
.toLowerCase()
|
|
267
514
|
.replace("af_lp_", "")
|
|
@@ -271,6 +518,13 @@ Pools.displayLpCoinType = (lpCoinType) => coin_1.Coin.getCoinTypeSymbol(lpCoinTy
|
|
|
271
518
|
// =========================================================================
|
|
272
519
|
// Helpers
|
|
273
520
|
// =========================================================================
|
|
521
|
+
/**
|
|
522
|
+
* A quick heuristic check to see if the given `lpCoinType` string
|
|
523
|
+
* might represent an Aftermath LP token. This is not a full on-chain validation.
|
|
524
|
+
*
|
|
525
|
+
* @param inputs - An object containing `lpCoinType`.
|
|
526
|
+
* @returns `true` if it matches a known pattern; otherwise `false`.
|
|
527
|
+
*/
|
|
274
528
|
Pools.isPossibleLpCoinType = (inputs) => {
|
|
275
529
|
const { lpCoinType } = inputs;
|
|
276
530
|
return (lpCoinType.split("::").length === 3 &&
|