Skip to content

Commit

Permalink
Merge pull request #64 from maticnetwork/jdkanani/mapping-cleaup
Browse files Browse the repository at this point in the history
chg: add cleanup mapping tokens
  • Loading branch information
jdkanani authored Feb 1, 2021
2 parents 00a77e5 + 1740303 commit 0091d4c
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 2 deletions.
2 changes: 1 addition & 1 deletion artifacts/ChildChainManager.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"abi":[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"rootToken","type":"address"},{"indexed":true,"internalType":"address","name":"childToken","type":"address"}],"name":"TokenMapped","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DEPOSIT","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAPPER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAP_TOKEN","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"STATE_SYNCER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"childToRootToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getRoleMember","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleMemberCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"rootToChildToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"rootToken","type":"address"},{"internalType":"address","name":"childToken","type":"address"}],"name":"mapToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"onStateReceive","outputs":[],"stateMutability":"nonpayable","type":"function"}]}
{"abi":[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"rootToken","type":"address"},{"indexed":true,"internalType":"address","name":"childToken","type":"address"}],"name":"TokenMapped","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DEPOSIT","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAPPER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAP_TOKEN","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"STATE_SYNCER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"childToRootToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getRoleMember","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleMemberCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"rootToChildToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"rootToken","type":"address"},{"internalType":"address","name":"childToken","type":"address"}],"name":"mapToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"onStateReceive","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"rootToken","type":"address"},{"internalType":"address","name":"childToken","type":"address"}],"name":"cleanMapToken","outputs":[],"stateMutability":"nonpayable","type":"function"}]}
2 changes: 1 addition & 1 deletion artifacts/RootChainManager.json

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions contracts/child/ChildChainManager/ChildChainManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,19 @@ contract ChildChainManager is

emit TokenMapped(rootToken, childToken);
}

/**
* @notice Clean polluted token mapping
* @param rootToken address of token on root chain. Since rename token was introduced later stage,
* clean method is used to clean pollulated mapping
*/
function cleanMapToken(
address rootToken,
address childToken
) external override only(MAPPER_ROLE) {
rootToChildToken[rootToken] = address(0);
childToRootToken[childToken] = address(0);

emit TokenMapped(rootToken, childToken);
}
}
1 change: 1 addition & 0 deletions contracts/child/ChildChainManager/IChildChainManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ interface IChildChainManager {
event TokenMapped(address indexed rootToken, address indexed childToken);

function mapToken(address rootToken, address childToken) external;
function cleanMapToken(address rootToken, address childToken) external;
}
5 changes: 5 additions & 0 deletions contracts/root/RootChainManager/IRootChainManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ interface IRootChainManager {
bytes32 tokenType
) external;

function cleanMapToken(
address rootToken,
address childToken
) external;

function remapToken(
address rootToken,
address childToken,
Expand Down
16 changes: 16 additions & 0 deletions contracts/root/RootChainManager/RootChainManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,22 @@ contract RootChainManager is
_mapToken(rootToken, childToken, tokenType);
}

/**
* @notice Clean polluted token mapping
* @param rootToken address of token on root chain. Since rename token was introduced later stage,
* clean method is used to clean pollulated mapping
*/
function cleanMapToken(
address rootToken,
address childToken
) external override only(MAPPER_ROLE) {
rootToChildToken[rootToken] = address(0);
childToRootToken[childToken] = address(0);
tokenToType[rootToken] = bytes32(0);

emit TokenMapped(rootToken, childToken, tokenToType[rootToken]);
}

/**
* @notice Remap a token that has already been mapped, properly cleans up old mapping
* Callable only by mappers
Expand Down
16 changes: 16 additions & 0 deletions flat/ChildChainManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ interface IChildChainManager {
event TokenMapped(address indexed rootToken, address indexed childToken);

function mapToken(address rootToken, address childToken) external;
function cleanMapToken(address rootToken, address childToken) external;
}

// File: contracts/child/ChildToken/IChildToken.sol
Expand Down Expand Up @@ -883,4 +884,19 @@ contract ChildChainManager is

emit TokenMapped(rootToken, childToken);
}

/**
* @notice Clean polluted token mapping
* @param rootToken address of token on root chain. Since rename token was introduced later stage,
* clean method is used to clean pollulated mapping
*/
function cleanMapToken(
address rootToken,
address childToken
) external override only(MAPPER_ROLE) {
rootToChildToken[rootToken] = address(0);
childToRootToken[childToken] = address(0);

emit TokenMapped(rootToken, childToken);
}
}
21 changes: 21 additions & 0 deletions flat/RootChainManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ interface IRootChainManager {
bytes32 tokenType
) external;

function cleanMapToken(
address rootToken,
address childToken
) external;

function remapToken(
address rootToken,
address childToken,
Expand Down Expand Up @@ -1816,6 +1821,22 @@ contract RootChainManager is
_mapToken(rootToken, childToken, tokenType);
}

/**
* @notice Clean polluted token mapping
* @param rootToken address of token on root chain. Since rename token was introduced later stage,
* clean method is used to clean pollulated mapping
*/
function cleanMapToken(
address rootToken,
address childToken
) external override only(MAPPER_ROLE) {
rootToChildToken[rootToken] = address(0);
childToRootToken[childToken] = address(0);
tokenToType[rootToken] = bytes32(0);

emit TokenMapped(rootToken, childToken, tokenToType[rootToken]);
}

/**
* @notice Remap a token that has already been mapped, properly cleans up old mapping
* Callable only by mappers
Expand Down

0 comments on commit 0091d4c

Please sign in to comment.