Skip to content

Commit

Permalink
Implement forceApprove
Browse files Browse the repository at this point in the history
  • Loading branch information
0xNeshi committed Sep 25, 2024
1 parent 423743b commit d47db5a
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion contracts/src/token/erc20/utils/safe_erc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,25 @@ impl SafeErc20 {
spender: Address,
value: U256,
) -> Result<(), Error> {
todo!()
type TransferType = (SOLAddress, Uint<256>);
let tx_data = (spender, value);
let data = TransferType::abi_encode_params(&tx_data);
let hashed_function_selector =
function_selector!("approve", Address, U256);
// Combine function selector and input data (use abi_packed way)
let approve_calldata = [&hashed_function_selector[..4], &data].concat();

if self.call_optional_return(token, approve_calldata.clone()).is_err() {
let tx_data = (spender, U256::ZERO);
let data = TransferType::abi_encode_params(&tx_data);
self.call_optional_return(
token,
[&hashed_function_selector[..4], &data].concat(),
)?;
self.call_optional_return(token, approve_calldata)?;
}

Ok(())
}
}

Expand Down

0 comments on commit d47db5a

Please sign in to comment.