Skip to content

Commit 2393f6e

Browse files
committed
added erc6551 5 call method w gas param
1 parent 09d0e56 commit 2393f6e

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

src/wallet.rs

+21-16
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ sol! {
5858

5959
interface IERC6551Account {
6060
function execute(address to, uint256 value, bytes calldata data, uint8 operation) external payable returns (bytes memory);
61+
function execute(address to, uint256 value, bytes calldata data, uint8 operation, uint256 txGas) external payable returns (bytes memory);
6162
function isValidSigner(address signer, bytes calldata data) external view returns (bytes4 magicValue);
6263
function token() external view returns (uint256 chainId, address tokenContract, uint256 tokenId);
6364
function setSignerDataKey(bytes32 signerDataKey) external;
@@ -492,7 +493,7 @@ where
492493
}
493494

494495
// Create the ERC-6551 execute call
495-
let execute_call = IERC6551Account::executeCall {
496+
let execute_call = IERC6551Account::execute_0Call {
496497
to: *hypermap.address(),
497498
value: U256::ZERO,
498499
data: hypermap_call_data,
@@ -1498,14 +1499,13 @@ pub fn set_gene<S: Signer>(
14981499
/// (e.g., via Hypermap notes like ~access-list) rather than the direct owner of the underlying NFT.
14991500
/// The TBA's own `execute` implementation is responsible for verifying the signer's authorization.
15001501
pub fn execute_via_tba_with_signer<S: Signer>(
1501-
tba_address_or_name: &str, // Address or name of the TBA to execute through
1502-
hot_wallet_signer: &S, // The signer (e.g., hot wallet) authorized to call execute
1503-
target_address_or_name: &str, // Address or name of the contract to call via the TBA
1504-
call_data: Vec<u8>, // ABI-encoded data for the call to the target contract
1505-
value: U256, // ETH value to send with the call to the target contract
1502+
tba_address_or_name: &str,
1503+
hot_wallet_signer: &S,
1504+
target_address_or_name: &str,
1505+
call_data: Vec<u8>,
1506+
value: U256,
15061507
provider: &Provider,
1507-
operation: Option<u8>, // ERC-6551 operation type (0=CALL, 1=DELEGATECALL, etc.). Defaults to 0.
1508-
gas_limit: Option<u64>, // Optional gas limit override. Defaults to 500,000.
1508+
operation: Option<u8>,
15091509
) -> Result<TxReceipt, WalletError> {
15101510
// Resolve addresses
15111511
let tba = resolve_name(tba_address_or_name, provider.chain_id)?;
@@ -1521,35 +1521,40 @@ pub fn execute_via_tba_with_signer<S: Signer>(
15211521
value
15221522
);
15231523

1524-
// Create the outer execute call directed at the TBA
1525-
let execute_call = IERC6551Account::executeCall {
1524+
// Create the outer execute call (with txGas) directed at the TBA
1525+
// Use the _1 suffix for the second defined execute function (5 args)
1526+
let internal_gas_limit = U256::from(500_000); // Explicitly set gas for the internal call
1527+
let execute_call = IERC6551Account::execute_1Call { // <-- Using _1 suffix now
15261528
to: target,
15271529
value, // This value is sent from the TBA to the target
15281530
data: Bytes::from(call_data),
15291531
operation: op,
1532+
txGas: internal_gas_limit, // Provide gas for the internal call
15301533
};
15311534
let execute_call_data = execute_call.abi_encode();
15321535

15331536
// Format receipt message
15341537
let format_receipt = move |_| {
15351538
format!(
1536-
"Execute via TBA {} to target {} (Signer: {})",
1539+
"Execute via TBA {} to target {} (Signer: {}, Internal Gas: {})", // Updated log
15371540
tba_address_or_name,
15381541
target_address_or_name,
1539-
hot_wallet_signer.address()
1542+
hot_wallet_signer.address(),
1543+
internal_gas_limit // Log internal gas
15401544
)
15411545
};
15421546

15431547
// Prepare and send the transaction *to* the TBA, signed by the hot_wallet_signer.
1544-
// The `value` field in `prepare_and_send_tx` is U256::ZERO because the ETH transfer
1548+
// The `value` field in the *outer* transaction is U256::ZERO because the ETH transfer
15451549
// happens *inside* the TBA's execution context, funded by the TBA itself.
1550+
// prepare_and_send_tx will handle gas estimation for the outer transaction.
15461551
prepare_and_send_tx(
15471552
tba, // Transaction is sent TO the TBA address
1548-
execute_call_data, // Data is the ABI-encoded `execute` call
1553+
execute_call_data, // Data is the ABI-encoded `execute` call with internal gas limit
15491554
U256::ZERO, // Outer transaction sends no ETH directly to the TBA
15501555
provider,
15511556
hot_wallet_signer, // Signed by the provided (potentially delegated) signer
1552-
gas_limit.or(Some(500_000)), // Default gas limit for TBA executions
1557+
None, // Let prepare_and_send_tx estimate outer gas limit
15531558
format_receipt,
15541559
)
15551560
}
@@ -1570,7 +1575,7 @@ pub fn tba_execute<S: Signer>(
15701575
let target = resolve_name(target_address, provider.chain_id)?;
15711576

15721577
// Create the execute call
1573-
let execute_call = IERC6551Account::executeCall {
1578+
let execute_call = IERC6551Account::execute_0Call {
15741579
to: target,
15751580
value,
15761581
data: Bytes::from(call_data),

0 commit comments

Comments
 (0)