# 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.

```solidity
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

```solidity
// 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://nashpoint.gitbook.io/nashpoint/node-execute-function.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
