@opendatalabs/vana-sdk 2.2.3-canary.046cb7e → 2.2.3-canary.ee13d65

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.
@@ -350,22 +350,49 @@ class StakingController extends import_base.BaseController {
350
350
  * ```
351
351
  */
352
352
  async getStakerSummary(staker, entityId) {
353
- const stakingContract = this.getStakingContract();
354
- const entityContract = this.getEntityContract();
355
- const position = await stakingContract.read.stakerEntities([
356
- staker,
357
- entityId
358
- ]);
359
- const earnedRewards = await stakingContract.read.getEarnedRewards([
360
- staker,
361
- entityId
362
- ]);
353
+ const chainId = this.getChainId();
354
+ const stakingAddress = (0, import_addresses.getContractAddress)(chainId, "VanaPoolStaking");
355
+ const entityAddress = (0, import_addresses.getContractAddress)(chainId, "VanaPoolEntity");
356
+ const stakingAbi = (0, import_abi.getAbi)("VanaPoolStaking");
357
+ const entityAbi = (0, import_abi.getAbi)("VanaPoolEntity");
363
358
  const block = await this.context.publicClient.getBlock();
359
+ const blockNumber = block.number;
360
+ const multicallResults = await this.context.publicClient.multicall({
361
+ contracts: [
362
+ {
363
+ address: stakingAddress,
364
+ abi: stakingAbi,
365
+ functionName: "stakerEntities",
366
+ args: [staker, entityId]
367
+ },
368
+ {
369
+ address: stakingAddress,
370
+ abi: stakingAbi,
371
+ functionName: "getEarnedRewards",
372
+ args: [staker, entityId]
373
+ },
374
+ {
375
+ address: entityAddress,
376
+ abi: entityAbi,
377
+ functionName: "entityShareToVana",
378
+ args: [entityId]
379
+ }
380
+ ],
381
+ blockNumber
382
+ });
383
+ const [positionResult, earnedRewardsResult, shareToVanaResult] = multicallResults;
384
+ if (positionResult.status === "failure" || earnedRewardsResult.status === "failure" || shareToVanaResult.status === "failure") {
385
+ throw new import_errors.BlockchainError(
386
+ "Failed to fetch staker summary: one or more contract calls failed"
387
+ );
388
+ }
389
+ const position = positionResult.result;
390
+ const earnedRewards = earnedRewardsResult.result;
391
+ const shareToVana = shareToVanaResult.result;
364
392
  const currentTimestamp = block.timestamp;
365
393
  const eligibilityTimestamp = position.rewardEligibilityTimestamp;
366
394
  const remainingBondingTime = eligibilityTimestamp > currentTimestamp ? eligibilityTimestamp - currentTimestamp : 0n;
367
395
  const isInBondingPeriod = remainingBondingTime > 0n;
368
- const shareToVana = await entityContract.read.entityShareToVana([entityId]);
369
396
  const currentValue = position.shares * shareToVana / 10n ** 18n;
370
397
  const unvestedRewards = currentValue > position.costBasis ? currentValue - position.costBasis : 0n;
371
398
  return {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/controllers/staking.ts"],"sourcesContent":["/**\n * Provides staking functionality for the VanaPool protocol.\n *\n * @remarks\n * This controller handles interactions with VanaPool staking contracts,\n * allowing users to query staking information such as total VANA staked,\n * entity information, and staker positions.\n *\n * @category Controllers\n * @module StakingController\n */\n\nimport type { ControllerContext } from \"../types/controller-context\";\nimport type { TransactionOptions } from \"../types/operations\";\nimport { BaseController } from \"./base\";\nimport { getContract, parseEther } from \"viem\";\nimport type { Address, Hash } from \"viem\";\nimport { getContractAddress } from \"../generated/addresses\";\nimport { getAbi } from \"../generated/abi\";\nimport { BlockchainError } from \"../errors\";\n\n/**\n * Information about a staking entity in the VanaPool protocol.\n */\nexport interface EntityInfo {\n entityId: bigint;\n ownerAddress: Address;\n status: number;\n name: string;\n maxAPY: bigint;\n lockedRewardPool: bigint;\n activeRewardPool: bigint;\n totalShares: bigint;\n lastUpdateTimestamp: bigint;\n}\n\n/**\n * Information about a staker's position in an entity.\n */\nexport interface StakerEntityInfo {\n shares: bigint;\n costBasis: bigint;\n rewardEligibilityTimestamp: bigint;\n realizedRewards: bigint;\n vestedRewards: bigint;\n}\n\n/**\n * Comprehensive staking summary for a staker in an entity.\n */\nexport interface StakerEntitySummary {\n /** Number of shares owned by the staker */\n shares: bigint;\n /** Cost basis - the original VANA amount staked */\n costBasis: bigint;\n /** Current value of the staker's shares in VANA */\n currentValue: bigint;\n /** Timestamp when rewards become eligible */\n rewardEligibilityTimestamp: bigint;\n /** Remaining bonding time in seconds (0 if bonding period has passed) */\n remainingBondingTime: bigint;\n /** Whether the staker is still in the bonding period */\n isInBondingPeriod: boolean;\n /** Vested rewards that can be claimed without penalty */\n vestedRewards: bigint;\n /** Unvested rewards (pending interest = currentValue - costBasis) */\n unvestedRewards: bigint;\n /** Realized/withdrawn rewards (already claimed) */\n realizedRewards: bigint;\n /** Total earned rewards (includes vested, unvested, and realized) */\n earnedRewards: bigint;\n}\n\n/**\n * Controller for VanaPool staking operations.\n *\n * @remarks\n * Provides methods to query staking information from the VanaPool contracts.\n * This includes total VANA staked across the protocol, entity information,\n * and individual staker positions.\n *\n * @example\n * ```typescript\n * // Get total VANA staked in the protocol\n * const totalStaked = await vana.staking.getTotalVanaStaked();\n * console.log(`Total staked: ${totalStaked} wei`);\n *\n * // Get entity information\n * const entity = await vana.staking.getEntity(1n);\n * console.log(`Entity name: ${entity.name}`);\n * ```\n *\n * @category Controllers\n */\nexport class StakingController extends BaseController {\n constructor(context: ControllerContext) {\n super(context);\n }\n\n /**\n * Gets the chain ID from context.\n */\n private getChainId(): number {\n const chainId =\n this.context.walletClient?.chain?.id ??\n this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n return chainId;\n }\n\n /**\n * Gets the VanaPoolEntity contract instance.\n */\n private getEntityContract() {\n const chainId = this.getChainId();\n return getContract({\n address: getContractAddress(chainId, \"VanaPoolEntity\"),\n abi: getAbi(\"VanaPoolEntity\"),\n client: this.context.publicClient,\n });\n }\n\n /**\n * Gets the VanaPoolStaking contract instance.\n */\n private getStakingContract() {\n const chainId = this.getChainId();\n return getContract({\n address: getContractAddress(chainId, \"VanaPoolStaking\"),\n abi: getAbi(\"VanaPoolStaking\"),\n client: this.context.publicClient,\n });\n }\n\n /**\n * Gets the total amount of VANA staked in the VanaPool protocol or a specific entity.\n *\n * @remarks\n * When called without an entityId, this retrieves the sum of activeRewardPool\n * across all active entities in the VanaPool protocol.\n * When called with an entityId, this returns the activeRewardPool for that specific entity.\n * The value is returned in wei (10^18 = 1 VANA).\n *\n * @param entityId - Optional entity ID to get staked amount for a specific entity\n * @returns The total amount of VANA staked in wei\n *\n * @example\n * ```typescript\n * // Get total staked across all entities\n * const totalStaked = await vana.staking.getTotalVanaStaked();\n * console.log(`Total staked: ${Number(totalStaked) / 1e18} VANA`);\n *\n * // Get staked amount for a specific entity\n * const entityStaked = await vana.staking.getTotalVanaStaked(1n);\n * console.log(`Entity 1 staked: ${Number(entityStaked) / 1e18} VANA`);\n * ```\n */\n async getTotalVanaStaked(entityId?: bigint): Promise<bigint> {\n const entityContract = this.getEntityContract();\n\n // If entityId is provided, return the activeRewardPool for that specific entity\n if (entityId !== undefined) {\n const entity = await entityContract.read.entities([entityId]);\n return entity.activeRewardPool;\n }\n\n // Otherwise, sum up the activeRewardPool from all active entities\n const activeEntityIds = await entityContract.read.activeEntitiesValues();\n\n let totalStaked = 0n;\n for (const id of activeEntityIds) {\n const entity = await entityContract.read.entities([id]);\n totalStaked += entity.activeRewardPool;\n }\n\n return totalStaked;\n }\n\n /**\n * Gets information about a specific staking entity.\n *\n * @param entityId - The ID of the entity to query\n * @returns The entity information including name, APY, shares, and reward pools\n *\n * @example\n * ```typescript\n * const entity = await vana.staking.getEntity(1n);\n * console.log(`Entity: ${entity.name}`);\n * console.log(`Total shares: ${entity.totalShares}`);\n * console.log(`Max APY: ${Number(entity.maxAPY) / 100}%`);\n * ```\n */\n async getEntity(entityId: bigint): Promise<EntityInfo> {\n const entityContract = this.getEntityContract();\n\n const result = await entityContract.read.entities([entityId]);\n\n return {\n entityId: result.entityId,\n ownerAddress: result.ownerAddress as Address,\n status: result.status,\n name: result.name,\n maxAPY: result.maxAPY,\n lockedRewardPool: result.lockedRewardPool,\n activeRewardPool: result.activeRewardPool,\n totalShares: result.totalShares,\n lastUpdateTimestamp: result.lastUpdateTimestamp,\n };\n }\n\n /**\n * Gets the total number of staking entities in the protocol.\n *\n * @returns The count of entities\n *\n * @example\n * ```typescript\n * const count = await vana.staking.getEntitiesCount();\n * console.log(`Total entities: ${count}`);\n * ```\n */\n async getEntitiesCount(): Promise<bigint> {\n const entityContract = this.getEntityContract();\n return entityContract.read.entitiesCount();\n }\n\n /**\n * Gets the IDs of all active staking entities.\n *\n * @returns Array of active entity IDs\n *\n * @example\n * ```typescript\n * const activeIds = await vana.staking.getActiveEntities();\n * console.log(`Active entities: ${activeIds.join(', ')}`);\n * ```\n */\n async getActiveEntities(): Promise<readonly bigint[]> {\n const entityContract = this.getEntityContract();\n return entityContract.read.activeEntitiesValues();\n }\n\n /**\n * Gets a staker's position in a specific entity.\n *\n * @param staker - The address of the staker\n * @param entityId - The ID of the entity\n * @returns The staker's position information\n *\n * @example\n * ```typescript\n * const position = await vana.staking.getStakerPosition(\n * '0x742d35...',\n * 1n\n * );\n * console.log(`Shares: ${position.shares}`);\n * console.log(`Rewards: ${position.realizedRewards}`);\n * ```\n */\n async getStakerPosition(\n staker: Address,\n entityId: bigint,\n ): Promise<StakerEntityInfo> {\n const stakingContract = this.getStakingContract();\n\n const result = await stakingContract.read.stakerEntities([\n staker,\n entityId,\n ]);\n\n return {\n shares: result.shares,\n costBasis: result.costBasis,\n rewardEligibilityTimestamp: result.rewardEligibilityTimestamp,\n realizedRewards: result.realizedRewards,\n vestedRewards: result.vestedRewards,\n };\n }\n\n /**\n * Gets the earned rewards for a staker in an entity.\n *\n * @param staker - The address of the staker\n * @param entityId - The ID of the entity\n * @returns The earned rewards amount in wei\n *\n * @example\n * ```typescript\n * const rewards = await vana.staking.getEarnedRewards(\n * '0x742d35...',\n * 1n\n * );\n * console.log(`Earned: ${Number(rewards) / 1e18} VANA`);\n * ```\n */\n async getEarnedRewards(staker: Address, entityId: bigint): Promise<bigint> {\n const stakingContract = this.getStakingContract();\n return stakingContract.read.getEarnedRewards([staker, entityId]);\n }\n\n /**\n * Gets the minimum stake amount required to stake.\n *\n * @returns The minimum stake amount in wei\n *\n * @example\n * ```typescript\n * const minStake = await vana.staking.getMinStakeAmount();\n * console.log(`Minimum stake: ${Number(minStake) / 1e18} VANA`);\n * ```\n */\n async getMinStakeAmount(): Promise<bigint> {\n const stakingContract = this.getStakingContract();\n return stakingContract.read.minStakeAmount();\n }\n\n /**\n * Gets the count of active stakers in the protocol.\n *\n * @returns The number of active stakers\n *\n * @example\n * ```typescript\n * const count = await vana.staking.getActiveStakersCount();\n * console.log(`Active stakers: ${count}`);\n * ```\n */\n async getActiveStakersCount(): Promise<bigint> {\n const stakingContract = this.getStakingContract();\n return stakingContract.read.activeStakersListCount();\n }\n\n /**\n * Gets the bonding period for staking.\n *\n * @returns The bonding period in seconds\n *\n * @example\n * ```typescript\n * const bondingPeriod = await vana.staking.getBondingPeriod();\n * console.log(`Bonding period: ${bondingPeriod / 86400n} days`);\n * ```\n */\n async getBondingPeriod(): Promise<bigint> {\n const stakingContract = this.getStakingContract();\n return stakingContract.read.bondingPeriod();\n }\n\n /**\n * Gets the total distributed rewards for a specific entity from the subgraph.\n *\n * @remarks\n * This queries the VanaPool subgraph to retrieve the cumulative `totalDistributedRewards`\n * for a staking entity. This value represents the sum of all rewards that have been\n * processed (moved from lockedRewardPool to activeRewardPool) minus any forfeited\n * rewards that were returned.\n *\n * Requires a configured `subgraphUrl` in the Vana constructor options.\n *\n * @param entityId - The ID of the entity to query\n * @param options - Optional configuration including custom subgraph URL\n * @returns The total distributed rewards in wei\n * @throws {BlockchainError} When subgraph URL is not configured or query fails\n *\n * @example\n * ```typescript\n * const totalRewards = await vana.staking.getTotalDistributedRewards(1n);\n * const totalRewardsVana = Number(totalRewards) / 1e18;\n * console.log(`Total distributed rewards: ${totalRewardsVana.toLocaleString()} VANA`);\n * ```\n */\n async getTotalDistributedRewards(\n entityId: bigint,\n options: { subgraphUrl?: string } = {},\n ): Promise<bigint> {\n const graphqlEndpoint = options.subgraphUrl ?? this.context.subgraphUrl;\n\n if (!graphqlEndpoint) {\n throw new BlockchainError(\n \"subgraphUrl is required. Please provide a valid subgraph endpoint or configure it in Vana constructor.\",\n );\n }\n\n const query = `\n query GetStakingEntityRewards($entityId: ID!) {\n stakingEntity(id: $entityId) {\n totalDistributedRewards\n }\n }\n `;\n\n const response = await fetch(graphqlEndpoint, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n query,\n variables: {\n entityId: entityId.toString(),\n },\n }),\n });\n\n if (!response.ok) {\n throw new BlockchainError(\n `Subgraph query failed with status ${response.status}`,\n );\n }\n\n const result = (await response.json()) as {\n data?: { stakingEntity?: { totalDistributedRewards: string } };\n errors?: Array<{ message: string }>;\n };\n\n if (result.errors && result.errors.length > 0) {\n throw new BlockchainError(\n `Subgraph query error: ${result.errors[0].message}`,\n );\n }\n\n if (!result.data?.stakingEntity) {\n throw new BlockchainError(`Staking entity ${entityId} not found`);\n }\n\n return BigInt(result.data.stakingEntity.totalDistributedRewards);\n }\n\n /**\n * Gets a comprehensive staking summary for a staker in an entity.\n *\n * @remarks\n * This method aggregates all relevant staking information for a staker in a single call,\n * including staked amount, current value, bonding status, and all reward types.\n *\n * Reward breakdown:\n * - `earnedRewards` = pendingInterest + vestedRewards + realizedRewards\n * - `pendingInterest` = currentValue - costBasis (unvested appreciation)\n * - `vestedRewards` = rewards that have vested but not yet withdrawn\n * - `realizedRewards` = rewards already withdrawn during unstakes\n *\n * @param staker - The address of the staker\n * @param entityId - The ID of the entity\n * @returns A comprehensive summary of the staker's position\n *\n * @example\n * ```typescript\n * const summary = await vana.staking.getStakerSummary('0x742d35...', 1n);\n * console.log(`Total staked: ${Number(summary.totalStaked) / 1e18} VANA`);\n * console.log(`Current value: ${Number(summary.currentValue) / 1e18} VANA`);\n * console.log(`In bonding period: ${summary.isInBondingPeriod}`);\n * console.log(`Remaining bonding time: ${Number(summary.remainingBondingTime) / 86400} days`);\n * console.log(`Vested rewards: ${Number(summary.vestedRewards) / 1e18} VANA`);\n * console.log(`Unvested rewards: ${Number(summary.unvestedRewards) / 1e18} VANA`);\n * console.log(`Realized rewards: ${Number(summary.realizedRewards) / 1e18} VANA`);\n * console.log(`Total earned: ${Number(summary.earnedRewards) / 1e18} VANA`);\n * ```\n */\n async getStakerSummary(\n staker: Address,\n entityId: bigint,\n ): Promise<StakerEntitySummary> {\n const stakingContract = this.getStakingContract();\n const entityContract = this.getEntityContract();\n\n // Get staker's position data\n const position = await stakingContract.read.stakerEntities([\n staker,\n entityId,\n ]);\n\n // Get earned rewards from contract\n const earnedRewards = await stakingContract.read.getEarnedRewards([\n staker,\n entityId,\n ]);\n\n // Get current timestamp from the blockchain\n const block = await this.context.publicClient.getBlock();\n const currentTimestamp = block.timestamp;\n\n // Calculate remaining bonding time\n const eligibilityTimestamp = position.rewardEligibilityTimestamp;\n const remainingBondingTime =\n eligibilityTimestamp > currentTimestamp\n ? eligibilityTimestamp - currentTimestamp\n : 0n;\n const isInBondingPeriod = remainingBondingTime > 0n;\n\n // Calculate current value of shares\n // entityShareToVana returns the VANA value of 1 share (scaled by 1e18)\n const shareToVana = await entityContract.read.entityShareToVana([entityId]);\n const currentValue = (position.shares * shareToVana) / 10n ** 18n;\n\n // Calculate pending interest (unvested rewards)\n // pendingInterest = currentValue - costBasis (if positive)\n const unvestedRewards =\n currentValue > position.costBasis\n ? currentValue - position.costBasis\n : 0n;\n\n return {\n shares: position.shares,\n costBasis: position.costBasis,\n currentValue,\n rewardEligibilityTimestamp: eligibilityTimestamp,\n remainingBondingTime,\n isInBondingPeriod,\n vestedRewards: position.vestedRewards,\n unvestedRewards,\n realizedRewards: position.realizedRewards,\n earnedRewards,\n };\n }\n\n /**\n * Stakes VANA to an entity in the VanaPool protocol.\n *\n * @remarks\n * This method stakes native VANA tokens to a specified entity. The staker will receive\n * shares in proportion to their stake amount. A bonding period applies during which\n * rewards cannot be fully claimed without penalty.\n *\n * Requires a wallet client to be configured in the Vana constructor.\n *\n * @param params - The staking parameters\n * @param params.entityId - The ID of the entity to stake to\n * @param params.amount - The amount of VANA to stake (in wei, or as a string like \"1.5\" for 1.5 VANA)\n * @param params.recipient - Optional recipient address for the shares (defaults to the sender)\n * @param params.minShares - Optional minimum shares to receive (slippage protection, defaults to 0)\n * @returns The transaction hash\n * @throws {BlockchainError} When wallet client is not configured\n *\n * @example\n * ```typescript\n * // Stake 100 VANA to entity 1\n * const txHash = await vana.staking.stake({\n * entityId: 1n,\n * amount: \"100\", // 100 VANA\n * });\n * console.log(`Staked! Transaction: ${txHash}`);\n *\n * // Stake with slippage protection\n * const txHash2 = await vana.staking.stake({\n * entityId: 1n,\n * amount: parseEther(\"50\"), // 50 VANA in wei\n * minShares: parseEther(\"49\"), // Expect at least 49 shares\n * });\n * ```\n */\n async stake(\n params: {\n entityId: bigint;\n amount: bigint | string;\n recipient?: Address;\n minShares?: bigint;\n },\n options?: TransactionOptions,\n ): Promise<Hash> {\n this.assertWallet();\n\n const chainId = this.getChainId();\n const stakingAddress = getContractAddress(chainId, \"VanaPoolStaking\");\n const stakingAbi = getAbi(\"VanaPoolStaking\");\n\n // Convert amount to bigint if it's a string (e.g., \"1.5\" -> 1.5 VANA in wei)\n const amountWei =\n typeof params.amount === \"string\"\n ? parseEther(params.amount)\n : params.amount;\n\n // Get account with fallback to userAddress\n const account =\n this.context.walletClient.account ?? this.context.userAddress;\n const accountAddress =\n typeof account === \"string\" ? account : account.address;\n\n // Default recipient to the sender's address\n const recipient = params.recipient ?? accountAddress;\n\n // Default minShares to 0 (no slippage protection)\n const minShares = params.minShares ?? 0n;\n\n const txHash = await this.context.walletClient.writeContract({\n address: stakingAddress,\n abi: stakingAbi,\n functionName: \"stake\",\n args: [params.entityId, recipient, minShares],\n value: amountWei,\n account,\n chain: this.context.walletClient.chain,\n ...this.spreadTransactionOptions(options),\n });\n\n return txHash;\n }\n\n /**\n * Gets the maximum amount of VANA that can be unstaked in a single transaction.\n *\n * @remarks\n * This calls the contract's getMaxUnstakeAmount which returns the minimum of:\n * 1. The withdrawable VANA (costBasis if in bonding period, shareValue if eligible)\n * 2. The entity's activeRewardPool (what the entity has available)\n * 3. The treasury balance (what can be paid out)\n *\n * The limiting factor indicates what's constraining the unstake:\n * - 0 = user shares/costBasis\n * - 1 = activeRewardPool\n * - 2 = treasury\n *\n * @param staker - The address of the staker\n * @param entityId - The ID of the entity\n * @returns Object containing maxVana, maxShares, limitingFactor, and isInBondingPeriod\n *\n * @example\n * ```typescript\n * const result = await vana.staking.getMaxUnstakeAmount('0x742d35...', 1n);\n * console.log(`Max unstake: ${Number(result.maxVana) / 1e18} VANA`);\n * console.log(`Max shares: ${result.maxShares}`);\n * console.log(`In bonding period: ${result.isInBondingPeriod}`);\n * ```\n */\n async getMaxUnstakeAmount(\n staker: Address,\n entityId: bigint,\n ): Promise<{\n maxVana: bigint;\n maxShares: bigint;\n limitingFactor: number;\n isInBondingPeriod: boolean;\n }> {\n const stakingContract = this.getStakingContract();\n\n const result = await stakingContract.read.getMaxUnstakeAmount([\n staker,\n entityId,\n ]);\n\n return {\n maxVana: result[0],\n maxShares: result[1],\n limitingFactor: Number(result[2]),\n isInBondingPeriod: result[3],\n };\n }\n\n /**\n * Unstakes VANA from an entity in the VanaPool protocol.\n *\n * @remarks\n * This method unstakes native VANA tokens from a specified entity. The amount\n * that can be unstaked depends on whether the staker is in the bonding period:\n *\n * - **During bonding period**: Only cost basis can be withdrawn; rewards are forfeited\n * - **After bonding period**: Full current value (cost basis + rewards) can be withdrawn\n *\n * Use `getMaxUnstakeAmount` to determine the maximum amount that can be unstaked.\n *\n * Requires a wallet client to be configured in the Vana constructor.\n *\n * @param params - The unstaking parameters\n * @param params.entityId - The ID of the entity to unstake from\n * @param params.amount - The amount of VANA to unstake (in wei, or as a string like \"1.5\" for 1.5 VANA)\n * @param params.maxShares - Maximum shares to burn for slippage protection (defaults to 0, no protection)\n * @returns The transaction hash\n * @throws {BlockchainError} When wallet client is not configured\n *\n * @example\n * ```typescript\n * // Get max unstake amount first\n * const maxUnstake = await vana.staking.getMaxUnstakeAmount(address, 1n);\n *\n * // Unstake the maximum amount with slippage protection\n * const txHash = await vana.staking.unstake({\n * entityId: 1n,\n * amount: maxUnstake.maxVana,\n * maxShares: maxUnstake.maxShares,\n * });\n * console.log(`Unstaked! Transaction: ${txHash}`);\n * ```\n */\n async unstake(\n params: {\n entityId: bigint;\n amount: bigint | string;\n maxShares?: bigint;\n },\n options?: TransactionOptions,\n ): Promise<Hash> {\n this.assertWallet();\n\n const chainId = this.getChainId();\n const stakingAddress = getContractAddress(chainId, \"VanaPoolStaking\");\n const stakingAbi = getAbi(\"VanaPoolStaking\");\n\n // Convert amount to bigint if it's a string (e.g., \"1.5\" -> 1.5 VANA in wei)\n const amountWei =\n typeof params.amount === \"string\"\n ? parseEther(params.amount)\n : params.amount;\n\n // Default maxShares to 0 (no slippage protection)\n const maxShares = params.maxShares ?? 0n;\n\n // Get account with fallback to userAddress\n const account =\n this.context.walletClient.account ?? this.context.userAddress;\n\n const txHash = await this.context.walletClient.writeContract({\n address: stakingAddress,\n abi: stakingAbi,\n functionName: \"unstakeVana\",\n args: [params.entityId, amountWei, maxShares],\n account,\n chain: this.context.walletClient.chain,\n ...this.spreadTransactionOptions(options),\n });\n\n return txHash;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAcA,kBAA+B;AAC/B,kBAAwC;AAExC,uBAAmC;AACnC,iBAAuB;AACvB,oBAAgC;AA2EzB,MAAM,0BAA0B,2BAAe;AAAA,EACpD,YAAY,SAA4B;AACtC,UAAM,OAAO;AAAA,EACf;AAAA;AAAA;AAAA;AAAA,EAKQ,aAAqB;AAC3B,UAAM,UACJ,KAAK,QAAQ,cAAc,OAAO,MAClC,KAAK,QAAQ,aAAa,OAAO;AACnC,QAAI,CAAC,SAAS;AACZ,YAAM,IAAI,MAAM,wBAAwB;AAAA,IAC1C;AACA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKQ,oBAAoB;AAC1B,UAAM,UAAU,KAAK,WAAW;AAChC,eAAO,yBA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oB;AAAA,MAC5D;AAAA,MACA;AAAA,IACF,CAAC;AAED,WAAO;AAAA,MACL,SAAS,OAAO,CAAC;AAAA,MACjB,WAAW,OAAO,CAAC;AAAA,MACnB,gBAAgB,OAAO,OAAO,CAAC,CAAC;AAAA,MAChC,mBAAmB,OAAO,CAAC;AAAA,IAC7B;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAqCA,MAAM,QACJ,QAKA,SACe;AACf,SAAK,aAAa;AAElB,UAAM,UAAU,KAAK,WAAW;AAChC,UAAM,qBAAiB,qCAAmB,SAAS,iBAAiB;AACpE,UAAM,iBAAa,mBAAO,iBAAiB;AAG3C,UAAM,YACJ,OAAO,OAAO,WAAW,eACrB,wBAAW,OAAO,MAAM,IACxB,OAAO;AAGb,UAAM,YAAY,OAAO,aAAa;AAGtC,UAAM,UACJ,KAAK,QAAQ,aAAa,WAAW,KAAK,QAAQ;AAEpD,UAAM,SAAS,MAAM,KAAK,QAAQ,aAAa,cAAc;AAAA,MAC3D,SAAS;AAAA,MACT,KAAK;AAAA,MACL,cAAc;AAAA,MACd,MAAM,CAAC,OAAO,UAAU,WAAW,SAAS;AAAA,MAC5C;AAAA,MACA,OAAO,KAAK,QAAQ,aAAa;AAAA,MACjC,GAAG,KAAK,yBAAyB,OAAO;AAAA,IAC1C,CAAC;AAED,WAAO;AAAA,EACT;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/controllers/staking.ts"],"sourcesContent":["/**\n * Provides staking functionality for the VanaPool protocol.\n *\n * @remarks\n * This controller handles interactions with VanaPool staking contracts,\n * allowing users to query staking information such as total VANA staked,\n * entity information, and staker positions.\n *\n * @category Controllers\n * @module StakingController\n */\n\nimport type { ControllerContext } from \"../types/controller-context\";\nimport type { TransactionOptions } from \"../types/operations\";\nimport { BaseController } from \"./base\";\nimport { getContract, parseEther } from \"viem\";\nimport type { Address, Hash } from \"viem\";\nimport { getContractAddress } from \"../generated/addresses\";\nimport { getAbi } from \"../generated/abi\";\nimport { BlockchainError } from \"../errors\";\n\n/**\n * Information about a staking entity in the VanaPool protocol.\n */\nexport interface EntityInfo {\n entityId: bigint;\n ownerAddress: Address;\n status: number;\n name: string;\n maxAPY: bigint;\n lockedRewardPool: bigint;\n activeRewardPool: bigint;\n totalShares: bigint;\n lastUpdateTimestamp: bigint;\n}\n\n/**\n * Information about a staker's position in an entity.\n */\nexport interface StakerEntityInfo {\n shares: bigint;\n costBasis: bigint;\n rewardEligibilityTimestamp: bigint;\n realizedRewards: bigint;\n vestedRewards: bigint;\n}\n\n/**\n * Comprehensive staking summary for a staker in an entity.\n */\nexport interface StakerEntitySummary {\n /** Number of shares owned by the staker */\n shares: bigint;\n /** Cost basis - the original VANA amount staked */\n costBasis: bigint;\n /** Current value of the staker's shares in VANA */\n currentValue: bigint;\n /** Timestamp when rewards become eligible */\n rewardEligibilityTimestamp: bigint;\n /** Remaining bonding time in seconds (0 if bonding period has passed) */\n remainingBondingTime: bigint;\n /** Whether the staker is still in the bonding period */\n isInBondingPeriod: boolean;\n /** Vested rewards that can be claimed without penalty */\n vestedRewards: bigint;\n /** Unvested rewards (pending interest = currentValue - costBasis) */\n unvestedRewards: bigint;\n /** Realized/withdrawn rewards (already claimed) */\n realizedRewards: bigint;\n /** Total earned rewards (includes vested, unvested, and realized) */\n earnedRewards: bigint;\n}\n\n/**\n * Controller for VanaPool staking operations.\n *\n * @remarks\n * Provides methods to query staking information from the VanaPool contracts.\n * This includes total VANA staked across the protocol, entity information,\n * and individual staker positions.\n *\n * @example\n * ```typescript\n * // Get total VANA staked in the protocol\n * const totalStaked = await vana.staking.getTotalVanaStaked();\n * console.log(`Total staked: ${totalStaked} wei`);\n *\n * // Get entity information\n * const entity = await vana.staking.getEntity(1n);\n * console.log(`Entity name: ${entity.name}`);\n * ```\n *\n * @category Controllers\n */\nexport class StakingController extends BaseController {\n constructor(context: ControllerContext) {\n super(context);\n }\n\n /**\n * Gets the chain ID from context.\n */\n private getChainId(): number {\n const chainId =\n this.context.walletClient?.chain?.id ??\n this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n return chainId;\n }\n\n /**\n * Gets the VanaPoolEntity contract instance.\n */\n private getEntityContract() {\n const chainId = this.getChainId();\n return getContract({\n address: getContractAddress(chainId, \"VanaPoolEntity\"),\n abi: getAbi(\"VanaPoolEntity\"),\n client: this.context.publicClient,\n });\n }\n\n /**\n * Gets the VanaPoolStaking contract instance.\n */\n private getStakingContract() {\n const chainId = this.getChainId();\n return getContract({\n address: getContractAddress(chainId, \"VanaPoolStaking\"),\n abi: getAbi(\"VanaPoolStaking\"),\n client: this.context.publicClient,\n });\n }\n\n /**\n * Gets the total amount of VANA staked in the VanaPool protocol or a specific entity.\n *\n * @remarks\n * When called without an entityId, this retrieves the sum of activeRewardPool\n * across all active entities in the VanaPool protocol.\n * When called with an entityId, this returns the activeRewardPool for that specific entity.\n * The value is returned in wei (10^18 = 1 VANA).\n *\n * @param entityId - Optional entity ID to get staked amount for a specific entity\n * @returns The total amount of VANA staked in wei\n *\n * @example\n * ```typescript\n * // Get total staked across all entities\n * const totalStaked = await vana.staking.getTotalVanaStaked();\n * console.log(`Total staked: ${Number(totalStaked) / 1e18} VANA`);\n *\n * // Get staked amount for a specific entity\n * const entityStaked = await vana.staking.getTotalVanaStaked(1n);\n * console.log(`Entity 1 staked: ${Number(entityStaked) / 1e18} VANA`);\n * ```\n */\n async getTotalVanaStaked(entityId?: bigint): Promise<bigint> {\n const entityContract = this.getEntityContract();\n\n // If entityId is provided, return the activeRewardPool for that specific entity\n if (entityId !== undefined) {\n const entity = await entityContract.read.entities([entityId]);\n return entity.activeRewardPool;\n }\n\n // Otherwise, sum up the activeRewardPool from all active entities\n const activeEntityIds = await entityContract.read.activeEntitiesValues();\n\n let totalStaked = 0n;\n for (const id of activeEntityIds) {\n const entity = await entityContract.read.entities([id]);\n totalStaked += entity.activeRewardPool;\n }\n\n return totalStaked;\n }\n\n /**\n * Gets information about a specific staking entity.\n *\n * @param entityId - The ID of the entity to query\n * @returns The entity information including name, APY, shares, and reward pools\n *\n * @example\n * ```typescript\n * const entity = await vana.staking.getEntity(1n);\n * console.log(`Entity: ${entity.name}`);\n * console.log(`Total shares: ${entity.totalShares}`);\n * console.log(`Max APY: ${Number(entity.maxAPY) / 100}%`);\n * ```\n */\n async getEntity(entityId: bigint): Promise<EntityInfo> {\n const entityContract = this.getEntityContract();\n\n const result = await entityContract.read.entities([entityId]);\n\n return {\n entityId: result.entityId,\n ownerAddress: result.ownerAddress as Address,\n status: result.status,\n name: result.name,\n maxAPY: result.maxAPY,\n lockedRewardPool: result.lockedRewardPool,\n activeRewardPool: result.activeRewardPool,\n totalShares: result.totalShares,\n lastUpdateTimestamp: result.lastUpdateTimestamp,\n };\n }\n\n /**\n * Gets the total number of staking entities in the protocol.\n *\n * @returns The count of entities\n *\n * @example\n * ```typescript\n * const count = await vana.staking.getEntitiesCount();\n * console.log(`Total entities: ${count}`);\n * ```\n */\n async getEntitiesCount(): Promise<bigint> {\n const entityContract = this.getEntityContract();\n return entityContract.read.entitiesCount();\n }\n\n /**\n * Gets the IDs of all active staking entities.\n *\n * @returns Array of active entity IDs\n *\n * @example\n * ```typescript\n * const activeIds = await vana.staking.getActiveEntities();\n * console.log(`Active entities: ${activeIds.join(', ')}`);\n * ```\n */\n async getActiveEntities(): Promise<readonly bigint[]> {\n const entityContract = this.getEntityContract();\n return entityContract.read.activeEntitiesValues();\n }\n\n /**\n * Gets a staker's position in a specific entity.\n *\n * @param staker - The address of the staker\n * @param entityId - The ID of the entity\n * @returns The staker's position information\n *\n * @example\n * ```typescript\n * const position = await vana.staking.getStakerPosition(\n * '0x742d35...',\n * 1n\n * );\n * console.log(`Shares: ${position.shares}`);\n * console.log(`Rewards: ${position.realizedRewards}`);\n * ```\n */\n async getStakerPosition(\n staker: Address,\n entityId: bigint,\n ): Promise<StakerEntityInfo> {\n const stakingContract = this.getStakingContract();\n\n const result = await stakingContract.read.stakerEntities([\n staker,\n entityId,\n ]);\n\n return {\n shares: result.shares,\n costBasis: result.costBasis,\n rewardEligibilityTimestamp: result.rewardEligibilityTimestamp,\n realizedRewards: result.realizedRewards,\n vestedRewards: result.vestedRewards,\n };\n }\n\n /**\n * Gets the earned rewards for a staker in an entity.\n *\n * @param staker - The address of the staker\n * @param entityId - The ID of the entity\n * @returns The earned rewards amount in wei\n *\n * @example\n * ```typescript\n * const rewards = await vana.staking.getEarnedRewards(\n * '0x742d35...',\n * 1n\n * );\n * console.log(`Earned: ${Number(rewards) / 1e18} VANA`);\n * ```\n */\n async getEarnedRewards(staker: Address, entityId: bigint): Promise<bigint> {\n const stakingContract = this.getStakingContract();\n return stakingContract.read.getEarnedRewards([staker, entityId]);\n }\n\n /**\n * Gets the minimum stake amount required to stake.\n *\n * @returns The minimum stake amount in wei\n *\n * @example\n * ```typescript\n * const minStake = await vana.staking.getMinStakeAmount();\n * console.log(`Minimum stake: ${Number(minStake) / 1e18} VANA`);\n * ```\n */\n async getMinStakeAmount(): Promise<bigint> {\n const stakingContract = this.getStakingContract();\n return stakingContract.read.minStakeAmount();\n }\n\n /**\n * Gets the count of active stakers in the protocol.\n *\n * @returns The number of active stakers\n *\n * @example\n * ```typescript\n * const count = await vana.staking.getActiveStakersCount();\n * console.log(`Active stakers: ${count}`);\n * ```\n */\n async getActiveStakersCount(): Promise<bigint> {\n const stakingContract = this.getStakingContract();\n return stakingContract.read.activeStakersListCount();\n }\n\n /**\n * Gets the bonding period for staking.\n *\n * @returns The bonding period in seconds\n *\n * @example\n * ```typescript\n * const bondingPeriod = await vana.staking.getBondingPeriod();\n * console.log(`Bonding period: ${bondingPeriod / 86400n} days`);\n * ```\n */\n async getBondingPeriod(): Promise<bigint> {\n const stakingContract = this.getStakingContract();\n return stakingContract.read.bondingPeriod();\n }\n\n /**\n * Gets the total distributed rewards for a specific entity from the subgraph.\n *\n * @remarks\n * This queries the VanaPool subgraph to retrieve the cumulative `totalDistributedRewards`\n * for a staking entity. This value represents the sum of all rewards that have been\n * processed (moved from lockedRewardPool to activeRewardPool) minus any forfeited\n * rewards that were returned.\n *\n * Requires a configured `subgraphUrl` in the Vana constructor options.\n *\n * @param entityId - The ID of the entity to query\n * @param options - Optional configuration including custom subgraph URL\n * @returns The total distributed rewards in wei\n * @throws {BlockchainError} When subgraph URL is not configured or query fails\n *\n * @example\n * ```typescript\n * const totalRewards = await vana.staking.getTotalDistributedRewards(1n);\n * const totalRewardsVana = Number(totalRewards) / 1e18;\n * console.log(`Total distributed rewards: ${totalRewardsVana.toLocaleString()} VANA`);\n * ```\n */\n async getTotalDistributedRewards(\n entityId: bigint,\n options: { subgraphUrl?: string } = {},\n ): Promise<bigint> {\n const graphqlEndpoint = options.subgraphUrl ?? this.context.subgraphUrl;\n\n if (!graphqlEndpoint) {\n throw new BlockchainError(\n \"subgraphUrl is required. Please provide a valid subgraph endpoint or configure it in Vana constructor.\",\n );\n }\n\n const query = `\n query GetStakingEntityRewards($entityId: ID!) {\n stakingEntity(id: $entityId) {\n totalDistributedRewards\n }\n }\n `;\n\n const response = await fetch(graphqlEndpoint, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n query,\n variables: {\n entityId: entityId.toString(),\n },\n }),\n });\n\n if (!response.ok) {\n throw new BlockchainError(\n `Subgraph query failed with status ${response.status}`,\n );\n }\n\n const result = (await response.json()) as {\n data?: { stakingEntity?: { totalDistributedRewards: string } };\n errors?: Array<{ message: string }>;\n };\n\n if (result.errors && result.errors.length > 0) {\n throw new BlockchainError(\n `Subgraph query error: ${result.errors[0].message}`,\n );\n }\n\n if (!result.data?.stakingEntity) {\n throw new BlockchainError(`Staking entity ${entityId} not found`);\n }\n\n return BigInt(result.data.stakingEntity.totalDistributedRewards);\n }\n\n /**\n * Gets a comprehensive staking summary for a staker in an entity.\n *\n * @remarks\n * This method aggregates all relevant staking information for a staker in a single call,\n * including staked amount, current value, bonding status, and all reward types.\n *\n * Reward breakdown:\n * - `earnedRewards` = pendingInterest + vestedRewards + realizedRewards\n * - `pendingInterest` = currentValue - costBasis (unvested appreciation)\n * - `vestedRewards` = rewards that have vested but not yet withdrawn\n * - `realizedRewards` = rewards already withdrawn during unstakes\n *\n * @param staker - The address of the staker\n * @param entityId - The ID of the entity\n * @returns A comprehensive summary of the staker's position\n *\n * @example\n * ```typescript\n * const summary = await vana.staking.getStakerSummary('0x742d35...', 1n);\n * console.log(`Total staked: ${Number(summary.totalStaked) / 1e18} VANA`);\n * console.log(`Current value: ${Number(summary.currentValue) / 1e18} VANA`);\n * console.log(`In bonding period: ${summary.isInBondingPeriod}`);\n * console.log(`Remaining bonding time: ${Number(summary.remainingBondingTime) / 86400} days`);\n * console.log(`Vested rewards: ${Number(summary.vestedRewards) / 1e18} VANA`);\n * console.log(`Unvested rewards: ${Number(summary.unvestedRewards) / 1e18} VANA`);\n * console.log(`Realized rewards: ${Number(summary.realizedRewards) / 1e18} VANA`);\n * console.log(`Total earned: ${Number(summary.earnedRewards) / 1e18} VANA`);\n * ```\n */\n async getStakerSummary(\n staker: Address,\n entityId: bigint,\n ): Promise<StakerEntitySummary> {\n const chainId = this.getChainId();\n const stakingAddress = getContractAddress(chainId, \"VanaPoolStaking\");\n const entityAddress = getContractAddress(chainId, \"VanaPoolEntity\");\n const stakingAbi = getAbi(\"VanaPoolStaking\");\n const entityAbi = getAbi(\"VanaPoolEntity\");\n\n // Get latest block first to ensure all reads are from the same block\n const block = await this.context.publicClient.getBlock();\n const blockNumber = block.number;\n\n // Batch all contract reads into a single multicall RPC request at the same block\n const multicallResults = await this.context.publicClient.multicall({\n contracts: [\n {\n address: stakingAddress,\n abi: stakingAbi,\n functionName: \"stakerEntities\",\n args: [staker, entityId],\n },\n {\n address: stakingAddress,\n abi: stakingAbi,\n functionName: \"getEarnedRewards\",\n args: [staker, entityId],\n },\n {\n address: entityAddress,\n abi: entityAbi,\n functionName: \"entityShareToVana\",\n args: [entityId],\n },\n ],\n blockNumber,\n });\n\n const [positionResult, earnedRewardsResult, shareToVanaResult] =\n multicallResults;\n\n if (\n positionResult.status === \"failure\" ||\n earnedRewardsResult.status === \"failure\" ||\n shareToVanaResult.status === \"failure\"\n ) {\n throw new BlockchainError(\n \"Failed to fetch staker summary: one or more contract calls failed\",\n );\n }\n\n const position = positionResult.result as {\n shares: bigint;\n costBasis: bigint;\n rewardEligibilityTimestamp: bigint;\n realizedRewards: bigint;\n vestedRewards: bigint;\n };\n const earnedRewards = earnedRewardsResult.result as bigint;\n const shareToVana = shareToVanaResult.result as bigint;\n const currentTimestamp = block.timestamp;\n\n // Calculate remaining bonding time\n const eligibilityTimestamp = position.rewardEligibilityTimestamp;\n const remainingBondingTime =\n eligibilityTimestamp > currentTimestamp\n ? eligibilityTimestamp - currentTimestamp\n : 0n;\n const isInBondingPeriod = remainingBondingTime > 0n;\n\n // Calculate current value of shares\n // entityShareToVana returns the VANA value of 1 share (scaled by 1e18)\n const currentValue = (position.shares * shareToVana) / 10n ** 18n;\n\n // Calculate pending interest (unvested rewards)\n // pendingInterest = currentValue - costBasis (if positive)\n const unvestedRewards =\n currentValue > position.costBasis\n ? currentValue - position.costBasis\n : 0n;\n\n return {\n shares: position.shares,\n costBasis: position.costBasis,\n currentValue,\n rewardEligibilityTimestamp: eligibilityTimestamp,\n remainingBondingTime,\n isInBondingPeriod,\n vestedRewards: position.vestedRewards,\n unvestedRewards,\n realizedRewards: position.realizedRewards,\n earnedRewards,\n };\n }\n\n /**\n * Stakes VANA to an entity in the VanaPool protocol.\n *\n * @remarks\n * This method stakes native VANA tokens to a specified entity. The staker will receive\n * shares in proportion to their stake amount. A bonding period applies during which\n * rewards cannot be fully claimed without penalty.\n *\n * Requires a wallet client to be configured in the Vana constructor.\n *\n * @param params - The staking parameters\n * @param params.entityId - The ID of the entity to stake to\n * @param params.amount - The amount of VANA to stake (in wei, or as a string like \"1.5\" for 1.5 VANA)\n * @param params.recipient - Optional recipient address for the shares (defaults to the sender)\n * @param params.minShares - Optional minimum shares to receive (slippage protection, defaults to 0)\n * @returns The transaction hash\n * @throws {BlockchainError} When wallet client is not configured\n *\n * @example\n * ```typescript\n * // Stake 100 VANA to entity 1\n * const txHash = await vana.staking.stake({\n * entityId: 1n,\n * amount: \"100\", // 100 VANA\n * });\n * console.log(`Staked! Transaction: ${txHash}`);\n *\n * // Stake with slippage protection\n * const txHash2 = await vana.staking.stake({\n * entityId: 1n,\n * amount: parseEther(\"50\"), // 50 VANA in wei\n * minShares: parseEther(\"49\"), // Expect at least 49 shares\n * });\n * ```\n */\n async stake(\n params: {\n entityId: bigint;\n amount: bigint | string;\n recipient?: Address;\n minShares?: bigint;\n },\n options?: TransactionOptions,\n ): Promise<Hash> {\n this.assertWallet();\n\n const chainId = this.getChainId();\n const stakingAddress = getContractAddress(chainId, \"VanaPoolStaking\");\n const stakingAbi = getAbi(\"VanaPoolStaking\");\n\n // Convert amount to bigint if it's a string (e.g., \"1.5\" -> 1.5 VANA in wei)\n const amountWei =\n typeof params.amount === \"string\"\n ? parseEther(params.amount)\n : params.amount;\n\n // Get account with fallback to userAddress\n const account =\n this.context.walletClient.account ?? this.context.userAddress;\n const accountAddress =\n typeof account === \"string\" ? account : account.address;\n\n // Default recipient to the sender's address\n const recipient = params.recipient ?? accountAddress;\n\n // Default minShares to 0 (no slippage protection)\n const minShares = params.minShares ?? 0n;\n\n const txHash = await this.context.walletClient.writeContract({\n address: stakingAddress,\n abi: stakingAbi,\n functionName: \"stake\",\n args: [params.entityId, recipient, minShares],\n value: amountWei,\n account,\n chain: this.context.walletClient.chain,\n ...this.spreadTransactionOptions(options),\n });\n\n return txHash;\n }\n\n /**\n * Gets the maximum amount of VANA that can be unstaked in a single transaction.\n *\n * @remarks\n * This calls the contract's getMaxUnstakeAmount which returns the minimum of:\n * 1. The withdrawable VANA (costBasis if in bonding period, shareValue if eligible)\n * 2. The entity's activeRewardPool (what the entity has available)\n * 3. The treasury balance (what can be paid out)\n *\n * The limiting factor indicates what's constraining the unstake:\n * - 0 = user shares/costBasis\n * - 1 = activeRewardPool\n * - 2 = treasury\n *\n * @param staker - The address of the staker\n * @param entityId - The ID of the entity\n * @returns Object containing maxVana, maxShares, limitingFactor, and isInBondingPeriod\n *\n * @example\n * ```typescript\n * const result = await vana.staking.getMaxUnstakeAmount('0x742d35...', 1n);\n * console.log(`Max unstake: ${Number(result.maxVana) / 1e18} VANA`);\n * console.log(`Max shares: ${result.maxShares}`);\n * console.log(`In bonding period: ${result.isInBondingPeriod}`);\n * ```\n */\n async getMaxUnstakeAmount(\n staker: Address,\n entityId: bigint,\n ): Promise<{\n maxVana: bigint;\n maxShares: bigint;\n limitingFactor: number;\n isInBondingPeriod: boolean;\n }> {\n const stakingContract = this.getStakingContract();\n\n const result = await stakingContract.read.getMaxUnstakeAmount([\n staker,\n entityId,\n ]);\n\n return {\n maxVana: result[0],\n maxShares: result[1],\n limitingFactor: Number(result[2]),\n isInBondingPeriod: result[3],\n };\n }\n\n /**\n * Unstakes VANA from an entity in the VanaPool protocol.\n *\n * @remarks\n * This method unstakes native VANA tokens from a specified entity. The amount\n * that can be unstaked depends on whether the staker is in the bonding period:\n *\n * - **During bonding period**: Only cost basis can be withdrawn; rewards are forfeited\n * - **After bonding period**: Full current value (cost basis + rewards) can be withdrawn\n *\n * Use `getMaxUnstakeAmount` to determine the maximum amount that can be unstaked.\n *\n * Requires a wallet client to be configured in the Vana constructor.\n *\n * @param params - The unstaking parameters\n * @param params.entityId - The ID of the entity to unstake from\n * @param params.amount - The amount of VANA to unstake (in wei, or as a string like \"1.5\" for 1.5 VANA)\n * @param params.maxShares - Maximum shares to burn for slippage protection (defaults to 0, no protection)\n * @returns The transaction hash\n * @throws {BlockchainError} When wallet client is not configured\n *\n * @example\n * ```typescript\n * // Get max unstake amount first\n * const maxUnstake = await vana.staking.getMaxUnstakeAmount(address, 1n);\n *\n * // Unstake the maximum amount with slippage protection\n * const txHash = await vana.staking.unstake({\n * entityId: 1n,\n * amount: maxUnstake.maxVana,\n * maxShares: maxUnstake.maxShares,\n * });\n * console.log(`Unstaked! Transaction: ${txHash}`);\n * ```\n */\n async unstake(\n params: {\n entityId: bigint;\n amount: bigint | string;\n maxShares?: bigint;\n },\n options?: TransactionOptions,\n ): Promise<Hash> {\n this.assertWallet();\n\n const chainId = this.getChainId();\n const stakingAddress = getContractAddress(chainId, \"VanaPoolStaking\");\n const stakingAbi = getAbi(\"VanaPoolStaking\");\n\n // Convert amount to bigint if it's a string (e.g., \"1.5\" -> 1.5 VANA in wei)\n const amountWei =\n typeof params.amount === \"string\"\n ? parseEther(params.amount)\n : params.amount;\n\n // Default maxShares to 0 (no slippage protection)\n const maxShares = params.maxShares ?? 0n;\n\n // Get account with fallback to userAddress\n const account =\n this.context.walletClient.account ?? this.context.userAddress;\n\n const txHash = await this.context.walletClient.writeContract({\n address: stakingAddress,\n abi: stakingAbi,\n functionName: \"unstakeVana\",\n args: [params.entityId, amountWei, maxShares],\n account,\n chain: this.context.walletClient.chain,\n ...this.spreadTransactionOptions(options),\n });\n\n return txHash;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAcA,kBAA+B;AAC/B,kBAAwC;AAExC,uBAAmC;AACnC,iBAAuB;AACvB,oBAAgC;AA2EzB,MAAM,0BAA0B,2BAAe;AAAA,EACpD,YAAY,SAA4B;AACtC,UAAM,OAAO;AAAA,EACf;AAAA;AAAA;AAAA;AAAA,EAKQ,aAAqB;AAC3B,UAAM,UACJ,KAAK,QAAQ,cAAc,OAAO,MAClC,KAAK,QAAQ,aAAa,OAAO;AACnC,QAAI,CAAC,SAAS;AACZ,YAAM,IAAI,MAAM,wBAAwB;AAAA,IAC1C;AACA,WAAO;AAAA,EAC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;AACpE,UAAM,iBAAa,mBAAO,iBAAiB;AAG3C,UAAM,YACJ,OAAO,OAAO,WAAW,eACrB,wBAAW,OAAO,MAAM,IACxB,OAAO;AAGb,UAAM,YAAY,OAAO,aAAa;AAGtC,UAAM,UACJ,KAAK,QAAQ,aAAa,WAAW,KAAK,QAAQ;AAEpD,UAAM,SAAS,MAAM,KAAK,QAAQ,aAAa,cAAc;AAAA,MAC3D,SAAS;AAAA,MACT,KAAK;AAAA,MACL,cAAc;AAAA,MACd,MAAM,CAAC,OAAO,UAAU,WAAW,SAAS;AAAA,MAC5C;AAAA,MACA,OAAO,KAAK,QAAQ,aAAa;AAAA,MACjC,GAAG,KAAK,yBAAyB,OAAO;AAAA,IAC1C,CAAC;AAED,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -327,22 +327,49 @@ class StakingController extends BaseController {
327
327
  * ```
328
328
  */
329
329
  async getStakerSummary(staker, entityId) {
330
- const stakingContract = this.getStakingContract();
331
- const entityContract = this.getEntityContract();
332
- const position = await stakingContract.read.stakerEntities([
333
- staker,
334
- entityId
335
- ]);
336
- const earnedRewards = await stakingContract.read.getEarnedRewards([
337
- staker,
338
- entityId
339
- ]);
330
+ const chainId = this.getChainId();
331
+ const stakingAddress = getContractAddress(chainId, "VanaPoolStaking");
332
+ const entityAddress = getContractAddress(chainId, "VanaPoolEntity");
333
+ const stakingAbi = getAbi("VanaPoolStaking");
334
+ const entityAbi = getAbi("VanaPoolEntity");
340
335
  const block = await this.context.publicClient.getBlock();
336
+ const blockNumber = block.number;
337
+ const multicallResults = await this.context.publicClient.multicall({
338
+ contracts: [
339
+ {
340
+ address: stakingAddress,
341
+ abi: stakingAbi,
342
+ functionName: "stakerEntities",
343
+ args: [staker, entityId]
344
+ },
345
+ {
346
+ address: stakingAddress,
347
+ abi: stakingAbi,
348
+ functionName: "getEarnedRewards",
349
+ args: [staker, entityId]
350
+ },
351
+ {
352
+ address: entityAddress,
353
+ abi: entityAbi,
354
+ functionName: "entityShareToVana",
355
+ args: [entityId]
356
+ }
357
+ ],
358
+ blockNumber
359
+ });
360
+ const [positionResult, earnedRewardsResult, shareToVanaResult] = multicallResults;
361
+ if (positionResult.status === "failure" || earnedRewardsResult.status === "failure" || shareToVanaResult.status === "failure") {
362
+ throw new BlockchainError(
363
+ "Failed to fetch staker summary: one or more contract calls failed"
364
+ );
365
+ }
366
+ const position = positionResult.result;
367
+ const earnedRewards = earnedRewardsResult.result;
368
+ const shareToVana = shareToVanaResult.result;
341
369
  const currentTimestamp = block.timestamp;
342
370
  const eligibilityTimestamp = position.rewardEligibilityTimestamp;
343
371
  const remainingBondingTime = eligibilityTimestamp > currentTimestamp ? eligibilityTimestamp - currentTimestamp : 0n;
344
372
  const isInBondingPeriod = remainingBondingTime > 0n;
345
- const shareToVana = await entityContract.read.entityShareToVana([entityId]);
346
373
  const currentValue = position.shares * shareToVana / 10n ** 18n;
347
374
  const unvestedRewards = currentValue > position.costBasis ? currentValue - position.costBasis : 0n;
348
375
  return {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/controllers/staking.ts"],"sourcesContent":["/**\n * Provides staking functionality for the VanaPool protocol.\n *\n * @remarks\n * This controller handles interactions with VanaPool staking contracts,\n * allowing users to query staking information such as total VANA staked,\n * entity information, and staker positions.\n *\n * @category Controllers\n * @module StakingController\n */\n\nimport type { ControllerContext } from \"../types/controller-context\";\nimport type { TransactionOptions } from \"../types/operations\";\nimport { BaseController } from \"./base\";\nimport { getContract, parseEther } from \"viem\";\nimport type { Address, Hash } from \"viem\";\nimport { getContractAddress } from \"../generated/addresses\";\nimport { getAbi } from \"../generated/abi\";\nimport { BlockchainError } from \"../errors\";\n\n/**\n * Information about a staking entity in the VanaPool protocol.\n */\nexport interface EntityInfo {\n entityId: bigint;\n ownerAddress: Address;\n status: number;\n name: string;\n maxAPY: bigint;\n lockedRewardPool: bigint;\n activeRewardPool: bigint;\n totalShares: bigint;\n lastUpdateTimestamp: bigint;\n}\n\n/**\n * Information about a staker's position in an entity.\n */\nexport interface StakerEntityInfo {\n shares: bigint;\n costBasis: bigint;\n rewardEligibilityTimestamp: bigint;\n realizedRewards: bigint;\n vestedRewards: bigint;\n}\n\n/**\n * Comprehensive staking summary for a staker in an entity.\n */\nexport interface StakerEntitySummary {\n /** Number of shares owned by the staker */\n shares: bigint;\n /** Cost basis - the original VANA amount staked */\n costBasis: bigint;\n /** Current value of the staker's shares in VANA */\n currentValue: bigint;\n /** Timestamp when rewards become eligible */\n rewardEligibilityTimestamp: bigint;\n /** Remaining bonding time in seconds (0 if bonding period has passed) */\n remainingBondingTime: bigint;\n /** Whether the staker is still in the bonding period */\n isInBondingPeriod: boolean;\n /** Vested rewards that can be claimed without penalty */\n vestedRewards: bigint;\n /** Unvested rewards (pending interest = currentValue - costBasis) */\n unvestedRewards: bigint;\n /** Realized/withdrawn rewards (already claimed) */\n realizedRewards: bigint;\n /** Total earned rewards (includes vested, unvested, and realized) */\n earnedRewards: bigint;\n}\n\n/**\n * Controller for VanaPool staking operations.\n *\n * @remarks\n * Provides methods to query staking information from the VanaPool contracts.\n * This includes total VANA staked across the protocol, entity information,\n * and individual staker positions.\n *\n * @example\n * ```typescript\n * // Get total VANA staked in the protocol\n * const totalStaked = await vana.staking.getTotalVanaStaked();\n * console.log(`Total staked: ${totalStaked} wei`);\n *\n * // Get entity information\n * const entity = await vana.staking.getEntity(1n);\n * console.log(`Entity name: ${entity.name}`);\n * ```\n *\n * @category Controllers\n */\nexport class StakingController extends BaseController {\n constructor(context: ControllerContext) {\n super(context);\n }\n\n /**\n * Gets the chain ID from context.\n */\n private getChainId(): number {\n const chainId =\n this.context.walletClient?.chain?.id ??\n this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n return chainId;\n }\n\n /**\n * Gets the VanaPoolEntity contract instance.\n */\n private getEntityContract() {\n const chainId = this.getChainId();\n return getContract({\n address: getContractAddress(chainId, \"VanaPoolEntity\"),\n abi: getAbi(\"VanaPoolEntity\"),\n client: this.context.publicClient,\n });\n }\n\n /**\n * Gets the VanaPoolStaking contract instance.\n */\n private getStakingContract() {\n const chainId = this.getChainId();\n return getContract({\n address: getContractAddress(chainId, \"VanaPoolStaking\"),\n abi: getAbi(\"VanaPoolStaking\"),\n client: this.context.publicClient,\n });\n }\n\n /**\n * Gets the total amount of VANA staked in the VanaPool protocol or a specific entity.\n *\n * @remarks\n * When called without an entityId, this retrieves the sum of activeRewardPool\n * across all active entities in the VanaPool protocol.\n * When called with an entityId, this returns the activeRewardPool for that specific entity.\n * The value is returned in wei (10^18 = 1 VANA).\n *\n * @param entityId - Optional entity ID to get staked amount for a specific entity\n * @returns The total amount of VANA staked in wei\n *\n * @example\n * ```typescript\n * // Get total staked across all entities\n * const totalStaked = await vana.staking.getTotalVanaStaked();\n * console.log(`Total staked: ${Number(totalStaked) / 1e18} VANA`);\n *\n * // Get staked amount for a specific entity\n * const entityStaked = await vana.staking.getTotalVanaStaked(1n);\n * console.log(`Entity 1 staked: ${Number(entityStaked) / 1e18} VANA`);\n * ```\n */\n async getTotalVanaStaked(entityId?: bigint): Promise<bigint> {\n const entityContract = this.getEntityContract();\n\n // If entityId is provided, return the activeRewardPool for that specific entity\n if (entityId !== undefined) {\n const entity = await entityContract.read.entities([entityId]);\n return entity.activeRewardPool;\n }\n\n // Otherwise, sum up the activeRewardPool from all active entities\n const activeEntityIds = await entityContract.read.activeEntitiesValues();\n\n let totalStaked = 0n;\n for (const id of activeEntityIds) {\n const entity = await entityContract.read.entities([id]);\n totalStaked += entity.activeRewardPool;\n }\n\n return totalStaked;\n }\n\n /**\n * Gets information about a specific staking entity.\n *\n * @param entityId - The ID of the entity to query\n * @returns The entity information including name, APY, shares, and reward pools\n *\n * @example\n * ```typescript\n * const entity = await vana.staking.getEntity(1n);\n * console.log(`Entity: ${entity.name}`);\n * console.log(`Total shares: ${entity.totalShares}`);\n * console.log(`Max APY: ${Number(entity.maxAPY) / 100}%`);\n * ```\n */\n async getEntity(entityId: bigint): Promise<EntityInfo> {\n const entityContract = this.getEntityContract();\n\n const result = await entityContract.read.entities([entityId]);\n\n return {\n entityId: result.entityId,\n ownerAddress: result.ownerAddress as Address,\n status: result.status,\n name: result.name,\n maxAPY: result.maxAPY,\n lockedRewardPool: result.lockedRewardPool,\n activeRewardPool: result.activeRewardPool,\n totalShares: result.totalShares,\n lastUpdateTimestamp: result.lastUpdateTimestamp,\n };\n }\n\n /**\n * Gets the total number of staking entities in the protocol.\n *\n * @returns The count of entities\n *\n * @example\n * ```typescript\n * const count = await vana.staking.getEntitiesCount();\n * console.log(`Total entities: ${count}`);\n * ```\n */\n async getEntitiesCount(): Promise<bigint> {\n const entityContract = this.getEntityContract();\n return entityContract.read.entitiesCount();\n }\n\n /**\n * Gets the IDs of all active staking entities.\n *\n * @returns Array of active entity IDs\n *\n * @example\n * ```typescript\n * const activeIds = await vana.staking.getActiveEntities();\n * console.log(`Active entities: ${activeIds.join(', ')}`);\n * ```\n */\n async getActiveEntities(): Promise<readonly bigint[]> {\n const entityContract = this.getEntityContract();\n return entityContract.read.activeEntitiesValues();\n }\n\n /**\n * Gets a staker's position in a specific entity.\n *\n * @param staker - The address of the staker\n * @param entityId - The ID of the entity\n * @returns The staker's position information\n *\n * @example\n * ```typescript\n * const position = await vana.staking.getStakerPosition(\n * '0x742d35...',\n * 1n\n * );\n * console.log(`Shares: ${position.shares}`);\n * console.log(`Rewards: ${position.realizedRewards}`);\n * ```\n */\n async getStakerPosition(\n staker: Address,\n entityId: bigint,\n ): Promise<StakerEntityInfo> {\n const stakingContract = this.getStakingContract();\n\n const result = await stakingContract.read.stakerEntities([\n staker,\n entityId,\n ]);\n\n return {\n shares: result.shares,\n costBasis: result.costBasis,\n rewardEligibilityTimestamp: result.rewardEligibilityTimestamp,\n realizedRewards: result.realizedRewards,\n vestedRewards: result.vestedRewards,\n };\n }\n\n /**\n * Gets the earned rewards for a staker in an entity.\n *\n * @param staker - The address of the staker\n * @param entityId - The ID of the entity\n * @returns The earned rewards amount in wei\n *\n * @example\n * ```typescript\n * const rewards = await vana.staking.getEarnedRewards(\n * '0x742d35...',\n * 1n\n * );\n * console.log(`Earned: ${Number(rewards) / 1e18} VANA`);\n * ```\n */\n async getEarnedRewards(staker: Address, entityId: bigint): Promise<bigint> {\n const stakingContract = this.getStakingContract();\n return stakingContract.read.getEarnedRewards([staker, entityId]);\n }\n\n /**\n * Gets the minimum stake amount required to stake.\n *\n * @returns The minimum stake amount in wei\n *\n * @example\n * ```typescript\n * const minStake = await vana.staking.getMinStakeAmount();\n * console.log(`Minimum stake: ${Number(minStake) / 1e18} VANA`);\n * ```\n */\n async getMinStakeAmount(): Promise<bigint> {\n const stakingContract = this.getStakingContract();\n return stakingContract.read.minStakeAmount();\n }\n\n /**\n * Gets the count of active stakers in the protocol.\n *\n * @returns The number of active stakers\n *\n * @example\n * ```typescript\n * const count = await vana.staking.getActiveStakersCount();\n * console.log(`Active stakers: ${count}`);\n * ```\n */\n async getActiveStakersCount(): Promise<bigint> {\n const stakingContract = this.getStakingContract();\n return stakingContract.read.activeStakersListCount();\n }\n\n /**\n * Gets the bonding period for staking.\n *\n * @returns The bonding period in seconds\n *\n * @example\n * ```typescript\n * const bondingPeriod = await vana.staking.getBondingPeriod();\n * console.log(`Bonding period: ${bondingPeriod / 86400n} days`);\n * ```\n */\n async getBondingPeriod(): Promise<bigint> {\n const stakingContract = this.getStakingContract();\n return stakingContract.read.bondingPeriod();\n }\n\n /**\n * Gets the total distributed rewards for a specific entity from the subgraph.\n *\n * @remarks\n * This queries the VanaPool subgraph to retrieve the cumulative `totalDistributedRewards`\n * for a staking entity. This value represents the sum of all rewards that have been\n * processed (moved from lockedRewardPool to activeRewardPool) minus any forfeited\n * rewards that were returned.\n *\n * Requires a configured `subgraphUrl` in the Vana constructor options.\n *\n * @param entityId - The ID of the entity to query\n * @param options - Optional configuration including custom subgraph URL\n * @returns The total distributed rewards in wei\n * @throws {BlockchainError} When subgraph URL is not configured or query fails\n *\n * @example\n * ```typescript\n * const totalRewards = await vana.staking.getTotalDistributedRewards(1n);\n * const totalRewardsVana = Number(totalRewards) / 1e18;\n * console.log(`Total distributed rewards: ${totalRewardsVana.toLocaleString()} VANA`);\n * ```\n */\n async getTotalDistributedRewards(\n entityId: bigint,\n options: { subgraphUrl?: string } = {},\n ): Promise<bigint> {\n const graphqlEndpoint = options.subgraphUrl ?? this.context.subgraphUrl;\n\n if (!graphqlEndpoint) {\n throw new BlockchainError(\n \"subgraphUrl is required. Please provide a valid subgraph endpoint or configure it in Vana constructor.\",\n );\n }\n\n const query = `\n query GetStakingEntityRewards($entityId: ID!) {\n stakingEntity(id: $entityId) {\n totalDistributedRewards\n }\n }\n `;\n\n const response = await fetch(graphqlEndpoint, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n query,\n variables: {\n entityId: entityId.toString(),\n },\n }),\n });\n\n if (!response.ok) {\n throw new BlockchainError(\n `Subgraph query failed with status ${response.status}`,\n );\n }\n\n const result = (await response.json()) as {\n data?: { stakingEntity?: { totalDistributedRewards: string } };\n errors?: Array<{ message: string }>;\n };\n\n if (result.errors && result.errors.length > 0) {\n throw new BlockchainError(\n `Subgraph query error: ${result.errors[0].message}`,\n );\n }\n\n if (!result.data?.stakingEntity) {\n throw new BlockchainError(`Staking entity ${entityId} not found`);\n }\n\n return BigInt(result.data.stakingEntity.totalDistributedRewards);\n }\n\n /**\n * Gets a comprehensive staking summary for a staker in an entity.\n *\n * @remarks\n * This method aggregates all relevant staking information for a staker in a single call,\n * including staked amount, current value, bonding status, and all reward types.\n *\n * Reward breakdown:\n * - `earnedRewards` = pendingInterest + vestedRewards + realizedRewards\n * - `pendingInterest` = currentValue - costBasis (unvested appreciation)\n * - `vestedRewards` = rewards that have vested but not yet withdrawn\n * - `realizedRewards` = rewards already withdrawn during unstakes\n *\n * @param staker - The address of the staker\n * @param entityId - The ID of the entity\n * @returns A comprehensive summary of the staker's position\n *\n * @example\n * ```typescript\n * const summary = await vana.staking.getStakerSummary('0x742d35...', 1n);\n * console.log(`Total staked: ${Number(summary.totalStaked) / 1e18} VANA`);\n * console.log(`Current value: ${Number(summary.currentValue) / 1e18} VANA`);\n * console.log(`In bonding period: ${summary.isInBondingPeriod}`);\n * console.log(`Remaining bonding time: ${Number(summary.remainingBondingTime) / 86400} days`);\n * console.log(`Vested rewards: ${Number(summary.vestedRewards) / 1e18} VANA`);\n * console.log(`Unvested rewards: ${Number(summary.unvestedRewards) / 1e18} VANA`);\n * console.log(`Realized rewards: ${Number(summary.realizedRewards) / 1e18} VANA`);\n * console.log(`Total earned: ${Number(summary.earnedRewards) / 1e18} VANA`);\n * ```\n */\n async getStakerSummary(\n staker: Address,\n entityId: bigint,\n ): Promise<StakerEntitySummary> {\n const stakingContract = this.getStakingContract();\n const entityContract = this.getEntityContract();\n\n // Get staker's position data\n const position = await stakingContract.read.stakerEntities([\n staker,\n entityId,\n ]);\n\n // Get earned rewards from contract\n const earnedRewards = await stakingContract.read.getEarnedRewards([\n staker,\n entityId,\n ]);\n\n // Get current timestamp from the blockchain\n const block = await this.context.publicClient.getBlock();\n const currentTimestamp = block.timestamp;\n\n // Calculate remaining bonding time\n const eligibilityTimestamp = position.rewardEligibilityTimestamp;\n const remainingBondingTime =\n eligibilityTimestamp > currentTimestamp\n ? eligibilityTimestamp - currentTimestamp\n : 0n;\n const isInBondingPeriod = remainingBondingTime > 0n;\n\n // Calculate current value of shares\n // entityShareToVana returns the VANA value of 1 share (scaled by 1e18)\n const shareToVana = await entityContract.read.entityShareToVana([entityId]);\n const currentValue = (position.shares * shareToVana) / 10n ** 18n;\n\n // Calculate pending interest (unvested rewards)\n // pendingInterest = currentValue - costBasis (if positive)\n const unvestedRewards =\n currentValue > position.costBasis\n ? currentValue - position.costBasis\n : 0n;\n\n return {\n shares: position.shares,\n costBasis: position.costBasis,\n currentValue,\n rewardEligibilityTimestamp: eligibilityTimestamp,\n remainingBondingTime,\n isInBondingPeriod,\n vestedRewards: position.vestedRewards,\n unvestedRewards,\n realizedRewards: position.realizedRewards,\n earnedRewards,\n };\n }\n\n /**\n * Stakes VANA to an entity in the VanaPool protocol.\n *\n * @remarks\n * This method stakes native VANA tokens to a specified entity. The staker will receive\n * shares in proportion to their stake amount. A bonding period applies during which\n * rewards cannot be fully claimed without penalty.\n *\n * Requires a wallet client to be configured in the Vana constructor.\n *\n * @param params - The staking parameters\n * @param params.entityId - The ID of the entity to stake to\n * @param params.amount - The amount of VANA to stake (in wei, or as a string like \"1.5\" for 1.5 VANA)\n * @param params.recipient - Optional recipient address for the shares (defaults to the sender)\n * @param params.minShares - Optional minimum shares to receive (slippage protection, defaults to 0)\n * @returns The transaction hash\n * @throws {BlockchainError} When wallet client is not configured\n *\n * @example\n * ```typescript\n * // Stake 100 VANA to entity 1\n * const txHash = await vana.staking.stake({\n * entityId: 1n,\n * amount: \"100\", // 100 VANA\n * });\n * console.log(`Staked! Transaction: ${txHash}`);\n *\n * // Stake with slippage protection\n * const txHash2 = await vana.staking.stake({\n * entityId: 1n,\n * amount: parseEther(\"50\"), // 50 VANA in wei\n * minShares: parseEther(\"49\"), // Expect at least 49 shares\n * });\n * ```\n */\n async stake(\n params: {\n entityId: bigint;\n amount: bigint | string;\n recipient?: Address;\n minShares?: bigint;\n },\n options?: TransactionOptions,\n ): Promise<Hash> {\n this.assertWallet();\n\n const chainId = this.getChainId();\n const stakingAddress = getContractAddress(chainId, \"VanaPoolStaking\");\n const stakingAbi = getAbi(\"VanaPoolStaking\");\n\n // Convert amount to bigint if it's a string (e.g., \"1.5\" -> 1.5 VANA in wei)\n const amountWei =\n typeof params.amount === \"string\"\n ? parseEther(params.amount)\n : params.amount;\n\n // Get account with fallback to userAddress\n const account =\n this.context.walletClient.account ?? this.context.userAddress;\n const accountAddress =\n typeof account === \"string\" ? account : account.address;\n\n // Default recipient to the sender's address\n const recipient = params.recipient ?? accountAddress;\n\n // Default minShares to 0 (no slippage protection)\n const minShares = params.minShares ?? 0n;\n\n const txHash = await this.context.walletClient.writeContract({\n address: stakingAddress,\n abi: stakingAbi,\n functionName: \"stake\",\n args: [params.entityId, recipient, minShares],\n value: amountWei,\n account,\n chain: this.context.walletClient.chain,\n ...this.spreadTransactionOptions(options),\n });\n\n return txHash;\n }\n\n /**\n * Gets the maximum amount of VANA that can be unstaked in a single transaction.\n *\n * @remarks\n * This calls the contract's getMaxUnstakeAmount which returns the minimum of:\n * 1. The withdrawable VANA (costBasis if in bonding period, shareValue if eligible)\n * 2. The entity's activeRewardPool (what the entity has available)\n * 3. The treasury balance (what can be paid out)\n *\n * The limiting factor indicates what's constraining the unstake:\n * - 0 = user shares/costBasis\n * - 1 = activeRewardPool\n * - 2 = treasury\n *\n * @param staker - The address of the staker\n * @param entityId - The ID of the entity\n * @returns Object containing maxVana, maxShares, limitingFactor, and isInBondingPeriod\n *\n * @example\n * ```typescript\n * const result = await vana.staking.getMaxUnstakeAmount('0x742d35...', 1n);\n * console.log(`Max unstake: ${Number(result.maxVana) / 1e18} VANA`);\n * console.log(`Max shares: ${result.maxShares}`);\n * console.log(`In bonding period: ${result.isInBondingPeriod}`);\n * ```\n */\n async getMaxUnstakeAmount(\n staker: Address,\n entityId: bigint,\n ): Promise<{\n maxVana: bigint;\n maxShares: bigint;\n limitingFactor: number;\n isInBondingPeriod: boolean;\n }> {\n const stakingContract = this.getStakingContract();\n\n const result = await stakingContract.read.getMaxUnstakeAmount([\n staker,\n entityId,\n ]);\n\n return {\n maxVana: result[0],\n maxShares: result[1],\n limitingFactor: Number(result[2]),\n isInBondingPeriod: result[3],\n };\n }\n\n /**\n * Unstakes VANA from an entity in the VanaPool protocol.\n *\n * @remarks\n * This method unstakes native VANA tokens from a specified entity. The amount\n * that can be unstaked depends on whether the staker is in the bonding period:\n *\n * - **During bonding period**: Only cost basis can be withdrawn; rewards are forfeited\n * - **After bonding period**: Full current value (cost basis + rewards) can be withdrawn\n *\n * Use `getMaxUnstakeAmount` to determine the maximum amount that can be unstaked.\n *\n * Requires a wallet client to be configured in the Vana constructor.\n *\n * @param params - The unstaking parameters\n * @param params.entityId - The ID of the entity to unstake from\n * @param params.amount - The amount of VANA to unstake (in wei, or as a string like \"1.5\" for 1.5 VANA)\n * @param params.maxShares - Maximum shares to burn for slippage protection (defaults to 0, no protection)\n * @returns The transaction hash\n * @throws {BlockchainError} When wallet client is not configured\n *\n * @example\n * ```typescript\n * // Get max unstake amount first\n * const maxUnstake = await vana.staking.getMaxUnstakeAmount(address, 1n);\n *\n * // Unstake the maximum amount with slippage protection\n * const txHash = await vana.staking.unstake({\n * entityId: 1n,\n * amount: maxUnstake.maxVana,\n * maxShares: maxUnstake.maxShares,\n * });\n * console.log(`Unstaked! Transaction: ${txHash}`);\n * ```\n */\n async unstake(\n params: {\n entityId: bigint;\n amount: bigint | string;\n maxShares?: bigint;\n },\n options?: TransactionOptions,\n ): Promise<Hash> {\n this.assertWallet();\n\n const chainId = this.getChainId();\n const stakingAddress = getContractAddress(chainId, \"VanaPoolStaking\");\n const stakingAbi = getAbi(\"VanaPoolStaking\");\n\n // Convert amount to bigint if it's a string (e.g., \"1.5\" -> 1.5 VANA in wei)\n const amountWei =\n typeof params.amount === \"string\"\n ? parseEther(params.amount)\n : params.amount;\n\n // Default maxShares to 0 (no slippage protection)\n const maxShares = params.maxShares ?? 0n;\n\n // Get account with fallback to userAddress\n const account =\n this.context.walletClient.account ?? this.context.userAddress;\n\n const txHash = await this.context.walletClient.writeContract({\n address: stakingAddress,\n abi: stakingAbi,\n functionName: \"unstakeVana\",\n args: [params.entityId, amountWei, maxShares],\n account,\n chain: this.context.walletClient.chain,\n ...this.spreadTransactionOptions(options),\n });\n\n return txHash;\n }\n}\n"],"mappings":"AAcA,SAAS,sBAAsB;AAC/B,SAAS,aAAa,kBAAkB;AAExC,SAAS,0BAA0B;AACnC,SAAS,cAAc;AACvB,SAAS,uBAAuB;AA2EzB,MAAM,0BAA0B,eAAe;AAAA,EACpD,YAAY,SAA4B;AACtC,UAAM,OAAO;AAAA,EACf;AAAA;AAAA;AA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,KAAK,yBAAyB,OAAO;AAAA,IAC1C,CAAC;AAED,WAAO;AAAA,EACT;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/controllers/staking.ts"],"sourcesContent":["/**\n * Provides staking functionality for the VanaPool protocol.\n *\n * @remarks\n * This controller handles interactions with VanaPool staking contracts,\n * allowing users to query staking information such as total VANA staked,\n * entity information, and staker positions.\n *\n * @category Controllers\n * @module StakingController\n */\n\nimport type { ControllerContext } from \"../types/controller-context\";\nimport type { TransactionOptions } from \"../types/operations\";\nimport { BaseController } from \"./base\";\nimport { getContract, parseEther } from \"viem\";\nimport type { Address, Hash } from \"viem\";\nimport { getContractAddress } from \"../generated/addresses\";\nimport { getAbi } from \"../generated/abi\";\nimport { BlockchainError } from \"../errors\";\n\n/**\n * Information about a staking entity in the VanaPool protocol.\n */\nexport interface EntityInfo {\n entityId: bigint;\n ownerAddress: Address;\n status: number;\n name: string;\n maxAPY: bigint;\n lockedRewardPool: bigint;\n activeRewardPool: bigint;\n totalShares: bigint;\n lastUpdateTimestamp: bigint;\n}\n\n/**\n * Information about a staker's position in an entity.\n */\nexport interface StakerEntityInfo {\n shares: bigint;\n costBasis: bigint;\n rewardEligibilityTimestamp: bigint;\n realizedRewards: bigint;\n vestedRewards: bigint;\n}\n\n/**\n * Comprehensive staking summary for a staker in an entity.\n */\nexport interface StakerEntitySummary {\n /** Number of shares owned by the staker */\n shares: bigint;\n /** Cost basis - the original VANA amount staked */\n costBasis: bigint;\n /** Current value of the staker's shares in VANA */\n currentValue: bigint;\n /** Timestamp when rewards become eligible */\n rewardEligibilityTimestamp: bigint;\n /** Remaining bonding time in seconds (0 if bonding period has passed) */\n remainingBondingTime: bigint;\n /** Whether the staker is still in the bonding period */\n isInBondingPeriod: boolean;\n /** Vested rewards that can be claimed without penalty */\n vestedRewards: bigint;\n /** Unvested rewards (pending interest = currentValue - costBasis) */\n unvestedRewards: bigint;\n /** Realized/withdrawn rewards (already claimed) */\n realizedRewards: bigint;\n /** Total earned rewards (includes vested, unvested, and realized) */\n earnedRewards: bigint;\n}\n\n/**\n * Controller for VanaPool staking operations.\n *\n * @remarks\n * Provides methods to query staking information from the VanaPool contracts.\n * This includes total VANA staked across the protocol, entity information,\n * and individual staker positions.\n *\n * @example\n * ```typescript\n * // Get total VANA staked in the protocol\n * const totalStaked = await vana.staking.getTotalVanaStaked();\n * console.log(`Total staked: ${totalStaked} wei`);\n *\n * // Get entity information\n * const entity = await vana.staking.getEntity(1n);\n * console.log(`Entity name: ${entity.name}`);\n * ```\n *\n * @category Controllers\n */\nexport class StakingController extends BaseController {\n constructor(context: ControllerContext) {\n super(context);\n }\n\n /**\n * Gets the chain ID from context.\n */\n private getChainId(): number {\n const chainId =\n this.context.walletClient?.chain?.id ??\n this.context.publicClient.chain?.id;\n if (!chainId) {\n throw new Error(\"Chain ID not available\");\n }\n return chainId;\n }\n\n /**\n * Gets the VanaPoolEntity contract instance.\n */\n private getEntityContract() {\n const chainId = this.getChainId();\n return getContract({\n address: getContractAddress(chainId, \"VanaPoolEntity\"),\n abi: getAbi(\"VanaPoolEntity\"),\n client: this.context.publicClient,\n });\n }\n\n /**\n * Gets the VanaPoolStaking contract instance.\n */\n private getStakingContract() {\n const chainId = this.getChainId();\n return getContract({\n address: getContractAddress(chainId, \"VanaPoolStaking\"),\n abi: getAbi(\"VanaPoolStaking\"),\n client: this.context.publicClient,\n });\n }\n\n /**\n * Gets the total amount of VANA staked in the VanaPool protocol or a specific entity.\n *\n * @remarks\n * When called without an entityId, this retrieves the sum of activeRewardPool\n * across all active entities in the VanaPool protocol.\n * When called with an entityId, this returns the activeRewardPool for that specific entity.\n * The value is returned in wei (10^18 = 1 VANA).\n *\n * @param entityId - Optional entity ID to get staked amount for a specific entity\n * @returns The total amount of VANA staked in wei\n *\n * @example\n * ```typescript\n * // Get total staked across all entities\n * const totalStaked = await vana.staking.getTotalVanaStaked();\n * console.log(`Total staked: ${Number(totalStaked) / 1e18} VANA`);\n *\n * // Get staked amount for a specific entity\n * const entityStaked = await vana.staking.getTotalVanaStaked(1n);\n * console.log(`Entity 1 staked: ${Number(entityStaked) / 1e18} VANA`);\n * ```\n */\n async getTotalVanaStaked(entityId?: bigint): Promise<bigint> {\n const entityContract = this.getEntityContract();\n\n // If entityId is provided, return the activeRewardPool for that specific entity\n if (entityId !== undefined) {\n const entity = await entityContract.read.entities([entityId]);\n return entity.activeRewardPool;\n }\n\n // Otherwise, sum up the activeRewardPool from all active entities\n const activeEntityIds = await entityContract.read.activeEntitiesValues();\n\n let totalStaked = 0n;\n for (const id of activeEntityIds) {\n const entity = await entityContract.read.entities([id]);\n totalStaked += entity.activeRewardPool;\n }\n\n return totalStaked;\n }\n\n /**\n * Gets information about a specific staking entity.\n *\n * @param entityId - The ID of the entity to query\n * @returns The entity information including name, APY, shares, and reward pools\n *\n * @example\n * ```typescript\n * const entity = await vana.staking.getEntity(1n);\n * console.log(`Entity: ${entity.name}`);\n * console.log(`Total shares: ${entity.totalShares}`);\n * console.log(`Max APY: ${Number(entity.maxAPY) / 100}%`);\n * ```\n */\n async getEntity(entityId: bigint): Promise<EntityInfo> {\n const entityContract = this.getEntityContract();\n\n const result = await entityContract.read.entities([entityId]);\n\n return {\n entityId: result.entityId,\n ownerAddress: result.ownerAddress as Address,\n status: result.status,\n name: result.name,\n maxAPY: result.maxAPY,\n lockedRewardPool: result.lockedRewardPool,\n activeRewardPool: result.activeRewardPool,\n totalShares: result.totalShares,\n lastUpdateTimestamp: result.lastUpdateTimestamp,\n };\n }\n\n /**\n * Gets the total number of staking entities in the protocol.\n *\n * @returns The count of entities\n *\n * @example\n * ```typescript\n * const count = await vana.staking.getEntitiesCount();\n * console.log(`Total entities: ${count}`);\n * ```\n */\n async getEntitiesCount(): Promise<bigint> {\n const entityContract = this.getEntityContract();\n return entityContract.read.entitiesCount();\n }\n\n /**\n * Gets the IDs of all active staking entities.\n *\n * @returns Array of active entity IDs\n *\n * @example\n * ```typescript\n * const activeIds = await vana.staking.getActiveEntities();\n * console.log(`Active entities: ${activeIds.join(', ')}`);\n * ```\n */\n async getActiveEntities(): Promise<readonly bigint[]> {\n const entityContract = this.getEntityContract();\n return entityContract.read.activeEntitiesValues();\n }\n\n /**\n * Gets a staker's position in a specific entity.\n *\n * @param staker - The address of the staker\n * @param entityId - The ID of the entity\n * @returns The staker's position information\n *\n * @example\n * ```typescript\n * const position = await vana.staking.getStakerPosition(\n * '0x742d35...',\n * 1n\n * );\n * console.log(`Shares: ${position.shares}`);\n * console.log(`Rewards: ${position.realizedRewards}`);\n * ```\n */\n async getStakerPosition(\n staker: Address,\n entityId: bigint,\n ): Promise<StakerEntityInfo> {\n const stakingContract = this.getStakingContract();\n\n const result = await stakingContract.read.stakerEntities([\n staker,\n entityId,\n ]);\n\n return {\n shares: result.shares,\n costBasis: result.costBasis,\n rewardEligibilityTimestamp: result.rewardEligibilityTimestamp,\n realizedRewards: result.realizedRewards,\n vestedRewards: result.vestedRewards,\n };\n }\n\n /**\n * Gets the earned rewards for a staker in an entity.\n *\n * @param staker - The address of the staker\n * @param entityId - The ID of the entity\n * @returns The earned rewards amount in wei\n *\n * @example\n * ```typescript\n * const rewards = await vana.staking.getEarnedRewards(\n * '0x742d35...',\n * 1n\n * );\n * console.log(`Earned: ${Number(rewards) / 1e18} VANA`);\n * ```\n */\n async getEarnedRewards(staker: Address, entityId: bigint): Promise<bigint> {\n const stakingContract = this.getStakingContract();\n return stakingContract.read.getEarnedRewards([staker, entityId]);\n }\n\n /**\n * Gets the minimum stake amount required to stake.\n *\n * @returns The minimum stake amount in wei\n *\n * @example\n * ```typescript\n * const minStake = await vana.staking.getMinStakeAmount();\n * console.log(`Minimum stake: ${Number(minStake) / 1e18} VANA`);\n * ```\n */\n async getMinStakeAmount(): Promise<bigint> {\n const stakingContract = this.getStakingContract();\n return stakingContract.read.minStakeAmount();\n }\n\n /**\n * Gets the count of active stakers in the protocol.\n *\n * @returns The number of active stakers\n *\n * @example\n * ```typescript\n * const count = await vana.staking.getActiveStakersCount();\n * console.log(`Active stakers: ${count}`);\n * ```\n */\n async getActiveStakersCount(): Promise<bigint> {\n const stakingContract = this.getStakingContract();\n return stakingContract.read.activeStakersListCount();\n }\n\n /**\n * Gets the bonding period for staking.\n *\n * @returns The bonding period in seconds\n *\n * @example\n * ```typescript\n * const bondingPeriod = await vana.staking.getBondingPeriod();\n * console.log(`Bonding period: ${bondingPeriod / 86400n} days`);\n * ```\n */\n async getBondingPeriod(): Promise<bigint> {\n const stakingContract = this.getStakingContract();\n return stakingContract.read.bondingPeriod();\n }\n\n /**\n * Gets the total distributed rewards for a specific entity from the subgraph.\n *\n * @remarks\n * This queries the VanaPool subgraph to retrieve the cumulative `totalDistributedRewards`\n * for a staking entity. This value represents the sum of all rewards that have been\n * processed (moved from lockedRewardPool to activeRewardPool) minus any forfeited\n * rewards that were returned.\n *\n * Requires a configured `subgraphUrl` in the Vana constructor options.\n *\n * @param entityId - The ID of the entity to query\n * @param options - Optional configuration including custom subgraph URL\n * @returns The total distributed rewards in wei\n * @throws {BlockchainError} When subgraph URL is not configured or query fails\n *\n * @example\n * ```typescript\n * const totalRewards = await vana.staking.getTotalDistributedRewards(1n);\n * const totalRewardsVana = Number(totalRewards) / 1e18;\n * console.log(`Total distributed rewards: ${totalRewardsVana.toLocaleString()} VANA`);\n * ```\n */\n async getTotalDistributedRewards(\n entityId: bigint,\n options: { subgraphUrl?: string } = {},\n ): Promise<bigint> {\n const graphqlEndpoint = options.subgraphUrl ?? this.context.subgraphUrl;\n\n if (!graphqlEndpoint) {\n throw new BlockchainError(\n \"subgraphUrl is required. Please provide a valid subgraph endpoint or configure it in Vana constructor.\",\n );\n }\n\n const query = `\n query GetStakingEntityRewards($entityId: ID!) {\n stakingEntity(id: $entityId) {\n totalDistributedRewards\n }\n }\n `;\n\n const response = await fetch(graphqlEndpoint, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n query,\n variables: {\n entityId: entityId.toString(),\n },\n }),\n });\n\n if (!response.ok) {\n throw new BlockchainError(\n `Subgraph query failed with status ${response.status}`,\n );\n }\n\n const result = (await response.json()) as {\n data?: { stakingEntity?: { totalDistributedRewards: string } };\n errors?: Array<{ message: string }>;\n };\n\n if (result.errors && result.errors.length > 0) {\n throw new BlockchainError(\n `Subgraph query error: ${result.errors[0].message}`,\n );\n }\n\n if (!result.data?.stakingEntity) {\n throw new BlockchainError(`Staking entity ${entityId} not found`);\n }\n\n return BigInt(result.data.stakingEntity.totalDistributedRewards);\n }\n\n /**\n * Gets a comprehensive staking summary for a staker in an entity.\n *\n * @remarks\n * This method aggregates all relevant staking information for a staker in a single call,\n * including staked amount, current value, bonding status, and all reward types.\n *\n * Reward breakdown:\n * - `earnedRewards` = pendingInterest + vestedRewards + realizedRewards\n * - `pendingInterest` = currentValue - costBasis (unvested appreciation)\n * - `vestedRewards` = rewards that have vested but not yet withdrawn\n * - `realizedRewards` = rewards already withdrawn during unstakes\n *\n * @param staker - The address of the staker\n * @param entityId - The ID of the entity\n * @returns A comprehensive summary of the staker's position\n *\n * @example\n * ```typescript\n * const summary = await vana.staking.getStakerSummary('0x742d35...', 1n);\n * console.log(`Total staked: ${Number(summary.totalStaked) / 1e18} VANA`);\n * console.log(`Current value: ${Number(summary.currentValue) / 1e18} VANA`);\n * console.log(`In bonding period: ${summary.isInBondingPeriod}`);\n * console.log(`Remaining bonding time: ${Number(summary.remainingBondingTime) / 86400} days`);\n * console.log(`Vested rewards: ${Number(summary.vestedRewards) / 1e18} VANA`);\n * console.log(`Unvested rewards: ${Number(summary.unvestedRewards) / 1e18} VANA`);\n * console.log(`Realized rewards: ${Number(summary.realizedRewards) / 1e18} VANA`);\n * console.log(`Total earned: ${Number(summary.earnedRewards) / 1e18} VANA`);\n * ```\n */\n async getStakerSummary(\n staker: Address,\n entityId: bigint,\n ): Promise<StakerEntitySummary> {\n const chainId = this.getChainId();\n const stakingAddress = getContractAddress(chainId, \"VanaPoolStaking\");\n const entityAddress = getContractAddress(chainId, \"VanaPoolEntity\");\n const stakingAbi = getAbi(\"VanaPoolStaking\");\n const entityAbi = getAbi(\"VanaPoolEntity\");\n\n // Get latest block first to ensure all reads are from the same block\n const block = await this.context.publicClient.getBlock();\n const blockNumber = block.number;\n\n // Batch all contract reads into a single multicall RPC request at the same block\n const multicallResults = await this.context.publicClient.multicall({\n contracts: [\n {\n address: stakingAddress,\n abi: stakingAbi,\n functionName: \"stakerEntities\",\n args: [staker, entityId],\n },\n {\n address: stakingAddress,\n abi: stakingAbi,\n functionName: \"getEarnedRewards\",\n args: [staker, entityId],\n },\n {\n address: entityAddress,\n abi: entityAbi,\n functionName: \"entityShareToVana\",\n args: [entityId],\n },\n ],\n blockNumber,\n });\n\n const [positionResult, earnedRewardsResult, shareToVanaResult] =\n multicallResults;\n\n if (\n positionResult.status === \"failure\" ||\n earnedRewardsResult.status === \"failure\" ||\n shareToVanaResult.status === \"failure\"\n ) {\n throw new BlockchainError(\n \"Failed to fetch staker summary: one or more contract calls failed\",\n );\n }\n\n const position = positionResult.result as {\n shares: bigint;\n costBasis: bigint;\n rewardEligibilityTimestamp: bigint;\n realizedRewards: bigint;\n vestedRewards: bigint;\n };\n const earnedRewards = earnedRewardsResult.result as bigint;\n const shareToVana = shareToVanaResult.result as bigint;\n const currentTimestamp = block.timestamp;\n\n // Calculate remaining bonding time\n const eligibilityTimestamp = position.rewardEligibilityTimestamp;\n const remainingBondingTime =\n eligibilityTimestamp > currentTimestamp\n ? eligibilityTimestamp - currentTimestamp\n : 0n;\n const isInBondingPeriod = remainingBondingTime > 0n;\n\n // Calculate current value of shares\n // entityShareToVana returns the VANA value of 1 share (scaled by 1e18)\n const currentValue = (position.shares * shareToVana) / 10n ** 18n;\n\n // Calculate pending interest (unvested rewards)\n // pendingInterest = currentValue - costBasis (if positive)\n const unvestedRewards =\n currentValue > position.costBasis\n ? currentValue - position.costBasis\n : 0n;\n\n return {\n shares: position.shares,\n costBasis: position.costBasis,\n currentValue,\n rewardEligibilityTimestamp: eligibilityTimestamp,\n remainingBondingTime,\n isInBondingPeriod,\n vestedRewards: position.vestedRewards,\n unvestedRewards,\n realizedRewards: position.realizedRewards,\n earnedRewards,\n };\n }\n\n /**\n * Stakes VANA to an entity in the VanaPool protocol.\n *\n * @remarks\n * This method stakes native VANA tokens to a specified entity. The staker will receive\n * shares in proportion to their stake amount. A bonding period applies during which\n * rewards cannot be fully claimed without penalty.\n *\n * Requires a wallet client to be configured in the Vana constructor.\n *\n * @param params - The staking parameters\n * @param params.entityId - The ID of the entity to stake to\n * @param params.amount - The amount of VANA to stake (in wei, or as a string like \"1.5\" for 1.5 VANA)\n * @param params.recipient - Optional recipient address for the shares (defaults to the sender)\n * @param params.minShares - Optional minimum shares to receive (slippage protection, defaults to 0)\n * @returns The transaction hash\n * @throws {BlockchainError} When wallet client is not configured\n *\n * @example\n * ```typescript\n * // Stake 100 VANA to entity 1\n * const txHash = await vana.staking.stake({\n * entityId: 1n,\n * amount: \"100\", // 100 VANA\n * });\n * console.log(`Staked! Transaction: ${txHash}`);\n *\n * // Stake with slippage protection\n * const txHash2 = await vana.staking.stake({\n * entityId: 1n,\n * amount: parseEther(\"50\"), // 50 VANA in wei\n * minShares: parseEther(\"49\"), // Expect at least 49 shares\n * });\n * ```\n */\n async stake(\n params: {\n entityId: bigint;\n amount: bigint | string;\n recipient?: Address;\n minShares?: bigint;\n },\n options?: TransactionOptions,\n ): Promise<Hash> {\n this.assertWallet();\n\n const chainId = this.getChainId();\n const stakingAddress = getContractAddress(chainId, \"VanaPoolStaking\");\n const stakingAbi = getAbi(\"VanaPoolStaking\");\n\n // Convert amount to bigint if it's a string (e.g., \"1.5\" -> 1.5 VANA in wei)\n const amountWei =\n typeof params.amount === \"string\"\n ? parseEther(params.amount)\n : params.amount;\n\n // Get account with fallback to userAddress\n const account =\n this.context.walletClient.account ?? this.context.userAddress;\n const accountAddress =\n typeof account === \"string\" ? account : account.address;\n\n // Default recipient to the sender's address\n const recipient = params.recipient ?? accountAddress;\n\n // Default minShares to 0 (no slippage protection)\n const minShares = params.minShares ?? 0n;\n\n const txHash = await this.context.walletClient.writeContract({\n address: stakingAddress,\n abi: stakingAbi,\n functionName: \"stake\",\n args: [params.entityId, recipient, minShares],\n value: amountWei,\n account,\n chain: this.context.walletClient.chain,\n ...this.spreadTransactionOptions(options),\n });\n\n return txHash;\n }\n\n /**\n * Gets the maximum amount of VANA that can be unstaked in a single transaction.\n *\n * @remarks\n * This calls the contract's getMaxUnstakeAmount which returns the minimum of:\n * 1. The withdrawable VANA (costBasis if in bonding period, shareValue if eligible)\n * 2. The entity's activeRewardPool (what the entity has available)\n * 3. The treasury balance (what can be paid out)\n *\n * The limiting factor indicates what's constraining the unstake:\n * - 0 = user shares/costBasis\n * - 1 = activeRewardPool\n * - 2 = treasury\n *\n * @param staker - The address of the staker\n * @param entityId - The ID of the entity\n * @returns Object containing maxVana, maxShares, limitingFactor, and isInBondingPeriod\n *\n * @example\n * ```typescript\n * const result = await vana.staking.getMaxUnstakeAmount('0x742d35...', 1n);\n * console.log(`Max unstake: ${Number(result.maxVana) / 1e18} VANA`);\n * console.log(`Max shares: ${result.maxShares}`);\n * console.log(`In bonding period: ${result.isInBondingPeriod}`);\n * ```\n */\n async getMaxUnstakeAmount(\n staker: Address,\n entityId: bigint,\n ): Promise<{\n maxVana: bigint;\n maxShares: bigint;\n limitingFactor: number;\n isInBondingPeriod: boolean;\n }> {\n const stakingContract = this.getStakingContract();\n\n const result = await stakingContract.read.getMaxUnstakeAmount([\n staker,\n entityId,\n ]);\n\n return {\n maxVana: result[0],\n maxShares: result[1],\n limitingFactor: Number(result[2]),\n isInBondingPeriod: result[3],\n };\n }\n\n /**\n * Unstakes VANA from an entity in the VanaPool protocol.\n *\n * @remarks\n * This method unstakes native VANA tokens from a specified entity. The amount\n * that can be unstaked depends on whether the staker is in the bonding period:\n *\n * - **During bonding period**: Only cost basis can be withdrawn; rewards are forfeited\n * - **After bonding period**: Full current value (cost basis + rewards) can be withdrawn\n *\n * Use `getMaxUnstakeAmount` to determine the maximum amount that can be unstaked.\n *\n * Requires a wallet client to be configured in the Vana constructor.\n *\n * @param params - The unstaking parameters\n * @param params.entityId - The ID of the entity to unstake from\n * @param params.amount - The amount of VANA to unstake (in wei, or as a string like \"1.5\" for 1.5 VANA)\n * @param params.maxShares - Maximum shares to burn for slippage protection (defaults to 0, no protection)\n * @returns The transaction hash\n * @throws {BlockchainError} When wallet client is not configured\n *\n * @example\n * ```typescript\n * // Get max unstake amount first\n * const maxUnstake = await vana.staking.getMaxUnstakeAmount(address, 1n);\n *\n * // Unstake the maximum amount with slippage protection\n * const txHash = await vana.staking.unstake({\n * entityId: 1n,\n * amount: maxUnstake.maxVana,\n * maxShares: maxUnstake.maxShares,\n * });\n * console.log(`Unstaked! Transaction: ${txHash}`);\n * ```\n */\n async unstake(\n params: {\n entityId: bigint;\n amount: bigint | string;\n maxShares?: bigint;\n },\n options?: TransactionOptions,\n ): Promise<Hash> {\n this.assertWallet();\n\n const chainId = this.getChainId();\n const stakingAddress = getContractAddress(chainId, \"VanaPoolStaking\");\n const stakingAbi = getAbi(\"VanaPoolStaking\");\n\n // Convert amount to bigint if it's a string (e.g., \"1.5\" -> 1.5 VANA in wei)\n const amountWei =\n typeof params.amount === \"string\"\n ? parseEther(params.amount)\n : params.amount;\n\n // Default maxShares to 0 (no slippage protection)\n const maxShares = params.maxShares ?? 0n;\n\n // Get account with fallback to userAddress\n const account =\n this.context.walletClient.account ?? this.context.userAddress;\n\n const txHash = await this.context.walletClient.writeContract({\n address: stakingAddress,\n abi: stakingAbi,\n functionName: \"unstakeVana\",\n args: [params.entityId, amountWei, maxShares],\n account,\n chain: this.context.walletClient.chain,\n ...this.spreadTransactionOptions(options),\n });\n\n return txHash;\n }\n}\n"],"mappings":"AAcA,SAAS,sBAAsB;AAC/B,SAAS,aAAa,kBAAkB;AAExC,SAAS,0BAA0B;AACnC,SAAS,cAAc;AACvB,SAAS,uBAAuB;AA2EzB,MAAM,0BAA0B,eAAe;AAAA,EACp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