Skip to content

Commit

Permalink
remove EVMUtils & implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
sisyphusSmiling committed Jun 13, 2024
1 parent efd99b1 commit 34fa385
Show file tree
Hide file tree
Showing 42 changed files with 91 additions and 234 deletions.
5 changes: 2 additions & 3 deletions cadence/contracts/bridge/FlowEVMBridge.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import "FlowToken"

import "EVM"

import "EVMUtils"
import "IBridgePermissions"
import "ICrossVM"
import "IEVMBridgeNFTMinter"
Expand Down Expand Up @@ -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()
)
}

Expand Down Expand Up @@ -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()
)
}
}
16 changes: 7 additions & 9 deletions cadence/contracts/bridge/FlowEVMBridgeConfig.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import "EVM"

import "FlowToken"

import "EVMUtils"
import "FlowEVMBridgeHandlerInterfaces"

/// This contract is used to store configuration information shared by FlowEVMBridge contracts
Expand Down Expand Up @@ -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]
}

Expand All @@ -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
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -285,7 +284,7 @@ contract FlowEVMBridgeConfig {

emit HandlerConfigured(
targetType: targetType,
targetEVMAddress: EVMUtils.getEVMAddressAsHexString(address: targetEVMAddress),
targetEVMAddress: targetEVMAddress.toString(),
isEnabled: handler.isEnabled()
)
}
Expand All @@ -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()!,
Expand All @@ -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 }

Expand Down
1 change: 0 additions & 1 deletion cadence/contracts/bridge/FlowEVMBridgeHandlers.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import "NonFungibleToken"

import "EVM"

import "EVMUtils"
import "FlowEVMBridgeHandlerInterfaces"
import "FlowEVMBridgeConfig"
import "FlowEVMBridgeUtils"
Expand Down
8 changes: 3 additions & 5 deletions cadence/contracts/bridge/FlowEVMBridgeUtils.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import "FlowStorageFees"

import "EVM"

import "EVMUtils"
import "SerializeMetadata"
import "FlowEVMBridgeConfig"
import "CrossVMNFT"
Expand Down Expand Up @@ -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
Expand All @@ -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())
}

/****************
Expand Down Expand Up @@ -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())
}
}
19 changes: 8 additions & 11 deletions cadence/contracts/bridge/interfaces/IFlowEVMNFTBridge.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import "NonFungibleToken"

import "EVM"

import "EVMUtils"
import "FlowEVMBridgeConfig"
import "CrossVMNFT"

Expand Down Expand Up @@ -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
)
}
}
Expand Down Expand Up @@ -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
)
}
}
Expand Down
20 changes: 8 additions & 12 deletions cadence/contracts/bridge/interfaces/IFlowEVMTokenBridge.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import "NonFungibleToken"

import "EVM"

import "EVMUtils"

access(all) contract interface IFlowEVMTokenBridge {

/*************
Expand Down Expand Up @@ -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
)
}
}
Expand Down Expand Up @@ -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
)
}
}
Expand Down
34 changes: 0 additions & 34 deletions cadence/contracts/utils/EVMUtils.cdc

This file was deleted.

10 changes: 5 additions & 5 deletions cadence/scripts/bridge/batch_evm_address_requires_onboarding.cdc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "EVMUtils"
import "EVM"

import "FlowEVMBridge"

/// Returns whether a EVM contract needs to be onboarded to the FlowEVMBridge
Expand All @@ -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
}
9 changes: 4 additions & 5 deletions cadence/scripts/bridge/evm_address_requires_onboarding.cdc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "EVMUtils"
import "EVM"

import "FlowEVMBridge"

/// Returns whether a EVM contract needs to be onboarded to the FlowEVMBridge
Expand All @@ -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)
}
3 changes: 1 addition & 2 deletions cadence/scripts/bridge/get_associated_evm_address.cdc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import "EVM"

import "EVMUtils"
import "FlowEVMBridgeConfig"

/// Returns the EVM address associated with the given Cadence type (as its identifier String)
Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions cadence/scripts/bridge/get_associated_type.cdc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import "EVM"

import "EVMUtils"
import "FlowEVMBridgeConfig"

/// Returns the Cadence Type associated with the given EVM address (as its hex String)
Expand All @@ -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)
}
4 changes: 1 addition & 3 deletions cadence/scripts/bridge/get_bridge_coa_address.cdc
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import "EVM"

import "EVMUtils"
import "FlowEVMBridge"

/// Returns the EVM address associated with the 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()
}
12 changes: 1 addition & 11 deletions cadence/scripts/evm/get_evm_address_string_from_bytes.cdc
Original file line number Diff line number Diff line change
@@ -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]>())
}
13 changes: 5 additions & 8 deletions cadence/scripts/utils/balance_of.cdc
Original file line number Diff line number Diff line change
@@ -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)
)
}
3 changes: 1 addition & 2 deletions cadence/scripts/utils/derive_bridged_nft_contract_name.cdc
Original file line number Diff line number Diff line change
@@ -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)
)
}
Loading

0 comments on commit 34fa385

Please sign in to comment.