Skip to content

Latest commit

 

History

History
139 lines (76 loc) · 3.46 KB

tip-171.md

File metadata and controls

139 lines (76 loc) · 3.46 KB
tip:  171
title: STAKE instructions in TVM
author: taihao.fu@gmail.com
status: Draft
type: Standards Track
category : Core
created: 2020-08-05

Simple Summary

To provide Staking operations in TVM.

Abstract

This is a simplified solution for PoS incentive mechanism in smart contract.

Motivation

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.

Specification

The following instructions are introduced:

0xd5: STAKE

STAKE is a TRX staking to get TRON Powever and voting SR process for a smart contract.

FACTS:

  1. STAKE ONLY available for single SR.
  2. 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:

  1. Contract stake trx as bandwidth and add the frozen amount to its Account.frozenBalance. The default staking period is 3 days.
  2. 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.

0xd6: UNSTAKE

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:

  1. 3 days after the last STAKE operation for this contract, the contract can choose to UNSTAKE its TRX.
  2. Update block produce reward balance for this contract.
  3. Unfrozne balance in contract.
  4. Contract clears vote information.

Execute UNSTAKE function and push 0 to stack if fail, push 1 otherwise.

0xd7: WITHDRAWREWARD

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.

0xd8: REWARDBALANCE

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.

0xd9: ISWITNESS

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.

Rationale

STAKE tier.ExtTier

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

UNSTAKE tier.ExtTier

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

WITHDRAWREWARD tier.ExtTier

5 key changes:

ccountStore: the contract account key

delegateStore: Remark,BeginCycle,EndCycle,AccountVote

25,000 Energy = 5 * 5000

REWARDBALANCE tier.ExtTier

20 Energy

ISWITNESS tier.ExtTier

20 Energy