# Composite Operations

In order to perform arbitrary actions with borrowed funds, Concordia allows for composite operations.  A user may perform any sequence of operations in a single **atomic transaction** so long as the user’s portfolio is healthy at the conclusion of the transaction.  This loose constraint – that the portfolio is healthy at the conclusion of the transaction – allows for the portfolio to become unhealthy at any point during the transaction.

#### An example of composite actions is performing a “margin trade.”   In this situation, the user is able to perform a composite operation where they:

1. Withdraw the entirety of their portfolio
2. Trade the withdrawn capital for another asset
3. Deposit that different asset into their portfolio

For example: suppose a user has $4 of ETH in their account, with $2 of equity.  In this situation, the portfolio is 2x leveraged.  They have access to twice as much value as their equity.  In other words, half of their portfolio's value is a liability.  The user wants to trade the ETH for USDT at 2x leverage (essentially shorting ETH). &#x20;

In one transaction: they **withdraw** all $4 of ETH, swap it for \~$4 of USDC, and **deposit** the \~$4 USDC into their portfolio.  At the conclusion of this transaction, this portfolio has $2 of ETH liability and $4 of USDC deposited. &#x20;

This kind of leveraged trade would not be possible without the ability to compose operations in a single transaction, since the withdrawal of all $4 ETH makes the portfolio unhealthy – though only “temporarily” when immediately followed by a deposit of $4.

#### The most common pattern for composite operations is to perform an action with borrowed funds.  They generally will take the shape of:

1. Borrow an asset in order to lever up one’s holdings
2. Withdraw assets from a portfolio (making it “temporarily” under-collateralized)
3. Perform an operation – or several – on a 3rd-party protocol with these withdrawn assets
4. Deposit a new sum of assets into the portfolio, restoring its health from the withdrawal at Step 2.

But any operation on Concordia can be composed with others in a single transaction.  Application developers are free to create useful compositions to create convenient financial products for users.  Programming a composite instruction has blockchain specific requirements.  Please see the developer documentation for instructions on how to create multi-operation transactions.


---

# 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.concordia.systems/platform-spec/composite-operations.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.
