Lachain AAVE handler

// pragma solidity 0.6.4;
pragma experimental ABIEncoderV2;
import "../interfaces/IDepositExecute.sol";
import "../interfaces/IERC20.sol";
import "../interfaces/ILendingPool.sol";
import "../interfaces/IBridge.sol";
import "./HandlerHelpers.sol";
import "../ERC20Safe.sol";
import "../ExampleToken.sol";
import "../utils/Ownable.sol";
@title Handles ERC20 deposits and deposit executions.
@notice This contract is intended to be used with the Bridge contract.
contract AaveHandler is IDepositExecute, HandlerHelpers, Ownable, ERC20Safe {
address public constant AAVE_POLYGON_LP_ADDR = 0x8dFf5E27EA6b7AC08EbFdf9eB090F32ee9a30fcf;
address public constant AAVE_MUMBAI_LP_ADDR = 0x9198F13B08E299d85E096929fA9781A1E3d5d827;
bytes8 public constant LACHAIN_ID = 0x0000000000000019;
bytes8 public constant LACHAIN_TESTNET_ID = 0x00000000574c4131;
address public amTokenHandler;
address public erc20Handler;
struct DepositRecord {
address _tokenAddress;
bytes8 _destinationChainID;
bytes32 _resourceID;
address _destinationRecipientAddress;
address _depositer;
uint256 _amount;
mapping(bytes8 => mapping(uint64 => DepositRecord)) public _depositRecords;
mapping(bytes32 => bytes32) public aaveTokenResources;
event AAVEDepositDone(
address indexed recipientAddress,
uint256 amount,
bytes32 indexed resourceID
@param bridgeAddress Contract address of previously deployed Bridge.
address bridgeAddress
) public {
_bridgeAddress = bridgeAddress;
function setErc20Handler(address _erc20Handler) external onlyOwner {
erc20Handler = _erc20Handler;
function setAmTokenHandler(address _amTokenHandler) external onlyOwner {
amTokenHandler = _amTokenHandler;
function setAaveTokenResources(bytes32 aaveTokenResourceId, bytes32 amTokenResourceId) external onlyOwner {
aaveTokenResources[aaveTokenResourceId] = amTokenResourceId;
function adminChangeBridgeAddress(address newBridgeAddress) external onlyOwner {
_bridgeAddress = newBridgeAddress;
function getDepositRecord(uint64 depositNonce, bytes8 destId)
returns (DepositRecord memory)
return _depositRecords[destId][depositNonce];
function deposit(
bytes32 resourceID,
bytes8 destinationChainID,
uint64 depositNonce,
address depositer,
address recipientAddress,
uint256 amount,
bytes calldata params
) external override onlyBridge returns (address) {
address tokenAddress = _resourceIDToTokenContractAddress[resourceID];
"provided tokenAddress is not whitelisted"
if (_burnList[tokenAddress]) {
burnERC20(tokenAddress, depositer, amount);
} else {
lockERC20(tokenAddress, depositer, address(this), amount);
_depositRecords[destinationChainID][depositNonce] = DepositRecord(
return (tokenAddress);
function executeProposal(
bytes32 resourceID,
address recipientAddress,
uint256 amount,
bytes calldata params
) external override onlyBridge {
address tokenAddress = _resourceIDToTokenContractAddress[resourceID];
IERC20(tokenAddress).transferFrom(erc20Handler, address(this), amount);
IERC20(tokenAddress).approve(AAVE_MUMBAI_LP_ADDR, amount);
ILendingPool(AAVE_MUMBAI_LP_ADDR).deposit(tokenAddress, amount, amTokenHandler, 0x0);
IBridge(_bridgeAddress).internalDeposit(LACHAIN_TESTNET_ID, aaveTokenResources[resourceID], amount, recipientAddress);
emit AAVEDepositDone(
@notice Used to manually release ERC20 tokens from ERC20Safe.
@param tokenAddress Address of token contract to release.
@param recipient Address to release tokens to.
@param amount The amount of ERC20 tokens to release.
function withdraw(
address tokenAddress,
address recipient,
uint256 amount
) external override onlyBridge {
releaseERC20(tokenAddress, recipient, amount);
function getAddressFromResourceId(bytes32 resourceID) external override view returns (address) {
return _resourceIDToTokenContractAddress[resourceID];