Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update documentation with new gas estimation #61

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ Below is an example from criseth's pathfinder for transferring 1000 CRC between


## Gas limitations
Each transfer in a transitive transaction costs gas. Transactions made through [circles.garden](https://circles.garden) are paid for by the Circles Coop in Eth. In terms of CRC a small fee in circles is added for each transaction to "compensate" for this.
Each transfer in a transitive transaction costs gas. Transactions made through [circles.garden](https://circles.garden) are paid for by the Circles Coop in xDai. In terms of CRC a small fee in circles is added for each transaction to "compensate" for this.

On the Ethereum blockchain all contract calls or transactions end up inside a block. A block is either accepted or rejected on the blockchain.
All transactions in a transitive transaction should end up in the same block to make sure that all or none of the transfer steps go through. The maximum gas for a block is 12.500.000. This means that the total gas cost for a transitive transaction must not exceed this.
On Gnosis Chain all contract calls or transactions end up inside a block. A block is either accepted or rejected on the blockchain.
All transactions in a transitive transaction should end up in the same block to make sure that all or none of the transfer steps go through. The maximum gas for a block is 30.000.000. This means that the total gas cost for a transitive transaction must not exceed this.

In practice it is dangerous to get close to this limit. A transaction with a gas cost close to this limit might have to wait a very, very long time to fit into a block with other contract calls, because of how the Ethereum blockchain works.
In practice it is dangerous to get close to this limit. A transaction with a gas cost close to this limit might have to wait a very, very long time to fit into a block with other contract calls, because of how the Ethereum blockchains work.


## What this means in terms of number of transfer steps
Because of the limitations to the gas costs we have to set a maximum limit to the number of transfer steps in a transaction. This limit is currently set to 52. Here we explain why.
Because of the limitations to the gas costs we have to set a maximum limit to the number of transfer steps in a transaction. This limit is currently set to 40. Here we explain why.

Following the steps in [this tutorial](../tutorials/estimate-gas-cost.md) gas costs for a number of hypothetical transactions were estimated. The results are displayed in this figure:

Expand Down
33 changes: 16 additions & 17 deletions docs/developers/tutorials/estimate-gas-cost.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ This tutorial is made for finding the transfer steps that the circles api would
- The checksummed* address of another account you want to transfer to

### To estimate the gas cost you will also need:
- A metamask account connected to the first circles account
- A Metamask account connected to the first circles account
- You can follow [this guide](gnosis-safe-as-wallet.mdx)
- Switch from Ethereum mainnet to the xDai network. To add xDai chose custom RCP under Networks and specify the following:
- name: xdai
- URL: https://xdai.poanetwork.dev
- [Switch from Ethereum mainnet to the Gnosis Chain network](https://docs.gnosischain.com/tools/wallets/metamask/). To add Gnosis Chain chose "Add Network" under "Networks" and specify the following:
- name: Gnosis
- URL: https://rpc.gnosischain.com
- Chain ID: 100
- Symbol: xDai
- Block Explorer URL: https://gnosisscan.io

*A checksummed address will contain some capital letters unlike the non-checksummed address.

Expand Down Expand Up @@ -84,18 +86,17 @@ transfers.data.transferSteps.forEach(transfer =>{
amounts.push(transfer.value);
});

console.log({
tokenOwnerAddresses,
srcs,
dests,
amounts
});
console.log(JSON.stringify(tokenOwnerAddresses));
console.log(tokenOwnerAddressestoString());
console.log(JSON.stringify(srcs));
console.log(JSON.stringify(dests));
console.log(JSON.stringify(amounts));
```
Then remove white spaces and make sure quotations are double quotations.
Then make sure there are no quotations in the elements list.

4. **Get the hex data for the transaction**

Now that you have the lists of `tokenOwnerAddresses`, `srcs`, `dests` and `amounts`, go to [the circles Hub on blockscout](https://blockscout.com/xdai/mainnet/address/0x29b9a7fBb8995b2423a71cC17cf9810798F6C543/transactions).
Now that you have the lists of `tokenOwnerAddresses`, `srcs`, `dests` and `amounts`, go to [the circles Hub on blockscout](https://gnosisscan.io/address/0x29b9a7fBb8995b2423a71cC17cf9810798F6C543#writeContract).
In the "Write Contract" tab:
- connect to your metamask account
- use "3.transferThrough" and paste the value arrays from above
Expand All @@ -107,9 +108,7 @@ In the "Write Contract" tab:
Running this curl command (it needs the checksummed safe address, which you can find it in your circles wallet and the hex data)

```shell=fish
curl -X POST "
https://relay.circles.garden/api/v2/safes/
<SAFE_ADDRESS>/transactions/estimate/" -H "Content-Type: application/json" -H "accept: application/json" -d '{ "safe": "<SAFE_ADDRESS>", "data": "<HEX_DATA>", "to": "0x29b9a7fBb8995b2423a71cC17cf9810798F6C543", "value": 0, "operation": 0, "gasToken": "0x0000000000000000000000000000000000000000" }'
curl -X POST "https://relay.circles.garden/api/v2/safes/<SAFE_ADDRESS>/transactions/estimate/" -H "Content-Type: application/json" -H "accept: application/json" -d '{ "safe": "<SAFE_ADDRESS>", "data": "<HEX_DATA>", "to": "0x29b9a7fBb8995b2423a71cC17cf9810798F6C543", "value": 0, "operation": 0, "gasToken": "0x0000000000000000000000000000000000000000" }'
```
returns the gas information like this:
```json
Expand All @@ -125,6 +124,6 @@ returns the gas information like this:
}
```

The total gas is `safeTxGas + baseGas`. In the example above, the total gas is then `4.159.332` (which under the `12.500.000` gas per block limit).
The total gas is `safeTxGas + baseGas`. In the example above, the total gas is then `4.159.332` (which is under the gas per block limit).

The gas price is specified in Wei and is constant on the xDai network.
The [gas limit per block changes over time](https://gnosisscan.io/chart/gaslimit) and currently it's `30.000.000`. The [gas price](https://gnosisscan.io/chart/gasprice) is specified in Gwei and it fluctuates over time in Gnosis Chain (average is around 7 Gwei).