github.com/codingfuture/orig-energi3@v0.8.4/energi/contracts/test_deploy/2_genesis.js (about)

     1  // Copyright 2019 The Energi Core Authors
     2  // This file is part of the Energi Core library.
     3  //
     4  // The Energi Core library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The Energi Core library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the Energi Core library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  'use strict';
    18  
    19  const BackboneRewardV1 = artifacts.require('BackboneRewardV1');
    20  const BlacklistRegistryV1 = artifacts.require('BlacklistRegistryV1');
    21  const BlockRewardV1 = artifacts.require('BlockRewardV1');
    22  const CheckpointRegistryV1 = artifacts.require('CheckpointRegistryV1');
    23  const CheckpointRegistryV2 = artifacts.require('CheckpointRegistryV2');
    24  const Gen2Migration = artifacts.require('Gen2Migration');
    25  //const GenericProposalV1 = artifacts.require('GenericProposalV1');
    26  const GovernedProxy = artifacts.require('GovernedProxy');
    27  const MasternodeTokenV1 = artifacts.require('MasternodeTokenV1');
    28  const MasternodeTokenV2 = artifacts.require('MasternodeTokenV2');
    29  const MasternodeRegistryV1 = artifacts.require('MasternodeRegistryV1');
    30  const MasternodeRegistryV2 = artifacts.require('MasternodeRegistryV2');
    31  const SporkRegistryV1 = artifacts.require('SporkRegistryV1');
    32  const SporkRegistryV2 = artifacts.require('SporkRegistryV2');
    33  const StakerRewardV1 = artifacts.require('StakerRewardV1');
    34  const TreasuryV1 = artifacts.require('TreasuryV1');
    35  
    36  const MockProxy = artifacts.require("MockProxy");
    37  const MockContract = artifacts.require("MockContract");
    38  const MockSporkRegistry = artifacts.require("MockSporkRegistry");
    39  const MockProposal = artifacts.require("MockProposal");
    40  
    41  const common = require('../test/common');
    42  
    43  module.exports = async (deployer, _, accounts) => {
    44      try {
    45          // V1 instances
    46          await deployer.deploy(MockProxy);
    47          const mn_token_proxy = MockProxy.address;
    48          await deployer.deploy(MockProxy);
    49          const treasury_proxy = MockProxy.address;
    50          await deployer.deploy(MockProxy);
    51          const blacklist_registry = MockProxy.address;
    52          await deployer.deploy(MockProxy);
    53          const mn_registry_proxy = MockProxy.address;
    54          await deployer.deploy(MockProxy);
    55          const staker_proxy = MockProxy.address;
    56          await deployer.deploy(MockProxy);
    57          const backbone_proxy = MockProxy.address;
    58  
    59          const deploy_common = async (type, proxy, ...args) => {
    60              if (!proxy) {
    61                  await deployer.deploy(MockProxy);
    62                  proxy = MockProxy.address;
    63              }
    64  
    65              const instance = await deployer.deploy(type, proxy, ...args);
    66              await (await MockProxy.at(proxy)).setImpl(instance.address);
    67          };
    68  
    69          await deployer.deploy(Gen2Migration, blacklist_registry, common.chain_id, common.migration_signer);
    70  
    71          const compensation_fund = await TreasuryV1.new(treasury_proxy, mn_registry_proxy, 1);
    72          await deploy_common(BlacklistRegistryV1,
    73              blacklist_registry, mn_registry_proxy,
    74              Gen2Migration.address, compensation_fund.address,
    75              accounts[3],
    76              { gas: "10000000" });
    77          await deploy_common(BackboneRewardV1, backbone_proxy, accounts[5]);
    78          await deploy_common(CheckpointRegistryV1, undefined, mn_registry_proxy, common.cpp_signer);
    79          await deploy_common(CheckpointRegistryV2, undefined, mn_registry_proxy, common.cpp_signer);
    80          await deploy_common(MasternodeTokenV1, mn_token_proxy, mn_registry_proxy);
    81          await deploy_common(MasternodeTokenV2, mn_token_proxy, mn_registry_proxy);
    82          await deploy_common(MasternodeRegistryV1,
    83              mn_registry_proxy, mn_token_proxy, treasury_proxy,
    84              common.mnregistry_config);
    85          await deploy_common(MasternodeRegistryV2,
    86              mn_registry_proxy, mn_token_proxy, treasury_proxy,
    87              common.mnregistry_config_v2, common.mnreg_deploy_opts);
    88          await deploy_common(SporkRegistryV1, undefined, mn_registry_proxy);
    89          await deploy_common(SporkRegistryV2, undefined, mn_registry_proxy, common.emergency_signer);
    90          await deploy_common(StakerRewardV1, staker_proxy);
    91          await deploy_common(TreasuryV1, treasury_proxy, mn_registry_proxy, common.superblock_cycles);
    92          await deploy_common(BlockRewardV1, undefined, [
    93              staker_proxy,
    94              backbone_proxy,
    95              treasury_proxy,
    96              mn_registry_proxy,
    97          ]);
    98  
    99          // For unit test
   100          await deployer.deploy(GovernedProxy, BackboneRewardV1.address, SporkRegistryV1.address);
   101          await deployer.deploy(MockProxy);
   102          await deployer.deploy(MockContract, MockProxy.address);
   103          await deployer.deploy(MockSporkRegistry, MockProxy.address);
   104          await deployer.deploy(MockProposal, MockProxy.address, MockContract.address);
   105          //await deployer.deploy(GenericProposalV1, mn_registry_proxy, 1, 1, mn_registry_proxy)
   106      } catch (e) {
   107          // eslint-disable-next-line no-console
   108          console.dir(e);
   109          throw e;
   110      }
   111  };