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

Adds ViemSigner compatibility layer #294

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
0816de9
Patches `EthBridger.from` to expand provider support
douglance Jun 12, 2023
bbc9844
Adds provider tests
douglance Jun 14, 2023
5c9f2f6
wip
douglance Jun 15, 2023
2df622a
wip
douglance Jun 16, 2023
5a3f349
wip
douglance Jun 16, 2023
af59b68
backports wagmi's viem implementation
douglance Jun 20, 2023
6ed17ab
feat: adds global config experimental flag
douglance Jul 6, 2023
a2e90fa
wip
douglance Jul 10, 2023
bee556f
reorganizes code adds temporary test script
douglance Oct 19, 2023
6936763
fix signing test
douglance Oct 23, 2023
ebec718
wip
douglance Oct 25, 2023
8f32f0d
remove extra stuff
douglance Oct 27, 2023
02e02ce
signs with custom class for viem
douglance Oct 30, 2023
7729774
signs with viem
douglance Oct 30, 2023
c78d2a0
improves compatibility for viem transaction receipt
douglance Oct 31, 2023
1efa6a8
adds more tests
douglance Nov 6, 2023
440c59e
fixes tests
douglance Nov 14, 2023
00201e4
wip
douglance Nov 17, 2023
a30b67e
wip
douglance Nov 28, 2023
8bb2f70
passes tests
douglance Nov 29, 2023
10cf84c
bump node version in ci
douglance Nov 29, 2023
3962cc0
fix builds
douglance Nov 29, 2023
2a51435
fix build
douglance Nov 30, 2023
f73a5fa
wip
douglance Dec 7, 2023
1794dfb
cleans up changes
douglance Dec 11, 2023
2ca1be6
fix test errors
douglance Dec 11, 2023
cf47b1e
attempts matrix of jobs
douglance Dec 11, 2023
6b63481
update tsconfig
douglance Dec 11, 2023
f6268d7
revert build script
douglance Dec 11, 2023
240a9f4
revert node version
douglance Dec 11, 2023
ab56329
add names for matrix tests
douglance Dec 12, 2023
baf2be0
fixes linting errors
douglance Dec 12, 2023
232bfcf
sets viem to latest
douglance Dec 12, 2023
116d764
updates lockfile
douglance Dec 12, 2023
a15bc80
simplifies implementation
douglance Dec 22, 2023
8d2671e
Merge branch 'main' into add-provider-map
douglance Dec 22, 2023
28400bf
moar cleanup and pr responses
douglance Dec 22, 2023
77290dd
adds unit tests
douglance Dec 28, 2023
ad78f32
removes launch.json
douglance Dec 28, 2023
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
2 changes: 1 addition & 1 deletion .env-sample
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ GOERLI_RPC="https://goerli.infura.io/v3/2323"
GOERLI_ROLLUP_TESTNET_RPC="https://goerli-rollup.arbitrum.io/rpc"

NOVA_RPC="soontm"

# Swaps integration tests to use Viem signer instead of Ethers
SHOULD_USE_VIEM_SIGNER='0'
douglance marked this conversation as resolved.
Show resolved Hide resolved
18 changes: 6 additions & 12 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ jobs:
matrix:
node-version: [16, 18, 20]
steps:
- uses: actions/setup-node@v3
with:
node-version: 16

- name: Checkout
uses: actions/checkout@v3

Expand Down Expand Up @@ -128,22 +124,20 @@ jobs:
run: CI=true yarn test:unit

test-integration:
name: Test (Integration)
name: Test (Integration) - ${{ matrix.description }}
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16, 18, 20]
include:
- viem_signer: '0'
description: 'Ethers v5'
- viem_signer: '1'
description: 'Viem'
needs: install
strategy:
matrix:
viem_signer: ['0', '1']
env:
SHOULD_USE_VIEM_SIGNER: ${{ matrix.viem_signer }}
steps:
- uses: actions/setup-node@v3
with:
node-version: 16

- name: Checkout
uses: actions/checkout@v3

Expand Down
66 changes: 0 additions & 66 deletions .vscode/launch.json
douglance marked this conversation as resolved.
Outdated
Show resolved Hide resolved

This file was deleted.

