> For the complete documentation index, see [llms.txt](https://docs.peach.ag/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.peach.ag/documentation/bsc/aggregator/smart-contract-functions.md).

# Smart Contract Functions

Understand the contract calls behind SDK preparation, approvals and execution.

The Peach API builds swap calldata; the SDK validates it and submits the prepared transaction. This page explains the contract calls used by that workflow. For deployment addresses, see [Contract Address](https://docs.peach.ag/documentation/bsc/aggregator/contract-address).

### Execute a swap

`PeachExecutionRouter.executePlan()` is the swap entry point for both Direct and Delegated execution. Its ABI is exported as `PEACH_EXECUTION_ROUTER_ABI`.

<table><thead><tr><th width="213.20703125">Argument</th><th>Purpose</th></tr></thead><tbody><tr><td><code>plan</code></td><td>Signed roles, tokens, amounts, minimum output, deadline, nonce, fees and hash bindings</td></tr><tr><td><code>params</code></td><td>Underlying swap parameters, route steps and intermediate tokens</td></tr><tr><td><code>logicalPoolIds</code></td><td>Logical pool identifiers bound to the route</td></tr><tr><td><code>amountModes</code></td><td>Amount handling modes for the route steps</td></tr><tr><td><code>payerSignature</code></td><td>Permit2 Witness authorization in Delegated mode; empty in Direct mode</td></tr><tr><td><code>aggregatorSignature</code></td><td>Aggregator signature authorizing the execution plan</td></tr></tbody></table>

#### Return values

`executePlan()` returns a receipt tuple containing `planHash`, `payer`, `executor`, `recipient`, `tokenOut`, `requestedAmountIn`, `actualAmountIn` and `userAmountOut`.

The SDK decodes this return value during `simulateSwap()`. It describes execution against the simulated RPC state. A submitted transaction instead returns an ethers transaction response; `wait()` returns the mined transaction receipt, not this tuple. See [Transaction Safety](https://docs.peach.ag/documentation/bsc/aggregator/editor/validation-approvals-and-expiry).

### Funding flows

The function is payable. For native BNB input, the prepared transaction's `value` equals the input amount; otherwise it is zero. Keep the service-built `to`, `data` and `value` unchanged.

Direct execution obtains the transaction through `swapAllowance()`. Delegated execution uses `swapPermit2()` followed by `swapPermit2Build()`. `swap()` selects the mode from whether payer and executor are equal. All three preparation methods accept `from`, `target` and the exact-input `amount`. Submit either ready transaction with `executeSwap()`. A display quote cannot be used to reconstruct executable calldata.

### Supporting functions

#### Token approvals

ERC20 approvals call `approve(address spender, uint256 amount)` on the input token contract. `allowance(address owner, address spender)` reads the existing allowance.

<table><thead><tr><th width="219.07421875">Flow</th><th>Spender</th><th>SDK workflow</th></tr></thead><tbody><tr><td>Direct ERC20 input</td><td>Prepared Execution Router</td><td><code>buildDirectApprovalRequest()</code> skips sufficient allowance or builds unlimited approval</td></tr><tr><td>Delegated ERC20 input</td><td>Canonical Permit2</td><td><code>checkPermit2BaseAllowance()</code> checks the base allowance; the tutorial approves the prepared amount</td></tr><tr><td>Native BNB input</td><td>None</td><td>No ERC20 approval</td></tr></tbody></table>

Wait for a successful approval receipt before submitting the swap. The Permit2 Witness message signature is separate from this ERC20 approval and from the executor's transaction signature. See [Direct Swaps](https://docs.peach.ag/documentation/bsc/aggregator/editor/direct-allowance) and [Delegated Swaps](https://docs.peach.ag/documentation/bsc/aggregator/editor/delegated-execution-with-permit2-witness).

#### Router configuration

The SDK reads these functions from the underlying **PeachRouter**, not the Execution Router:

| Contract functions                                                                                                                         | SDK method                            |
| ------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------- |
| `WETH()`, `owner()`, `pendingOwner()`, `paused()`, `maxCustomFeeBps()`, `maxProtocolCutBps()`, `protocolFeeReceiver()`, `protocolCutBps()` | `getRouterConfig(routerAddress)`      |
| `protocolFeeReceiver()`, `protocolCutBps()`                                                                                                | `getProtocolFeeConfig(routerAddress)` |

These are current configuration snapshots and can change. They do not override a signed execution plan. See [Fees](https://docs.peach.ag/documentation/bsc/aggregator/editor/fees-slippage-and-settlement) for fee limits and [Slippage](https://docs.peach.ag/documentation/bsc/aggregator/editor/slippage) for settlement, or [SDK Reference](https://docs.peach.ag/documentation/bsc/aggregator/editor/configuration-and-error-handling/sdk-reference) for method signatures and return types.

`getRouterConfig()` performs the reads in parallel; it does not pin them to one block. In SDK 0.5.0, use `getProtocolFeeConfig()` and `ProtocolFeeConfig`; the older platform-named method and type have been removed.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.peach.ag/documentation/bsc/aggregator/smart-contract-functions.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
