arbos/util/
transfer.rs

1use alloy_primitives::{Address, U256};
2
3/// Transfers balance between two addresses.
4///
5/// If `from` is None, this is a mint operation.
6/// If `to` is None, this is a burn operation.
7pub fn transfer_balance<F>(
8    from: Option<&Address>,
9    to: Option<&Address>,
10    amount: U256,
11    mut state_fn: F,
12) -> Result<(), ()>
13where
14    F: FnMut(Option<&Address>, Option<&Address>, U256) -> Result<(), ()>,
15{
16    state_fn(from, to, amount)
17}
18
19/// Mints balance to the given address.
20pub fn mint_balance<F>(to: &Address, amount: U256, state_fn: F) -> Result<(), ()>
21where
22    F: FnMut(Option<&Address>, Option<&Address>, U256) -> Result<(), ()>,
23{
24    transfer_balance(None, Some(to), amount, state_fn)
25}
26
27/// Burns balance from the given address.
28pub fn burn_balance<F>(from: &Address, amount: U256, state_fn: F) -> Result<(), ()>
29where
30    F: FnMut(Option<&Address>, Option<&Address>, U256) -> Result<(), ()>,
31{
32    transfer_balance(Some(from), None, amount, state_fn)
33}