Skip to content

Commit d11f5e0

Browse files
update CrossVMMetadataViews & add to go lib
1 parent 3c02d16 commit d11f5e0

File tree

4 files changed

+124
-22
lines changed

4 files changed

+124
-22
lines changed

contracts/CrossVMMetadataViews.cdc

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import "EVM"
2+
3+
/// This contract implements views originally proposed in FLIP-318 supporting NFT collections
4+
/// with project-defined implementations across both Cadence & EVM.
5+
///
6+
access(all) contract CrossVMMetadataViews {
7+
8+
/// An enum denoting a VM. For now, there are only two VMs on Flow, but this enum could be
9+
/// expanded in the event other VMs are supported on the network.
10+
///
11+
access(all) enum VM : UInt8 {
12+
access(all) case Cadence
13+
access(all) case EVM
14+
}
15+
16+
/// View resolved at contract & resource level pointing to the associated EVM implementation.
17+
/// NOTE: This view alone is not sufficient to validate an association across Cadence & EVM!
18+
/// Both the Cadence Type/contract *and* the EVM contract should point to each other, with the
19+
/// EVM pointer being facilitated by ICrossVM.sol contract interface methods. For more
20+
/// information and context, see FLIP-318: https://github.com/onflow/flips/issues/318
21+
///
22+
access(all) struct EVMPointer {
23+
/// The associated Cadence Type
24+
access(all) let cadenceType: Type
25+
/// The defining Cadence contract address
26+
access(all) let cadenceContractAddress: Address
27+
/// The associated EVM contract address
28+
access(all) let evmContractAddress: EVM.EVMAddress
29+
/// Whether the asset is Cadence- or EVM-native. Native here meaning the VM in which the
30+
/// asset is distributed.
31+
access(all) let nativeVM: VM
32+
33+
init(
34+
cadenceType: Type,
35+
cadenceContractAddress: Address,
36+
evmContractAddress: EVM.EVMAddress,
37+
nativeVM: VM
38+
) {
39+
self.cadenceType = cadenceType
40+
self.cadenceContractAddress = cadenceContractAddress
41+
self.evmContractAddress = evmContractAddress
42+
self.nativeVM = nativeVM
43+
}
44+
}
45+
46+
/// View resolved at resource level denoting any metadata to be passed to the associated EVM
47+
/// contract at the time of / bridging. This optional view would allow EVM side metadata to be
48+
/// updated based on current Cadence state. If the / view is not supported, no bytes will be
49+
/// passed into EVM when bridging.
50+
///
51+
access(all) struct EVMBytesMetadata {
52+
/// Returns the bytes to be passed to the EVM contract on `fulfillToEVM` call, allowing the
53+
/// EVM contract to update / the metadata associated with the NFT. The corresponding Solidity
54+
/// `bytes` type allows the implementer greater / flexibility by enabling them to pass
55+
/// arbitrary data between VMs.
56+
access(all) let bytes: EVM.EVMBytes?
57+
58+
init(bytes: EVM.EVMBytes?) {
59+
self.bytes = bytes
60+
}
61+
}
62+
63+
}

lib/go/contracts/contracts.go

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,30 @@ import (
1414
)
1515

1616
var (
17-
placeholderNonFungibleToken = regexp.MustCompile(`"NonFungibleToken"`)
18-
nonFungibleTokenImport = "NonFungibleToken from "
19-
placeholderMetadataViews = regexp.MustCompile(`"MetadataViews"`)
20-
metadataViewsImport = "MetadataViews from "
21-
placeholderFungibleToken = regexp.MustCompile(`"FungibleToken"`)
22-
fungibleTokenImport = "FungibleToken from "
23-
placeholderResolver = regexp.MustCompile(`"ViewResolver"`)
24-
viewResolverImport = "ViewResolver from "
25-
placeholderUniversalCollection = regexp.MustCompile(`"UniversalCollection"`)
26-
universalCollectionImport = "UniversalCollection from "
17+
placeholderNonFungibleToken = regexp.MustCompile(`"NonFungibleToken"`)
18+
nonFungibleTokenImport = "NonFungibleToken from "
19+
placeholderMetadataViews = regexp.MustCompile(`"MetadataViews"`)
20+
metadataViewsImport = "MetadataViews from "
21+
placeholderFungibleToken = regexp.MustCompile(`"FungibleToken"`)
22+
fungibleTokenImport = "FungibleToken from "
23+
placeholderResolver = regexp.MustCompile(`"ViewResolver"`)
24+
viewResolverImport = "ViewResolver from "
25+
placeholderUniversalCollection = regexp.MustCompile(`"UniversalCollection"`)
26+
universalCollectionImport = "UniversalCollection from "
27+
placeholderCrossVMMetadataViews = regexp.MustCompile(`"CrossVMMetadataViews"`)
28+
crossVMMetadataViewsImport = "CrossVMMetadataViews from "
2729
)
2830

2931
const (
30-
filenameNonFungibleToken = "NonFungibleToken.cdc"
31-
filenameExampleNFT = "ExampleNFT.cdc"
32-
filenameMetadataViews = "MetadataViews.cdc"
33-
filenameNFTMetadataViews = "NFTMetadataViews.cdc"
34-
filenameViewResolver = "ViewResolver.cdc"
35-
filenameUniversalCollection = "UniversalCollection.cdc"
36-
filenameBasicNFT = "BasicNFT.cdc"
37-
filenameFungibleToken = "utility/FungibleToken.cdc"
32+
filenameNonFungibleToken = "NonFungibleToken.cdc"
33+
filenameExampleNFT = "ExampleNFT.cdc"
34+
filenameMetadataViews = "MetadataViews.cdc"
35+
filenameCrossVMMetadataViews = "CrossVMMetadataViews.cdc"
36+
filenameNFTMetadataViews = "NFTMetadataViews.cdc"
37+
filenameViewResolver = "ViewResolver.cdc"
38+
filenameUniversalCollection = "UniversalCollection.cdc"
39+
filenameBasicNFT = "BasicNFT.cdc"
40+
filenameFungibleToken = "utility/FungibleToken.cdc"
3841
)
3942

4043
func withHexPrefix(address string) string {
@@ -84,6 +87,14 @@ func ViewResolver() []byte {
8487
return []byte(code)
8588
}
8689

90+
func CrossVMMetadataViews(evmAddress string) []byte {
91+
code := assets.MustAssetString(filenameCrossVMMetadataViews)
92+
93+
code = placeholderFungibleToken.ReplaceAllString(code, fungibleTokenImport+withHexPrefix(evmAddress))
94+
95+
return []byte(code)
96+
}
97+
8798
func UniversalCollection(nftAddress, resolverAddress, metadataAddress flow.Address) []byte {
8899
code := assets.MustAssetString(filenameUniversalCollection)
89100
code = placeholderMetadataViews.ReplaceAllString(code, metadataViewsImport+withHexPrefix(metadataAddress.String()))

lib/go/contracts/contracts_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,8 @@ func TestMetadataViewsContract(t *testing.T) {
3535
contract := contracts.MetadataViews(addrA, addrA, addrA)
3636
assert.NotNil(t, contract)
3737
}
38+
39+
func TestCrossVMMetadataViewsContract(t *testing.T) {
40+
contract := contracts.CrossVMMetadataViews(addrA)
41+
assert.NotNil(t, contract)
42+
}

0 commit comments

Comments
 (0)