From 8e750c4e3d69a1bb2ea76e5ac6ebbe9307a86cd2 Mon Sep 17 00:00:00 2001 From: jxom Date: Tue, 10 Sep 2024 07:55:55 +1000 Subject: [PATCH] chore: refactor --- src/chains/definitions/abstractTestnet.ts | 79 +++++++++-------------- src/zksync/utils/getEip712Domain.ts | 3 - 2 files changed, 32 insertions(+), 50 deletions(-) diff --git a/src/chains/definitions/abstractTestnet.ts b/src/chains/definitions/abstractTestnet.ts index 0b560d4d78..d261e2d777 100644 --- a/src/chains/definitions/abstractTestnet.ts +++ b/src/chains/definitions/abstractTestnet.ts @@ -1,51 +1,7 @@ -import { transactionToMessage } from '../..//zksync/utils/getEip712Domain.js' import { defineChain } from '../../utils/chain/defineChain.js' import { chainConfig } from '../../zksync/chainConfig.js' -import type { EIP712DomainFn } from '../../zksync/types/eip712.js' -import type { - ZksyncEIP712TransactionSignable, - ZksyncTransactionSerializable, - ZksyncTransactionSerializableEIP712, -} from '../../zksync/types/transaction.js' -import { assertEip712Transaction } from '../../zksync/utils/assertEip712Transaction.js' - -export const getAbstractEip712Domain: EIP712DomainFn< - ZksyncTransactionSerializable, - ZksyncEIP712TransactionSignable -> = (transaction) => { - assertEip712Transaction(transaction) - - const message = transactionToMessage( - transaction as ZksyncTransactionSerializableEIP712, - ) - - return { - domain: { - name: 'Abstract', // Use 'Abstract' rather than 'zkSync' - version: '2', - chainId: transaction.chainId, - }, - types: { - Transaction: [ - { name: 'txType', type: 'uint256' }, - { name: 'from', type: 'uint256' }, - { name: 'to', type: 'uint256' }, - { name: 'gasLimit', type: 'uint256' }, - { name: 'gasPerPubdataByteLimit', type: 'uint256' }, - { name: 'maxFeePerGas', type: 'uint256' }, - { name: 'maxPriorityFeePerGas', type: 'uint256' }, - { name: 'paymaster', type: 'uint256' }, - { name: 'nonce', type: 'uint256' }, - { name: 'value', type: 'uint256' }, - { name: 'data', type: 'bytes' }, - { name: 'factoryDeps', type: 'bytes32[]' }, - { name: 'paymasterInput', type: 'bytes' }, - ], - }, - primaryType: 'Transaction', - message: message, - } -} +import type { ZksyncTransactionSerializableEIP712 } from '../../zksync/types/transaction.js' +import { transactionToMessage } from '../../zksync/utils/getEip712Domain.js' export const abstractTestnet = /*#__PURE__*/ defineChain({ ...chainConfig, @@ -67,6 +23,35 @@ export const abstractTestnet = /*#__PURE__*/ defineChain({ }, testnet: true, custom: { - getEip712Domain: getAbstractEip712Domain, // Use Abstract's specific EIP712 domain + getEip712Domain(transaction: ZksyncTransactionSerializableEIP712) { + const message = transactionToMessage(transaction) + + return { + domain: { + name: 'Abstract', // Use 'Abstract' rather than 'zkSync' + version: '2', + chainId: transaction.chainId, + }, + types: { + Transaction: [ + { name: 'txType', type: 'uint256' }, + { name: 'from', type: 'uint256' }, + { name: 'to', type: 'uint256' }, + { name: 'gasLimit', type: 'uint256' }, + { name: 'gasPerPubdataByteLimit', type: 'uint256' }, + { name: 'maxFeePerGas', type: 'uint256' }, + { name: 'maxPriorityFeePerGas', type: 'uint256' }, + { name: 'paymaster', type: 'uint256' }, + { name: 'nonce', type: 'uint256' }, + { name: 'value', type: 'uint256' }, + { name: 'data', type: 'bytes' }, + { name: 'factoryDeps', type: 'bytes32[]' }, + { name: 'paymasterInput', type: 'bytes' }, + ], + }, + primaryType: 'Transaction', + message: message, + } + }, }, }) diff --git a/src/zksync/utils/getEip712Domain.ts b/src/zksync/utils/getEip712Domain.ts index 04c716504b..7eb9df5acc 100644 --- a/src/zksync/utils/getEip712Domain.ts +++ b/src/zksync/utils/getEip712Domain.ts @@ -6,15 +6,12 @@ import type { ZksyncTransactionSerializable, ZksyncTransactionSerializableEIP712, } from '../types/transaction.js' -import { assertEip712Transaction } from './assertEip712Transaction.js' import { hashBytecode } from './hashBytecode.js' export const getEip712Domain: EIP712DomainFn< ZksyncTransactionSerializable, ZksyncEIP712TransactionSignable > = (transaction) => { - assertEip712Transaction(transaction) - const message = transactionToMessage( transaction as ZksyncTransactionSerializableEIP712, )