Skip to content

Commit

Permalink
makes examples truthful
Browse files Browse the repository at this point in the history
  • Loading branch information
m4sterbunny committed Dec 4, 2023
1 parent 8278497 commit 44bc5e7
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 38 deletions.
15 changes: 9 additions & 6 deletions docs/operating/transaction-gas.mdx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
title: Fees & Gas
proofedDate: na
proofedDate: 20231204
iterationBy: na
includedInSite: true
approvedBy: na
comment: wip items inline
comment: todo the zero gas for testing setup (see commented out section)
---

import Formula from '../single-source-snippets/_price_formula.mdx'
Expand Down Expand Up @@ -32,7 +32,7 @@ The Neon EVM calculates gas usage by tracking the SOL spent by the Neon Operator

### Pass on gas savings

Because the Neon EVM operates on Solana, not Ethereum it takes advantage of Solana’s inexpensive transaction costs and favourable approach to only charge for storage allocation. This contrasts with Ethereum, where calculations require much more gas, and gas is charged for every change in data stored in Ethereum. As a result, gas usage on Solana is much cheaper than on Ethereum, and the Neon EVM passes these savings on to users.
Because the Neon EVM operates on Solana, not Ethereum, it takes advantage of Solana’s inexpensive transaction costs and favorable approach to only charge for storage allocation. This contrasts with Ethereum, where calculations require much more gas, and gas is charged for every change in data stored in Ethereum. As a result, gas usage on Solana is much cheaper than on Ethereum, and the Neon EVM passes these savings on to users.


