Smart Contract
A smart contract is a protocol that digitally verifies contract negotiation. They define the rules and penalties related to an agreement and also automatically enforce those obligations. The smart contract code facilitates, verifies, and enforces the negotiation or performance of an agreement or transaction. From a tokenization perspective, smart contracts also facilitate automatic funds transfers between participating parties should certain criteria be met.
LGCY smart contracts are written in the Solidity language. Once written and tested, they can be compiled into bytecode, then deployed onto the LGCY Network for the LGCY Virtual Machine. Once deployed, smart contracts can be queried via their contract addresses. The contract Application Binary Interface (ABI) shows the contract’s call functions and is used for interacting with the network.
ENERGY MODEL
The maximum energy limit for deploying and triggering a smart contract is a function of several variables:
  • Dynamic energy from freezing 1 LGCY is 50,000,000,000 (Total Energy Limit) / (Total Energy Weight)
  • Energy limit is the daily account energy limit from freezing LGCY
  • Remaining daily account energy from freezing LGCY is calculated as Energy Limit - Energy Used
  • Fee limit in LGCY is set in smart contract deploy/trigger call
  • Remaining usable LGCY in the account
  • Energy per LGCY if purchased directly (10 LGCY = 1 Energy) = 100,000, GBs can vote on adjustment
There are two consumption scenarios to calculate for maximum energy limit for deployment and trigger. The logic can be expressed as follows:
const R = Dynamic Energy Limit
const F = Daily account energy from freezing LGCY
const E = Remaining daily account energy from freezing LGCY
const L = Fee limit in LGCY set in deploy/trigger call
const T = Remaining usable LGCY in account
const C = Energy per LGCY if purchased directly
// Calculate M, defined as maximum energy limit for deployment/trigger of smart contract
if F > L*R
let M = min(E+T*C, L*R)
else
let M = E+T*C
DEPLOYMENT
When a LGCY Solidity smart contract is compiled, the LGCY Virtual Machine reads the compiled bytecode. The bytecode consists of a section for code deployment, contract code, and the Auxdata. The Auxdata is the source code’s cryptographic fingerprint, used for verification. The deployment bytecode runs the constructor function and sets up the initial storage variables. The deployment code also calculates the contract code and returns it to the LVM. The ABI is a JSON file that describes a LGCY smart contract’s functions. This file defines the function names, their payability, the function return values, and their state mutability.
TRIGGER FUNCTION
Once the LGCY smart contracts are deployed, their functions can be triggered individually either via LGCYStudio or through API calls. State-changing functions require Energy while read-only functions execute without Energy.
LGCY SOLIDITY
LGCY Solidity is a fork from TRON’s Solidity language. LGCY adopted TRON’s project to support LGCY and DRIPS units (1 LGCY = 1,000,000 DRIPS). The rest of the language syntax is compatible with Solidity ^0.4.24. Thus the LGCY Virtual Machine (LVM) is almost 100% compatible with EVM and TVM instructions.
Copy link