diff --git a/hardhat.config.ts b/hardhat.config.ts index 95821e6..15254e7 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -1,10 +1,10 @@ import { HardhatUserConfig, task } from 'hardhat/config' import { networkConfig } from './utils/config-loader' -import '@nomiclabs/hardhat-truffle5' import '@nomicfoundation/hardhat-ethers' +import '@nomicfoundation/hardhat-verify' +import '@nomiclabs/hardhat-truffle5' import '@nomiclabs/hardhat-web3' -import '@nomiclabs/hardhat-etherscan' import '@tenderly/hardhat-tenderly' import 'hardhat-gas-reporter' diff --git a/package.json b/package.json index 916280b..581c31f 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ }, "devDependencies": { "@nomicfoundation/hardhat-ethers": "^3.0.5", - "@nomiclabs/hardhat-etherscan": "^3.1.8", + "@nomicfoundation/hardhat-verify": "^2.0.4", "@nomiclabs/hardhat-truffle5": "^2.0.7", "@nomiclabs/hardhat-web3": "^2.0.0", "@tenderly/hardhat-tenderly": "^1.0.11", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 91b0122..eafc0b7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -19,9 +19,9 @@ devDependencies: '@nomicfoundation/hardhat-ethers': specifier: ^3.0.5 version: 3.0.5(ethers@6.11.1)(hardhat@2.20.1) - '@nomiclabs/hardhat-etherscan': - specifier: ^3.1.8 - version: 3.1.8(hardhat@2.20.1) + '@nomicfoundation/hardhat-verify': + specifier: ^2.0.4 + version: 2.0.4(hardhat@2.20.1) '@nomiclabs/hardhat-truffle5': specifier: ^2.0.7 version: 2.0.7(@nomiclabs/hardhat-web3@2.0.0)(hardhat@2.20.1)(web3-core-helpers@1.10.3)(web3-core-promievent@1.10.3)(web3-eth-abi@1.10.4)(web3-utils@1.10.4)(web3@1.10.4) @@ -973,6 +973,25 @@ packages: - supports-color dev: true + /@nomicfoundation/hardhat-verify@2.0.4(hardhat@2.20.1): + resolution: {integrity: sha512-B8ZjhOrmbbRWqJi65jvQblzjsfYktjqj2vmOm+oc2Vu8drZbT2cjeSCRHZKbS7lOtfW78aJZSFvw+zRLCiABJA==} + peerDependencies: + hardhat: ^2.0.4 + dependencies: + '@ethersproject/abi': 5.7.0 + '@ethersproject/address': 5.7.0 + cbor: 8.1.0 + chalk: 2.4.2 + debug: 4.3.4(supports-color@8.1.1) + hardhat: 2.20.1(ts-node@10.9.1)(typescript@4.7.4) + lodash.clonedeep: 4.5.0 + semver: 6.3.1 + table: 6.8.1 + undici: 5.28.3 + transitivePeerDependencies: + - supports-color + dev: true + /@nomicfoundation/solidity-analyzer-darwin-arm64@0.1.1: resolution: {integrity: sha512-KcTodaQw8ivDZyF+D76FokN/HdpgGpfjc/gFCImdLUyqB6eSWVaZPazMbeAjmfhx3R0zm/NYVzxwAokFKgrc0w==} engines: {node: '>= 10'} @@ -1079,27 +1098,6 @@ packages: '@nomicfoundation/solidity-analyzer-win32-x64-msvc': 0.1.1 dev: true - /@nomiclabs/hardhat-etherscan@3.1.8(hardhat@2.20.1): - resolution: {integrity: sha512-v5F6IzQhrsjHh6kQz4uNrym49brK9K5bYCq2zQZ729RYRaifI9hHbtmK+KkIVevfhut7huQFEQ77JLRMAzWYjQ==} - deprecated: The @nomiclabs/hardhat-etherscan package is deprecated, please use @nomicfoundation/hardhat-verify instead - peerDependencies: - hardhat: ^2.0.4 - dependencies: - '@ethersproject/abi': 5.7.0 - '@ethersproject/address': 5.7.0 - cbor: 8.1.0 - chalk: 2.4.2 - debug: 4.3.4(supports-color@8.1.1) - fs-extra: 7.0.1 - hardhat: 2.20.1(ts-node@10.9.1)(typescript@4.7.4) - lodash: 4.17.21 - semver: 6.3.1 - table: 6.8.1 - undici: 5.28.3 - transitivePeerDependencies: - - supports-color - dev: true - /@nomiclabs/hardhat-truffle5@2.0.7(@nomiclabs/hardhat-web3@2.0.0)(hardhat@2.20.1)(web3-core-helpers@1.10.3)(web3-core-promievent@1.10.3)(web3-eth-abi@1.10.4)(web3-utils@1.10.4)(web3@1.10.4): resolution: {integrity: sha512-Pw8451IUZp1bTp0QqCHCYfCHs66sCnyxPcaorapu9mfOV9xnZsVaFdtutnhNEiXdiZwbed7LFKpRsde4BjFwig==} peerDependencies: @@ -7355,6 +7353,10 @@ packages: /lodash.camelcase@4.3.0: resolution: {integrity: sha512-TwuEnCnxbc3rAvhf/LbG7tJUDzhqXyFnv3dtzLOPgCG/hODL7WFnsbwktkD7yUV0RrreP/l1PALq/YSg6VvjlA==} + /lodash.clonedeep@4.5.0: + resolution: {integrity: sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ==} + dev: true + /lodash.isequal@4.5.0: resolution: {integrity: sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==} dev: true diff --git a/test/GuestModule.spec.ts b/test/GuestModule.spec.ts index 39fbd5a..7d466e3 100644 --- a/test/GuestModule.spec.ts +++ b/test/GuestModule.spec.ts @@ -72,7 +72,8 @@ contract('GuestModule', () => { await expectToBeRejected(tx, 'DelegateCallNotAllowed(0)') }) it('Should not accept ETH', async () => { - const tx = hethers.provider.getSigner().sendTransaction({ value: 1, to: await guestModule.getAddress() }) + const signer = await hethers.provider.getSigner() + const tx = signer.sendTransaction({ value: 1, to: await guestModule.getAddress() }) await expect(tx).to.be.rejected }) it('Should not implement hooks', async () => { diff --git a/test/MainModule.spec.ts b/test/MainModule.spec.ts index 39aa3e9..69cb1c7 100644 --- a/test/MainModule.spec.ts +++ b/test/MainModule.spec.ts @@ -1,7 +1,7 @@ import { ethers } from 'ethers' import { ethers as hethers } from 'hardhat' -import { bytes32toAddress, CHAIN_ID, expect, expectToBeRejected, randomHex } from './utils' +import { bytes32toAddress, getChainId, expect, expectToBeRejected, randomHex } from './utils' import { CallReceiverMock, @@ -243,7 +243,7 @@ contract('MainModule', (accounts: string[]) => { data: callReceiver.interface.encodeFunctionData('testCall', [5423, randomHex(32)]) } - const subdigest = subdigestOf(wallet.address, digestOf([transaction], await wallet.getNonce())) + const subdigest = await subdigestOf(wallet.address, digestOf([transaction], await wallet.getNonce())) const badNestedSignature = await wallet_b.signDigest(subdigest).then(s => s + '03') const tx = wallet.sendTransactions([transaction]) @@ -261,7 +261,7 @@ contract('MainModule', (accounts: string[]) => { await wallet.deploy() const signauture = await wallet.signTransactions([{}]) - const subdigest = subdigestOf(wallet.address, digestOf([{}], await wallet.getNonce())) + const subdigest = await subdigestOf(wallet.address, digestOf([{}], await wallet.getNonce())) const tx = wallet.relayTransactions([{}], signauture) await expect(tx).to.be.rejected @@ -310,14 +310,14 @@ contract('MainModule', (accounts: string[]) => { describe('Network ID', () => { it('Should reject a transaction of another network id', async () => { - wallet = wallet.useChainId(CHAIN_ID() + 1) + wallet = wallet.useChainId((await getChainId()) + 1n) const tx = wallet.sendTransactions([{}]) await expectToBeRejected(tx, 'InvalidSignature') }) describe('Universal network signatures', async () => { it('Should reject signature for another network id, even if encoded as universal', async () => { - wallet = wallet.useChainId(CHAIN_ID() + 1) + wallet = wallet.useChainId((await getChainId()) + 1n) const tx = wallet.sendTransactions([{}]) await expectToBeRejected(tx, 'InvalidSignature') }) @@ -438,7 +438,7 @@ contract('MainModule', (accounts: string[]) => { await wallet.sendTransactions([{}], encodeNonce(space, 0)) - const storageValue = await hethers.provider.getStorageAt(wallet.address, storageKey) + const storageValue = await hethers.provider.getStorage(wallet.address, storageKey) expect(BigInt(storageValue)).to.equal(1) }) }) @@ -501,7 +501,7 @@ contract('MainModule', (accounts: string[]) => { it('Should reject signature with bad encoding type', async () => { const tx = wallet.relayTransactions([{}], '0x2012') - const subdigest = subdigestOf(wallet.address, digestOf([{}], 0)) + const subdigest = await subdigestOf(wallet.address, digestOf([{}], 0)) await expectToBeRejected(tx, `InvalidSignatureType("0x20")`) }) @@ -559,7 +559,7 @@ contract('MainModule', (accounts: string[]) => { it('Should use implementation storage key', async () => { await wallet.updateImageHash(ethers.randomBytes(32)) - const storageValue = await hethers.provider.getStorageAt(wallet.address, wallet.address) + const storageValue = await hethers.provider.getStorage(wallet.address, wallet.address) expect(bytes32toAddress(storageValue)).to.equal(await context.mainModuleUpgradable.getAddress()) }) }) @@ -677,7 +677,7 @@ contract('MainModule', (accounts: string[]) => { describe(c.name, () => { it('Should reject proof for another subdigest', async () => { const digests = new Array(2).fill(0).map(() => ethers.hexlify(ethers.randomBytes(32))) - const subdigests = digests.map(d => ({ subdigest: subdigestOf(wallet.address, d, 0) })) + const subdigests = await Promise.all(digests.map(async d => ({ subdigest: await subdigestOf(wallet.address, d, 0) }))) const subdigestsMerkle = merkleTopology([...subdigests]) const prevLeaves = leavesOf(wallet.config.topology) @@ -700,7 +700,7 @@ contract('MainModule', (accounts: string[]) => { wallet = SequenceWallet.basicWallet(context, { signing: 10, idle: 11 }) const digests = new Array(33).fill(0).map(() => ethers.hexlify(ethers.randomBytes(32))) - const subdigests = digests.map(d => ({ subdigest: subdigestOf(wallet.address, d, 0) })) + const subdigests = await Promise.all(digests.map(async d => ({ subdigest: await subdigestOf(wallet.address, d, 0) }))) const subdigestsMerkle = merkleTopology([...subdigests]) const prevLeaves = leavesOf(wallet.config.topology) @@ -891,7 +891,8 @@ contract('MainModule', (accounts: string[]) => { }) it('Should perform call a contract and transfer eth in one tx', async () => { - await hethers.provider.getSigner().sendTransaction({ to: wallet.address, value: 100 }) + const signer = await hethers.provider.getSigner() + await signer.sendTransaction({ to: wallet.address, value: 100 }) const receiver = new ethers.Wallet(ethers.hexlify(ethers.randomBytes(32))) const transactions = [ @@ -913,7 +914,8 @@ contract('MainModule', (accounts: string[]) => { }) it('Should fail if one transaction fails', async () => { - await hethers.provider.getSigner().sendTransaction({ to: wallet.address, value: 100 }) + const signer = await hethers.provider.getSigner() + await signer.sendTransaction({ to: wallet.address, value: 100 }) await callReceiver.setRevertFlag(true) @@ -1004,11 +1006,13 @@ contract('MainModule', (accounts: string[]) => { describe('Handle ETH', () => { it('Should receive ETH', async () => { - hethers.provider.getSigner().sendTransaction({ to: wallet.address, value: 1 }) + const signer = await hethers.provider.getSigner() + signer.sendTransaction({ to: wallet.address, value: 1 }) }) it('Should transfer ETH', async () => { - hethers.provider.getSigner().sendTransaction({ to: wallet.address, value: 100 }) + const signer = await hethers.provider.getSigner() + signer.sendTransaction({ to: wallet.address, value: 100 }) const receiver = ethers.Wallet.createRandom().address @@ -1022,7 +1026,8 @@ contract('MainModule', (accounts: string[]) => { }) it('Should call payable function', async () => { - hethers.provider.getSigner().sendTransaction({ to: wallet.address, value: 100 }) + const signer = await hethers.provider.getSigner() + signer.sendTransaction({ to: wallet.address, value: 100 }) const valA = 63129 const valB = randomHex(120) @@ -1124,7 +1129,7 @@ contract('MainModule', (accounts: string[]) => { } ] - const txHash = subdigestOf(wallet.address, digestOf(transactions, await wallet.getNonce())) + const txHash = await subdigestOf(wallet.address, digestOf(transactions, await wallet.getNonce())) const receipt = await wallet.sendTransactions(transactions).then(r => r.wait()) if (!receipt) { @@ -1286,7 +1291,7 @@ contract('MainModule', (accounts: string[]) => { const subkey = ethers.AbiCoder.defaultAbiCoder().encode(['bytes4'], [hookSelector]) const storageKey = computeStorageKey('org.arcadeum.module.hooks.hooks', subkey) - const storageValue = await hethers.provider.getStorageAt(wallet.address, storageKey) + const storageValue = await hethers.provider.getStorage(wallet.address, storageKey) const addr = (() => { try { @@ -1302,7 +1307,8 @@ contract('MainModule', (accounts: string[]) => { it('Should pass calling a non registered hook', async () => { const data = ethers.AbiCoder.defaultAbiCoder().encode(['bytes4'], [hookSelector]) - await hethers.provider.getSigner().sendTransaction({ to: wallet.address, data: data }) + const signer = await hethers.provider.getSigner() + await signer.sendTransaction({ to: wallet.address, data: data }) }) }) @@ -1317,18 +1323,14 @@ contract('MainModule', (accounts: string[]) => { await wallet.sendTransactions([transaction]) + const signer = await hethers.provider.getSigner() + // Calling the wallet with '0x112233' should not forward the call to the hook - const tx = hethers.provider - .getSigner() - .sendTransaction({ to: wallet.address, data: '0x112233' }) - .then(t => t.wait()) + const tx = signer.sendTransaction({ to: wallet.address, data: '0x112233' }).then(t => t.wait()) await expect(tx).to.be.fulfilled // Calling the wallet with '0x11223300' should forward the call to the hook (and thus revert) - const tx2 = hethers.provider - .getSigner() - .sendTransaction({ to: wallet.address, data: '0x11223300' }) - .then(t => t.wait()) + const tx2 = signer.sendTransaction({ to: wallet.address, data: '0x11223300' }).then(t => t.wait()) await expect(tx2).to.be.rejected }) @@ -1431,7 +1433,7 @@ contract('MainModule', (accounts: string[]) => { it('Should use image hash storage key', async () => { const storageKey = computeStorageKey('org.arcadeum.module.auth.upgradable.image.hash') - const storageValue = await hethers.provider.getStorageAt(wallet.address, storageKey) + const storageValue = await hethers.provider.getStorage(wallet.address, storageKey) expect(ethers.AbiCoder.defaultAbiCoder().encode(['bytes32'], [storageValue])).to.equal(walletb.imageHash) }) @@ -1463,7 +1465,7 @@ contract('MainModule', (accounts: string[]) => { it('Should use image hash storage key', async () => { const storageKey = computeStorageKey('org.arcadeum.module.auth.upgradable.image.hash') - const storageValue = await hethers.provider.getStorageAt(walletb.address, storageKey) + const storageValue = await hethers.provider.getStorage(walletb.address, storageKey) expect(ethers.AbiCoder.defaultAbiCoder().encode(['bytes32'], [storageValue])).to.equal(walletc.imageHash) }) }) @@ -1950,7 +1952,8 @@ contract('MainModule', (accounts: string[]) => { it('Should create a contract with value', async () => { const deployCode = CallReceiverMock.factory().bytecode - await hethers.provider.getSigner().sendTransaction({ to: wallet.address, value: 100 }) + const signer = await hethers.provider.getSigner() + await signer.sendTransaction({ to: wallet.address, value: 100 }) const transaction = { target: wallet.address, @@ -1979,7 +1982,7 @@ contract('MainModule', (accounts: string[]) => { describe('Transaction events', () => { it('Should emit TxExecuted event', async () => { - const txHash = subdigestOf(wallet.address, digestOf([{}], await wallet.getNonce())) + const txHash = await subdigestOf(wallet.address, digestOf([{}], await wallet.getNonce())) const res = await wallet.sendTransactions([{}]) const receipt = await res.wait() @@ -1997,7 +2000,7 @@ contract('MainModule', (accounts: string[]) => { }) it('Should emit multiple TxExecuted events', async () => { - const txHash = subdigestOf(wallet.address, digestOf([{}, {}], await wallet.getNonce())) + const txHash = await subdigestOf(wallet.address, digestOf([{}, {}], await wallet.getNonce())) const receipt = await wallet.sendTransactions([{}, {}]).then(t => t.wait()) if (!receipt) { diff --git a/test/MultiCallUtils.spec.ts b/test/MultiCallUtils.spec.ts index e3646cb..085e7b7 100644 --- a/test/MultiCallUtils.spec.ts +++ b/test/MultiCallUtils.spec.ts @@ -1,7 +1,7 @@ import { ethers } from 'ethers' import { ethers as hethers } from 'hardhat' -import { CHAIN_ID, encodeError, expect, expectStaticToBeRejected } from './utils' +import { getChainId, encodeError, expect, expectStaticToBeRejected } from './utils' import { CallReceiverMock, ContractType, MultiCallUtils } from './utils/contracts' import { applyTxDefault, applyTxDefaults } from './utils/sequence' @@ -210,7 +210,7 @@ contract('Multi call utils', (accounts: string[]) => { const txs = await Promise.all( [ - i.encodeFunctionData('callBlockhash', [lastBlock.number - 1]), + i.encodeFunctionData('callBlockhash', [lastBlock!.number - 1]), i.encodeFunctionData('callCoinbase'), i.encodeFunctionData('callDifficulty'), i.encodeFunctionData('callGasLimit'), @@ -258,7 +258,7 @@ contract('Multi call utils', (accounts: string[]) => { expect(res[1][4]).to.not.equal(emptyBytes32, 'return block number') expect(res[1][5]).to.not.equal(emptyBytes32, 'return timestamp') expect(res[1][6]).to.not.equal(emptyBytes32, 'return gas left') - expect(BigInt(res[1][7])).to.equal(1, 'return gas price') + expect(BigInt(res[1][7])).to.equal(1n, 'return gas price') expect(res[1][8]).to.not.equal(emptyBytes32, 'return origin') expect(res[1][9]).to.not.equal(emptyBytes32, 'return balance of 0x') expect(res[1][10]).to.equal(emptyBytes32, 'return balance of empty account') @@ -269,14 +269,14 @@ contract('Multi call utils', (accounts: string[]) => { const codeSize = ethers.AbiCoder.defaultAbiCoder().decode(['uint256'], res[1][12])[0] expect(ethers.AbiCoder.defaultAbiCoder().decode(['bytes'], res[1][14])[0].length).to.equal( - 2 + codeSize * 2, + 2 + Number(codeSize) * 2, 'return code of correct size' ) expect(res[1][15]).to.not.equal(emptyBytes32) expect(res[1][16]).to.not.equal(emptyBytes32) - expect(ethers.AbiCoder.defaultAbiCoder().decode(['uint256'], Number(res[1][17])[0])).to.equal(CHAIN_ID(), 'return chain id') + expect(ethers.AbiCoder.defaultAbiCoder().decode(['uint256'], res[1][17])[0]).to.equal(await getChainId(), 'return chain id') }) }) }) diff --git a/test/utils/contracts.ts b/test/utils/contracts.ts index 5ccb243..f9d0f69 100644 --- a/test/utils/contracts.ts +++ b/test/utils/contracts.ts @@ -7,7 +7,7 @@ const cachedFactories: { [name: string]: ethers.ContractFactory } = {} async function deploy(name: string, ...args: any[]) { const factory = await hethers.getContractFactory(name) cachedFactories[name] = factory - return (await factory.deploy(...args)) as Y + return (await factory.deploy(...args)) as unknown as Y } function attach(name: string, address: string) { diff --git a/test/utils/index.ts b/test/utils/index.ts index fcb752f..3902eaf 100644 --- a/test/utils/index.ts +++ b/test/utils/index.ts @@ -5,7 +5,8 @@ import { ethers } from 'ethers' import { solidity } from 'ethereum-waffle' import { ethers as hethers } from 'hardhat' -export const CHAIN_ID = (): number => (process.env.NET_ID ? Number(BigInt(process.env.NET_ID)) : hethers.provider.network.chainId) +export const getChainId = async (): Promise => + process.env.NET_ID ? BigInt(process.env.NET_ID) : (await hethers.provider.getNetwork()).chainId export const { assert, expect } = chai.use(chaiString).use(chaiAsPromised).use(solidity) @@ -36,8 +37,10 @@ export async function expectToBeRejected(promise: Promise, error: string) { } export async function expectStaticToBeRejected(promise: Promise, signature: string, ...args: any[]) { - await expectToBeRejected(promise, `errorName="${signature.split('(')[0]}"`) - await expectToBeRejected(promise, `errorSignature="${signature}"`) + // await expectToBeRejected(promise, `errorName="${signature.split('(')[0]}"`) + // await expectToBeRejected(promise, `errorSignature="${signature}"`) + + await expectToBeRejected(promise, `${signature.split('(')[0]}`) const sigTypes = signature.split('(')[1].split(')')[0].split(',') @@ -60,28 +63,36 @@ export async function expectStaticToBeRejected(promise: Promise, signature: } if (type.startsWith('uint') || type.startsWith('int')) { - return `{"type":"BigNumber","hex":"${ethers.toBeHex(BigInt(arg))}"}` + //return `{"type":"BigNumber","hex":"${ethers.toBeHex(BigInt(arg))}"}` + return BigInt(arg).toString() } throw new Error(`Unknown type: ${type}`) }) - .join(',') + .join(', ') const groups = formattedArgs.split('*') - if (groups.length === 1) { - await expectToBeRejected(promise, `errorArgs=[${formattedArgs}]`) - } else { - for (let i = 0; i < groups.length; i++) { - const group = groups[i] - if (i === 0) { - await expectToBeRejected(promise, `errorArgs=[${group}`) - } else if (i === groups.length - 1) { - await expectToBeRejected(promise, `${group}]`) - } else { - await expectToBeRejected(promise, `${group}`) - } - } + + for (let i = 0; i < groups.length; i++) { + await expectToBeRejected(promise, `${groups[i]}`) } + + // if (groups.length === 1) { + // // await expectToBeRejected(promise, `errorArgs=[${formattedArgs}]`) + // await expectToBeRejected(promise, `${formattedArgs}`) + // } else { + // for (let i = 0; i < groups.length; i++) { + // const group = groups[i] + // if (i === 0) { + // // await expectToBeRejected(promise, `errorArgs=[${group}`) + // await expectToBeRejected(promise, `${group}`) + // } else if (i === groups.length - 1) { + // await expectToBeRejected(promise, `${group}]`) + // } else { + // await expectToBeRejected(promise, `${group}`) + // } + // } + // } } export function encodeError(error: string): string { diff --git a/test/utils/sequence.ts b/test/utils/sequence.ts index 36ebb58..065192a 100644 --- a/test/utils/sequence.ts +++ b/test/utils/sequence.ts @@ -1,5 +1,5 @@ import { BigNumberish, BytesLike, ethers, Wallet } from 'ethers' -import { CHAIN_ID } from '.' +import { getChainId } from '.' export const WALLET_CODE = '0x603a600e3d39601a805130553df3363d3d373d3d3d363d30545af43d82803e903d91601857fd5bf3' @@ -330,7 +330,8 @@ export function digestOf(txs: Partial[], nonce: ethers.BigNumberish ) } -export function subdigestOf(wallet: string, digest: ethers.BytesLike, chainId: ethers.BigNumberish = CHAIN_ID()) { +export async function subdigestOf(wallet: string, digest: ethers.BytesLike, chainId?: ethers.BigNumberish) { + chainId = chainId ?? (await getChainId()) return ethers.keccak256( ethers.solidityPacked(['string', 'uint256', 'address', 'bytes32'], ['\x19\x01', chainId, wallet, digest]) ) diff --git a/test/utils/wallet.ts b/test/utils/wallet.ts index 4385c14..72cf311 100644 --- a/test/utils/wallet.ts +++ b/test/utils/wallet.ts @@ -84,8 +84,8 @@ export class SequenceWallet { public isSequence = true _isSigner: boolean = true - factoryAddress: string = '' - mainModuleAddress: string = '' + factoryAddress: string = ethers.ZeroAddress + mainModuleAddress: string = ethers.ZeroAddress constructor(public options: WalletOptions) { this.options.context.factory.getAddress().then(address => (this.factoryAddress = address)) @@ -257,7 +257,7 @@ export class SequenceWallet { } async signDigest(digest: ethers.BytesLike): Promise { - const subdigest = ethers.getBytes(subdigestOf(this.address, digest, this.options.chainId)) + const subdigest = ethers.getBytes(await subdigestOf(this.address, digest, this.options.chainId)) return this.signSubdigest(subdigest) } diff --git a/utils/deploy-contracts.ts b/utils/deploy-contracts.ts index 2571b00..4e9b3c3 100644 --- a/utils/deploy-contracts.ts +++ b/utils/deploy-contracts.ts @@ -13,7 +13,6 @@ import { ContractDeployTransaction, ContractFactory, Signer, ethers } from 'ethe import fs from 'fs' const provider = hethers.provider -const signer = provider.getSigner(0) const singletonFactoryFactory = { address: '0xce0042B868300000d44A59004Da54A005ffdcf9f', @@ -81,6 +80,7 @@ const deploy = async ( contract: new (...args: [signer?: Signer]) => ContractFactory, ...args: any[] ): Promise => { + const signer = await provider.getSigner(0) const singletonFactory = new ethers.Contract(singletonFactoryFactory.address, singletonFactoryFactory.abi, signer) if (ethers.getBytes(await provider.getCode(await singletonFactory.getAddress())).length <= 2) { @@ -96,7 +96,7 @@ const deploy = async ( await tx.wait() o.info('Funded. Deploying singleton factory') } - const tx = await provider.sendTransaction(singletonFactoryDeployTx) + const tx = await provider.broadcastTransaction(singletonFactoryDeployTx) await tx.wait() o.succeed(`Deployed singleton factory`) } @@ -109,7 +109,7 @@ const deploy = async ( throw new Error(`no data for ${name}`) } - const maxGasLimit = await provider.getBlock('latest').then(b => (b.gasLimit * 4n) / 10n) + const maxGasLimit = await provider.getBlock('latest').then(b => (b!.gasLimit * 4n) / 10n) const address = ethers.getAddress( ethers.dataSlice( @@ -140,9 +140,11 @@ const deploy = async ( } const main = async () => { + const signer = await provider.getSigner(0) + const address = await signer.getAddress() prompt.info(`Network Name: ${network.name}`) - prompt.info(`Local Deployer Address: ${await signer.getAddress()}`) - prompt.info(`Local Deployer Balance: ${await signer.getBalance()}`) + prompt.info(`Local Deployer Address: ${address}`) + prompt.info(`Local Deployer Balance: ${await provider.getBalance(address)}`) const walletFactory = await deploy('Factory', Factory__factory) const mainModuleUpgradeable = await deploy('MainModuleUpgradable', MainModuleUpgradable__factory)