-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathLendToAaveMigrator.sol
78 lines (64 loc) · 2.25 KB
/
LendToAaveMigrator.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
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.7.5;
import {IERC20} from "../interfaces/IERC20.sol";
import {SafeMath} from "../open-zeppelin/SafeMath.sol";
import {VersionedInitializable} from "../utils/VersionedInitializable.sol";
/**
* @title LendToAaveMigrator
* @notice This contract implements the migration from LEND to AAVE token
* @author Aave
*/
contract LendToAaveMigrator is VersionedInitializable {
using SafeMath for uint256;
IERC20 public immutable AAVE;
IERC20 public immutable LEND;
uint256 public immutable LEND_AAVE_RATIO;
uint256 public constant REVISION = 1;
uint256 public _totalLendMigrated;
/**
* @dev emitted on migration
* @param sender the caller of the migration
* @param amount the amount being migrated
*/
event LendMigrated(address indexed sender, uint256 indexed amount);
/**
* @param aave the address of the AAVE token
* @param lend the address of the LEND token
* @param lendAaveRatio the exchange rate between LEND and AAVE
*/
constructor(IERC20 aave, IERC20 lend, uint256 lendAaveRatio) public {
AAVE = aave;
LEND = lend;
LEND_AAVE_RATIO = lendAaveRatio;
}
/**
* @dev initializes the implementation
*/
function initialize() public initializer {
}
/**
* @dev returns true if the migration started
*/
function migrationStarted() external view returns(bool) {
return lastInitializedRevision != 0;
}
/**
* @dev executes the migration from LEND to AAVE. Users need to give allowance to this contract to transfer LEND before executing
* this transaction.
* @param amount the amount of LEND to be migrated
*/
function migrateFromLEND(uint256 amount) external {
require(lastInitializedRevision != 0, "MIGRATION_NOT_STARTED");
_totalLendMigrated = _totalLendMigrated.add(amount);
LEND.transferFrom(msg.sender, address(this), amount);
AAVE.transfer(msg.sender, amount.div(LEND_AAVE_RATIO));
emit LendMigrated(msg.sender, amount);
}
/**
* @dev returns the implementation revision
* @return the implementation revision
*/
function getRevision() internal pure override returns (uint256) {
return REVISION;
}
}