tip: 171
title: STAKE instructions in TVM
author: [email protected]
status: Draft
type: Standards Track
category : Core
created: 2020-08-05
To provide Staking operations in TVM.
This is a simplified solution for PoS incentive mechanism in smart contract.
Current mechanism allows a normal privatkey address to vote for SR and get dividend, while TRX locked in smart contract can't get benefit from the mechanism. This TIP introduced a new way to support vote and get block procude reward in smart contracts. This will motivate more developers for their DApp developing. They should be able to get more profit from their products.
The following instructions are introduced:
STAKE
is a TRX staking to get TRON Powever and voting SR process for a smart contract.
FACTS:
- STAKE ONLY available for single SR.
- As long as a STAKE be executed, it is not adding a vote information, but replacing the entire vote information belongs to the contract itself.
The STAKE
takes 2 operands pop up from stack:
sr_address
: the target address to vote.
stake_amount
: TRX amount to freeze in SUN.
Will process following logic:
- Contract stake trx as bandwidth and add the frozen amount to its
Account.frozenBalance
. The default staking period is 3 days. - Contract update vote information in voteStore and accountStore (this will replace the entire vote state for owner, not append)
Execute STAKE function and push 0 to stack if fail, push 1 otherwise.
UNSTAKE
is a TRX unstaking and clear all votes process for a smart contract.
The UNSTAKE
takes 0 operands from stack.
Will process following logic:
- 3 days after the last
STAKE
operation for this contract, the contract can choose toUNSTAKE
its TRX. - Update block produce reward balance for this contract.
- Unfrozne balance in contract.
- Contract clears vote information.
Execute UNSTAKE function and push 0 to stack if fail, push 1 otherwise.
A smart contract can collects block produce reward by using WITHDRAWREWARD
instruction.
The WITHDRAWREWARD
takes 0 operand from stack.
Execute withdraw function and push exact balance value to stack if success, push 0 if it is failed.
Show current reward balance for an address
The REWARDBALANCE
takes 1 operand from stack.
accountAddress
: target account address.
Push the block reward balance of the target address to stack.
Check if a target address is a witness.
The ISSRCANDIDATE
takes 1 operand from stack.
accountAddress
: target account address.
Push 0 if target address is not a candidate witness, otherwise push 1.
7 key changes:
dynamiceStore: TOTAL_NET_WEIGHT
AccountStore: the contract account key
delegateStore: Remark
,BeginCycle
,EndCycle
,AccountVote
VoteStore: the contract vote key
35,000 Energy = 7 * 5000
7 key changes:
dynamiceStore: TOTAL_NET_WEIGHT
AccountStore: the contract account key
delegateStore: Remark
,BeginCycle
,EndCycle
,AccountVote
VoteStore: the contract vote key
35,000 Energy = 7 * 5000
5 key changes:
ccountStore: the contract account key
delegateStore: Remark
,BeginCycle
,EndCycle
,AccountVote
25,000 Energy = 5 * 5000
20 Energy
20 Energy