Skip to content

Commit

Permalink
Merge pull request #89 from onflow/update-bridge-events
Browse files Browse the repository at this point in the history
Polish bridge contract events for traceability & readability
  • Loading branch information
sisyphusSmiling authored Jun 25, 2024
2 parents 5db91fa + 700dfe4 commit 01691c9
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 38 deletions.
4 changes: 2 additions & 2 deletions cadence/contracts/bridge/FlowEVMBridge.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ contract FlowEVMBridge : IFlowEVMNFTBridge, IFlowEVMTokenBridge {

/// Emitted any time a new asset type is onboarded to the bridge
access(all)
event Onboarded(type: Type, cadenceContractAddress: Address, evmContractAddress: String)
event Onboarded(type: String, cadenceContractAddress: Address, evmContractAddress: String)
/// Denotes a defining contract was deployed to the bridge account
access(all)
event BridgeDefiningContractDeployed(
Expand Down Expand Up @@ -118,7 +118,7 @@ contract FlowEVMBridge : IFlowEVMNFTBridge, IFlowEVMTokenBridge {
)

emit Onboarded(
type: type,
type: type.identifier,
cadenceContractAddress: FlowEVMBridgeUtils.getContractAddress(fromType: type)!,
evmContractAddress: onboardingValues.evmContractAddress.toString()
)
Expand Down
18 changes: 9 additions & 9 deletions cadence/contracts/bridge/FlowEVMBridgeConfig.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,19 @@ contract FlowEVMBridgeConfig {
/// Emitted whenever a TokenHandler is configured
///
access(all)
event HandlerConfigured(targetType: Type, targetEVMAddress: String?, isEnabled: Bool)
event HandlerConfigured(targetType: String, targetEVMAddress: String?, isEnabled: Bool)
/// Emitted whenever the bridge is paused or unpaused globally - true for paused, false for unpaused
///
access(all)
event BridgePauseStatusUpdated(paused: Bool)
/// Emitted whenever a specific asset is paused or unpaused - true for paused, false for unpaused
///
access(all)
event AssetPauseStatusUpdated(paused: Bool, type: Type, evmAddress: String)
event AssetPauseStatusUpdated(paused: Bool, type: String, evmAddress: String)
/// Emitted whenever an association is updated
///
access(all)
event AssociationUpdated(type: Type, evmAddress: String)
event AssociationUpdated(type: String, evmAddress: String)

/*************
Getters
Expand Down Expand Up @@ -143,7 +143,7 @@ contract FlowEVMBridgeConfig {
let evmAddressHex = evmAddress.toString()
self.evmAddressHexToType[evmAddressHex] = type

emit AssociationUpdated(type: type, evmAddress: evmAddressHex)
emit AssociationUpdated(type: type.identifier, evmAddress: evmAddressHex)
}

/// Returns whether the given Type has a TokenHandler configured
Expand Down Expand Up @@ -186,7 +186,7 @@ contract FlowEVMBridgeConfig {
}

emit HandlerConfigured(
targetType: type,
targetType: type.identifier,
targetEVMAddress: targetEVMAddressHex,
isEnabled: handler.isEnabled()
)
Expand Down Expand Up @@ -342,7 +342,7 @@ contract FlowEVMBridgeConfig {
association.pause()

let evmAddress = association.evmAddress.toString()
emit AssetPauseStatusUpdated(paused: true, type: type, evmAddress: evmAddress)
emit AssetPauseStatusUpdated(paused: true, type: type.identifier, evmAddress: evmAddress)
}

/// Unpauses all operations for a given asset type
Expand All @@ -358,7 +358,7 @@ contract FlowEVMBridgeConfig {

association.unpause()
let evmAddress = association.evmAddress.toString()
emit AssetPauseStatusUpdated(paused: false, type: type, evmAddress: evmAddress)
emit AssetPauseStatusUpdated(paused: false, type: type.identifier, evmAddress: evmAddress)
}

/// Sets the target EVM contract address on the handler for a given Type, associating the Cadence type with the
Expand Down Expand Up @@ -390,7 +390,7 @@ contract FlowEVMBridgeConfig {
)

emit HandlerConfigured(
targetType: targetType,
targetType: targetType.identifier,
targetEVMAddress: targetEVMAddress.toString(),
isEnabled: handler.isEnabled()
)
Expand All @@ -413,7 +413,7 @@ contract FlowEVMBridgeConfig {
?? panic("Handler cannot be enabled without a target EVM Address")

emit HandlerConfigured(
targetType: handler.getTargetType()!,
targetType: handler.getTargetType()!.identifier,
targetEVMAddress: targetEVMAddressHex,
isEnabled: handler.isEnabled()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,19 @@ access(all) contract FlowEVMBridgeHandlerInterfaces {
**************/

/// Event emitted when a handler is enabled between a Cadence type and an EVM address
access(all) event HandlerEnabled(handlerType: Type, targetType: Type, targetEVMAddress: EVM.EVMAddress)
access(all) event HandlerEnabled(
handlerType: String,
handlerUUID: UInt64,
targetType: String,
targetEVMAddress: String
)
access(all) event MinterSet(handlerType: String,
handlerUUID: UInt64,
targetType: String?,
targetEVMAddress: String?,
minterType: String,
minterUUID: UInt64
)

/****************
Constructs
Expand Down Expand Up @@ -71,6 +83,15 @@ access(all) contract FlowEVMBridgeHandlerInterfaces {
access(Admin) fun setMinter(_ minter: @{FlowEVMBridgeHandlerInterfaces.TokenMinter}) {
pre {
self.getExpectedMinterType() == minter.getType(): "Minter is not of the expected type"
minter.getMintedType() == self.getTargetType(): "Minter does not mint the target type"
emit MinterSet(
handlerType: self.getType().identifier,
handlerUUID: self.uuid,
targetType: self.getTargetType()?.identifier,
targetEVMAddress: self.getTargetEVMAddress()?.toString(),
minterType: minter.getType().identifier,
minterUUID: minter.uuid
)
}
}
/// Enables the Handler to fulfill bridge requests for the configured targets. If implementers utilize a minter,
Expand All @@ -84,9 +105,10 @@ access(all) contract FlowEVMBridgeHandlerInterfaces {
post {
self.isEnabled(): "Problem enabling Handler"
emit HandlerEnabled(
handlerType: self.getType(),
targetType: self.getTargetType()!,
targetEVMAddress: self.getTargetEVMAddress()!
handlerType: self.getType().identifier,
handlerUUID: self.uuid,
targetType: self.getTargetType()!.identifier,
targetEVMAddress: self.getTargetEVMAddress()!.toString()
)
}
}
Expand All @@ -97,7 +119,7 @@ access(all) contract FlowEVMBridgeHandlerInterfaces {
access(all) resource interface TokenMinter {
/// Returns the Cadence type minted by this resource
access(all) view fun getMintedType(): Type
/// Mints the specified amount of the Cadence
/// Mints the specified amount of tokens
access(Mint) fun mint(amount: UFix64): @{FungibleToken.Vault} {
pre {
amount > 0.0: "Amount must be greater than 0"
Expand Down
5 changes: 3 additions & 2 deletions cadence/contracts/bridge/interfaces/IEVMBridgeNFTMinter.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "NonFungibleToken"
access(all)
contract interface IEVMBridgeNFTMinter {

access(all) event Minted(type: Type, id: UInt64, evmID: UInt256, tokenURI: String, minter: Address)
access(all) event Minted(type: String, id: UInt64, uuid: UInt64, evmID: UInt256, tokenURI: String, minter: Address)
access(all) event TokenURIUpdated(evmID: UInt256, newURI: String, updater: Address)

/// Account-only method to mint an NFT
Expand All @@ -14,8 +14,9 @@ contract interface IEVMBridgeNFTMinter {
fun mintNFT(id: UInt256, tokenURI: String): @{NonFungibleToken.NFT} {
post {
emit Minted(
type: result.getType(),
type: result.getType().identifier,
id: result.id,
uuid: result.uuid,
evmID: id,
tokenURI: tokenURI,
minter: self.account.address
Expand Down
9 changes: 7 additions & 2 deletions cadence/contracts/bridge/interfaces/IEVMBridgeTokenMinter.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@ access(all)
contract interface IEVMBridgeTokenMinter {

/// Emitted whenever tokens are minted, identifying the type, amount, and minter
access(all) event Minted(type: Type, amount: UFix64, minter: Address)
access(all) event Minted(type: String, amount: UFix64, mintedUUID: UInt64, minter: Address)

/// Account-only method to mint a fungible token of the specified amount.
///
access(account)
fun mintTokens(amount: UFix64): @{FungibleToken.Vault} {
post {
result.balance == amount: "Result does not contained specified amount"
emit Minted(type: result.getType(), amount: amount, minter: self.account.address)
emit Minted(
type: result.getType().identifier,
amount: amount,
mintedUUID: result.uuid,
minter: self.account.address
)
}
}
}
12 changes: 8 additions & 4 deletions cadence/contracts/bridge/interfaces/IFlowEVMNFTBridge.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ access(all) contract interface IFlowEVMNFTBridge {
/// Broadcasts an NFT was bridged from Cadence to EVM
access(all)
event BridgedNFTToEVM(
type: Type,
type: String,
id: UInt64,
uuid: UInt64,
evmID: UInt256,
to: String,
evmContractAddress: String,
Expand All @@ -25,8 +26,9 @@ access(all) contract interface IFlowEVMNFTBridge {
/// Broadcasts an NFT was bridged from EVM to Cadence
access(all)
event BridgedNFTFromEVM(
type: Type,
type: String,
id: UInt64,
uuid: UInt64,
evmID: UInt256,
caller: String,
evmContractAddress: String,
Expand Down Expand Up @@ -65,8 +67,9 @@ access(all) contract interface IFlowEVMNFTBridge {
) {
pre {
emit BridgedNFTToEVM(
type: token.getType(),
type: token.getType().identifier,
id: token.id,
uuid: token.uuid,
evmID: CrossVMNFT.getEVMID(from: &token as &{NonFungibleToken.NFT}) ?? UInt256(token.id),
to: to.toString(),
evmContractAddress: self.getAssociatedEVMAddress(with: token.getType())?.toString()
Expand Down Expand Up @@ -99,8 +102,9 @@ access(all) contract interface IFlowEVMNFTBridge {
): @{NonFungibleToken.NFT} {
post {
emit BridgedNFTFromEVM(
type: result.getType(),
type: result.getType().identifier,
id: result.id,
uuid: result.uuid,
evmID: id,
caller: owner.toString(),
evmContractAddress: self.getAssociatedEVMAddress(with: result.getType())?.toString()
Expand Down
12 changes: 8 additions & 4 deletions cadence/contracts/bridge/interfaces/IFlowEVMTokenBridge.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@ access(all) contract interface IFlowEVMTokenBridge {
/// Broadcasts fungible tokens were bridged from Cadence to EVM
access(all)
event BridgedTokensToEVM(
type: Type,
type: String,
amount: UFix64,
bridgedUUID: UInt64,
to: String,
evmContractAddress: String,
bridgeAddress: Address
)
/// Broadcasts fungible tokens were bridged from EVM to Cadence
access(all)
event BridgedTokensFromEVM(
type: Type,
type: String,
amount: UInt256,
bridgedUUID: UInt64,
caller: String,
evmContractAddress: String,
bridgeAddress: Address
Expand Down Expand Up @@ -60,8 +62,9 @@ access(all) contract interface IFlowEVMTokenBridge {
) {
pre {
emit BridgedTokensToEVM(
type: vault.getType(),
type: vault.getType().identifier,
amount: vault.balance,
bridgedUUID: vault.uuid,
to: to.toString(),
evmContractAddress: self.getAssociatedEVMAddress(with: vault.getType())?.toString()
?? panic("Could not find EVM Contract address associated with provided NFT"),
Expand Down Expand Up @@ -93,8 +96,9 @@ access(all) contract interface IFlowEVMTokenBridge {
): @{FungibleToken.Vault} {
post {
emit BridgedTokensFromEVM(
type: result.getType(),
type: result.getType().identifier,
amount: amount,
bridgedUUID: result.uuid,
caller: owner.toString(),
evmContractAddress: self.getAssociatedEVMAddress(with: result.getType())?.toString()
?? panic("Could not find EVM Contract address associated with provided Vault"),
Expand Down
Loading

0 comments on commit 01691c9

Please sign in to comment.