80 lines
2.8 KiB
Solidity
80 lines
2.8 KiB
Solidity
// SPDX-License-Identifier: LGPL-3.0-only
|
|
pragma solidity ^0.8.0;
|
|
|
|
import "../interfaces/IERCHandler.sol";
|
|
|
|
/**
|
|
@title Function used across handler contracts.
|
|
@author ChainSafe Systems.
|
|
@notice This contract is intended to be used with the Bridge contract.
|
|
*/
|
|
contract HandlerHelpers is IERCHandler {
|
|
address public immutable _bridgeAddress;
|
|
|
|
// resourceID => token contract address
|
|
mapping (bytes32 => address) public _resourceIDToTokenContractAddress;
|
|
|
|
// token contract address => resourceID
|
|
mapping (address => bytes32) public _tokenContractAddressToResourceID;
|
|
|
|
// token contract address => is whitelisted
|
|
mapping (address => bool) public _contractWhitelist;
|
|
|
|
// token contract address => is burnable
|
|
mapping (address => bool) public _burnList;
|
|
|
|
modifier onlyBridge() {
|
|
_onlyBridge();
|
|
_;
|
|
}
|
|
|
|
/**
|
|
@param bridgeAddress Contract address of previously deployed Bridge.
|
|
*/
|
|
constructor(
|
|
address bridgeAddress
|
|
) public {
|
|
_bridgeAddress = bridgeAddress;
|
|
}
|
|
|
|
function _onlyBridge() private view {
|
|
require(msg.sender == _bridgeAddress, "sender must be bridge contract");
|
|
}
|
|
|
|
/**
|
|
@notice First verifies {_resourceIDToContractAddress}[{resourceID}] and
|
|
{_contractAddressToResourceID}[{contractAddress}] are not already set,
|
|
then sets {_resourceIDToContractAddress} with {contractAddress},
|
|
{_contractAddressToResourceID} with {resourceID},
|
|
and {_contractWhitelist} to true for {contractAddress}.
|
|
@param resourceID ResourceID to be used when making deposits.
|
|
@param contractAddress Address of contract to be called when a deposit is made and a deposited is executed.
|
|
*/
|
|
function setResource(bytes32 resourceID, address contractAddress) external override onlyBridge {
|
|
|
|
_setResource(resourceID, contractAddress);
|
|
}
|
|
|
|
/**
|
|
@notice First verifies {contractAddress} is whitelisted, then sets {_burnList}[{contractAddress}]
|
|
to true.
|
|
@param contractAddress Address of contract to be used when making or executing deposits.
|
|
*/
|
|
function setBurnable(address contractAddress) external override onlyBridge{
|
|
_setBurnable(contractAddress);
|
|
}
|
|
|
|
function withdraw(bytes memory data) external virtual override {}
|
|
|
|
function _setResource(bytes32 resourceID, address contractAddress) internal {
|
|
_resourceIDToTokenContractAddress[resourceID] = contractAddress;
|
|
_tokenContractAddressToResourceID[contractAddress] = resourceID;
|
|
|
|
_contractWhitelist[contractAddress] = true;
|
|
}
|
|
|
|
function _setBurnable(address contractAddress) internal {
|
|
require(_contractWhitelist[contractAddress], "provided contract is not whitelisted");
|
|
_burnList[contractAddress] = true;
|
|
}
|
|
} |