Connecting your Frontend

Connect to Fuji

User Operations

What is your ID ?

At this point your ID will be shared with you by our Developers after the approval of the Senate.
You can easily check your id with the following function:
Portal.getIdFromName( {your name} )

Get Important Stats about your Planet from Portal

gAVAX address

Portal.gAVAX();

Maintainer Address

Portal.getMaintainerFromId(uint256 id);

Maintainer fee as a percentage

Portal.getMaintainerFeeFromId(uint256 id) / Portal.getFeeDenominator() * 100 ;

Current ERC1155Interface

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);

Withdrawal Pool address

Portal.planetWithdrawalPool(uint256 id);

Withdrawal Pool LP token address

Portal.planetLPToken(uint256 id);

Current activeOperator

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;

Last reported OraclePrice

Portal.planetOraclePrice( uint256 planetId );

Surplus and Debt

Portal.planetClaimableSurplus(uint256 planetId);
Portal.planetDebt(uint256 planetId);

Staking Might be paused for your Pool, by your Maintainer

Portal.isStakingPausedForPool(uint256 planetId);

Staking

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.

Easy way of calculating:

price = Portal.planetOraclePrice( uint256 planetId );
return AvaxStakedAmount / price * 1e18;

A better way of calculating:

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 ;
}

Stake

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
);

Withdrawals

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
);
Copy link
On this page
Connect to Fuji
User Operations
Get Important Stats about your Planet from Portal
Staking
Stake
Withdrawals