💫FlashAngle - Instant AgToken liquidity

Flash loans on top of Angle Protocol stablecoins

1. Introduction

FlashAngle is a contract to take flash loans on top of Angle Protocol AgTokens. With this contract and for a whitelisted stablecoin, any address can take a flash-loan of AgToken.

The innovation here is that stablecoins given out in flash loans are minted during the transaction and burnt at the end of it: this means that this contract could be used to take theorically uncapped and free flash loans on Angle Protocol stablecoins.

2. Contract Details

Interfaces

Implements IFlashAngle, IERC3156FlashLender, ReentrancyGuardUpgradeable and Initializable. This contract is upgradeable.

Parameters and Mappings

  • core: Reference to the CoreBorrow contract

  • stablecoinMap: Maps a stablecoin to its associated parameters and reference, that is to say: the treasury contract associated to the stablecoin, the maximum amount borrowable through a flash-loan and the fee taken on each flash loan.

Access Control

Some functions can only be called by the CoreBorrow contract as such a custom modifier onlyCore has been defined. This contract also reads in its associated core contract to know whether addresses have the guardian role.

3. Key Mechanisms & Concepts

ERC3156 Methods

All standard ERC3156 methods are implemented, such as flashFee(), maxFlashLoan() and flashLoan().

    function flashLoan(
        IERC3156FlashBorrower receiver,
        address token,
        uint256 amount,
        bytes calldata data
    ) external returns (bool);

The flashLoan implementation differs from other standard implementations in that stablecoins are minted to the receiver address.

This address must have a function onFlashLoan to receive the flash-loan, and this function should return keccak256("ERC3156FlashBorrower.onFlashLoan") after being called. If there are some fees setup for this function, then if amount of stablecoins have been sent to the receiver, then amount + amount * fees will have to be burnt from the receiver contract.

This function will revert if it is called on a token, that is to say a stablecoin, that has not been whitelisted.

Maintenance Function

If fees are taken, then this contract may make revenue. There is a accrueInterestToTreasury function to pass these fees to Treasury contract responsible for doing the accounting of profits and losses.

There can never be a loss by the FlashAngle contract.

Governance Functions

The FlashAngle contract can be made aware that it supports a new stablecoin by associating a non-zero treasury address to the stablecoin address in the stablecoinMap.

This can be done by the core contract in the addStablecoinSupport function. The core contract can also remove a stablecoin through the removeStablecoinSupport function, or pass its role to another contract with the setCore function.

Parameters for flash loans and for a given stablecoin can be changed by governance with the setFlashLoanParameters function.

Last updated