@opendatalabs/vana-sdk 2.2.2 → 2.2.3-canary.5d4d0b4

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 (43) hide show
  1. package/dist/controllers/permissions.cjs +19 -14
  2. package/dist/controllers/permissions.cjs.map +1 -1
  3. package/dist/controllers/permissions.js +19 -14
  4. package/dist/controllers/permissions.js.map +1 -1
  5. package/dist/controllers/staking.cjs +539 -0
  6. package/dist/controllers/staking.cjs.map +1 -0
  7. package/dist/controllers/staking.d.ts +404 -0
  8. package/dist/controllers/staking.js +515 -0
  9. package/dist/controllers/staking.js.map +1 -0
  10. package/dist/core.cjs +4 -0
  11. package/dist/core.cjs.map +1 -1
  12. package/dist/core.d.ts +3 -0
  13. package/dist/core.js +4 -0
  14. package/dist/core.js.map +1 -1
  15. package/dist/generated/abi/VanaPoolEntityImplementation.cjs +37 -0
  16. package/dist/generated/abi/VanaPoolEntityImplementation.cjs.map +1 -1
  17. package/dist/generated/abi/VanaPoolEntityImplementation.d.ts +29 -0
  18. package/dist/generated/abi/VanaPoolEntityImplementation.js +37 -0
  19. package/dist/generated/abi/VanaPoolEntityImplementation.js.map +1 -1
  20. package/dist/generated/abi/VanaPoolStakingImplementation.cjs +156 -19
  21. package/dist/generated/abi/VanaPoolStakingImplementation.cjs.map +1 -1
  22. package/dist/generated/abi/VanaPoolStakingImplementation.d.ts +120 -14
  23. package/dist/generated/abi/VanaPoolStakingImplementation.js +156 -19
  24. package/dist/generated/abi/VanaPoolStakingImplementation.js.map +1 -1
  25. package/dist/generated/abi/index.d.ts +149 -14
  26. package/dist/generated/event-types.cjs.map +1 -1
  27. package/dist/generated/event-types.d.ts +4 -0
  28. package/dist/generated/eventRegistry.cjs +24 -0
  29. package/dist/generated/eventRegistry.cjs.map +1 -1
  30. package/dist/generated/eventRegistry.js +24 -0
  31. package/dist/generated/eventRegistry.js.map +1 -1
  32. package/dist/index.browser.d.ts +2 -0
  33. package/dist/index.browser.js +2 -0
  34. package/dist/index.browser.js.map +1 -1
  35. package/dist/index.node.cjs +3 -0
  36. package/dist/index.node.cjs.map +1 -1
  37. package/dist/index.node.d.ts +2 -0
  38. package/dist/index.node.js +2 -0
  39. package/dist/index.node.js.map +1 -1
  40. package/dist/tests/staking.test.d.ts +1 -0
  41. package/dist/types/permissions.cjs.map +1 -1
  42. package/dist/types/permissions.d.ts +2 -0
  43. package/package.json +1 -1
