aftermath-ts-sdk 1.2.63 → 1.2.64-docs.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +267 -2
- 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
|
@@ -13,15 +13,39 @@ exports.Staking = void 0;
|
|
|
13
13
|
const caller_1 = require("../../general/utils/caller");
|
|
14
14
|
const utils_1 = require("../../general/utils");
|
|
15
15
|
/**
|
|
16
|
-
* The Staking class provides
|
|
16
|
+
* The `Staking` class provides methods for interacting with Aftermath's
|
|
17
|
+
* staking and unstaking systems for SUI. This includes fetching validator
|
|
18
|
+
* information, creating stake and unstake transactions, and retrieving
|
|
19
|
+
* relevant staking statistics such as TVL and APY.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* // Instantiate Staking
|
|
24
|
+
* const sdk = new Aftermath("MAINNET");
|
|
25
|
+
* await sdk.init();
|
|
26
|
+
* const staking = sdk.Staking();
|
|
27
|
+
*
|
|
28
|
+
* // Get active validators
|
|
29
|
+
* const validators = await staking.getActiveValidators();
|
|
30
|
+
*
|
|
31
|
+
* // Create a transaction for staking SUI
|
|
32
|
+
* const stakeTx = await staking.getStakeTransaction({
|
|
33
|
+
* walletAddress: "0x...",
|
|
34
|
+
* suiStakeAmount: BigInt("1000000000"),
|
|
35
|
+
* validatorAddress: "0x..."
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
17
38
|
*/
|
|
18
39
|
class Staking extends caller_1.Caller {
|
|
19
40
|
// =========================================================================
|
|
20
41
|
// Constructor
|
|
21
42
|
// =========================================================================
|
|
22
43
|
/**
|
|
23
|
-
* Creates a new instance of the Staking class
|
|
24
|
-
*
|
|
44
|
+
* Creates a new instance of the `Staking` class for interacting with Aftermath
|
|
45
|
+
* staking contracts.
|
|
46
|
+
*
|
|
47
|
+
* @param config - Optional configuration containing the Sui network and/or access token.
|
|
48
|
+
* @param Provider - Optional instance of `AftermathApi` for building transactions.
|
|
25
49
|
*/
|
|
26
50
|
constructor(config, Provider) {
|
|
27
51
|
super(config, "staking");
|
|
@@ -29,6 +53,13 @@ class Staking extends caller_1.Caller {
|
|
|
29
53
|
// =========================================================================
|
|
30
54
|
// Private Helpers
|
|
31
55
|
// =========================================================================
|
|
56
|
+
/**
|
|
57
|
+
* Returns a provider instance for building transactions. Throws an error
|
|
58
|
+
* if `Provider` is not defined.
|
|
59
|
+
*
|
|
60
|
+
* @returns An instance of `AftermathApi.Staking`.
|
|
61
|
+
* @throws Will throw if the `Provider` is undefined.
|
|
62
|
+
*/
|
|
32
63
|
this.useProvider = () => {
|
|
33
64
|
var _a;
|
|
34
65
|
const provider = (_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Staking();
|
|
@@ -41,8 +72,16 @@ class Staking extends caller_1.Caller {
|
|
|
41
72
|
// Objects
|
|
42
73
|
// =========================================================================
|
|
43
74
|
/**
|
|
44
|
-
* Fetches the list of active validators.
|
|
45
|
-
*
|
|
75
|
+
* Fetches the list of currently active validators on the Sui network.
|
|
76
|
+
*
|
|
77
|
+
* @returns A promise that resolves to an array of `SuiValidatorSummary` objects,
|
|
78
|
+
* each describing a validator's on-chain metadata.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* const validators = await staking.getActiveValidators();
|
|
83
|
+
* console.log(validators);
|
|
84
|
+
* ```
|
|
46
85
|
*/
|
|
47
86
|
getActiveValidators() {
|
|
48
87
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -50,8 +89,16 @@ class Staking extends caller_1.Caller {
|
|
|
50
89
|
});
|
|
51
90
|
}
|
|
52
91
|
/**
|
|
53
|
-
* Fetches the APYs for all validators.
|
|
54
|
-
*
|
|
92
|
+
* Fetches the current APYs for all validators, aggregated by the indexer.
|
|
93
|
+
*
|
|
94
|
+
* @returns A promise that resolves to a `ValidatorsApy` object, containing
|
|
95
|
+
* APY data indexed by validator addresses.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* const validatorApys = await staking.getValidatorApys();
|
|
100
|
+
* console.log(validatorApys);
|
|
101
|
+
* ```
|
|
55
102
|
*/
|
|
56
103
|
getValidatorApys() {
|
|
57
104
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -59,8 +106,16 @@ class Staking extends caller_1.Caller {
|
|
|
59
106
|
});
|
|
60
107
|
}
|
|
61
108
|
/**
|
|
62
|
-
* Fetches the configuration for
|
|
63
|
-
*
|
|
109
|
+
* Fetches the configuration details for each validator, including fees and
|
|
110
|
+
* operation caps.
|
|
111
|
+
*
|
|
112
|
+
* @returns A promise that resolves to an array of `ValidatorConfigObject`s.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* const configs = await staking.getValidatorConfigs();
|
|
117
|
+
* console.log(configs);
|
|
118
|
+
* ```
|
|
64
119
|
*/
|
|
65
120
|
getValidatorConfigs() {
|
|
66
121
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -68,9 +123,22 @@ class Staking extends caller_1.Caller {
|
|
|
68
123
|
});
|
|
69
124
|
}
|
|
70
125
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* @
|
|
126
|
+
* Retrieves a list of staking positions for the specified account.
|
|
127
|
+
*
|
|
128
|
+
* @param inputs - Contains the `walletAddress` to query, plus optional cursor
|
|
129
|
+
* and limit for pagination.
|
|
130
|
+
* @returns A promise that resolves to an array of `StakingPosition` objects
|
|
131
|
+
* reflecting the user's active or pending stakes.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* const positions = await staking.getStakingPositions({
|
|
136
|
+
* walletAddress: "0x...",
|
|
137
|
+
* cursor: 0,
|
|
138
|
+
* limit: 10
|
|
139
|
+
* });
|
|
140
|
+
* console.log(positions);
|
|
141
|
+
* ```
|
|
74
142
|
*/
|
|
75
143
|
getStakingPositions(inputs) {
|
|
76
144
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -78,9 +146,19 @@ class Staking extends caller_1.Caller {
|
|
|
78
146
|
});
|
|
79
147
|
}
|
|
80
148
|
/**
|
|
81
|
-
* Fetches
|
|
82
|
-
*
|
|
83
|
-
*
|
|
149
|
+
* Fetches all delegated stakes for a specific wallet address. Delegated
|
|
150
|
+
* stakes typically represent user funds staked to one or more validators.
|
|
151
|
+
*
|
|
152
|
+
* @param inputs - Contains the `walletAddress` for which to fetch delegated stakes.
|
|
153
|
+
* @returns A promise resolving to an array of `SuiDelegatedStake` objects.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* const delegatedStakes = await staking.getDelegatedStakes({
|
|
158
|
+
* walletAddress: "0x..."
|
|
159
|
+
* });
|
|
160
|
+
* console.log(delegatedStakes);
|
|
161
|
+
* ```
|
|
84
162
|
*/
|
|
85
163
|
getDelegatedStakes(inputs) {
|
|
86
164
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -88,9 +166,22 @@ class Staking extends caller_1.Caller {
|
|
|
88
166
|
});
|
|
89
167
|
}
|
|
90
168
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
169
|
+
* Retrieves validator operation caps for a specified address. Operation caps
|
|
170
|
+
* typically govern who is authorized to adjust validator fees and settings.
|
|
171
|
+
*
|
|
172
|
+
* @param inputs - Contains the `walletAddress` for which to fetch validator
|
|
173
|
+
* operation caps, plus optional pagination.
|
|
174
|
+
* @returns A promise resolving to an array of `ValidatorOperationCapObject`s.
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```typescript
|
|
178
|
+
* const caps = await staking.getValidatorOperationCaps({
|
|
179
|
+
* walletAddress: "0x...",
|
|
180
|
+
* cursor: 0,
|
|
181
|
+
* limit: 5
|
|
182
|
+
* });
|
|
183
|
+
* console.log(caps);
|
|
184
|
+
* ```
|
|
94
185
|
*/
|
|
95
186
|
getValidatorOperationCaps(inputs) {
|
|
96
187
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -101,9 +192,23 @@ class Staking extends caller_1.Caller {
|
|
|
101
192
|
// Transactions
|
|
102
193
|
// =========================================================================
|
|
103
194
|
/**
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
195
|
+
* Builds or fetches a staking transaction object, which can then be signed
|
|
196
|
+
* and submitted to the network.
|
|
197
|
+
*
|
|
198
|
+
* @param inputs - Includes the `walletAddress`, the amount of SUI to stake, and
|
|
199
|
+
* the validator address to stake with. Optionally includes a `referrer`, `externalFee`,
|
|
200
|
+
* and a sponsored transaction flag.
|
|
201
|
+
* @returns A promise resolving to a transaction that can be signed and executed.
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```typescript
|
|
205
|
+
* const stakeTx = await staking.getStakeTransaction({
|
|
206
|
+
* walletAddress: "0x...",
|
|
207
|
+
* suiStakeAmount: BigInt("1000000000"), // 1 SUI
|
|
208
|
+
* validatorAddress: "0x..."
|
|
209
|
+
* });
|
|
210
|
+
* // sign and execute this transaction using your preferred Sui wallet
|
|
211
|
+
* ```
|
|
107
212
|
*/
|
|
108
213
|
getStakeTransaction(inputs) {
|
|
109
214
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -111,9 +216,24 @@ class Staking extends caller_1.Caller {
|
|
|
111
216
|
});
|
|
112
217
|
}
|
|
113
218
|
/**
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
219
|
+
* Builds or fetches an unstaking transaction object, allowing a user to
|
|
220
|
+
* convert their afSUI back into SUI (either atomically or via partial
|
|
221
|
+
* liquidity).
|
|
222
|
+
*
|
|
223
|
+
* @param inputs - Contains the `walletAddress`, the afSUI amount to unstake,
|
|
224
|
+
* and whether it's an atomic operation. Optionally includes a `referrer`,
|
|
225
|
+
* `externalFee`, and a sponsored transaction flag.
|
|
226
|
+
* @returns A promise resolving to a transaction that can be signed and executed.
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```typescript
|
|
230
|
+
* const unstakeTx = await staking.getUnstakeTransaction({
|
|
231
|
+
* walletAddress: "0x...",
|
|
232
|
+
* afSuiUnstakeAmount: BigInt("1000000000"), // 1 afSUI
|
|
233
|
+
* isAtomic: true
|
|
234
|
+
* });
|
|
235
|
+
* // sign and execute this transaction to receive SUI
|
|
236
|
+
* ```
|
|
117
237
|
*/
|
|
118
238
|
getUnstakeTransaction(inputs) {
|
|
119
239
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -121,9 +241,25 @@ class Staking extends caller_1.Caller {
|
|
|
121
241
|
});
|
|
122
242
|
}
|
|
123
243
|
/**
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
244
|
+
* Builds or fetches a transaction to stake an existing stakedSUI object
|
|
245
|
+
* (e.g., re-staking funds that were already staked under a different
|
|
246
|
+
* validator).
|
|
247
|
+
*
|
|
248
|
+
* @param inputs - Contains the `walletAddress`, an array of `stakedSuiIds`
|
|
249
|
+
* to be re-staked, and the new `validatorAddress`. Optionally includes
|
|
250
|
+
* a `referrer` and a sponsored transaction flag.
|
|
251
|
+
* @returns A promise resolving to a transaction object that can be signed
|
|
252
|
+
* and executed.
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```typescript
|
|
256
|
+
* const stakeStakedTx = await staking.getStakeStakedSuiTransaction({
|
|
257
|
+
* walletAddress: "0x...",
|
|
258
|
+
* stakedSuiIds: ["0x<stakedSuiId1>", "0x<stakedSuiId2>"],
|
|
259
|
+
* validatorAddress: "0x..."
|
|
260
|
+
* });
|
|
261
|
+
* // sign and execute this transaction
|
|
262
|
+
* ```
|
|
127
263
|
*/
|
|
128
264
|
getStakeStakedSuiTransaction(inputs) {
|
|
129
265
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -131,13 +267,45 @@ class Staking extends caller_1.Caller {
|
|
|
131
267
|
});
|
|
132
268
|
}
|
|
133
269
|
/**
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
270
|
+
* Builds or fetches a transaction to update the validator fee for a
|
|
271
|
+
* validator in which the user has operation cap privileges.
|
|
272
|
+
*
|
|
273
|
+
* @param inputs - Contains the `walletAddress`, `validatorOperationCapId`,
|
|
274
|
+
* and `newFeePercentage`. Optionally includes a sponsored transaction flag.
|
|
275
|
+
* @returns A transaction object that can be signed and executed to
|
|
276
|
+
* update the validator's fee on-chain.
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* ```typescript
|
|
280
|
+
* const updateFeeTx = await staking.getUpdateValidatorFeeTransaction({
|
|
281
|
+
* walletAddress: "0x...",
|
|
282
|
+
* validatorOperationCapId: "0x...",
|
|
283
|
+
* newFeePercentage: 0.01,
|
|
284
|
+
* isSponsoredTx: false
|
|
285
|
+
* });
|
|
286
|
+
* // sign and execute to update the validator fee
|
|
287
|
+
* ```
|
|
137
288
|
*/
|
|
138
289
|
getUpdateValidatorFeeTransaction(inputs) {
|
|
139
290
|
return this.useProvider().buildUpdateValidatorFeeTx(inputs);
|
|
140
291
|
}
|
|
292
|
+
/**
|
|
293
|
+
* Builds a "crank" transaction to update the epoch for afSUI. This can
|
|
294
|
+
* trigger certain internal processes within the Aftermath protocol,
|
|
295
|
+
* such as distributing rewards or rebalancing.
|
|
296
|
+
*
|
|
297
|
+
* @param inputs - Contains the `walletAddress` to sign the transaction.
|
|
298
|
+
* @returns A transaction object that can be signed and submitted to
|
|
299
|
+
* trigger an epoch update.
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* ```typescript
|
|
303
|
+
* const crankTx = await staking.getCrankAfSuiTransaction({
|
|
304
|
+
* walletAddress: "0x..."
|
|
305
|
+
* });
|
|
306
|
+
* // sign and execute transaction
|
|
307
|
+
* ```
|
|
308
|
+
*/
|
|
141
309
|
getCrankAfSuiTransaction(inputs) {
|
|
142
310
|
return this.useProvider().buildEpochWasChangedTx(inputs);
|
|
143
311
|
}
|
|
@@ -145,8 +313,17 @@ class Staking extends caller_1.Caller {
|
|
|
145
313
|
// Inspections
|
|
146
314
|
// =========================================================================
|
|
147
315
|
/**
|
|
148
|
-
*
|
|
149
|
-
*
|
|
316
|
+
* Retrieves the total value locked (TVL) in SUI across the Aftermath
|
|
317
|
+
* staking systems.
|
|
318
|
+
*
|
|
319
|
+
* @returns A promise that resolves to a `Balance` representing the total
|
|
320
|
+
* staked SUI in the protocol.
|
|
321
|
+
*
|
|
322
|
+
* @example
|
|
323
|
+
* ```typescript
|
|
324
|
+
* const tvl = await staking.getSuiTvl();
|
|
325
|
+
* console.log("Total value locked in SUI:", tvl);
|
|
326
|
+
* ```
|
|
150
327
|
*/
|
|
151
328
|
getSuiTvl() {
|
|
152
329
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -154,8 +331,17 @@ class Staking extends caller_1.Caller {
|
|
|
154
331
|
});
|
|
155
332
|
}
|
|
156
333
|
/**
|
|
157
|
-
*
|
|
158
|
-
*
|
|
334
|
+
* Retrieves the current exchange rate between afSUI and SUI. This rate
|
|
335
|
+
* is used to determine how much SUI a single afSUI token is worth.
|
|
336
|
+
*
|
|
337
|
+
* @returns A promise that resolves to a `number` representing the
|
|
338
|
+
* afSUI-to-SUI rate.
|
|
339
|
+
*
|
|
340
|
+
* @example
|
|
341
|
+
* ```typescript
|
|
342
|
+
* const rate = await staking.getAfSuiToSuiExchangeRate();
|
|
343
|
+
* console.log("1 afSUI =", rate, "SUI");
|
|
344
|
+
* ```
|
|
159
345
|
*/
|
|
160
346
|
getAfSuiToSuiExchangeRate() {
|
|
161
347
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -163,8 +349,18 @@ class Staking extends caller_1.Caller {
|
|
|
163
349
|
});
|
|
164
350
|
}
|
|
165
351
|
/**
|
|
166
|
-
*
|
|
167
|
-
*
|
|
352
|
+
* Retrieves the stakedSui vault state from the protocol, which holds
|
|
353
|
+
* important values for calculating fees, reserves, and total active
|
|
354
|
+
* stake.
|
|
355
|
+
*
|
|
356
|
+
* @returns A promise that resolves to a `StakedSuiVaultStateObject`,
|
|
357
|
+
* containing details like atomic unstake reserves, fees, and total SUI.
|
|
358
|
+
*
|
|
359
|
+
* @example
|
|
360
|
+
* ```typescript
|
|
361
|
+
* const vaultState = await staking.getStakedSuiVaultState();
|
|
362
|
+
* console.log("Vault State:", vaultState);
|
|
363
|
+
* ```
|
|
168
364
|
*/
|
|
169
365
|
getStakedSuiVaultState() {
|
|
170
366
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -172,14 +368,35 @@ class Staking extends caller_1.Caller {
|
|
|
172
368
|
});
|
|
173
369
|
}
|
|
174
370
|
/**
|
|
175
|
-
*
|
|
176
|
-
*
|
|
371
|
+
* Retrieves the current APY (Annual Percentage Yield) for staking SUI
|
|
372
|
+
* through Aftermath.
|
|
373
|
+
*
|
|
374
|
+
* @returns A promise that resolves to a `number` representing the APY.
|
|
375
|
+
*
|
|
376
|
+
* @example
|
|
377
|
+
* ```typescript
|
|
378
|
+
* const apy = await staking.getApy();
|
|
379
|
+
* console.log("Current staking APY:", apy);
|
|
380
|
+
* ```
|
|
177
381
|
*/
|
|
178
382
|
getApy() {
|
|
179
383
|
return __awaiter(this, void 0, void 0, function* () {
|
|
180
384
|
return this.fetchApi("apy");
|
|
181
385
|
});
|
|
182
386
|
}
|
|
387
|
+
/**
|
|
388
|
+
* Retrieves historical APY data points over a specified timeframe.
|
|
389
|
+
*
|
|
390
|
+
* @param inputs - Contains a `timeframe` key, such as `"1W"`, `"1M"`, `"1Y"`, etc.
|
|
391
|
+
* @returns A promise resolving to an array of `StakingApyDataPoint` objects,
|
|
392
|
+
* each containing a timestamp and an APY value.
|
|
393
|
+
*
|
|
394
|
+
* @example
|
|
395
|
+
* ```typescript
|
|
396
|
+
* const historicalApy = await staking.getHistoricalApy({ timeframe: "1M" });
|
|
397
|
+
* console.log(historicalApy); // e.g. [{ timestamp: 1686000000, apy: 0.045 }, ...]
|
|
398
|
+
* ```
|
|
399
|
+
*/
|
|
183
400
|
getHistoricalApy(inputs) {
|
|
184
401
|
return __awaiter(this, void 0, void 0, function* () {
|
|
185
402
|
return this.fetchApi("historical-apy", inputs);
|
|
@@ -192,9 +409,21 @@ class Staking extends caller_1.Caller {
|
|
|
192
409
|
// Calculations
|
|
193
410
|
// =========================================================================
|
|
194
411
|
/**
|
|
195
|
-
* Calculates the atomic unstake fee
|
|
196
|
-
*
|
|
197
|
-
*
|
|
412
|
+
* Calculates the atomic unstake fee based on the current vault state. If
|
|
413
|
+
* the `atomicUnstakeSuiReserves` remain above the target, the minimum fee
|
|
414
|
+
* applies; otherwise, the fee adjusts proportionally up to the maximum
|
|
415
|
+
* possible fee.
|
|
416
|
+
*
|
|
417
|
+
* @param inputs - Contains the `stakedSuiVaultState`, which holds data on
|
|
418
|
+
* liquidity reserves, target values, and min/max fees.
|
|
419
|
+
* @returns A `Percentage` representing the resulting fee (0.01 = 1%).
|
|
420
|
+
*
|
|
421
|
+
* @example
|
|
422
|
+
* ```typescript
|
|
423
|
+
* const vaultState = await staking.getStakedSuiVaultState();
|
|
424
|
+
* const fee = Staking.calcAtomicUnstakeFee({ stakedSuiVaultState: vaultState });
|
|
425
|
+
* console.log("Current atomic unstake fee:", fee);
|
|
426
|
+
* ```
|
|
198
427
|
*/
|
|
199
428
|
static calcAtomicUnstakeFee(inputs) {
|
|
200
429
|
const { stakedSuiVaultState } = inputs;
|
|
@@ -202,14 +431,13 @@ class Staking extends caller_1.Caller {
|
|
|
202
431
|
if (stakedSuiVaultState.atomicUnstakeSuiReserves >=
|
|
203
432
|
stakedSuiVaultState.atomicUnstakeSuiReservesTargetValue) {
|
|
204
433
|
// Atomic unstakes that keep the `atomic_unstake_sui_reserves` larger than the desired target
|
|
205
|
-
//
|
|
434
|
+
// value receive the minimum fee.
|
|
206
435
|
return utils_1.Casting.bigIntToFixedNumber(stakedSuiVaultState.minAtomicUnstakeFee);
|
|
207
436
|
}
|
|
208
437
|
else {
|
|
209
|
-
// Atomic unstakes that
|
|
210
|
-
//
|
|
211
|
-
//
|
|
212
|
-
// e.g. fee = max_fee - ((max_fee - min_fee) * liquidity_after / target_liquidity_value)
|
|
438
|
+
// Atomic unstakes that bring the `atomic_unstake_sui_reserves` below the desired target
|
|
439
|
+
// incur a variable fee:
|
|
440
|
+
// fee = max_fee - ((max_fee - min_fee) * liquidity_after / target_liquidity_value)
|
|
213
441
|
const atomicFeeDelta = stakedSuiVaultState.maxAtomicUnstakeFee -
|
|
214
442
|
stakedSuiVaultState.minAtomicUnstakeFee;
|
|
215
443
|
return utils_1.Casting.bigIntToFixedNumber(stakedSuiVaultState.maxAtomicUnstakeFee -
|
|
@@ -224,21 +452,50 @@ exports.Staking = Staking;
|
|
|
224
452
|
// Constants
|
|
225
453
|
// =========================================================================
|
|
226
454
|
/**
|
|
227
|
-
*
|
|
455
|
+
* Contains constants for staking, including protocol fees, default validator
|
|
456
|
+
* fee, and staking/unstaking bounds. Also defines the maximum external fee
|
|
457
|
+
* percentage allowed for third-party fees.
|
|
228
458
|
*/
|
|
229
459
|
Staking.constants = {
|
|
460
|
+
/**
|
|
461
|
+
* Configuration for fees related to staking and unstaking operations.
|
|
462
|
+
*/
|
|
230
463
|
fees: {
|
|
464
|
+
/**
|
|
465
|
+
* Protocol unstake fee (5%).
|
|
466
|
+
*/
|
|
231
467
|
protocolUnstake: 0.05,
|
|
468
|
+
/**
|
|
469
|
+
* Default validator fee (0%).
|
|
470
|
+
*/
|
|
232
471
|
defaultValidator: 0,
|
|
233
|
-
|
|
472
|
+
/**
|
|
473
|
+
* Maximum validator fee (5%).
|
|
474
|
+
*/
|
|
475
|
+
maxValidator: 0.05,
|
|
234
476
|
},
|
|
477
|
+
/**
|
|
478
|
+
* Configuration for minimum stake/unstake amounts, and maximum external fee
|
|
479
|
+
* percentage allowed.
|
|
480
|
+
*/
|
|
235
481
|
bounds: {
|
|
482
|
+
/**
|
|
483
|
+
* Minimum SUI that can be staked. 1 SUI = 10^9 MIST.
|
|
484
|
+
*/
|
|
236
485
|
minStake: BigInt("1000000000"),
|
|
486
|
+
/**
|
|
487
|
+
* Minimum afSUI that can be unstaked. 1 afSUI = 10^9 MIST (mirroring SUI decimals).
|
|
488
|
+
*/
|
|
237
489
|
minUnstake: BigInt("1000000000"),
|
|
238
490
|
/**
|
|
239
|
-
*
|
|
491
|
+
* Maximum external fee percentage that third parties can add on top
|
|
492
|
+
* of protocol fees for staking or unstaking transactions.
|
|
493
|
+
* @remarks 0.5 = 50%
|
|
240
494
|
*/
|
|
241
|
-
maxExternalFeePercentage: 0.5,
|
|
495
|
+
maxExternalFeePercentage: 0.5,
|
|
242
496
|
},
|
|
243
|
-
|
|
497
|
+
/**
|
|
498
|
+
* The default validator fee (0%).
|
|
499
|
+
*/
|
|
500
|
+
defaultValidatorFee: 0,
|
|
244
501
|
};
|