Skip to content

Commit

Permalink
Merge pull request #6211 from onflow/jribbink/add-burner
Browse files Browse the repository at this point in the history
Add missing System Contracts
  • Loading branch information
janezpodhostnik authored Jul 15, 2024
2 parents aa5cd6a + 73970f8 commit 2f0d0de
Showing 1 changed file with 47 additions and 26 deletions.
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

0 comments on commit 2f0d0de

Please sign in to comment.