How we Calculate EOS Resource Usage

Alex Binesh
Shyft Network
Published in
7 min readApr 21, 2019

Hello, my name is Alex Binesh and I’m a systems engineer here at Shyft Network. For the uninitiated, Shyft is a blockchain platform aimed at interoperability between both distributed and traditional networks.

This article will attempt to shed light on the method by which resource usage in the EOSIO Blockchain is calculated and priced. Given that at Shyft Network we use Merkle Tree Proofs (MTP) extensively in our algorithms, here we shall utilize an MTP Opcode in the form of a Dapp we have created in EOSIO to do a sample resource usage calculation.

  1. Resource types:

There are three types of resources consumed by accounts:

a) State Storage (RAM)

b) Bandwidth and Log Storage (Network)

c) Computation and Computational Backlog (CPU)

2. Resource usage

a) RAM: Blockchain state storage contains information that is accessible from application logic. It includes information such as order books and account balances

b) Network: Bandwidth is measured as average consumption in bytes over the last 3 days. Net bandwidth is temporarily consumed every time you send an action or transaction

c) CPU: Bandwidth is measured as average consumption in microseconds over the last 3 days. CPU bandwidth is temporarily consumed when you send an action or transaction

3. Resource allocation

Network, CPU — staking

The Bandwidth and CPU are allocated in proportion to the amount of tokens held in a 3-day staking contract. As time goes by, the consumed Network and the CPU free up, and you can use the same staked tokens again and again.

RAM — market purchase

RAM needs to be purchased at the Market Price which follows Bancor Algorithm. Unlike CPU and bandwidth, RAM doesn’t get freed up automatically. The only way to free it up is to delete data from the account state. Once freed up, the RAM can be sold at the market price.

4. Resource price calculator

a) RAM Price

When you buy RAM, you’re buying from the contract. When you sell RAM, you sell to the contract. You pay EOS and get RAMCORE tokens which entitles you to store as much RAM as your RAMCORE tokens allow:

( ( RAMCORE held / Total RAMCORE supply ) * Total RAM bytes available )

Your EOS is added to the connector balance and the RAMCORE tokens are created on the spot and added to the outstanding supply. The opposite occurs when you sell your RAMCORE token thus effectively releasing your right to occupy that RAM. Your EOS given to you is deducted from the connector balance and the RAMCORE tokens are destroyed.

Each time someone buys or sells RAM a 1% fee is applied (to both sides of the transaction meaning 2% total). This helps reduce speculation (the fee is ten times what a normal exchange would charge) and also serves to reduce the overall inflation as these fees collected are removed from circulation i.e. burned.

Speculators are further discouraged because at any point more RAM could be added by block producers (who actually supply the RAM) essentially flooding the market with supply and crashing the price.

b) User Cost on EOS

In EOS every user account costs money to the developer. To be exact, 4KB RAM per user. For more information, please see the EOS Resource Planner.

c) RAM Price Calculation

To calculate the RAM price we should use Bancor Algorithm (see section 3.1).

RAM price and availability fluctuates over time so the below is just an example.

At the command line in Linux the below directive the output for this example can be obtained:

$ cleos -u http://nodes.get-scatter.com:80 get table eosio eosio rammarket{“supply”: “10000000000.0000 RAMCORE”,“base”:{“balance”: “35044821247 RAM”, //Smart Token’s Outstanding supply“weight”: “0.50000000000000000”},“quote”:{“balance”: “3158350.8754 EOS”, //Connector Balance“weight”: “0.50000000000000000” // CW or Quote Wait}
  • Connector Balance = quote.balance
  • Smart Token’s Outstanding supply = base.balance
  • CW = quote.weight (More on CW a little later.)
  • EOS is the connector, RAMCORE is the smart token paid for with EOS to buy RAM

RAM price/Kib = Connector Balance / (Smart Token’s Outstanding supply × CW)

= (3158350.8754 EOS / 35044821247 RAM) X 0.50 = 0.09 EOS/Kib

d)- NET/CPU Price:

These resources depend on block producer.

Here is an example for eosnewyorkio producer

$ cleos -u https://api.eosnewyork.io/ get account eosnewyorkio

Network bandwidth:

staked: 900.0000 EOS (total stake delegated from account to self)

delegated: 0.0010 EOS (total staked delegated to account from others)

used: 200 bytes

available: 578.4 MiB

limit: 578.4 MiB

CPU bandwidth:

