Skip to content

Commit

Permalink
rename some types
Browse files Browse the repository at this point in the history
  • Loading branch information
godzillaba committed Oct 3, 2023
1 parent 3b8b600 commit 2c6fbf7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 55 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/* eslint-env node */
'use strict'

export { L1L3Bridger } from './lib/assetBridger/l1l3Bridger'
export { Erc20L1L3Bridger } from './lib/assetBridger/l1l3Bridger'
export { EthBridger } from './lib/assetBridger/ethBridger'
export { Erc20Bridger } from './lib/assetBridger/erc20Bridger'
export {
Expand Down
74 changes: 23 additions & 51 deletions src/lib/assetBridger/l1l3Bridger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,35 +38,7 @@ import { L1ToL2MessageStatus } from '../message/L1ToL2Message'
import { L2ForwarderPredictor } from '../abi/L2ForwarderPredictor'
import { L1ToL2TransactionRequest } from '../dataEntities/transactionRequest'

/*
API:
fromProvider
DONE: checkL1Network (and L2 and L3)
deposit
getDepositRequest
DONE: getL1L2GatewayAddress (and L2L3)
approveToken
DONE (untested): getApproveTokenRequest
DONE: getL1TokenContract (L2 and L3 too)
DONE: getL2ERC20Address (L3)
DONE: l1TokenIsDisabled (L2)
for gas estimation:
if the l1l2 gateway is default, use hardcoded gas limit and calldata size
if it is custom, then throw if user does not provide a specific gas limit and calldata size
do the same for the l2l3 gateway
*/

export enum TeleportationLeg {
export enum Erc20TeleportationLeg {
BridgeToL2,
CallL2ForwarderFactory,
BridgeToL3,
Expand All @@ -90,7 +62,7 @@ export interface PopulatedRetryableGasParams extends ManualRetryableGasParams {
l3GasPrice: BigNumber
}

export interface DepositRequestParams {
export interface Erc20DepositRequestParams {
erc20L1Address: string
to: string
amount: BigNumberish
Expand All @@ -101,7 +73,7 @@ export interface DepositRequestParams {
}
}

export interface DepositEthRequestParams {
export interface EthDepositRequestParams {
to: string
amount: BigNumberish
overrides?: {
Expand All @@ -110,9 +82,9 @@ export interface DepositEthRequestParams {
}

// if using relayer and leg 1 times out, failedLegStatus will be undefined
export interface WaitForDepositResult {
export interface WaitForErc20DepositResult {
success: boolean
failedLeg?: TeleportationLeg
failedLeg?: Erc20TeleportationLeg
failedLegStatus?: Exclude<L1ToL2MessageStatus, L1ToL2MessageStatus.REDEEMED>
}

Expand All @@ -126,12 +98,12 @@ export type RelayerInfo = L2ForwarderPredictor.L2ForwarderParamsStruct & {
chainId: number
}

export type DepositRequestUsingRelayerResult = {
export type RelayedErc20DepositRequestResult = {
txRequest: L1ToL2TransactionRequest
relayerInfo: RelayerInfo
}

export type DepositUsingRelayerResult = {
export type RelayedErc20DepositResult = {
tx: L1ContractCallTransaction
relayerInfo: RelayerInfo
}
Expand Down Expand Up @@ -200,7 +172,7 @@ class BaseL1L3Bridger {
}
}

class Erc20L1L3Bridger extends BaseL1L3Bridger {
class BaseErc20L1L3Bridger extends BaseL1L3Bridger {
public readonly teleporterAddresses: TeleporterAddresses

// todo: tune these
Expand Down Expand Up @@ -441,7 +413,7 @@ class Erc20L1L3Bridger extends BaseL1L3Bridger {
}

protected async _populateGasParams(
params: DepositRequestParams,
params: Erc20DepositRequestParams,
l1Provider: Provider,
l2Provider: Provider,
l3Provider: Provider
Expand Down Expand Up @@ -489,7 +461,7 @@ class Erc20L1L3Bridger extends BaseL1L3Bridger {
}
}

export class L1L3Bridger extends Erc20L1L3Bridger {
export class Erc20L1L3Bridger extends BaseErc20L1L3Bridger {
/**
* Get a tx request to approve tokens for teleportation.
* The tokens will be approved for the Teleporter on L1.
Expand Down Expand Up @@ -524,7 +496,7 @@ export class L1L3Bridger extends Erc20L1L3Bridger {
}

public async getDepositRequest(
params: DepositRequestParams,
params: Erc20DepositRequestParams,
l1Provider: Provider,
l2Provider: Provider,
l3Provider: Provider
Expand Down Expand Up @@ -570,7 +542,7 @@ export class L1L3Bridger extends Erc20L1L3Bridger {
}

public async deposit(
params: DepositRequestParams,
params: Erc20DepositRequestParams,
l1Signer: Signer,
l2Provider: Provider,
l3Provider: Provider
Expand All @@ -591,7 +563,7 @@ export class L1L3Bridger extends Erc20L1L3Bridger {
depositTxReceipt: L1TransactionReceipt,
l2Provider: Provider,
l3Provider: Provider
): Promise<WaitForDepositResult> {
): Promise<WaitForErc20DepositResult> {
if (depositTxReceipt.to !== this.teleporterAddresses.l1Teleporter) {
throw new ArbSdkError(
`Transaction receipt is not for the teleporter: ${depositTxReceipt.to}`
Expand All @@ -608,13 +580,13 @@ export class L1L3Bridger extends Erc20L1L3Bridger {
if (firstLegStatus != L1ToL2MessageStatus.REDEEMED) {
return {
success: false,
failedLeg: TeleportationLeg.BridgeToL2,
failedLeg: Erc20TeleportationLeg.BridgeToL2,
failedLegStatus: firstLegStatus,
}
} else if (secondLegStatus != L1ToL2MessageStatus.REDEEMED) {
return {
success: false,
failedLeg: TeleportationLeg.CallL2ForwarderFactory,
failedLeg: Erc20TeleportationLeg.CallL2ForwarderFactory,
failedLegStatus: secondLegStatus,
}
}
Expand All @@ -630,7 +602,7 @@ export class L1L3Bridger extends Erc20L1L3Bridger {
if (thirdLegStatus != L1ToL2MessageStatus.REDEEMED) {
return {
success: false,
failedLeg: TeleportationLeg.BridgeToL3,
failedLeg: Erc20TeleportationLeg.BridgeToL3,
failedLegStatus: thirdLegStatus,
}
}
Expand All @@ -641,7 +613,7 @@ export class L1L3Bridger extends Erc20L1L3Bridger {
}
}

export class L1L3BridgerUsingRelayer extends Erc20L1L3Bridger {
export class RelayedErc20L1L3Bridger extends BaseErc20L1L3Bridger {
public async getApproveTokenRequest(
params: TokenApproveParams,
l1Provider: Provider
Expand All @@ -657,11 +629,11 @@ export class L1L3BridgerUsingRelayer extends Erc20L1L3Bridger {
}

public async getDepositRequest(
params: DepositRequestParams,
params: Erc20DepositRequestParams,
l1Signer: Signer,
l2Provider: Provider,
l3Provider: Provider
): Promise<DepositRequestUsingRelayerResult> {
): Promise<RelayedErc20DepositRequestResult> {
await this._checkL1Network(l1Signer)
await this._checkL2Network(l2Provider)
await this._checkL3Network(l3Provider)
Expand Down Expand Up @@ -738,19 +710,19 @@ export class L1L3BridgerUsingRelayer extends Erc20L1L3Bridger {
}

public async deposit(
params: DepositRequestParams,
params: Erc20DepositRequestParams,
l1Signer: Signer,
l2Provider: Provider,
l3Provider: Provider
): Promise<DepositUsingRelayerResult> {
): Promise<RelayedErc20DepositResult> {
throw new Error('Not implemented')
}

public async waitForDeposit(
depositResult: DepositUsingRelayerResult,
depositResult: RelayedErc20DepositResult,
l2Provider: Provider,
l3Provider: Provider
): Promise<WaitForDepositResult> {
): Promise<WaitForErc20DepositResult> {
throw new Error('Not implemented')
}

Expand Down
6 changes: 3 additions & 3 deletions tests/integration/l1l3Bridger.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { testSetup } from '../../scripts/testSetup'
import { L1L3Bridger } from '../../src'
import { Erc20L1L3Bridger } from '../../src'
import { L2ForwarderContractsDeployer__factory } from '../../src/lib/abi/factories/L2ForwarderContractsDeployer__factory'
import { MockToken__factory } from '../../src/lib/abi/factories/MockToken__factory'
import { MockToken } from '../../src/lib/abi/MockToken'
Expand All @@ -11,7 +11,7 @@ type Unwrap<T> = T extends Promise<infer U> ? U : T

describe('Teleporter', () => {
let setup: Unwrap<ReturnType<typeof testSetup>>
let l1l3Bridger: L1L3Bridger
let l1l3Bridger: Erc20L1L3Bridger
let l1Token: MockToken

before(async function () {
Expand Down Expand Up @@ -45,7 +45,7 @@ describe('Teleporter', () => {
l2ForwarderFactory,
}

l1l3Bridger = new L1L3Bridger(setup.l3Network)
l1l3Bridger = new Erc20L1L3Bridger(setup.l3Network)

// deploy the mock token
l1Token = await new MockToken__factory(setup.l1Signer).deploy(
Expand Down

0 comments on commit 2c6fbf7

Please sign in to comment.