use alloy_primitives::{Bytes, U256};
use alloy_sol_types::SolCall;
use super::relay::GMX_ROUTER;
use crate::deployments;
alloy_sol_types::sol! {
struct BridgeOutParams {
address token;
uint256 amount;
uint256 minAmountOut;
address provider;
bytes data;
}
function transferOut(BridgeOutParams params);
}
pub(crate) const TRANSFER_ROUTER: alloy_primitives::Address = GMX_ROUTER;
pub(crate) fn transfer_out(amount: U256) -> Bytes {
let params = BridgeOutParams {
token: deployments::GMX.token,
amount,
minAmountOut: U256::ZERO,
provider: alloy_primitives::Address::ZERO,
data: Bytes::new(),
};
transferOutCall { params }.abi_encode().into()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn transfer_out_equals_the_typescript_sdks_calldata() {
let word = |value: U256| format!("{value:064x}");
let token = U256::from_be_slice(deployments::GMX.token.as_slice());
let amount = U256::from(123_456_789u64);
let expected = format!(
"0x0b9066d9{}{}{}{}{}{}{}",
word(U256::from(32u8)),
word(token),
word(amount),
word(U256::ZERO),
word(U256::ZERO),
word(U256::from(160u8)),
word(U256::ZERO),
);
assert_eq!(transfer_out(amount).to_string(), expected);
}
}