11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"test:coverage": "nyc mocha",
"test:fork": "SHOULD_FORK=1 hardhat test tests/fork/*.test.ts",
"test:integration": "mocha tests/integration/ --timeout 30000000 --bail",
"test:universal": "mocha tests/integration/universal --timeout 30000000 --watch",
"test:unit": "mocha --parallel tests/unit/ --timeout 30000 --bail",
"test:ci": "nyc --reporter=lcovonly mocha --reporter xunit",
"lint": "eslint .",
Expand Down Expand Up @@ -63,9 +62,9 @@
"@types/node-fetch": "^2.6.4",
"@types/prompts": "^2.0.14",
"@types/yargs": "^17.0.9",
"@typescript-eslint/eslint-plugin": "^5.14.0",
"@typescript-eslint/eslint-plugin-tslint": "^5.27.1",
"@typescript-eslint/parser": "^5.14.0",
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/eslint-plugin-tslint": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
"arb-bridge-peripherals": "1.0.10",
"audit-ci": "^6.3.0",
"axios": "^0.21.3",
Expand All @@ -77,7 +76,7 @@
"eslint-plugin-mocha": "^9.0.0",
"eslint-plugin-prettier": "^4.0.0",
"ethers-v6": "npm:ethers@^6.5.1",
"hardhat": "^2.8.3",
"hardhat": "^2.18.3",
"mocha": "^9.2.1",
"nyc": "^15.1.0",
"prettier": "^2.3.2",
Expand All @@ -90,7 +89,7 @@
"typedoc": "^0.24.6",
"typedoc-plugin-markdown": "^3.15.3",
"typescript": "^5.3.2",
"viem": "^1.0.5",
"viem": "^1.19.13",
"web3": "^4.0.1",
"yargs": "^17.3.1"
},
Expand Down
3 changes: 1 addition & 2 deletions scripts/deployBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ const deployBehindProxy = async <
await proxy.deployed()
console.log(factory['contractName'], proxy.address)

//@ts-ignore
return instance.attach(proxy.address)
return instance.attach(proxy.address) as ReturnType<T['deploy']>
}

