# Smart Margin

Kwenta's on-chain margin engine "Smart Margin" offers a comprehensive suite of tools for trading derivatives powered by Synthetix. Smart Margin (SM) accounts utilize a script-like trading language that defines ordered commands (or steps) to be batch executed by the trader in a single transaction.&#x20;

The command structure supports unrestricted interactions with Synthetix (like modifying position margin and size across multiple markets) and other protocols integrated into the engine. Commands ranging from depositing margin from an EOA to the SM account and executing swaps via Uniswap's UniversalRouter can all be scripted in whatever order the trader desires.

<figure><img src="/files/XGsP8YIZ3MiEHWkjTVBZ" alt=""><figcaption><p>Smart Margin Command Execution Flow</p></figcaption></figure>

Furthermore, given the upgradable nature of the SM system, future protocol integrations can happen seamlessly without disrupting the functionality already offered.

<figure><img src="/files/MXqPzB9vGgHkdOHveRSh" alt=""><figcaption><p>Smart Margin Account Proxy Architecture</p></figcaption></figure>

Additional details concerning protocol architecture and direct usage can be found in the [README](https://github.com/Kwenta/smart-margin/blob/main/README.md). A complete list of supported commands and related inputs can be found in our Smart Margin [wiki](https://github.com/Kwenta/smart-margin/wiki/Commands). Finally, specific interaction flows have been tested natively in solidity [here](https://github.com/Kwenta/smart-margin/blob/main/test/integration/margin.behavior.t.sol) and offer a great starting place for anyone looking to integrate Kwenta's margin engine.

<figure><img src="/files/K6CHlhIEFydnyM3bk7R5" alt=""><figcaption><p>Smart Margin Account Creation UI</p></figcaption></figure>

<table data-view="cards"><thead><tr><th data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><a href="/pages/hiwPZweFedVMqdOrH598">/pages/hiwPZweFedVMqdOrH598</a></td></tr><tr><td><a href="/pages/Ek7gKxNYvyqcVJuxHA8J">/pages/Ek7gKxNYvyqcVJuxHA8J</a></td></tr><tr><td><a href="/pages/MsTb5Gyegpbswz97mTCq">/pages/MsTb5Gyegpbswz97mTCq</a></td></tr><tr><td><a href="/pages/dRFvi1mtiRoI5RrG5cAh">/pages/dRFvi1mtiRoI5RrG5cAh</a></td></tr><tr><td><a href="/pages/3kGsxePENrGSE0yYnJNL">/pages/3kGsxePENrGSE0yYnJNL</a></td></tr></tbody></table>


---

# 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://docs.kwenta.io/using-kwenta/perpetual-futures/smart-margin.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.
