Skip to content

Commit

Permalink
fixed Aave lending logic
Browse files Browse the repository at this point in the history
  • Loading branch information
MickdeGraaf committed Nov 12, 2020
1 parent e46f717 commit facf3c2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,6 @@ function setUnderlyingToProtocolWrapped(address _underlying, bytes32 _protocol,
| Protocol | Key | Address |
|----------|--------------------------------------------------------------------|--------------------------------------------|
| Compound | 0x561ca898cce9f021c15a441ef41899706e923541cee724530075d1a1144761c7 | 0xB9a13E1D9c5dad1557C3B9B20ab99fb0FB16cCA7 |
| Aave | 0xa9699be9874dcc3e11474d7d87b44bb314eb412a1960f1478100f7e2ccd4a6eb | 0x1708BC3AAAAcE29fB1Cf78AB917d135957317583 |
| Aave | 0xa9699be9874dcc3e11474d7d87b44bb314eb412a1960f1478100f7e2ccd4a6eb | 0x6Eb123bbd02324600AcF8a53575547EEB0a43135 |

Lending logic contracts return the calls needed to lend or unlend from a protocol.
11 changes: 11 additions & 0 deletions buidler.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { LendingLogicCompoundFactory } from "./typechain/LendingLogicCompoundFac
import { LendingRegistry } from "./typechain/LendingRegistry";
import { LendingRegistryFactory } from "./typechain/LendingRegistryFactory";
import { LendingLogicAaveFactory } from "./typechain/LendingLogicAaveFactory";
import { LendingManagerFactory } from "./typechain/LendingManagerFactory";

usePlugin("@nomiclabs/buidler-ethers");
usePlugin('solidity-coverage');
Expand Down Expand Up @@ -250,6 +251,16 @@ task("deploy-pie-factory")

});

task("deploy-lending-manager")
.addParam("lendingRegistry", "address of the lending registry")
.addParam("pie", "address of the pie to manage")
.setAction(async(taskArgs, {ethers}) => {
const signers = await ethers.getSigners();
const lendingManager = await (new LendingManagerFactory(signers[0])).deploy(taskArgs.lendingRegistry, taskArgs.pie);

console.log(`lendingManager deployed at: ${lendingManager.address}`);
});

task("deploy-lending-registry")
.setAction(async(taskArgs, {ethers}) => {
const signers = await ethers.getSigners();
Expand Down
6 changes: 4 additions & 2 deletions contracts/callManagers/LendingManager/LendingLogicAave.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@ contract LendingLogicAave is ILendingLogic {
function lend(address _underlying, uint256 _amount) external view override returns(address[] memory targets, bytes[] memory data) {
IERC20 underlying = IERC20(_underlying);

address core = lendingPool.core();

targets = new address[](3);
data = new bytes[](3);

// zero out approval to be sure
targets[0] = _underlying;
data[0] = abi.encodeWithSelector(underlying.approve.selector, address(lendingPool), 0);
data[0] = abi.encodeWithSelector(underlying.approve.selector, address(core), 0);

// Set approval
targets[1] = _underlying;
data[1] = abi.encodeWithSelector(underlying.approve.selector, address(lendingPool), _amount);
data[1] = abi.encodeWithSelector(underlying.approve.selector, address(core), _amount);

// Deposit into Aave
targets[2] = address(lendingPool);
Expand Down
1 change: 1 addition & 0 deletions contracts/interfaces/IAaveLendingPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ pragma solidity ^0.7.1;

interface IAaveLendingPool {
function deposit(address _reserve, uint256 _amount, uint16 _referralCode) external;
function core() external view returns(address);
}
4 changes: 4 additions & 0 deletions contracts/test/MockAaveLendingPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ contract MockAaveLendingPool is IAaveLendingPool {
function setRevertDeposit(bool _doRevert) external {
revertDeposit = _doRevert;
}

function core() external view override returns(address) {
return address(this);
}
}

0 comments on commit facf3c2

Please sign in to comment.