Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Win 1423 update v4 contracts arbeth opeth #114

Merged
merged 4 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions contracts/WalletSimple.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
*
Expand All @@ -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.
*
*
*/
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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');
}

/**
Expand All @@ -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');
}

/**
Expand Down
16 changes: 8 additions & 8 deletions contracts/coins/ArbethWalletSimple.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
*
*/
Expand All @@ -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');
}
}
16 changes: 8 additions & 8 deletions contracts/coins/OpethWalletSimple.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
*
*/
Expand All @@ -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');
}
}
12 changes: 7 additions & 5 deletions test/gas.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ describe(`Wallet Operations Gas Usage`, function () {
value: amount
});

// By default the chain id of hardhat network is 31337
const operationHash = helpers.getSha3ForConfirmationTx(
'ETHER',
'31337',
destinationAccount,
amount,
data,
Expand Down Expand Up @@ -120,7 +121,7 @@ describe(`Wallet Operations Gas Usage`, function () {
.eq(destinationEndBalance)
.should.be.true();

checkGasUsed(99555, transaction.receipt.gasUsed);
checkGasUsed(100585, transaction.receipt.gasUsed);
});

const sendBatchHelper = async (batchSize) => {
Expand All @@ -147,8 +148,9 @@ describe(`Wallet Operations Gas Usage`, function () {
});

// Get the operation hash to be signed
// By default the chain id of hardhat network is 31337
const operationHash = helpers.getSha3ForBatchTx(
'ETHER-Batch',
'31337-Batch',
recipients.map((recipient) => recipient.address.toLowerCase()),
recipients.map((recipient) => recipient.amount),
expireTime,
Expand Down Expand Up @@ -178,8 +180,8 @@ describe(`Wallet Operations Gas Usage`, function () {

it('WalletSimple send batch [ @skip-on-coverage ]', async function () {
const gasUsageByBatchSize = [
101810, 113113, 124451, 135753, 147126, 158442, 169709, 181023, 192338,
203641
103386, 114701, 126027, 137341, 148655, 159971, 171285, 182599, 193902,
205205
];

for (let batchSize = 1; batchSize <= 10; batchSize++) {
Expand Down
3 changes: 2 additions & 1 deletion test/walletFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ describe('WalletFactory', function () {

// Get the operation hash to be signed
const expireTime = Math.floor(new Date().getTime() / 1000) + 60;
// By default the chain id of hardhat network is 31337
const operationHash = helpers.getSha3ForConfirmationTx(
'ETHER',
'31337',
accounts[3].toLowerCase(),
amount,
'0x',
Expand Down
19 changes: 10 additions & 9 deletions test/walletSimple.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ const FORWARDER_DEPOSITED_EVENT = 'ForwarderDeposited';
const TRANSACTED_EVENT = 'Transacted';
const SAFE_MODE_ACTIVATE_EVENT = 'SafeModeActivated';

// By default the chain id of hardhat network is 31337
const coins = [
{
name: 'Eth',
nativePrefix: 'ETHER',
nativeBatchPrefix: 'ETHER-Batch',
tokenPrefix: 'ERC20',
nativePrefix: '31337',
nativeBatchPrefix: '31337-Batch',
tokenPrefix: '31337-ERC20',
WalletSimple: EthWalletSimple
},
{
Expand Down Expand Up @@ -84,16 +85,16 @@ const coins = [
},
{
name: 'Arbeth',
nativePrefix: 'ARBETH',
nativeBatchPrefix: 'ARBETH-Batch',
tokenPrefix: 'ARBETH-ERC20',
nativePrefix: '31337',
nativeBatchPrefix: '31337-Batch',
tokenPrefix: '31337-ERC20',
WalletSimple: ArbethWalletSimple
},
{
name: 'Opeth',
nativePrefix: 'OPETH',
nativeBatchPrefix: 'OPETH-Batch',
tokenPrefix: 'OPETH-ERC20',
nativePrefix: '31337',
nativeBatchPrefix: '31337-Batch',
tokenPrefix: '31337-ERC20',
WalletSimple: OpethWalletSimple
}
];
Expand Down