staked: 900.0000 EOS (total stake delegated from account to self)

delegated: 0.0000 EOS (total staked delegated to account from others)

used: 10.91 ms

available: 1.864 min

limit: 1.864 min

Net Price = (Net Staked / Net Available) / 3

= 900.0000 / (578.4*1024) / 3 = 0.0005 EOS/KiB/Day

CPU Price = (CPU Staked / CPU Available) / 3

= 900.0000/(1.864*60*1000)/3 = 0.0025 EOS/ms/Day

You can check the current resource price at: https://www.eosrp.io/#calc

5)- Merkle Tree Proof (MTP) EOS DApp resource (CPU/NET/RAM) calculation

Assumptions:

  • EOS, RAM, CPU, and NET prices are calculated based on Section 4 above
  • EOS Price of $5
  • Price Of RAM = 0.09 EOS/Kib
  • There is no data to be stored on EOS DB by the DApp
  • RAM Prices are as per section 4 Above and are not volatile before and after the execution of the DApp
  • RAM is NOT sold back after the DApp execution is complete, hence only a %1 commission is charged instead of an additional %1 for reselling the RAM.
  • There are no concurrent MTP DApps requiring staking of additional EOS tokens
  • Given that the size of the wast file for the DApp is 15388 bytes, it is rounded up to 16 KiB for the network traffic calculation
  • There are 125 users accessing the DApp on a daily basis
  • Each user conducts 5 transactions per second
  • Normally, each 200 bytes transaction takes 1ms for CPU, so 16KiB should take 80 ms.
  • For CPU and NET, a 3 day supply of bandwidth is assumed since the calculation by the system is done over a previous 3-day consumption. Hence multiplication of a day’s amount for each by 3.

More on CW

Traditionally, price discovery is achieved through buying and selling with bids and asks. Liquidity, or the relative ability to move larger sums of assets with low price slippage, was created by market makers, or large financial institutions whose job it is to continue buying and selling.

Bancor’s price discovery is dictated by a formula. This effectively removes the need for market makers to exist. The Bancor algorithm is always available to trade with and will show you the guaranteed price of your order (no matter how large..) before you place it. The formula for price is below.

When you buy, you’re buying from the contract. When you sell, you sell to the contract. There is not another person, also known as a counter-party, that is picking up the other end of your trade. In buying, you pay EOS and get RAMCORE tokens which entitle you to store as much RAM as your RAMCORE tokens allow:

( ( RAMCORE held / Total RAMCORE supply ) * Total RAM bytes available )

Your EOS is added to the connector balance and the RAMCORE tokens are created on the spot and added to the outstanding supply. The opposite occurs when you sell your RAMCORE token thus effectively releasing your right to occupy that RAM. Your EOS given to you is deducted from the connector balance and the RAMCORE tokens are destroyed.

Connector balance = how much EOS is held in reserve to conduct trading

Smart Token’s outstanding supply = Total RAMCORE tokens (100 trillion (with 4 decimal places comes to 10B)

Smart Token’s total value = price × Smart Token supply (10 billion RAMCORE)

(Source | Bancor White Paper)

You can find the connector weight with the following command:

cleos -u https://nodes.get-scatter.com:443 get table eosio eosio rammarket{
“rows”: [{
“supply”: “10000000000.0000 RAMCORE”,
“base”: {
“balance”: “11870290976 RAM”,
“weight”: “0.50000000000000000”
},
“quote”: {
“balance”: “5789275.3804 EOS”,
“weight”: “0.50000000000000000”
}
}
],
“more”: false
}

The CW is expressed as a percentage greater than 0% and up to 100%, and is initially set by the creator when a Smart Token is configured. The value chosen for the CW has significant implications for the pricing of the token

The higher the CW % the less volatility there is. The reason the CW exists is to prevent the reserve value of EOS tokens from being depleted, i.e., the price lowers drastically as the supply goes down to prevent others from being able to receive value from selling as they will receive less and less. Here is a photo that illustrates some of the CW rates and their corresponding affect on price as supply reaches 100%.

The formula for how many RAMCORE tokens you will get for your EOS when you buy:

The formula for how many EOS you will get back for your RAMCORE when you sell:

Thanks for reading! We’ll be sharing some more technical posts like this one in the coming days as we prep Shyft’s Mainnet launch.

--

--

Alex Binesh
Shyft Network

Telecommunication and Blockchain Engineer interested in the latest trends and challenges in both fields specially Blockchain