-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathCollateralAdapter.sol
59 lines (48 loc) · 1.91 KB
/
CollateralAdapter.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
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
import {Errors} from '../libraries/helpers/Errors.sol';
import {ILendingPool} from '../../interfaces/ILendingPool.sol';
import {VersionedInitializable} from '../../protocol/libraries/sturdy-upgradeability/VersionedInitializable.sol';
import {ILendingPoolAddressesProvider} from '../../interfaces/ILendingPoolAddressesProvider.sol';
/**
* @title CollateralAdapter
* @notice CollateralToVault mapping adapter
* @author Sturdy
**/
contract CollateralAdapter is VersionedInitializable {
modifier onlyAdmin() {
require(_addressesProvider.getPoolAdmin() == msg.sender, Errors.CALLER_NOT_POOL_ADMIN);
_;
}
uint256 public constant VAULT_REVISION = 0x1;
ILendingPoolAddressesProvider internal _addressesProvider;
// External collateral asset -> vault
mapping(address => address) internal _assetToVaults;
// External collateral asset -> internal collateral asset
mapping(address => address) internal _collateralAssets;
/**
* @dev Function is invoked by the proxy contract when the Adapter contract is deployed.
* @param _provider The address of the provider
**/
function initialize(ILendingPoolAddressesProvider _provider) public initializer {
_addressesProvider = _provider;
}
function getRevision() internal pure override returns (uint256) {
return VAULT_REVISION;
}
function addCollateralAsset(
address _externalAsset,
address _internalAsset,
address _acceptVault
) external onlyAdmin {
_assetToVaults[_externalAsset] = _acceptVault;
_collateralAssets[_externalAsset] = _internalAsset;
}
function getAcceptableVault(address _externalAsset) external view returns (address) {
return _assetToVaults[_externalAsset];
}
function getInternalCollateralAsset(address _externalAsset) external view returns (address) {
return _collateralAssets[_externalAsset];
}
}