质押
amount + MINIMAL_CONTRACT_DEPOSIT 的 ALPH。要把质押归属到某个渠道地址,请使用 stakeAlphWithReferral(amount, referral)。使用 referral 之前请先联系团队,见推荐质押与渠道分润。
显示兑换率和用户持仓价值
解除质押
getSettings().unstakeDuration(主网为 30 天)内线性解锁:已解锁的部分随时可以领取,期满后可领取全部。每个用户最多有 16 个活跃请求。
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
质押、显示兑换率、发起解除质押,并随解锁进度领取。
import { ONE_ALPH } from '@alephium/web3'
const tx = await powfi.staking.stakeAlph(100n * ONE_ALPH)
amount + MINIMAL_CONTRACT_DEPOSIT 的 ALPH。要把质押归属到某个渠道地址,请使用 stakeAlphWithReferral(amount, referral)。使用 referral 之前请先联系团队,见推荐质押与渠道分润。
import Decimal from 'decimal.js'
const { fields } = await powfi.staking.getXAlphTokenState()
const rate = new Decimal(fields.totalDepositedAlph.toString()).div(fields.totalXAlphSupply.toString()) // ALPH per xALPH
const xAlphId = powfi.staking.getConfig().xAlphTokenId
const bal = await powfi.nodeProvider.addresses.getAddressesAddressBalance(address)
const xAlph = BigInt(bal.tokenBalances?.find((t) => t.id === xAlphId)?.amount ?? '0')
const valueInAlph = rate.mul(xAlph.toString()).div(1e18) // xALPH has 18 decimals, like ALPH
await powfi.staking.startUnstake(50n * ONE_ALPH) // amount of xALPH to burn
getSettings().unstakeDuration(主网为 30 天)内线性解锁:已解锁的部分随时可以领取,期满后可领取全部。每个用户最多有 16 个活跃请求。
const indexes = await powfi.staking.getActiveUnstakeVaultIndexes(address)
const requests = await Promise.all(
indexes.map(async (i) => {
const { fields } = await powfi.staking.getAlphUnstakeVaultState(address, i)
return {
index: i,
total: fields.totalUnstakeAmount,
withdrawn: fields.withdrawnAmount,
fullyUnlockedAt: new Date(Number(fields.unstakeStartTime + fields.unstakeDuration)),
claimable: await powfi.staking.getClaimableAmount(address, i)
}
})
)
for (const r of requests) {
if (r.claimable > 0n) await powfi.staking.claimUnstaked(r.index, r.claimable)
}
// change of mind: unlocked ALPH is paid out, the rest is re-staked as xALPH
await powfi.staking.cancelUnstake(requests[0].index)