@@ -6,12 +6,14 @@ import { Create2 } from '../../lib/Create2.sol';
66import { Ownable } from '../../lib/Ownable.sol ' ;
77import { FxERC20 } from '../../tokens/FxERC20.sol ' ;
88
9+
910/**
1011 * @title FxMintableERC20ChildTunnel
1112 */
1213contract FxMintableERC20ChildTunnel is Ownable , FxBaseChildTunnel , Create2 {
1314 bytes32 public constant DEPOSIT = keccak256 ("DEPOSIT " );
14- bytes32 public constant MAP_TOKEN = keccak256 ("MAP_TOKEN " );
15+ //bytes32 public constant MAP_TOKEN = keccak256("MAP_TOKEN");
16+
1517
1618 // event for token maping
1719 event TokenMapped (address indexed rootToken , address indexed childToken );
@@ -42,10 +44,29 @@ contract FxMintableERC20ChildTunnel is Ownable, FxBaseChildTunnel, Create2 {
4244 // check if mapping is already there
4345 require (rootToChildToken[rootToken] == address (0x0 ), "FxMintableERC20ChildTunnel: ALREADY_MAPPED " );
4446 rootToChildToken[rootToken] = childToken;
45-
47+ emit TokenMapped (rootToken,childToken);
48+
4649 // initialize child token with all parameters
4750 FxERC20 (childToken).initialize (address (this ), rootToken, name, symbol, decimals);
4851 }
52+
53+ //To mint tokens on child chain
54+ function mintToken (address childToken , uint256 amount ) public onlyOwner {
55+ FxERC20 childTokenContract = FxERC20 (childToken);
56+ // child token contract will have root token
57+ address rootToken = childTokenContract.connectedToken ();
58+
59+ // validate root and child token mapping
60+ require (
61+ childToken != address (0x0 ) &&
62+ rootToken != address (0x0 ) &&
63+ childToken == rootToChildToken[rootToken],
64+ "FxERC20ChildTunnel: NO_MAPPED_TOKEN "
65+ );
66+
67+ //mint token
68+ childTokenContract.mint (msg .sender , amount);
69+ }
4970
5071 function withdraw (address childToken , uint256 amount ) public {
5172 FxERC20 childTokenContract = FxERC20 (childToken);
@@ -62,9 +83,9 @@ contract FxMintableERC20ChildTunnel is Ownable, FxBaseChildTunnel, Create2 {
6283
6384 // withdraw tokens
6485 childTokenContract.burn (msg .sender , amount);
65-
86+
6687 // name, symbol and decimals
67- FxERC20 rootTokenContract = FxERC20 (rootToken );
88+ FxERC20 rootTokenContract = FxERC20 (childToken );
6889 string memory name = rootTokenContract.name ();
6990 string memory symbol = rootTokenContract.symbol ();
7091 uint8 decimals = rootTokenContract.decimals ();
@@ -86,12 +107,14 @@ contract FxMintableERC20ChildTunnel is Ownable, FxBaseChildTunnel, Create2 {
86107 // decode incoming data
87108 (bytes32 syncType , bytes memory syncData ) = abi.decode (data, (bytes32 , bytes ));
88109
110+
89111 if (syncType == DEPOSIT) {
90112 _syncDeposit (syncData);
91- } else {
113+ } else {
92114 revert ("FxERC20ChildTunnel: INVALID_SYNC_TYPE " );
93115 }
94116 }
117+
95118
96119 function _syncDeposit (bytes memory syncData ) internal {
97120 (address rootToken , address depositor , address to , uint256 amount , bytes memory depositData ) = abi.decode (syncData, (address , address , address , uint256 , bytes ));
@@ -122,3 +145,4 @@ contract FxMintableERC20ChildTunnel is Ownable, FxBaseChildTunnel, Create2 {
122145 return (size > 0 );
123146 }
124147}
148+
0 commit comments