Skip to content

Commit cf87da0

Browse files
committed
add calldata to batch bridge transaction
1 parent 31a091f commit cf87da0

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

cadence/tests/flow_evm_bridge_tests.cdc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ fun testBatchBridgeCadenceNativeNFTToEVMSucceeds() {
762762
// Execute bridge to EVM
763763
let bridgeResult = executeTransaction(
764764
"../transactions/bridge/nft/batch_bridge_nft_to_evm.cdc",
765-
[ exampleNFTIdentifier, aliceOwnedIDs ],
765+
[ exampleNFTIdentifier, aliceOwnedIDs, [], [], [], [] ],
766766
alice
767767
)
768768
Test.expect(bridgeResult, Test.beSucceeded())

cadence/transactions/bridge/nft/batch_bridge_nft_to_evm.cdc

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,44 @@ import "FlowEVMBridgeConfig"
1313
import "FlowEVMBridgeUtils"
1414

1515
/// Bridges NFTs (from the same collection) from the signer's collection in Cadence to the signer's COA in FlowEVM
16+
/// and then performs an arbitrary number of calls afterwards to potentially do things
17+
/// with the bridged NFTs
1618
///
17-
/// NOTE: This transaction also onboards the NFT to the bridge if necessary which may incur additional fees
18-
/// than bridging an asset that has already been onboarded.
19+
/// This transaction assumes that the NFT has already been onboarded to the bridge
1920
///
2021
/// @param nftIdentifier: The Cadence type identifier of the NFT to bridge - e.g. nft.getType().identifier
2122
/// @param ids: The Cadence NFT.id of the NFTs to bridge to EVM
23+
/// @params evmContractAddressHexes, calldatas, gasLimits, values: An array of calldata
24+
/// to be included in transaction calls to Flow EVM from the signer's COA.
25+
/// The arrays are all expected to be of the same length
2226
///
23-
transaction(nftIdentifier: String, ids: [UInt64]) {
27+
transaction(
28+
nftIdentifier: String,
29+
ids: [UInt64],
30+
evmContractAddressHexes: [String],
31+
calldatas: [String],
32+
gasLimits: [UInt64],
33+
values: [UFix64]
34+
) {
2435

2536
let nftType: Type
2637
let collection: auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Collection}
27-
let coa: auth(EVM.Bridge) &EVM.CadenceOwnedAccount
38+
let coa: auth(EVM.Bridge, EVM.Call) &EVM.CadenceOwnedAccount
2839
let requiresOnboarding: Bool
2940
let scopedProvider: @ScopedFTProviders.ScopedFTProvider
3041

3142
prepare(signer: auth(CopyValue, BorrowValue, IssueStorageCapabilityController, PublishCapability, SaveValue) &Account) {
43+
pre {
44+
(evmContractAddressHexes.length == calldatas.length)
45+
&& (calldatas.length == gasLimits.length)
46+
&& (gasLimits.length == values.length):
47+
"Calldata array lengths must all be the same!"
48+
}
49+
3250
/* --- Reference the signer's CadenceOwnedAccount --- */
3351
//
3452
// Borrow a reference to the signer's COA
35-
self.coa = signer.storage.borrow<auth(EVM.Bridge) &EVM.CadenceOwnedAccount>(from: /storage/evm)
53+
self.coa = signer.storage.borrow<auth(EVM.Bridge, EVM.Call) &EVM.CadenceOwnedAccount>(from: /storage/evm)
3654
?? panic("Could not borrow COA signer's account at path /storage/evm")
3755

3856
/* --- Construct the NFT type --- */
@@ -98,6 +116,7 @@ transaction(nftIdentifier: String, ids: [UInt64]) {
98116
}
99117

100118
execute {
119+
101120
if self.requiresOnboarding {
102121
// Onboard the NFT to the bridge
103122
FlowEVMBridge.onboardByType(
@@ -124,5 +143,22 @@ transaction(nftIdentifier: String, ids: [UInt64]) {
124143

125144
// Destroy the ScopedFTProvider
126145
destroy self.scopedProvider
146+
147+
// Perform all the calls
148+
for index, evmAddressHex in evmContractAddressHexes {
149+
let evmAddress = EVM.addressFromString(evmAddressHex)
150+
151+
let valueBalance = EVM.Balance(attoflow: 0)
152+
valueBalance.setFLOW(flow: values[index])
153+
let callResult = self.coa.call(
154+
to: evmAddress,
155+
data: calldatas[index].decodeHex(),
156+
gasLimit: gasLimits[index],
157+
value: valueBalance
158+
)
159+
assert(
160+
callResult.status == EVM.Status.successful,
161+
message: "Call failed with address \(evmAddressHex) and calldata \(calldatas[index]) with error \(callResult.errorMessage)")
162+
}
127163
}
128164
}

0 commit comments

Comments
 (0)