exchange.IO("approve", ...)
Sets the token approval mode: approve only what each swap needs, or grant an unlimited allowance.
exchange.IO(k)
exchange.IO(k, mode)Examples
Set the token approval mode.
javascript
function main() {
exchange.IO("approve", "max")
Log("Current approval mode:", exchange.IO("approve"))
}Returns
| Type | Description |
string | Returns the current approval mode, either |
Arguments
| Name | Type | Required | Description |
k | string | Yes | Fixed to |
mode | string | No | Approval mode. |
See Also
Uniswap / PancakeSwap Aerodrome / Velodrome KyberSwap 1inch exchange.IO exchange.IO("transfer") exchange.IO("simulate") exchange.IO("gasMultiplier")
Remarks
Before selling a token (using an ERC20 token as the input), the connector checks how much the router contract is allowed to spend. If that allowance is too low, the connector first sends an approval transaction and waits for it to be confirmed on-chain. Only then does it send the swap transaction. If the existing allowance is not 0 but is still too low, the connector first resets it to 0 and then approves again, because some tokens such as USDT require this.
Uniswap V4 routes and PancakeSwap Infinity routes use a two-step approval. First, the token is approved for the Permit2 contract, following the same rules as above (each exchange uses its own Permit2). Second, the matching Universal Router is approved to spend through Permit2. In exact mode this second approval covers only the current amount and expires after 1 day. In max mode it is unlimited and expires after 30 days. For each step, a transaction is sent only when the allowance is too low or has expired.
max mode avoids later approval transactions and their gas fees, but the router contract can then spend your entire balance of that token. Choose the mode that fits your needs.
Who gets approved depends on the exchange: on Uniswap and PancakeSwap, V2/V3 routes approve their router and V4/Infinity CL routes go through Permit2 (see above); Aerodrome and Velodrome approve the router used by the swap (the basic pools and both Slipstream generations each have their own); KyberSwap and 1inch approve the aggregator's router directly (MetaAggregationRouterV2 for KyberSwap, AggregationRouterV6 for 1inch), without Permit2. LP and bridge approvals follow this mode too: lp.add approves the PositionManager and bridge.send the approvalAddress of the LI.FI quote.