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

Use core-contracts templates that use Environment #5401

Merged
merged 19 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
13 changes: 7 additions & 6 deletions cmd/util/cmd/epochs/cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,15 @@ func getDeployEpochTransactionText(snapshot *inmem.Snapshot) []byte {
chainID := head.ChainID
systemContracts := systemcontracts.SystemContractsForChain(chainID)

env := systemContracts.AsTemplateEnv()
env.FungibleTokenAddress = flagFungibleTokenAddress
env.FlowTokenAddress = flagFlowTokenAddress
env.IDTableAddress = flagIDTableAddress
env.FlowFeesAddress = flagFlowFeesAddress

// epoch contract name and get code for contract
epochContractCode := contracts.FlowEpoch(
flagFungibleTokenAddress,
flagFlowTokenAddress,
flagIDTableAddress,
systemContracts.ClusterQC.Address.Hex(),
systemContracts.DKG.Address.Hex(),
flagFlowFeesAddress,
env,
)

// convert the epoch contract code to an [UInt8] literal string that can be
Expand Down
131 changes: 33 additions & 98 deletions cmd/util/ledger/migrations/change_contract_code_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@
import (
"fmt"

coreContracts "github.com/onflow/flow-core-contracts/lib/go/contracts"
ftContracts "github.com/onflow/flow-ft/lib/go/contracts"
nftContracts "github.com/onflow/flow-nft/lib/go/contracts"

sdk "github.com/onflow/flow-go-sdk"

"github.com/onflow/cadence/runtime/common"
coreContracts "github.com/onflow/flow-core-contracts/lib/go/contracts"

evm "github.com/onflow/flow-go/fvm/evm/stdlib"
"github.com/onflow/flow-go/fvm/systemcontracts"
Expand Down Expand Up @@ -77,64 +72,40 @@
func SystemContractChanges(chainID flow.ChainID, options SystemContractChangesOptions) []StagedContract {
systemContracts := systemcontracts.SystemContractsForChain(chainID)

serviceAccountAddress := systemContracts.FlowServiceAccount.Address
idTableStakingAddress := systemContracts.IDTableStaking.Address
clusterQCAddress := systemContracts.ClusterQC.Address
dkgAddress := systemContracts.DKG.Address
fungibleTokenAddress := systemContracts.FungibleToken.Address
flowTokenAddress := systemContracts.FlowToken.Address
flowFeesAddress := systemContracts.FlowFees.Address
flowStorageFeesAddress := systemContracts.FlowStorageFees.Address
viewResolverAddress := systemContracts.ViewResolver.Address
metadataViewsAddress := systemContracts.MetadataViews.Address
fungibleTokenMetadataViewsAddress := common.Address(fungibleTokenAddress)
fungibleTokenSwitchboardAddress := common.Address(fungibleTokenAddress)

burnerAddress := BurnerAddressForChain(chainID)

var stakingCollectionAddress common.Address
var stakingProxyAddress common.Address
env := systemContracts.AsTemplateEnv()
env.BurnerAddress = BurnerAddressForChain(chainID).Hex()

switch chainID {
case flow.Mainnet:
stakingCollectionAddress = mustHexAddress("0x8d0e87b65159ae63")
stakingProxyAddress = mustHexAddress("0x62430cf28c26d095")
env.StakingCollectionAddress = "0x8d0e87b65159ae63"
env.StakingProxyAddress = "0x62430cf28c26d095"

case flow.Testnet:
stakingCollectionAddress = mustHexAddress("0x95e019a17d0e23d7")
stakingProxyAddress = mustHexAddress("0x7aad92e5a0715d21")
env.StakingCollectionAddress = "0x95e019a17d0e23d7"
env.StakingProxyAddress = "0x7aad92e5a0715d21"

case flow.Emulator, flow.Localnet:
stakingCollectionAddress = common.Address(serviceAccountAddress)
stakingProxyAddress = common.Address(serviceAccountAddress)
env.StakingCollectionAddress = env.ServiceAccountAddress
env.StakingProxyAddress = env.ServiceAccountAddress

default:
panic(fmt.Errorf("unsupported chain ID: %s", chainID))
}

lockedTokensAddress := stakingCollectionAddress
env.LockedTokensAddress = env.StakingCollectionAddress

contractChanges := []StagedContract{
// epoch related contracts
NewSystemContractChange(
systemContracts.Epoch,
coreContracts.FlowEpoch(
fungibleTokenAddress.HexWithPrefix(),
flowTokenAddress.HexWithPrefix(),
idTableStakingAddress.HexWithPrefix(),
clusterQCAddress.HexWithPrefix(),
dkgAddress.HexWithPrefix(),
flowFeesAddress.HexWithPrefix(),
env,
),
),
NewSystemContractChange(
systemContracts.IDTableStaking,
coreContracts.FlowIDTableStaking(
fungibleTokenAddress.HexWithPrefix(),
flowTokenAddress.HexWithPrefix(),
flowFeesAddress.HexWithPrefix(),
burnerAddress.HexWithPrefix(),
true,
env,
),
),
NewSystemContractChange(
Expand All @@ -150,10 +121,7 @@
NewSystemContractChange(
systemContracts.FlowServiceAccount,
coreContracts.FlowServiceAccount(
fungibleTokenAddress.HexWithPrefix(),
flowTokenAddress.HexWithPrefix(),
flowFeesAddress.HexWithPrefix(),
flowStorageFeesAddress.HexWithPrefix(),
env,
),
),
NewSystemContractChange(
Expand All @@ -167,105 +135,74 @@
NewSystemContractChange(
systemContracts.FlowStorageFees,
coreContracts.FlowStorageFees(
fungibleTokenAddress.HexWithPrefix(),
flowTokenAddress.HexWithPrefix(),
env,
),
),
{
Address: stakingCollectionAddress,
Address: common.Address(flow.HexToAddress(env.StakingCollectionAddress)),
Contract: Contract{
Name: "FlowStakingCollection",
Code: coreContracts.FlowStakingCollection(
fungibleTokenAddress.HexWithPrefix(),
flowTokenAddress.HexWithPrefix(),
idTableStakingAddress.HexWithPrefix(),
stakingProxyAddress.HexWithPrefix(),
lockedTokensAddress.HexWithPrefix(),
flowStorageFeesAddress.HexWithPrefix(),
clusterQCAddress.HexWithPrefix(),
dkgAddress.HexWithPrefix(),
systemContracts.Epoch.Address.HexWithPrefix(),
),
Code: coreContracts.FlowStakingCollection(env),
},
},
{
Address: stakingProxyAddress,
Address: common.Address(flow.HexToAddress(env.StakingProxyAddress)),
Contract: Contract{
Name: "StakingProxy",
Code: coreContracts.FlowStakingProxy(),
},
},
{
Address: lockedTokensAddress,
Address: common.Address(flow.HexToAddress(env.LockedTokensAddress)),
Contract: Contract{
Name: "LockedTokens",
Code: coreContracts.FlowLockedTokens(
fungibleTokenAddress.HexWithPrefix(),
flowTokenAddress.HexWithPrefix(),
idTableStakingAddress.HexWithPrefix(),
stakingProxyAddress.HexWithPrefix(),
flowStorageFeesAddress.HexWithPrefix(),
),
Code: coreContracts.FlowLockedTokens(env),
},
},

// token related contracts
NewSystemContractChange(
systemContracts.FlowFees,
coreContracts.FlowFees(
fungibleTokenAddress.HexWithPrefix(),
flowTokenAddress.HexWithPrefix(),
flowStorageFeesAddress.HexWithPrefix(),
env,
),
),
NewSystemContractChange(
systemContracts.FlowToken,
coreContracts.FlowToken(
fungibleTokenAddress.HexWithPrefix(),
fungibleTokenMetadataViewsAddress.HexWithPrefix(),
metadataViewsAddress.HexWithPrefix(),
burnerAddress.HexWithPrefix(),
env,
),
),
NewSystemContractChange(
systemContracts.FungibleToken,
ftContracts.FungibleToken(
// Use `Hex()`, since this method adds the prefix.
viewResolverAddress.Hex(),
burnerAddress.Hex(),
coreContracts.FungibleToken(
env,
),
),
{
Address: fungibleTokenMetadataViewsAddress,
Address: common.Address(flow.HexToAddress(env.FungibleTokenMetadataViewsAddress)),
Contract: Contract{
Name: "FungibleTokenMetadataViews",
Code: ftContracts.FungibleTokenMetadataViews(
// Use `Hex()`, since this method adds the prefix.
fungibleTokenAddress.Hex(),
metadataViewsAddress.Hex(),
viewResolverAddress.Hex(),
),
Code: coreContracts.FungibleTokenMetadataViews(env),
},
},

// NFT related contracts
NewSystemContractChange(
systemContracts.NonFungibleToken,
nftContracts.NonFungibleToken(
sdk.Address(viewResolverAddress),
coreContracts.NonFungibleToken(
env,
),
),
NewSystemContractChange(
systemContracts.MetadataViews,
nftContracts.MetadataViews(
sdk.Address(fungibleTokenAddress),
sdk.Address(systemContracts.NonFungibleToken.Address),
sdk.Address(viewResolverAddress),
coreContracts.MetadataViews(
env,
),
),
NewSystemContractChange(
systemContracts.ViewResolver,
nftContracts.ViewResolver(),
coreContracts.ViewResolver(),
),
}

Expand All @@ -277,12 +214,10 @@
contractChanges = append(
contractChanges,
StagedContract{
Address: fungibleTokenSwitchboardAddress,
Address: common.Address(flow.HexToAddress(env.FungibleTokenSwitchboardAddress)),
Contract: Contract{
Name: "FungibleTokenSwitchboard",
Code: ftContracts.FungibleTokenSwitchboard(
fungibleTokenAddress.HexWithPrefix(),
),
Code: coreContracts.FungibleTokenSwitchboard(env),
},
},
)
Expand All @@ -299,7 +234,7 @@
NewSystemContractChange(
systemContracts.EVMContract,
evm.ContractCode(
flowTokenAddress,
flow.HexToAddress(env.FlowTokenAddress),
abiOnly,
),
),
Expand All @@ -311,7 +246,7 @@
return contractChanges
}

func mustHexAddress(hexAddress string) common.Address {

Check failure on line 249 in cmd/util/ledger/migrations/change_contract_code_migration.go

View workflow job for this annotation

GitHub Actions / Lint (./)

func `mustHexAddress` is unused (unused)
address, err := common.HexToAddress(hexAddress)
if err != nil {
panic(err)
Expand Down
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("60d6e4db7b60d4a36770b171fd6991bc4ab973eba1c513f9352ca3e6fd1782df")
expectedStateCommitmentBytes, _ := hex.DecodeString("aaedf522051619566e1042948e961edab3b609757225d6781d022066d42f06e6")
expectedStateCommitment, err := flow.ToStateCommitment(expectedStateCommitmentBytes)
require.NoError(t, err)

Expand Down
1 change: 1 addition & 0 deletions fvm/blueprints/epochs.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func DeployEpochTransaction(service flow.Address, contract []byte, epochConfig e
},
),
)).
AddArgument(jsoncdc.MustEncode(cadence.String("FlowEpoch"))).
AddArgument(jsoncdc.MustEncode(cadence.String(hex.EncodeToString(contract)))).
AddArgument(jsoncdc.MustEncode(epochConfig.CurrentEpochCounter)).
AddArgument(jsoncdc.MustEncode(epochConfig.NumViewsInEpoch)).
Expand Down
8 changes: 1 addition & 7 deletions fvm/blueprints/fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/onflow/cadence"
jsoncdc "github.com/onflow/cadence/encoding/json"
"github.com/onflow/cadence/runtime/common"
"github.com/onflow/flow-core-contracts/lib/go/contracts"
"github.com/onflow/flow-core-contracts/lib/go/templates"

"github.com/onflow/flow-go/model/flow"
Expand Down Expand Up @@ -45,12 +44,7 @@ var setupFeesTransactionTemplate string
//go:embed scripts/setExecutionMemoryLimit.cdc
var setExecutionMemoryLimit string

func DeployTxFeesContractTransaction(service, fungibleToken, flowToken, storageFees, flowFees flow.Address) *flow.TransactionBody {
contract := contracts.FlowFees(
fungibleToken.HexWithPrefix(),
flowToken.HexWithPrefix(),
storageFees.HexWithPrefix(),
)
func DeployTxFeesContractTransaction(flowFees, service flow.Address, contract []byte) *flow.TransactionBody {

return flow.NewTransactionBody().
SetScript([]byte(deployTxFeesTransactionTemplate)).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import FlowToken from 0xFLOWTOKENADDRESS
import FlowToken from "FlowToken"

transaction {
prepare(serviceAccount: auth(Storage) &Account) {
Expand Down
5 changes: 3 additions & 2 deletions fvm/blueprints/scripts/deployEpochTransactionTemplate.cdc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import FlowClusterQC from 0xQCADDRESS
import FlowClusterQC from "FlowClusterQC"

transaction(
name: String,
code: String,
currentEpochCounter: UInt64,
numViewsInEpoch: UInt64,
Expand All @@ -21,7 +22,7 @@ transaction(
}

serviceAccount.contracts.add(
name: "FlowEpoch",
name: name,
code: code.decodeHex(),
currentEpochCounter: currentEpochCounter,
numViewsInEpoch: numViewsInEpoch,
Expand Down
4 changes: 2 additions & 2 deletions fvm/blueprints/scripts/fundAccountTemplate.cdc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import FungibleToken from 0xFUNGIBLETOKENADDRESS
import FlowToken from 0xFLOWTOKENADDRESS
import FungibleToken from "FungibleToken"
import FlowToken from "FlowToken"

transaction(amount: UFix64, recipient: Address) {

Expand Down
4 changes: 2 additions & 2 deletions fvm/blueprints/scripts/mintFlowTokenTransactionTemplate.cdc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import FungibleToken from 0xFUNGIBLETOKENADDRESS
import FlowToken from 0xFLOWTOKENADDRESS
import FungibleToken from "FungibleToken"
import FlowToken from "FlowToken"

transaction(amount: UFix64) {

Expand Down
4 changes: 2 additions & 2 deletions fvm/blueprints/scripts/setupAccountTemplate.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// to add a Vault resource to their account
// so that they can use the flowToken

import FungibleToken from 0xFUNGIBLETOKENADDRESS
import FlowToken from 0xFLOWTOKENADDRESS
import FungibleToken from "FungibleToken"
import FlowToken from "FlowToken"

transaction {

Expand Down
2 changes: 1 addition & 1 deletion fvm/blueprints/scripts/setupFeesTransactionTemplate.cdc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import FlowFees from 0xFLOWFEESADDRESS
import FlowFees from "FlowFees"

transaction(surgeFactor: UFix64, inclusionEffortCost: UFix64, executionEffortCost: UFix64) {
prepare(service: auth(BorrowValue) &Account) {
Expand Down
4 changes: 2 additions & 2 deletions fvm/blueprints/scripts/setupParametersTransactionTemplate.cdc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import FlowStorageFees from 0xFLOWSTORAGEFEESADDRESS
import FlowServiceAccount from 0xFLOWSERVICEADDRESS
import FlowStorageFees from "FlowStorageFees"
import FlowServiceAccount from "FlowServiceAccount"

transaction(accountCreationFee: UFix64, minimumStorageReservation: UFix64, storageMegaBytesPerReservedFLOW: UFix64, restrictedAccountCreationEnabled: Bool) {

Expand Down
8 changes: 4 additions & 4 deletions fvm/blueprints/scripts/setupStorageForAccount.cdc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import FlowServiceAccount from 0xFLOWSERVICEADDRESS
import FlowStorageFees from 0xFLOWSTORAGEFEESADDRESS
import FungibleToken from 0xFUNGIBLETOKENADDRESS
import FlowToken from 0xFLOWTOKENADDRESS
import FlowServiceAccount from "FlowServiceAccount"
import FlowStorageFees from "FlowStorageFees"
import FungibleToken from "FungibleToken"
import FlowToken from "FlowToken"

// This transaction sets up storage on a auth account.
// This is used during bootstrapping a local environment
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import FlowServiceAccount from 0xFLOWSERVICEADDRESS
import FlowStorageFees from 0xFLOWSTORAGEFEESADDRESS
import FungibleToken from 0xFUNGIBLETOKENADDRESS
import FlowToken from 0xFLOWTOKENADDRESS
import FlowServiceAccount from "FlowServiceAccount"
import FlowStorageFees from "FlowStorageFees"
import FungibleToken from "FungibleToken"
import FlowToken from "FlowToken"

// This transaction sets up storage on any auth accounts that were created before the storage fees.
// This is used during bootstrapping a local environment
Expand Down
Loading
Loading