> For the complete documentation index, see [llms.txt](https://docs.kanalabs.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.kanalabs.io/perpetual-futures/kana-perps/breaking-down-kana-perps/1-click-trading-in-kana-perps/delegation.md).

# Delegation

In Kana Perps, we separate **fund management** from **trading execution** using a **delegation model** (optional). This architecture improves security, reduces wallet prompts, and enables features like one-click trading.

### Overview

There are two account roles in this model:

* **Main Wallet**: Custodian of funds. Only used for deposits and withdrawals.
* **Delegate Account**: Authorized to place/cancel orders and manage positions on behalf of the main wallet. Cannot withdraw funds.

The main wallet is only used for **deposits** and **withdrawals**, while the delegate account is used to **place/cancel orders** and **close positions**. This separation allows us to offer **one-click trading** in the frontend by avoiding repeated wallet confirmations for each trade action.

### Account Roles and Capabilities

<table><thead><tr><th width="299.5625">Action</th><th>Main Wallet</th><th>Delegate Account</th></tr></thead><tbody><tr><td>Deposit Funds</td><td>✅</td><td>❌</td></tr><tr><td>Withdraw Funds</td><td>✅</td><td>❌</td></tr><tr><td>Place Orders</td><td>❌</td><td>✅</td></tr><tr><td>Cancel Orders</td><td>❌</td><td>✅</td></tr><tr><td>Close/Update Positions</td><td>❌</td><td>✅</td></tr><tr><td>Transfer Between Profiles</td><td>✅</td><td>❌</td></tr></tbody></table>

> 💡 The delegate account **cannot withdraw funds**, ensuring user funds remain secure even if the delegate key is compromised.

### Use Cases

This delegation setup is ideal for:

* One-click trading (auto-signing trade ops)
* Enabling bots or trading assistants with limited permissions

#### 🆚 Delegated vs Non-Delegated Scripts

| Use Case                     | Script Module            |
| ---------------------------- | ------------------------ |
| Trading via delegate account | `delegated_scripts.move` |
| Direct control (no delegate) | `perpetual_scripts.move` |

### Security Benefits

* **Fine-grained control** (toggle, change, extend, remove)
* **Time-bounded delegation**
* Only **one proxy** per user
* **On-chain enforcement** of delegation permissions

### Implementation Notes

* Delegation is established by the main wallet via an on-chain transaction.
* Delegates can be added or removed at any time.
* Delegated function are available on `delegated_scripts` while non delegated functions available on `perpetual_scripts`
* All delegate actions are scoped and validated to ensure they cannot move funds.

> ⚠️ Always recommend users to review delegate permissions and rotate keys if suspicious activity is detected.
