vyperlang / titanoboa

a vyper interpreter
https://titanoboa.readthedocs.io
Other
247 stars 49 forks source link

feat: abi method factory #260

Open bout3fiddy opened 1 month ago

bout3fiddy commented 1 month ago

What I did

Enables:

fn = boa.loads_fn_sig("def balanceOf(a: address) -> uint256: view")
crv = fn.at("0xD533a949740bb3306d119CC777fa900bA034cd52")

This way, I don't need to store a long abi file, or write a complicated json dict and let vyper handle it for me underneath.

How I did it

Added method from_fn_sig to ABIContractFactory class, thus extending it's scope to beyond just providing a list of dict.

How to verify it

Run test: https://github.com/bout3fiddy/titanoboa/blob/ac38a8b79a2467b8c68bbe42b38fd21e072a1caa/tests/integration/fork/test_abi_contract.py#L43

Description for the changelog

Adds boa.loads_fn_sig("def foo() -> uint256: view") -> contract object.

Cute Animal Picture

image

charles-cooper commented 1 month ago

this seems like a bit of a niche use case. i think it might be more generally useful for users if the function were boa.from_sigs(list[str]) -> ABIContractFactory which takes a list of signatures instead of a single function, as it's a bit odd to think of a smart contract with a full interface as consisting of a single function.

charles-cooper commented 1 month ago

also, ABIContractFactory.from_sigs() might be better, since it's a bit of a niche use case we don't need to pollute the global boa namespace.