2 unstable releases
0.2.0 | Jan 31, 2025 |
---|---|
0.1.0 | Jan 15, 2025 |
#372 in #index
190 downloads per month
110KB
3K
SLoC
Cido Ethereum
The ethereum implementation of the cido crate.
Ethereum specific functionality
This crate exports a procedural macro called ethereum_contract
that can be used to annotate
unit structs. The following is an example of how to use the macro.
// A module should contain the macro as all the structs representing all the events and
// functions in this contract are created in the same namespace as the contract struct.
mod uniswap_v3 {
pub const UNISWAP_V3_FACTORY: H160 =
H160::from_hex_str("0x1F98431c8aD98523631AE4a59f267346ea31F984");
#[ethereum_contract(
// (required) path to abi json file from the directory that contains Cargo.toml
source = "../abis/uniswap_v3_factory.json",
// Events from the contract that we're interested in
events = [PoolCreated],
// Order of processing. If set to 1 then address is also required. If 2 or 3 then
// the filters for following these events will need to be created in a generator
order = 1,
// Address of the contract if known. For now it only takes identifiers so a const will
// need to be created that can be used here
address = UNISWAP_V3_FACTORY,
)]
// The unit struct. This will have some internal fields added
pub struct UniswapV3Factory;
}
The struct annotated with #[ethereum_contract(...)]
will have all the functions from the
abi added to it. They can be called after creating an instead of the struct by calling bind
async fn handle_event(cx: Context<'_, Uniswap>, meta: MetaEvent<Uniswap>) -> Result<(), UniswapError> {
let factory = UniswapV3Factory::bind(cx.network(), meta.block_number(), UNISWAP_V3_FACTORY);
let first_pair = factory.allPairs(0).await?;
}
A complete working example of using cido to index all of the uniswap-v2 events is in the examples folder under uniswap-v2.
Dependencies
~74MB
~1.5M SLoC