Gets the total amount of VANA staked in the VanaPool protocol or a specific entity.
OptionalentityId: bigintOptional entity ID to get staked amount for a specific entity
The total amount of VANA staked in wei
When called without an entityId, this retrieves the sum of activeRewardPool across all active entities in the VanaPool protocol. When called with an entityId, this returns the activeRewardPool for that specific entity. The value is returned in wei (10^18 = 1 VANA).
// Get total staked across all entities
const totalStaked = await vana.staking.getTotalVanaStaked();
console.log(`Total staked: ${Number(totalStaked) / 1e18} VANA`);
// Get staked amount for a specific entity
const entityStaked = await vana.staking.getTotalVanaStaked(1n);
console.log(`Entity 1 staked: ${Number(entityStaked) / 1e18} VANA`);
Gets information about a specific staking entity.
The ID of the entity to query
The entity information including name, APY, shares, and reward pools
Gets a staker's position in a specific entity.
The address of the staker
The ID of the entity
The staker's position information
Gets the earned rewards for a staker in an entity.
The address of the staker
The ID of the entity
The earned rewards amount in wei
Gets the total distributed rewards for a specific entity from the subgraph.
The ID of the entity to query
Optional configuration including custom subgraph URL
The total distributed rewards in wei
This queries the VanaPool subgraph to retrieve the cumulative totalDistributedRewards
for a staking entity. This value represents the sum of all rewards that have been
processed (moved from lockedRewardPool to activeRewardPool) minus any forfeited
rewards that were returned.
Requires a configured subgraphUrl in the Vana constructor options.
Gets a comprehensive staking summary for a staker in an entity.
The address of the staker
The ID of the entity
A comprehensive summary of the staker's position
This method aggregates all relevant staking information for a staker in a single call, including staked amount, current value, bonding status, and all reward types.
Reward breakdown:
earnedRewards = pendingInterest + vestedRewards + realizedRewardspendingInterest = currentValue - costBasis (unvested appreciation)vestedRewards = rewards that have vested but not yet withdrawnrealizedRewards = rewards already withdrawn during unstakesconst summary = await vana.staking.getStakerSummary('0x742d35...', 1n);
console.log(`Total staked: ${Number(summary.totalStaked) / 1e18} VANA`);
console.log(`Current value: ${Number(summary.currentValue) / 1e18} VANA`);
console.log(`In bonding period: ${summary.isInBondingPeriod}`);
console.log(`Remaining bonding time: ${Number(summary.remainingBondingTime) / 86400} days`);
console.log(`Vested rewards: ${Number(summary.vestedRewards) / 1e18} VANA`);
console.log(`Unvested rewards: ${Number(summary.unvestedRewards) / 1e18} VANA`);
console.log(`Realized rewards: ${Number(summary.realizedRewards) / 1e18} VANA`);
console.log(`Total earned: ${Number(summary.earnedRewards) / 1e18} VANA`);
Stakes VANA to an entity in the VanaPool protocol.
The staking parameters
The ID of the entity to stake to
The amount of VANA to stake (in wei, or as a string like "1.5" for 1.5 VANA)
Optionalrecipient?: `0x${string}`Optional recipient address for the shares (defaults to the sender)
OptionalminShares?: bigintOptional minimum shares to receive (slippage protection, defaults to 0)
Optionaloptions: TransactionOptionsThe transaction hash
This method stakes native VANA tokens to a specified entity. The staker will receive shares in proportion to their stake amount. A bonding period applies during which rewards cannot be fully claimed without penalty.
Requires a wallet client to be configured in the Vana constructor.
// Stake 100 VANA to entity 1
const txHash = await vana.staking.stake({
entityId: 1n,
amount: "100", // 100 VANA
});
console.log(`Staked! Transaction: ${txHash}`);
// Stake with slippage protection
const txHash2 = await vana.staking.stake({
entityId: 1n,
amount: parseEther("50"), // 50 VANA in wei
minShares: parseEther("49"), // Expect at least 49 shares
});
Gets the maximum amount of VANA that can be unstaked in a single transaction.
The address of the staker
The ID of the entity
Object containing maxVana, maxShares, limitingFactor, and isInBondingPeriod
This calls the contract's getMaxUnstakeAmount which returns the minimum of:
The limiting factor indicates what's constraining the unstake:
Computes the new bonding period end timestamp after adding stake.
The parameters for computing the new bonding period
The address of the staker
The ID of the entity
The amount of VANA to stake (in wei)
Object containing the new eligibility timestamp and related info
When a staker adds more stake to an existing position, the reward eligibility timestamp is recalculated as a weighted average of the existing and new positions. This function allows you to preview what the new eligibility timestamp would be without executing the stake transaction.
The formula used (matching the contract):
newEligibility = (existingShares * existingEligibility + newShares * newEligibility) / totalShares
Where newEligibility for the incoming stake is currentTimestamp + bondingPeriod.
// Preview bonding period after staking 100 VANA
const preview = await vana.staking.computeNewBondingPeriod({
staker: '0x742d35...',
entityId: 1n,
stakeAmount: parseEther("100"),
});
console.log(`New eligibility: ${new Date(Number(preview.newEligibilityTimestamp) * 1000)}`);
console.log(`Remaining bonding time: ${Number(preview.newRemainingBondingTime) / 86400} days`);
Unstakes VANA from an entity in the VanaPool protocol.
The unstaking parameters
The ID of the entity to unstake from
The amount of VANA to unstake (in wei, or as a string like "1.5" for 1.5 VANA)
OptionalmaxShares?: bigintMaximum shares to burn for slippage protection (defaults to 0, no protection)
Optionaloptions: TransactionOptionsThe transaction hash
This method unstakes native VANA tokens from a specified entity. The amount that can be unstaked depends on whether the staker is in the bonding period:
Use getMaxUnstakeAmount to determine the maximum amount that can be unstaked.
Requires a wallet client to be configured in the Vana constructor.
// Get max unstake amount first
const maxUnstake = await vana.staking.getMaxUnstakeAmount(address, 1n);
// Unstake the maximum amount with slippage protection
const txHash = await vana.staking.unstake({
entityId: 1n,
amount: maxUnstake.maxVana,
maxShares: maxUnstake.maxShares,
});
console.log(`Unstaked! Transaction: ${txHash}`);
Controller for VanaPool staking operations.
Remarks
Provides methods to query staking information from the VanaPool contracts. This includes total VANA staked across the protocol, entity information, and individual staker positions.
Example