# Resource Model¶

## Introduction¶

STABILA network has 4 types of resources: Bandwidth, CPU, Storage and RAM. Benefit by STABILA's exclusive RAM model, STABILA's RAM resource is almost infinite.

STABILA network imports two resource conceptions: Bandwidth points and Ucr. Bandwidth Point represents Bandwidth, Ucr represents CPU and Storage.

Note

• Ordinary transaction only consumes Bandwidth points
• Smart contract related transaction not only consumes Bandwidth points, but also Ucr

## Bandwidth Points¶

The transaction information is stored and transmitted in the form of byte array, Bandwidth Points consumed = the number of bytes of the transaction * Bandwidth Points rate. Currently Bandwidth Points rate = 1.

Such as if the number of bytes of a transaction is 200, so this transaction consumes 200 Bandwidth Points.

Note

Due to the change of the total amount of the staked STB in the network and the self-staked STB amount, the Bandwidth Points an account possesses is not fixed.

### 1. How to Get Bandwidth Points¶

1. By staking STB to get Bandwidth Points, Bandwidth Points = the amount of STB self-staked / the total amount of STB staked for Bandwidth Points in the network * 43_200_000_000
2. Every account has a fixed amount of free Bandwidth Points(5000) every day

### 2. Bandwidth Points Consumption¶

Except for query operation, any transaction consumes Bandwidth points.

There's another situation: When you transfer(STB or token) to an account that does not exist in the network, this operation will first create that account in the network and then do the transfer. It only consumes Bandwidth points for account creation, no extra Bandwidth points consumption for transfer.

To create an account, a flat charge of 1 STB is required. If there are insufficient Bandwidth points obtained by STB staking, an additional 0.1 STB will be spent.

Bandwidth points consumption sequence for SRC-10 transfer:

1. Free Bandwidth points.

2. SRC-10 issuer's Bandwidth points(if possible.)

3. Bandwidth points STB staking.

4. Bandwidth points obtained by STB burning, the rate = the number of bytes of the transaction * 1_000 UNIT;

Bandwidth points consumption sequence for other transactions:

1. Free Bandwidth points.

2. Bandwidth points STB staking.

3. Bandwidth points obtained by STB burning, the rate = the number of bytes of the transaction * 1_000 UNIT;

### 3. Bandwidth Points Recovery¶

Every 24 hours, the amount of the usage of Bandwidth points of an account will be reset to 0. For the specific formula:

$$U^\prime = ( 1 - \frac{T_2 - T_1}{24h} ) * U + u$$

Every 24 hours, the amount of the usage of Bandwidth points of an account will be reset to 0.

## Ucr¶

Each command of smart contract consume system resource while running, we use 'Ucr' as the unit of the consumption of the resource.

### 1. How to Get Ucr¶

Stake STB to get ucr.

Example (Using wallet-cli):

cdBalance cded_balance cded_duration [ResourceCode:0 BANDWIDTH,1 UCR]


stake STB to get ucr, ucr obtained = user's STB staked amount / total amount of staked STB in STABILA * 50_000_000_000.

Example:

If there are only two users, A stakes 2 STB, B stakes 2 STB
the ucr they can get is:
A: 25_000_000_000 and ucr_limit is 25_000_000_000
B: 25_000_000_000 and ucr_limit is 25_000_000_000

when C stakes 1 STB:
the ucr they can get is:
A: 20_000_000_000 and ucr_limit is 20_000_000_000
B: 20_000_000_000 and ucr_limit is 20_000_000_000
B: 10_000_000_000 and ucr_limit is 10_000_000_000


#### Ucr Recovery¶

The ucr consumed will reduce to 0 smoothly within 24 hours.

Example:

at one moment, A has used 72_000_000 Ucr
if there is no continuous consumption or STB stake
one hour later, the ucr consumption amount will be 72_000_000 - (72_000_000 * (60*60/60*60*24)) Ucr = 69_000_000 Ucr
24 hours later, the ucr consumption amount will be 0 Ucr


### 2. How to Set Fee Limit (Caller Must Read)¶

Within the scope of this section, the smart contract developer will be called "developer", the users or other contracts which call the smart contract will be called "caller"

The amount of ucr consumed while call the contract can be converted to STB or UNIT, so within the scope of this section, when refer to the consumption of the resource, there's no strict difference between Ucr, STB and UNIT, unless they are used as a number unit.

Set a rational fee limit can guarantee the smart contract execution. And if the execution of the contract cost great ucr, it will not consume too much ucr from the caller. Before you set fee limit, you need to know several conception:

1. The legal fee limit is a integer between 0 - 10^9, unit is UNIT.
2. Different smart contracts consume different amount of ucr due to their complexity. The same trigger in the same contract almost consumes the same amount fo ucr1. When the contract is triggered, the commands will be executed one by one and consume ucr. If it reaches the fee limit, commands will fail to be executed, and ucr is not refundable.
3. Currently fee limit only refers to the ucr converted to UNIT that will be consumed from the caller2. The ucr consumed by triggering contract also includes developer's share.
4. For a vicious contract, if it encounters execution timeout or bug crash, all it's ucr will be consumed.
5. Developer may undertake a proportion of ucr consumption(like 90%). But if the developer's ucr is not enough for consumption, the rest of the ucr consumption will be undertaken by caller completely. Within the fee limit range, if the caller does not have enough ucr, then it will burn equivalent amount of STB 2.

To encourage caller to trigger the contract, usually developer has enough ucr.

