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

feat: XDai support #1136

Merged
merged 5 commits into from
Jul 21, 2021
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
24 changes: 24 additions & 0 deletions brownie/data/network-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
15 changes: 12 additions & 3 deletions brownie/network/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -1174,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"])),
Expand Down Expand Up @@ -1893,7 +1903,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} "
Expand Down
1 change: 1 addition & 0 deletions docs/network-management.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
1 change: 1 addition & 0 deletions tests/cli/test_cli_networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down