Stake 2.0 Solidity API
Stake 2.0 Solidity API
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
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.
Example:
<address payable>.delegateResource(uint amount, uint resourceType)
Description: Delegate bandwidth or energy resources to a specific address.
Params:
Amount — the quantity of POX staked for the delegated resource, measured in RAM
Resource type — the type of resource, where 0 represents BANDWIDTH and 1 corresponds to ENERGY
Returns: N/A
Example:
<address payable>.unDelegateResource(amount, resourceType)
Description: Revoke the resource delegation associated with the specified address.
Params:
Amount: the quantity of POX staked for the resource to be undelegated, measured in RAM.
Resource Type: the type of resource, where 0 represents BANDWIDTH and 1 represents ENERGY.
Returns: N/A
Example:
Chain Properties
chain.totalNetLimit: Overall network bandwidth allocation, presently set at 5,00,00,000.
chain.totalNetWeight: Cumulative POX staked for bandwidth, measured in POX.
chain.totalEnergyCurrentLimit: Total energy allocation in the network, currently set at 500,00,00,000.
chain.totalEnergyWeight: Cumulative POX staked for energy, measured in POX.
chain.unfreezeDelayDays: Waiting period for unstaking, measured in days.
Example:
<address>.availableUnfreezeV2Size() returns(uint)
Description: Retrieve the remaining attempts for executing the unstake operation associated with a specific address.
Params:N/A
Returns: the remaining attempts for executing the unstake operation.
Example:
<address>.unfreezableBalanceV2() returns(uint amount)
Description: Retrieve the balance of a specified resource type that is eligible for unfreezing, associated with a given address.
Params:
resourceType — type of resource, 0 represents BANDWIDTH, and 1 represents ENERGY
Returns: non-freezable POX balance, measured in RAM
Example:
<address>.expireUnfreezeBalanceV2(uint timestamp) returns(uint amount)
Description: Retrieve the withdrawable balance for the given address at the designated timestamp.
Params:
timestamp — inquiry cutoff time, measured in seconds
Returns: withdrawable POX balance, measured in RAM
Example:
<address>.delegatableResource(uint resourceType) returns(uint amount)
Description: Retrieve the share of delegatable resources associated with the specified resourceType for a given address.
Params:
Resource type — designation of resource type, where 0 represents BANDWIDTH and 1 corresponds to ENERGY.
Return: divisible resource allocation, measured in RAM units.
Example:
<address>.resourceV2(address from, uint resourceType) returns(uint amount)
Description: Retrieve the allocated resource share for a designated resource type delegated from one address to another.
Params:
From — proprietor of resources
Resource type — Type of resource, with 0 denoting BANDWIDTH and 1 signifying ENERGY.
Return: Allocated resource portion, measured in units of RAM.
Example:
<address>.checkUnDelegateResource(uint amount, uint resourceTyp) returns(uint available, uint used, uint restoreTime)
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.
Example:
<address>.getResourceUsage(uint resourceTyp) returns(uint used, uint restoreTime)
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
Example:
<address>.totalResource(uint resourceTyp) returns(uint amount)
Description: Retrieve the overall allocated resource allocation for a designated resource type associated with the given address.
Params:
Resource Type — resource type, 0 represents BANDWIDTH and 1 represents ENERGY.
Results: Indicates the quantity of accessible resource allocation, measured in RAM units.
Example:
<address>.totalDelegatedResource(uint resourceTyp) returns(uint amount)
Description: Retrieve the allocated resource quota for a designated resource type associated with a given address.
Params:
resourceType — designation of resource, where 0 represents BANDWIDTH and 1 represents ENERGY.
Returns: the quantity of allocated resource share, expressed in uint as RAM.
Example:
<address>.totalAcquiredResource(uint resourceType) returns(uint amount)
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.
Example:
Last updated