Skip to content

Commit 93b68c4

Browse files
committed
Better error message in EVMTokenConnectors.Sink.depositCapacity() regarding insufficient bridging fees
1 parent 3798cb4 commit 93b68c4

2 files changed

Lines changed: 21 additions & 17 deletions

File tree

cadence/contracts/connectors/evm/ERC4626SinkConnectors.cdc

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,16 @@ access(all) contract ERC4626SinkConnectors {
132132
// approve the ERC4626 vault to spend the assets on deposit
133133
let uintAmount = FlowEVMBridgeUtils.convertCadenceAmountToERC20Amount(amount, erc20Address: self.assetEVMAddress)
134134
let approveRes = self._call(
135-
to: self.assetEVMAddress,
136-
signature: "approve(address,uint256)",
137-
args: [self.vault, uintAmount],
138-
gasLimit: 500_000
139-
)!
140-
if approveRes.status != EVM.Status.successful {
141-
// Cadence panic reverts all EVM state changes in this transaction, so no need to bridge token back.
142-
panic(self._approveErrorMessage(ufixAmount: amount, uintAmount: uintAmount, approveRes: approveRes))
143-
}
135+
to: self.assetEVMAddress,
136+
signature: "approve(address,uint256)",
137+
args: [self.vault, uintAmount],
138+
gasLimit: 500_000
139+
)!
140+
// Cadence panic reverts all EVM state changes in this transaction, so no need to bridge token back.
141+
assert(
142+
approveRes.status == EVM.Status.successful,
143+
message: self._approveErrorMessage(ufixAmount: amount, uintAmount: uintAmount, approveRes: approveRes)
144+
)
144145

145146
// deposit the assets to the ERC4626 vault
146147
let depositRes = self._call(
@@ -149,11 +150,12 @@ access(all) contract ERC4626SinkConnectors {
149150
args: [uintAmount, self.coa.borrow()!.address()],
150151
gasLimit: 1_000_000
151152
)!
152-
if depositRes.status != EVM.Status.successful {
153-
// No need to revoke the approval: a Cadence panic atomically reverts all EVM
154-
// state changes made in this transaction, including the approve() call above.
155-
panic(self._depositErrorMessage(ufixAmount: amount, uintAmount: uintAmount, depositRes: depositRes))
156-
}
153+
// No need to revoke the approval: a Cadence panic atomically reverts all EVM
154+
// state changes made in this transaction, including the approve() call above.
155+
assert(
156+
depositRes.status == EVM.Status.successful,
157+
message: self._depositErrorMessage(ufixAmount: amount, uintAmount: uintAmount, depositRes: depositRes)
158+
)
157159
}
158160
/// Returns a ComponentInfo struct containing information about this component and a list of ComponentInfo for
159161
/// each inner component in the stack.

cadence/contracts/connectors/evm/EVMTokenConnectors.cdc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,11 @@ access(all) contract EVMTokenConnectors {
125125

126126
// collect VM bridge fees
127127
let feeAmount = FlowEVMBridgeConfig.baseFee
128-
if self.feeSource.minimumAvailable() < feeAmount {
129-
return // early return here instead of reverting in bridge scope on insufficient fees
130-
}
128+
let availableFees = self.feeSource.minimumAvailable()
129+
assert(
130+
availableFees >= feeAmount,
131+
message: "Fee source \(availableFees.toString()) cannot cover bridging base fee \(feeAmount.toString())"
132+
)
131133
let fees <- self.feeSource.withdrawAvailable(maxAmount: feeAmount)
132134

133135
// deposit tokens and handle remaining fees

0 commit comments

Comments
 (0)