Stake 2.0 seamlessly integrates with PVM, enabling users to engage in staking/unstaking, delegating/undelegating, resource status queries, and more within the smart contract realm. The following outlines the Solidity APIs associated with Stake 2.0.
freezebalancev2(uint amount, uint resourceType)
Description: Stake PRC to acquire Pollux Power (voting rights) along with bandwidth or energy. In case of failure, the process will trigger a revert exception.
Params:
Amount — the quantity of POX to be staked, measured in RAM.
Resource type — the type of resource, where 0 represents "BANDWIDTH" and 1 corresponds to "ENERGY".
Returns: N/A
pragma solidity ^0.8.17;
contract C {
event BalanceFreezedV2(uint, uint);
// stake 1 POX to obtain energy
function example() external {
freezebalancev2(1000000, 1);
emit BalanceFreezedV2(1000000, 1);
}
}
unfreezeBalanceV2(uint amount, uint resourceType)
Description: Unstake POX to free up bandwidth and energy, simultaneously reducing Pollux Power and canceling corresponding votes. Following the execution of this transaction, users are required to wait for N days before being able to invoke withdraw expire unfreeze to retrieve their funds.
Params:
Amount — the amount of POX to be staked, measured in RAM
Resource type — the type of resource, where 0 corresponds to "BANDWIDTH" and 1 represents "ENERGY"
Returns: N/A
Example:
cancelAllUnfreezeV2()
Description: Canceling all outstanding unstaking requests is essential. Prior to invoking selfdestruct(address) for the contract's destruction, it is imperative to cancel any pending unstaking requests. Failure to do so would hinder the contract's ability to be successfully terminated.
Params: N/A
Returns: N/A
Example:
withdrawExpireUnfreeze() returns(uint amount)
Description: Retrieve unfrozen POX—users can utilize this API to withdraw funds to their account following the execution of the unfreezeBalanceV2 transaction, subject to a waiting period of N days, where N is a network parameter.
Params: N/A
Returns: the quantity of POX successfully withdrawn, measured in RAM.
Description: Verify if the contract is eligible to reclaim the designated resource share for a specific resource type that has been delegated to a given address.
Params:
Amount — allocated resource portion, measured in units of RAM
Resource Category — type of resource, with 0 representing BANDWIDTH and 1 indicating ENERGY.
Returns: Available designates the quantity of available resource share, measured in RAM. "Used" represents the amount of utilized resource share, with the unit specified as RAM. The "restore time" indicates the time point when the used resources are scheduled for restoration, measured in seconds.
Description: Inquire about the usage of a particular resource type for the given address.
Params:
Resource Type — resource type; 0 represents BANDWIDTH, and 1 represents ENERGY
Results: Utilization signifies the allocated resource share, measured in RAM units. Replenishment time denotes the point in time when the utilized resources are regenerated, measured in seconds
Description: Retrieve the obtained allocation of resource shares for a designated resource type associated with a given address.
Params:
resourceType — the type of resource, with 0 representing BANDWIDTH, and 1 representing ENERGY.
Returns: the quantity of obtained resource share, measured in the unit of RAM.
Example:
vote(address[] srList, uint[] tpList)
Description: Cast your vote for a witness in the srList array, and each elected witness will receive the corresponding TP as listed in the tpList array.
Params:
srList — List of Super Representatives.
tpList — Number of votes allocated to the Super Representatives in the srList.
Returns: N/A
The following scenarios may lead to a revert exception:
Mismatch in the lengths of srList and tpList arrays.
The array lengths exceed the defined MAX_VOTE_NUMBER limit (30).
Presence of regular account addresses in the srList array.
Existence of negative values in the 'tpList' array.
The total required Pollux Power surpasses the current Tron Power owned by the contract.
Example:
withdrawReward() returns(uint)
Description: withdraw all approved funds and incentives to the smart contract pool.
Params:N/A
Returns:Provides the realigned sum of withdrawn funds from both the approved allowance and rewards, measured in RAM units.
Instances leading to a revert exception encompass the following scenarios:
Inclusion of the contract address within the witness list of the genesis block.
Overflow of the total, combining contract balance and reward, exceeding the length of a long integer (8 bytes).
Example:
rewardBalance() returns(uint)
Description: Retrieve the allowances and rewards associated with the contract account.
Params:N/A
Returns: Total amount comprising the allowance and reward associated with the contract account.
Example:
isSrCandidate(address sr) returns(bool)
Description: Determine if the given address qualifies as a candidate address.
Params:
sr - Address to query
Returns: Returns true if the address is a qualified candidate address; otherwise, returns false.
Example:
voteCount(address from, address to) returns(uint)
Description: Retrieve the vote count from the specified account that has voted for the designated recipient account.
Params:
from - vote address
to - SR address
Returns: The associated vote count measured in Pollux-power, where 1 POX equals 1 Pollux-power.
Example:
usedVoteCount(address owner) returns(uint)
Description: Retrieve the vote count utilized by the owner.
Params:
owner - address to query
Returns: The vote count employed by the owner account, measured in Pollux-power, with 1 POX equivalent to 1 Pollux-power.
Example:
ReceivedVoteCount(address owner) returns(uint)
Description: Retrieve the vote count received by the owner.
Params:
owner - address to query
Returns: received votes for the owner account, measured in Pollux-power, where 1 POX equals 1 Pollux-power.
Example:
TotalVoteCount(address owner) returns(uint)
Description: Retrieve the overall vote count of the owner, alternatively referred to as the Pollux-power owned by the contract.
Params:
owner - address to query
Returns: The cumulative vote count associated with the owner account, measured in Pollux-power, with 1 POX equivalent to 1 Pollux-power.
pragma solidity ^0.8.17;
contract C {
event ExpireUnfreezeWithdrew(uint);
// the contract delegates 1 POX bandwidth resource share to receiver
function example(address payable receiver) external {
receiver.delegateResource(1000000, 0);
emit ResourceDelegated(1000000, 0, receiver);
}
}
pragma solidity ^0.8.17;
contract C {
event ResourceUnDelegated(uint, uint, address);
// the contract undelegates 1 POX bandwidth resource share from the receiver
function example(address payable receiver) external {
receiver.unDelegateResource(1000000, 0);
emit ResourceDelegated(1000000, 0, receiver);
}
}
pragma solidity ^0.8.17;
contract C {
function getChainParameters() view public returns(uint, uint, uint, uint, uint)
{
return (chain.totalNetLimit, chain.totalNetWeight,
chain.totalEnergyCurrentLimit, chain.totalEnergyWeight,
chain.unfreezeDelayDays);
}
}
pragma solidity ^0.8.17;
contract C {
function getvailableUnfreezeV2Size(address target) view public returns(uint) {
return target.availableUnfreezeV2Size();
}
}
pragma solidity ^0.8.17;
contract C {
function getvailableUnfreezeV2Size(address target) view public returns(uint amount) {
return target.unfreezableBalanceV2(1);
}
}
pragma solidity ^0.8.17;
contract C {
function getExpireUnfreezeBalanceV2(address target) view public returns(uint amount) {
return target.expireUnfreezeBalanceV2(block.timestamp);
}
}
pragma solidity ^0.8.17;
contract C {
//query the amount of delegatable resources share of energy for target address
function getDelegatableResource(address target) view public returns(uint) {
return target.delegatableResource(1);
}
}
pragma solidity ^0.8.17;
contract C {
//query the amount of resources share of energy delegated by a to b
function getResourceV2(address b, address a) view public returns(uint) {
return b.resourceV2(a, 1);
}
}
pragma solidity ^0.8.17;
contract C {
function checkUnDelegateResource(address target) view public returns(uint, uint, uint) {
(uint available, uint used, uint restoreTime) = target.checkUnDelegateResource(1000000, 1);
return (available, used, restoreTime);
}
}
pragma solidity ^0.8.17;
contract C {
function getResourceUsage(address target) view public returns(uint, uint) {
(uint used, uint restoreTime) = target.resourceUsage(1);
return (used, restoreTime);
}
}
pragma solidity ^0.8.17;
contract C {
//query the available resource share of energy for the target address
function getTotalResource(address target) view public returns(uint) {
return target.totalResource(1);
}
}
pragma solidity ^0.8.17;
contract C {
//query the delegated resource share of energy for the target address
function getTotalDelegatedResource(address from) view public returns(uint) {
return from.totalDelegatedResource(1);
}
}
pragma solidity ^0.8.17;
contract C {
//query the acquired resource share of energy for the target address
function getTotalAcquiredResource(address target) view public returns(uint) {
return target.totalAcquiredResource(1);
}
}
pragma solidity ^0.8.17;
contract C {
function voteWitness(address[] calldata srList, uint[] calldata tpList) external {
vote(srList, tpList);
}
}
pragma solidity ^0.8.17;
contract C {
function withdrawReward() external returns(uint) {
return withdrawreward();
}
}
pragma solidity ^0.8.17;
contract C {
function queryRewardBalance() external view returns(uint) {
return rewardBalance();
}
}
pragma solidity ^0.8.17;
contract C {
function isWitness(address sr) external view returns(bool) {
return isSrCandidate(sr);
}
}
pragma solidity ^0.8.17;
contract C {
function queryVoteCount(address from, address to) external view returns(uint) {
return voteCount(from, to);
}
}
pragma solidity ^0.8.17;
contract C {
function queryUsedVoteCount(address owner) external view returns(uint) {
return usedVoteCount(owner);
}
}
pragma solidity ^0.8.17;
contract C {
function queryReceivedVoteCount(address owner) external view returns(uint) {
return receivedVoteCount(owner);
}
}
pragma solidity ^0.8.17;
contract C {
function queryTotalVoteCount(address owner) external view returns(uint) {
return totalVoteCount(owner);
}
}