bobcat_interfaces/
sels.rs1
2use bobcat_storage::const_keccak256;
3
4use array_concat::concat_arrays;
5
6pub(crate) const fn leftpad_addr(x: [u8; 20]) -> [u8; 32] {
7 concat_arrays!([0u8; 32 - 20], x)
8}
9
10pub(crate) const fn leftpad_u8(x: u8) -> [u8; 32] {
11 concat_arrays!([0u8; 32 - 1], [x])
12}
13
14const fn keccak_sel(x: &[u8]) -> [u8; 4] {
15 let x = const_keccak256(x).0;
16 [x[0], x[1], x[2], x[3]]
17}
18
19#[macro_export]
20macro_rules! selectors {
21 ($($name:ident = $str:literal),* $(,)?) => {
22 $(
23 pub(crate) const $name: [u8; 4] = keccak_sel($str);
24 )*
25 };
26}
27
28selectors! {
29 SEL_TOTAL_SUPPLY = b"totalSupply()",
30 SEL_BALANCE_OF = b"balanceOf(address)",
31 SEL_ALLOWANCE = b"allowance(address,address)",
32 SEL_TRANSFER = b"transfer(address,uint256)",
33 SEL_TRANSFER_FROM = b"transferFrom(address,address,uint256)",
34 SEL_APPROVE = b"approve(address,uint256)",
35 SEL_PERMIT = b"permit(address,address,uint256,uint256,uint8,bytes32,bytes32)",
36 SEL_NONCES = b"nonces(address)",
37 SEL_DOMAIN_SEPARATOR = b"DOMAIN_SEPARATOR()"
38}