Skip to content

Commit

Permalink
Remove brownie lib.
Browse files Browse the repository at this point in the history
  • Loading branch information
calina-c committed Aug 3, 2023
1 parent 616b0dd commit 122c3c4
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 123 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r requirements_dev.txt
brownie bake github-actions
sed -i 's#https://polygon-mainnet.infura.io/v3/$WEB3_INFURA_PROJECT_ID#https://polygon-rpc.com/#g; s#https://polygon-mumbai.infura.io/v3/$WEB3_INFURA_PROJECT_ID#https://rpc-mumbai.maticvigil.com#g' $HOME/.brownie/network-config.yaml
- name: Wait for contracts deployment
working-directory: ${{ github.workspace }}/barge
run: |
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ With ocean.py, you can:

- **Publish** data services: downloadable files or compute-to-data. Create an ERC721 **data NFT** for each service, and ERC20 **datatoken** for access (1.0 datatokens to access).
- **Sell** datatokens via for a fixed price. Sell data NFTs.
- **Transfer** data NFTs & datatokens to another owner, and **all other ERC721 & ERC20 actions** using [web3.py](https://web3py.readthedocs.io) or [Brownie](https://eth-brownie.readthedocs.io/en/latest/).
- **Transfer** data NFTs & datatokens to another owner, and **all other ERC721 & ERC20 actions** using [web3.py](https://web3py.readthedocs.io).

ocean.py is part of the [Ocean Protocol](https://www.oceanprotocol.com) toolset.

Expand Down Expand Up @@ -64,7 +64,6 @@ Each of the following shows how to publish & consume a particular type of data.
### Learn more
- [Understand config parameters](READMEs/parameters.md) - envvars vs files
- [Learn about off-chain services](READMEs/services.md) - Ocean Provider for data services, Aquarius metadata store
- [Using hardware wallets with ocean.py](READMEs/using-clef.md) - Learn how to use hardware wallets with ocean.py via Brownie and Clef

## 🦑 Development

Expand Down
10 changes: 1 addition & 9 deletions READMEs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,9 @@ Issue: MacOS "Unsupported Architecture"
Issue: Dependencies and Python 3.11

- ocean.py has two dependencies that don't support Python 3.11 yet. Here's the workaround for each.
- (1) The `eth-brownie` package uses Vyper which doesn't support Python 3.11. The workaround: before installing ocean-lib, run `pip install vyper==0.3.7 --ignore-requires-python` and `sudo apt-get install python3.11-dev`
- (1) Vyper which doesn't support Python 3.11. The workaround: before installing ocean-lib, run `pip install vyper==0.3.7 --ignore-requires-python` and `sudo apt-get install python3.11-dev`
- (2) The `parsimonious` package depends on `getargsspec`, which doesn't support Python 3.11. The workaround: open the package's expressions.py file (e.g. in ./venv/lib/python3.11/site-packages/parsimonious/expressions.py), and change the line `import getfullargspec as getargsspec` instead of the regular import.

## ocean.py uses Brownie

When you installed Ocean (`ocean-lib` pypi package) above, it included installation of Brownie (`eth-brownie` package).

ocean.py uses Brownie to connect with deployed smart contracts.

Thanks to Brownie, ocean.py treats each Ocean smart contract as a Python class, and each deployed smart contract as a Python object. We love this feature, because it means Python programmers can treat Solidity code as Python code! 🤯

## Next step

You've now installed Ocean, great!
Expand Down
8 changes: 4 additions & 4 deletions READMEs/main-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ ERC725:
- Official spec is at [eips.ethereum.org](https://eips.ethereum.org/EIPS/eip-725)
- Solidity interface: [IERC725X.sol](https://github.com/oceanprotocol/contracts/blob/main/contracts/interfaces/IERC725X.sol) (execution) and [IERC725Y.sol](https://github.com/oceanprotocol/contracts/blob/main/contracts/interfaces/IERC725Y.sol) (key-value store)

The `data_nft` is a Python object of class [DataNFT](https://github.com/oceanprotocol/ocean.py/blob/main/ocean_lib/models/data_nft.py). Thanks to Brownie, the DataNFT class directly exposes the Solidity ERC721 & ERC725 interfaces. This means your `data_nft` object has a Python method for every Solidity method! Thank you, Brownie :)
The `data_nft` is a Python object of class [DataNFT](https://github.com/oceanprotocol/ocean.py/blob/main/ocean_lib/models/data_nft.py). The DataNFT class directly exposes the Solidity ERC721 & ERC725 interfaces. This means your `data_nft` object has a Python method for every Solidity method!

Besides that, DataNFT implements other Python methods like `create_datatoken()` to improve developer experience. And, [ocean_assets.OceanAssets](https://github.com/oceanprotocol/ocean.py/blob/main/ocean_lib/ocean/ocean_assets.py) and other higher-level Python classes / methods work with DataNFT.

Expand All @@ -191,7 +191,7 @@ Ocean's architecture allows for >1 implementations of ERC20, each with its own "

Template 1:
- Solidity: [ERC20Template.sol](https://github.com/oceanprotocol/contracts/blob/main/contracts/templates/ERC20Template.sol)
- Python wrapper: [Datatoken1](https://github.com/oceanprotocol/ocean.py/blob/main/ocean_lib/models/datatoken.py). It has a Python method for every Solidity method, via Brownie.
- Python wrapper: [Datatoken1](https://github.com/oceanprotocol/ocean.py/blob/main/ocean_lib/models/datatoken.py). It has a Python method for every Solidity method.
- Implements methods like `start_order()`, `create_exchange()`, and `create_dispenser()` to enhance developer experience.

Template 2:
Expand Down Expand Up @@ -303,7 +303,7 @@ A given datatoken can create exactly one dispenser for that datatoken.

**Interface via [`Dispenser`](https://github.com/oceanprotocol/ocean.py/blob/main/ocean_lib/models/dispenser.py) Python class:**
- You can access its instance via `ocean.dispenser`.
- `Dispenser` wraps [Dispenser.sol](https://github.com/oceanprotocol/contracts/blob/main/contracts/pools/dispenser/Dispenser.sol) Solidity implementation, to expose `Dispenser.sol`'s methods as Python methods (via Brownie).
- `Dispenser` wraps [Dispenser.sol](https://github.com/oceanprotocol/contracts/blob/main/contracts/pools/dispenser/Dispenser.sol) Solidity implementation, to expose `Dispenser.sol`'s methods as Python methods.
- Note that `Dispenser` is _global_ across all datatokens. Therefore calls to the Solidity contract - or Python calls that pass through - provide the datatoken address as an argument.
- Example call: `ocean.dispenser.setAllowedSwapper(datatoken_addr, ZERO_ADDRESS, {"from": alice})`

Expand Down Expand Up @@ -377,7 +377,7 @@ While most interactions are with `OneExchange` described above, sometimes we may

**Interface via [`FixedRateExchange`](https://github.com/oceanprotocol/ocean.py/blob/4aa12afd8a933d64bc2ed68d1e5359d0b9ae62f9/ocean_lib/models/fixed_rate_exchange.py#L106) Python class:**
- You can access its instance via `ocean.fixed_rate_exchange`.
- `FixedRateExchange` wraps [FixedRateExchange.sol](https://github.com/oceanprotocol/contracts/blob/main/contracts/pools/fixedRate/FixedRateExchange.sol) Solidity implementation, to expose `Dispenser.sol`'s methods as Python methods (via Brownie).
- `FixedRateExchange` wraps [FixedRateExchange.sol](https://github.com/oceanprotocol/contracts/blob/main/contracts/pools/fixedRate/FixedRateExchange.sol) Solidity implementation, to expose `Dispenser.sol`'s methods as Python methods.
- Note that `FixedRateExchange` is _global_ across all datatokens. Therefore calls to the Solidity contract - or Python calls that pass through - provide the exchange id address as an argument. It's exchange id, and not datatoken, because there may be >1 exchange for a given datatoken.
- Example call: `ocean.fixed_rate_exchange.getRate(exchange_id)` returns rate (price).

Expand Down
14 changes: 3 additions & 11 deletions READMEs/setup-local.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,7 @@ docker system prune -a --volumes

Now that we have barge running, we can mostly ignore its console while it runs.

## 2. Brownie local network configuration

(You don't need to do anything in this step, it's just useful to understand.)

Brownie's network configuration file is at `~/.brownie/network-config.yaml`.

When running locally, Brownie will use the chain listed under `development`, having id `development`. This refers to Ganache, which is running in Barge.

## 3. Set envvars
## 2. Set envvars

From here on, go to a console different than Barge. (E.g. the console where you installed Ocean, or a new one.)

Expand All @@ -65,7 +57,7 @@ export TEST_PRIVATE_KEY3=0x732fbb7c355aa8898f4cff92fa7a6a947339eaf026a08a51f1711
export FACTORY_DEPLOYER_PRIVATE_KEY=0xc594c6e5def4bab63ac29eed19a134c130388f74f019bc74b8f4389df2837a58
```

## 4. Setup in Python
## 3. Setup in Python

In the same console, run Python console:
```console
Expand Down Expand Up @@ -113,7 +105,7 @@ assert OCEAN.balanceOf(carlos) > 0, "Carlos needs OCEAN"
from ocean_lib.ocean.util import to_wei, from_wei
```

## 5. Next step
## 4. Next step

You've now set up everything you need for local testing, congrats!

Expand Down
89 changes: 7 additions & 82 deletions READMEs/setup-remote.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Here, we do setup for Mumbai, the testnet for Polygon. It's similar for other re
We assume you've already [installed Ocean](install.md).

Here, we will:
1. Configure Brownie networks
1. Configure networks
2. Create two accounts - `REMOTE_TEST_PRIVATE_KEY1` and `2`
3. Get fake MATIC on Mumbai
4. Get fake OCEAN on Mumbai
Expand All @@ -19,96 +19,22 @@ Here, we will:

Let's go!

## 1. Configure Brownie Networks (One-Time)
## 1. Configure Networks

### 1.1 Network config file
### 1.1 Setup network RPC URLs for all desired networks

Brownie's network config file is `network-config.yaml`. It is located in the `.brownie/` subfolder of your home folder.
- For Linux & MacOS, it's: `~/.brownie/network-config.yaml`
- For Windows users, it's: `C:\Users\<user_name>\.brownie\network-config.yaml`
All [Ocean-deployed](https://docs.oceanprotocol.com/core-concepts/networks) chains (Eth mainnet, Polygon, etc) are supported.

### 1.2 Generate network config file (if needed)

If you already see the config file, skip this section.

If you don't, you need to auto-generate by calling any brownie function from a Python console. Here's an example.

First, in a new or existing console, run Python:

```console
python
```

In the Python console:
```
from ocean_lib.example_config import get_config_dict
```

It will generate the file in the target location. You can check the target location to confirm.

### 1.3 Contents of network config file

The network configuration file has settings for each network, e.g. development (ganache), Ethereum mainnet, Polygon, and Mumbai.

Each network gets specifications for:
- `host` - the RPC URL, i.e. what URL do we pass through to talk to the chain
- `required_confs` - the number of confirmations before a tx is done
- `id` - e.g. `polygon`, `mumbai` (Mumbai)

`development chains` run locally; `live` chains run remotely.

The example `network-config.yaml` in Brownie's GitHub repo is [here](https://github.com/eth-brownie/brownie/blob/master/brownie/data/network-config.yaml). It can serve as a comparison to your local copy.

Ocean.py follows the exact `id` name for the network's name from the default Brownie configuration file. Therefore, you need to ensure that your target network name matches the corresponding Brownie `id`.

### 1.4 Networks Supported

All [Ocean-deployed](https://docs.oceanprotocol.com/core-concepts/networks) chains (Eth mainnet, Polygon, etc) should be in Brownie's default `network-config.yaml` except Energy Web Chain (EWC).

For Windows users: it's possible that your `network-config.yaml` doesn't have all the network entries. In this case, just replace your local file's content with the `network-config.yaml` in Brownie's GitHub repo, [here](https://github.com/eth-brownie/brownie/blob/master/brownie/data/network-config.yaml).

For all users: to use EWC, add the following to network-config.yaml:

```yaml
- name: energyweb
networks:
- chainid: 246
host: https://rpc.energyweb.org
id: energyweb
name: energyweb
```
### 1.5 RPCs and Infura
The config file's default RPCs point to Infura, which require you to have an Infura account with corresponding token `WEB3_INFURA_PROJECT_ID`.
Export env vars of the format `NETWORKNAME_RPC_URL` e.g. `export POLYGON_RPC_URL=https://polygon-rpc.com`

In case you have an Infura project, you need to also export the `WEB3_INFURA_PROJECT_ID` variable *alongside* the base rpc urls.

#### If you do have an Infura account

- Linux & MacOS users: in console: `export WEB3_INFURA_PROJECT_ID=<your infura ID>`
- Windows: in console: `set WEB3_INFURA_PROJECT_ID=<your infura ID>`


#### If you do _not_ have an Infura account

One option is to get an Infura account. A simpler option is to *bypass the need* for an Infura account: just change to RPCs that don't need Infura.

You can bypass manually: just edit your brownie network config file.

Or you can bypass via the command line. The following command replaces Infura RPCs with public ones in `network-config.yaml`:


* Linux users: in the console: `sed -i 's#https://polygon-mainnet.infura.io/v3/$WEB3_INFURA_PROJECT_ID#https://polygon-rpc.com/#g; s#https://polygon-mumbai.infura.io/v3/$WEB3_INFURA_PROJECT_ID#https://rpc-mumbai.maticvigil.com#g' ~/.brownie/network-config.yaml`

- MacOS users: you can achieve the same thing with `gnu-sed` and the `gsed` command. (Or just manually edit the file.)

- For Windows: you might need something similar to [powershell](https://www.marek.tokyo/2020/01/remove-string-from-file-in-windows-10.html). (Or just manually edit the file.)

#### 1.6 Network config file wrapup

Congrats, you've now configured your Brownie network file! You rarely need to worry about it from now on.


## 2. Create EVM Accounts (One-Time)

An EVM account is singularly defined by its private key. Its address is a function of that key. Let's generate two accounts!
Expand Down Expand Up @@ -217,8 +143,7 @@ assert OCEAN.balanceOf(bob) > 0, "Bob needs OCEAN"
from ocean_lib.ocean.util import to_wei, from_wei
```

If you get a gas-related error like `transaction underpriced`, you'll need to change the `priority_fee` or `max_fee`. See details in [brownie docs](https://eth-brownie.readthedocs.io/en/stable/core-gas.html).

If you get a gas-related error like `transaction underpriced`, you'll need to change the `priority_fee` or `max_fee`.

## Next step

Expand Down
5 changes: 3 additions & 2 deletions ocean_lib/models/ve/test/test_ve_ocean.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from ocean_lib.ocean.util import from_wei, send_ether, to_wei

# chain = brownie.network.chain
WEEK = 7 * 86400
MAXTIME = 4 * 365 * 86400 # 4 years

Expand Down Expand Up @@ -36,9 +35,11 @@ def test_ve_ocean1(ocean, factory_deployer_wallet, ocean_token):
veOCEAN.checkpoint({"from": factory_deployer_wallet})
OCEAN.approve(veOCEAN.address, TA, {"from": alice_wallet})

t0 = chain[-1].timestamp # ve funcs use block.timestamp, not chain.time()
latest_block = ocean.config_dict["web3_instance"].eth.get_block("latest")
t0 = latest_block.timestamp # ve funcs use block.timestamp, not chain.time()
t1 = t0 // WEEK * WEEK + WEEK # this is a Thursday, because Jan 1 1970 was
t2 = t1 + WEEK
# TODO: mining??
chain.sleep(t1 - t0)

assert OCEAN.balanceOf(alice_wallet.address) != 0
Expand Down
6 changes: 0 additions & 6 deletions ocean_lib/web3_internal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from typing import Any, Union

import requests
from brownie.network import chain
from enforce_typing import enforce_types
from eth_keys import KeyAPI
from eth_keys.backends import NativeECCBackend
Expand Down Expand Up @@ -87,11 +86,6 @@ def get_gas_fees() -> tuple:
# Polygon & Mumbai uses EIP-1559. So, dynamically determine priority fee
gas_resp = requests.get("https://gasstation.polygon.technology/v2")

if not gas_resp or gas_resp.status_code != 200:
print("Invalid response from Polygon gas station. Retry with brownie values...")

return chain.priority_fee, chain.base_fee + 2 * chain.priority_fee

return (
Web3.toWei(gas_resp.json()["fast"]["maxPriorityFee"], "gwei"),
Web3.toWei(gas_resp.json()["fast"]["maxFee"], "gwei"),
Expand Down
8 changes: 3 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@
"pytz", # used minimally and unlikely to change, common dependency
"enforce-typing==1.0.0.post1",
"eciespy==0.3.11",
"eth-brownie==1.19.3",
"cryptography==41.0.2",
"yarl==1.8.1",
"bitarray>=2.6.0,<3",
# brownie requires web3.py, eth-abi, requests, and more,
"web3==5.31.3"
# web3.py requires eth-abi, requests, and more,
# so those will be installed too.
# See https://github.com/ethereum/web3.py/blob/master/setup.py
]
Expand All @@ -55,7 +53,7 @@
"watchdog==3.0.0",
"isort==5.12.0",
"flake8==6.1.0",
"black", # need to keep this up to date to brownie
"black",
"pre-commit==3.3.3",
"licenseheaders==0.8.8",
]
Expand Down

0 comments on commit 122c3c4

Please sign in to comment.