Skip to content

Commit

Permalink
Merge pull request #28 from lidofinance/feat/mantle-testnet
Browse files Browse the repository at this point in the history
feat: add mantle support with goerli example config
  • Loading branch information
TheDZhon authored Nov 11, 2023
2 parents 2885a37 + ee77de6 commit 8c15f78
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 7 deletions.
19 changes: 19 additions & 0 deletions config_samples/mantle_testnet_config_L1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"contracts": {
"0xBc6bbb98E73D15cc6a280e96b32Cc73b4f9068E1": "OssifiableProxy",
"0x8bed2E40522E21119B8A78A4842767c9bCceC47b": "L1ERC20TokenBridge"
},
"explorer_hostname": "api-goerli.etherscan.io",
"github_repo": {
"url": "https://github.com/mantlenetworkio/lido-l2",
"commit": "cdd513cd3d25699a8757f8e730b443a495d0240e",
"relative_root": ""
},
"dependencies": {
"@openzeppelin/contracts": {
"url": "https://github.com/OpenZeppelin/openzeppelin-contracts",
"commit": "d4fb3a89f9d0a39c7ee6f2601d33ffbf30085322",
"relative_root": "contracts"
}
}
}
21 changes: 21 additions & 0 deletions config_samples/mantle_testnet_config_L2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"contracts": {
"0xFCCC4297be972bb2861Da6D78a6fad588dF03ab1": "OssifiableProxy",
"0x7Aa9EEEcECD56Bd43Bb66ee1B42dBEB754792C84": "L2ERC20TokenBridge",
"0x2C402BE58E5849c5413a79aa3b8aF3136e6C017F": "OssifiableProxy",
"0x1008C85f796314c0985639b1a03083Be53eEf5aA": "ERC20BridgedPermit"
},
"explorer_hostname": "explorer.testnet.mantle.xyz",
"github_repo": {
"url": "https://github.com/mantlenetworkio/lido-l2",
"commit": "cdd513cd3d25699a8757f8e730b443a495d0240e",
"relative_root": ""
},
"dependencies": {
"@openzeppelin/contracts": {
"url": "https://github.com/OpenZeppelin/openzeppelin-contracts",
"commit": "d4fb3a89f9d0a39c7ee6f2601d33ffbf30085322",
"relative_root": "contracts"
}
}
}
39 changes: 32 additions & 7 deletions utils/explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
from utils.logger import logger


def _errorNoSourceCodeAndExit(address):
logger.error("source code is not verified or an EOA address", address)
sys.exit(1)


def _get_contract_from_etherscan(token, etherscan_hostname, contract):
etherscan_link = f"https://{etherscan_hostname}/api?module=contract&action=getsourcecode&address={contract}&apikey={token}"

Expand All @@ -17,17 +22,19 @@ def _get_contract_from_etherscan(token, etherscan_hostname, contract):
sys.exit(1)

data = response["result"][0]
if not data["ContractName"]:
logger.error("Not a contract or source code is not verified", contract)
sys.exit(1)
if "ContractName" not in data:
_errorNoSourceCodeAndExit(contract)

contract_name = data["ContractName"]
source_files = json.loads(data["SourceCode"][1:-1])["sources"].items()

return (contract_name, source_files)


def _get_contract_from_zksync(token, zksync_explorer_hostname, contract):
zksync_explorer_link = f"https://{zksync_explorer_hostname}/contract_verification/info/{contract}"
zksync_explorer_link = (
f"https://{zksync_explorer_hostname}/contract_verification/info/{contract}"
)

response = fetch(zksync_explorer_link)

Expand All @@ -37,16 +44,34 @@ def _get_contract_from_zksync(token, zksync_explorer_hostname, contract):
sys.exit(1)

data = response["request"]
if not data["contractName"]:
logger.error("Not a contract or source code is not verified", contract)
sys.exit(1)
if "ContractName" not in data:
_errorNoSourceCodeAndExit(contract)

contract_name = data["contractName"].split(":")[-1]
source_files = data["sourceCode"]["sources"].items()

return (contract_name, source_files)


def _get_contract_from_mantle(token, mantle_explorer_hostname, contract):
etherscan_link = f"https://{mantle_explorer_hostname}/api?module=contract&action=getsourcecode&address={contract}"

response = fetch(etherscan_link)

data = response["result"][0]
if "ContractName" not in data:
_errorNoSourceCodeAndExit(contract)

source_files = [(data["FileName"], {"content": data["SourceCode"]})]
for entry in data.get("AdditionalSources", []):
source_files.append((entry["Filename"], {"content": entry["SourceCode"]}))

return (data["ContractName"], source_files)


def get_contract_from_explorer(token, explorer_hostname, contract):
if explorer_hostname.startswith("zksync"):
return _get_contract_from_zksync(token, explorer_hostname, contract)
if explorer_hostname.endswith("mantle.xyz"):
return _get_contract_from_mantle(token, explorer_hostname, contract)
return _get_contract_from_etherscan(token, explorer_hostname, contract)

0 comments on commit 8c15f78

Please sign in to comment.