Smart Contract
CrossVMMetadataViews
A.3eebe1cb4a1126b2.CrossVMMetadataViews
1import ViewResolver from 0x1d7e57aa55817448
2import EVM from 0xe467b9dd11fa00df
3
4/// This contract implements views originally proposed in FLIP-318 supporting NFT collections
5/// with project-defined implementations across both Cadence & EVM.
6/// The View structs in this contract should be implemented in the same way that views from `MetadataViews` are implemented
7///
8access(all) contract CrossVMMetadataViews {
9
10 /// An enum denoting a VM. For now, there are only two VMs on Flow, but this enum could be
11 /// expanded in the event other VMs are supported on the network.
12 ///
13 access(all) enum VM : UInt8 {
14 access(all) case Cadence
15 access(all) case EVM
16 }
17
18 /// View resolved at contract & resource level pointing to the associated EVM implementation.
19 /// NOTE: This view alone is not sufficient to validate an association across Cadence & EVM!
20 /// Both the Cadence Type/contract *and* the EVM contract should point to each other, with the
21 /// EVM pointer being facilitated by ICrossVM.sol contract interface methods. For more
22 /// information and context, see FLIP-318: https://github.com/onflow/flips/issues/318
23 ///
24 access(all) struct EVMPointer {
25 /// The associated Cadence Type defined in the contract that this view is returned from
26 access(all) let cadenceType: Type
27 /// The defining Cadence contract address
28 access(all) let cadenceContractAddress: Address
29 /// The associated EVM contract address that the Cadence contract will bridge to
30 access(all) let evmContractAddress: EVM.EVMAddress
31 /// Whether the asset is Cadence- or EVM-native. Native here meaning the VM in which the
32 /// asset is originally distributed.
33 access(all) let nativeVM: VM
34
35 init(
36 cadenceType: Type,
37 cadenceContractAddress: Address,
38 evmContractAddress: EVM.EVMAddress,
39 nativeVM: VM
40 ) {
41 self.cadenceType = cadenceType
42 self.cadenceContractAddress = cadenceContractAddress
43 self.evmContractAddress = evmContractAddress
44 self.nativeVM = nativeVM
45 }
46 }
47
48 access(all) fun getEVMPointer(_ viewResolver: &{ViewResolver.Resolver}): EVMPointer? {
49 if let view = viewResolver.resolveView(Type<EVMPointer>()) {
50 if let v = view as? EVMPointer {
51 return v
52 }
53 }
54 return nil
55 }
56
57 /// View resolved at resource level denoting any metadata to be passed to the associated EVM
58 /// contract at the time of bridging. This optional view would allow EVM side metadata to be
59 /// updated based on current Cadence state. If the view is not supported, no bytes will be
60 /// passed into EVM when bridging.
61 ///
62 access(all) struct EVMBytesMetadata {
63 /// Returns the bytes to be passed to the EVM contract on `fulfillToEVM` call, allowing the
64 /// EVM contract to update the metadata associated with the NFT. The corresponding Solidity
65 /// `bytes` type allows the implementer greater flexibility by enabling them to pass
66 /// arbitrary data between VMs.
67 access(all) let bytes: EVM.EVMBytes
68
69 init(bytes: EVM.EVMBytes) {
70 self.bytes = bytes
71 }
72 }
73
74 access(all) fun getEVMBytesMetadata(_ viewResolver: &{ViewResolver.Resolver}): EVMBytesMetadata? {
75 if let view = viewResolver.resolveView(Type<EVMBytesMetadata>()) {
76 if let v = view as? EVMBytesMetadata {
77 return v
78 }
79 }
80 return nil
81 }
82
83}
84