-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from onflow/add-bridge-interface
Add NFT bridge interface
- Loading branch information
Showing
4 changed files
with
171 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import "FungibleToken" | ||
import "NonFungibleToken" | ||
|
||
import "EVM" | ||
|
||
import "FlowEVMBridgeConfig" | ||
import "FlowEVMBridgeUtils" | ||
import "CrossVMNFT" | ||
|
||
access(all) contract interface IFlowEVMNFTBridge { | ||
|
||
/************* | ||
Events | ||
**************/ | ||
|
||
/// Broadcasts an NFT was bridged from Cadence to EVM | ||
access(all) | ||
event BridgedNFTToEVM( | ||
type: Type, | ||
id: UInt64, | ||
evmID: UInt256, | ||
to: String, | ||
evmContractAddress: String, | ||
bridgeAddress: Address | ||
) | ||
/// Broadcasts an NFT was bridged from EVM to Cadence | ||
access(all) | ||
event BridgedNFTFromEVM( | ||
type: Type, | ||
id: UInt64, | ||
evmID: UInt256, | ||
caller: String, | ||
evmContractAddress: String, | ||
bridgeAddress: Address | ||
) | ||
|
||
/************** | ||
Getters | ||
***************/ | ||
|
||
/// Returns the EVM address associated with the provided type | ||
/// | ||
access(all) | ||
view fun getAssociatedEVMAddress(with type: Type): EVM.EVMAddress? | ||
|
||
/// Returns the EVM address of the bridge coordinating COA | ||
/// | ||
access(all) | ||
view fun getBridgeCOAEVMAddress(): EVM.EVMAddress | ||
|
||
/******************************** | ||
Public Bridge Entrypoints | ||
*********************************/ | ||
|
||
/// Public entrypoint to bridge NFTs from Cadence to EVM. | ||
/// | ||
/// @param token: The NFT to be bridged | ||
/// @param to: The NFT recipient in FlowEVM | ||
/// @param feeProvider: A reference to a FungibleToken Provider from which the bridging fee is withdrawn in $FLOW | ||
/// | ||
access(all) | ||
fun bridgeNFTToEVM( | ||
token: @{NonFungibleToken.NFT}, | ||
to: EVM.EVMAddress, | ||
feeProvider: auth(FungibleToken.Withdraw) &{FungibleToken.Provider} | ||
) { | ||
pre { | ||
emit BridgedNFTToEVM( | ||
type: token.getType(), | ||
id: token.id, | ||
evmID: CrossVMNFT.getEVMID(from: &token as &{NonFungibleToken.NFT}) ?? UInt256(token.id), | ||
to: FlowEVMBridgeUtils.getEVMAddressAsHexString(address: to), | ||
evmContractAddress: FlowEVMBridgeUtils.getEVMAddressAsHexString( | ||
address: self.getAssociatedEVMAddress(with: token.getType()) | ||
?? panic("Could not find EVM Contract address associated with provided NFT") | ||
), bridgeAddress: self.account.address | ||
) | ||
} | ||
} | ||
|
||
/// Public entrypoint to bridge NFTs from EVM to Cadence | ||
/// | ||
/// @param owner: The EVM address of the NFT owner. Current ownership and successful transfer (via | ||
/// `protectedTransferCall`) is validated before the bridge request is executed. | ||
/// @param calldata: Caller-provided approve() call, enabling contract COA to operate on NFT in EVM contract | ||
/// @param id: The NFT ID to bridged | ||
/// @param evmContractAddress: Address of the EVM address defining the NFT being bridged - also call target | ||
/// @param feeProvider: A reference to a FungibleToken Provider from which the bridging fee is withdrawn in $FLOW | ||
/// @param protectedTransferCall: A function that executes the transfer of the NFT from the named owner to the | ||
/// bridge's COA. This function is expected to return a Result indicating the status of the transfer call. | ||
/// | ||
/// @returns The bridged NFT | ||
/// | ||
access(all) | ||
fun bridgeNFTFromEVM( | ||
owner: EVM.EVMAddress, | ||
type: Type, | ||
id: UInt256, | ||
feeProvider: auth(FungibleToken.Withdraw) &{FungibleToken.Provider}, | ||
protectedTransferCall: fun (): EVM.Result | ||
): @{NonFungibleToken.NFT} { | ||
post { | ||
emit BridgedNFTFromEVM( | ||
type: result.getType(), | ||
id: result.id, | ||
evmID: id, | ||
caller: FlowEVMBridgeUtils.getEVMAddressAsHexString(address: owner), | ||
evmContractAddress: FlowEVMBridgeUtils.getEVMAddressAsHexString( | ||
address: self.getAssociatedEVMAddress(with: result.getType()) | ||
?? panic("Could not find EVM Contract address associated with provided NFT") | ||
), bridgeAddress: self.account.address | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters