Skip to content
Merged
Changes from all commits
Commits
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
75 changes: 47 additions & 28 deletions packages/boba/gateway/src/services/networkService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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...
Expand Down