Node Execute Function
The execute
function enables valid Routers to make arbitrary contract calls on behalf of the Node, allowing for complex DeFi interactions while maintaining security controls.
function execute(address target, bytes calldata data)
external
onlyRouter
onlyWhenRebalancing
returns (bytes memory)
{
if (target == address(0)) revert ErrorsLib.ZeroAddress();
bytes memory result = target.functionCall(data);
emit EventsLib.Execute(target, data, result);
return result;
}
Security Controls
Only whitelisted routers can call
execute
Only works during rebalance window
Target address cannot be zero
Emits event with full call data and result
Common Usage
// Example: Approve spending in router
function _safeApprove(address node, address token, address spender, uint256 amount) internal {
bytes memory data = INode(node).execute(
token,
abi.encodeCall(IERC20.approve, (spender, amount))
);
if (!(data.length == 0 || abi.decode(data, (bool)))) revert ErrorsLib.SafeApproveFailed();
}
Use Cases
Token approvals
Vault deposits/withdrawals
Protocol-specific interactions
Multi-step DeFi operations
All interactions must be implemented in the router contract, maintaining security through the whitelisting system.
Last updated