diff --git a/vlayer/ethereum/circuits/lib/src/token.nr b/vlayer/ethereum/circuits/lib/src/token.nr index 433c02e4..35440b85 100644 --- a/vlayer/ethereum/circuits/lib/src/token.nr +++ b/vlayer/ethereum/circuits/lib/src/token.nr @@ -22,11 +22,20 @@ impl ERC20Token { } trait ERC20 { - fn get_balance(self, wallet_address: Address, block_number: u64) -> U128 ; + fn get_balance(self, wallet_address: Address, block_number: u64) -> U128; + fn get_balance_recursive(self, wallet_address: Address, block_number: u64) -> U128; } impl ERC20 for ERC20Token { fn get_balance(self, wallet_address: Address, block_number: u64) -> U128 { + let storage_key = self.calculate_balance_storage_key(wallet_address); + let account = get_account_with_storage(self.chain_id, block_number, self.address, storage_key); + let balance = account.values[TOKEN_BALANCE_INDEX]; + + U128::from_integer(bytes32_to_field(balance)) + } + + fn get_balance_recursive(self, wallet_address: Address, block_number: u64) -> U128 { let storage_key = self.calculate_balance_storage_key(wallet_address); let account = get_account_with_storage_recursive(self.chain_id, block_number, self.address, storage_key); let balance = account.values[TOKEN_BALANCE_INDEX]; diff --git a/vlayer/ethereum/circuits/lib/src/token_int_test.nr b/vlayer/ethereum/circuits/lib/src/token_int_test.nr index 00a6d8ca..79c8e9ed 100644 --- a/vlayer/ethereum/circuits/lib/src/token_int_test.nr +++ b/vlayer/ethereum/circuits/lib/src/token_int_test.nr @@ -4,14 +4,20 @@ mod test_ERC20Token { use dep::ethereum::fixtures::mainnet::{ paris::usdc_circle::header::{block_header_partial as paris_block_header_partial, block_header_rlp as paris_block_header_rlp}, paris::usdc_circle::header::{hash, number, state_root, transactions_root, receipts_root}, - paris::usdc_circle::account::account, + paris::usdc_circle::account::account, paris::usdc_circle::storage::values, paris::usdc_circle::state_proof::proof_input_serialized as state_proof_input_serialized, paris::usdc_circle::storage_proof::proofs_serialized }; use crate::chain_id::MAINNET; + use dep::ethereum::account_with_storage_recursive::RecursiveProof; + use dep::ethereum::account_with_storage::StorageWithinBlock; #[test] fn success() { + let result = StorageWithinBlock { block_hash: hash, account, values }; + let recursive_proof = RecursiveProof { key_hash: 1, verification_key: [0; 114], proof: [0; 93] }; + + let _ = OracleMock::mock("get_storage_recursive").returns((result.serialize(), recursive_proof)); let _ = OracleMock::mock("get_header").returns((paris_block_header_partial, paris_block_header_rlp)); let _ = OracleMock::mock("get_proof").returns((account, state_proof_input_serialized, proofs_serialized[0]));