-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: getBridgeTransaction partial support for V2 structs
- Loading branch information
1 parent
2b77b4a
commit 271f59d
Showing
2 changed files
with
27 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,13 +127,32 @@ contract FastBridgeV2 is Admin, IFastBridgeV2, IFastBridgeV2Errors { | |
} | ||
|
||
/// @inheritdoc IFastBridge | ||
function getBridgeTransaction(bytes memory request) external pure returns (BridgeTransaction memory) { | ||
// TODO: the note below isn't true anymore with the BridgeTransactionV2 struct | ||
// since the variable length `callParams` was added. This needs to be fixed/acknowledged. | ||
|
||
// Note: when passing V2 request, this will decode the V1 fields correctly since the new fields were | ||
// added as the last fields of the struct and hence the ABI decoder will simply ignore the extra data. | ||
return abi.decode(request, (BridgeTransaction)); | ||
/// @dev This method is added to achieve backwards compatibility with decoding requests into V1 structs: | ||
/// - `callValue` is partially reported as a zero/non-zero flag | ||
/// - `callParams` is ignored | ||
/// In order to process all kinds of requests use getBridgeTransactionV2 instead. | ||
function getBridgeTransaction(bytes memory request) external view returns (BridgeTransaction memory) { | ||
// Try decoding into V2 struct first. This will revert if V1 struct is passed | ||
try this.getBridgeTransactionV2(request) returns (BridgeTransactionV2 memory txV2) { | ||
// Note: we entirely ignore the callParams field, as it was not present in V1 | ||
return BridgeTransaction({ | ||
originChainId: txV2.originChainId, | ||
destChainId: txV2.destChainId, | ||
originSender: txV2.originSender, | ||
destRecipient: txV2.destRecipient, | ||
originToken: txV2.originToken, | ||
destToken: txV2.destToken, | ||
originAmount: txV2.originAmount, | ||
destAmount: txV2.destAmount, | ||
originFeeAmount: txV2.originFeeAmount, | ||
sendChainGas: txV2.callValue != 0, | ||
deadline: txV2.deadline, | ||
nonce: txV2.nonce | ||
}); | ||
} catch { | ||
// Fallback to V1 struct | ||
return abi.decode(request, (BridgeTransaction)); | ||
} | ||
} | ||
Check warning Code scanning / Slither Public variable read in external context Warning
The function FastBridgeV2.getBridgeTransaction(bytes) reads txV2 = this.getBridgeTransactionV2(request) with this which adds an extra STATICCALL.
|
||
|
||
/// @inheritdoc IFastBridgeV2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters