From 368844ad2a28ec07848e3c0169cf2b83b579a2e8 Mon Sep 17 00:00:00 2001 From: Aaron Buchwald Date: Mon, 23 Nov 2020 20:46:35 -0500 Subject: Add native asset precompiled contracts for apricot release --- plugin/evm/export_tx.go | 3 ++- plugin/evm/import_tx.go | 3 ++- plugin/evm/vm.go | 9 +++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) (limited to 'plugin') diff --git a/plugin/evm/export_tx.go b/plugin/evm/export_tx.go index 2735573..2ebfeff 100644 --- a/plugin/evm/export_tx.go +++ b/plugin/evm/export_tx.go @@ -240,8 +240,8 @@ func (vm *VM) newExportTx( func (tx *UnsignedExportTx) EVMStateTransfer(vm *VM, state *state.StateDB) error { addrs := map[[20]byte]uint64{} for _, from := range tx.Ins { - log.Info("crosschain C->X", "addr", from.Address, "amount", from.Amount) if from.AssetID == vm.ctx.AVAXAssetID { + log.Info("crosschain C->X", "from", from.Address, "amount", from.Amount, "assetID", "AVAX") amount := new(big.Int).Mul( new(big.Int).SetUint64(from.Amount), x2cRate) if state.GetBalance(from.Address).Cmp(amount) < 0 { @@ -250,6 +250,7 @@ func (tx *UnsignedExportTx) EVMStateTransfer(vm *VM, state *state.StateDB) error state.SubBalance(from.Address, amount) } else { amount := new(big.Int).SetUint64(from.Amount) + log.Info("crosschain C->X", "from", from.Address, "amount", from.Amount, "assetID", from.AssetID) if state.GetBalanceMultiCoin(from.Address, common.Hash(from.AssetID)).Cmp(amount) < 0 { return errInsufficientFunds } diff --git a/plugin/evm/import_tx.go b/plugin/evm/import_tx.go index 1ec394c..d6b4b7d 100644 --- a/plugin/evm/import_tx.go +++ b/plugin/evm/import_tx.go @@ -270,12 +270,13 @@ func (vm *VM) newImportTx( // accounts accordingly with the imported EVMOutputs func (tx *UnsignedImportTx) EVMStateTransfer(vm *VM, state *state.StateDB) error { for _, to := range tx.Outs { - log.Info("crosschain X->C", "addr", to.Address, "amount", to.Amount) if to.AssetID == vm.ctx.AVAXAssetID { + log.Info("crosschain X->C", "to", to.Address, "amount", to.Amount, "assetID", "AVAX") amount := new(big.Int).Mul( new(big.Int).SetUint64(to.Amount), x2cRate) state.AddBalance(to.Address, amount) } else { + log.Info("crosschain X->C", "to", to.Address, "amount", to.Amount, "assetID", to.AssetID) amount := new(big.Int).SetUint64(to.Amount) state.AddBalanceMultiCoin(to.Address, common.Hash(to.AssetID), amount) } diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index c9bdad9..fc571b9 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -239,6 +239,15 @@ func (vm *VM) Initialize( return err } + // Set the Apricot Fork Block on the ChainConfig + // TODO switch to correct block number of the fork + switch { + case g.Config.ChainID.Cmp(params.AvalancheMainnetChainID) == 0: + g.Config.ApricotBlock = nil + case g.Config.ChainID.Cmp(params.AvalancheFujiChainID) == 0: + g.Config.ApricotBlock = nil + } + vm.acceptedDB = prefixdb.New([]byte(acceptedPrefix), db) vm.chainID = g.Config.ChainID -- cgit v1.2.3 From cc2a13f91f95bd377f5c3efb86ebbcc7096f6d97 Mon Sep 17 00:00:00 2001 From: Aaron Buchwald Date: Tue, 15 Dec 2020 17:30:03 -0500 Subject: Set chain rules based on block times for mainnet/fuji --- plugin/evm/vm.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'plugin') diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index fc571b9..2732a79 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -243,11 +243,10 @@ func (vm *VM) Initialize( // TODO switch to correct block number of the fork switch { case g.Config.ChainID.Cmp(params.AvalancheMainnetChainID) == 0: - g.Config.ApricotBlock = nil + g.Config = params.AvalancheApricotMainnetChainConfig case g.Config.ChainID.Cmp(params.AvalancheFujiChainID) == 0: - g.Config.ApricotBlock = nil + g.Config = params.AvalancheApricotFujiChainConfig } - vm.acceptedDB = prefixdb.New([]byte(acceptedPrefix), db) vm.chainID = g.Config.ChainID -- cgit v1.2.3 From faf845717a170e1c4baebaafef051d32058e2f99 Mon Sep 17 00:00:00 2001 From: Aaron Buchwald Date: Tue, 15 Dec 2020 17:34:48 -0500 Subject: Move params for network upgrade --- plugin/evm/vm.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'plugin') diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index 2732a79..9f5607a 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -239,13 +239,13 @@ func (vm *VM) Initialize( return err } - // Set the Apricot Fork Block on the ChainConfig - // TODO switch to correct block number of the fork + // If Mainnet or Fuji ChainID is present then switch + // manually set the config switch { case g.Config.ChainID.Cmp(params.AvalancheMainnetChainID) == 0: - g.Config = params.AvalancheApricotMainnetChainConfig + g.Config.ApricotBlockTimestamp = params.AvalancheMainnetApricotTimestamp case g.Config.ChainID.Cmp(params.AvalancheFujiChainID) == 0: - g.Config = params.AvalancheApricotFujiChainConfig + g.Config.ApricotBlockTimestamp = params.AvalancheFujiApricotTimestamp } vm.acceptedDB = prefixdb.New([]byte(acceptedPrefix), db) -- cgit v1.2.3