Class: Erc20Bridger
assetBridger/erc20Bridger.Erc20Bridger
Bridger for moving ERC20 tokens back and forth between L1 to L2
Hierarchy
AssetBridger
<Erc20DepositParams
|L1ToL2TxReqAndSignerProvider
,OmitTyped
<Erc20WithdrawParams
,"from"
> |L2ToL1TransactionRequest
>↳
Erc20Bridger
Constructors
constructor
new Erc20Bridger(l2Network
)
Bridger for moving ERC20 tokens back and forth between L1 to L2
Parameters
Name | Type |
---|---|
l2Network | L2Network |
Overrides
AssetBridger< Erc20DepositParams | L1ToL2TxReqAndSignerProvider, OmitTyped<Erc20WithdrawParams, 'from'\> | L2ToL1TransactionRequest \>.constructor
Defined in
src/lib/assetBridger/erc20Bridger.ts:181
Methods
approveToken
approveToken(params
): Promise
<ContractTransaction
>
Approve tokens for deposit to the bridge. The tokens will be approved for the relevant gateway.
Parameters
Name | Type |
---|---|
params | ApproveParamsOrTxRequest |
Returns
Promise
<ContractTransaction
>
Defined in
src/lib/assetBridger/erc20Bridger.ts:269
checkL1Network
Protected
checkL1Network(sop
): Promise
<void
>
Check the signer/provider matches the l1Network, throws if not
Parameters
Name | Type |
---|---|
sop | SignerOrProvider |
Returns
Promise
<void
>
Inherited from
Defined in
src/lib/assetBridger/assetBridger.ts:48
checkL2Network
Protected
checkL2Network(sop
): Promise
<void
>
Check the signer/provider matches the l2Network, throws if not
Parameters
Name | Type |
---|---|
sop | SignerOrProvider |
Returns
Promise
<void
>
Inherited from
Defined in
src/lib/assetBridger/assetBridger.ts:56
deposit
deposit(params
): Promise
<L1ContractCallTransaction
>
Execute a token deposit from L1 to L2
Parameters
Name | Type |
---|---|
params | Erc20DepositParams | L1ToL2TxReqAndSignerProvider |
Returns
Promise
<L1ContractCallTransaction
>
Overrides
Defined in
src/lib/assetBridger/erc20Bridger.ts:604
getApproveTokenRequest
getApproveTokenRequest(params
): Promise
<Required
<Pick
<TransactionRequest
, "value"
| "to"
| "data"
>>>
Get a tx request to approve tokens for deposit to the bridge. The tokens will be approved for the relevant gateway.
Parameters
Name | Type |
---|---|
params | ProviderTokenApproveParams |
Returns
Promise
<Required
<Pick
<TransactionRequest
, "value"
| "to"
| "data"
>>>
Defined in
src/lib/assetBridger/erc20Bridger.ts:236
getDepositRequest
getDepositRequest(params
): Promise
<L1ToL2TransactionRequest
>
Get the arguments for calling the deposit function
Parameters
Name | Type |
---|---|
params | DepositRequest |
Returns
Promise
<L1ToL2TransactionRequest
>
Defined in
src/lib/assetBridger/erc20Bridger.ts:506
getL1ERC20Address
getL1ERC20Address(erc20L2Address
, l2Provider
): Promise
<string
>
Get the corresponding L1 for the provided L2 token Validates the returned address against the l2 router to ensure it is correctly mapped to the provided erc20L2Address
Parameters
Name | Type |
---|---|
erc20L2Address | string |
l2Provider | Provider |
Returns
Promise
<string
>
Defined in
src/lib/assetBridger/erc20Bridger.ts:434
getL1GatewayAddress
getL1GatewayAddress(erc20L1Address
, l1Provider
): Promise
<string
>
Get the address of the l1 gateway for this token
Parameters
Name | Type |
---|---|
erc20L1Address | string |
l1Provider | Provider |
Returns
Promise
<string
>
Defined in
src/lib/assetBridger/erc20Bridger.ts:200
getL1TokenContract
getL1TokenContract(l1Provider
, l1TokenAddr
): ERC20
Get the L1 token contract at the provided address Note: This function just returns a typed ethers object for the provided address, it doesnt check the underlying form of the contract bytecode to see if it's an erc20, and doesn't ensure the validity of any of the underlying functions on that contract.
Parameters
Name | Type |
---|---|
l1Provider | Provider |
l1TokenAddr | string |
Returns
ERC20
Defined in
src/lib/assetBridger/erc20Bridger.ts:401
getL2ERC20Address
getL2ERC20Address(erc20L1Address
, l1Provider
): Promise
<string
>
Get the corresponding L2 for the provided L1 token
Parameters
Name | Type |
---|---|
erc20L1Address | string |
l1Provider | Provider |
Returns
Promise
<string
>
Defined in
src/lib/assetBridger/erc20Bridger.ts:411
getL2GatewayAddress
getL2GatewayAddress(erc20L1Address
, l2Provider
): Promise
<string
>
Get the address of the l2 gateway for this token
Parameters
Name | Type |
---|---|
erc20L1Address | string |
l2Provider | Provider |
Returns
Promise
<string
>
Defined in
src/lib/assetBridger/erc20Bridger.ts:218
getL2TokenContract
getL2TokenContract(l2Provider
, l2TokenAddr
): L2GatewayToken
Get the L2 token contract at the provided address Note: This function just returns a typed ethers object for the provided address, it doesnt check the underlying form of the contract bytecode to see if it's an erc20, and doesn't ensure the validity of any of the underlying functions on that contract.
Parameters
Name | Type |
---|---|
l2Provider | Provider |
l2TokenAddr | string |
Returns
L2GatewayToken
Defined in
src/lib/assetBridger/erc20Bridger.ts:385
getL2WithdrawalEvents
getL2WithdrawalEvents(l2Provider
, gatewayAddress
, filter
, l1TokenAddress?
, fromAddress?
): Promise
<{ _amount
: BigNumber
; _exitNum
: BigNumber
; _from
: string
; _l2ToL1Id
: BigNumber
; _to
: string
; l1Token
: string
} & { txHash
: string
}[]>
Get the L2 events created by a withdrawal
Parameters
Name | Type |
---|---|
l2Provider | Provider |
gatewayAddress | string |
filter | Object |
filter.fromBlock | BlockTag |
filter.toBlock | BlockTag |
l1TokenAddress? | string |
fromAddress? | string |
Returns
Promise
<{ _amount
: BigNumber
; _exitNum
: BigNumber
; _from
: string
; _l2ToL1Id
: BigNumber
; _to
: string
; l1Token
: string
} & { txHash
: string
}[]>
Defined in
src/lib/assetBridger/erc20Bridger.ts:295
getWithdrawalRequest
getWithdrawalRequest(params
): Promise
<L2ToL1TransactionRequest
>
Get the arguments for calling the token withdrawal function
Parameters
Name | Type |
---|---|
params | Erc20WithdrawParams |
Returns
Promise
<L2ToL1TransactionRequest
>
Defined in
src/lib/assetBridger/erc20Bridger.ts:640
isWethGateway
Private
isWethGateway(gatewayAddress
, l1Provider
): Promise
<boolean
>
Is this a known or unknown WETH gateway
Parameters
Name | Type |
---|---|
gatewayAddress | string |
l1Provider | Provider |
Returns
Promise
<boolean
>
Defined in
src/lib/assetBridger/erc20Bridger.ts:359
l1TokenIsDisabled
l1TokenIsDisabled(l1TokenAddress
, l1Provider
): Promise
<boolean
>
Whether the token has been disabled on the router
Parameters
Name | Type |
---|---|
l1TokenAddress | string |
l1Provider | Provider |
Returns
Promise
<boolean
>
Defined in
src/lib/assetBridger/erc20Bridger.ts:473
looksLikeWethGateway
Private
looksLikeWethGateway(potentialWethGatewayAddress
, l1Provider
): Promise
<boolean
>
Does the provided address look like a weth gateway
Parameters
Name | Type |
---|---|
potentialWethGatewayAddress | string |
l1Provider | Provider |
Returns
Promise
<boolean
>
Defined in
src/lib/assetBridger/erc20Bridger.ts:329
withdraw
withdraw(params
): Promise
<L2ContractTransaction
>
Withdraw tokens from L2 to L1
Parameters
Name | Type |
---|---|
params | OmitTyped <Erc20WithdrawParams , "from" > & { l2Signer : Signer } | L2ToL1TxReqAndSigner |
Returns
Promise
<L2ContractTransaction
>
Overrides
Defined in
src/lib/assetBridger/erc20Bridger.ts:694
fromProvider
Static
fromProvider(l2Provider
): Promise
<Erc20Bridger
>
Instantiates a new Erc20Bridger from an L2 Provider
Parameters
Name | Type |
---|---|
l2Provider | Provider |
Returns
Promise
<Erc20Bridger
>