Connect Your Frontend
Portal.gAVAX();
Portal.getMaintainerFromId(uint256 id);
Portal.getMaintainerFeeFromId(uint256 id) / Portal.getFeeDenominator() * 100 ;
Note, this function can be used in your frontend but you should probably hard code your Interfaces, as you can have multiple interfaces and this function is not reliable for most cases.
Portal.planetCurrentInterface(uint256 id);
Portal.planetWithdrawalPool(uint256 id);
Portal.planetLPToken(uint256 id);
Portal.planetActiveOperator(uint256 id);
Note, there can be multiple operators that are still operating on your pool. Please refer to the next code for such cases:
// get all operators( type 4 )
allOps = Portal.getIdsByType(4);
for(allOps){
if(
Portal.operatorActivationExpiration(
uint256 planetId,
uint256 allOps[i] ) <= now.timestamp
){
currentOperators.push(allOps[i]);
}
}
return currentOperators;
Currently we are working on Avalanche Portal to improve Staking Pool - Node Operator interactions. With an incoming update, Portal will adopt the Open Market approach that is implemented in Ethereum.
Which means activeOperator approach will be abandoned soon.
Learn more here:
Portal.planetOraclePrice( uint256 planetId );
Portal.planetClaimableSurplus(uint256 planetId);
Portal.planetDebt(uint256 planetId);
Portal.isStakingPausedForPool(uint256 planetId);
The Portal finds the best price for your users, however it is not always predictable. We advise trusting the Oracle Price as the "minimum amount" that will be received by the staker. However, while we make sure it will not be lower than that, it can be drastically more than that according to the debt of your pool. We have not implemented any functions to guess the output.
price = Portal.planetOraclePrice( uint256 planetId );
return AvaxStakedAmount / price * 1e18;
WPaddress= Portal.planetWithdrawalPool(uint256 id);
WPool = web3.eth.Contract( abi, WPaddress );
debt = Portal.planetDebt(uint256 planetId);
if( AvaxStakedAmount <= debt )
{
// In such case take a look at the second code piece that routes directly to WP
return WPool.calculateSwap(AvaxStakedAmount );
}
else{
buyAmount = WPool.calculateSwap(debt);
mintAmount = (AvaxStakedAmount - debt) / price * 1e18;
return buyAmount + mintAmount ;
}
Portal.stake(
uint256 planetId,
uint256 minGavax,
uint256 deadline
);
If AvaxStakedAmount <= debt, you can route your use directly to WP and save them gas fees :)
WPaddress= Portal.planetWithdrawalPool(uint256 id);
WPool = web3.eth.Contract( abi, WPaddress );
WPool.swap(
0, // caution 0(avax) to 1(gAVAX)
1,
uint256 amount,
uint256 minGavax,
uint256 deadline
);
There is no complexity as all withdrawals finalize in the Withdrawal Pools.
WPaddress= Portal.planetWithdrawalPool(uint256 id);
WPool = web3.eth.Contract( abi, WPaddress );
WPool.swap(
1, // caution 1(gAVAX) to 0(avax)
0,
uint256 amount,
uint256 minGavax,
uint256 deadline
);
Last modified 3mo ago