Skip to content

Latest commit

 

History

History
111 lines (67 loc) · 3.04 KB

tip-157.md

File metadata and controls

111 lines (67 loc) · 3.04 KB
tip:  157
title: Freeze instructions in TVM
author: [email protected]
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 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: BANDWIDTH

The BANDWIDTH takes 1 operand from stack.

accountAddress: target account address.

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

0xd8: ENERGY

The ENERGY takes 1 operand from stack.

accountAddress: target account address.

Push current current energy left in the target address to stack.

Result show in SystemLog

As introduced in TIP156, a system log structure for freeze & unfreeze can be defined as below:

message SystemLog {
  enum operationType {
    VOTE = 1;
    WITHDRAWREWARD = 2;
    FREEZE = 3;
    UNFREEZE = 4;
  }
  bytes address = 1; // user address or contract address
  repeated bytes params = 2;
  // FREEZE contains 4 parameters: FREEZE(delegatedAddress, freezeAmount, frozenDay, resourceType);
  // WITHDRAWREWARD contains 2 parameters: UNFREEZE(delegatedAddress, resourceType);
  
  operationType type = 3;
}

Freeze and Unfreeze infomation will be record in the SystemLog field in transactionInfo.

Rationale

Tier

FREEZE tier.ExtTier

UNFREEZE tier.ExtTier

BANDWIDTH tier.ExtTier

ENERGY 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,.