Skip to content

Commit

Permalink
fix updated EVM dependency aliasing
Browse files Browse the repository at this point in the history
  • Loading branch information
sisyphusSmiling committed Apr 15, 2024
1 parent ff89295 commit e73a0a1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
2 changes: 2 additions & 0 deletions cmd/util/ledger/migrations/change_contract_code_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ func SystemContractChanges(chainID flow.ChainID, options SystemContractsMigratio
NewSystemContractChange(
systemContracts.EVMContract,
evm.ContractCode(
flow.HexToAddress(env.NonFungibleTokenAddress),
flow.HexToAddress(env.FungibleTokenAddress),
flow.HexToAddress(env.FlowTokenAddress),
),
),
Expand Down
6 changes: 3 additions & 3 deletions fvm/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ func (b *bootstrapExecutor) Execute() error {
b.deployStakingCollection(service, &env)

// sets up the EVM environment
b.setupEVM(service, fungibleToken, flowToken)
b.setupEVM(service, nonFungibleToken, fungibleToken, flowToken)

err = expectAccounts(systemcontracts.EVMStorageAccountIndex)
if err != nil {
Expand Down Expand Up @@ -895,7 +895,7 @@ func (b *bootstrapExecutor) setStakingAllowlist(
panicOnMetaInvokeErrf("failed to set staking allow-list: %s", txError, err)
}

func (b *bootstrapExecutor) setupEVM(serviceAddress, fungibleTokenAddress, flowTokenAddress flow.Address) {
func (b *bootstrapExecutor) setupEVM(serviceAddress, nonFungibleTokenAddress, fungibleTokenAddress, flowTokenAddress flow.Address) {
if b.setupEVMEnabled {
// account for storage
// we dont need to deploy anything to this account, but it needs to exist
Expand All @@ -906,7 +906,7 @@ func (b *bootstrapExecutor) setupEVM(serviceAddress, fungibleTokenAddress, flowT
// deploy the EVM contract to the service account
tx := blueprints.DeployContractTransaction(
serviceAddress,
stdlib.ContractCode(flowTokenAddress),
stdlib.ContractCode(nonFungibleTokenAddress, fungibleTokenAddress, flowTokenAddress),
stdlib.ContractName,
)
// WithEVMEnabled should only be used after we create an account for storage
Expand Down
19 changes: 15 additions & 4 deletions fvm/evm/stdlib/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,24 @@ import (
//go:embed contract.cdc
var contractCode string

var flowTokenImportPattern = regexp.MustCompile(`(?m)^import "FlowToken"\n`)
var nftImportPattern = regexp.MustCompile(`(?m)^import "NonFungibleToken"`)
var fungibleTokenImportPattern = regexp.MustCompile(`(?m)^import "FungibleToken"`)
var flowTokenImportPattern = regexp.MustCompile(`(?m)^import "FlowToken"`)

func ContractCode(flowTokenAddress flow.Address) []byte {
return []byte(flowTokenImportPattern.ReplaceAllString(
func ContractCode(nonFungibleTokenAddress, fungibleTokenAddress, flowTokenAddress flow.Address) []byte {
contractCode = nftImportPattern.ReplaceAllString(
contractCode,
fmt.Sprintf("import NonFungibleToken from %s", nonFungibleTokenAddress.HexWithPrefix()),
)
contractCode = fungibleTokenImportPattern.ReplaceAllString(
contractCode,
fmt.Sprintf("import FungibleToken from %s", fungibleTokenAddress.HexWithPrefix()),
)
contractCode = flowTokenImportPattern.ReplaceAllString(
contractCode,
fmt.Sprintf("import FlowToken from %s", flowTokenAddress.HexWithPrefix()),
))
)
return []byte(contractCode)
}

const ContractName = "EVM"
Expand Down
2 changes: 1 addition & 1 deletion fvm/evm/stdlib/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func deployContracts(
},
{
name: stdlib.ContractName,
code: stdlib.ContractCode(contractsAddress),
code: stdlib.ContractCode(contractsAddress, contractsAddress, contractsAddress),
},
}

Expand Down

0 comments on commit e73a0a1

Please sign in to comment.