Skip to content

Commit

Permalink
feat: map ics20 denoms to erc20
Browse files Browse the repository at this point in the history
  • Loading branch information
blckngm committed Sep 14, 2023
1 parent 1555e26 commit eb0804b
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions contracts/apps/20-transfer/ICS20TransferERC20.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.9;

import "./ICS20Transfer.sol";
import "../../core/25-handler/IBCHandler.sol";
import "@openzeppelin/contracts/access/AccessControlEnumerable.sol";
import "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol";

// An ICS20 implementation that maps denoms to ERC20.
contract ICS20TransferERC20 is ICS20Transfer, AccessControlEnumerable {
// ERC20PresetMinterPauser role. Why can't I reference this?
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");

// Map denom to ERC20 contract (ERC20PresetMinterPauser).
mapping(string => address) public denomTokenContract;

constructor(IBCHandler ibcHandler_) ICS20Transfer(ibcHandler_) {
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
}

function setDenomTokenContract(string calldata denom, address tokenContract) onlyRole(DEFAULT_ADMIN_ROLE) external {
require(ERC20PresetMinterPauser(tokenContract).hasRole(MINTER_ROLE, address(this)));
denomTokenContract[denom] = tokenContract;
}

function _transferFrom(address, address, string memory, uint256)
internal
override
pure
returns (bool)
{
// Not supported because we always assume that we are the sink zone and we will only mint/burn.
return false;
}

function _mint(address account, string memory denom, uint256 amount) internal override returns (bool) {
try ERC20PresetMinterPauser(denomTokenContract[denom]).mint(account, amount) {
return true;
} catch (bytes memory) {
return false;
}
}

function _burn(address account, string memory denom, uint256 amount) internal override returns (bool) {
try ERC20PresetMinterPauser(denomTokenContract[denom]).burnFrom(account, amount) {
return true;
} catch (bytes memory) {
return false;
}
}
}

0 comments on commit eb0804b

Please sign in to comment.