contracts icon indicating copy to clipboard operation
contracts copied to clipboard

Request for Hardhat Deployment Example for TokenStake Contract

Open terry1ee opened this issue 1 year ago • 1 comments

Description

I am planning to deploy the TokenStake contract using Hardhat and would appreciate guidance on the recommended deployment procedure. I am particularly interested in understanding the best practices for deploying this contract with initializer functions and potential proxy setups for upgradability.

Request

Could you provide a detailed Hardhat deployment script example for the TokenStake contract? I am looking for guidance on:

  1. Proper handling of constructor and initializer parameters.
  2. Recommendations for setting up proxies if necessary for upgradability.
  3. Any specific Hardhat configurations or plugins that are recommended for this deployment.

This example will help ensure that I am implementing the deployment process correctly and leveraging the best practices you recommend.

Thank you for your support and assistance.

terry1ee avatar May 07 '24 09:05 terry1ee

I tried to deploy using the following Hardhat Ignition script but encountered an error.

import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";

const TokenStakeModule = buildModule("TokenStakeModule", (m) => {
  const nativeTokenWrapper = m.getParameter(
    "nativeTokenWrapper",
    "0xdf572718C075C93544F5624ebF7B26bBb85ca8CE"
  );
  const defaultAdmin = m.getParameter("defaultAdmin", m.getAccount(0));
  const contractURI = m.getParameter("contractURI", "ipfs://...");
  const trustedForwarders = m.getParameter("trustedForwarders", []);
  const rewardToken = m.getParameter(
    "rewardToken",
    "0xB3c3327A98a1F9b055b404F4b1629367d074C7eC"
  );
  const stakingToken = m.getParameter(
    "stakingToken",
    "0x6F0d766D99bf6007AF9364BEED348C177D877d82"
  );
  const timeUnit = m.getParameter("timeUnit", 60);
  const rewardRatioNumerator = m.getParameter("rewardRatioNumerator", 1);
  const rewardRatioDenominator = m.getParameter("rewardRatioDenominator", 10);

  const tokenStake = m.contract("TokenStake", [nativeTokenWrapper]);

  m.call(tokenStake, "initialize", [
    defaultAdmin,
    contractURI,
    trustedForwarders,
    rewardToken,
    stakingToken,
    timeUnit,
    rewardRatioNumerator,
    rewardRatioDenominator,
  ]);

  return { tokenStake };
});

export default TokenStakeModule;

error message

$ npx hardhat ignition deploy ./ignition/modules/TokenStake.ts --reset
Hardhat Ignition 🚀

Deploying [ TokenStakeModule ]

Batch #1
  Executed TokenStakeModule#TokenStake

Batch #2
  Failed TokenStakeModule#TokenStake.initialize

[ TokenStakeModule ] failed ⛔

Futures failed during execution:
 - TokenStakeModule#TokenStake.initialize: Simulating the transaction failed with error: Reverted with reason "Initializable: contract is already initialized"

To learn how to handle these errors: https://hardhat.org/ignition-errors

terry1ee avatar May 07 '24 11:05 terry1ee