export const deployErc20L1 = async (deployer: Signer) => {
Expand Down
68 changes: 47 additions & 21 deletions scripts/testSetup.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,47 @@
;('use strict')
/*
* Copyright 2021, Offchain Labs, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint-env node */
'use strict'

import 'isomorphic-unfetch'
import { JsonRpcProvider } from '@ethersproject/providers'
import { Wallet } from '@ethersproject/wallet'

import { execSync } from 'child_process'
import dotenv from 'dotenv'
import { Signer } from 'ethers'
import * as fs from 'fs'
import * as path from 'path'
import { Erc20Bridger, EthBridger, InboxTools } from '../src'
import { Bridge__factory } from '../src/lib/abi/factories/Bridge__factory'
import { RollupAdminLogic__factory } from '../src/lib/abi/factories/RollupAdminLogic__factory'
import { AdminErc20Bridger } from '../src/lib/assetBridger/erc20Bridger'
import { ArbSdkError } from '../src/lib/dataEntities/errors'
import { EthBridger, InboxTools, Erc20Bridger } from '../src'
import {
L1Network,
L2Network,
addCustomNetwork,
getL1Network,
getL2Network,
addCustomNetwork,
} from '../src/lib/dataEntities/networks'
import { Signer } from 'ethers'
import { AdminErc20Bridger } from '../src/lib/assetBridger/erc20Bridger'
import { execSync } from 'child_process'
import { Bridge__factory } from '../src/lib/abi/factories/Bridge__factory'
import { RollupAdminLogic__factory } from '../src/lib/abi/factories/RollupAdminLogic__factory'
import { deployErc20AndInit } from './deployBridge'
import * as path from 'path'
import * as fs from 'fs'
import { ArbSdkError } from '../src/lib/dataEntities/errors'
import { createWalletClient, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { mainnet } from 'viem/chains'
import { walletClientToSigner } from '../src/lib/utils/universal/signerTransforms'
import 'isomorphic-unfetch'
import { privateKeyToAccount } from 'viem/accounts'
import { createViemSigner } from '../src/lib/utils/universal/signerTransforms'

dotenv.config()

Expand Down Expand Up @@ -199,21 +215,20 @@ export const ethLocal = {
id: 1337,
rpcUrls: {
default: {
http: ['http://127.0.0.1:8545'],
http: [config.ethUrl],
},
public: {
http: ['http://127.0.0.1:8545'],
http: [config.ethUrl],
},
},
}
const ethRpcUrl = config.ethUrl

export const testSetup = async (): Promise<{
seed: Wallet
pk: any
l1Network: L1Network
l2Network: L2Network
l1Signer: any
l1Signer: Signer
ethersL1Signer: Signer
l2Signer: Signer
erc20Bridger: Erc20Bridger
Expand All @@ -236,11 +251,22 @@ export const testSetup = async (): Promise<{
const pk = ethersL1Signer._signingKey().privateKey as `0x${string}`
const ethWalletClient = createWalletClient({
account: privateKeyToAccount(pk),
transport: http(ethRpcUrl),
chain: ethLocal,
transport: http(config.ethUrl),
chain: {
...mainnet,
id: 1337,
rpcUrls: {
default: {
http: [config.ethUrl],
},
public: {
http: [config.ethUrl],
},
},
},
Comment on lines +255 to +266
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why wouldn't you use ethLocal here?

})
const l1Signer = config.shouldUseViemSigner
? walletClientToSigner(ethWalletClient)
? createViemSigner(ethWalletClient)
: ethersL1Signer

let setL1Network: L1Network, setL2Network: L2Network
Expand Down
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,9 @@ export {
RetryableDataTools,
} from './lib/dataEntities/retryableData'

export {
createViemSigner,
type ViemSigner,
} from './lib/utils/universal/signerTransforms'

export { Address } from './lib/dataEntities/address'
29 changes: 12 additions & 17 deletions src/lib/assetBridger/erc20Bridger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import { L2Network, getL2Network } from '../dataEntities/networks'
import { ArbSdkError, MissingProviderArbSdkError } from '../dataEntities/errors'
import { DISABLED_GATEWAY } from '../dataEntities/constants'
import { EventFetcher } from '../utils/eventFetcher'
import { EthDepositParams, EthWithdrawParams, Signerish } from './ethBridger'
import { EthDepositParams, EthWithdrawParams } from './ethBridger'
import { AssetBridger } from './assetBridger'
import {
L1ContractCallTransaction,
Expand All @@ -71,7 +71,6 @@ import { OmitTyped, RequiredPick } from '../utils/types'
import { RetryableDataTools } from '../dataEntities/retryableData'
import { EventArgs } from '../dataEntities/event'
import { L1ToL2MessageGasParams } from '../message/L1ToL2MessageCreator'
import { transformUniversalSignerToEthersV5Signer } from '../utils/universal/signerTransforms'

export interface TokenApproveParams {
/**
Expand Down Expand Up @@ -610,10 +609,7 @@ export class Erc20Bridger extends AssetBridger<
public async deposit(
params: Erc20DepositParams | L1ToL2TxReqAndSignerProvider
): Promise<L1ContractCallTransaction> {
const signer = await transformUniversalSignerToEthersV5Signer(
params.l1Signer
)
await this.checkL1Network(signer)
await this.checkL1Network(params.l1Signer)

// Although the types prevent should alert callers that value is not
// a valid override, it is possible that they pass it in anyway as it's a common override
Expand All @@ -624,16 +620,16 @@ export class Erc20Bridger extends AssetBridger<
)
}

const l1Provider = SignerProviderUtils.getProviderOrThrow(signer)
const l1Provider = SignerProviderUtils.getProviderOrThrow(params.l1Signer)
const tokenDeposit = isL1ToL2TransactionRequest(params)
? params
: await this.getDepositRequest({
...params,
l1Provider,
from: await signer.getAddress(),
from: await params.l1Signer.getAddress(),
})

const tx = await signer.sendTransaction({
const tx = await params.l1Signer.sendTransaction({
...tokenDeposit.txRequest,
...params.overrides,
})
Expand Down Expand Up @@ -754,16 +750,15 @@ export class AdminErc20Bridger extends Erc20Bridger {
l1Signer: Signer,
l2Provider: Provider
): Promise<L1ContractTransaction> {
const signer = await transformUniversalSignerToEthersV5Signer(l1Signer)
if (!SignerProviderUtils.signerHasProvider(signer)) {
if (!SignerProviderUtils.signerHasProvider(l1Signer)) {
throw new MissingProviderArbSdkError('l1Signer')
}
await this.checkL1Network(signer)
await this.checkL1Network(l1Signer)
await this.checkL2Network(l2Provider)

const l1SenderAddress = await signer.getAddress()
const l1SenderAddress = await l1Signer.getAddress()

const l1Token = ICustomToken__factory.connect(l1TokenAddress, signer)
const l1Token = ICustomToken__factory.connect(l1TokenAddress, l1Signer)
const l2Token = IArbToken__factory.connect(l2TokenAddress, l2Provider)

// sanity checks
Expand All @@ -781,7 +776,7 @@ export class AdminErc20Bridger extends Erc20Bridger {
maxSubmissionCost: BigNumber
gasLimit: BigNumber
}
const from = await signer.getAddress()
const from = await l1Signer.getAddress()
const encodeFuncData = (
setTokenGas: GasParams,
setGatewayGas: GasParams,
Expand Down Expand Up @@ -822,7 +817,7 @@ export class AdminErc20Bridger extends Erc20Bridger {
}
}

const l1Provider = signer.provider!
const l1Provider = l1Signer.provider!
const gEstimator = new L1ToL2MessageGasEstimator(l2Provider)
const setTokenEstimates2 = await gEstimator.populateFunctionParams(
(params: OmitTyped<L1ToL2MessageGasParams, 'deposit'>) =>
Expand Down Expand Up @@ -856,7 +851,7 @@ export class AdminErc20Bridger extends Erc20Bridger {
l1Provider
)

const registerTx = await signer.sendTransaction({
const registerTx = await l1Signer.sendTransaction({
to: l1Token.address,
data: setGatewayEstimates2.data,
value: setGatewayEstimates2.value,
Expand Down
Loading