diff --git a/packages/boba/gateway/src/services/networkService.js b/packages/boba/gateway/src/services/networkService.js index 9f7f6995d2..376d895b4b 100644 --- a/packages/boba/gateway/src/services/networkService.js +++ b/packages/boba/gateway/src/services/networkService.js @@ -2113,14 +2113,29 @@ class NetworkService { this.addresses.DiscretionaryExitFee ) - // Should approve BOBA - if ( BobaAllowance.lt(BobaApprovalAmount) ) { - const res = await this.approveERC20( - BobaApprovalAmount, - this.addresses.TK_L2BOBA, - this.addresses.DiscretionaryExitFee - ) - if (!res) return false + if (this.networkGateway === NETWORK.ETHEREUM) { + // Should approve BOBA + if (utils.getAddress(currencyAddress) === utils.getAddress(this.addresses.TK_L2BOBA)) { + BobaApprovalAmount = BobaApprovalAmount.add(value) + } + + if ( BobaAllowance.lt(BobaApprovalAmount) ) { + const res = await this.approveERC20( + BobaApprovalAmount, + this.addresses.TK_L2BOBA, + this.addresses.DiscretionaryExitFee + ) + if (!res) return false + } + + } + + let otherField; + if (this.networkGateway === NETWORK.ETHEREUM) { + otherField = currencyAddress === this.addresses.L2_ETH_Address ? { value: value } : {} + } else { + otherField = currencyAddress === this.addresses.L2_ETH_Address ? + { value: value.add(BobaApprovalAmount) } : { value: BobaApprovalAmount } } // Should approve other tokens @@ -2148,8 +2163,7 @@ class NetworkService { value_Wei_String, this.L1GasLimit, utils.formatBytes32String(new Date().getTime().toString()), - currencyAddress === this.addresses.L2_ETH_Address ? - { value: value.add(BobaApprovalAmount) } : { value: BobaApprovalAmount } + otherField ) //everything submitted... waiting @@ -2158,12 +2172,6 @@ class NetworkService { //can close window now updateSignatureStatus_exitTRAD(true) - const opts = { - fromBlock: -4000 - } - const receipt = await this.watcher.waitForMessageReceipt(tx, opts) - console.log(' got L2->L1 receipt', receipt) - return tx } catch (error) { console.log("NS: exitBOBA error:", error) @@ -3329,17 +3337,21 @@ class NetworkService { ) try { - // Approve BOBA first - if (utils.getAddress(currencyAddress) === utils.getAddress(this.addresses.TK_L2BOBA)) { - BobaApprovalAmount = BobaApprovalAmount.add(BigNumber.from(value_Wei_String)) - } - if (BobaAllowance.lt(BobaApprovalAmount)) { - const approveStatus = await this.approveERC20( - BobaApprovalAmount, - this.addresses.TK_L2BOBA, - this.addresses.L2LPAddress - ) - if (!approveStatus) return false + + if (this.networkGateway === NETWORK.ETHEREUM) { + // Approve BOBA first only when the Boba is not native token. + if (utils.getAddress(currencyAddress) === utils.getAddress(this.addresses.TK_L2BOBA)) { + BobaApprovalAmount = BobaApprovalAmount.add(BigNumber.from(value_Wei_String)) + } + if (BobaAllowance.lt(BobaApprovalAmount)) { + const approveStatus = await this.approveERC20( + BobaApprovalAmount, + this.addresses.TK_L2BOBA, + this.addresses.L2LPAddress + ) + if (!approveStatus) return false + } + } // Approve other tokens @@ -3373,11 +3385,18 @@ class NetworkService { const time_start = new Date().getTime() console.log("TX start time:", time_start) + let otherField; + if (this.networkGateway === NETWORK.ETHEREUM) { + otherField= currencyAddress === this.addresses.L2_ETH_Address ? { value: value_Wei_String } : {} + } else { + otherField= currencyAddress === this.addresses.L2_ETH_Address ? { value: BobaApprovalAmount.add(value_Wei_String) } : {value: BobaApprovalAmount} + } + const depositTX = await this.L2LPContract .connect(this.provider.getSigner()).clientDepositL2( value_Wei_String, currencyAddress, - currencyAddress === this.addresses.L2_ETH_Address ? { value: value_Wei_String } : {value: BobaApprovalAmount} + otherField, ) //at this point the tx has been submitted, and we are waiting...