The protocol creates leveraged positions in existing lending protocols, providing leverage on the means of flash loans.
To create a leveraged position, the user must have a collateral token from the list of available tokens on the Lending Protocols. This token will be a collateral to open a trade and it will calculate the PnL position.
If the user does not have a token from the list, the flash flow protocol will be able to exchange any user token from the list. Directly in the opening of the position without additional trades.
- choose a token based on the CF and LL of that token and available liquidity.
- look for a loan based on the token, amount and loan fee.
- look for a trade and prepare a stake date for it.
- we put together a calldata for a trade, a short-term loan, a deposit and a loan.
- the user gives an approve to the protocol contract. (if the token supports it, it can only be signed).
- trade execution (position opening).
Possiton:
address
account - owneraddress
debt - token for the loanaddress
collateral - security tokenuint256
amountIn - original amount of the positionuint256
leverage - leverageuint256
collateralAmount - amount for the collateral received after the tradeuint256
borrowAmount - amount of the loan for the redemption of the short-term loan and calculation of the fund
SwapParams:
address
fromToken - input tokenaddress
toToken - output tokenuint256
amount - exchange amountstring
targetName - connector namebytes
data - calldata for the exchange
- for each position opening, the commission is calculated based on the leveraged transaction amount and the commission set on the contract, the commission can only be changed by the configurator contract.
- position opening and creation of proxy accounts for users.
- accounts are created by cloning a proxy contract when a position is opened and the user has no account.
- open and closing a position in a token that is not present in the lending protocols, there are methods by which we can make the exchange before opening or after closing a position.
- it stores the data of all user accounts and positions.
- contains the logic for opening and closing positions. Account contains the logic for opening and closing positions.
- main registry of addresses part of or connected to the protocol.
- sets the addresses for support contracts for interactions with other protocols.
- main registry of connector contract addresses.
- is used to take and return flash loans.
- it works with aave, balancer, maker.
- the parameters are calculated using the flash resolver contract (in the future they will be calculated on the backend).
- calculates the parameters for working with flash aggregator.
- contains the minimal logic for working with external protocols.
- they are handled by delegatecall. There's a thought of making libraries out of them
- access control list manager, main registry of system roles and permissions.
- implements the configuration methods for the zRex protocol.
Smart contracts for zRex protocol are available under the MIT License.