Decentralized forex trading with up to 30x leveraging built with Aave and 1inch.
1fx is a cutting-edge protocol designed to empower traders with the ability to establish significantly leveraged positions within the Aave protocol. This is achieved by concentrating on token pairs that fall under the same eMode category.
The eMode category, which can be activated by a user, permits a higher collateral factor for asset arrangements that exhibit a high correlation. This feature provides traders the flexibility to maintain multiple leveraged positions simultaneously. Each position is meticulously isolated from the rest, ensuring the integrity of individual trades.
Every position is represented by a UUPS upgradeable abstract account. This account safeguards the balances in Aave on behalf of the user. Leveraging this architecture, users can open such a position seamlessly in a single transaction, streamlining their trading operations and enhancing efficiency.
1fx leverages four primary features to facilitate single-click margin positioning.
Abstract Accounts with Create2: At the heart of 1fx is a factory contract that deploys unique entities known as slots, essentially abstract accounts that signify an individual leveraged position.
eMode Activation: Following the deposit, the slot contract enables eMode, a feature that empowers users to hold high-leverage positions.
Aave Flash Loans: These flash loans play a crucial role in promoting the cost-effective generation of leveraged positions
The system eliminates the need to cycle through borrow-swap-supply loops to establish the desired leverage. Here's how the process unfolds when opening a position with a 10 USDC deposit as collateral and USDT as debt - all within a single transaction:
(i) The factory creates an abstract account (the slot) using create2.
(ii) An initial collateral of 10 USDC is supplied to the slot.
(iii) The slot then flash loans the target collateral amount (in this case, for a 20x leverage on the initial deposit, it would be 190 USDC).
(iv) The slot supplies the acquired 190 USDC.
(v) With eMode enabled, the slot can borrow roughly 0.95 x 200 (=190) USDT.
(vi) This 190 USDT is then swapped for USDC to enable the repayment of the flash loan.
(vii) Consequently, the slot now maintains a 20x leveraged position in USDC/USDT on Aave on behalf of the user.
-> this sequence of interactions is showcased in the slot https://polygonscan.com/address/0xB5Cee144309B9e36e7bce1B5B07432f8F2f42224#code and its creation transaction (it uses 20x leverage on 1 USDC initial deposit).