diff --git a/cadence/tests/flow_evm_bridge_handler_tests.cdc b/cadence/tests/flow_evm_bridge_handler_tests.cdc index 94017183..628d8f10 100644 --- a/cadence/tests/flow_evm_bridge_handler_tests.cdc +++ b/cadence/tests/flow_evm_bridge_handler_tests.cdc @@ -455,8 +455,11 @@ fun testBridgeHandledCadenceNativeTokenToEVMFails() { // Execute bridge to EVM - should fail since Handler is not enabled bridgeTokensToEVM( signer: alice, - contractAddr: exampleHandledTokenAccount.address, - contractName: "ExampleHandledToken", + vaultIdentifier: buildTypeIdentifier( + address: exampleHandledTokenAccount.address, + contractName: "ExampleHandledToken", + resourceName: "Vault" + ), amount: cadenceBalance, beFailed: true ) @@ -474,8 +477,11 @@ fun testBridgeHandledCadenceNativeTokenFromEVMFails() { // Execute bridge from EVM bridgeTokensFromEVM( signer: alice, - contractAddr: exampleHandledTokenAccount.address, - contractName: "ExampleHandledToken", + vaultIdentifier: buildTypeIdentifier( + address: exampleHandledTokenAccount.address, + contractName: "ExampleHandledToken", + resourceName: "Vault" + ), amount: evmBalance, beFailed: true ) @@ -518,8 +524,11 @@ fun testBridgeHandledCadenceNativeTokenToEVMFirstSucceeds() { // Execute bridge to EVM bridgeTokensToEVM( signer: alice, - contractAddr: exampleHandledTokenAccount.address, - contractName: "ExampleHandledToken", + vaultIdentifier: buildTypeIdentifier( + address: exampleHandledTokenAccount.address, + contractName: "ExampleHandledToken", + resourceName: "Vault" + ), amount: cadenceBalance, beFailed: false ) @@ -557,8 +566,11 @@ fun testBridgeHandledCadenceNativeTokenFromEVMSecondSucceeds() { let ufixEVMbalance = uint256ToUFix64(evmBalance, decimals: defaultDecimals) bridgeTokensFromEVM( signer: alice, - contractAddr: exampleHandledTokenAccount.address, - contractName: "ExampleHandledToken", + vaultIdentifier: buildTypeIdentifier( + address: exampleHandledTokenAccount.address, + contractName: "ExampleHandledToken", + resourceName: "Vault" + ), amount: evmBalance, beFailed: false ) @@ -617,8 +629,11 @@ fun testBridgeHandledCadenceNativeTokenFromEVMFirstSucceeds() { // Execute bridge from EVM bridgeTokensFromEVM( signer: alice, - contractAddr: exampleHandledTokenAccount.address, - contractName: "ExampleHandledToken", + vaultIdentifier: buildTypeIdentifier( + address: exampleHandledTokenAccount.address, + contractName: "ExampleHandledToken", + resourceName: "Vault" + ), amount: aliceEVMBalanceBefore, beFailed: false ) @@ -666,9 +681,11 @@ fun testBridgeHandledCadenceNativeTokenToEVMSecondSucceeds() { // Execute bridge to EVM bridgeTokensToEVM( signer: alice, - contractAddr: exampleHandledTokenAccount.address, - contractName: "ExampleHandledToken", - amount: aliceCadenceBalanceBefore, + vaultIdentifier: buildTypeIdentifier( + address: exampleHandledTokenAccount.address, + contractName: "ExampleHandledToken", + resourceName: "Vault" + ), amount: aliceCadenceBalanceBefore, beFailed: false ) diff --git a/cadence/tests/flow_evm_bridge_tests.cdc b/cadence/tests/flow_evm_bridge_tests.cdc index bca990e5..6ab64d01 100644 --- a/cadence/tests/flow_evm_bridge_tests.cdc +++ b/cadence/tests/flow_evm_bridge_tests.cdc @@ -386,9 +386,11 @@ fun testBridgeFlowToEVMSucceeds() { let bridgeAmount = 100.0 bridgeTokensToEVM( signer: alice, - contractAddr: Address(0x03), - contractName: "FlowToken", - amount: bridgeAmount, + vaultIdentifier: buildTypeIdentifier( + address: Address(0x03), + contractName: "FlowToken", + resourceName: "Vault" + ), amount: bridgeAmount, beFailed: false ) @@ -605,8 +607,7 @@ fun testOnboardAndBridgeNFTToEVMSucceeds() { // Execute bridge NFT to EVM - should also onboard the NFT type bridgeNFTToEVM( signer: alice, - contractAddr: exampleNFTAccount.address, - contractName: "ExampleNFT", + nftIdentifier: exampleNFTIdentifier, nftID: aliceID, bridgeAccountAddr: bridgeAccount.address, beFailed: false @@ -658,7 +659,7 @@ fun testOnboardAndCrossVMTransferNFTToEVMSucceeds() { // Execute bridge NFT to EVM recipient - should also onboard the NFT type let crossVMTransferResult = executeTransaction( "../transactions/bridge/nft/bridge_nft_to_any_evm_address.cdc", - [ exampleNFTAccount.address, "ExampleNFT", aliceID, recipient ], + [ exampleNFTIdentifier, aliceID, recipient ], alice ) Test.expect(crossVMTransferResult, Test.beSucceeded()) @@ -731,8 +732,7 @@ fun testOnboardAndBridgeTokensToEVMSucceeds() { // Execute bridge to EVM - should also onboard the token type bridgeTokensToEVM( signer: alice, - contractAddr: exampleTokenAccount.address, - contractName: "ExampleToken", + vaultIdentifier: exampleTokenIdentifier, amount: cadenceBalance, beFailed: false ) @@ -780,7 +780,7 @@ fun testOnboardAndCrossVMTransferTokensToEVMSucceeds() { // Execute bridge to EVM - should also onboard the token type let crossVMTransferResult = executeTransaction( "../transactions/bridge/tokens/bridge_tokens_to_any_evm_address.cdc", - [ exampleTokenAccount.address, "ExampleToken", cadenceBalance, recipient ], + [ exampleTokenIdentifier, cadenceBalance, recipient ], alice ) Test.expect(crossVMTransferResult, Test.beSucceeded()) @@ -973,8 +973,7 @@ fun testPauseBridgeSucceeds() { // Execute bridge to EVM - should fail after pausing bridgeNFTToEVM( signer: alice, - contractAddr: exampleNFTAccount.address, - contractName: "ExampleNFT", + nftIdentifier: exampleNFTIdentifier, nftID: aliceOwnedIDs[0], bridgeAccountAddr: bridgeAccount.address, beFailed: true @@ -1006,8 +1005,7 @@ fun testBridgeCadenceNativeNFTToEVMSucceeds() { // Execute bridge to EVM bridgeNFTToEVM( signer: alice, - contractAddr: exampleNFTAccount.address, - contractName: "ExampleNFT", + nftIdentifier: exampleNFTIdentifier, nftID: aliceOwnedIDs[0], bridgeAccountAddr: bridgeAccount.address, beFailed: false @@ -1052,7 +1050,7 @@ fun testCrossVMTransferCadenceNativeNFTFromEVMSucceeds() { // Execute bridge NFT from EVM to Cadence recipient (Bob in this case) let crossVMTransferResult = executeTransaction( "../transactions/bridge/nft/bridge_nft_to_any_cadence_address.cdc", - [ exampleNFTAccount.address, "ExampleNFT", UInt256(mintedNFTID), bob.address ], + [ exampleNFTIdentifier, UInt256(mintedNFTID), bob.address ], alice ) Test.expect(crossVMTransferResult, Test.beSucceeded()) @@ -1082,8 +1080,7 @@ fun testBridgeCadenceNativeNFTFromEVMSucceeds() { // Execute bridge from EVM bridgeNFTFromEVM( signer: alice, - contractAddr: exampleNFTAccount.address, - contractName: "ExampleNFT", + nftIdentifier: exampleNFTIdentifier, erc721ID: UInt256(mintedNFTID), bridgeAccountAddr: bridgeAccount.address, beFailed: false @@ -1108,9 +1105,11 @@ fun testBridgeEVMNativeNFTFromEVMSucceeds() { bridgeNFTFromEVM( signer: alice, - contractAddr: bridgeAccount.address, - contractName: derivedERC721ContractName, - erc721ID: erc721ID, + nftIdentifier: buildTypeIdentifier( + address: bridgeAccount.address, + contractName: derivedERC721ContractName, + resourceName: "NFT" + ), erc721ID: erc721ID, bridgeAccountAddr: bridgeAccount.address, beFailed: false ) @@ -1152,8 +1151,7 @@ fun testPauseByTypeSucceeds() { // Execute bridge to EVM - should fail after pausing bridgeNFTToEVM( signer: alice, - contractAddr: exampleNFTAccount.address, - contractName: "ExampleNFT", + nftIdentifier: exampleNFTIdentifier, nftID: aliceOwnedIDs[0], bridgeAccountAddr: bridgeAccount.address, beFailed: true @@ -1187,9 +1185,11 @@ fun testBridgeEVMNativeNFTToEVMSucceeds() { bridgeNFTToEVM( signer: alice, - contractAddr: bridgeAccount.address, - contractName: derivedERC721ContractName, - nftID: aliceOwnedIDs[0], + nftIdentifier: buildTypeIdentifier( + address: bridgeAccount.address, + contractName: derivedERC721ContractName, + resourceName: "NFT" + ), nftID: aliceOwnedIDs[0], bridgeAccountAddr: bridgeAccount.address, beFailed: false ) @@ -1214,8 +1214,7 @@ fun testBridgeCadenceNativeTokenToEVMSucceeds() { // Execute bridge to EVM bridgeTokensToEVM( signer: alice, - contractAddr: exampleTokenAccount.address, - contractName: "ExampleToken", + vaultIdentifier: exampleTokenIdentifier, amount: cadenceBalance, beFailed: false ) @@ -1266,7 +1265,7 @@ fun testCrossVMTransferCadenceNativeTokenFromEVMSucceeds() { // Execute bridge tokens from EVM to Cadence recipient (Bob in this case) let crossVMTransferResult = executeTransaction( "../transactions/bridge/tokens/bridge_tokens_to_any_cadence_address.cdc", - [ exampleTokenAccount.address, "ExampleToken", evmBalance, bob.address ], + [ exampleTokenIdentifier, evmBalance, bob.address ], alice ) Test.expect(crossVMTransferResult, Test.beSucceeded()) @@ -1305,8 +1304,7 @@ fun testBridgeCadenceNativeTokenFromEVMSucceeds() { // Execute bridge from EVM bridgeTokensFromEVM( signer: alice, - contractAddr: exampleTokenAccount.address, - contractName: "ExampleToken", + vaultIdentifier: exampleTokenIdentifier, amount: evmBalance, beFailed: false ) @@ -1339,9 +1337,11 @@ fun testBridgeEVMNativeTokenFromEVMSucceeds() { // Execute bridge from EVM bridgeTokensFromEVM( signer: alice, - contractAddr: bridgeAccount.address, - contractName: derivedERC20ContractName, - amount: evmBalance, + vaultIdentifier: buildTypeIdentifier( + address: bridgeAccount.address, + contractName: derivedERC20ContractName, + resourceName: "Vault" + ), amount: evmBalance, beFailed: false ) @@ -1388,9 +1388,11 @@ fun testBridgeEVMNativeTokenToEVMSucceeds() { // Execute bridge from EVM bridgeTokensToEVM( signer: alice, - contractAddr: bridgeAccount.address, - contractName: derivedERC20ContractName, - amount: cadenceBalance, + vaultIdentifier: buildTypeIdentifier( + address: bridgeAccount.address, + contractName: derivedERC20ContractName, + resourceName: "Vault" + ), amount: cadenceBalance, beFailed: false ) diff --git a/cadence/tests/test_helpers.cdc b/cadence/tests/test_helpers.cdc index 3fc5d8d2..e2c3fded 100644 --- a/cadence/tests/test_helpers.cdc +++ b/cadence/tests/test_helpers.cdc @@ -138,6 +138,15 @@ fun getEVMAddressHexFromEvents(_ evts: [AnyStruct], idx: Int): String { return hexAddress } +/* --- Derivation Helpers --- */ + +access(all) +fun buildTypeIdentifier(address: Address, contractName: String, resourceName: String): String { + return "A.".concat(address.toString().split(separator: "x")[1]).concat(".") + .concat(contractName).concat(".") + .concat(resourceName) +} + /* --- Script Helpers --- */ access(all) @@ -367,15 +376,14 @@ fun createCOA(signer: Test.TestAccount, fundingAmount: UFix64) { access(all) fun bridgeNFTToEVM( signer: Test.TestAccount, - contractAddr: Address, - contractName: String, + nftIdentifier: String, nftID: UInt64, bridgeAccountAddr: Address, beFailed: Bool ) { let bridgeResult = _executeTransaction( "../transactions/bridge/nft/bridge_nft_to_evm.cdc", - [contractAddr, contractName, nftID], + [nftIdentifier, nftID], signer ) if beFailed { @@ -399,15 +407,14 @@ fun bridgeNFTToEVM( access(all) fun bridgeNFTFromEVM( signer: Test.TestAccount, - contractAddr: Address, - contractName: String, + nftIdentifier: String, erc721ID: UInt256, bridgeAccountAddr: Address, beFailed: Bool ) { let bridgeResult = _executeTransaction( "../transactions/bridge/nft/bridge_nft_from_evm.cdc", - [contractAddr, contractName, erc721ID], + [nftIdentifier, erc721ID], signer ) if beFailed { @@ -429,14 +436,13 @@ fun bridgeNFTFromEVM( access(all) fun bridgeTokensToEVM( signer: Test.TestAccount, - contractAddr: Address, - contractName: String, + vaultIdentifier: String, amount: UFix64, beFailed: Bool ) { let bridgeResult = _executeTransaction( "../transactions/bridge/tokens/bridge_tokens_to_evm.cdc", - [contractAddr, contractName, amount], + [vaultIdentifier, amount], signer ) Test.expect(bridgeResult, beFailed ? Test.beFailed() : Test.beSucceeded()) @@ -448,14 +454,13 @@ fun bridgeTokensToEVM( access(all) fun bridgeTokensFromEVM( signer: Test.TestAccount, - contractAddr: Address, - contractName: String, + vaultIdentifier: String, amount: UInt256, beFailed: Bool ) { let bridgeResult = _executeTransaction( "../transactions/bridge/tokens/bridge_tokens_from_evm.cdc", - [contractAddr, contractName, amount], + [vaultIdentifier, amount], signer ) Test.expect(bridgeResult, beFailed ? Test.beFailed() : Test.beSucceeded()) diff --git a/cadence/transactions/bridge/nft/bridge_nft_from_evm.cdc b/cadence/transactions/bridge/nft/bridge_nft_from_evm.cdc index 718e2710..01bf3157 100644 --- a/cadence/transactions/bridge/nft/bridge_nft_from_evm.cdc +++ b/cadence/transactions/bridge/nft/bridge_nft_from_evm.cdc @@ -16,11 +16,10 @@ import "FlowEVMBridgeUtils" /// NOTE: The ERC721 must have first been onboarded to the bridge. This can be checked via the method /// FlowEVMBridge.evmAddressRequiresOnboarding(address: self.evmContractAddress) /// -/// @param nftContractAddress: The Flow account address hosting the NFT-defining Cadence contract -/// @param nftContractName: The name of the NFT-defining Cadence contract +/// @param nftIdentifier: The Cadence type identifier of the NFT to bridge - e.g. nft.getType().identifier /// @param id: The ERC721 id of the NFT to bridge to Cadence from EVM /// -transaction(nftContractAddress: Address, nftContractName: String, id: UInt256) { +transaction(nftIdentifier: String, id: UInt256) { let nftType: Type let collection: &{NonFungibleToken.Collection} @@ -34,12 +33,16 @@ transaction(nftContractAddress: Address, nftContractName: String, id: UInt256) { self.coa = signer.storage.borrow(from: /storage/evm) ?? panic("Could not borrow COA from provided gateway address") - // Get the ERC721 contract address for the given NFT type - self.nftType = FlowEVMBridgeUtils.buildCompositeType( - address: nftContractAddress, - contractName: nftContractName, - resourceName: "NFT" - ) ?? panic("Could not construct NFT type") + /* --- Construct the NFT type --- */ + // + // Construct the NFT type from the provided identifier + self.nftType = CompositeType(nftIdentifier) + ?? panic("Could not construct NFT type from identifier: ".concat(nftIdentifier)) + // Parse the NFT identifier into its components + let nftContractAddress = FlowEVMBridgeUtils.getContractAddress(fromType: self.nftType) + ?? panic("Could not get contract address from identifier: ".concat(nftIdentifier)) + let nftContractName = FlowEVMBridgeUtils.getContractName(fromType: self.nftType) + ?? panic("Could not get contract name from identifier: ".concat(nftIdentifier)) /* --- Reference the signer's NFT Collection --- */ // diff --git a/cadence/transactions/bridge/nft/bridge_nft_to_any_cadence_address.cdc b/cadence/transactions/bridge/nft/bridge_nft_to_any_cadence_address.cdc index f0212c1f..63bb9669 100644 --- a/cadence/transactions/bridge/nft/bridge_nft_to_any_cadence_address.cdc +++ b/cadence/transactions/bridge/nft/bridge_nft_to_any_cadence_address.cdc @@ -2,7 +2,6 @@ import "FungibleToken" import "NonFungibleToken" import "ViewResolver" import "MetadataViews" -import "FlowToken" import "ScopedFTProviders" @@ -18,12 +17,11 @@ import "FlowEVMBridgeUtils" /// NOTE: The ERC721 must have first been onboarded to the bridge. This can be checked via the method /// FlowEVMBridge.evmAddressRequiresOnboarding(address: self.evmContractAddress) /// -/// @param nftContractAddress: The Flow account address hosting the NFT-defining Cadence contract -/// @param nftContractName: The name of the NFT-defining Cadence contract +/// @param nftIdentifier: The Cadence type identifier of the NFT to bridge - e.g. nft.getType().identifier /// @param id: The ERC721 id of the NFT to bridge to Cadence from EVM /// @param recipient: The Flow account address to receive the bridged NFT /// -transaction(nftContractAddress: Address, nftContractName: String, id: UInt256, recipient: Address) { +transaction(nftIdentifier: String, id: UInt256, recipient: Address) { let nftType: Type let receiver: &{NonFungibleToken.Receiver} @@ -37,12 +35,16 @@ transaction(nftContractAddress: Address, nftContractName: String, id: UInt256, r self.coa = signer.storage.borrow(from: /storage/evm) ?? panic("Could not borrow COA from provided gateway address") - // Get the ERC721 contract address for the given NFT type - self.nftType = FlowEVMBridgeUtils.buildCompositeType( - address: nftContractAddress, - contractName: nftContractName, - resourceName: "NFT" - ) ?? panic("Could not construct NFT type") + /* --- Construct the NFT type --- */ + // + // Construct the NFT type from the provided identifier + self.nftType = CompositeType(nftIdentifier) + ?? panic("Could not construct NFT type from identifier: ".concat(nftIdentifier)) + // Parse the NFT identifier into its components + let nftContractAddress = FlowEVMBridgeUtils.getContractAddress(fromType: self.nftType) + ?? panic("Could not get contract address from identifier: ".concat(nftIdentifier)) + let nftContractName = FlowEVMBridgeUtils.getContractName(fromType: self.nftType) + ?? panic("Could not get contract name from identifier: ".concat(nftIdentifier)) /* --- Reference the recipient's NFT Receiver --- */ // diff --git a/cadence/transactions/bridge/nft/bridge_nft_to_any_evm_address.cdc b/cadence/transactions/bridge/nft/bridge_nft_to_any_evm_address.cdc index 418b3bc7..858fc713 100644 --- a/cadence/transactions/bridge/nft/bridge_nft_to_any_evm_address.cdc +++ b/cadence/transactions/bridge/nft/bridge_nft_to_any_evm_address.cdc @@ -2,7 +2,6 @@ import "FungibleToken" import "NonFungibleToken" import "ViewResolver" import "MetadataViews" -import "FlowToken" import "ScopedFTProviders" @@ -17,18 +16,28 @@ import "FlowEVMBridgeUtils" /// NOTE: This transaction also onboards the NFT to the bridge if necessary which may incur additional fees /// than bridging an asset that has already been onboarded. /// -/// @param nftContractAddress: The Flow account address hosting the NFT-defining Cadence contract -/// @param nftContractName: The name of the NFT-defining Cadence contract +/// @param nftIdentifier: The Cadence type identifier of the NFT to bridge - e.g. nft.getType().identifier /// @param id: The Cadence NFT.id of the NFT to bridge to EVM /// @param recipient: The hex-encoded EVM address to receive the NFT /// -transaction(nftContractAddress: Address, nftContractName: String, id: UInt64, recipient: String) { +transaction(nftIdentifier: String, id: UInt64, recipient: String) { let nft: @{NonFungibleToken.NFT} let requiresOnboarding: Bool let scopedProvider: @ScopedFTProviders.ScopedFTProvider prepare(signer: auth(CopyValue, BorrowValue, IssueStorageCapabilityController, PublishCapability, SaveValue) &Account) { + /* --- Construct the NFT type --- */ + // + // Construct the NFT type from the provided identifier + let nftType = CompositeType(nftIdentifier) + ?? panic("Could not construct NFT type from identifier: ".concat(nftIdentifier)) + // Parse the NFT identifier into its components + let nftContractAddress = FlowEVMBridgeUtils.getContractAddress(fromType: nftType) + ?? panic("Could not get contract address from identifier: ".concat(nftIdentifier)) + let nftContractName = FlowEVMBridgeUtils.getContractName(fromType: nftType) + ?? panic("Could not get contract name from identifier: ".concat(nftIdentifier)) + /* --- Retrieve the NFT --- */ // // Borrow a reference to the NFT collection, configuring if necessary diff --git a/cadence/transactions/bridge/nft/bridge_nft_to_evm.cdc b/cadence/transactions/bridge/nft/bridge_nft_to_evm.cdc index 22eb23b8..2a18426a 100644 --- a/cadence/transactions/bridge/nft/bridge_nft_to_evm.cdc +++ b/cadence/transactions/bridge/nft/bridge_nft_to_evm.cdc @@ -17,11 +17,10 @@ import "FlowEVMBridgeUtils" /// NOTE: This transaction also onboards the NFT to the bridge if necessary which may incur additional fees /// than bridging an asset that has already been onboarded. /// -/// @param nftContractAddress: The Flow account address hosting the NFT-defining Cadence contract -/// @param nftContractName: The name of the NFT-defining Cadence contract +/// @param nftIdentifier: The Cadence type identifier of the NFT to bridge - e.g. nft.getType().identifier /// @param id: The Cadence NFT.id of the NFT to bridge to EVM /// -transaction(nftContractAddress: Address, nftContractName: String, id: UInt64) { +transaction(nftIdentifier: String, id: UInt64) { let nft: @{NonFungibleToken.NFT} let coa: auth(EVM.Bridge) &EVM.CadenceOwnedAccount @@ -35,13 +34,24 @@ transaction(nftContractAddress: Address, nftContractName: String, id: UInt64) { self.coa = signer.storage.borrow(from: /storage/evm) ?? panic("Could not borrow COA from provided gateway address") + /* --- Construct the NFT type --- */ + // + // Construct the NFT type from the provided identifier + let nftType = CompositeType(nftIdentifier) + ?? panic("Could not construct NFT type from identifier: ".concat(nftIdentifier)) + // Parse the NFT identifier into its components + let nftContractAddress = FlowEVMBridgeUtils.getContractAddress(fromType: nftType) + ?? panic("Could not get contract address from identifier: ".concat(nftIdentifier)) + let nftContractName = FlowEVMBridgeUtils.getContractName(fromType: nftType) + ?? panic("Could not get contract name from identifier: ".concat(nftIdentifier)) + /* --- Retrieve the NFT --- */ // // Borrow a reference to the NFT collection, configuring if necessary let viewResolver = getAccount(nftContractAddress).contracts.borrow<&{ViewResolver}>(name: nftContractName) ?? panic("Could not borrow ViewResolver from NFT contract") let collectionData = viewResolver.resolveContractView( - resourceType: nil, + resourceType: nftType, viewType: Type() ) as! MetadataViews.NFTCollectionData? ?? panic("Could not resolve NFTCollectionData view") let collection = signer.storage.borrow( diff --git a/cadence/transactions/bridge/tokens/bridge_tokens_from_evm.cdc b/cadence/transactions/bridge/tokens/bridge_tokens_from_evm.cdc index a92bbced..33e099c1 100644 --- a/cadence/transactions/bridge/tokens/bridge_tokens_from_evm.cdc +++ b/cadence/transactions/bridge/tokens/bridge_tokens_from_evm.cdc @@ -18,11 +18,11 @@ import "FlowEVMBridgeUtils" /// NOTE: The ERC721 must have first been onboarded to the bridge. This can be checked via the method /// FlowEVMBridge.evmAddressRequiresOnboarding(address: self.evmContractAddress) /// -/// @param tokenContractAddress: The Flow account address hosting the FT-defining Cadence contract -/// @param tokenContractName: The name of the Vault-defining Cadence contract +/// @param vaultIdentifier: The Cadence type identifier of the FungibleToken Vault to bridge +/// - e.g. vault.getType().identifier /// @param amount: The amount of tokens to bridge from EVM /// -transaction(tokenContractAddress: Address, tokenContractName: String, amount: UInt256) { +transaction(vaultIdentifier: String, amount: UInt256) { let vaultType: Type let receiver: &{FungibleToken.Vault} @@ -36,12 +36,16 @@ transaction(tokenContractAddress: Address, tokenContractName: String, amount: UI self.coa = signer.storage.borrow(from: /storage/evm) ?? panic("Could not borrow COA from provided gateway address") - // Get the ERC20 contract address for the given FungibleToken Vault type - self.vaultType = FlowEVMBridgeUtils.buildCompositeType( - address: tokenContractAddress, - contractName: tokenContractName, - resourceName: "Vault" - ) ?? panic("Could not construct Vault type of: " .concat(tokenContractAddress.toString()).concat(".").concat(tokenContractName).concat(".Vault")) + /* --- Construct the Vault type --- */ + // + // Construct the Vault type from the provided identifier + self.vaultType = CompositeType(vaultIdentifier) + ?? panic("Could not construct Vault type from identifier: ".concat(vaultIdentifier)) + // Parse the Vault identifier into its components + let tokenContractAddress = FlowEVMBridgeUtils.getContractAddress(fromType: self.vaultType) + ?? panic("Could not get contract address from identifier: ".concat(vaultIdentifier)) + let tokenContractName = FlowEVMBridgeUtils.getContractName(fromType: self.vaultType) + ?? panic("Could not get contract name from identifier: ".concat(vaultIdentifier)) /* --- Reference the signer's Vault --- */ // diff --git a/cadence/transactions/bridge/tokens/bridge_tokens_to_any_cadence_address.cdc b/cadence/transactions/bridge/tokens/bridge_tokens_to_any_cadence_address.cdc index e3c0ff06..038e0094 100644 --- a/cadence/transactions/bridge/tokens/bridge_tokens_to_any_cadence_address.cdc +++ b/cadence/transactions/bridge/tokens/bridge_tokens_to_any_cadence_address.cdc @@ -20,12 +20,12 @@ import "FlowEVMBridgeUtils" /// NOTE: The ERC20 must have first been onboarded to the bridge. This can be checked via the method /// FlowEVMBridge.evmAddressRequiresOnboarding(address: self.evmContractAddress) /// -/// @param tokenContractAddress: The Flow account address hosting the FT-defining Cadence contract -/// @param tokenContractName: The name of the Vault-defining Cadence contract -/// @param amount: The amount of tokens to bridge from EVM +/// @param vaultIdentifier: The Cadence type identifier of the FungibleToken Vault to bridge +/// - e.g. vault.getType().identifier +/// @param amount: The amount of tokens to bridge from EVM and transfer to the recipient /// @param recipient: The Flow account address to receive the bridged tokens /// -transaction(tokenContractAddress: Address, tokenContractName: String, amount: UInt256, recipient: Address) { +transaction(vaultIdentifier: String, amount: UInt256, recipient: Address) { let vaultType: Type let receiver: &{FungibleToken.Receiver} @@ -39,12 +39,16 @@ transaction(tokenContractAddress: Address, tokenContractName: String, amount: UI self.coa = signer.storage.borrow(from: /storage/evm) ?? panic("Could not borrow COA from provided gateway address") - // Get the ERC20 contract address for the given FungibleToken Vault type - self.vaultType = FlowEVMBridgeUtils.buildCompositeType( - address: tokenContractAddress, - contractName: tokenContractName, - resourceName: "Vault" - ) ?? panic("Could not construct Vault type of: " .concat(tokenContractAddress.toString()).concat(".").concat(tokenContractName).concat(".Vault")) + /* --- Construct the Vault type --- */ + // + // Construct the Vault type from the provided identifier + self.vaultType = CompositeType(vaultIdentifier) + ?? panic("Could not construct Vault type from identifier: ".concat(vaultIdentifier)) + // Parse the Vault identifier into its components + let tokenContractAddress = FlowEVMBridgeUtils.getContractAddress(fromType: self.vaultType) + ?? panic("Could not get contract address from identifier: ".concat(vaultIdentifier)) + let tokenContractName = FlowEVMBridgeUtils.getContractName(fromType: self.vaultType) + ?? panic("Could not get contract name from identifier: ".concat(vaultIdentifier)) /* --- Reference the signer's Vault --- */ // diff --git a/cadence/transactions/bridge/tokens/bridge_tokens_to_any_evm_address.cdc b/cadence/transactions/bridge/tokens/bridge_tokens_to_any_evm_address.cdc index 4a45784d..69c7de0c 100644 --- a/cadence/transactions/bridge/tokens/bridge_tokens_to_any_evm_address.cdc +++ b/cadence/transactions/bridge/tokens/bridge_tokens_to_any_evm_address.cdc @@ -18,18 +18,29 @@ import "FlowEVMBridgeConfig" /// NOTE: The Vault being bridged must have first been onboarded to the bridge. This can be checked for with the method /// FlowEVMBridge.typeRequiresOnboarding(type): Bool? /// -/// @param tokenContractAddress: The Flow account address hosting the FT-defining Cadence contract -/// @param tokenContractName: The name of the Vault-defining Cadence contract -/// @param amount: The amount of tokens to bridge from EVM +/// @param vaultIdentifier: The Cadence type identifier of the FungibleToken Vault to bridge +/// - e.g. vault.getType().identifier +/// @param amount: The amount of tokens to bridge from Cadence to the named recipient in EVM /// @param recipient: The hex-encoded EVM address to send the tokens to /// -transaction(tokenContractAddress: Address, tokenContractName: String, amount: UFix64, recipient: String) { +transaction(vaultIdentifier: String, amount: UFix64, recipient: String) { let sentVault: @{FungibleToken.Vault} let requiresOnboarding: Bool let scopedProvider: @ScopedFTProviders.ScopedFTProvider prepare(signer: auth(CopyValue, BorrowValue, IssueStorageCapabilityController, PublishCapability, SaveValue) &Account) { + /* --- Construct the Vault type --- */ + // + // Construct the Vault type from the provided identifier + let vaultType = CompositeType(vaultIdentifier) + ?? panic("Could not construct Vault type from identifier: ".concat(vaultIdentifier)) + // Parse the Vault identifier into its components + let tokenContractAddress = FlowEVMBridgeUtils.getContractAddress(fromType: vaultType) + ?? panic("Could not get contract address from identifier: ".concat(vaultIdentifier)) + let tokenContractName = FlowEVMBridgeUtils.getContractName(fromType: vaultType) + ?? panic("Could not get contract name from identifier: ".concat(vaultIdentifier)) + /* --- Retrieve the funds --- */ // // Borrow a reference to the FungibleToken Vault diff --git a/cadence/transactions/bridge/tokens/bridge_tokens_to_evm.cdc b/cadence/transactions/bridge/tokens/bridge_tokens_to_evm.cdc index 6ba68244..0938b341 100644 --- a/cadence/transactions/bridge/tokens/bridge_tokens_to_evm.cdc +++ b/cadence/transactions/bridge/tokens/bridge_tokens_to_evm.cdc @@ -16,11 +16,11 @@ import "FlowEVMBridgeUtils" /// NOTE: This transaction also onboards the Vault to the bridge if necessary which may incur additional fees /// than bridging an asset that has already been onboarded. /// -/// @param tokenContractAddress: The Flow account address hosting the FT-defining Cadence contract -/// @param tokenContractName: The name of the Vault-defining Cadence contract +/// @param vaultIdentifier: The Cadence type identifier of the FungibleToken Vault to bridge +/// - e.g. vault.getType().identifier /// @param amount: The amount of tokens to bridge from EVM /// -transaction(tokenContractAddress: Address, tokenContractName: String, amount: UFix64) { +transaction(vaultIdentifier: String, amount: UFix64) { let sentVault: @{FungibleToken.Vault} let coa: auth(EVM.Bridge) &EVM.CadenceOwnedAccount @@ -34,13 +34,24 @@ transaction(tokenContractAddress: Address, tokenContractName: String, amount: UF self.coa = signer.storage.borrow(from: /storage/evm) ?? panic("Could not borrow COA from provided gateway address") + /* --- Construct the Vault type --- */ + // + // Construct the Vault type from the provided identifier + let vaultType = CompositeType(vaultIdentifier) + ?? panic("Could not construct Vault type from identifier: ".concat(vaultIdentifier)) + // Parse the Vault identifier into its components + let tokenContractAddress = FlowEVMBridgeUtils.getContractAddress(fromType: vaultType) + ?? panic("Could not get contract address from identifier: ".concat(vaultIdentifier)) + let tokenContractName = FlowEVMBridgeUtils.getContractName(fromType: vaultType) + ?? panic("Could not get contract name from identifier: ".concat(vaultIdentifier)) + /* --- Retrieve the funds --- */ // // Borrow a reference to the FungibleToken Vault let viewResolver = getAccount(tokenContractAddress).contracts.borrow<&{ViewResolver}>(name: tokenContractName) ?? panic("Could not borrow ViewResolver from FungibleToken contract") let vaultData = viewResolver.resolveContractView( - resourceType: nil, + resourceType: vaultType, viewType: Type() ) as! FungibleTokenMetadataViews.FTVaultData? ?? panic("Could not resolve FTVaultData view") let vault = signer.storage.borrow(