#### Example¶

How to estimate the fee limit:

Assume contract C's last execution consumes 18000 Ucr, so estimate the ucr consumption limit to be 20000 Ucr3

According to the staked STB amount and ucr conversion, assume 1 STB = 400 ucr.

When to burn STB, 4 STB = 100000 ucr4

Assume developer undertake 90% ucr consumption, and developer has enough ucr.

Then the way to estimate the fee limit is:

1. A = 20000 ucr * (1 STB / 400 ucr) = 50 STB = 50_000_000 UNIT,
2. B = 20000 ucr * (4 STB / 100000 ucr) = 0.8 STB = 800_000 UNIT,
3. Take the greater number of A and B, which is 50_000_000 UNIT,
4. Developer undertakes 90% ucr consumption, caller undertakes 10% ucr consumption,

So, the caller is suggested to set fee limit to 50_000_000 UNIT * 10% = 5_000_000 UNIT

### 3. Ucr Calculation (Developer Must Read)¶

1. In order to punish the vicious developer, for the abnormal contract, if the execution times out (more than 50ms) or quits due to bug (revert not included), the maximum available ucr will be deducted. If the contract runs normally or revert, only the ucr needed for the execution of the commands will be deducted.

2. Developer can set the proportion of the ucr consumption it undertakes during the execution, this proportion cna be changed later. If the developer's ucr is not enough, it will consume the caller's ucr.

3. Currently, the total ucr available when trigger a contract is composed of caller fee limit and developer's share

Note

• If the developer is not sure about whether the contract is normal, do not set caller's ucr consumption proportion to 0%, in case all developer's ucr will be deducted due to vicious execution1.
• We recommend to set caller's ucr consumption proportion to 10% ~ 100%2.

Example 1

A has an account with a balance of 90 STB(90000000 UNIT) and 10 STB staked for 100000 ucr.

Smart contract C set the caller ucr consumption proportion to 100% which means the caller will pay for the ucr consumption completely.

A triggers C, the fee limit set is 30000000 (unit UNIT, 30 STB)

So during this trigger the ucr A can use is from two parts:

• A's ucr by staking STB;
• The ucr converted from the amount of STB burning according to a fixed rate;

If fee limit is greater than the ucr obtained from staking STB, then it will burn STB to get ucr. The fixed rate is: 1 Ucr = 40 UNIT, fee limit still has (30 - 10) STB = 20 STB available, so the ucr it can keep consuming is 20 STB / 100 UNIT = 200000 ucr.

Finally, in this call, the ucr A can use is (100000 + 200000) = 300000 ucr.

If contract executes successfully without any exception, the ucr needed for the execution will be deducted. Generally, it is far less than the amount of ucr this trigger can use.

If Assert-style error come out, it will consume the whole number of ucr set for fee limit.

Example 2

A has an account with a balance of 90 STB(90000000 UNIT) and 10 STB staked for 100000 ucr.

Smart contract C set the caller ucr consumption proportion to 40% which means the developer will pay for the rest 60% ucr consumption.

Developer D stakes 50 STB to get 500000 ucr.

A triggers C, the fee limit set is 200000000 (unit UNIT, 200 STB).

So during this trigger the ucr A can use is from three parts:

• A's ucr by staking STB -- X;
• The ucr converted from the amount of STB burning according to a fixed rate -- Y;

If fee limit is greater than the ucr obtained from staking STB, then it will burn STB to get ucr. The fixed rate is: 1 Ucr = 40 UNIT, fee limit still has (200 - 10) STB = 190 STB available, but A only has 90 STB left, so the ucr it can keep consuming is 90 STB / 100 UNIT = 900000 ucr;

• D's ucr by staking STB -- Z;

There are two situation: if (X + Y) / 40% >= Z / 60%, the ucr A can use is X + Y + Z if (X + Y) / 40% < Z / 60%, the ucr A can use is (X + Y) / 40%

If contract executes successfully without any exception, the ucr needed for the execution will be deducted. Generally, it is far less than the amount of ucr this trigger can use.

If Assert-style error comes out, it will consume the whole number of ucr set for fee limit.

Note: when developer create a contract, do not set consume_user_resource_percent to 0, which means developer will undertake all the ucr consumption. If Assert-style error comes out, it will consume all ucr from the developer itself.

To avoid unnecessary lost, 10 - 100 is recommended for consume_user_resource_percent.

## Resource Delegation¶

In STABILA network, an account can stake STB for Bandwidth or Ucr for other accounts. The primary account owns the staked STB and STABILA power, the recipient account owns the Bandwidth or Ucr. Like ordinary staking, resource delegation staking is also at least 3 days.

• Example(Using wallet-cli)
cdBalance cded_balance cded_duration [ResourceCode:0 BANDWIDTH,1 UCR] [receiverAddress]

cded_balance: the amount of STB to stake (unit UNIT)
cded_duration: the staking period (currently a fixed 3 days)
ResourceCode: 0 for Bandwidth, 1 for Ucr


## Other Fees¶

Type Fee
Create a executive 9999 STB
Issue a token 1024 STB
Create an account 1 STB
Create an exchange 1024 STB

1. The ucr consumption of each execution may fluctuate slightly due to the situation of all the nodes.

2. STABILA may change this policy.

3. The estimated ucr consumption limit for the next execution should be greater than the last one.

4. 4 STB = 10^5 ucr is a fixed number for burning STB to get ucr, STABILA may change it in the future.