@@ -0,0 +1,404 @@
1
+ /**
2
+ * Provides staking functionality for the VanaPool protocol.
3
+ *
4
+ * @remarks
5
+ * This controller handles interactions with VanaPool staking contracts,
6
+ * allowing users to query staking information such as total VANA staked,
7
+ * entity information, and staker positions.
8
+ *
9
+ * @category Controllers
10
+ * @module StakingController
11
+ */
12
+ import type { ControllerContext } from "../types/controller-context";
13
+ import type { TransactionOptions } from "../types/operations";
14
+ import { BaseController } from "./base";
15
+ import type { Address, Hash } from "viem";
16
+ /**
17
+ * Information about a staking entity in the VanaPool protocol.
18
+ */
19
+ export interface EntityInfo {
20
+ entityId: bigint;
21
+ ownerAddress: Address;
22
+ status: number;
23
+ name: string;
24
+ maxAPY: bigint;
25
+ lockedRewardPool: bigint;
26
+ activeRewardPool: bigint;
27
+ totalShares: bigint;
28
+ lastUpdateTimestamp: bigint;
29
+ }
30
+ /**
31
+ * Information about a staker's position in an entity.
32
+ */
33
+ export interface StakerEntityInfo {
34
+ shares: bigint;
35
+ costBasis: bigint;
36
+ rewardEligibilityTimestamp: bigint;
37
+ realizedRewards: bigint;
38
+ vestedRewards: bigint;
39
+ }
40
+ /**
41
+ * Comprehensive staking summary for a staker in an entity.
42
+ */
43
+ export interface StakerEntitySummary {
44
+ /** Number of shares owned by the staker */
45
+ shares: bigint;
46
+ /** Cost basis - the original VANA amount staked */
47
+ costBasis: bigint;
48
+ /** Current value of the staker's shares in VANA */
49
+ currentValue: bigint;
50
+ /** Timestamp when rewards become eligible */
51
+ rewardEligibilityTimestamp: bigint;
52
+ /** Remaining bonding time in seconds (0 if bonding period has passed) */
53
+ remainingBondingTime: bigint;
54
+ /** Whether the staker is still in the bonding period */
55
+ isInBondingPeriod: boolean;
56
+ /** Vested rewards that can be claimed without penalty */
57
+ vestedRewards: bigint;
58
+ /** Unvested rewards (pending interest = currentValue - costBasis) */
59
+ unvestedRewards: bigint;
60
+ /** Realized/withdrawn rewards (already claimed) */
61
+ realizedRewards: bigint;
62
+ /** Total earned rewards (includes vested, unvested, and realized) */
63
+ earnedRewards: bigint;
64
+ }
65
+ /**
66
+ * Controller for VanaPool staking operations.
67
+ *
68
+ * @remarks
69
+ * Provides methods to query staking information from the VanaPool contracts.
70
+ * This includes total VANA staked across the protocol, entity information,
71
+ * and individual staker positions.
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * // Get total VANA staked in the protocol
76
+ * const totalStaked = await vana.staking.getTotalVanaStaked();
77
+ * console.log(`Total staked: ${totalStaked} wei`);
78
+ *
79
+ * // Get entity information
80
+ * const entity = await vana.staking.getEntity(1n);
81
+ * console.log(`Entity name: ${entity.name}`);
82
+ * ```
83
+ *
84
+ * @category Controllers
85
+ */
86
+ export declare class StakingController extends BaseController {
87
+ constructor(context: ControllerContext);
88
+ /**
89
+ * Gets the chain ID from context.
90
+ */
91
+ private getChainId;
92
+ /**
93
+ * Gets the VanaPoolEntity contract instance.
94
+ */
95
+ private getEntityContract;
96
+ /**
97
+ * Gets the VanaPoolStaking contract instance.
98
+ */
99
+ private getStakingContract;
100
+ /**
101
+ * Gets the total amount of VANA staked in the VanaPool protocol or a specific entity.
102
+ *
103
+ * @remarks
104
+ * When called without an entityId, this retrieves the sum of activeRewardPool
105
+ * across all active entities in the VanaPool protocol.
106
+ * When called with an entityId, this returns the activeRewardPool for that specific entity.
107
+ * The value is returned in wei (10^18 = 1 VANA).
108
+ *
109
+ * @param entityId - Optional entity ID to get staked amount for a specific entity
110
+ * @returns The total amount of VANA staked in wei
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * // Get total staked across all entities
115
+ * const totalStaked = await vana.staking.getTotalVanaStaked();
116
+ * console.log(`Total staked: ${Number(totalStaked) / 1e18} VANA`);
117
+ *
118
+ * // Get staked amount for a specific entity
119
+ * const entityStaked = await vana.staking.getTotalVanaStaked(1n);
120
+ * console.log(`Entity 1 staked: ${Number(entityStaked) / 1e18} VANA`);
121
+ * ```
122
+ */
123
+ getTotalVanaStaked(entityId?: bigint): Promise<bigint>;
124
+ /**
125
+ * Gets information about a specific staking entity.
126
+ *
127
+ * @param entityId - The ID of the entity to query
128
+ * @returns The entity information including name, APY, shares, and reward pools
129
+ *
130
+ * @example
131
+ * ```typescript
132
+ * const entity = await vana.staking.getEntity(1n);
133
+ * console.log(`Entity: ${entity.name}`);
134
+ * console.log(`Total shares: ${entity.totalShares}`);
135
+ * console.log(`Max APY: ${Number(entity.maxAPY) / 100}%`);
136
+ * ```
137
+ */
138
+ getEntity(entityId: bigint): Promise<EntityInfo>;
139
+ /**
140
+ * Gets the total number of staking entities in the protocol.
141
+ *
142
+ * @returns The count of entities
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * const count = await vana.staking.getEntitiesCount();
147
+ * console.log(`Total entities: ${count}`);
148
+ * ```
149
+ */
150
+ getEntitiesCount(): Promise<bigint>;
151
+ /**
152
+ * Gets the IDs of all active staking entities.
153
+ *
154
+ * @returns Array of active entity IDs
155
+ *
156
+ * @example
157
+ * ```typescript
158
+ * const activeIds = await vana.staking.getActiveEntities();
159
+ * console.log(`Active entities: ${activeIds.join(', ')}`);
160
+ * ```
161
+ */
162
+ getActiveEntities(): Promise<readonly bigint[]>;
163
+ /**
164
+ * Gets a staker's position in a specific entity.
165
+ *
166
+ * @param staker - The address of the staker
167
+ * @param entityId - The ID of the entity
168
+ * @returns The staker's position information
169
+ *
170
+ * @example
171
+ * ```typescript
172
+ * const position = await vana.staking.getStakerPosition(
173
+ * '0x742d35...',
174
+ * 1n
175
+ * );
176
+ * console.log(`Shares: ${position.shares}`);
177
+ * console.log(`Rewards: ${position.realizedRewards}`);
178
+ * ```
179
+ */
180
+ getStakerPosition(staker: Address, entityId: bigint): Promise<StakerEntityInfo>;
181
+ /**
182
+ * Gets the earned rewards for a staker in an entity.
183
+ *
184
+ * @param staker - The address of the staker
185
+ * @param entityId - The ID of the entity
186
+ * @returns The earned rewards amount in wei
187
+ *
188
+ * @example
189
+ * ```typescript
190
+ * const rewards = await vana.staking.getEarnedRewards(
191
+ * '0x742d35...',
192
+ * 1n
193
+ * );
194
+ * console.log(`Earned: ${Number(rewards) / 1e18} VANA`);
195
+ * ```
196
+ */
197
+ getEarnedRewards(staker: Address, entityId: bigint): Promise<bigint>;
198
+ /**
199
+ * Gets the minimum stake amount required to stake.
200
+ *
201
+ * @returns The minimum stake amount in wei
202
+ *
203
+ * @example
204
+ * ```typescript
205
+ * const minStake = await vana.staking.getMinStakeAmount();
206
+ * console.log(`Minimum stake: ${Number(minStake) / 1e18} VANA`);
207
+ * ```
208
+ */
209
+ getMinStakeAmount(): Promise<bigint>;
210
+ /**
211
+ * Gets the count of active stakers in the protocol.
212
+ *
213
+ * @returns The number of active stakers
214
+ *
215
+ * @example
216
+ * ```typescript
217
+ * const count = await vana.staking.getActiveStakersCount();
218
+ * console.log(`Active stakers: ${count}`);
219
+ * ```
220
+ */
221
+ getActiveStakersCount(): Promise<bigint>;
222
+ /**
223
+ * Gets the bonding period for staking.
224
+ *
225
+ * @returns The bonding period in seconds
226
+ *
227
+ * @example
228
+ * ```typescript
229
+ * const bondingPeriod = await vana.staking.getBondingPeriod();
230
+ * console.log(`Bonding period: ${bondingPeriod / 86400n} days`);
231
+ * ```
232
+ */
233
+ getBondingPeriod(): Promise<bigint>;
234
+ /**
235
+ * Gets the total distributed rewards for a specific entity from the subgraph.
236
+ *
237
+ * @remarks
238
+ * This queries the VanaPool subgraph to retrieve the cumulative `totalDistributedRewards`
239
+ * for a staking entity. This value represents the sum of all rewards that have been
240
+ * processed (moved from lockedRewardPool to activeRewardPool) minus any forfeited
241
+ * rewards that were returned.
242
+ *
243
+ * Requires a configured `subgraphUrl` in the Vana constructor options.
244
+ *
245
+ * @param entityId - The ID of the entity to query
246
+ * @param options - Optional configuration including custom subgraph URL
247
+ * @returns The total distributed rewards in wei
248
+ * @throws {BlockchainError} When subgraph URL is not configured or query fails
249
+ *
250
+ * @example
251
+ * ```typescript
252
+ * const totalRewards = await vana.staking.getTotalDistributedRewards(1n);
253
+ * const totalRewardsVana = Number(totalRewards) / 1e18;
254
+ * console.log(`Total distributed rewards: ${totalRewardsVana.toLocaleString()} VANA`);
255
+ * ```
256
+ */
257
+ getTotalDistributedRewards(entityId: bigint, options?: {
258
+ subgraphUrl?: string;
259
+ }): Promise<bigint>;
260
+ /**
261
+ * Gets a comprehensive staking summary for a staker in an entity.
262
+ *
263
+ * @remarks
264
+ * This method aggregates all relevant staking information for a staker in a single call,
265
+ * including staked amount, current value, bonding status, and all reward types.
266
+ *
267
+ * Reward breakdown:
268
+ * - `earnedRewards` = pendingInterest + vestedRewards + realizedRewards
269
+ * - `pendingInterest` = currentValue - costBasis (unvested appreciation)
270
+ * - `vestedRewards` = rewards that have vested but not yet withdrawn
271
+ * - `realizedRewards` = rewards already withdrawn during unstakes
272
+ *
273
+ * @param staker - The address of the staker
274
+ * @param entityId - The ID of the entity
275
+ * @returns A comprehensive summary of the staker's position
276
+ *
277
+ * @example
278
+ * ```typescript
279
+ * const summary = await vana.staking.getStakerSummary('0x742d35...', 1n);
280
+ * console.log(`Total staked: ${Number(summary.totalStaked) / 1e18} VANA`);
281
+ * console.log(`Current value: ${Number(summary.currentValue) / 1e18} VANA`);
282
+ * console.log(`In bonding period: ${summary.isInBondingPeriod}`);
283
+ * console.log(`Remaining bonding time: ${Number(summary.remainingBondingTime) / 86400} days`);
284
+ * console.log(`Vested rewards: ${Number(summary.vestedRewards) / 1e18} VANA`);
285
+ * console.log(`Unvested rewards: ${Number(summary.unvestedRewards) / 1e18} VANA`);
286
+ * console.log(`Realized rewards: ${Number(summary.realizedRewards) / 1e18} VANA`);
287
+ * console.log(`Total earned: ${Number(summary.earnedRewards) / 1e18} VANA`);
288
+ * ```
289
+ */
290
+ getStakerSummary(staker: Address, entityId: bigint): Promise<StakerEntitySummary>;
291
+ /**
292
+ * Stakes VANA to an entity in the VanaPool protocol.
293
+ *
294
+ * @remarks
295
+ * This method stakes native VANA tokens to a specified entity. The staker will receive
296
+ * shares in proportion to their stake amount. A bonding period applies during which
297
+ * rewards cannot be fully claimed without penalty.
298
+ *
299
+ * Requires a wallet client to be configured in the Vana constructor.
300
+ *
301
+ * @param params - The staking parameters
302
+ * @param params.entityId - The ID of the entity to stake to
303
+ * @param params.amount - The amount of VANA to stake (in wei, or as a string like "1.5" for 1.5 VANA)
304
+ * @param params.recipient - Optional recipient address for the shares (defaults to the sender)
305
+ * @param params.minShares - Optional minimum shares to receive (slippage protection, defaults to 0)
306
+ * @returns The transaction hash
307
+ * @throws {BlockchainError} When wallet client is not configured
308
+ *
309
+ * @example
310
+ * ```typescript
311
+ * // Stake 100 VANA to entity 1
312
+ * const txHash = await vana.staking.stake({
313
+ * entityId: 1n,
314
+ * amount: "100", // 100 VANA
315
+ * });
316
+ * console.log(`Staked! Transaction: ${txHash}`);
317
+ *
318
+ * // Stake with slippage protection
319
+ * const txHash2 = await vana.staking.stake({
320
+ * entityId: 1n,
321
+ * amount: parseEther("50"), // 50 VANA in wei
322
+ * minShares: parseEther("49"), // Expect at least 49 shares
323
+ * });
324
+ * ```
325
+ */
326
+ stake(params: {
327
+ entityId: bigint;
328
+ amount: bigint | string;
329
+ recipient?: Address;
330
+ minShares?: bigint;
331
+ }, options?: TransactionOptions): Promise<Hash>;
332
+ /**
333
+ * Gets the maximum amount of VANA that can be unstaked in a single transaction.
334
+ *
335
+ * @remarks
336
+ * This calls the contract's getMaxUnstakeAmount which returns the minimum of:
337
+ * 1. The withdrawable VANA (costBasis if in bonding period, shareValue if eligible)
338
+ * 2. The entity's activeRewardPool (what the entity has available)
339
+ * 3. The treasury balance (what can be paid out)
340
+ *
341
+ * The limiting factor indicates what's constraining the unstake:
342
+ * - 0 = user shares/costBasis
343
+ * - 1 = activeRewardPool
344
+ * - 2 = treasury
345
+ *
346
+ * @param staker - The address of the staker
347
+ * @param entityId - The ID of the entity
348
+ * @returns Object containing maxVana, maxShares, limitingFactor, and isInBondingPeriod
349
+ *
350
+ * @example
351
+ * ```typescript
352
+ * const result = await vana.staking.getMaxUnstakeAmount('0x742d35...', 1n);
353
+ * console.log(`Max unstake: ${Number(result.maxVana) / 1e18} VANA`);
354
+ * console.log(`Max shares: ${result.maxShares}`);
355
+ * console.log(`In bonding period: ${result.isInBondingPeriod}`);
356
+ * ```
357
+ */
358
+ getMaxUnstakeAmount(staker: Address, entityId: bigint): Promise<{
359
+ maxVana: bigint;
360
+ maxShares: bigint;
361
+ limitingFactor: number;
362
+ isInBondingPeriod: boolean;
363
+ }>;
364
+ /**
365
+ * Unstakes VANA from an entity in the VanaPool protocol.
366
+ *
367
+ * @remarks
368
+ * This method unstakes native VANA tokens from a specified entity. The amount
369
+ * that can be unstaked depends on whether the staker is in the bonding period:
370
+ *
371
+ * - **During bonding period**: Only cost basis can be withdrawn; rewards are forfeited
372
+ * - **After bonding period**: Full current value (cost basis + rewards) can be withdrawn
373
+ *
374
+ * Use `getMaxUnstakeAmount` to determine the maximum amount that can be unstaked.
375
+ *
376
+ * Requires a wallet client to be configured in the Vana constructor.
377
+ *
378
+ * @param params - The unstaking parameters
379
+ * @param params.entityId - The ID of the entity to unstake from
380
+ * @param params.amount - The amount of VANA to unstake (in wei, or as a string like "1.5" for 1.5 VANA)
381
+ * @param params.maxShares - Maximum shares to burn for slippage protection (defaults to 0, no protection)
382
+ * @returns The transaction hash
383
+ * @throws {BlockchainError} When wallet client is not configured
384
+ *
385
+ * @example
386
+ * ```typescript
387
+ * // Get max unstake amount first
388
+ * const maxUnstake = await vana.staking.getMaxUnstakeAmount(address, 1n);
389
+ *
390
+ * // Unstake the maximum amount with slippage protection
391
+ * const txHash = await vana.staking.unstake({
392
+ * entityId: 1n,
393
+ * amount: maxUnstake.maxVana,
394
+ * maxShares: maxUnstake.maxShares,
395
+ * });
396
+ * console.log(`Unstaked! Transaction: ${txHash}`);
397
+ * ```
398
+ */
399
+ unstake(params: {
400
+ entityId: bigint;
401
+ amount: bigint | string;
402
+ maxShares?: bigint;
403
+ }, options?: TransactionOptions): Promise<Hash>;
404
+ }