@athenalend/protocol-v2
v0.0.1
Published
Athena Protocol V2 smart contracts
Downloads
2
Maintainers
Readme
.///. .///. //. .// `/////////////-
`++:++` .++:++` :++` `++: `++:......---.`
`/+: -+/` `++- :+/` /+/ `/+/ `++.
/+/ :+/ /+: /+/ `/+/ /+/` `++.
-::/++::` /+: -::/++::` `/+: `++: :++` `++/:::::::::.
-:+++::-` `/+: --++/---` `++- .++- -++. `++/:::::::::.
-++. .++- -++` .++. .++. .++- `++.
.++- -++. .++. -++. -++``++- `++.
`++: :++` .++- :++` :+//+: `++:----------`
-/: :/- -/: :/. ://: `/////////////-
Athena Protocol v2
This repository contains the smart contracts source code and markets configuration for Athena Protocol V2. The repository uses Docker Compose and Hardhat as development enviroment for compilation, testing and deployment tasks.
What is Athena?
Athena is a decentralized non-custodial liquidity markets protocol where users can participate as depositors or borrowers. Depositors provide liquidity to the market to earn a passive income, while borrowers are able to borrow in an overcollateralized (perpetually) or undercollateralized (one-block liquidity) fashion.
Documentation
The documentation of Athena V2 is in the following Athena V2 documentation link. At the documentation you can learn more about the protocol, see the contract interfaces, integration guides and audits.
For getting the latest contracts addresses, please check the Deployed contracts page at the documentation to stay up to date.
A more detailed and technical description of the protocol can be found in this repository, here
Audits
- MixBytes (16/09/2020 - 03/12/2020): report
- PeckShield (29/09/2020 - 03/12/2020) : report (Also available in Chinese in the same folder)
- CertiK (28/09/2020 - 02/12/2020): report
- Consensys Diligence (09/09/2020 - 09/10/2020): report
- Certora, formal verification (02/08/2020 - 29/10/2020): report
- SigmaPrime (January 2021): report
Connect with the community
You can join at the Discord channel or at the Governance Forum for asking questions about the protocol or talk about Athena with other peers.
Getting Started
You can install @athenalend/protocol-v2
as an NPM package in your Hardhat, Buidler or Truffle project to import the contracts and interfaces:
npm install @athenalend/protocol-v2
Import at Solidity files:
import {ILendingPool} from "@athenalend/protocol-v2/contracts/interfaces/ILendingPool.sol";
contract Misc {
function deposit(address pool, address token, address user, uint256 amount) public {
ILendingPool(pool).deposit(token, amount, user, 0);
{...}
}
}
The JSON artifacts with the ABI and Bytecode are also included into the bundled NPM package at artifacts/
directory.
Import JSON file via Node JS require
:
const LendingPoolV2Artifact = require('@athenalend/protocol-v2/artifacts/contracts/protocol/lendingpool/LendingPool.sol/LendingPool.json');
// Log the ABI into console
console.log(LendingPoolV2Artifact.abi)
Setup
The repository uses Docker Compose to manage sensitive keys and load the configuration. Prior any action like test or deploy, you must run docker-compose up
to start the contracts-env
container, and then connect to the container console via docker-compose exec contracts-env bash
.
Follow the next steps to setup the repository:
- Install
docker
anddocker-compose
- Create an enviroment file named
.env
and fill the next enviroment variables
# Mnemonic, only first address will be used
MNEMONIC=""
# Add Alchemy or Infura provider keys, alchemy takes preference at the config level
ALCHEMY_KEY=""
INFURA_KEY=""
# Optional Etherscan key, for automatize the verification of the contracts at Etherscan
ETHERSCAN_KEY=""
# Optional, if you plan to use Tenderly scripts
TENDERLY_PROJECT=""
TENDERLY_USERNAME=""
Markets configuration
The configurations related with the Athena Markets are located at markets
directory. You can follow the IAthenaConfiguration
interface to create new Markets configuration or extend the current Athena configuration.
Each market should have his own Market configuration file, and their own set of deployment tasks, using the Athena market config and tasks as a reference.
Test
You can run the full test suite with the following commands:
# In one terminal
docker-compose up
# Open another tab or terminal
docker-compose exec contracts-env bash
# A new Bash terminal is prompted, connected to the container
npm run test
Deployments
For deploying Athena Protocol V2, you can use the available scripts located at package.json
. For a complete list, run npm run
to see all the tasks.
Kovan deployment
# In one terminal
docker-compose up
# Open another tab or terminal
docker-compose exec contracts-env bash
# A new Bash terminal is prompted, connected to the container
npm run athena:kovan:full:migration
Mainnet fork deployment
You can deploy Athena Protocol v2 in a forked Mainnet chain using Hardhat built-in fork feature:
docker-compose run contracts-env npm run athena:fork:main
Deploy Athena into a Mainnet Fork via console
You can deploy Athena into the Hardhat console in fork mode, to interact with the protocol inside the fork or for testing purposes.
Run the console in Mainnet fork mode:
docker-compose run contracts-env npm run console:fork
At the Hardhat console, interact with the Athena protocol in Mainnet fork mode:
// Deploy the Athena protocol in fork mode
await run('athena:mainnet')
// Or your custom Hardhat task
await run('your-custom-task');
// After you initialize the HRE via 'set-DRE' task, you can import any TS/JS file
run('set-DRE');
// Import contract getters to retrieve an Ethers.js Contract instance
const contractGetters = require('./helpers/contracts-getters'); // Import a TS/JS file
// Lending pool instance
const lendingPool = await contractGetters.getLendingPool("LendingPool address from 'athena:mainnet' task");
// You can impersonate any Ethereum address
await network.provider.request({ method: "hardhat_impersonateAccount", params: ["0xb1adceddb2941033a090dd166a462fe1c2029484"]});
const signer = await ethers.provider.getSigner("0xb1adceddb2941033a090dd166a462fe1c2029484")
// ERC20 token DAI Mainnet instance
const DAI = await contractGetters.getIErc20Detailed("0x6B175474E89094C44Da98b954EedeAC495271d0F");
// Approve 100 DAI to LendingPool address
await DAI.connect(signer).approve(lendingPool.address, ethers.utils.parseUnits('100'));
// Deposit 100 DAI
await lendingPool.connect(signer).deposit(DAI.address, ethers.utils.parseUnits('100'), await signer.getAddress(), '0');
Interact with Athena in Mainnet via console
You can interact with Athena at Mainnet network using the Hardhat console, in the scenario where the frontend is down or you want to interact directly. You can check the deployed addresses at https://docs.athena.com/developers/deployed-contracts.
Run the Hardhat console pointing to the Mainnet network:
docker-compose run contracts-env npx hardhat --network main console
At the Hardhat console, you can interact with the protocol:
// Load the HRE into helpers to access signers
run("set-DRE")
// Import getters to instance any Athena contract
const contractGetters = require('./helpers/contracts-getters');
// Load the first signer
const signer = await contractGetters.getFirstSigner();
// Lending pool instance
const lendingPool = await contractGetters.getLendingPool("0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9");
// ERC20 token DAI Mainnet instance
const DAI = await contractGetters.getIErc20Detailed("0x6B175474E89094C44Da98b954EedeAC495271d0F");
// Approve 100 DAI to LendingPool address
await DAI.connect(signer).approve(lendingPool.address, ethers.utils.parseUnits('100'));
// Deposit 100 DAI
await lendingPool.connect(signer).deposit(DAI.address, ethers.utils.parseUnits('100'), await signer.getAddress(), '0');