Skip to content

Commit

Permalink
Merge #4536
Browse files Browse the repository at this point in the history
4536: Update bootstrapping to include nft and metadata views r=janezpodhostnik a=joshuahannan

In onflow/flow-core-contracts#370, we're adding metadata views to the `FlowToken` smart contract. For this, the contract needs to implement all the metadata views contracts. This PR updates the bootstrapping logic to deploy `NonFungibleToken`, `MetadataViews`, `ViewResolver`, and `FungibleTokenMetadataViews` and provide those import addresses to the `FlowToken` smart contract deployment.

Co-authored-by: Josh Hannan <hannanjoshua19@gmail.com>
Co-authored-by: Janez Podhostnik <janez.podhostnik@gmail.com>
Co-authored-by: Janez Podhostnik <67895329+janezpodhostnik@users.noreply.github.com>
  • Loading branch information
4 people authored Jul 17, 2023
2 parents f1d5a06 + fd4ffaf commit f1ba16c
Show file tree
Hide file tree
Showing 11 changed files with 336 additions and 51 deletions.
4 changes: 2 additions & 2 deletions cmd/util/cmd/execution-state-extract/export_report.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"EpochCounter": 0,
"PreviousStateCommitment": "18eb0e8beef7ce851e552ecd29c813fde0a9e6f0c5614d7615642076602a48cf",
"CurrentStateCommitment": "18eb0e8beef7ce851e552ecd29c813fde0a9e6f0c5614d7615642076602a48cf",
"PreviousStateCommitment": "1c9f9d343cb8d4610e0b2c1eb74d6ea2f2f8aef2d666281dc22870e3efaa607b",
"CurrentStateCommitment": "1c9f9d343cb8d4610e0b2c1eb74d6ea2f2f8aef2d666281dc22870e3efaa607b",
"ReportSucceeded": true
}
2 changes: 1 addition & 1 deletion engine/execution/state/bootstrap/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestBootstrapLedger(t *testing.T) {
}

func TestBootstrapLedger_ZeroTokenSupply(t *testing.T) {
expectedStateCommitmentBytes, _ := hex.DecodeString("60a1998dc3c2656758f76520d040e1612b14d80bae263dd0d1118aa7c7d6e4ee")
expectedStateCommitmentBytes, _ := hex.DecodeString("986c540657fdb3b4154311069d901223a3268492f678ae706010cd537cc328ad")
expectedStateCommitment, err := flow.ToStateCommitment(expectedStateCommitmentBytes)
require.NoError(t, err)

Expand Down
40 changes: 38 additions & 2 deletions fvm/blueprints/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,42 @@ func DeployFungibleTokenContractTransaction(fungibleToken flow.Address) *flow.Tr
contractName)
}

func DeployNonFungibleTokenContractTransaction(nonFungibleToken flow.Address) *flow.TransactionBody {
contract := contracts.NonFungibleToken()
contractName := "NonFungibleToken"
return DeployContractTransaction(
nonFungibleToken,
contract,
contractName)
}

func DeployMetadataViewsContractTransaction(fungibleToken, nonFungibleToken flow.Address) *flow.TransactionBody {
contract := contracts.MetadataViews(fungibleToken.HexWithPrefix(), nonFungibleToken.HexWithPrefix())
contractName := "MetadataViews"
return DeployContractTransaction(
nonFungibleToken,
contract,
contractName)
}

func DeployViewResolverContractTransaction(nonFungibleToken flow.Address) *flow.TransactionBody {
contract := contracts.ViewResolver()
contractName := "ViewResolver"
return DeployContractTransaction(
nonFungibleToken,
contract,
contractName)
}

func DeployFungibleTokenMetadataViewsContractTransaction(fungibleToken, nonFungibleToken flow.Address) *flow.TransactionBody {
contract := contracts.FungibleTokenMetadataViews(fungibleToken.Hex(), nonFungibleToken.Hex())
contractName := "FungibleTokenMetadataViews"
return DeployContractTransaction(
fungibleToken,
contract,
contractName)
}

//go:embed scripts/deployFlowTokenTransactionTemplate.cdc
var deployFlowTokenTransactionTemplate string

Expand All @@ -31,8 +67,8 @@ var createFlowTokenMinterTransactionTemplate string
//go:embed scripts/mintFlowTokenTransactionTemplate.cdc
var mintFlowTokenTransactionTemplate string

