diff --git a/contracts/WalletSimple.sol b/contracts/WalletSimple.sol index 1bc11fe..02e31fe 100644 --- a/contracts/WalletSimple.sol +++ b/contracts/WalletSimple.sol @@ -7,6 +7,7 @@ import './IForwarder.sol'; /** ERC721, ERC1155 imports */ import '@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol'; import '@openzeppelin/contracts/token/ERC1155/utils/ERC1155Receiver.sol'; +import '@openzeppelin/contracts/utils/Strings.sol'; /** * @@ -29,8 +30,8 @@ import '@openzeppelin/contracts/token/ERC1155/utils/ERC1155Receiver.sol'; * Unlike eth_sign, the message is not prefixed. * * The operationHash the result of keccak256(prefix, toAddress, value, data, expireTime). - * For ether transactions, `prefix` is "ETHER". - * For token transaction, `prefix` is "ERC20" and `data` is the tokenContractAddress. + * For ether transactions, `prefix` is chain id of the coin i.e. for eth mainnet it is "1". + * For token transaction, `prefix` is chain id + "-ERC20" i.e. for mainnet it is "1-ERC20" and `data` is the tokenContractAddress. * * */ @@ -93,8 +94,8 @@ contract WalletSimple is IERC721Receiver, ERC1155Receiver { * to allow this contract to be used by proxy with delegatecall, which will * not pick up on state variables */ - function getNetworkId() internal pure virtual returns (string memory) { - return 'ETHER'; + function getNetworkId() internal view virtual returns (string memory) { + return Strings.toString(block.chainid); } /** @@ -105,8 +106,8 @@ contract WalletSimple is IERC721Receiver, ERC1155Receiver { * to allow this contract to be used by proxy with delegatecall, which will * not pick up on state variables */ - function getTokenNetworkId() internal pure virtual returns (string memory) { - return 'ERC20'; + function getTokenNetworkId() internal view virtual returns (string memory) { + return string.concat(Strings.toString(block.chainid), '-ERC20'); } /** @@ -117,8 +118,8 @@ contract WalletSimple is IERC721Receiver, ERC1155Receiver { * to allow this contract to be used by proxy with delegatecall, which will * not pick up on state variables */ - function getBatchNetworkId() internal pure virtual returns (string memory) { - return 'ETHER-Batch'; + function getBatchNetworkId() internal view virtual returns (string memory) { + return string.concat(Strings.toString(block.chainid), '-Batch'); } /** diff --git a/contracts/coins/ArbethWalletSimple.sol b/contracts/coins/ArbethWalletSimple.sol index 7970f64..0fe579c 100644 --- a/contracts/coins/ArbethWalletSimple.sol +++ b/contracts/coins/ArbethWalletSimple.sol @@ -25,8 +25,8 @@ import '../WalletSimple.sol'; * Unlike eth_sign, the message is not prefixed. * * The operationHash the result of keccak256(prefix, toAddress, value, data, expireTime). - * For ether transactions, `prefix` is "ARBETH". - * For token transaction, `prefix` is "ARBETH-ERC20" and `data` is the tokenContractAddress. + * For ether transactions, `prefix` is chain id of the coin i.e. for arbitrum mainnet it is "42161" + * For token transaction, `prefix` is "42161-ERC20" and `data` is the tokenContractAddress. * * */ @@ -35,23 +35,23 @@ contract ArbethWalletSimple is WalletSimple { * Get the network identifier that signers must sign over * This provides protection signatures being replayed on other chains */ - function getNetworkId() internal override pure returns (string memory) { - return 'ARBETH'; + function getNetworkId() internal override view returns (string memory) { + return Strings.toString(block.chainid); } /** * Get the network identifier that signers must sign over for token transfers * This provides protection signatures being replayed on other chains */ - function getTokenNetworkId() internal override pure returns (string memory) { - return 'ARBETH-ERC20'; + function getTokenNetworkId() internal override view returns (string memory) { + return string.concat(Strings.toString(block.chainid), '-ERC20'); } /** * Get the network identifier that signers must sign over for batch transfers * This provides protection signatures being replayed on other chains */ - function getBatchNetworkId() internal override pure returns (string memory) { - return 'ARBETH-Batch'; + function getBatchNetworkId() internal override view returns (string memory) { + return string.concat(Strings.toString(block.chainid), '-Batch'); } } diff --git a/contracts/coins/OpethWalletSimple.sol b/contracts/coins/OpethWalletSimple.sol index c8f8626..f1ed494 100644 --- a/contracts/coins/OpethWalletSimple.sol +++ b/contracts/coins/OpethWalletSimple.sol @@ -25,8 +25,8 @@ import '../WalletSimple.sol'; * Unlike eth_sign, the message is not prefixed. * * The operationHash the result of keccak256(prefix, toAddress, value, data, expireTime). - * For ether transactions, `prefix` is "OPETH". - * For token transaction, `prefix` is "OPETH-ERC20" and `data` is the tokenContractAddress. + * For ether transactions, `prefix` is chain id of the coin i.e. for optimism mainnet it is "10" + * For token transaction, `prefix` is "10-ERC20" and `data` is the tokenContractAddress. * * */ @@ -35,23 +35,23 @@ contract OpethWalletSimple is WalletSimple { * Get the network identifier that signers must sign over * This provides protection signatures being replayed on other chains */ - function getNetworkId() internal override pure returns (string memory) { - return 'OPETH'; + function getNetworkId() internal override view returns (string memory) { + return Strings.toString(block.chainid); } /** * Get the network identifier that signers must sign over for token transfers * This provides protection signatures being replayed on other chains */ - function getTokenNetworkId() internal override pure returns (string memory) { - return 'OPETH-ERC20'; + function getTokenNetworkId() internal override view returns (string memory) { + return string.concat(Strings.toString(block.chainid), '-ERC20'); } /** * Get the network identifier that signers must sign over for batch transfers * This provides protection signatures being replayed on other chains */ - function getBatchNetworkId() internal override pure returns (string memory) { - return 'OPETH-Batch'; + function getBatchNetworkId() internal override view returns (string memory) { + return string.concat(Strings.toString(block.chainid), '-Batch'); } }