Skip to content

Commit

Permalink
feat(accounts): rename DepositTransaction fields
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Renamed `DepositTransaction` fields:
`ApproveERC20` to `ApproveToken`, `ApproveBaseERC20` to
`ApproveBaseToken`.
  • Loading branch information
danijelTxFusion committed Nov 5, 2024
1 parent 80dd564 commit c070cfe
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
12 changes: 6 additions & 6 deletions accounts/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -849,12 +849,12 @@ type DepositTransaction struct {
BridgeAddress *common.Address

// Whether should the token approval be performed under the hood. Set this flag to true if you
// bridge an ERC20 token and didn't call the approveERC20 function beforehand.
ApproveERC20 bool
// bridge an ERC20 token and didn't call the ApproveToken function beforehand.
ApproveToken bool

// Whether should the base token approval be performed under the hood. Set this flag to true if you
// bridge an ERC20 token and didn't call the approveERC20 function beforehand.
ApproveBaseERC20 bool
// bridge an ERC20 token and didn't call the ApproveToken function beforehand.
ApproveBaseToken bool

L2GasLimit *big.Int // Maximum amount of L2 gas that transaction can consume during execution on L2.

Expand Down Expand Up @@ -913,10 +913,10 @@ func (t *DepositTransaction) PopulateEmptyFields(from common.Address) {
if t.Token == (common.Address{}) {
t.Token = utils.LegacyEthAddress
}
if t.ApproveERC20 && t.ApproveAuth == nil {
if t.ApproveToken && t.ApproveAuth == nil {
t.ApproveAuth = ensureTransactOptsL1(t.ApproveAuth)
}
if t.ApproveBaseERC20 && t.ApproveBaseAuth == nil {
if t.ApproveBaseToken && t.ApproveBaseAuth == nil {
t.ApproveAuth = ensureTransactOptsL1(t.ApproveBaseAuth)
}
}
Expand Down
16 changes: 8 additions & 8 deletions accounts/wallet_l1.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ func (w *WalletL1) DepositAllowanceParams(opts *CallOpts, msg DepositCallMsg) ([
// to the target account on the L2 network. The token can be either ETH or any ERC20 token.
// For ERC20 tokens, enough approved tokens must be associated with the specified L1 bridge
// (default one or the one defined in DepositTransaction.BridgeAddress).
// In this case, depending on is the chain ETH-based or not DepositTransaction.ApproveERC20 or
// DepositTransaction.ApproveBaseERC20 can be enabled to perform token approval.
// In this case, depending on is the chain ETH-based or not DepositTransaction.ApproveToken or
// DepositTransaction.ApproveBaseToken can be enabled to perform token approval.
// If there are already enough approved tokens for the L1 bridge, token approval will be skipped.
// To check the amount of approved tokens for a specific bridge, use the AdapterL1.AllowanceL1 method.
func (w *WalletL1) Deposit(auth *TransactOptsL1, tx DepositTransaction) (*ethTypes.Transaction, error) {
Expand Down Expand Up @@ -961,7 +961,7 @@ func (w *WalletL1) depositTokenToEthBasedChain(opts *TransactOptsL1, tx *Deposit
return nil, checkErr
}

if tx.ApproveERC20 {
if tx.ApproveToken {
l1SharedBridgeAddress, addressError := w.cache.L1SharedBridgeAddress()
if addressError != nil {
return nil, addressError
Expand Down Expand Up @@ -1048,7 +1048,7 @@ func (w *WalletL1) depositEthToNonEthBasedChain(opts *TransactOptsL1, tx *Deposi
return nil, checkErr
}

if tx.ApproveBaseERC20 {
if tx.ApproveBaseToken {
l1SharedBridgeAddress, addressError := w.cache.L1SharedBridgeAddress()
if addressError != nil {
return nil, addressError
Expand Down Expand Up @@ -1123,9 +1123,9 @@ func (w *WalletL1) depositBaseTokenToNonEthBasedChain(opts *TransactOptsL1, tx *
return nil, err
}

if tx.ApproveBaseERC20 || tx.ApproveERC20 {
if tx.ApproveBaseToken || tx.ApproveToken {
approveOpts := tx.ApproveBaseAuth
if tx.ApproveBaseERC20 {
if tx.ApproveBaseToken {
approveOpts = tx.ApproveAuth
}
l1SharedBridgeAddress, addressError := w.cache.L1SharedBridgeAddress()
Expand Down Expand Up @@ -1180,7 +1180,7 @@ func (w *WalletL1) depositNonBaseTokenToNonEthBasedChain(opts *TransactOptsL1, t
return nil, checkErr
}

if tx.ApproveBaseERC20 {
if tx.ApproveBaseToken {
l1SharedBridgeAddress, addressError := w.cache.L1SharedBridgeAddress()
if addressError != nil {
return nil, addressError
Expand All @@ -1191,7 +1191,7 @@ func (w *WalletL1) depositNonBaseTokenToNonEthBasedChain(opts *TransactOptsL1, t
}
}

if tx.ApproveERC20 {
if tx.ApproveToken {
l1SharedBridgeAddress, addressError := w.cache.L1SharedBridgeAddress()
if addressError != nil {
return nil, addressError
Expand Down
4 changes: 2 additions & 2 deletions test/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ func sendTokenToL2(wallet *accounts.Wallet, client *clients.Client, ethClient *e
Token: l1Token,
Amount: amount,
To: wallet.Address(),
ApproveERC20: true,
ApproveBaseERC20: true,
ApproveToken: true,
ApproveBaseToken: true,
RefundRecipient: wallet.Address(),
})
if err != nil {
Expand Down
16 changes: 8 additions & 8 deletions test/wallet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,7 @@ func TestIntegrationWallet_DeployAccount(t *testing.T) {
// To: wallet.Address1(),
// Amount: big.NewInt(5),
// ApproveToken: true,
// ApproveBaseERC20: true,
// ApproveBaseToken: true,
// L2GasLimit: big.NewInt(255_000), // make it fail because of low gas
// })
//
Expand All @@ -1460,8 +1460,8 @@ func TestIntegration_Wallet_ClaimFailedDepositSuccessfulDeposit(t *testing.T) {
To: wallet.Address(),
Token: L1Dai,
Amount: big.NewInt(5),
ApproveERC20: true,
ApproveBaseERC20: true,
ApproveToken: true,
ApproveBaseToken: true,
RefundRecipient: wallet.Address(),
})
assert.NoError(t, err, "Deposit should not return an error")
Expand Down Expand Up @@ -1605,7 +1605,7 @@ func TestIntegration_EthBasedChain_Wallet_DepositToken(t *testing.T) {
To: wallet.Address(),
Token: L1Dai,
Amount: amount,
ApproveERC20: true,
ApproveToken: true,
RefundRecipient: wallet.Address(),
})
assert.NoError(t, err, "Deposit should not return an error")
Expand Down Expand Up @@ -1947,7 +1947,7 @@ func TestIntegration_NonEthBasedChain_Wallet_DepositEth(t *testing.T) {
To: wallet.Address(),
Token: utils.LegacyEthAddress,
Amount: amount,
ApproveBaseERC20: true,
ApproveBaseToken: true,
RefundRecipient: wallet.Address(),
})
assert.NoError(t, err, "Deposit should not return an error")
Expand Down Expand Up @@ -1999,7 +1999,7 @@ func TestIntegration_NonEthBasedChain_Wallet_DepositBaseToken(t *testing.T) {
To: wallet.Address(),
Token: baseToken,
Amount: amount,
ApproveBaseERC20: true,
ApproveBaseToken: true,
RefundRecipient: wallet.Address(),
})
assert.NoError(t, err, "Deposit should not return an error")
Expand Down Expand Up @@ -2048,8 +2048,8 @@ func TestIntegration_NonEthBasedChain_Wallet_DepositNonBaseToken(t *testing.T) {
To: wallet.Address(),
Token: L1Dai,
Amount: amount,
ApproveERC20: true,
ApproveBaseERC20: true,
ApproveToken: true,
ApproveBaseToken: true,
RefundRecipient: wallet.Address(),
})
assert.NoError(t, err, "Deposit should not return an error")
Expand Down

0 comments on commit c070cfe

Please sign in to comment.