Detailed tx analysis

Given the architecture behind Contango, it's worth taking a deeper dive into how the steps described in the previous section are batched into a real transaction.

Please note: how each transaction is built can vary depending on the asset, money market and chain you trade on.

Let’s dig into this transaction, where a trader goes long 0.01 ETH with $6.42 USDC as margin.

1) $6.42 USDC, the initial margin from the trader, are sent to the Contango vault (to be conceived as an account that the trader has with the protocol). This step is only needed if the trader doesn’t have funds in the vault/account. For instance, existing funds collected from rebates/referrals into this account could cover totally or partially the amount to be sent. The first address in this line is the trader’s address, the second one is the Contango vault.

2) The remaining $9.92 USDC are flash borrowed from Aave to the trader’s position (they’ll be used later and swapped for the full 0.01 ETH). The second address is a minimal beacon proxy contract that represents the trader’s position (Contango creates one for every new position).

3) $9.92 USDC are transferred from the beacon proxy to the main Contango address.

4) The trader’s margin ($6.42 USDC) is also transferred to the main Contango address.

5) Contango transfers the total of $16.34 USDC to the spot executor, which is responsible for invoking the swap part of the trade (see following steps).

6-10) $16.34 USDC are swapped for ~0.01 ETH and transferred to the main Contango address. In this example Paraswap is being used to swap, becasue it was chosen offchain as best spot rate for this transaction. Contango uses a meta aggregator to always route the swap to the best pricing.

11) Trading fees in the base currency, WETH, are transferred to the Contango treasury account ($0.016, rounded up in the explorer to $0.02).

12) Contango transfer the remaining ETH ($16.28) to the proxy account that represents the trader’s position.

13) The position account supplies $16.28 of ETH on Aave to lend it.

14) Aave mints the corresponding aWETH token (collateral) into the trader’s position account.

15) Aave mints the corresponding vUSDC (debt) into the trader’s position account. This concludes the flash borrow cycle.

Note that these tokens (vUSDC and aWETH) are the tokens that determine the basis rate, meant as the difference between the lending profits (given by aWETH) and the borrowing costs (given by vUSD).

16) Separately, an NFT representing the trader’s position is minted from the Contango account into the trader’s address.

Last updated