func DeployFlowTokenContractTransaction(service, fungibleToken, flowToken flow.Address) *flow.TransactionBody {
contract := contracts.FlowToken(fungibleToken.HexWithPrefix())
func DeployFlowTokenContractTransaction(service, fungibleToken, metadataViews, flowToken flow.Address) *flow.TransactionBody {
contract := contracts.FlowToken(fungibleToken.HexWithPrefix(), metadataViews.HexWithPrefix(), metadataViews.HexWithPrefix())

return flow.NewTransactionBody().
SetScript([]byte(deployFlowTokenTransactionTemplate)).
Expand Down
46 changes: 44 additions & 2 deletions fvm/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,9 @@ func (b *bootstrapExecutor) Execute() error {
service := b.createServiceAccount()

fungibleToken := b.deployFungibleToken()
flowToken := b.deployFlowToken(service, fungibleToken)
nonFungibleToken := b.deployNonFungibleToken(service)
b.deployMetadataViews(fungibleToken, nonFungibleToken)
flowToken := b.deployFlowToken(service, fungibleToken, nonFungibleToken)
storageFees := b.deployStorageFees(service, fungibleToken, flowToken)
feeContract := b.deployFlowFees(service, fungibleToken, flowToken, storageFees)

Expand Down Expand Up @@ -411,14 +413,54 @@ func (b *bootstrapExecutor) deployFungibleToken() flow.Address {
return fungibleToken
}

func (b *bootstrapExecutor) deployFlowToken(service, fungibleToken flow.Address) flow.Address {
func (b *bootstrapExecutor) deployNonFungibleToken(deployTo flow.Address) flow.Address {

txError, err := b.invokeMetaTransaction(
b.ctx,
Transaction(
blueprints.DeployNonFungibleTokenContractTransaction(deployTo),
0),
)
panicOnMetaInvokeErrf("failed to deploy non-fungible token contract: %s", txError, err)
return deployTo
}

func (b *bootstrapExecutor) deployMetadataViews(fungibleToken, nonFungibleToken flow.Address) {

txError, err := b.invokeMetaTransaction(
b.ctx,
Transaction(
blueprints.DeployMetadataViewsContractTransaction(fungibleToken, nonFungibleToken),
0),
)
panicOnMetaInvokeErrf("failed to deploy metadata views contract: %s", txError, err)

txError, err = b.invokeMetaTransaction(
b.ctx,
Transaction(
blueprints.DeployViewResolverContractTransaction(nonFungibleToken),
0),
)
panicOnMetaInvokeErrf("failed to deploy view resolver contract: %s", txError, err)

txError, err = b.invokeMetaTransaction(
b.ctx,
Transaction(
blueprints.DeployFungibleTokenMetadataViewsContractTransaction(fungibleToken, nonFungibleToken),
0),
)
panicOnMetaInvokeErrf("failed to deploy fungible token metadata views contract: %s", txError, err)
}

func (b *bootstrapExecutor) deployFlowToken(service, fungibleToken, metadataViews flow.Address) flow.Address {
flowToken := b.createAccount(b.accountKeys.FlowTokenAccountPublicKeys)
txError, err := b.invokeMetaTransaction(
b.ctx,
Transaction(
blueprints.DeployFlowTokenContractTransaction(
service,
fungibleToken,
metadataViews,
flowToken),
0),
)
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ require (
github.com/onflow/atree v0.6.0
github.com/onflow/cadence v0.39.12
github.com/onflow/flow v0.3.4
github.com/onflow/flow-core-contracts/lib/go/contracts v1.2.3
github.com/onflow/flow-core-contracts/lib/go/contracts v1.2.4-0.20230703193002-53362441b57d
github.com/onflow/flow-core-contracts/lib/go/templates v1.2.3
github.com/onflow/flow-go-sdk v0.41.6
github.com/onflow/flow-go/crypto v0.24.7
Expand Down Expand Up @@ -228,6 +228,7 @@ require (
github.com/multiformats/go-multistream v0.4.1 // indirect
github.com/multiformats/go-varint v0.0.7 // indirect
github.com/onflow/flow-ft/lib/go/contracts v0.7.0 // indirect
github.com/onflow/flow-nft/lib/go/contracts v1.1.0 // indirect
github.com/onflow/sdks v0.5.0 // indirect
github.com/onsi/ginkgo/v2 v2.9.7 // indirect
github.com/opencontainers/runtime-spec v1.0.2 // indirect
Expand Down
Loading

0 comments on commit f1ba16c

Please sign in to comment.