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

update governance deploy #96

Merged

Conversation

felix-shin-wt
Copy link

Fix the logic to deploy using the structure of wemix/bind.

Removed unnecessary files

  • wemix/contracts/WemixGovernance.js
  • wemix/scripts/deploy-governance.js
  • wemix/scripts/solc.sh

wemix/bind/structs.go Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
go.mod Show resolved Hide resolved
wemix/scripts/gwemix.sh Outdated Show resolved Hide resolved
wemix/scripts/gwemix.sh Outdated Show resolved Hide resolved
@felix-shin-wt felix-shin-wt merged commit dc29a65 into feat/governance-simulationbackend Jun 4, 2024
@felix-shin-wt felix-shin-wt deleted the feat/deploy-governance branch June 4, 2024 00:38
@@ -165,38 +173,40 @@ func DeployGovContracts(opts *bind.TransactOpts, backend IBackend, optionDomains
}
}

// deploy proxys
// deploy proxies
txs = make([]*types.Transaction, 0)
Copy link

@steve-oh-wt steve-oh-wt Jun 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

common code for no size slice initialization
txs = txs[:0]

@@ -208,6 +218,7 @@ func DeployGovContracts(opts *bind.TransactOpts, backend IBackend, optionDomains
}

// setup registry
logger.Info("Setting registry...")
txs = make([]*types.Transaction, 0)
Copy link

@steve-oh-wt steve-oh-wt Jun 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

common code for no size slice initialization
txs = txs[:0]

@@ -208,6 +218,7 @@ func DeployGovContracts(opts *bind.TransactOpts, backend IBackend, optionDomains
}

// setup registry
logger.Info("Setting registry...")
txs = make([]*types.Transaction, 0)
if tx, err := gov.Registry.SetContractDomain(opts, metclient.ToBytes32("GovernanceContract"), gov.address.Gov); err != nil {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the code below.

optionDomains["GovernanceContract"] = gov.address.Gov
optionDomains["Staking"] = gov.address.Staking
optionDomains["BallotStorage"] = gov.address.BallotStorage
optionDomains["EnvStorage"] = gov.address.EnvStorage

for name, address := range optionDomains {
	if tx, err := gov.Registry.SetContractDomain(opts, metclient.ToBytes32(name), address); err != nil {
		return nil, nil, errors.Wrap(err, fmt.Sprintf("SetContractDomain(%s)", name))
	} else {
		txs = append(txs, tx)
	}
}

@@ -438,7 +460,6 @@ type InitEnvStorage struct {
BLOCK_GASLIMIT *big.Int
BASE_FEE_MAX_CHANGE_RATE *big.Int
GAS_TARGET_PERCENTAGE *big.Int
Options map[string]*big.Int
}
Copy link

@steve-oh-wt steve-oh-wt Jun 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Remove duplicate code using reflect and tag
  2. Easily check method names and variable names
  3. Process all without missing members
type InitEnvStorage struct {
	BLOCKS_PER                               *big.Int `method:"blocksPer"`
	BALLOT_DURATION_MIN                      *big.Int `method:"ballotDurationMin"`
	BALLOT_DURATION_MAX                      *big.Int `method:"ballotDurationMax"`
	STAKING_MIN                              *big.Int `method:"stakingMin"`
	STAKING_MAX                              *big.Int `method:"stakingMax"`
	MAX_IDLE_BLOCK_INTERVAL                  *big.Int `method:"MaxIdleBlockInterval"`
	BLOCK_CREATION_TIME                      *big.Int `method:"blockCreationTime"`
	BLOCK_REWARD_AMOUNT                      *big.Int `method:"blockRewardAmount"`
	MAX_PRIORITY_FEE_PER_GAS                 *big.Int `method:"maxPriorityFeePerGas"`
	BLOCK_REWARD_DISTRIBUTION_BLOCK_PRODUCER *big.Int `method:"blockRewardDistributionBlockProducer"`
	BLOCK_REWARD_DISTRIBUTION_STAKING_REWARD *big.Int `method:"blockRewardDistributionStakingReward"`
	BLOCK_REWARD_DISTRIBUTION_ECOSYSTEM      *big.Int `method:"blockRewardDistributionEcosystem"`
	BLOCK_REWARD_DISTRIBUTION_MAINTENANCE    *big.Int `method:"blockRewardDistributionMaintenance"`
	MAX_BASE_FEE                             *big.Int `method:"maxBaseFee"`
	BLOCK_GASLIMIT                           *big.Int `method:"blockGasLimit"`
	BASE_FEE_MAX_CHANGE_RATE                 *big.Int `method:"baseFeeMaxChangeRate"`
	GAS_TARGET_PERCENTAGE                    *big.Int `method:"gasTargetPercentage"`
}
func (cfg InitEnvStorage) Args() (names [][32]byte, values []*big.Int) {
	v := reflect.ValueOf(cfg)
	t := reflect.TypeOf(cfg)
	numField := v.NumField()
	names = [][32]byte{}
	values = []*big.Int{}
	for i := 0; i < numField; i++ {
		value, ok := v.Field(i).Interface().(*big.Int)
		if ok && value != nil && value.Sign() > 0 {
			tag := t.Field(i).Tag.Get("method")
			names = append(names, crypto.Keccak256Hash([]byte(tag)))
			values = append(values, value)
		}
	}
	return
}

@@ -527,20 +541,19 @@ var DefaultInitEnvStorage InitEnvStorage = InitEnvStorage{
BALLOT_DURATION_MIN: big.NewInt(86400),
BALLOT_DURATION_MAX: big.NewInt(604800),
STAKING_MIN: new(big.Int).Mul(big.NewInt(1500000), big.NewInt(params.Ether)),
STAKING_MAX: new(big.Int).Mul(big.NewInt(1500000), big.NewInt(params.Ether)),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

common code

var DefaultInitEnvStorage InitEnvStorage = InitEnvStorage{
->
var DefaultInitEnvStorage = InitEnvStorage{

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants