Skip to content

Commit cb56b38

Browse files
authored
Add Aave Leverage Module (#116)
* Add aave V2 token interfaces * Add Aave Leverage Module contract * Add tests for module contract * Remove unused parts of interfaces * Add suggested changes * Add ReserveTokens struct * Emit events on lendingPool and aave reserve update * Optimize removeStorage calls * Add tests for deleverToZeroBorrowBalance * Avoid explicitly invoking setUserUserReserveAsCollateral in lever() * At first issuance when user transfers aTokens to SetToken via the issuance module, Aave enables that asset to be used as collateral by the SetToken * Remove ability to take stable debt * Stable debt is not required in structured products on mainnet * stable debt is not supported on Matic * Increase test coverage and fix bugs * Add tests for setTotalSupply == 0 in sync and remove checks for usageAsCollateralEnabled * Add tests for assets initialized but not part of Set position * Refactor validateNewCollateralAsset and validateNewBorrowAsset * Add javadoc comments for internal functions * Rename addAaveReserve to updateUnderlyingToReserveTokensMapping * More verbose naming * Added return param docs to internal functions * Add integration tests written by @richardliang * Format comments to natspec specification * Attempt at fixing coverage, removed WETH borrow * Fix addCollateralAsets, removeCollateralAssets and removeModule functions * Make sure the fuctions do what the manager expects them to do * Maintain state consistency between aave and ALM * Refactor tests to include above changes * fix test comments * Skip integration tests
1 parent 4d25d7e commit cb56b38

File tree

13 files changed

+6299
-13
lines changed

13 files changed

+6299
-13
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
Copyright 2021 Set Labs Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
SPDX-License-Identifier: Apache License, Version 2.0
17+
*/
18+
pragma solidity 0.6.10;
19+
20+
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
21+
interface IAToken is IERC20 {}

contracts/interfaces/external/aave-v2/ILendingPool.sol

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1-
// SPDX-License-Identifier: agpl-3.0
1+
/*
2+
Copyright 2021 Set Labs Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
SPDX-License-Identifier: Apache License, Version 2.0
17+
*/
218
pragma solidity 0.6.10;
319
pragma experimental ABIEncoderV2;
420

contracts/interfaces/external/aave-v2/ILendingPoolAddressesProvider.sol

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1-
// SPDX-License-Identifier: agpl-3.0
1+
/*
2+
Copyright 2021 Set Labs Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
SPDX-License-Identifier: Apache License, Version 2.0
17+
*/
218
pragma solidity 0.6.10;
319

420
/**

contracts/interfaces/external/aave-v2/IProtocolDataProvider.sol

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
1-
// SPDX-License-Identifier: agpl-3.0
1+
/*
2+
Copyright 2021 Set Labs Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
SPDX-License-Identifier: Apache License, Version 2.0
17+
*/
218
pragma solidity 0.6.10;
319
pragma experimental ABIEncoderV2;
420

5-
import {ILendingPoolAddressesProvider} from "./ILendingPoolAddressesProvider.sol";
21+
import { ILendingPoolAddressesProvider } from "./ILendingPoolAddressesProvider.sol";
622

723
interface IProtocolDataProvider {
824
struct TokenData {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
Copyright 2021 Set Labs Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
SPDX-License-Identifier: Apache License, Version 2.0
17+
*/
18+
pragma solidity 0.6.10;
19+
20+
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
21+
22+
/**
23+
* @title IStableDebtToken
24+
* @notice Defines the interface for the stable debt token
25+
* @author Aave
26+
**/
27+
28+
interface IStableDebtToken is IERC20 {}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
Copyright 2021 Set Labs Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
SPDX-License-Identifier: Apache License, Version 2.0
17+
*/
18+
pragma solidity 0.6.10;
19+
20+
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
21+
22+
/**
23+
* @title IVariableDebtToken
24+
* @author Aave
25+
* @notice Defines the basic interface for a variable debt token.
26+
**/
27+
interface IVariableDebtToken is IERC20 {}

contracts/interfaces/external/aave-v2/lib/DataTypes.sol

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1-
// SPDX-License-Identifier: agpl-3.0
1+
/*
2+
Copyright 2021 Set Labs Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
SPDX-License-Identifier: Apache License, Version 2.0
17+
*/
218
pragma solidity 0.6.10;
319

420
library DataTypes {

0 commit comments

Comments
 (0)