Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions tip-156.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
```
tip: 156
title: Vote instructions in TVM
author: taihao.fu@gmail.com
status: Draft
type: Standards Track
category : Core
created: 2020-06-03

```

## Simple Summary

To provide vote related operations in TVM.

## Abstract

Vote & withdrawBalance operation in system contract are introduced, smart contract can vote for witness and get reward from the system.

## Motivation

Common user can vote for activated witness to get block reward. However, none privatekey accounts, like smart contracts, can't get benefit from this incentive mechanism. This TIP provide instructions to implement the incentive functionalities.

## Specification

The following instructions are introduced:

### `0xd9`: `VOTE`

The `VOTE` takes 4 operands pop up from stack:
`witnessOffset`: witness information offset.
`witnessSize`: witness information size.
`tronPowerOffset`: tron power information.
`tronPowerSize`: tron power information array size.

TVM will get sr array from memory by using `witnessOffset` and `witnessSize`.
TVM will get tron power nubmer array from memory by using `tronPowerOffset` and `tronPowerSize`.

Execute vote function and push 0 to stack if fail, push 1 otherwize.

### `0xda`: `WITHDRAWBALANCE`

The `WITHDRAWBALANCE` takes 1 operand from stack.
`accountAddress`: target account address.

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

### `0xdb`: `REWARDBALANCE`

The `REWARDBALANCE` takes 1 operand from stack.
`accountAddress`: target account address.

Push the block reward balance of the target address to stack.

### `0xdc`: `ISWITNESS`

The `ISWITNESS` takes 1 operand from stack.
`accountAddress`: target account address.

Push 0 if target address is not a witness, otherwise push 1.

## Rationale

`VOTE` tier.ExtTier
`WITHDRAWBALANCE` tier.ExtTier
`REWARDBALANCE` tier.ExtTier
`ISWITNESS` tier.ExtTier
77 changes: 77 additions & 0 deletions tip-157.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
```
tip: 156
title: Freeze instructions in TVM
author: taihao.fu@gmail.com
status: Draft
type: Standards Track
category : Core
created: 2020-06-03

```

## Simple Summary

To provide freeze related operations in TVM.

## Abstract

Freeze & Unfreeze operation in system contract are introduced, smart contract can freeze and get resource from the system.

## Motivation

Common user can freeze TRX to get resource, such as TRON power, bandwidth, energy. However, none privatekey accounts, like smart contracts, can't get al resources from the staking mechanism. This TIP provide instructions to get resource, so that smart contracts can provide tron power for voting and aslo provide resource delegation to others.

## Specification

The following instructions are introduced:

### `0xd5`: `FREEZE`

The `FREEZE` takes 4 operands pop up from stack:
`delegatedAddress`: the target address to delegate frozen TRX generated resource to.
`freezeAmount`: TRX amount to freeze in SUN.
`day`: time duration willing to freeze TRX in day.
`resourceType`: 0 as bandwidth, 1 as energy.

Execute freeze function and push 0 to stack if fail, push 1 otherwize.

### `0xd6`: `UNFREEZE`

The `UNFREEZE` takes 2 operands from stack.
`delegatedAddress`: the target address to delegate frozen TRX generated resource to.
`resourceType`: 0 as bandwidth, 1 as energy.

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

### `0xd7`: `BANDWIDTHVAlUE`

The `BANDWIDTHVAlUE` takes 1 operand from stack.
`accountAddress`: target account address.

Push current frozen generated bandwidth value of the target address to stack.

### `0xd8`: `ENERGYVALUE`

The `ENERGYVALUE` takes 1 operand from stack.
`accountAddress`: target account address.

Push current frozen generated energy value of the target address to stack.

## Rationale

### Tier

`FREEZE` tier.ExtTier
`UNFREEZE` tier.ExtTier
`BANDWIDTHVAlUE` tier.ExtTier
`ENERGYVALUE` tier.ExtTier

### Selfdestruct

When selfdestruct is executed, 2 cases need to be considered:

1. Any type of account A delegates its resource to contract B and B selfdestruct itself to address C.
Now, C should preserve the delegated resource from A.

2. Contract A delegates its resource to any type of account B and A selfdestruct itself to address C.
Now, C should preserve the privilege that delegate resource to B. C can't unfreeze its delegation with B until frozen time exceed to the expiration date,.