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:
Withdraw the entirety of their portfolio
Trade the withdrawn capital for another asset
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).
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.
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:
Borrow an asset in order to lever up one’s holdings
Withdraw assets from a portfolio (making it “temporarily” under-collateralized)
Perform an operation – or several – on a 3rd-party protocol with these withdrawn assets
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.
Last updated