From 752f8286ecccc61473432113a6afcdc59a644048 Mon Sep 17 00:00:00 2001 From: Edward Amor Date: Sat, 3 Jul 2021 20:06:01 -0400 Subject: [PATCH 1/5] fix: polygon network id --- brownie/network/contract.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/brownie/network/contract.py b/brownie/network/contract.py index 725810c63..7d5ffa8a1 100644 --- a/brownie/network/contract.py +++ b/brownie/network/contract.py @@ -113,11 +113,12 @@ def decode_input(self, calldata: Union[str, bytes]) -> Tuple[str, Any]: if not isinstance(calldata, HexBytes): calldata = HexBytes(calldata) + fn_selector = calldata[:4].hex() # type: ignore abi = next( ( i for i in self.abi - if i["type"] == "function" and build_function_selector(i) == calldata[:4].hex() + if i["type"] == "function" and build_function_selector(i) == fn_selector ), None, ) @@ -713,11 +714,12 @@ def decode_input(self, calldata: Union[str, bytes]) -> Tuple[str, Any]: if not isinstance(calldata, HexBytes): calldata = HexBytes(calldata) + fn_selector = calldata[:4].hex() # type: ignore abi = next( ( i for i in self.abi - if i["type"] == "function" and build_function_selector(i) == calldata[:4].hex() + if i["type"] == "function" and build_function_selector(i) == fn_selector ), None, ) @@ -1893,7 +1895,6 @@ def _fetch_from_explorer(address: str, action: str, silent: bool) -> Dict: "as the environment variable $POLYGONSCAN_TOKEN", BrownieEnvironmentWarning, ) - if not silent: print( f"Fetching source of {color('bright blue')}{address}{color} " From 4ac88fde308bec64f819aa106250ef38fb9e3d54 Mon Sep 17 00:00:00 2001 From: Edward Amor Date: Sat, 3 Jul 2021 20:18:50 -0400 Subject: [PATCH 2/5] feat: add xdai to default network config --- brownie/data/network-config.yaml | 24 ++++++++++++++++++++++++ tests/cli/test_cli_networks.py | 1 + 2 files changed, 25 insertions(+) diff --git a/brownie/data/network-config.yaml b/brownie/data/network-config.yaml index 7a7920ae6..edacea6ba 100644 --- a/brownie/data/network-config.yaml +++ b/brownie/data/network-config.yaml @@ -81,6 +81,18 @@ live: host: https://polygon-mumbai.infura.io/v3/$WEB3_INFURA_PROJECT_ID explorer: https://api-testnet.polygonscan.com/api multicall2: "0x6842E0412AC1c00464dc48961330156a07268d14" + - name: XDai + networks: + - name: Mainnet + chainid: 100 + id: xdai-main + host: https://xdai.poanetwork.dev + explorer: https://blockscout.com/xdai/mainnet/api + - name: Testnet + chainid: 77 + id: xdai-test + host: https://sokol.poa.network + explorer: https://blockscout.com/poa/sokol/api development: - name: Ganache-CLI @@ -147,3 +159,15 @@ development: evm_version: istanbul mnemonic: brownie fork: polygon-main + - name: Ganache-CLI (XDai-Mainnet Fork) + id: xdai-main-fork + cmd: ganache-cli + host: http://127.0.0.1 + timeout: 120 + cmd_settings: + port: 8545 + gas_limit: 20000000 + accounts: 10 + evm_version: istanbul + mnemonic: brownie + fork: xdai-main diff --git a/tests/cli/test_cli_networks.py b/tests/cli/test_cli_networks.py index a27a19d44..64b46aaa1 100644 --- a/tests/cli/test_cli_networks.py +++ b/tests/cli/test_cli_networks.py @@ -158,6 +158,7 @@ def test_delete_development(): "bsc-main-fork", "ftm-main-fork", "polygon-main-fork", + "xdai-main-fork", "geth-dev", ): cli_networks._delete(network_name) From 424c4050b8a988bbeaac43f95db948524902e370 Mon Sep 17 00:00:00 2001 From: Edward Amor Date: Sun, 4 Jul 2021 12:46:50 -0400 Subject: [PATCH 3/5] fix: fetching source from blockscout Limited support, only queries ABI from blockscout ATM. TODO: handle compilation errors --- brownie/network/contract.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/brownie/network/contract.py b/brownie/network/contract.py index 7d5ffa8a1..f365f86ac 100644 --- a/brownie/network/contract.py +++ b/brownie/network/contract.py @@ -1176,6 +1176,14 @@ def from_explorer( BrownieCompilerWarning, ) return cls.from_abi(name, address, abi, owner) + elif data["result"][0]["OptimizationUsed"] in ("true", "false"): + if not silent: + warnings.warn( + f"Blockscout explorer API has limited support by Brownie. " # noqa + "Some debugging functionality will not be available.", + BrownieCompilerWarning, + ) + return cls.from_abi(name, address, abi, owner) optimizer = { "enabled": bool(int(data["result"][0]["OptimizationUsed"])), From ff00c2a90d13ff95ac871a9d447306bb71d4726f Mon Sep 17 00:00:00 2001 From: Edward Amor Date: Sun, 4 Jul 2021 15:17:09 -0400 Subject: [PATCH 4/5] docs: add XDai network to list of native integrations --- docs/network-management.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/network-management.rst b/docs/network-management.rst index 59ae644dd..186f9e371 100644 --- a/docs/network-management.rst +++ b/docs/network-management.rst @@ -235,6 +235,7 @@ Brownie natively supports the following collection of EVM-compatible chains: * Binance Smart Chain * Fantom Opera * Polygon Network +* XDai Network In order to enable native support for an EVM-compatible chain, there are 2 requirements. The chain must have a JSON-RPC endpoint which is publicly accessible (free in cost, sign-up may be required), and it should have a block explorer with API support for fetching contract sources and ABIs. From b385df46544ab239bfa3b1d928cf5ac94c24841a Mon Sep 17 00:00:00 2001 From: Edward Amor Date: Wed, 21 Jul 2021 16:36:55 -0400 Subject: [PATCH 5/5] chore: update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c018cf51..f7bb86c95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add support for `POLYGONSCAN_TOKEN` env var ([#1135](https://github.com/eth-brownie/brownie/pull/1135)) - Add Multicall context manager ([#1125](https://github.com/eth-brownie/brownie/pull/1125)) - Add initial support for Solidity 0.8's typed errors ([#1110](https://github.com/eth-brownie/brownie/pull/1110)) +- Add xdai network integration ([#1136](https://github.com/eth-brownie/brownie/pull/1136)) ### Added - Added `LocalAccount.sign_message` method to sign `EIP712Message` objects ([#1097](https://github.com/eth-brownie/brownie/pull/1097))