SLPx
SLPx offers ways to stake and unstake vToken assets.
Key Features
Supported Networks and Assets
- Moonbeam Network: vGLMR, vFIL, vDOT
- Moonriver Network: vMOVR, vBNC, vKSM
- Astar Network: vASTR, vDOT
- Ethereum Network: vETH
Install
npm install @bifrost-finance/slpx
Usage
First, import the necessary modules and instantiate the SLPx
class:
import { usePublicClient, useWalletClient } from 'wagmi';
import SLPx from '@bifrost-finance/slpx';
const publicClient = usePublicClient();
const { data: walletClient } = useWalletClient();
const slpx = new SLPx(publicClient, walletClient, channel);
Stake an Asset
import { useContractReads, erc20ABI, useAccount } from 'wagmi';
const { address } = useAccount()
const vToken = 'vBNC';
const amount = 1.0;
const token = vToken?.replace(/^v/, '').toUpperCase();
const { data, refetch } = useContractReads(
{
contracts: [
{
address: slpx.getContractAddressByToken(token),
abi: erc20ABI,
functionName: 'allowance',
args: [address, slpx.getContractAddressByToken('SLPx')]
}
]
}
)
slpx.approveStake(vToken, amount)
.then(txHash => console.log(`Transaction hash: ${txHash}`))
.catch(error => console.error(`Error approving stake: ${error}`));
const minStake = slpx.getMinStake(vToken)
slpx.stakeAsset(vToken, amount)
.then(txHash => console.log(`Transaction hash: ${txHash}`))
.catch(error => console.error(`Error staking asset: ${error}`));
UnStake an Asset
import { useContractReads, erc20ABI, useAccount } from 'wagmi';
const { address } = useAccount();
const vToken = 'vBNC';
const amount = 1.0;
const { data, refetch } = useContractReads(
{
contracts: [
{
address: slpx.getContractAddressByToken(vToken),
abi: erc20ABI,
functionName: 'allowance',
args: [address, slpx.getContractAddressByToken('SLPx')]
}
]
}
)
slpx.approveUnstake(vToken, amount)
.then(txHash => console.log(`Transaction hash: ${txHash}`))
.catch(error => console.error(`Error approving stake: ${error}`));
const minStake = slpx.getMinUnstake(vToken)
slpx.unstakeAsset(vToken, amount)
.then(txHash => console.log(`Transaction hash: ${txHash}`))
.catch(error => console.error(`Error staking asset: ${error}`));
vETH
After the completion of vETH Unstaking, the dedicated interface for claiming
slpx.getClaimInfo('vETH')
.then(info => console.log(`Claim info: ${JSON.stringify(info)}`))
.catch(error => console.error(`Error getting claim info: ${error}`));
slpx.toClaim('vETH')
.then(info => console.log(`Claim info: ${JSON.stringify(info)}`))
.catch(error => console.error(`Error getting claim info: ${error}`));