-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6699f07
commit 8f1b613
Showing
20 changed files
with
333 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
"""Types for foundry-rs.""" | ||
from typing import Any, Literal, TypedDict | ||
|
||
from web3.types import ABI | ||
|
||
|
||
class FoundryByteCode(TypedDict): | ||
"""Foundry""" | ||
|
||
object: str | ||
sourceMap: str | ||
linkReference: Any | ||
|
||
|
||
class FoundryDeployedByteCode(TypedDict): | ||
"""Foundry""" | ||
|
||
object: str | ||
sourceMap: str | ||
linkReference: Any | ||
|
||
|
||
class FoundryCompiler(TypedDict): | ||
"""Foundry""" | ||
|
||
version: str | ||
|
||
|
||
class FoundryMetadata(TypedDict, total=False): | ||
"""Foundry""" | ||
|
||
compiler: FoundryCompiler | ||
language: Literal["Solidity", "Vyper"] | ||
|
||
|
||
class FoundryJson(TypedDict): | ||
"""Foundry""" | ||
|
||
abi: ABI | ||
bytecode: FoundryByteCode | ||
deployedBytecode: FoundryDeployedByteCode | ||
methodIdentifiers: dict[str, str] | ||
rawMetadata: str | ||
metadata: FoundryMetadata | ||
ast: Any | ||
id: int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
"""Utilities for working with foundry-rs.""" | ||
from typing import TypeGuard | ||
|
||
from pypechain.foundry.types import FoundryJson | ||
|
||
|
||
def is_foundry_json(val: object) -> TypeGuard[FoundryJson]: | ||
"""Determines whether a json object is a FoundryJson.""" | ||
required_keys = {"abi", "bytecode", "deployedBytecode", "methodIdentifiers", "rawMetadata", "metadata", "ast", "id"} | ||
return isinstance(val, dict) and required_keys.issubset(val.keys()) | ||
|
||
|
||
def get_bytecode_from_foundry_json(json_abi: FoundryJson) -> str: | ||
"""Gets the bytecode from a foundry json file.""" | ||
return json_abi.get("bytecode").get("object") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
"""Types for solc.""" | ||
|
||
from typing import TypedDict | ||
|
||
from web3.types import ABI | ||
|
||
|
||
class SolcContract(TypedDict): | ||
"""Foundry""" | ||
|
||
abi: ABI | ||
bin: str | ||
metadata: str | ||
|
||
|
||
class SolcJson(TypedDict): | ||
"""Foundry""" | ||
|
||
contracts: dict[str, SolcContract] | ||
version: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"""Utilities for working with solc.""" | ||
from typing import TypeGuard | ||
|
||
from pypechain.solc.types import SolcJson | ||
|
||
|
||
def is_solc_json(val: object) -> TypeGuard[SolcJson]: | ||
"""Determines whether a json object is a SolcJson.""" | ||
return ( | ||
isinstance(val, dict) | ||
and "contracts" in val | ||
and isinstance(val["contracts"], dict) | ||
and all( | ||
isinstance(contract, dict) and "abi" in contract and "bin" in contract and "metadata" in contract | ||
for contract in val["contracts"].values() | ||
) | ||
and "version" in val | ||
) | ||
|
||
|
||
def get_bytecode_from_solc_json(json_abi: SolcJson) -> str: | ||
"""Gets the bytecode from a foundry json file.""" | ||
# assume one contract right now | ||
contract = list(json_abi.get("contracts").values())[0] | ||
binary = contract.get("bin") | ||
return f"0x{binary}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{{contract_name | lower}}_abi: ABI = cast(ABI, {{abi}}) | ||
{% if bytecode %} | ||
{% if bytecode %}# pylint: disable=line-too-long | ||
{{contract_name | lower}}_bytecode = HexStr("{{bytecode}}") | ||
{%- endif -%} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,2 @@ | ||
{ | ||
"contracts": { | ||
"pypechain/test/overloading/contracts/OverloadedMethods.sol:OverloadedMethods": { | ||
"abi": [ | ||
{ | ||
"inputs": [ | ||
{ "internalType": "string", "name": "s", "type": "string" } | ||
], | ||
"name": "doSomething", | ||
"outputs": [ | ||
{ "internalType": "string", "name": "", "type": "string" } | ||
], | ||
"stateMutability": "pure", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ "internalType": "uint256", "name": "x", "type": "uint256" } | ||
], | ||
"name": "doSomething", | ||
"outputs": [ | ||
{ "internalType": "uint256", "name": "", "type": "uint256" } | ||
], | ||
"stateMutability": "pure", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ "internalType": "uint256", "name": "x", "type": "uint256" }, | ||
{ "internalType": "uint256", "name": "y", "type": "uint256" } | ||
], | ||
"name": "doSomething", | ||
"outputs": [ | ||
{ "internalType": "uint256", "name": "added", "type": "uint256" } | ||
], | ||
"stateMutability": "pure", | ||
"type": "function" | ||
} | ||
], | ||
"bin": "608060405234801561000f575f80fd5b506104d08061001d5f395ff3fe608060405234801561000f575f80fd5b506004361061003f575f3560e01c80638ae3048e14610043578063a6b206bf14610073578063b2dd1d79146100a3575b5f80fd5b61005d60048036038101906100589190610254565b6100d3565b60405161006a9190610315565b60405180910390f35b61008d60048036038101906100889190610368565b6100dd565b60405161009a91906103a2565b60405180910390f35b6100bd60048036038101906100b891906103bb565b6100f2565b6040516100ca91906103a2565b60405180910390f35b6060819050919050565b5f6002826100eb9190610426565b9050919050565b5f81836100ff9190610467565b905092915050565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b61016682610120565b810181811067ffffffffffffffff8211171561018557610184610130565b5b80604052505050565b5f610197610107565b90506101a3828261015d565b919050565b5f67ffffffffffffffff8211156101c2576101c1610130565b5b6101cb82610120565b9050602081019050919050565b828183375f83830152505050565b5f6101f86101f3846101a8565b61018e565b9050828152602081018484840111156102145761021361011c565b5b61021f8482856101d8565b509392505050565b5f82601f83011261023b5761023a610118565b5b813561024b8482602086016101e6565b91505092915050565b5f6020828403121561026957610268610110565b5b5f82013567ffffffffffffffff81111561028657610285610114565b5b61029284828501610227565b91505092915050565b5f81519050919050565b5f82825260208201905092915050565b5f5b838110156102d25780820151818401526020810190506102b7565b5f8484015250505050565b5f6102e78261029b565b6102f181856102a5565b93506103018185602086016102b5565b61030a81610120565b840191505092915050565b5f6020820190508181035f83015261032d81846102dd565b905092915050565b5f819050919050565b61034781610335565b8114610351575f80fd5b50565b5f813590506103628161033e565b92915050565b5f6020828403121561037d5761037c610110565b5b5f61038a84828501610354565b91505092915050565b61039c81610335565b82525050565b5f6020820190506103b55f830184610393565b92915050565b5f80604083850312156103d1576103d0610110565b5b5f6103de85828601610354565b92505060206103ef85828601610354565b9150509250929050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f61043082610335565b915061043b83610335565b925082820261044981610335565b915082820484148315176104605761045f6103f9565b5b5092915050565b5f61047182610335565b915061047c83610335565b9250828201905080821115610494576104936103f9565b5b9291505056fea264697066735822122030deddf27c7d4db295788e5d996b4428f4e2eb5cf7d4e84a067e6776ac7b8ee464736f6c63430008170033", | ||
"metadata": "{\"compiler\":{\"version\":\"0.8.23+commit.f704f362\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"string\",\"name\":\"s\",\"type\":\"string\"}],\"name\":\"doSomething\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"pure\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"x\",\"type\":\"uint256\"}],\"name\":\"doSomething\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"pure\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"x\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"y\",\"type\":\"uint256\"}],\"name\":\"doSomething\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"added\",\"type\":\"uint256\"}],\"stateMutability\":\"pure\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"pypechain/test/overloading/contracts/OverloadedMethods.sol\":\"OverloadedMethods\"},\"evmVersion\":\"shanghai\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":false,\"runs\":200},\"remappings\":[]},\"sources\":{\"pypechain/test/overloading/contracts/OverloadedMethods.sol\":{\"keccak256\":\"0x189b9cc9e57b72a172e36cf533ece6b6fdd88f8c7f329c5690ee45fe381bec6c\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://1fb8762ce2440e288fd86e0d8037909b4fe979f30a88f50194f7f193b3a4bb2e\",\"dweb:/ipfs/QmZCayU5PBxvKE9oF7XDQKxUaPK784RougENHkfxeTHjh9\"]}},\"version\":1}" | ||
} | ||
}, | ||
"version": "0.8.23+commit.f704f362.Darwin.appleclang" | ||
} | ||
{"contracts":{"contracts/OverloadedMethods.sol:OverloadedMethods":{"abi":[{"inputs":[{"internalType":"string","name":"s","type":"string"}],"name":"doSomething","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"x","type":"uint256"}],"name":"doSomething","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"x","type":"uint256"},{"internalType":"uint256","name":"y","type":"uint256"}],"name":"doSomething","outputs":[{"internalType":"uint256","name":"added","type":"uint256"}],"stateMutability":"pure","type":"function"}],"bin":"608060405234801561000f575f80fd5b506104d08061001d5f395ff3fe608060405234801561000f575f80fd5b506004361061003f575f3560e01c80638ae3048e14610043578063a6b206bf14610073578063b2dd1d79146100a3575b5f80fd5b61005d60048036038101906100589190610254565b6100d3565b60405161006a9190610315565b60405180910390f35b61008d60048036038101906100889190610368565b6100dd565b60405161009a91906103a2565b60405180910390f35b6100bd60048036038101906100b891906103bb565b6100f2565b6040516100ca91906103a2565b60405180910390f35b6060819050919050565b5f6002826100eb9190610426565b9050919050565b5f81836100ff9190610467565b905092915050565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b61016682610120565b810181811067ffffffffffffffff8211171561018557610184610130565b5b80604052505050565b5f610197610107565b90506101a3828261015d565b919050565b5f67ffffffffffffffff8211156101c2576101c1610130565b5b6101cb82610120565b9050602081019050919050565b828183375f83830152505050565b5f6101f86101f3846101a8565b61018e565b9050828152602081018484840111156102145761021361011c565b5b61021f8482856101d8565b509392505050565b5f82601f83011261023b5761023a610118565b5b813561024b8482602086016101e6565b91505092915050565b5f6020828403121561026957610268610110565b5b5f82013567ffffffffffffffff81111561028657610285610114565b5b61029284828501610227565b91505092915050565b5f81519050919050565b5f82825260208201905092915050565b5f5b838110156102d25780820151818401526020810190506102b7565b5f8484015250505050565b5f6102e78261029b565b6102f181856102a5565b93506103018185602086016102b5565b61030a81610120565b840191505092915050565b5f6020820190508181035f83015261032d81846102dd565b905092915050565b5f819050919050565b61034781610335565b8114610351575f80fd5b50565b5f813590506103628161033e565b92915050565b5f6020828403121561037d5761037c610110565b5b5f61038a84828501610354565b91505092915050565b61039c81610335565b82525050565b5f6020820190506103b55f830184610393565b92915050565b5f80604083850312156103d1576103d0610110565b5b5f6103de85828601610354565b92505060206103ef85828601610354565b9150509250929050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f61043082610335565b915061043b83610335565b925082820261044981610335565b915082820484148315176104605761045f6103f9565b5b5092915050565b5f61047182610335565b915061047c83610335565b9250828201905080821115610494576104936103f9565b5b9291505056fea2646970667358221220302a4cdc1dfb754065d06f51532b94876e677fac92e5bc7cf8488748219e851564736f6c63430008170033","metadata":"{\"compiler\":{\"version\":\"0.8.23+commit.f704f362\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"string\",\"name\":\"s\",\"type\":\"string\"}],\"name\":\"doSomething\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"pure\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"x\",\"type\":\"uint256\"}],\"name\":\"doSomething\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"pure\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"x\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"y\",\"type\":\"uint256\"}],\"name\":\"doSomething\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"added\",\"type\":\"uint256\"}],\"stateMutability\":\"pure\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"contracts/OverloadedMethods.sol\":\"OverloadedMethods\"},\"evmVersion\":\"shanghai\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":false,\"runs\":200},\"remappings\":[]},\"sources\":{\"contracts/OverloadedMethods.sol\":{\"keccak256\":\"0x189b9cc9e57b72a172e36cf533ece6b6fdd88f8c7f329c5690ee45fe381bec6c\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://1fb8762ce2440e288fd86e0d8037909b4fe979f30a88f50194f7f193b3a4bb2e\",\"dweb:/ipfs/QmZCayU5PBxvKE9oF7XDQKxUaPK784RougENHkfxeTHjh9\"]}},\"version\":1}"}},"version":"0.8.23+commit.f704f362.Darwin.appleclang"} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.