Note
This repository contains the core smart contracts for the 3A DAO Borrowing Protocol.
The 3A Borrowing Protocol is an open-source project of the 3A DAO. It's a DeFi protocol aiming to provide an over-collateralized EUR pegged stablecoin across the Ethereum ecosystem.
Note
A3A
is the 3A DAO utility token bridge from Ethereum with a max supply of 1 Million and it is deployed under the A3A contract.
A3A.sol
The A3A
contract is an ERC20 token called the 3A Utility Token with a total fixed supply of 1 billion tokens. Upon deployment, the constructor mints the total supply to the contract deployer's address, setting up the token for usage within the Ethereum ecosystem.
A3AStaking.sol
Stake A3A to get Mintable Token rewards for paying your debt back from your vault.
veA3AStaking.sol (Staking V2)
Stake A3A to receive Mintable Token rewards for repaying your vault's debt. This version includes a lock-up period, and if you withdraw before the end of the staking period, a portion of your stake will be burned.Note
StableCoin (EURO3)
is deployed under the MintableToken contract.
MintableToken.sol
The MintableToken
contract extends ERC20, implementing minting and burning functionalities for the contract owner. It features functions to mint tokens to designated addresses and burn tokens held by the message sender. Ownership control is ensured for minting operations.
StabilityPool.sol
The StabilityPool
contract allows users to deposit the Stablecoin, pay other vault´s debt back when liquidation and get the collateral from those users with more value than the debt they are paying back.
Meanwhile, the depositors will get rewarded with A3A based on the amount they have deposited.
MintableTokenOwner.sol
The MintableTokenOwner
contract will maintain the privileges of who can mint more Mintable Token and it will work as a middleware for allowing or refusing new Mintable Token minted.
Tip
You can check all the openned vaults in our open API.
VaultFactoryZapper.sol
The VaultFactoryZapper
contract facilitates the creation of Vaults with collateral and borrowing capabilities. It integrates with VaultFactory to generate and manage custom-named Vaults based on user-defined prefixes. The contract supports collateral deposits, borrowing against collateral, and Ether-based collateral creation for Vaults.
VaultFactory.sol
The VaultFactory
contract facilitates the creation, management, and liquidation of Vaults. It enables users to create Vaults, add/remove collateral, borrow funds, and manage debt, with features including collateral redemption and liquidation checks based on health factors. Additionally, it incorporates native and custom tokens as collateral, offering functionality to transfer ownership and repay borrowed amounts.
Vault.sol
The Vault
contract manages collateral, debt, and borrowable amounts, allowing collateral addition/removal, borrowing, and redemption. It calculates health factors based on collateralization ratios and facilitates collateral liquidation for debt recovery.
SmartVault.sol (Vault V2)
The SmartVault
contract extends the functionality of a standard Vault by enabling low-level calls to execute actions such as claiming rewards from third-party protocols. This allows for more advanced interactions and integrations with other protocols, enhancing the overall capabilities of the Vault.
VaultDeployer.sol
The VaultDeployer
contract deploys new instances of the Vault contract, facilitating the creation of vaults with specified factory, owner, and name parameters. It includes a single function deployVault to create and return the address of the newly deployed Vault instance.
SmartVaultDeployer.sol
The SmartVaultDeployer
contract deploys new instances of the SmartVault contract, facilitating the creation of smart vaults with specified factory, owner, and name parameters. It includes a single function deploySmartVault to create and return the address of the newly deployed SmartVault instance.
SmartVaultDeployer.sol (Deployer V2)
The SmartVaultDeployer
contract deploys new instances of the SmartVault contract, facilitating the creation of smart vaults with specified factory, owner, and name parameters. It includes a single function deploySmartVault to create and return the address of the newly deployed SmartVault instance.
SmartVaultProxy.sol
The SmartVaultProxy
contract acts as an intermediary for executing whitelisted low level calls through SmartVaults. This includes functionalities such as claiming rewards from third-party protocols, enabling a more extensive range of interactions and integrations with other protocols.
VaultBorrowRate.sol
The `VaultBorrowRate` contract calculates the overall borrow rate for a given Vault based on its collateral types and respective borrow rates. It fetches collateral details via interfaces, computes collateral values, and aggregates weighted fees to determine the final borrow rate returned as a percentage.VaultFactoryHelper.sol
The VaultFactoryHelper
contract aids in retrieving data about vaults within a factory, including TVL by collateral, liquidatable and redeemable vaults, and the protocol's total TVL. It provides functions to fetch collaterals held by vaults, assess TVL based on collateral, and identify vaults based on their liquidatable or redeemable status.
VaultFactoryConfig.sol
The VaultFactoryConfig
contract defines the protocol parameters. Manages protocol parameters, setting rates, limits, and recipients, also modifying collateral capacities, debt limits, and protocol addresses while providing methods for setting rates, addresses, and ceiling values.
Note
This section will take care of the liquidation & Redemption flow. Every time a liquidation or redemption happens, the same value will be burnt in Mintable Token.
LiquidationRouter.sol
The LiquidationRouter
acts as a crucial gateway for the liquidation process. It coordinates between the Stability Pool and the vaults, initiating auctioning if the Stability Pool lacks Mintable Token and executes liquidation when sufficient Mintable Token exists in the Stability Pool.
AuctionManager.sol
The AuctionManager
smart contract facilitates auctions to liquidate debt against collateral, managing auction creation, bids, and liquidation thresholds. It allows bids based on collateral value, and upon auction end or expiration, transfers bids to the LastResortLiquidation
contract for debt settlement.
LastResortLiquidation.sol
The LastResortLiquidation
contract serves as a control mechanism for collateral and debt handling in liquidation scenarios. It manages various functionalities including collateral addition and withdrawal, tracks and handles bad debt, and allows permission-based distribution to designated vaults, ensuring controlled access and management of assets during liquidation events.
VaultOptimizerBot.sol
The VaultOptimizerBot
streamlines vault actions, enabling borrowing and depositing tokens into a Stability Pool, withdrawal and repayment from vaults, and secure token transfers to respective vault owners. It interfaces with multiple contracts to efficiently execute these operations while maintaining security and reliability.
- Not deployed yet
OwnerProxy.sol
The OwnerProxy
contract facilitates the main owner's control over finely-grained permissions for specific callers to execute functions on designated addresses. Through permission management, it allows addition and removal of permissions, enabling authorized callers to execute functions on specified addresses, all while using cryptographic hashes for permission validation and emitting events for permission changes and function executions.
Note
Oracle flow to retrieve price feeds for EURO
& whitelisted assets such as USDC.e, WETH, WMATIC, QNT and more
.
TokenToPriceFeed.sol
The TokenToPriceFeed
contract manages token-to-price-feed mappings, enabling the owner to set/update price feed contracts for tokens. It provides functions to retrieve token prices, collateral ratios, and borrow rates while ensuring constraints on ratios and rates. The contract implements an interface (ITokenPriceFeed
) to access token-related information. TokenToPriceFeed can handle token prices such as USDC.e, WETH, WMATIC, QNT and more.
ChainlinkPriceFeed.sol
The ChainlinkPriceFeed
contract integrates with Chainlink oracles to fetch and manage up-to-date token prices. It uses precision settings, monitors price updates, and emits signals when price changes occur for associated tokens. It will track the price of the asset in USD
.
ConvertedPriceFeed.sol
The ConvertedPriceFeed
contract integrates two price feed contracts to convert prices and emits signals based on the converted price for a specific token. It allows retrieving the converted price to EURO and emits updates accordingly.
PricesOrchestrator.sol
The PricesOrchestrator
contract integrates Pyth Network's real-time price data into EVM applications. It allows token owners to associate Ethereum tokens with corresponding Pyth Network price IDs and provides functions to update and retrieve token prices.
OrchestratorPriceFeed.sol
The OrchestratorPriceFeed
contract ensures that the retrieved prices are up-to-date and provides functions for accessing current token prices in USD format.
ConvertedPriceFeed.sol
The ConvertedPriceFeed
contract ensures that the retrieved prices are up-to-date and provides functions for accessing current token prices in EUR format.
Note
Utils are smart contracts & libraries used within the system to enhance functionality and provide reusable code for various operations.
Constants.sol
The Constants
contract encapsulates declarations for various constants used in precision, reserves, percentages, and rates without explicitly listing the constant values in this summary.
LinkedAddressList.sol
The LinkedAddressList
library implements a linked list structure for managing sorted Troves and provides functionality to add and remove elements within the list.
PoolAddress.sol
The PoolAddress
library contains functions to generate a pool address using the Uniswap V3 factory contract, tokens, and fee details. It includes logic to create a deterministic pool address based on the PoolKey structure and the factory contract's initialization code hash.
BONQMath.sol
The BONQMath
library offers essential mathematical functions with precise decimal calculations, including min, max, and an optimized exponentiation algorithm tailored for time in minutes.
-
Node Version Manager (NVM)
- If you haven't installed NVM, please visit NVM GitHub page and follow the instructions.
- Set up the correct Node.js version by running
nvm use
command in the root of the project. Make sure the project's.nvmrc
file specifies the correct Node.js version.
-
Node Package Manager (NPM)
- Install project dependencies by running
npm install
command in the root of the project.
- Install project dependencies by running
-
Environment Variables
- Set up the environment variables as shown in the
.env.example
file. Copy the.env.example
file and rename it to.env
. Then, replace the placeholders with your actual values.
- Set up the environment variables as shown in the
Tests are an essential part of this project. They ensure that the current functionality works as expected and helps to prevent regressions when new features are developed.
To run the tests, execute the following command in the root of the project:
# compile solidity code and generate typings
npx hardhat compile
# normal tests
npx hardhat test
# tests with traces
npx hardhat test --traces
This project is licensed under the Business Source License 1.1 - see the LICENSE.md file for details.