Skip to content

Commit 712675c

Browse files
ckoopmannChristian Koopmann
andauthored
fix: Sync aave leverage module upon leveraged issuance / redemption (#99)
* Sync aave leverage module from inside the contract * Add IAaveLeverageModule interface * Parameterize integration test to be run both for Eth2x and iEth * Change calculation of eth to spend per test case * Reduce min amount out in test Co-authored-by: Christian Koopmann <[email protected]>
1 parent 2845261 commit 712675c

File tree

5 files changed

+427
-339
lines changed

5 files changed

+427
-339
lines changed

contracts/exchangeIssuance/ExchangeIssuanceLeveraged.sol

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.s
2626

2727
import { ISwapRouter} from "../interfaces/external/ISwapRouter.sol";
2828
import { IAToken } from "../interfaces/IAToken.sol";
29+
import { IAaveLeverageModule } from "../interfaces/IAaveLeverageModule.sol";
2930
import { IDebtIssuanceModule } from "../interfaces/IDebtIssuanceModule.sol";
3031
import { IController } from "../interfaces/IController.sol";
3132
import { ISetToken } from "../interfaces/ISetToken.sol";
@@ -93,6 +94,7 @@ contract ExchangeIssuanceLeveraged is ReentrancyGuard, FlashLoanReceiverBaseV2,
9394
address immutable public WETH;
9495
IController public immutable setController;
9596
IDebtIssuanceModule public immutable debtIssuanceModule;
97+
IAaveLeverageModule public immutable aaveLeverageModule;
9698

9799
/* ============ Events ============ */
98100

@@ -135,6 +137,7 @@ contract ExchangeIssuanceLeveraged is ReentrancyGuard, FlashLoanReceiverBaseV2,
135137
* @param _uniV3Router Address of uniswap v3 router
136138
* @param _setController SetToken controller used to verify a given token is a set
137139
* @param _debtIssuanceModule DebtIssuanceModule used to issue and redeem tokens
140+
* @param _aaveLeverageModule AaveLeverageModule to sync before every issuance / redemption
138141
* @param _addressProvider Address of DebtIssuanceModule used to issue and redeem tokens
139142
*/
140143
constructor(
@@ -144,6 +147,7 @@ contract ExchangeIssuanceLeveraged is ReentrancyGuard, FlashLoanReceiverBaseV2,
144147
ISwapRouter _uniV3Router,
145148
IController _setController,
146149
IDebtIssuanceModule _debtIssuanceModule,
150+
IAaveLeverageModule _aaveLeverageModule,
147151
address _addressProvider
148152
)
149153
public
@@ -152,6 +156,7 @@ contract ExchangeIssuanceLeveraged is ReentrancyGuard, FlashLoanReceiverBaseV2,
152156
{
153157
setController = _setController;
154158
debtIssuanceModule = _debtIssuanceModule;
159+
aaveLeverageModule = _aaveLeverageModule;
155160

156161
WETH = _weth;
157162
}
@@ -571,6 +576,7 @@ contract ExchangeIssuanceLeveraged is ReentrancyGuard, FlashLoanReceiverBaseV2,
571576
isSetToken(_setToken)
572577
internal
573578
{
579+
aaveLeverageModule.sync(_setToken);
574580
LeveragedTokenData memory leveragedTokenData = _getLeveragedTokenData(_setToken, _setAmount, true);
575581

576582
address[] memory assets = new address[](1);
@@ -620,6 +626,7 @@ contract ExchangeIssuanceLeveraged is ReentrancyGuard, FlashLoanReceiverBaseV2,
620626
isSetToken(_setToken)
621627
internal
622628
{
629+
aaveLeverageModule.sync(_setToken);
623630
LeveragedTokenData memory leveragedTokenData = _getLeveragedTokenData(_setToken, _setAmount, false);
624631

625632
address[] memory assets = new address[](1);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
import { ISetToken } from "./ISetToken.sol";
20+
21+
interface IAaveLeverageModule {
22+
function sync(ISetToken _setToken) external virtual;
23+
}

test/exchangeIssuance/exchangeIssuanceLeveraged.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ describe("ExchangeIssuanceLeveraged", async () => {
381381
uniswapV3RouterAddress,
382382
controllerAddress,
383383
debtIssuanceModuleAddress,
384+
aaveLeverageModule.address,
384385
addressProviderAddress,
385386
);
386387
return result;
@@ -433,6 +434,7 @@ describe("ExchangeIssuanceLeveraged", async () => {
433434
uniswapV3RouterAddress,
434435
controllerAddress,
435436
debtIssuanceModuleAddress,
437+
aaveLeverageModule.address,
436438
addressProviderAddress,
437439
);
438440
ethAddress = await exchangeIssuance.ETH_ADDRESS();

0 commit comments

Comments
 (0)