From 34fa385a86a8a5ea434ceaf081e9d0d4c47c7d46 Mon Sep 17 00:00:00 2001 From: Giovanni Sanchez <108043524+sisyphusSmiling@users.noreply.github.com> Date: Thu, 13 Jun 2024 17:20:43 -0600 Subject: [PATCH] remove EVMUtils & implementations --- cadence/contracts/bridge/FlowEVMBridge.cdc | 5 ++- .../contracts/bridge/FlowEVMBridgeConfig.cdc | 16 ++++----- .../bridge/FlowEVMBridgeHandlers.cdc | 1 - .../contracts/bridge/FlowEVMBridgeUtils.cdc | 8 ++--- .../bridge/interfaces/IFlowEVMNFTBridge.cdc | 19 +++++------ .../bridge/interfaces/IFlowEVMTokenBridge.cdc | 20 +++++------ cadence/contracts/utils/EVMUtils.cdc | 34 ------------------- .../batch_evm_address_requires_onboarding.cdc | 10 +++--- .../evm_address_requires_onboarding.cdc | 9 +++-- .../bridge/get_associated_evm_address.cdc | 3 +- .../scripts/bridge/get_associated_type.cdc | 5 ++- .../scripts/bridge/get_bridge_coa_address.cdc | 4 +-- .../evm/get_evm_address_string_from_bytes.cdc | 12 +------ cadence/scripts/utils/balance_of.cdc | 13 +++---- .../derive_bridged_nft_contract_name.cdc | 3 +- .../derive_bridged_token_contract_name.cdc | 3 +- .../utils/get_evm_address_from_hex.cdc | 4 +-- cadence/scripts/utils/get_factory_address.cdc | 4 +-- cadence/scripts/utils/get_token_decimals.cdc | 6 ++-- cadence/scripts/utils/is_owner.cdc | 13 +++---- .../scripts/utils/is_owner_or_approved.cdc | 13 +++---- cadence/scripts/utils/token_uri.cdc | 7 ++-- cadence/scripts/utils/total_supply.cdc | 7 ++-- .../tests/flow_evm_bridge_handler_tests.cdc | 6 ---- cadence/tests/flow_evm_bridge_tests.cdc | 6 ---- cadence/tests/flow_evm_bridge_utils_tests.cdc | 6 ---- .../bridge/admin/evm/add_deployer.cdc | 6 ++-- .../admin/evm/set_delegated_deployer.cdc | 6 ++-- .../admin/evm/set_deployment_registry.cdc | 6 ++-- .../bridge/admin/evm/set_registrar.cdc | 4 +-- .../token-handler/enable_token_handler.cdc | 1 - .../set_handler_target_evm_address.cdc | 4 +-- .../batch_onboard_by_evm_address.cdc | 5 ++- .../onboarding/onboard_by_evm_address.cdc | 7 ++-- .../evm/transfer_flow_to_evm_address.cdc | 5 +-- .../example-assets/evm-assets/mint_erc20.cdc | 8 ++--- .../evm-assets/safe_mint_erc721.cdc | 8 ++--- .../evm-assets/safe_transfer_from_erc721.cdc | 5 ++- .../evm-assets/transfer_erc20.cdc | 5 ++- .../flow-token/dynamic_vm_transfer.cdc | 4 +-- flow.json | 13 ------- main.go | 1 - 42 files changed, 91 insertions(+), 234 deletions(-) delete mode 100644 cadence/contracts/utils/EVMUtils.cdc diff --git a/cadence/contracts/bridge/FlowEVMBridge.cdc b/cadence/contracts/bridge/FlowEVMBridge.cdc index 3199bb23..ba531058 100644 --- a/cadence/contracts/bridge/FlowEVMBridge.cdc +++ b/cadence/contracts/bridge/FlowEVMBridge.cdc @@ -8,7 +8,6 @@ import "FlowToken" import "EVM" -import "EVMUtils" import "IBridgePermissions" import "ICrossVM" import "IEVMBridgeNFTMinter" @@ -121,7 +120,7 @@ contract FlowEVMBridge : IFlowEVMNFTBridge, IFlowEVMTokenBridge { emit Onboarded( type: type, cadenceContractAddress: FlowEVMBridgeUtils.getContractAddress(fromType: type)!, - evmContractAddress: EVMUtils.getEVMAddressAsHexString(address: onboardingValues.evmContractAddress) + evmContractAddress: onboardingValues.evmContractAddress.toString() ) } @@ -659,7 +658,7 @@ contract FlowEVMBridge : IFlowEVMNFTBridge, IFlowEVMTokenBridge { assetName: evmOnboardingValues.name, symbol: evmOnboardingValues.symbol, isERC721: evmOnboardingValues.isERC721, - evmContractAddress: EVMUtils.getEVMAddressAsHexString(address: evmContractAddress) + evmContractAddress: evmContractAddress.toString() ) } } diff --git a/cadence/contracts/bridge/FlowEVMBridgeConfig.cdc b/cadence/contracts/bridge/FlowEVMBridgeConfig.cdc index 32c2edd3..f48ae20c 100644 --- a/cadence/contracts/bridge/FlowEVMBridgeConfig.cdc +++ b/cadence/contracts/bridge/FlowEVMBridgeConfig.cdc @@ -2,7 +2,6 @@ import "EVM" import "FlowToken" -import "EVMUtils" import "FlowEVMBridgeHandlerInterfaces" /// This contract is used to store configuration information shared by FlowEVMBridge contracts @@ -99,7 +98,7 @@ contract FlowEVMBridgeConfig { /// access(all) view fun getTypeAssociated(with evmAddress: EVM.EVMAddress): Type? { - let evmAddressHex = EVMUtils.getEVMAddressAsHexString(address: evmAddress) + let evmAddressHex = evmAddress.toString() return self.evmAddressHexToType[evmAddressHex] } @@ -112,7 +111,7 @@ contract FlowEVMBridgeConfig { access(account) fun associateType(_ type: Type, with evmAddress: EVM.EVMAddress) { self.typeToEVMAddress[type] = evmAddress - let evmAddressHex = EVMUtils.getEVMAddressAsHexString(address: evmAddress) + let evmAddressHex = evmAddress.toString() self.evmAddressHexToType[evmAddressHex] = type } @@ -145,7 +144,7 @@ contract FlowEVMBridgeConfig { let type = handler.getTargetType()! var targetEVMAddressHex: String? = nil if let targetEVMAddress = handler.getTargetEVMAddress() { - targetEVMAddressHex = EVMUtils.getEVMAddressAsHexString(address: targetEVMAddress) + targetEVMAddressHex = targetEVMAddress.toString() let associatedType = self.getTypeAssociated(with: targetEVMAddress) assert( @@ -285,7 +284,7 @@ contract FlowEVMBridgeConfig { emit HandlerConfigured( targetType: targetType, - targetEVMAddress: EVMUtils.getEVMAddressAsHexString(address: targetEVMAddress), + targetEVMAddress: targetEVMAddress.toString(), isEnabled: handler.isEnabled() ) } @@ -303,9 +302,8 @@ contract FlowEVMBridgeConfig { ?? panic("No handler found for target Type") handler.enableBridging() - let targetEVMAddressHex = EVMUtils.getEVMAddressAsHexString( - address: handler.getTargetEVMAddress() ?? panic("Handler cannot be enabled without a target EVM Address") - ) + let targetEVMAddressHex = handler.getTargetEVMAddress()?.toString() + ?? panic("Handler cannot be enabled without a target EVM Address") emit HandlerConfigured( targetType: handler.getTargetType()!, @@ -328,7 +326,7 @@ contract FlowEVMBridgeConfig { bytes: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0] ) let flowVaultType = Type<@FlowToken.Vault>() - let flowOriginationAddressHex = EVMUtils.getEVMAddressAsHexString(address: flowOriginationAddress) + let flowOriginationAddressHex = flowOriginationAddress.toString() self.typeToEVMAddress = { flowVaultType: flowOriginationAddress } self.evmAddressHexToType = { flowOriginationAddressHex: flowVaultType } diff --git a/cadence/contracts/bridge/FlowEVMBridgeHandlers.cdc b/cadence/contracts/bridge/FlowEVMBridgeHandlers.cdc index 415e2fcc..ebe1e9a8 100644 --- a/cadence/contracts/bridge/FlowEVMBridgeHandlers.cdc +++ b/cadence/contracts/bridge/FlowEVMBridgeHandlers.cdc @@ -4,7 +4,6 @@ import "NonFungibleToken" import "EVM" -import "EVMUtils" import "FlowEVMBridgeHandlerInterfaces" import "FlowEVMBridgeConfig" import "FlowEVMBridgeUtils" diff --git a/cadence/contracts/bridge/FlowEVMBridgeUtils.cdc b/cadence/contracts/bridge/FlowEVMBridgeUtils.cdc index 30ad1c25..508823e5 100644 --- a/cadence/contracts/bridge/FlowEVMBridgeUtils.cdc +++ b/cadence/contracts/bridge/FlowEVMBridgeUtils.cdc @@ -8,7 +8,6 @@ import "FlowStorageFees" import "EVM" -import "EVMUtils" import "SerializeMetadata" import "FlowEVMBridgeConfig" import "CrossVMNFT" @@ -761,7 +760,7 @@ contract FlowEVMBridgeUtils { view fun deriveBridgedNFTContractName(from evmContract: EVM.EVMAddress): String { return self.contractNamePrefixes[Type<@{NonFungibleToken.NFT}>()]!["bridged"]! .concat(self.delimiter) - .concat("0x".concat(EVMUtils.getEVMAddressAsHexString(address: evmContract))) + .concat(evmContract.toString()) } /// Derives the Cadence contract name for a given EVM fungible token of the form @@ -775,7 +774,7 @@ contract FlowEVMBridgeUtils { view fun deriveBridgedTokenContractName(from evmContract: EVM.EVMAddress): String { return self.contractNamePrefixes[Type<@{FungibleToken.Vault}>()]!["bridged"]! .concat(self.delimiter) - .concat("0x".concat(EVMUtils.getEVMAddressAsHexString(address: evmContract))) + .concat(evmContract.toString()) } /**************** @@ -1283,7 +1282,6 @@ contract FlowEVMBridgeUtils { "bridged": "EVMVMBridgedToken" } } - self.bridgeFactoryEVMAddress = EVMUtils.getEVMAddressFromHexString(address: bridgeFactoryAddressHex.toLower()) - ?? panic("Invalid EVM address hex: ".concat(bridgeFactoryAddressHex)) + self.bridgeFactoryEVMAddress = EVM.addressFromString(bridgeFactoryAddressHex.toLower()) } } diff --git a/cadence/contracts/bridge/interfaces/IFlowEVMNFTBridge.cdc b/cadence/contracts/bridge/interfaces/IFlowEVMNFTBridge.cdc index c7e34b7f..7cbad77c 100644 --- a/cadence/contracts/bridge/interfaces/IFlowEVMNFTBridge.cdc +++ b/cadence/contracts/bridge/interfaces/IFlowEVMNFTBridge.cdc @@ -3,7 +3,6 @@ import "NonFungibleToken" import "EVM" -import "EVMUtils" import "FlowEVMBridgeConfig" import "CrossVMNFT" @@ -69,11 +68,10 @@ access(all) contract interface IFlowEVMNFTBridge { type: token.getType(), id: token.id, evmID: CrossVMNFT.getEVMID(from: &token as &{NonFungibleToken.NFT}) ?? UInt256(token.id), - to: EVMUtils.getEVMAddressAsHexString(address: to), - evmContractAddress: EVMUtils.getEVMAddressAsHexString( - address: self.getAssociatedEVMAddress(with: token.getType()) - ?? panic("Could not find EVM Contract address associated with provided NFT") - ), bridgeAddress: self.account.address + to: to.toString(), + evmContractAddress: self.getAssociatedEVMAddress(with: token.getType())?.toString() + ?? panic("Could not find EVM Contract address associated with provided NFT"), + bridgeAddress: self.account.address ) } } @@ -104,11 +102,10 @@ access(all) contract interface IFlowEVMNFTBridge { type: result.getType(), id: result.id, evmID: id, - caller: EVMUtils.getEVMAddressAsHexString(address: owner), - evmContractAddress: EVMUtils.getEVMAddressAsHexString( - address: self.getAssociatedEVMAddress(with: result.getType()) - ?? panic("Could not find EVM Contract address associated with provided NFT") - ), bridgeAddress: self.account.address + caller: owner.toString(), + evmContractAddress: self.getAssociatedEVMAddress(with: result.getType())?.toString() + ?? panic("Could not find EVM Contract address associated with provided NFT"), + bridgeAddress: self.account.address ) } } diff --git a/cadence/contracts/bridge/interfaces/IFlowEVMTokenBridge.cdc b/cadence/contracts/bridge/interfaces/IFlowEVMTokenBridge.cdc index 849790bb..4397c0b4 100644 --- a/cadence/contracts/bridge/interfaces/IFlowEVMTokenBridge.cdc +++ b/cadence/contracts/bridge/interfaces/IFlowEVMTokenBridge.cdc @@ -3,8 +3,6 @@ import "NonFungibleToken" import "EVM" -import "EVMUtils" - access(all) contract interface IFlowEVMTokenBridge { /************* @@ -64,11 +62,10 @@ access(all) contract interface IFlowEVMTokenBridge { emit BridgedTokensToEVM( type: vault.getType(), amount: vault.balance, - to: EVMUtils.getEVMAddressAsHexString(address: to), - evmContractAddress: EVMUtils.getEVMAddressAsHexString( - address: self.getAssociatedEVMAddress(with: vault.getType()) - ?? panic("Could not find EVM Contract address associated with provided NFT") - ), bridgeAddress: self.account.address + to: to.toString(), + evmContractAddress: self.getAssociatedEVMAddress(with: vault.getType())?.toString() + ?? panic("Could not find EVM Contract address associated with provided NFT"), + bridgeAddress: self.account.address ) } } @@ -98,11 +95,10 @@ access(all) contract interface IFlowEVMTokenBridge { emit BridgedTokensFromEVM( type: result.getType(), amount: amount, - caller: EVMUtils.getEVMAddressAsHexString(address: owner), - evmContractAddress: EVMUtils.getEVMAddressAsHexString( - address: self.getAssociatedEVMAddress(with: result.getType()) - ?? panic("Could not find EVM Contract address associated with provided Vault") - ), bridgeAddress: self.account.address + caller: owner.toString(), + evmContractAddress: self.getAssociatedEVMAddress(with: result.getType())?.toString() + ?? panic("Could not find EVM Contract address associated with provided Vault"), + bridgeAddress: self.account.address ) } } diff --git a/cadence/contracts/utils/EVMUtils.cdc b/cadence/contracts/utils/EVMUtils.cdc deleted file mode 100644 index c4635daa..00000000 --- a/cadence/contracts/utils/EVMUtils.cdc +++ /dev/null @@ -1,34 +0,0 @@ -import "EVM" - -/// Contract containing EVM-related utility methods -/// -access(all) contract EVMUtils { - /// Returns an EVMAddress as a hex string without a 0x prefix - /// - /// @param address: The EVMAddress to convert to a hex string - /// - /// @return The hex string representation of the EVMAddress without 0x prefix - /// - // TODO: Remove once EVMAddress.toString() is available - access(all) - view fun getEVMAddressAsHexString(address: EVM.EVMAddress): String { - return String.encodeHex(address.bytes.toVariableSized()) - } - - /// Returns an EVMAddress as a hex string without a 0x prefix, truncating the string's last 20 bytes if exceeded - /// - /// @param address: The hex string to convert to an EVMAddress without the 0x prefix - /// - /// @return The EVMAddress representation of the hex string - /// - access(all) - fun getEVMAddressFromHexString(address: String): EVM.EVMAddress? { - pre { - address.length == 40 || address.length == 42: "Invalid hex string length" - } - // Strip the 0x prefix if it exists - var withoutPrefix = (address[1] == "x" ? address.slice(from: 2, upTo: address.length) : address).toLower() - let bytes = withoutPrefix.decodeHex().toConstantSized<[UInt8;20]>()! - return EVM.EVMAddress(bytes: bytes) - } -} diff --git a/cadence/scripts/bridge/batch_evm_address_requires_onboarding.cdc b/cadence/scripts/bridge/batch_evm_address_requires_onboarding.cdc index 3f464219..ed62231e 100644 --- a/cadence/scripts/bridge/batch_evm_address_requires_onboarding.cdc +++ b/cadence/scripts/bridge/batch_evm_address_requires_onboarding.cdc @@ -1,4 +1,5 @@ -import "EVMUtils" +import "EVM" + import "FlowEVMBridge" /// Returns whether a EVM contract needs to be onboarded to the FlowEVMBridge @@ -15,10 +16,9 @@ access(all) fun main(evmAddresses: [String]): {String: Bool?} { if results[addressHex] != nil { continue } - if let address = EVMUtils.getEVMAddressFromHexString(address: addressHex) { - let requiresOnboarding = FlowEVMBridge.evmAddressRequiresOnboarding(address) - results.insert(key: addressHex, requiresOnboarding) - } + let address = EVM.addressFromString(addressHex) + let requiresOnboarding = FlowEVMBridge.evmAddressRequiresOnboarding(address) + results.insert(key: addressHex, requiresOnboarding) } return results } diff --git a/cadence/scripts/bridge/evm_address_requires_onboarding.cdc b/cadence/scripts/bridge/evm_address_requires_onboarding.cdc index 0affdae9..2ef39036 100644 --- a/cadence/scripts/bridge/evm_address_requires_onboarding.cdc +++ b/cadence/scripts/bridge/evm_address_requires_onboarding.cdc @@ -1,4 +1,5 @@ -import "EVMUtils" +import "EVM" + import "FlowEVMBridge" /// Returns whether a EVM contract needs to be onboarded to the FlowEVMBridge @@ -8,8 +9,6 @@ import "FlowEVMBridge" /// @return Whether the contract requires onboarding to the FlowEVMBridge if the type is bridgeable, otherwise nil /// access(all) fun main(evmAddressHex: String): Bool? { - if let address = EVMUtils.getEVMAddressFromHexString(address: evmAddressHex) { - return FlowEVMBridge.evmAddressRequiresOnboarding(address) - } - return nil + let address = EVM.addressFromString(evmAddressHex) + return FlowEVMBridge.evmAddressRequiresOnboarding(address) } diff --git a/cadence/scripts/bridge/get_associated_evm_address.cdc b/cadence/scripts/bridge/get_associated_evm_address.cdc index 89ad1f17..e5654895 100644 --- a/cadence/scripts/bridge/get_associated_evm_address.cdc +++ b/cadence/scripts/bridge/get_associated_evm_address.cdc @@ -1,6 +1,5 @@ import "EVM" -import "EVMUtils" import "FlowEVMBridgeConfig" /// Returns the EVM address associated with the given Cadence type (as its identifier String) @@ -13,7 +12,7 @@ access(all) fun main(identifier: String): String? { if let type = CompositeType(identifier) { if let address = FlowEVMBridgeConfig.getEVMAddressAssociated(with: type) { - return EVMUtils.getEVMAddressAsHexString(address: address) + return address.toString() } } return nil diff --git a/cadence/scripts/bridge/get_associated_type.cdc b/cadence/scripts/bridge/get_associated_type.cdc index 52520f03..1806189b 100644 --- a/cadence/scripts/bridge/get_associated_type.cdc +++ b/cadence/scripts/bridge/get_associated_type.cdc @@ -1,6 +1,5 @@ import "EVM" -import "EVMUtils" import "FlowEVMBridgeConfig" /// Returns the Cadence Type associated with the given EVM address (as its hex String) @@ -12,6 +11,6 @@ import "FlowEVMBridgeConfig" /// access(all) fun main(addressHex: String): Type? { - let address = EVMUtils.getEVMAddressFromHexString(address: addressHex) - return address != nil ? FlowEVMBridgeConfig.getTypeAssociated(with: address!) : nil + let address = EVM.addressFromString(addressHex) + return FlowEVMBridgeConfig.getTypeAssociated(with: address) } diff --git a/cadence/scripts/bridge/get_bridge_coa_address.cdc b/cadence/scripts/bridge/get_bridge_coa_address.cdc index 4a2d26cc..411c67c6 100644 --- a/cadence/scripts/bridge/get_bridge_coa_address.cdc +++ b/cadence/scripts/bridge/get_bridge_coa_address.cdc @@ -1,6 +1,5 @@ import "EVM" -import "EVMUtils" import "FlowEVMBridge" /// Returns the EVM address associated with the FlowEVMBridge @@ -8,6 +7,5 @@ import "FlowEVMBridge" /// @return The EVM address associated with the FlowEVMBridge's coordinating CadenceOwnedAccount /// access(all) fun main(): String { - let address: EVM.EVMAddress = FlowEVMBridge.getBridgeCOAEVMAddress() - return EVMUtils.getEVMAddressAsHexString(address: address) + return FlowEVMBridge.getBridgeCOAEVMAddress().toString() } \ No newline at end of file diff --git a/cadence/scripts/evm/get_evm_address_string_from_bytes.cdc b/cadence/scripts/evm/get_evm_address_string_from_bytes.cdc index 279f5248..74d04f65 100644 --- a/cadence/scripts/evm/get_evm_address_string_from_bytes.cdc +++ b/cadence/scripts/evm/get_evm_address_string_from_bytes.cdc @@ -1,17 +1,7 @@ import "EVM" -import "EVMUtils" - /// Converts EVM address bytes into to a hex string /// access(all) fun main(bytes: [UInt8]): String? { - let address = EVM.EVMAddress( - bytes: [ - bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], - bytes[5], bytes[6], bytes[7], bytes[8], bytes[9], - bytes[10], bytes[11], bytes[12], bytes[13], bytes[14], - bytes[15], bytes[16], bytes[17], bytes[18], bytes[19] - ] - ) - return EVMUtils.getEVMAddressAsHexString(address: address) + return EVM.EVMAddress(bytes: bytes.toConstantSized<[UInt8; 20]>()) } diff --git a/cadence/scripts/utils/balance_of.cdc b/cadence/scripts/utils/balance_of.cdc index 29069a45..a1838ee0 100644 --- a/cadence/scripts/utils/balance_of.cdc +++ b/cadence/scripts/utils/balance_of.cdc @@ -1,22 +1,19 @@ import "EVM" -import "EVMUtils" import "FlowEVMBridgeUtils" -/// Returns the balance of the owner (hex-encoded EVM address - minus 0x prefix) of a given ERC20 fungible token defined +/// Returns the balance of the owner (hex-encoded EVM address) of a given ERC20 fungible token defined /// at the hex-encoded EVM contract address /// -/// @param owner: The hex-encoded EVM address of the owner without the 0x prefix -/// @param evmContractAddress: The hex-encoded EVM contract address of the ERC20 contract without the 0x prefix +/// @param owner: The hex-encoded EVM address of the owner +/// @param evmContractAddress: The hex-encoded EVM contract address of the ERC20 contract /// /// @return The balance of the address, reverting if the given contract address does not implement the ERC20 method /// "balanceOf(address)(uint256)" /// access(all) fun main(owner: String, evmContractAddress: String): UInt256 { return FlowEVMBridgeUtils.balanceOf( - owner: EVMUtils.getEVMAddressFromHexString(address: owner) - ?? panic("Invalid owner address"), - evmContractAddress: EVMUtils.getEVMAddressFromHexString(address: evmContractAddress) - ?? panic("Invalid EVM contract address") + owner: EVM.addressFromString(owner), + evmContractAddress: EVM.addressFromString(evmContractAddress) ) } diff --git a/cadence/scripts/utils/derive_bridged_nft_contract_name.cdc b/cadence/scripts/utils/derive_bridged_nft_contract_name.cdc index bae8dcd1..1dd808db 100644 --- a/cadence/scripts/utils/derive_bridged_nft_contract_name.cdc +++ b/cadence/scripts/utils/derive_bridged_nft_contract_name.cdc @@ -1,11 +1,10 @@ import "EVM" -import "EVMUtils" import "FlowEVMBridgeUtils" access(all) fun main(evmAddressHex: String): String { return FlowEVMBridgeUtils.deriveBridgedNFTContractName( - from: EVMUtils.getEVMAddressFromHexString(address: evmAddressHex) ?? panic("Could not parse EVM address from hex string") + from: EVM.addressFromString(evmAddressHex) ) } diff --git a/cadence/scripts/utils/derive_bridged_token_contract_name.cdc b/cadence/scripts/utils/derive_bridged_token_contract_name.cdc index 2f194d09..defbbe6b 100644 --- a/cadence/scripts/utils/derive_bridged_token_contract_name.cdc +++ b/cadence/scripts/utils/derive_bridged_token_contract_name.cdc @@ -1,11 +1,10 @@ import "EVM" -import "EVMUtils" import "FlowEVMBridgeUtils" access(all) fun main(evmAddressHex: String): String { return FlowEVMBridgeUtils.deriveBridgedTokenContractName( - from: EVMUtils.getEVMAddressFromHexString(address: evmAddressHex) ?? panic("Could not parse EVM address from hex string") + from: EVM.addressFromString(evmAddressHex) ) } diff --git a/cadence/scripts/utils/get_evm_address_from_hex.cdc b/cadence/scripts/utils/get_evm_address_from_hex.cdc index b58ac9e0..3194ef68 100644 --- a/cadence/scripts/utils/get_evm_address_from_hex.cdc +++ b/cadence/scripts/utils/get_evm_address_from_hex.cdc @@ -1,8 +1,6 @@ import "EVM" -import "EVMUtils" - access(all) fun main(hex: String): EVM.EVMAddress? { - return EVMUtils.getEVMAddressFromHexString(address: hex) + return EVM.addressFromString(hex) } \ No newline at end of file diff --git a/cadence/scripts/utils/get_factory_address.cdc b/cadence/scripts/utils/get_factory_address.cdc index 810eb1ce..dc9773cd 100644 --- a/cadence/scripts/utils/get_factory_address.cdc +++ b/cadence/scripts/utils/get_factory_address.cdc @@ -1,7 +1,5 @@ import "EVM" -import "EVMUtils" - import "FlowEVMBridgeUtils" /// Returns the EVM address of the FlowEVMBridgeFactory solidity contract @@ -9,5 +7,5 @@ import "FlowEVMBridgeUtils" /// @return The EVM address of the FlowEVMBridgeFactory contract as hex string (without 0x prefix) /// access(all) fun main(): String { - return EVMUtils.getEVMAddressAsHexString(address: FlowEVMBridgeUtils.bridgeFactoryEVMAddress) + return FlowEVMBridgeUtils.bridgeFactoryEVMAddress.toString() } \ No newline at end of file diff --git a/cadence/scripts/utils/get_token_decimals.cdc b/cadence/scripts/utils/get_token_decimals.cdc index 3a04ce1f..1c837dff 100644 --- a/cadence/scripts/utils/get_token_decimals.cdc +++ b/cadence/scripts/utils/get_token_decimals.cdc @@ -1,10 +1,10 @@ -import "EVMUtils" +import "EVM" + import "FlowEVMBridgeUtils" access(all) fun main(erc20ContractAddressHex: String): UInt8 { return FlowEVMBridgeUtils.getTokenDecimals( - evmContractAddress: EVMUtils.getEVMAddressFromHexString(address: erc20ContractAddressHex) - ?? panic("Invalid ERC20 address") + evmContractAddress: EVM.addressFromString(erc20ContractAddressHex) ) } diff --git a/cadence/scripts/utils/is_owner.cdc b/cadence/scripts/utils/is_owner.cdc index b642476d..c03fc939 100644 --- a/cadence/scripts/utils/is_owner.cdc +++ b/cadence/scripts/utils/is_owner.cdc @@ -1,23 +1,20 @@ import "EVM" -import "EVMUtils" import "FlowEVMBridgeUtils" -/// Returns whether the given owner (hex-encoded EVM address - minus 0x prefix) is the owner of the given ERC721 NFT +/// Returns whether the given owner (hex-encoded EVM address) is the owner of the given ERC721 NFT /// defined at the hex-encoded EVM contract address /// /// @param ofNFT: The ERC721 ID of the NFT -/// @param owner: The hex-encoded EVM address of the owner without the 0x prefix -/// @param evmContractAddress: The hex-encoded EVM contract address of the ERC721 contract without the 0x prefix +/// @param owner: The hex-encoded EVM address of the owner +/// @param evmContractAddress: The hex-encoded EVM contract address of the ERC721 contract /// /// @return Whether the given owner is the owner of the given ERC721 NFT. Reverts on call failure. /// access(all) fun main(ofNFT: UInt256, owner: String, evmContractAddress: String): Bool { return FlowEVMBridgeUtils.isOwner( ofNFT: ofNFT, - owner: EVMUtils.getEVMAddressFromHexString(address: owner) - ?? panic("Invalid owner address"), - evmContractAddress: EVMUtils.getEVMAddressFromHexString(address: evmContractAddress) - ?? panic("Invalid EVM contract address") + owner: EVM.addressFromString(owner), + evmContractAddress: EVM.addressFromString(evmContractAddress), ) } diff --git a/cadence/scripts/utils/is_owner_or_approved.cdc b/cadence/scripts/utils/is_owner_or_approved.cdc index 423f0bab..5f31be8d 100644 --- a/cadence/scripts/utils/is_owner_or_approved.cdc +++ b/cadence/scripts/utils/is_owner_or_approved.cdc @@ -1,23 +1,20 @@ import "EVM" -import "EVMUtils" import "FlowEVMBridgeUtils" -/// Returns whether the given owner (hex-encoded EVM address - minus 0x prefix) is the owner or approved of the given +/// Returns whether the given owner (hex-encoded EVM address) is the owner or approved of the given /// ERC721 NFT defined at the hex-encoded EVM contract address /// /// @param ofNFT: The ERC721 ID of the NFT -/// @param owner: The hex-encoded EVM address of the owner without the 0x prefix -/// @param evmContractAddress: The hex-encoded EVM contract address of the ERC721 contract without the 0x prefix +/// @param owner: The hex-encoded EVM address of the owner +/// @param evmContractAddress: The hex-encoded EVM contract address of the ERC721 contract /// /// @return Whether the given owner is the owner or approved of the given ERC721 NFT. Reverts on call failure. /// access(all) fun main(ofNFT: UInt256, owner: String, evmContractAddress: String): Bool { return FlowEVMBridgeUtils.isOwnerOrApproved( ofNFT: ofNFT, - owner: EVMUtils.getEVMAddressFromHexString(address: owner) - ?? panic("Invalid owner address"), - evmContractAddress: EVMUtils.getEVMAddressFromHexString(address: evmContractAddress) - ?? panic("Invalid EVM contract address") + owner: EVM.addressFromString(owner), + evmContractAddress: EVM.addressFromString(evmContractAddress) ) } diff --git a/cadence/scripts/utils/token_uri.cdc b/cadence/scripts/utils/token_uri.cdc index 6cc61e12..c6077b23 100644 --- a/cadence/scripts/utils/token_uri.cdc +++ b/cadence/scripts/utils/token_uri.cdc @@ -1,21 +1,18 @@ import "EVM" -import "EVMUtils" import "FlowEVMBridgeUtils" /// Returns the tokenURI of the given tokenID from the given EVM contract address /// /// @param coaHost: The Flow account Address of the account that hosts the COA used to make the call /// @param id: The ID of the ERC721 token -/// @param contractAddressHex: The hex string of the contract address (without 0x prefix) of the ERC721 token +/// @param contractAddressHex: The hex string of the contract address of the ERC721 token /// /// @return The tokenURI of the given tokenID from the given EVM contract address. Reverts if the call is unsuccessful /// access(all) fun main(contractAddressHex: String, tokenID: UInt256): String? { - let address = EVMUtils.getEVMAddressFromHexString(address: contractAddressHex) - ?? panic("Problem ") return FlowEVMBridgeUtils.getTokenURI( - evmContractAddress: address, + evmContractAddress: EVM.addressFromString(contractAddressHex), id: tokenID ) } diff --git a/cadence/scripts/utils/total_supply.cdc b/cadence/scripts/utils/total_supply.cdc index d6991ed5..bee3f2a0 100644 --- a/cadence/scripts/utils/total_supply.cdc +++ b/cadence/scripts/utils/total_supply.cdc @@ -1,6 +1,5 @@ import "EVM" -import "EVMUtils" import "FlowEVMBridgeUtils" /// Retrieves the total supply of the ERC20 contract at the given EVM contract address. Reverts on EVM call failure. @@ -10,7 +9,7 @@ import "FlowEVMBridgeUtils" /// @return the total supply of the ERC20 /// access(all) fun main(evmContractAddressHex: String): UInt256 { - let evmContractAddress = EVMUtils.getEVMAddressFromHexString(address: evmContractAddressHex) - ?? panic("Invalid EVM contract address hex: ".concat(evmContractAddressHex)) - return FlowEVMBridgeUtils.totalSupply(evmContractAddress: evmContractAddress) + return FlowEVMBridgeUtils.totalSupply( + evmContractAddress: EVM.addressFromString(evmContractAddressHex) + ) } diff --git a/cadence/tests/flow_evm_bridge_handler_tests.cdc b/cadence/tests/flow_evm_bridge_handler_tests.cdc index 3cf54d27..94017183 100644 --- a/cadence/tests/flow_evm_bridge_handler_tests.cdc +++ b/cadence/tests/flow_evm_bridge_handler_tests.cdc @@ -67,12 +67,6 @@ fun setup() { arguments: [] ) Test.expect(err, Test.beNil()) - err = Test.deployContract( - name: "EVMUtils", - path: "../contracts/utils/EVMUtils.cdc", - arguments: [] - ) - Test.expect(err, Test.beNil()) // Transfer bridge account some $FLOW transferFlow(signer: serviceAccount, recipient: bridgeAccount.address, amount: 10_000.0) diff --git a/cadence/tests/flow_evm_bridge_tests.cdc b/cadence/tests/flow_evm_bridge_tests.cdc index b63b111a..7a3a7c69 100644 --- a/cadence/tests/flow_evm_bridge_tests.cdc +++ b/cadence/tests/flow_evm_bridge_tests.cdc @@ -84,12 +84,6 @@ fun setup() { arguments: [] ) Test.expect(err, Test.beNil()) - err = Test.deployContract( - name: "EVMUtils", - path: "../contracts/utils/EVMUtils.cdc", - arguments: [] - ) - Test.expect(err, Test.beNil()) // Transfer bridge account some $FLOW transferFlow(signer: serviceAccount, recipient: bridgeAccount.address, amount: 10_000.0) diff --git a/cadence/tests/flow_evm_bridge_utils_tests.cdc b/cadence/tests/flow_evm_bridge_utils_tests.cdc index aeae6a47..71713069 100644 --- a/cadence/tests/flow_evm_bridge_utils_tests.cdc +++ b/cadence/tests/flow_evm_bridge_utils_tests.cdc @@ -41,12 +41,6 @@ fun setup() { arguments: [] ) Test.expect(err, Test.beNil()) - err = Test.deployContract( - name: "EVMUtils", - path: "../contracts/utils/EVMUtils.cdc", - arguments: [] - ) - Test.expect(err, Test.beNil()) // Transfer bridge account some $FLOW transferFlow(signer: serviceAccount, recipient: bridgeAccount.address, amount: 10_000.0) diff --git a/cadence/transactions/bridge/admin/evm/add_deployer.cdc b/cadence/transactions/bridge/admin/evm/add_deployer.cdc index 47ad13e7..7f3f70f0 100644 --- a/cadence/transactions/bridge/admin/evm/add_deployer.cdc +++ b/cadence/transactions/bridge/admin/evm/add_deployer.cdc @@ -1,13 +1,12 @@ import "EVM" -import "EVMUtils" import "FlowEVMBridgeUtils" /// This transaction adds the given EVM address as a deployer in the bridge factory contract, indexed on the /// provided tag. /// /// @param deployerTag: The tag to index the deployer with - e.g. ERC20, ERC721, etc. -/// @param deployerEVMAddressHex: The EVM address of the deployer contract as a hex string, without the '0x' prefix +/// @param deployerEVMAddressHex: The EVM address of the deployer contract as a hex string /// transaction(deployerTag: String, deployerEVMAddressHex: String) { @@ -19,8 +18,7 @@ transaction(deployerTag: String, deployerEVMAddressHex: String) { } execute { - let deployerEVMAddress = EVMUtils.getEVMAddressFromHexString(address: deployerEVMAddressHex) - ?? panic("Could not convert deployer contract address to EVM address") + let deployerEVMAddress = EVM.addressFromString(deployerEVMAddressHex) let callResult = self.coa.call( to: FlowEVMBridgeUtils.bridgeFactoryEVMAddress, diff --git a/cadence/transactions/bridge/admin/evm/set_delegated_deployer.cdc b/cadence/transactions/bridge/admin/evm/set_delegated_deployer.cdc index 945f00d7..c5839ff8 100644 --- a/cadence/transactions/bridge/admin/evm/set_delegated_deployer.cdc +++ b/cadence/transactions/bridge/admin/evm/set_delegated_deployer.cdc @@ -1,12 +1,11 @@ import "EVM" -import "EVMUtils" import "FlowEVMBridgeUtils" /// Sets the bridge factory contract address as a delegated deployer in the provided deployer contract. This enables the /// factory contract to deploy new contracts via the deployer contract. /// -/// @param deployerEVMAddressHex The EVM address of the deployer contract as a hex string without the '0x' prefix +/// @param deployerEVMAddressHex The EVM address of the deployer contract as a hex string /// transaction(deployerEVMAddressHex: String) { @@ -18,8 +17,7 @@ transaction(deployerEVMAddressHex: String) { } execute { - let deployerEVMAddress = EVMUtils.getEVMAddressFromHexString(address: deployerEVMAddressHex) - ?? panic("Could not convert deployer contract address to EVM address") + let deployerEVMAddress = EVM.addressFromString(deployerEVMAddressHex) let callResult = self.coa.call( to: deployerEVMAddress, diff --git a/cadence/transactions/bridge/admin/evm/set_deployment_registry.cdc b/cadence/transactions/bridge/admin/evm/set_deployment_registry.cdc index cfd8c79a..2c15eff3 100644 --- a/cadence/transactions/bridge/admin/evm/set_deployment_registry.cdc +++ b/cadence/transactions/bridge/admin/evm/set_deployment_registry.cdc @@ -1,6 +1,5 @@ import "EVM" -import "EVMUtils" import "FlowEVMBridgeUtils" /// This transaction sets the address of the registry contract in the bridge factory contract. The registry contract @@ -10,7 +9,7 @@ import "FlowEVMBridgeUtils" /// NOTE: This is a sensitive operation as the registry contract serves as the source of truth for bridge-deployed /// contracts. /// -/// @param registryEVMAddressHex The EVM address of the registry contract as a hex string without the '0x' prefix. +/// @param registryEVMAddressHex The EVM address of the registry contract as a hex string /// transaction(registryEVMAddressHex: String) { @@ -22,8 +21,7 @@ transaction(registryEVMAddressHex: String) { } execute { - let registryEVMAddress = EVMUtils.getEVMAddressFromHexString(address: registryEVMAddressHex) - ?? panic("Could not convert registry address to EVM address") + let registryEVMAddress = EVM.addressFromString(registryEVMAddressHex) let callResult = self.coa.call( to: FlowEVMBridgeUtils.bridgeFactoryEVMAddress, diff --git a/cadence/transactions/bridge/admin/evm/set_registrar.cdc b/cadence/transactions/bridge/admin/evm/set_registrar.cdc index 25158e2e..ebe9a0cf 100644 --- a/cadence/transactions/bridge/admin/evm/set_registrar.cdc +++ b/cadence/transactions/bridge/admin/evm/set_registrar.cdc @@ -1,6 +1,5 @@ import "EVM" -import "EVMUtils" import "FlowEVMBridgeUtils" /// Sets the bridge factory contract address as the registrar for the provided FlowBridgeDeploymentRegistry address. @@ -18,8 +17,7 @@ transaction(registryEVMAddressHex: String) { } execute { - let registryEVMAddress = EVMUtils.getEVMAddressFromHexString(address: registryEVMAddressHex) - ?? panic("Could not convert registry address to EVM address") + let registryEVMAddress = EVM.addressFromString(registryEVMAddressHex) let callResult = self.coa.call( to: registryEVMAddress, diff --git a/cadence/transactions/bridge/admin/token-handler/enable_token_handler.cdc b/cadence/transactions/bridge/admin/token-handler/enable_token_handler.cdc index 900dc563..babecc91 100644 --- a/cadence/transactions/bridge/admin/token-handler/enable_token_handler.cdc +++ b/cadence/transactions/bridge/admin/token-handler/enable_token_handler.cdc @@ -1,6 +1,5 @@ import "EVM" -import "EVMUtils" import "FlowEVMBridgeHandlerInterfaces" import "FlowEVMBridgeConfig" diff --git a/cadence/transactions/bridge/admin/token-handler/set_handler_target_evm_address.cdc b/cadence/transactions/bridge/admin/token-handler/set_handler_target_evm_address.cdc index 556bc844..d6bf34ac 100644 --- a/cadence/transactions/bridge/admin/token-handler/set_handler_target_evm_address.cdc +++ b/cadence/transactions/bridge/admin/token-handler/set_handler_target_evm_address.cdc @@ -1,6 +1,5 @@ import "EVM" -import "EVMUtils" import "FlowEVMBridgeHandlerInterfaces" import "FlowEVMBridgeConfig" @@ -22,8 +21,7 @@ transaction(targetTypeIdentifier: String, targetEVMAddressHex: String) { execute { let targetType = CompositeType(targetTypeIdentifier) ?? panic("Invalid Type identifier provided") - let targetEVMAddress = EVMUtils.getEVMAddressFromHexString(address: targetEVMAddressHex) - ?? panic("Invalid EVM Address provided") + let targetEVMAddress = EVM.addressFromString(targetEVMAddressHex) self.admin.setHandlerTargetEVMAddress( targetType: targetType, targetEVMAddress: targetEVMAddress diff --git a/cadence/transactions/bridge/onboarding/batch_onboard_by_evm_address.cdc b/cadence/transactions/bridge/onboarding/batch_onboard_by_evm_address.cdc index c60f4f99..a5d805ef 100644 --- a/cadence/transactions/bridge/onboarding/batch_onboard_by_evm_address.cdc +++ b/cadence/transactions/bridge/onboarding/batch_onboard_by_evm_address.cdc @@ -5,7 +5,6 @@ import "ScopedFTProviders" import "EVM" -import "EVMUtils" import "FlowEVMBridge" import "FlowEVMBridgeConfig" @@ -13,7 +12,7 @@ import "FlowEVMBridgeConfig" /// environments /// NOTE: This must be done before bridging a Cadence-native NFT to EVM /// -/// @param addressesAsHex: Array of EVM contract addresses (as hex string without 0x prefix) defining the +/// @param addressesAsHex: Array of EVM contract addresses defining the /// bridgeable asset to be onboarded /// transaction(addressesAsHex: [String]) { @@ -50,7 +49,7 @@ transaction(addressesAsHex: [String]) { // Iterate over provided array for addressHex in addressesAsHex { // Convert hex string to EVMAddress - let address = EVMUtils.getEVMAddressFromHexString(address: addressHex) + let address = EVM.addressFromString(addressHex) // Continue if the hex is not a valid EVM address or if the address is already onboarded if address == nil || FlowEVMBridge.evmAddressRequiresOnboarding(address!) != true { continue diff --git a/cadence/transactions/bridge/onboarding/onboard_by_evm_address.cdc b/cadence/transactions/bridge/onboarding/onboard_by_evm_address.cdc index 2905d148..0d2793f3 100644 --- a/cadence/transactions/bridge/onboarding/onboard_by_evm_address.cdc +++ b/cadence/transactions/bridge/onboarding/onboard_by_evm_address.cdc @@ -5,15 +5,13 @@ import "ScopedFTProviders" import "EVM" -import "EVMUtils" import "FlowEVMBridge" import "FlowEVMBridgeConfig" /// This transaction onboards the NFT type to the bridge, configuring the bridge to move NFTs between environments /// NOTE: This must be done before bridging a Cadence-native NFT to EVM /// -/// @param contractAddressHex: The EVM address of the contract (as hex string without 0x prefix) defining the -/// bridgeable asset to be onboarded +/// @param contractAddressHex: The EVM address of the contract defining the bridgeable asset to be onboarded /// transaction(contractAddressHex: String) { @@ -23,8 +21,7 @@ transaction(contractAddressHex: String) { prepare(signer: auth(CopyValue, BorrowValue, IssueStorageCapabilityController, PublishCapability, SaveValue) &Account) { /* --- Construct EVMAddress from hex string (no leading `"0x"`) --- */ // - self.contractAddress = EVMUtils.getEVMAddressFromHexString(address: contractAddressHex) - ?? panic("Invalid EVM address string provided") + self.contractAddress = EVM.addressFromString(contractAddressHex) /* --- Configure a ScopedFTProvider --- */ // diff --git a/cadence/transactions/evm/transfer_flow_to_evm_address.cdc b/cadence/transactions/evm/transfer_flow_to_evm_address.cdc index 305021fc..4a0cc529 100644 --- a/cadence/transactions/evm/transfer_flow_to_evm_address.cdc +++ b/cadence/transactions/evm/transfer_flow_to_evm_address.cdc @@ -3,8 +3,6 @@ import "FlowToken" import "EVM" -import "EVMUtils" - /// Transfers $FLOW from the signer's account Cadence Flow balance to the recipient's hex-encoded EVM address. /// transaction(recipientEVMAddressHex: String, amount: UFix64, gasLimit: UInt64) { @@ -21,8 +19,7 @@ transaction(recipientEVMAddressHex: String, amount: UFix64, gasLimit: UInt64) { self.sentVault <- vaultRef.withdraw(amount: amount) as! @FlowToken.Vault // Get the recipient's EVM address - self.recipientEVMAddress = EVMUtils.getEVMAddressFromHexString(address: recipientEVMAddressHex) - ?? panic("Invalid recipient EVM address") + self.recipientEVMAddress = EVM.addressFromString(recipientEVMAddressHex) // Get the recipient's balance before the transfer to check the amount transferred self.recipientPreBalance = self.recipientEVMAddress.balance().inFLOW() diff --git a/cadence/transactions/example-assets/evm-assets/mint_erc20.cdc b/cadence/transactions/example-assets/evm-assets/mint_erc20.cdc index 429053a9..891b9e32 100644 --- a/cadence/transactions/example-assets/evm-assets/mint_erc20.cdc +++ b/cadence/transactions/example-assets/evm-assets/mint_erc20.cdc @@ -1,7 +1,5 @@ import "EVM" -import "EVMUtils" - transaction( recipientHexAddress: String, amount: UInt256, @@ -17,10 +15,8 @@ transaction( } execute { - let recipientAddress = EVMUtils.getEVMAddressFromHexString(address: recipientHexAddress) - ?? panic("Invalid recipient address") - let erc20Address = EVMUtils.getEVMAddressFromHexString(address: erc20HexAddress) - ?? panic("Invalid ERC20 address") + let recipientAddress = EVM.addressFromString(recipientHexAddress) + let erc20Address = EVM.addressFromString(erc20HexAddress) let calldata = EVM.encodeABIWithSignature( "mint(address,uint256)", [recipientAddress, amount] diff --git a/cadence/transactions/example-assets/evm-assets/safe_mint_erc721.cdc b/cadence/transactions/example-assets/evm-assets/safe_mint_erc721.cdc index 5f7e57d8..a8beef41 100644 --- a/cadence/transactions/example-assets/evm-assets/safe_mint_erc721.cdc +++ b/cadence/transactions/example-assets/evm-assets/safe_mint_erc721.cdc @@ -1,7 +1,5 @@ import "EVM" -import "EVMUtils" - transaction( recipientHexAddress: String, tokenId: UInt256, @@ -18,10 +16,8 @@ transaction( } execute { - let recipientAddress = EVMUtils.getEVMAddressFromHexString(address: recipientHexAddress) - ?? panic("Invalid recipient address") - let erc721Address = EVMUtils.getEVMAddressFromHexString(address: erc721HexAddress) - ?? panic("Invalid ERC721 address") + let recipientAddress = EVM.addressFromString(recipientHexAddress) + let erc721Address = EVM.addressFromString(erc721HexAddress) let calldata = EVM.encodeABIWithSignature( "safeMint(address,uint256,string)", [recipientAddress, tokenId, uri] diff --git a/cadence/transactions/example-assets/evm-assets/safe_transfer_from_erc721.cdc b/cadence/transactions/example-assets/evm-assets/safe_transfer_from_erc721.cdc index 1e71dd3b..478d09f3 100644 --- a/cadence/transactions/example-assets/evm-assets/safe_transfer_from_erc721.cdc +++ b/cadence/transactions/example-assets/evm-assets/safe_transfer_from_erc721.cdc @@ -1,6 +1,5 @@ import "EVM" -import "EVMUtils" import "FlowEVMBridgeUtils" /// Executes an NFT transfer to the defined recipient address against the specified ERC721 contract. @@ -14,8 +13,8 @@ transaction(evmContractAddressHex: String, recipientAddressHex: String, id: UInt var recipientOwnerCheck: Bool prepare(signer: auth(BorrowValue) &Account) { - self.evmContractAddress = EVMUtils.getEVMAddressFromHexString(address: evmContractAddressHex) ?? panic("Invalid contract address") - self.recipientAddress = EVMUtils.getEVMAddressFromHexString(address: recipientAddressHex) ?? panic("Invalid recipient address") + self.evmContractAddress = EVM.addressFromString(evmContractAddressHex) + self.recipientAddress = EVM.addressFromString(recipientAddressHex) self.coa = signer.storage.borrow(from: /storage/evm) ?? panic("Could not borrow CadenceOwnedAccount reference") diff --git a/cadence/transactions/example-assets/evm-assets/transfer_erc20.cdc b/cadence/transactions/example-assets/evm-assets/transfer_erc20.cdc index d2eb1607..133334b4 100644 --- a/cadence/transactions/example-assets/evm-assets/transfer_erc20.cdc +++ b/cadence/transactions/example-assets/evm-assets/transfer_erc20.cdc @@ -1,6 +1,5 @@ import "EVM" -import "EVMUtils" import "FlowEVMBridgeUtils" /// Executes a token transfer to the defined recipient address against the specified ERC20 contract. @@ -14,8 +13,8 @@ transaction(evmContractAddressHex: String, recipientAddressHex: String, amount: var postBalance: UInt256 prepare(signer: auth(BorrowValue) &Account) { - self.evmContractAddress = EVMUtils.getEVMAddressFromHexString(address: evmContractAddressHex) ?? panic("Invalid contract address") - self.recipientAddress = EVMUtils.getEVMAddressFromHexString(address: recipientAddressHex) ?? panic("Invalid recipient address") + self.evmContractAddress = EVM.addressFromString(evmContractAddressHex) + self.recipientAddress = EVM.addressFromString(recipientAddressHex) self.coa = signer.storage.borrow(from: /storage/evm) ?? panic("Could not borrow CadenceOwnedAccount reference") diff --git a/cadence/transactions/flow-token/dynamic_vm_transfer.cdc b/cadence/transactions/flow-token/dynamic_vm_transfer.cdc index 3b45d5df..4ef42f72 100644 --- a/cadence/transactions/flow-token/dynamic_vm_transfer.cdc +++ b/cadence/transactions/flow-token/dynamic_vm_transfer.cdc @@ -3,8 +3,6 @@ import "FlowToken" import "EVM" -import "EVMUtils" - // Transfers $FLOW from the signer's account to the recipient's address, determining the target VM based on the format // of the recipient's hex address. Note that the sender's funds are sourced by default from the target VM, pulling any // difference from the alternate VM if available. e.g. Transfers to Flow addresses will first attempt to withdraw from @@ -33,7 +31,7 @@ transaction(addressString: String, amount: UFix64) { // Define optional recipients for both VMs self.receiver = nil let cadenceRecipient = Address.fromString(addressString) - self.evmRecipient = cadenceRecipient == nil ? EVMUtils.getEVMAddressFromHexString(address: addressString) : nil + self.evmRecipient = cadenceRecipient == nil ? EVM.addressFromString(addressString) : nil // Validate exactly one target address is assigned if cadenceRecipient != nil && self.evmRecipient != nil { panic("Malformed recipient address - assignable as both Cadence and EVM addresses") diff --git a/flow.json b/flow.json index 883fca6c..8c76d43c 100644 --- a/flow.json +++ b/flow.json @@ -49,16 +49,6 @@ "testnet": "8c5303eaa26202d6" } }, - "EVMUtils": { - "source": "./cadence/contracts/utils/EVMUtils.cdc", - "aliases": { - "crescendo": "dfc20aee650fcbdf", - "emulator": "179b6b1cb6755e31", - "previewnet": "715c57f7a59bc39b", - "testing": "0000000000000007", - "testnet": "dfc20aee650fcbdf" - } - }, "ExampleHandledToken": { "source": "./cadence/contracts/example-assets/ExampleHandledToken.cdc", "aliases": { @@ -403,7 +393,6 @@ "ArrayUtils", "StringUtils", "ScopedFTProviders", - "EVMUtils", "Serialize", "SerializeMetadata", "IBridgePermissions", @@ -429,7 +418,6 @@ "ArrayUtils", "StringUtils", "ScopedFTProviders", - "EVMUtils", "Serialize", "SerializeMetadata", "IBridgePermissions", @@ -463,7 +451,6 @@ "ArrayUtils", "StringUtils", "ScopedFTProviders", - "EVMUtils", "Serialize", "SerializeMetadata", "IBridgePermissions", diff --git a/main.go b/main.go index c56fd469..bf6ce45e 100644 --- a/main.go +++ b/main.go @@ -33,7 +33,6 @@ var contracts = []string{ "ArrayUtils", "StringUtils", "ScopedFTProviders", - "EVMUtils", "Serialize", "SerializeMetadata", "IBridgePermissions",