-
Notifications
You must be signed in to change notification settings - Fork 106
Aave V2 Library and Fixture #112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
d93867f
Move Aave V1 ABIs to external/abi/aave/v1 subfolder
0xSachinK 2de20ea
Move Aave V1 contracts to external/contracts/aave/v1 subfolder
0xSachinK f903b4b
Remove unnecessary diff
0xSachinK 6e9027e
Add Aave V2 ABIs and contracts
0xSachinK 7084a77
Add interfaces to interfaces/external/aave-v2
0xSachinK ba623bf
Add AaveV2 library contract
0xSachinK 2668fc1
Add AaveV2 Mock contract
0xSachinK e381d69
Add AaveV2 fixture
0xSachinK e1a87e2
Add AaveV2 fixture tests
0xSachinK 21a7179
Fix bug in AaveV2Mock and library contracts
0xSachinK 3b5d02c
Add deployWethReserve and deployDaiReserve as separate functions in f…
0xSachinK 8865f16
Add tests for Aave V2 Library contract
0xSachinK b1ab176
* Add javadocs & other suggested changes to Library and Mock contract
0xSachinK 0f851f1
Add suggested changes to fixture
0xSachinK 4a7ae1f
Return values from library
0xSachinK cecf55d
Add detailed javadocs to library contract
0xSachinK ac2180d
Fix tests: Remove unnecessary checks
0xSachinK c2912b7
Untabify javadocs
0xSachinK f4d82ea
Remove extra line
0xSachinK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
contracts/interfaces/external/aave-v2/ILendingPoolAddressesProvider.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// SPDX-License-Identifier: agpl-3.0 | ||
pragma solidity 0.6.10; | ||
|
||
/** | ||
* @title LendingPoolAddressesProvider contract | ||
* @dev Main registry of addresses part of or connected to the protocol, including permissioned roles | ||
* - Acting also as factory of proxies and admin of those, so with right to change its implementations | ||
* - Owned by the Aave Governance | ||
* @author Aave | ||
**/ | ||
interface ILendingPoolAddressesProvider { | ||
event MarketIdSet(string newMarketId); | ||
event LendingPoolUpdated(address indexed newAddress); | ||
event ConfigurationAdminUpdated(address indexed newAddress); | ||
event EmergencyAdminUpdated(address indexed newAddress); | ||
event LendingPoolConfiguratorUpdated(address indexed newAddress); | ||
event LendingPoolCollateralManagerUpdated(address indexed newAddress); | ||
event PriceOracleUpdated(address indexed newAddress); | ||
event LendingRateOracleUpdated(address indexed newAddress); | ||
event ProxyCreated(bytes32 id, address indexed newAddress); | ||
event AddressSet(bytes32 id, address indexed newAddress, bool hasProxy); | ||
|
||
function getMarketId() external view returns (string memory); | ||
|
||
function setMarketId(string calldata marketId) external; | ||
|
||
function setAddress(bytes32 id, address newAddress) external; | ||
|
||
function setAddressAsProxy(bytes32 id, address impl) external; | ||
|
||
function getAddress(bytes32 id) external view returns (address); | ||
|
||
function getLendingPool() external view returns (address); | ||
|
||
function setLendingPoolImpl(address pool) external; | ||
|
||
function getLendingPoolConfigurator() external view returns (address); | ||
|
||
function setLendingPoolConfiguratorImpl(address configurator) external; | ||
|
||
function getLendingPoolCollateralManager() external view returns (address); | ||
|
||
function setLendingPoolCollateralManager(address manager) external; | ||
|
||
function getPoolAdmin() external view returns (address); | ||
|
||
function setPoolAdmin(address admin) external; | ||
|
||
function getEmergencyAdmin() external view returns (address); | ||
|
||
function setEmergencyAdmin(address admin) external; | ||
|
||
function getPriceOracle() external view returns (address); | ||
|
||
function setPriceOracle(address priceOracle) external; | ||
|
||
function getLendingRateOracle() external view returns (address); | ||
|
||
function setLendingRateOracle(address lendingRateOracle) external; | ||
} |
20 changes: 20 additions & 0 deletions
20
contracts/interfaces/external/aave-v2/IProtocolDataProvider.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// SPDX-License-Identifier: agpl-3.0 | ||
pragma solidity 0.6.10; | ||
pragma experimental ABIEncoderV2; | ||
|
||
import {ILendingPoolAddressesProvider} from "./ILendingPoolAddressesProvider.sol"; | ||
|
||
interface IProtocolDataProvider { | ||
struct TokenData { | ||
string symbol; | ||
address tokenAddress; | ||
} | ||
|
||
function ADDRESSES_PROVIDER() external view returns (ILendingPoolAddressesProvider); | ||
function getAllReservesTokens() external view returns (TokenData[] memory); | ||
function getAllATokens() external view returns (TokenData[] memory); | ||
function getReserveConfigurationData(address asset) external view returns (uint256 decimals, uint256 ltv, uint256 liquidationThreshold, uint256 liquidationBonus, uint256 reserveFactor, bool usageAsCollateralEnabled, bool borrowingEnabled, bool stableBorrowRateEnabled, bool isActive, bool isFrozen); | ||
function getReserveData(address asset) external view returns (uint256 availableLiquidity, uint256 totalStableDebt, uint256 totalVariableDebt, uint256 liquidityRate, uint256 variableBorrowRate, uint256 stableBorrowRate, uint256 averageStableBorrowRate, uint256 liquidityIndex, uint256 variableBorrowIndex, uint40 lastUpdateTimestamp); | ||
function getUserReserveData(address asset, address user) external view returns (uint256 currentATokenBalance, uint256 currentStableDebt, uint256 currentVariableDebt, uint256 principalStableDebt, uint256 scaledVariableDebt, uint256 stableBorrowRate, uint256 liquidityRate, uint40 stableRateLastUpdated, bool usageAsCollateralEnabled); | ||
function getReserveTokensAddresses(address asset) external view returns (address aTokenAddress, address stableDebtTokenAddress, address variableDebtTokenAddress); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// SPDX-License-Identifier: agpl-3.0 | ||
pragma solidity 0.6.10; | ||
|
||
library DataTypes { | ||
// refer to the whitepaper, section 1.1 basic concepts for a formal description of these properties. | ||
struct ReserveData { | ||
//stores the reserve configuration | ||
ReserveConfigurationMap configuration; | ||
//the liquidity index. Expressed in ray | ||
uint128 liquidityIndex; | ||
//variable borrow index. Expressed in ray | ||
uint128 variableBorrowIndex; | ||
//the current supply rate. Expressed in ray | ||
uint128 currentLiquidityRate; | ||
//the current variable borrow rate. Expressed in ray | ||
uint128 currentVariableBorrowRate; | ||
//the current stable borrow rate. Expressed in ray | ||
uint128 currentStableBorrowRate; | ||
uint40 lastUpdateTimestamp; | ||
//tokens addresses | ||
address aTokenAddress; | ||
address stableDebtTokenAddress; | ||
address variableDebtTokenAddress; | ||
//address of the interest rate strategy | ||
address interestRateStrategyAddress; | ||
//the id of the reserve. Represents the position in the list of the active reserves | ||
uint8 id; | ||
} | ||
|
||
struct ReserveConfigurationMap { | ||
//bit 0-15: LTV | ||
//bit 16-31: Liq. threshold | ||
//bit 32-47: Liq. bonus | ||
//bit 48-55: Decimals | ||
//bit 56: Reserve is active | ||
//bit 57: reserve is frozen | ||
//bit 58: borrowing is enabled | ||
//bit 59: stable rate borrowing enabled | ||
//bit 60-63: reserved | ||
//bit 64-79: reserve factor | ||
uint256 data; | ||
} | ||
|
||
struct UserConfigurationMap { | ||
uint256 data; | ||
} | ||
|
||
enum InterestRateMode {NONE, STABLE, VARIABLE} | ||
} |
191 changes: 191 additions & 0 deletions
191
contracts/mocks/protocol/integration/lib/AaveV2Mock.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
/* | ||
Copyright 2021 Set Labs Inc. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
|
||
SPDX-License-Identifier: Apache License, Version 2.0 | ||
*/ | ||
|
||
pragma solidity 0.6.10; | ||
|
||
import { AaveV2 } from "../../../../protocol/integration/lib/AaveV2.sol"; | ||
import { ILendingPool } from "../../../../interfaces/external/aave-v2/ILendingPool.sol"; | ||
import { ISetToken } from "../../../../interfaces/ISetToken.sol"; | ||
|
||
/** | ||
* @title AaveV2Mock | ||
* @author Set Protocol | ||
* | ||
* Mock for AaveV2 Library contract. Used for testing AaveV2 Library contract, as the library | ||
* contract can't be tested directly using ethers.js | ||
*/ | ||
contract AaveV2Mock { | ||
0xSachinK marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/* ============ External ============ */ | ||
|
||
function testGetDepositCalldata( | ||
ILendingPool _lendingPool, | ||
address _asset, | ||
uint256 _amountNotional, | ||
address _onBehalfOf, | ||
uint16 _referralCode | ||
) | ||
public | ||
pure | ||
returns (address, uint256, bytes memory) | ||
{ | ||
return AaveV2.getDepositCalldata(_lendingPool, _asset, _amountNotional, _onBehalfOf, _referralCode); | ||
} | ||
|
||
function testInvokeDeposit( | ||
ISetToken _setToken, | ||
ILendingPool _lendingPool, | ||
address _asset, | ||
uint256 _amountNotional | ||
) | ||
external | ||
{ | ||
return AaveV2.invokeDeposit(_setToken, _lendingPool, _asset, _amountNotional); | ||
} | ||
|
||
function testGetWithdrawCalldata( | ||
ILendingPool _lendingPool, | ||
address _asset, | ||
uint256 _amountNotional, | ||
address _receiver | ||
) | ||
public | ||
pure | ||
returns (address, uint256, bytes memory) | ||
{ | ||
return AaveV2.getWithdrawCalldata(_lendingPool, _asset, _amountNotional, _receiver); | ||
} | ||
|
||
function testInvokeWithdraw( | ||
ISetToken _setToken, | ||
ILendingPool _lendingPool, | ||
address _asset, | ||
uint256 _amountNotional | ||
) | ||
external | ||
returns (uint256) | ||
{ | ||
return AaveV2.invokeWithdraw(_setToken, _lendingPool, _asset, _amountNotional); | ||
} | ||
|
||
function testGetBorrowCalldata( | ||
ILendingPool _lendingPool, | ||
address _asset, | ||
uint256 _amountNotional, | ||
uint256 _interestRateMode, | ||
uint16 _referralCode, | ||
address _onBehalfOf | ||
) | ||
public | ||
pure | ||
returns (address, uint256, bytes memory) | ||
{ | ||
return AaveV2.getBorrowCalldata(_lendingPool, _asset, _amountNotional, _interestRateMode, _referralCode, _onBehalfOf); | ||
} | ||
|
||
function testInvokeBorrow( | ||
ISetToken _setToken, | ||
ILendingPool _lendingPool, | ||
address _asset, | ||
uint256 _amountNotional, | ||
uint256 _interestRateMode | ||
) | ||
external | ||
{ | ||
return AaveV2.invokeBorrow(_setToken, _lendingPool, _asset, _amountNotional, _interestRateMode); | ||
} | ||
|
||
function testGetRepayCalldata( | ||
ILendingPool _lendingPool, | ||
address _asset, | ||
uint256 _amountNotional, | ||
uint256 _interestRateMode, | ||
address _onBehalfOf | ||
) | ||
public | ||
pure | ||
returns (address, uint256, bytes memory) | ||
{ | ||
return AaveV2.getRepayCalldata(_lendingPool, _asset, _amountNotional, _interestRateMode, _onBehalfOf); | ||
} | ||
|
||
function testInvokeRepay( | ||
ISetToken _setToken, | ||
ILendingPool _lendingPool, | ||
address _asset, | ||
uint256 _amountNotional, | ||
uint256 _interestRateMode | ||
) | ||
external | ||
returns (uint256) | ||
{ | ||
return AaveV2.invokeRepay(_setToken, _lendingPool, _asset, _amountNotional, _interestRateMode); | ||
} | ||
|
||
function testGetSetUserUseReserveAsCollateralCalldata( | ||
ILendingPool _lendingPool, | ||
address _asset, | ||
bool _useAsCollateral | ||
) | ||
external | ||
pure | ||
returns (address, uint256, bytes memory) | ||
{ | ||
return AaveV2.getSetUserUseReserveAsCollateralCalldata(_lendingPool, _asset, _useAsCollateral); | ||
} | ||
|
||
function testInvokeSetUserUseReserveAsCollateral( | ||
ISetToken _setToken, | ||
ILendingPool _lendingPool, | ||
address _asset, | ||
bool _useAsCollateral | ||
) | ||
external | ||
{ | ||
return AaveV2.invokeSetUserUseReserveAsCollateral(_setToken, _lendingPool, _asset, _useAsCollateral); | ||
} | ||
|
||
function testGetSwapBorrowRateModeCalldata( | ||
ILendingPool _lendingPool, | ||
address _asset, | ||
uint256 _rateMode | ||
) | ||
external | ||
pure | ||
returns (address, uint256, bytes memory) | ||
{ | ||
return AaveV2.getSwapBorrowRateModeCalldata(_lendingPool, _asset, _rateMode); | ||
} | ||
|
||
function testInvokeSwapBorrowRateMode( | ||
ISetToken _setToken, | ||
ILendingPool _lendingPool, | ||
address _asset, | ||
uint256 _rateMode | ||
) | ||
external | ||
{ | ||
return AaveV2.invokeSwapBorrowRateMode(_setToken, _lendingPool, _asset, _rateMode); | ||
} | ||
|
||
/* ============ Helper Functions ============ */ | ||
|
||
function initializeModuleOnSet(ISetToken _setToken) external { | ||
_setToken.initializeModule(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.