-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAaveV2Controller.sol
95 lines (83 loc) · 3.53 KB
/
AaveV2Controller.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;
import {IController} from "../core/IController.sol";
import {IControllerFacade} from "../core/IControllerFacade.sol";
import {IProtocolDataProvider} from "./IProtocolDataProvider.sol";
/**
@title Aave V2 controller
@notice Controller for aave v2 interaction
eth:0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9
*/
contract AaveV2Controller is IController {
/* -------------------------------------------------------------------------- */
/* CONSTANT VARIABLES */
/* -------------------------------------------------------------------------- */
/// @notice deposit(address,uint256,address,uint16) function signature
bytes4 public constant DEPOSIT = 0xe8eda9df;
/// @notice withdraw(address,uint256,address) function signature
bytes4 public constant WITHDRAW = 0x69328dec;
/* -------------------------------------------------------------------------- */
/* STATE_VARIABLES */
/* -------------------------------------------------------------------------- */
/**
@notice IProtocolDataProvider
@dev https://docs.aave.com/developers/v/2.0/the-core-protocol/protocol-data-provider/iprotocoldataprovider
*/
IProtocolDataProvider public immutable dataProvider;
/// @notice IControllerFacade
IControllerFacade public immutable controllerFacade;
/* -------------------------------------------------------------------------- */
/* CONSTRUCTOR */
/* -------------------------------------------------------------------------- */
/**
@notice Contract constructor
@param _controller address of controller Facade
@param _dataProvider address of aave v2 data provider
*/
constructor(
IControllerFacade _controller,
IProtocolDataProvider _dataProvider
)
{
controllerFacade = _controller;
dataProvider = _dataProvider;
}
/* -------------------------------------------------------------------------- */
/* PUBLIC FUNCTIONS */
/* -------------------------------------------------------------------------- */
/// @inheritdoc IController
function canCall(address, bool, bytes calldata data)
external
view
returns (bool, address[] memory, address[] memory)
{
bytes4 sig = bytes4(data);
if (sig == DEPOSIT) {
address asset = abi.decode(
data[4:],
(address)
);
address[] memory tokensIn = new address[](1);
address[] memory tokensOut = new address[](1);
(tokensIn[0],,) = dataProvider.getReserveTokensAddresses(asset);
tokensOut[0] = asset;
return (
controllerFacade.isTokenAllowed(tokensIn[0]),
tokensIn,
tokensOut
);
}
if (sig == WITHDRAW) {
address asset = abi.decode(
data[4:],
(address)
);
address[] memory tokensIn = new address[](1);
address[] memory tokensOut = new address[](1);
tokensIn[0] = asset;
(tokensOut[0],,) = dataProvider.getReserveTokensAddresses(asset);
return (true, tokensIn, tokensOut);
}
return (false, new address[](0), new address[](0));
}
}