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

(do not merge) v4 #369

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b568467
Merge pull request #368 from OffchainLabs/dl/rebasemain
spsjvc Oct 18, 2023
5710ca2
chore: rename L1 and L2 to parent and child chain in inbox (#339)
douglance Oct 19, 2023
09a6eb0
chore: update l1/2 name for dataEntities (#340)
douglance Nov 2, 2023
4593ce8
Updates v4 with the latest on `main` (#376)
douglance Nov 20, 2023
1066dbf
chore: renames L1ToL2Message to parentChain/Chain (#344)
douglance Dec 4, 2023
92def11
chore: renames L2ToL1Message to Child/ParentChain (#345)
douglance Dec 12, 2023
de8a7b8
chore renames: L2ToL1MessageNitro to ChildToParentChain (#351)
douglance Jan 16, 2024
9968a70
Merge branch 'main' into dl/merge-main-2
douglance Feb 23, 2024
4300c4b
fix issues with merge
douglance Feb 23, 2024
5ba0408
fix lint issue
douglance Feb 23, 2024
4157f3a
swap to use release for testnode
douglance Feb 23, 2024
a3cd38b
Merge pull request #417 from OffchainLabs/dl/merge-main-2
spsjvc Mar 4, 2024
13e0b1b
Merge branch 'main' into dl/merge-main-5
douglance Mar 11, 2024
e1a4c24
Merge pull request #421 from OffchainLabs/dl/merge-main-5
spsjvc Mar 11, 2024
551ba58
chore: renames L2ToL1MessageClassic to Child/ParentChain (#352)
douglance Mar 14, 2024
c2296fc
chore: rename L1ToL2MessageCreator to parent/child (#422)
douglance Mar 14, 2024
2ca245f
Merge branch 'main' into dl/merge-main-6
douglance Mar 15, 2024
4a86b9a
Merge pull request #427 from OffchainLabs/dl/merge-main-6
spsjvc Mar 15, 2024
dd640d6
chore: renames L1ToL2MessageGasEstimator to Parent/Child (#423)
douglance Mar 19, 2024
8f8dbea
chore: rename L2Transaction to parent/child (#424)
douglance Mar 19, 2024
20e6341
chore: rename L1Transaction to parent/child (#425)
douglance Mar 19, 2024
253bd13
chore: renames networks.ts to parent/child (#430)
douglance Mar 27, 2024
5f377de
chore: rename erc20bridger to parent/child (#431)
douglance Mar 27, 2024
ea10ca3
chore: rename `testSetup` to parent/child (#438)
douglance Mar 29, 2024
241c924
chore: rename testHelper to parent/child (#440)
douglance Apr 9, 2024
72ee962
Merge branch 'main' into dl/merge-main-8
douglance Apr 9, 2024
448ef7d
Merge pull request #448 from OffchainLabs/dl/merge-main-8
spsjvc Apr 9, 2024
de63b27
chore: rename custom fee token files (#441)
douglance Apr 9, 2024
344d853
chore: rename deposit methods and associated types (#442)
douglance Apr 10, 2024
13ad8f1
chore: rename L1/L2 files to parent/child (#443)
douglance Apr 10, 2024
1a85aa3
chore: replace temporary imports/exports with renamed versions (#444)
douglance Apr 10, 2024
6b35df6
chore: renames ParentChainTx to ParentTx and similar (#451)
douglance Apr 17, 2024
f7fe00e
feat: remove some network properties (#449)
spsjvc Apr 17, 2024
29802ba
feat: clean up parent/children network properties (#452)
spsjvc Apr 17, 2024
0ee694c
refactor: add function to get multicall address (#454)
spsjvc Apr 17, 2024
33df534
feat: remove all references to L1Network (#453)
spsjvc Apr 18, 2024
a4b43b0
feat: clean up networks names and imports (#458)
spsjvc Apr 18, 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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ Below is an overview of the Arbitrum SDK functionality. See the [tutorials](http
- ##### Deposit Ether Into Arbitrum

```ts
import { getL2Network, EthBridger } from '@arbitrum/sdk'
import { getArbitrumNetwork, EthBridger } from '@arbitrum/sdk'

const l2Network = await getL2Network(
const l2Network = await getArbitrumNetwork(
l2ChainID /** <-- chain id of target Arbitrum chain */
)
const ethBridger = new EthBridger(l2Network)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@
"resolutions": {
"lodash.pick": "https://github.com/lodash/lodash/archive/refs/tags/4.17.21.tar.gz"
}
}
}
2 changes: 1 addition & 1 deletion scripts/cancelRetryable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { ContractReceipt } from '@ethersproject/contracts'

import { instantiateBridge } from './instantiate_bridge'
import args from './getCLargs'
import { L1TransactionReceipt } from '../src/lib/message/L1Transaction'
import { L1TransactionReceipt } from '../src/lib/message/ParentTransaction'

if (!args.txid) {
throw new Error('Include txid (--txid 0xmytxid)')
Expand Down
2 changes: 1 addition & 1 deletion scripts/deployStandard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const main = async () => {
}

/* check token not yet deployed */
const l2TokenAddress = await erc20Bridger.getL2ERC20Address(
const l2TokenAddress = await erc20Bridger.getChildERC20Address(
l1TokenAddress,
l1Provider
)
Expand Down
42 changes: 29 additions & 13 deletions scripts/genNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ import * as dotenv from 'dotenv'
dotenv.config()
import { execSync } from 'child_process'
import * as fs from 'fs'
import { L2Network } from '../src'
import { ARB_MINIMUM_BLOCK_TIME_IN_SECONDS } from '../src/lib/dataEntities/constants'

import { IERC20Bridge__factory } from '../src/lib/abi/factories/IERC20Bridge__factory'
import { ethers } from 'ethers'
import {
L2Network,
ArbitrumNetwork,
mapL2NetworkToArbitrumNetwork,
} from '../src/lib/dataEntities/networks'

const isTestingOrbitChains = process.env.ORBIT_TEST === '1'

Expand Down Expand Up @@ -39,24 +43,29 @@ async function patchNetworks(
l2Network: L2Network,
l3Network: L2Network | undefined,
l2Provider: ethers.providers.Provider | undefined
) {
// we need to add partnerChainIDs to the L2 network
l2Network.partnerChainIDs = l3Network ? [l3Network.chainID] : []
l2Network.blockTime = ARB_MINIMUM_BLOCK_TIME_IN_SECONDS
): Promise<{
patchedL2Network: ArbitrumNetwork
patchedL3Network?: ArbitrumNetwork
}> {
const patchedL2Network = mapL2NetworkToArbitrumNetwork(l2Network)

// native token for l3
if (l3Network && l2Provider) {
l3Network.partnerChainIDs = []
l3Network.blockTime = ARB_MINIMUM_BLOCK_TIME_IN_SECONDS
const patchedL3Network = mapL2NetworkToArbitrumNetwork(l3Network)

try {
l3Network.nativeToken = await IERC20Bridge__factory.connect(
patchedL3Network.nativeToken = await IERC20Bridge__factory.connect(
l3Network.ethBridge.bridge,
l2Provider
).nativeToken()
} catch (e) {
// l3 network doesn't have a native token
}

return { patchedL2Network, patchedL3Network }
}

return { patchedL2Network }
}

async function main() {
Expand All @@ -66,17 +75,24 @@ async function main() {

if (isTestingOrbitChains) {
const { l2Network: l3Network } = getLocalNetworksFromContainer('l2l3')
await patchNetworks(
const { patchedL2Network, patchedL3Network } = await patchNetworks(
output.l2Network,
l3Network,
new ethers.providers.JsonRpcProvider(process.env['ARB_URL'])
)

output = {
l1Network: output.l2Network,
l2Network: l3Network,
l1Network: patchedL2Network,
l2Network: patchedL3Network,
}
} else {
await patchNetworks(output.l2Network, undefined, undefined)
const { patchedL2Network } = await patchNetworks(
output.l2Network,
undefined,
undefined
)

output.l2Network = patchedL2Network
}

fs.writeFileSync('localNetwork.json', JSON.stringify(output, null, 2))
Expand Down
34 changes: 7 additions & 27 deletions scripts/instantiate_bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@ import dotenv from 'dotenv'
import args from './getCLargs'
import { EthBridger, InboxTools, Erc20Bridger } from '../src'
import {
l1Networks,
l2Networks,
L1Network,
L2Network,
ArbitrumNetwork,
getArbitrumNetwork,
} from '../src/lib/dataEntities/networks'
import { Signer } from 'ethers'
import { AdminErc20Bridger } from '../src/lib/assetBridger/erc20Bridger'
import { isDefined } from '../src/lib/utils/lib'

dotenv.config()

Expand All @@ -39,19 +36,18 @@ const ethKey = process.env['ETH_KEY'] as string

const defaultNetworkId = 421614

export const instantiateBridge = (
export const instantiateBridge = async (
l1PkParam?: string,
l2PkParam?: string
): {
l1Network: L1Network
l2Network: L2Network
): Promise<{
l2Network: ArbitrumNetwork
l1Signer: Signer
l2Signer: Signer
erc20Bridger: Erc20Bridger
ethBridger: EthBridger
adminErc20Bridger: AdminErc20Bridger
inboxTools: InboxTools
} => {
}> => {
if (!l1PkParam && !ethKey) {
throw new Error('need ARB_KEY var')
}
Expand All @@ -68,23 +64,8 @@ export const instantiateBridge = (

l2NetworkID = defaultNetworkId
}
const isL1 = isDefined(l1Networks[l2NetworkID])
const isL2 = isDefined(l2Networks[l2NetworkID])
if (!isL1 && !isL2) {
throw new Error(`Unrecognized network ID: ${l2NetworkID}`)
}
if (!isL2) {
throw new Error(`Tests must specify an L2 network ID: ${l2NetworkID}`)
}

const l2Network = l2Networks[l2NetworkID]
const l1Network = l1Networks[l2Network.partnerChainID]

if (!l1Network) {
throw new Error(
`Unrecognised partner chain id: ${l2Network.partnerChainID}`
)
}
const l2Network = await getArbitrumNetwork(l2NetworkID)

const l1Rpc = (() => {
if (l2NetworkID === 42161) return process.env['MAINNET_RPC'] as string
Expand Down Expand Up @@ -140,7 +121,6 @@ export const instantiateBridge = (
const inboxTools = new InboxTools(l1Signer, l2Network)

return {
l1Network,
l2Network,
l1Signer,
l2Signer,
Expand Down
35 changes: 18 additions & 17 deletions scripts/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import { ContractReceipt } from '@ethersproject/contracts'

import { ERC20__factory } from '../src/lib/abi/factories/ERC20__factory'
import { L1ToL2MessageStatus } from '../src/lib/message/L1ToL2Message'
import { L1TransactionReceipt } from '../src/lib/message/L1Transaction'
import { L1ToL2MessageStatus } from '../src/lib/message/ParentToChildMessage'
import { L1TransactionReceipt } from '../src/lib/message/ParentTransaction'
import { testSetup } from '../scripts/testSetup'

export const setStandardGateWays = async (
Expand All @@ -39,9 +39,10 @@ export const setGateWays = async (
type: 'standard' | 'arbCustom',
overrideGateways: string[] = []
): Promise<ContractReceipt> => {
const { adminErc20Bridger, l1Signer, l2Network, l2Signer } = await testSetup()
const l1Provider = l1Signer.provider!
const l2Provider = l2Signer.provider!
const { adminErc20Bridger, parentSigner, childChain, childSigner } =
await testSetup()
const parentProvider = parentSigner.provider!
const childProvider = childSigner.provider!
if (tokens.length === 0) {
throw new Error('Include some tokens to set')
}
Expand All @@ -55,7 +56,7 @@ export const setGateWays = async (

for (const tokenAddress of tokens) {
try {
const token = await ERC20__factory.connect(tokenAddress, l1Provider)
const token = await ERC20__factory.connect(tokenAddress, parentProvider)
console.warn('calling name for ', tokenAddress)

const symbol = await token.symbol()
Expand Down Expand Up @@ -85,17 +86,17 @@ export const setGateWays = async (
if (overrideGateways.length > 0) {
return overrideGateways
} else if (type === 'standard') {
return tokens.map(() => l2Network.tokenBridge.l1ERC20Gateway)
return tokens.map(() => childChain.tokenBridge.l1ERC20Gateway)
} else if (type === 'arbCustom') {
return tokens.map(() => l2Network.tokenBridge.l1CustomGateway)
return tokens.map(() => childChain.tokenBridge.l1CustomGateway)
} else {
throw new Error('Unhandled else case')
}
})()

const res = await adminErc20Bridger.setGateways(
l1Signer,
l2Provider,
parentSigner,
childProvider,
gateways.map((g, i) => ({
tokenAddr: tokens[i],
gatewayAddr: gateways[i],
Expand All @@ -110,7 +111,7 @@ export const setGateWays = async (
}

console.log('redeeming retryable ticket:')
const l2Tx = (await rec.getL1ToL2Messages(l2Signer))[0]
const l2Tx = (await rec.getParentToChildMessages(childSigner))[0]
if (!l2Tx) throw new Error('No l1 to l2 message found.')
const messageRes = await l2Tx.waitForStatus()
if (messageRes.status === L1ToL2MessageStatus.FUNDS_DEPOSITED_ON_L2) {
Expand All @@ -123,13 +124,13 @@ export const setGateWays = async (
}

export const checkRetryableStatus = async (l1Hash: string): Promise<void> => {
const { l1Signer, l2Signer } = await testSetup()
const l1Provider = l1Signer.provider!
const l2Provider = l2Signer.provider!
const rec = await l1Provider.getTransactionReceipt(l1Hash)
const { parentSigner, childSigner } = await testSetup()
const parentProvider = parentSigner.provider!
const childProvider = childSigner.provider!
const rec = await parentProvider.getTransactionReceipt(l1Hash)
if (!rec) throw new Error('L1 tx not found!')
const messages = await new L1TransactionReceipt(rec).getL1ToL2Messages(
l2Provider
const messages = await new L1TransactionReceipt(rec).getParentToChildMessages(
childProvider
)

for (const message of messages) {
Expand Down
10 changes: 5 additions & 5 deletions scripts/redeemRetryable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { ContractReceipt } from '@ethersproject/contracts'

import { testSetup } from '../scripts/testSetup'
import args from './getCLargs'
import { L1TransactionReceipt } from '../src/lib/message/L1Transaction'
import { L1TransactionReceipt } from '../src/lib/message/ParentTransaction'
import { L1ToL2MessageStatus, L1ToL2MessageWriter } from '../src'
import { fundL2 } from '../integration_test/testHelpers'

Expand All @@ -35,14 +35,14 @@ if (!l1Txn) {
}

;(async () => {
const { l1Signer, l2Signer } = await testSetup()
const { parentSigner, childSigner } = await testSetup()
// TODO: Should use the PRIVKEY envvar signer directly
fundL2(l2Signer)
const l1Provider = l1Signer.provider!
fundL2(childSigner)
const l1Provider = parentSigner.provider!
const l1Receipt = new L1TransactionReceipt(
await l1Provider.getTransactionReceipt(l1Txn)
)
const l1ToL2Message = await l1Receipt.getL1ToL2Message(l2Signer)
const l1ToL2Message = await l1Receipt.getL1ToL2Message(childSigner)
if (l1ToL2Message instanceof L1ToL2MessageWriter) {
const redeemStatus = (await l1ToL2Message.waitForStatus()).status
if (redeemStatus == L1ToL2MessageStatus.REDEEMED) {
Expand Down
8 changes: 4 additions & 4 deletions scripts/sendL2SignedMsg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@

import { BigNumber } from 'ethers'
import { InboxTools } from '../src/lib/inbox/inbox'
import { getL2Network } from '../src/lib/dataEntities/networks'
import { getArbitrumNetwork } from '../src/lib/dataEntities/networks'
import { testSetup } from '../scripts/testSetup'
const sendSignedMsg = async () => {
const { l1Deployer, l2Deployer } = await testSetup()
const l2Network = await getL2Network(await l2Deployer.getChainId())
const l2Network = await getArbitrumNetwork(await l2Deployer.getChainId())
const inbox = new InboxTools(l1Deployer, l2Network)
const message = {
to: await l2Deployer.getAddress(),
value: BigNumber.from(0),
data: '0x12',
}
const signedTx = await inbox.signL2Tx(message, l2Deployer)
await inbox.sendL2SignedTx(signedTx)
const signedTx = await inbox.signChildChainTx(message, l2Deployer)
await inbox.sendChildChainSignedTx(signedTx)
}

sendSignedMsg()
Expand Down
Loading
Loading