Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing System Contracts #6211

Merged
merged 2 commits into from
Jul 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 47 additions & 26 deletions fvm/systemcontracts/system_contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,24 @@ import (
const (
// Unqualified names of system smart contracts (not including address prefix)

ContractNameEpoch = "FlowEpoch"
ContractNameIDTableStaking = "FlowIDTableStaking"
ContractNameClusterQC = "FlowClusterQC"
ContractNameDKG = "FlowDKG"
ContractNameServiceAccount = "FlowServiceAccount"
ContractNameFlowFees = "FlowFees"
ContractNameStorageFees = "FlowStorageFees"
ContractNameNodeVersionBeacon = "NodeVersionBeacon"
ContractNameRandomBeaconHistory = "RandomBeaconHistory"
ContractNameFungibleToken = "FungibleToken"
ContractNameFlowToken = "FlowToken"
ContractNameNonFungibleToken = "NonFungibleToken"
ContractNameMetadataViews = "MetadataViews"
ContractNameViewResolver = "ViewResolver"
ContractNameEVM = "EVM"
ContractNameEpoch = "FlowEpoch"
ContractNameIDTableStaking = "FlowIDTableStaking"
ContractNameClusterQC = "FlowClusterQC"
ContractNameDKG = "FlowDKG"
ContractNameServiceAccount = "FlowServiceAccount"
ContractNameFlowFees = "FlowFees"
ContractNameStorageFees = "FlowStorageFees"
ContractNameNodeVersionBeacon = "NodeVersionBeacon"
ContractNameRandomBeaconHistory = "RandomBeaconHistory"
ContractNameFungibleToken = "FungibleToken"
ContractNameFlowToken = "FlowToken"
ContractNameFungibleTokenSwitchboard = "FungibleTokenSwitchboard"
ContractNameFungibleTokenMetadataViews = "FungibleTokenMetadataViews"
ContractNameNonFungibleToken = "NonFungibleToken"
ContractNameMetadataViews = "MetadataViews"
ContractNameViewResolver = "ViewResolver"
ContractNameEVM = "EVM"
ContractNameBurner = "Burner"

// AccountNameEVMStorage is not a contract, but a special account that is used to store EVM state
AccountNameEVMStorage = "EVMStorageAccount"
Expand Down Expand Up @@ -145,6 +148,7 @@ type SystemContracts struct {
FlowFees SystemContract
FlowToken SystemContract
FungibleToken SystemContract
FungibleTokenSwitchboard SystemContract
FungibleTokenMetadataViews SystemContract

// NFT related contracts
Expand All @@ -155,6 +159,9 @@ type SystemContracts struct {
// EVM related contracts
EVMContract SystemContract
EVMStorage SystemAccount

// Utility contracts
Burner SystemContract
}

// AsTemplateEnv returns a template environment with all system contracts filled in.
Expand All @@ -174,12 +181,14 @@ func (c SystemContracts) AsTemplateEnv() templates.Environment {
FlowFeesAddress: c.FlowFees.Address.Hex(),
FlowTokenAddress: c.FlowToken.Address.Hex(),
FungibleTokenAddress: c.FungibleToken.Address.Hex(),
FungibleTokenMetadataViewsAddress: c.FungibleToken.Address.Hex(),
FungibleTokenSwitchboardAddress: c.FungibleTokenSwitchboard.Address.Hex(),
FungibleTokenMetadataViewsAddress: c.FungibleTokenMetadataViews.Address.Hex(),

NonFungibleTokenAddress: c.NonFungibleToken.Address.Hex(),
MetadataViewsAddress: c.MetadataViews.Address.Hex(),
ViewResolverAddress: c.ViewResolver.Address.Hex(),

NonFungibleTokenAddress: c.NonFungibleToken.Address.Hex(),
MetadataViewsAddress: c.MetadataViews.Address.Hex(),
ViewResolverAddress: c.ViewResolver.Address.Hex(),
FungibleTokenSwitchboardAddress: c.FungibleToken.Address.Hex(),
BurnerAddress: c.Burner.Address.Hex(),
}
}

Expand All @@ -199,13 +208,17 @@ func (c SystemContracts) All() []SystemContract {
c.FlowFees,
c.FlowToken,
c.FungibleToken,
c.FungibleTokenMetadataViews,
c.FungibleTokenSwitchboard,

c.NonFungibleToken,
c.MetadataViews,
c.ViewResolver,

c.EVMContract,
// EVMStorage is not included here, since it is not a contract

c.Burner,
}
}

Expand Down Expand Up @@ -318,16 +331,20 @@ func init() {
ContractNameServiceAccount: serviceAddressFunc,
ContractNameStorageFees: serviceAddressFunc,

ContractNameFlowFees: nthAddressFunc(FlowFeesAccountIndex),
ContractNameFungibleToken: nthAddressFunc(FungibleTokenAccountIndex),
ContractNameFlowToken: nthAddressFunc(FlowTokenAccountIndex),
ContractNameFlowFees: nthAddressFunc(FlowFeesAccountIndex),
ContractNameFungibleToken: nthAddressFunc(FungibleTokenAccountIndex),
ContractNameFlowToken: nthAddressFunc(FlowTokenAccountIndex),
ContractNameFungibleTokenSwitchboard: nthAddressFunc(FungibleTokenAccountIndex),
ContractNameFungibleTokenMetadataViews: nthAddressFunc(FungibleTokenAccountIndex),

ContractNameNonFungibleToken: nftTokenAddressFunc,
ContractNameMetadataViews: nftTokenAddressFunc,
ContractNameViewResolver: nftTokenAddressFunc,

ContractNameEVM: serviceAddressFunc,
AccountNameEVMStorage: evmStorageEVMFunc,

ContractNameBurner: serviceAddressFunc,
}

getSystemContractsForChain := func(chainID flow.ChainID) *SystemContracts {
Expand Down Expand Up @@ -369,16 +386,20 @@ func init() {
RandomBeaconHistory: addressOfContract(ContractNameRandomBeaconHistory),
FlowStorageFees: addressOfContract(ContractNameStorageFees),

FlowFees: addressOfContract(ContractNameFlowFees),
FlowToken: addressOfContract(ContractNameFlowToken),
FungibleToken: addressOfContract(ContractNameFungibleToken),
FlowFees: addressOfContract(ContractNameFlowFees),
FlowToken: addressOfContract(ContractNameFlowToken),
FungibleToken: addressOfContract(ContractNameFungibleToken),
FungibleTokenMetadataViews: addressOfContract(ContractNameFungibleTokenMetadataViews),
FungibleTokenSwitchboard: addressOfContract(ContractNameFungibleTokenSwitchboard),

NonFungibleToken: addressOfContract(ContractNameNonFungibleToken),
MetadataViews: addressOfContract(ContractNameMetadataViews),
ViewResolver: addressOfContract(ContractNameViewResolver),

EVMContract: addressOfContract(ContractNameEVM),
EVMStorage: addressOfAccount(AccountNameEVMStorage),

Burner: addressOfContract(ContractNameBurner),
}

return contracts
Expand Down
Loading