I’m trying to simulate uniswap_v2 swap using revm. But I’m stuck on setting up token pair by calling the factory contract, the issue is when I called the transaction, I got “LackOfFundForMaxFee”, but I have already set up the caller account with enough ETH by calling insert_account_info(), is there something else that I need to do to really set up the account?
The result I got is “LackOfFundForMaxFee { fee: 500000000000000000, balance: 0 }”
I’m using revm = { version = “14.0.3”, features = [
“alloydb”,
“optional_block_gas_limit”,
“optional_no_base_fee”
] }
Here is the code snippet.
let mut alloydb = AlloyDB::new(provider.clone(), BlockId::latest()).unwrap();
let db = evm.db_mut();
// insert user account info
let ten_eth: Uint<256, 4> = parse_ether("10")?;
let user_acc_info = AccountInfo::new(ten_eth, 0, B256::default(), Bytecode::default());
db.insert_account_info(account, user_acc_info);
// insert simulator account info
let simulator_addr = address!("F2d01Ee818509a9540d8324a5bA52329af27D19E");
let simulator_acc_info = AccountInfo::new(Uint::from(0), 0, FixedBytes::ZERO, Bytecode::new_raw((*SIMULATOR_CODE.0).into()));
db.insert_account_info(simulator_addr, simulator_acc_info);
let input_token_address = match input_token_implementation {
Some(impl_addr) => impl_addr,
None => input_token
};
let output_token_address = match output_token_implementation {
Some(impl_addr) => impl_addr,
None => output_token
};
// insert factory, input token and output token account info
let factory_acc_info = alloydb.basic(factory).unwrap().unwrap();
let input_token_acc_info = alloydb.basic(input_token_address).unwrap().unwrap();
let output_token_acc_info = alloydb.basic(output_token_address).unwrap().unwrap();
db.insert_account_info(factory, factory_acc_info);
db.insert_account_info(input_token, input_token_acc_info);
db.insert_account_info(output_token, output_token_acc_info);
// create token pair through uniswap factory
let factory_create_pair = createPairCall { _0: convert_address(input_token), _1: convert_address(output_token) };
let calldata = factory_create_pair.abi_encode();
let gas_price = Uint::from(100 * 10u128.pow(9));
let tx = evm.tx_mut();
tx.caller = account;
tx.gas_limit = 5_000_000;
tx.gas_price = gas_price;
tx.transact_to = TransactTo::Call(factory);
tx.data = calldata.into();
let result = match evm.transact_commit() {
Result::Ok(result) => result,
Err(e) => return Err(anyhow!("EVM call failed: {e:?}")),
};