Skip to content

Commit

Permalink
Add EVMBridgedMetadata view (#288)
Browse files Browse the repository at this point in the history
* add evmbridgedmetadata view

* fix typo
  • Loading branch information
loic1 authored Feb 22, 2025
1 parent 3bfc5da commit bd638fe
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 6 deletions.
12 changes: 12 additions & 0 deletions contracts/TopShot.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,7 @@ access(all) contract TopShot: NonFungibleToken {
Type<MetadataViews.NFTCollectionData>(),
Type<MetadataViews.NFTCollectionDisplay>(),
Type<CrossVMMetadataViews.EVMPointer>(),
Type<MetadataViews.EVMBridgedMetadata>(),
Type<MetadataViews.Serial>(),
Type<MetadataViews.Traits>(),
Type<MetadataViews.Medias>()
Expand Down Expand Up @@ -801,6 +802,17 @@ access(all) contract TopShot: NonFungibleToken {
return TopShot.resolveContractView(resourceType: nil, viewType: Type<MetadataViews.NFTCollectionDisplay>())
case Type<CrossVMMetadataViews.EVMPointer>():
return TopShot.resolveContractView(resourceType: nil, viewType: Type<CrossVMMetadataViews.EVMPointer>())
case Type<MetadataViews.EVMBridgedMetadata>():
// Project-defined ERC721 EVM contract stores baseURI, name, and symbol in its own contract storage
// Name, symbol, and baseURI below are only used for legacy bridge-deployed ERC721 contract
return MetadataViews.EVMBridgedMetadata(
name: "NBA-Top-Shot",
symbol: "NBAT",
uri: MetadataViews.URI(
baseURI: ${EVMBASEURI},
value: self.id.toString()
)
)
case Type<MetadataViews.Traits>():
return self.resolveTraitsView()
case Type<MetadataViews.Medias>():
Expand Down
7 changes: 5 additions & 2 deletions lib/go/contracts/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ const (
defaultCrossVMMetadataViewsAddress = "CROSSVMMETADATAVIEWSADDRESS"
defaultNetwork = "${NETWORK}"
defaultEVMContractAddress = "${EVMCONTRACTADDRESS}"
defaultEVMBaseURI = "${EVMBASEURI}"
fastBreakFile = "FastBreakV1.cdc"
crossVMMetadataViewsFile = "imports/CrossVMMetadataViews.cdc"
)

// GenerateTopShotContract returns a copy
// of the topshot contract with the import addresses updated
func GenerateTopShotContract(ftAddr, nftAddr, metadataViewsAddr, viewResolverAddr, crossVMMetadataViewsAddr, evmAddr, topShotLockingAddr, royaltyAddr, network, flowEvmContractAddr string) []byte {
func GenerateTopShotContract(ftAddr, nftAddr, metadataViewsAddr, viewResolverAddr, crossVMMetadataViewsAddr, evmAddr, topShotLockingAddr, royaltyAddr, network, flowEvmContractAddr, evmBaseURI string) []byte {

topShotCode := assets.MustAssetString(topshotFile)

Expand All @@ -62,7 +63,9 @@ func GenerateTopShotContract(ftAddr, nftAddr, metadataViewsAddr, viewResolverAdd

codeWithEVMContractAddress := strings.ReplaceAll(codeWithNetwork, defaultEVMContractAddress, flowEvmContractAddr)

return []byte(codeWithEVMContractAddress)
codeWithEVMBaseURI := strings.ReplaceAll(codeWithEVMContractAddress, defaultEVMBaseURI, evmBaseURI)

return []byte(codeWithEVMBaseURI)
}

// GenerateTopShotShardedCollectionContract returns a copy
Expand Down
3 changes: 2 additions & 1 deletion lib/go/contracts/contracts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ var addrF = "0F"
var addrG = "0G"
var network = "mainnet"
var flowEvmContractAddr = "0x1234565789012345657890123456578901234565"
var evmBaseURI = "https://base.uri/moment/"

func TestTopShotContract(t *testing.T) {
contract := contracts.GenerateTopShotContract(addrA, addrA, addrA, addrA, addrA, addrA, addrA, addrA, network, flowEvmContractAddr)
contract := contracts.GenerateTopShotContract(addrA, addrA, addrA, addrA, addrA, addrA, addrA, addrA, network, flowEvmContractAddr, evmBaseURI)
assert.NotNil(t, contract)
}

Expand Down
6 changes: 3 additions & 3 deletions lib/go/contracts/internal/assets/assets.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/go/test/fast_break_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func TestFastBreak(t *testing.T) {
topShotRoyaltyAddr.String(),
Network,
FlowEvmContractAddr,
EvmBaseURI,
)
topshotAccountKey, topshotSigner := accountKeys.NewWithSigner()
topshotAddr, topshotAddrErr := adapter.CreateAccount(context.Background(), []*flow.AccountKey{topshotAccountKey}, []sdktemplates.Contract{
Expand Down
1 change: 1 addition & 0 deletions lib/go/test/locking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ func TestTopShotLocking(t *testing.T) {
env.FTSwitchboardAddress,
Network,
FlowEvmContractAddr,
EvmBaseURI,
)
fakeTopshotAccountKey, fakeTopshotSigner := accountKeys.NewWithSigner()
fakeTopshotAddress, _ := adapter.CreateAccount(context.Background(), []*flow.AccountKey{fakeTopshotAccountKey}, []sdktemplates.Contract{
Expand Down
3 changes: 3 additions & 0 deletions lib/go/test/topshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const (
ViewResolverReplaceAddress = `"ViewResolver"`
Network = `"mainnet"`
FlowEvmContractAddr = `"0x1234565789012345657890123456578901234565"`
EvmBaseURI = `"https://base.uri/moment/"`
)

// topshotTestContext will expose sugar for common actions needed to bootstrap testing
Expand Down Expand Up @@ -143,6 +144,7 @@ func NewTopShotTestBlockchain(t *testing.T) topshotTestBlockchain {
royaltyAddr.String(),
Network,
FlowEvmContractAddr,
EvmBaseURI,
)
topshotAccountKey, topshotSigner := accountKeys.NewWithSigner()
topshotAddr, err := adapter.CreateAccount(context.Background(), []*flow.AccountKey{topshotAccountKey}, []sdktemplates.Contract{
Expand Down Expand Up @@ -824,6 +826,7 @@ func TestTransferAdmin(t *testing.T) {
royaltyAddr.String(),
Network,
FlowEvmContractAddr,
EvmBaseURI,
)
topshotAccountKey, topshotSigner := accountKeys.NewWithSigner()
topshotAddr, _ := adapter.CreateAccount(context.Background(), []*flow.AccountKey{topshotAccountKey}, []sdktemplates.Contract{
Expand Down

0 comments on commit bd638fe

Please sign in to comment.