## Gas price: the Operator fee
Expand All @@ -43,9 +43,9 @@ The Neon Proxy obtains the current prices of SOL and NEON tokens from the [pyth.

> This ensures that the Neon Operator receives enough NEON to cover the transaction cost in SOL.
The Neon Operator configures the value of `PRX_OPERATOR_FEE` where 1.0 represents 100% of the potential fee extraction. The value of this parameter is currently set to **1**.
The Neon Operator configures the value of `PRX_OPERATOR_FEE`, where 1.0 represents 100% of the potential fee extraction. The value of this parameter is currently set to **1**.

Parameter `PRX_GAS_PRICE_SLIPPAGE` represents a buffer that is needed to skip transactions getting stucked in the mempool when there is spike in prices of $SOL and $NEON. The value of this parameter is currently set to **0.99**.
Parameter `PRX_GAS_PRICE_SLIPPAGE` provides a buffer against transactions getting stuck in the mempool if there is volatility in prices of $SOL and $NEON. The value of this parameter is currently set to **0.25**.

For example:
<Price/>
Expand Down Expand Up @@ -76,9 +76,12 @@ The Neon Proxy has several settings that accommodate the calculation of gas-pric
- `PRX_PYTH_MAPPING_ACCOUNT`: the Solana address of the Pyth mapping account; select the address on (https://pyth.network/developers/accounts) based on the type of network (Devnet/Mainnet)
- `PRX_UPDATE_PYTH_MAPPING_PERIOD_SEC`: the time period to reread the Pyth mapping account. The Neon Proxy reads the Pyth mapping account at the start, gets the addresses of $NEON and $SOL accounts, and rechecks the address from the Pyth Mapping account only after `UPDATE_PYTH_MAPPING_PERIOD_SEC`. It is recommended to set this generously (e.g. 1/3/10 hours), because the price feed accounts don’t change often.
- `PRX_MINIMAL_GAS_PRICE`: the minimum gas price to accept transactions into the mempool for on-chain execution

<!--

> Let's take a closer look at the minimum gas price variable.

<!-- ## Zero gas price for testing
## Zero gas price for testing

On Devnet test NEON is available, however, for beta Mainnet testing purposes, the Neon Proxy can be configured to accept transactions with a 0 gas price (a balance of SOL is available to cover the transaction fees on Solana).

Expand Down
14 changes: 7 additions & 7 deletions docs/single-source-snippets/_gas_price_calc.mdx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
| Component | Value | Units/Definition | Calculation |
| ------------------------ | ------------ | ---------------- | ----------- |
| Sol | 30 | $ | |
| Neon | 0.25 | $ | |
| Sol | 50 | $ | |
| Neon | 0.5 | $ | |
| Ratio | | SOL:NEON | 120 |
| Galan ratio | | Ratio \*10-9 | 0.00000012 |
| Operator fee ratio | 0.1 | | |
| Proxy Gas Price Slippage | 0.99 | | |
| Galan ratio | | Ratio \*10<sup>-9</sup> | 0.00000012 |
| Operator fee ratio | 1 | | |
| Proxy Gas Price Slippage | 0.25 | | |
| Adjustor | | 1+fee+slippage | 2.09 |
| **Gas price** | **0.0000002508** | NEON | [Gas price formula](#gas-price) |
| | **250.8** | Galan |
| **Gas price** | **0.0000002475** | NEON | [Gas price formula](#gas-price) |
| | **247.5** | Galan |
65 changes: 40 additions & 25 deletions docs/tokens/gas_fees.mdx
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
---
title: Gas Fees
proofedDate: na
proofedDate: 20231204
iterationBy: na
includedInSite: true
approvedBy: na
comment: Calc sheet https://docs.google.com/spreadsheets/d/1g2ms3DveyPgrG0Gf6cSwq6xhT0AgrrRus_pa9ICHP4w/edit?usp=sharing
---


import Formula from '../single-source-snippets/_price_formula.mdx'
import Price from '../single-source-snippets/_gas_price_calc.mdx'

## TL;DR

- `Gas Fee` = `Gas amount` \* `Gas price`
- [`Gas price`](#gas-price) dedends on the SOL:NEON ratio and Proxy Operator fee
- [`Gas price`](#gas-price) depends on the SOL:NEON ratio and Proxy Operator fee
- [`Gas amount`](#gas-amount) depends on the computational resources as per Solana's rules
- The first transaction (one which requires account setup), is more expensive than subsequent txs
- The first transaction (i.e. requires account setup), is [more expensive](#example-2-create-a-new-account) than subsequent transactions


## Introduction
Expand All @@ -41,23 +40,25 @@ On a high level, gas fee payments in the Neon EVM work as follows:

</div>

As depicted in the diagram above, users of dApps built on the Neon EVM pay for all the resources they consume, in addition to Operator fees (that may differ between Operators). Operators pay for the resources they consume in SOL. Specifically, Operators pay Solana validators and governance fees in SOL. Operators pay the same amount for governance as they pay to Solana validators (for the signature validation).
As depicted in the diagram, users of dApps built on the Neon EVM pay for all the resources they consume plus the Operator fees (that may differ between Operators). Operators pay for the resources they consume in SOL. Specifically, Operators pay Solana validators and governance fees in SOL. Operators pay the same amount for governance as they pay to Solana validators (for the signature validation).

### Gas amount

The **gas amount** is the amount of computational resources, such as CPU time and storage, used to execute the transaction. The gas amount is calculated in accordance with Solana's rules (in fact, 1 gas unit = 1 lamport) as a sum of the following amounts:
* The **computational cost**, which is 5,000 units for each transaction (Solana charges 5,000 lamports for the signature validation for each transaction). This amount goes to Solana validator. This computational cost is **doubled** to give the same amount of gas fees to the **DAO Treasury**.
* The **storage cost**, which is 6,960 units for each newly allocated byte (Solana charges 6,960 lamports for each byte), while re-use of existing or already-allocated storage is free.
The **gas amount** is the amount of computational resources, such as CPU time and storage, used to execute the transaction. The gas amount is calculated in accordance with Solana's rules (in fact, 1 gas unit = 1 Lamport) as a sum of the following amounts:
* The **computational cost**
> 5,000 units for each transaction (Solana charges 5,000 Lamports for the signature validation for each transaction). This amount goes to Solana validator. This computational cost is **doubled** to give the same amount of gas fees to the **DAO Treasury**.
* The **storage cost**
> 6,960 units for each newly allocated byte (Solana charges 6,960 Lamports for each byte), while re-use of existing or already-allocated storage is free.
For example, for a Neon transaction with N iterations and S newly allocated bytes, the *gas amount* will be:

> 2 \* (computational cost + storage cost)
> 2(computational cost) + storage cost
> = 2 \* (5,000 \* N + 6960 \* S units)
> = 2(5,000 \* N) + (6960 \* S units)
### Gas price

The **gas price** is the cost of 1 unit of gas in NEON. This price is calculated using the price of SOL:NEON multiplied by an adjustor:
The **gas price** is the cost of 1 unit of gas in NEON. This price is calculated using the price of SOL:NEON multiplied by an adjuster that is configured by the Proxy Operator:

<Formula/>

Expand All @@ -68,40 +69,54 @@ The following examples of gas fee calculations on Neon are all based on these as

<Price/>

### Example 1: swap
### Example 1: swap or transfer

If the spend is already approved from an account that already exists, we can use the following Gas amount with the Gas price as calculated above.

With the Gas price at 250.8 Galan, the Gas amount can be calulated with N=2 iterations and S=5 storage costs:
The Gas amount is calculated with N=1 iterations and S=0 storage costs:

| Component | Value | Units/Definition | Calculation |
| ------------------ | ---------- | ------------------ | ---------------------------- |
| Computational cost | 2 | iterations \* 5000 | 1000 |
| Storage cost | 5 | bytes \* 6960 | 34800 |
| Computational cost | 1 | iterations \* 5000 | 1000 |
| Storage cost | 0 | bytes \* 6960 | 34800 |
| Gas amount | 54800 | Lamports | (2\*computational) + storage |
| | | | |
| **Gas Fee** | **0.01374384** | NEON | gas price \* gas amount |
| **Gas Fee** | **0.002475** | NEON | [gas price](#examples) \* gas amount |

### Example 2: create a new account
Within [Solana](https://docs.solana.com/storage_rent_economics), the rental cost for storage can be paid via one of two methods:
1. Set it and forget it.

> With this approach, accounts with two years' worth of rent deposited are exempt from network rent charges. By maintaining this minimum balance, the broader network benefits from reduced liquidity and the account holder can rest assured that their data will be retained for continual access and usage.
> With this approach, accounts with two years' worth of rent deposited are exempt from network rent charges. By maintaining this minimum balance, the broader network benefits from reduced liquidity and the account holder can rest assured that their data is retained for continual access and usage.
2. Pay per byte.

> The network can charge rent on a per-epoch basis, in credit for the next epoch. This rent is deducted at a rate specified in genesis, in lamports per kilobyte-year.
> The network can charge rent on a per-epoch basis, in credit for the next epoch. This rent is deducted at a rate specified in genesis, in Lamports per Kilobyte-year.
To simplify the user experience, Neon takes option 1 and charges two years' worth of rent deposits for each new account. The gas cost of creating a new account is:
> 0 \* 2 \* 5,000 (computational cost + treasury) + (128 + 71) \* 6960 (storage cost for the minimum Neon account size) ≈ 1,400,000 units

Therefore, the total gas fee is 1,400,000 units \* 132 Galan = 0.1848 NEON tokens.

### Example 3: transfer
| Component | Value | Units/Definition | Calculation |
| ------------------ | ---------- | ------------------ | ---------------------------- |
| Computational cost | 1 | iterations \* 5000 | 1000 |
| Storage cost | 199 | bytes \* 6960 | 34800 |
| Gas amount | 1395040 | Lamports | (2\*computational) + storage |
| | | | |
| **Gas Fee** | **0.3452724** | NEON | [gas price](#examples) \* gas amount |


In the case of a transfer of NEON or ERC-20 tokens, from an existing account, the gas amount is:
> 1 \* 2 \* 5,000 (computational cost + treasury) + 0 \* 6,960 (storage cost in case the account exists) ≈ 10,000 units

Therefore, the total gas fee is 10,000 units * 132 Galan = 0.00132 NEON tokens.
### Example 3: create a pool in Sobal

| Component | Value | Units/Definition | Calculation |
| ------------------ | ---------- | ------------------ | ---------------------------- |
| Computational cost | 32 | iterations \* 5000 | 1000 |
| Storage cost | 10000 | bytes \* 6960 | 34800 |
| Gas amount | 69920000 | Lamports | (2\*computational) + storage |
| | | | |
| **Gas Fee** | **17.3052** | NEON | [gas price](#examples) \* gas amount |


## What next?

If you want to get your dApp started on Neon EVM you may be wondering how you pay for the first transactions that are required to buy the NEON required to cover gas costs. This is where our starter pack of [gasless transactions](/docs/developing/gasless) comes in and our "coming soon" feature will allow users to pay fees in [alternative tokens](https://neonevm.org/blog/feature-alternative-gas-fee-token).
If you want to get your dApp started on Neon EVM, you may be wondering how you pay for the first transactions that are required to buy the NEON required to cover gas costs. This is where our starter pack of [gasless transactions](/docs/developing/gasless) comes in. Furthermore, our "coming soon" feature will allow users to pay fees in [alternative tokens](https://neonevm.org/blog/feature-alternative-gas-fee-token).

0 comments on commit 44bc5e7

Please sign in to comment.