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

feat: add support for custom gas token #310

Merged
merged 216 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 93 commits
Commits
Show all changes
216 commits
Select commit Hold shift + click to select a range
0f6d1ca
adjust genAbi script
spsjvc Jul 10, 2023
9e9ef4c
copy bridger class
spsjvc Jul 10, 2023
44633d8
add native token property to L2 networ
spsjvc Jul 11, 2023
a88f940
add approval implementation and tests
spsjvc Jul 11, 2023
8ee89e2
add deposit
spsjvc Jul 11, 2023
5f1de81
extend eth bridger
spsjvc Jul 11, 2023
a06abfc
clean up
spsjvc Jul 13, 2023
7186838
return providers from testSetup
spsjvc Jul 13, 2023
ba8c7d4
clean up more
spsjvc Jul 14, 2023
21e0b31
don't export types
spsjvc Jul 14, 2023
7c6c3dc
extract test helpers and rename file
spsjvc Jul 14, 2023
bc1d82b
add more assertions
spsjvc Jul 14, 2023
b35868c
add test
spsjvc Jul 14, 2023
0bc5723
enable creating retryable tickets via erc20inbox
spsjvc Jul 18, 2023
4fedf32
improve test setup
spsjvc Jul 19, 2023
41913f7
cleanup
spsjvc Jul 19, 2023
2c5fb7c
add withdrawal test
spsjvc Jul 19, 2023
d19498e
clean up
spsjvc Jul 19, 2023
9193a0d
rename stuff
spsjvc Jul 19, 2023
1c426d7
test setup for custom fee token
spsjvc Jul 19, 2023
d149a0f
update to public and update comment
spsjvc Jul 19, 2023
374e894
improve approvals
spsjvc Jul 19, 2023
ff15160
remove async
spsjvc Jul 19, 2023
65ca1f2
refactor
spsjvc Jul 19, 2023
b5f747c
remove field
spsjvc Jul 19, 2023
78b13c1
refactor
spsjvc Jul 19, 2023
2ed6fcd
extract func
spsjvc Jul 19, 2023
522f852
add await
spsjvc Jul 19, 2023
363f988
unused imports
spsjvc Jul 19, 2023
828c529
add methods for approving custom fee token for gateways
spsjvc Jul 19, 2023
2e8143c
reverse cases
spsjvc Jul 19, 2023
fd63bb1
remove unused imports
spsjvc Jul 19, 2023
3033b90
reverse cases
spsjvc Jul 19, 2023
0dbdcaa
support erc-20 deposits paid by custom fee token
spsjvc Jul 19, 2023
4c67e85
rename stuff
spsjvc Jul 19, 2023
d75bddf
just commit
spsjvc Aug 2, 2023
11c1f8a
support L2 parent chains
brtkx Aug 2, 2023
7f758a5
add partnerChainIDs
brtkx Aug 2, 2023
b477a8a
extra error message
brtkx Aug 4, 2023
e14337b
update
brtkx Aug 9, 2023
8936273
add jsdoc
brtkx Aug 9, 2023
9ba357c
fix issues
brtkx Aug 9, 2023
50820b0
try thing
spsjvc Aug 10, 2023
f408fad
add parentChains, chains
brtkx Aug 11, 2023
0b030c2
reduce diff
brtkx Aug 11, 2023
2fd86ec
reduce diff
brtkx Aug 11, 2023
8205daa
clean up
brtkx Aug 11, 2023
2954097
clean up
brtkx Aug 11, 2023
96b7c23
fix addCustomNetwork
brtkx Aug 11, 2023
6365728
comment
brtkx Aug 11, 2023
2100d07
fix comments and addCustomNetwork
brtkx Aug 11, 2023
413f9e5
clean up
brtkx Aug 11, 2023
67e49c5
var name
brtkx Aug 11, 2023
7571156
fix
brtkx Aug 11, 2023
c086850
export types and methods
brtkx Aug 11, 2023
6f78538
fixes
brtkx Aug 11, 2023
796c64b
change bridger type for l1network
brtkx Aug 11, 2023
fbc4df7
chore: bump contracts to 1.1.0-alpha.4
gzeoneth Aug 14, 2023
eb15634
remove thing
spsjvc Aug 14, 2023
b850c2e
remove unused imporT
spsjvc Aug 14, 2023
3b4364d
v3.1.6-orbit-custom-fee-token.0
spsjvc Aug 14, 2023
100c3a8
chore: bump contracts to 1.1.0-alpha.5
gzeoneth Aug 14, 2023
2e76d7e
chore: bump contracts to 1.1.0-alpha.7
gzeoneth Aug 14, 2023
f07aab0
Merge branch 'feat-custom-fee-token' of github.com:OffchainLabs/arbit…
spsjvc Aug 15, 2023
1bf66bb
Merge branch 'main' of ssh://github.com/OffchainLabs/arbitrum-sdk int…
brtkx Aug 21, 2023
5a864e1
separate method for adding custom chains
brtkx Aug 21, 2023
7de3b79
spread l2networks
brtkx Aug 21, 2023
af42cc1
clean up
brtkx Aug 21, 2023
0f67d96
default blocktime to 12sec
brtkx Aug 21, 2023
d716532
clean up
brtkx Aug 21, 2023
b2f0c8b
clean up
brtkx Aug 21, 2023
d2e3502
fix assetBridger
brtkx Aug 21, 2023
649dca4
read l2network from l2Networks or chains
brtkx Aug 22, 2023
0119fd9
clean up
brtkx Aug 23, 2023
31ab5d3
unused import
brtkx Aug 23, 2023
4582b54
unused import
brtkx Aug 23, 2023
d3597cb
clean up, unit tests
brtkx Aug 24, 2023
ade62ad
Merge branch 'main' of ssh://github.com/OffchainLabs/arbitrum-sdk int…
brtkx Aug 24, 2023
3d22c14
v3.1.10-beta.0
gzeoneth Aug 28, 2023
cf3cfac
fix multicall
brtkx Aug 28, 2023
76eb545
Merge branch 'support-l2-parent-chains' of ssh://github.com/OffchainL…
brtkx Aug 28, 2023
41ffe31
Merge branch 'support-l2-parent-chains' into feat-custom-fee-token
spsjvc Sep 28, 2023
a589888
v
spsjvc Oct 2, 2023
ebc7870
Merge branch 'main' of ssh://github.com/OffchainLabs/arbitrum-sdk int…
brtkx Oct 5, 2023
c4934d8
merge main
brtkx Oct 5, 2023
158b8d4
bump version
spsjvc Oct 5, 2023
cc48da2
add stylus to partner chains for arb sepolia
brtkx Oct 5, 2023
980ca7a
bump version
spsjvc Oct 5, 2023
38cecca
Merge branch 'support-l2-parent-chains' into feat-custom-fee-token
spsjvc Nov 1, 2023
9615ca8
make consistent
spsjvc Nov 1, 2023
b150be0
bump version
spsjvc Nov 1, 2023
d35e6d6
handle zero address native token as eth
spsjvc Nov 3, 2023
d31e2ef
bump version
spsjvc Nov 3, 2023
388322a
Merge branch 'main' into support-l2-parent-chains
spsjvc Nov 3, 2023
8551202
bump version
spsjvc Nov 3, 2023
c84e20c
Merge branch 'support-l2-parent-chains' into feat-custom-fee-token
spsjvc Nov 3, 2023
611c48a
bump version
spsjvc Nov 3, 2023
cf61bb8
Testing the flat chains option
douglance Nov 18, 2023
814acf9
cleans up flat chains implementation
douglance Nov 20, 2023
500ced0
exports getters to fix unused function error
douglance Nov 20, 2023
a4999a6
sets type isOrbit to true rather than boolean
douglance Nov 21, 2023
c72eaac
swap getParentOf Network to getParentForNetwork
douglance Nov 21, 2023
08c27b3
swap getChildrenOf Network to getChildrenForNetwork
douglance Nov 21, 2023
ca6f1dc
responds to PR feedback
douglance Nov 21, 2023
21cbc1d
abstracts out getting chains by type
douglance Nov 28, 2023
0b194c2
Merge branch 'main' into dl/query
fionnachan Nov 30, 2023
49e7aea
responds to pr feedback
douglance Nov 30, 2023
769bb6c
Adds jsdocs for parent/child predicates
douglance Nov 30, 2023
b3737b6
fix lint issue
douglance Nov 30, 2023
6645ce8
actually fix lint issue
douglance Nov 30, 2023
5f3737a
updates `getNetwork` to return all parent chains for layer 1
douglance Nov 30, 2023
26538b4
removes exports from networks.ts
douglance Nov 30, 2023
290cf61
renames network object
douglance Nov 30, 2023
74a9f53
removes parentChain and l1NetworkOrParentChain from asset bridger
douglance Nov 30, 2023
34b7e28
adds generic customNetwork param to `addCustomNetwork`
douglance Dec 1, 2023
5b4b50b
fix add custom network param type
douglance Dec 1, 2023
f72e011
reverts change to addCustomNetwork
douglance Dec 4, 2023
e2a2dc9
implement pr changes
douglance Dec 12, 2023
a67a678
improves tests by resetting network state between tests
douglance Dec 15, 2023
842edcc
get rid of extra type
spsjvc Dec 18, 2023
bffe1f4
improves tests and simplifies AssetBridger constructor
douglance Dec 18, 2023
d63c7b6
Adds L1/L2Network types to asset bridger
douglance Dec 18, 2023
ee9f9d8
Merge branch 'main' into dl/query
douglance Jan 4, 2024
c6a0efa
update build script for l3 testing
douglance Jan 9, 2024
626ce8f
sets up tests to be orbit compatible
douglance Jan 9, 2024
058337a
reverts getL1Network type change
douglance Jan 9, 2024
5f50b5f
fix blocktime
douglance Jan 9, 2024
d259c2c
testing with restored build file
douglance Jan 9, 2024
c32084e
test with just l3-node
douglance Jan 9, 2024
e26e0f0
run only orbit tests
douglance Jan 9, 2024
c60f510
fix testnode ref
douglance Jan 9, 2024
584bb42
test without local network
douglance Jan 9, 2024
2cd6add
sets up l1 before localnetwork.json for orbit
douglance Jan 9, 2024
e0bdd34
improve ci labels
douglance Jan 9, 2024
743d168
Update name to use matrix label
douglance Jan 9, 2024
e2d9ba4
simplify name gen
douglance Jan 9, 2024
8d11b9c
clean up types (#389)
spsjvc Jan 10, 2024
0b5d100
clean up plus docs
spsjvc Jan 10, 2024
8379045
add test for l1Networks and l2Networks
spsjvc Jan 11, 2024
0c97ade
wrap in describe
spsjvc Jan 11, 2024
18f6d85
docs
spsjvc Jan 11, 2024
4c2ee0b
Merge branch 'main' into dl/query
spsjvc Jan 11, 2024
b775779
refactor: clean up networks (#390)
spsjvc Jan 11, 2024
2b7c643
bump version
spsjvc Jan 11, 2024
b14d4fb
Merge branch 'dl/query' into feat-custom-fee-token
spsjvc Jan 11, 2024
024ff03
bump packages
spsjvc Jan 11, 2024
aaa5997
bump version
spsjvc Jan 11, 2024
b68b6ca
chore: updates jsdoc comments on new functions/values
douglance Jan 12, 2024
edc038c
Merge branch 'main' into dl/query
douglance Jan 12, 2024
e8b29f7
swaps test setup to use arb_min_block_time
douglance Jan 16, 2024
da32655
adds more jsdoc comments to testsetup
douglance Jan 16, 2024
a1c70aa
adds another comment
douglance Jan 16, 2024
203d665
Merge branch 'dl/query' into feat-custom-fee-token
douglance Jan 18, 2024
c987678
clean up
spsjvc Jan 24, 2024
a118de2
clean up
spsjvc Jan 24, 2024
44d0036
update custom fee token support to prepare for merge to main (#398)
douglance Jan 26, 2024
400c457
Merge branch 'dl/query' into feat-custom-fee-token
douglance Jan 26, 2024
5200584
restores getParentChains to fix tests
douglance Jan 26, 2024
88f8fa5
Merge branch 'main' into dl/query
douglance Jan 26, 2024
b9e4e16
Merge branch 'dl/query' into feat-custom-fee-token
douglance Jan 26, 2024
6395ee2
linting
douglance Jan 26, 2024
eda81be
update lockfile
douglance Jan 29, 2024
be3708f
remove obsolete tests
spsjvc Jan 30, 2024
5824ef4
update ref
spsjvc Jan 30, 2024
48056bc
fix
spsjvc Feb 2, 2024
05b8540
revert comments
spsjvc Feb 2, 2024
555de69
remove obsolete test
spsjvc Feb 2, 2024
7fd3af8
start cleaning up tests
spsjvc Feb 2, 2024
5d95a0d
more
spsjvc Feb 2, 2024
0861bd1
add more assertions
spsjvc Feb 2, 2024
d478039
finish cleanup
spsjvc Feb 2, 2024
0d91ae4
bump version
spsjvc Feb 2, 2024
e1c5819
Merge branch 'dl/query' into feat-custom-fee-token
spsjvc Feb 2, 2024
c133974
revert changes
spsjvc Feb 2, 2024
abdc024
remove bangs
spsjvc Feb 2, 2024
6fe62da
bump
spsjvc Feb 2, 2024
61794ae
switch to early return
spsjvc Feb 2, 2024
4e9b557
clean up
spsjvc Feb 4, 2024
49a8c5b
move property up
spsjvc Feb 5, 2024
d1e2fc5
bump version
spsjvc Feb 5, 2024
8264a5b
Merge branch 'dl/query' into feat-custom-fee-token
spsjvc Feb 5, 2024
d1236dd
Merge branch 'main' into feat-custom-fee-token
spsjvc Feb 5, 2024
d2ea33a
fix script
spsjvc Feb 5, 2024
4fbb2ca
fix
spsjvc Feb 5, 2024
f2b43da
clean up job names
spsjvc Feb 5, 2024
eb31f69
use testnode bridge (#408)
godzillaba Feb 5, 2024
31243d1
Merge branch 'main' into feat-custom-fee-token
spsjvc Feb 5, 2024
27127b4
move nativeToken to parent class
spsjvc Feb 5, 2024
fdf1526
move nativeTokenIsEth to parent class
spsjvc Feb 5, 2024
45e63a8
clean up jsdoc
spsjvc Feb 5, 2024
243f020
clean up gen abi
spsjvc Feb 5, 2024
716fb1a
rename fee token to gas token
spsjvc Feb 5, 2024
b4ca425
remove check
spsjvc Feb 12, 2024
86380d2
add docs
spsjvc Feb 12, 2024
34dcdc5
clean up
spsjvc Feb 12, 2024
9e5ce1d
rename
spsjvc Feb 12, 2024
9c8a66e
add comment
spsjvc Feb 12, 2024
c21d321
Merge branch 'main' into feat-custom-fee-token
spsjvc Feb 12, 2024
f79541c
clean up
spsjvc Feb 12, 2024
b4a565b
add test
spsjvc Feb 12, 2024
ce42be3
fix
spsjvc Feb 12, 2024
2f1b5df
rename and jsdoc
spsjvc Feb 12, 2024
7caa388
bump version
spsjvc Feb 12, 2024
746cf4e
fix
spsjvc Feb 13, 2024
0f43ffa
remove unused script
spsjvc Feb 13, 2024
69aa6ef
rename for consistency
spsjvc Feb 13, 2024
ed9a199
clean up
spsjvc Feb 13, 2024
b541d27
patch
spsjvc Feb 13, 2024
8ed3593
clean up
spsjvc Feb 13, 2024
27fe056
oops
spsjvc Feb 13, 2024
4d5f968
clean up more
spsjvc Feb 13, 2024
abdf668
clean up more
spsjvc Feb 13, 2024
7028348
rename
spsjvc Feb 13, 2024
08f9af6
lol
spsjvc Feb 13, 2024
af5586f
bump contracts
spsjvc Feb 13, 2024
836bdb4
update values for L3
spsjvc Feb 14, 2024
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
18 changes: 18 additions & 0 deletions hardhat.nitro-contracts-abigen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @type import('hardhat/config').HardhatUserConfig
*/
module.exports = {
solidity: {
version: '0.8.9',
settings: {
optimizer: {
enabled: true,
runs: 100,
},
},
},
paths: {
sources: './src',
artifacts: './build/contracts',
},
}
18 changes: 18 additions & 0 deletions hardhat.token-bridge-contracts-abigen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @type import('hardhat/config').HardhatUserConfig
*/
module.exports = {
solidity: {
version: '0.8.17',
settings: {
optimizer: {
enabled: true,
runs: 100,
},
},
},
paths: {
sources: './contracts',
artifacts: './build/contracts',
},
}
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@arbitrum/sdk",
"version": "3.1.12",
"version": "3.1.12-orbit-custom-fee-token.1",
"description": "Typescript library client-side interactions with Arbitrum",
"author": "Offchain Labs, Inc.",
"license": "Apache-2.0",
Expand Down Expand Up @@ -31,7 +31,8 @@
"test": "mocha",
"test:coverage": "nyc mocha",
"test:fork": "SHOULD_FORK=1 hardhat test tests/fork/*.test.ts",
"test:integration": "mocha tests/integration/ --timeout 30000000 --bail",
"test:integration": "mocha tests/integration/ --ignore tests/integration/custom-fee-token/ --timeout 30000000 --bail",
"test:integration:custom-fee-token": "mocha tests/integration/custom-fee-token/ --timeout 30000000 --bail",
"test:unit": "mocha --parallel tests/unit/ --timeout 30000 --bail",
"test:ci": "nyc --reporter=lcovonly mocha --reporter xunit",
"lint": "eslint .",
Expand All @@ -43,7 +44,8 @@
"setStandard": "ts-node scripts/setStandardGateways.ts",
"setCustom": "ts-node scripts/setArbCustomGateways.ts",
"cancelRetryable": "ts-node scripts/cancelRetryable.ts",
"bridgeStandardToken": "ts-node scripts/deployStandard.ts"
"bridgeStandardToken": "ts-node scripts/deployStandard.ts",
"fund": "ts-node scripts/fundCustomFeeToken.ts"
},
"dependencies": {
"@ethersproject/address": "^5.0.8",
Expand All @@ -53,7 +55,8 @@
"ethers": "^5.1.0"
},
"devDependencies": {
"@arbitrum/nitro-contracts": "1.0.1",
"@arbitrum/nitro-contracts": "1.1.0-alpha.7",
"@arbitrum/token-bridge-contracts": "1.1.0-alpha.1",
"@nomiclabs/hardhat-ethers": "^2.0.4",
"@typechain/ethers-v5": "9.0.0",
"@types/chai": "^4.2.11",
Expand All @@ -63,7 +66,6 @@
"@typescript-eslint/eslint-plugin": "^5.14.0",
"@typescript-eslint/eslint-plugin-tslint": "^5.27.1",
"@typescript-eslint/parser": "^5.14.0",
"arb-bridge-peripherals": "1.0.10",
"audit-ci": "^6.3.0",
"axios": "^0.21.3",
"chai": "^4.2.0",
Expand Down
7 changes: 7 additions & 0 deletions scripts/fundCustomFeeToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { fundL1CustomFeeToken } from '../tests/integration/custom-fee-token/customFeeTokenTestHelpers'

async function main() {
await fundL1CustomFeeToken('0x3f1Eae7D46d88F08fc2F8ed27FCb2AB183EB2d0E')
}

main()
23 changes: 16 additions & 7 deletions scripts/genAbi.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async function main() {
const cwd = process.cwd()

const nitroPath = getPackagePath('@arbitrum/nitro-contracts')
const peripheralsPath = getPackagePath('arb-bridge-peripherals')
const tokenBridgePath = getPackagePath('@arbitrum/token-bridge-contracts')

console.log('Compiling paths.')

Expand All @@ -27,20 +27,29 @@ async function main() {
// https://yarnpkg.com/advanced/rulebook#packages-should-never-write-inside-their-own-folder-outside-of-postinstall
// instead of writing in postinstall in each of those packages, we should target a local folder in sdk's postinstall

console.log('building nitro')
execSync(`${npmExec} run hardhat:prod compile`, {
// copy the hardhat config to nitro-contracts
execSync(
`cp ${cwd}/hardhat.nitro-contracts-abigen.ts ${nitroPath}/hardhat-abigen.ts`
)
// copy the hardhat config to token-bridge-contracts
execSync(
`cp ${cwd}/hardhat.token-bridge-contracts-abigen.ts ${tokenBridgePath}/hardhat-abigen.ts`
)

console.log('building @arbitrum/nitro-contracts')
execSync(`${npmExec} run build --config hardhat-abigen.ts`, {
cwd: nitroPath,
})

console.log('building peripherals')
execSync(`${npmExec} run hardhat:prod compile`, {
cwd: peripheralsPath,
console.log('building @arbitrum/token-bridge-contracts')
execSync(`${npmExec} run build --config hardhat-abigen.ts`, {
cwd: tokenBridgePath,
})

console.log('Done compiling')

const nitroFiles = glob(cwd, [
`${peripheralsPath}/build/contracts/!(build-info)/**/+([a-zA-Z0-9_]).json`,
`${tokenBridgePath}/build/contracts/!(build-info)/**/+([a-zA-Z0-9_]).json`,
`${nitroPath}/build/contracts/!(build-info)/**/+([a-zA-Z0-9_]).json`,
])

Expand Down
9 changes: 7 additions & 2 deletions scripts/testSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@

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

import { Signer } from 'ethers'
import { Provider } from '@ethersproject/abstract-provider'
import dotenv from 'dotenv'

import { EthBridger, InboxTools, Erc20Bridger } from '../src'
import {
L1Network,
Expand All @@ -28,7 +30,6 @@ import {
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'
Expand Down Expand Up @@ -208,6 +209,8 @@ export const testSetup = async (): Promise<{
l2Network: L2Network
l1Signer: Signer
l2Signer: Signer
l1Provider: Provider
l2Provider: Provider
erc20Bridger: Erc20Bridger
ethBridger: EthBridger
adminErc20Bridger: AdminErc20Bridger
Expand Down Expand Up @@ -270,6 +273,8 @@ export const testSetup = async (): Promise<{
return {
l1Signer,
l2Signer,
l1Provider: ethProvider,
l2Provider: arbProvider,
l1Network: setL1Network,
l2Network: setL2Network,
erc20Bridger,
Expand Down
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,14 @@ export {
L2Networks,
L1Network,
L2Network,
Chain,
ParentChain,
getL1Network,
getL2Network,
getChain,
getParentChain,
addCustomNetwork,
addCustomChain,
addDefaultLocalNetwork,
} from './lib/dataEntities/networks'
export { InboxTools } from './lib/inbox/inbox'
Expand Down
27 changes: 21 additions & 6 deletions src/lib/assetBridger/assetBridger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ import { ArbSdkError } from '../dataEntities/errors'
import { L1ContractTransaction } from '../message/L1Transaction'
import { L2ContractTransaction } from '../message/L2Transaction'

import { l1Networks, L1Network, L2Network } from '../dataEntities/networks'
import {
l1Networks,
L1Network,
L2Network,
Chain,
ParentChain,
parentChains,
} from '../dataEntities/networks'
import {
SignerOrProvider,
SignerProviderUtils,
Expand All @@ -31,22 +38,30 @@ import {
*/
export abstract class AssetBridger<DepositParams, WithdrawParams> {
public readonly l1Network: L1Network
public readonly parentChain: ParentChain
private readonly l1NetworkOrParentChain: L1Network | ParentChain

public constructor(public readonly l2Network: L2Network) {
public constructor(public readonly l2Network: L2Network | Chain) {
this.l1Network = l1Networks[l2Network.partnerChainID]
if (!this.l1Network) {
this.parentChain = parentChains[l2Network.partnerChainID]
this.l1NetworkOrParentChain = this.l1Network || this.parentChain

if (!this.l1NetworkOrParentChain) {
throw new ArbSdkError(
`Unknown l1 network chain id: ${l2Network.partnerChainID}`
`Unknown parent network chain id: ${l2Network.partnerChainID}`
)
}
}

/**
* Check the signer/provider matches the l1Network, throws if not
* Check the signer/provider matches the L1 network or the Parent Chain, throws if not
* @param sop
*/
protected async checkL1Network(sop: SignerOrProvider): Promise<void> {
await SignerProviderUtils.checkNetworkMatches(sop, this.l1Network.chainID)
await SignerProviderUtils.checkNetworkMatches(
sop,
this.l1NetworkOrParentChain.chainID
)
}

/**
Expand Down
Loading
Loading