diff --git a/cmd/zetacore_utils/address-list.json b/cmd/zetacore_utils/address-list.json new file mode 100644 index 0000000000..e69de29bb2 diff --git a/cmd/zetacore_utils/main.go b/cmd/zetacore_utils/main.go new file mode 100644 index 0000000000..1068a160ce --- /dev/null +++ b/cmd/zetacore_utils/main.go @@ -0,0 +1,145 @@ +package main + +import ( + "bufio" + sdkmath "cosmossdk.io/math" + "encoding/json" + "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/zeta-chain/zetacore/cmd/zetacored/config" + "os" + "os/exec" + "path/filepath" + "time" +) + +const node = "tcp://3.218.170.198:26657" +const signer = "" +const chainID = "athens_7001-1" +const amount = "100000000000000000000" +const broadcastMode = "sync" + +//const node = "tcp://localhost:26657" +//const signer = "zeta" +//const chain_id = "localnet_101-1" +//const amount = "100000000" // Amount in azeta +//const broadcast_mode = "block" + +type TokenDistribution struct { + Address string `json:"address"` + BalanceBefore sdk.Coin `json:"balance_before"` + BalanceAfter sdk.Coin `json:"balance_after"` + TokensDistributed sdk.Coin `json:"tokens_distributed"` +} + +func main() { + file, _ := filepath.Abs(filepath.Join("cmd", "zetacore_utils", "address-list.json")) + addresses, err := readLines(file) + if err != nil { + panic(err) + } + addresses = removeDuplicates(addresses) + fileS, _ := filepath.Abs(filepath.Join("cmd", "zetacore_utils", "successful_address.json")) + fileF, _ := filepath.Abs(filepath.Join("cmd", "zetacore_utils", "failed_address.json")) + + distributionList := make([]TokenDistribution, len(addresses)) + for i, address := range addresses { + cmd := exec.Command("zetacored", "q", "bank", "balances", address, "--output", "json", "--denom", "azeta", "--node", node) // #nosec G204 + output, err := cmd.CombinedOutput() + if err != nil { + fmt.Println(cmd.String()) + fmt.Println(fmt.Sprint(err) + ": " + string(output)) + return + } + balance := sdk.Coin{} + err = json.Unmarshal(output, &balance) + if err != nil { + panic(err) + } + distributionAmount, ok := sdkmath.NewIntFromString(amount) + if !ok { + panic("parse error for amount") + } + distributionList[i] = TokenDistribution{ + Address: address, + BalanceBefore: balance, + TokensDistributed: sdk.NewCoin(config.BaseDenom, distributionAmount), + } + } + + args := []string{"tx", "bank", "multi-send", signer} + for _, address := range addresses { + args = append(args, address) + } + + args = append(args, []string{distributionList[0].TokensDistributed.String(), "--keyring-backend", "test", "--chain-id", chainID, "--yes", + "--broadcast-mode", broadcastMode, "--gas=auto", "--gas-adjustment=2", "--gas-prices=0.001azeta", "--node", node}...) + + cmd := exec.Command("zetacored", args...) + output, err := cmd.CombinedOutput() + if err != nil { + fmt.Println(cmd.String()) + fmt.Println(fmt.Sprint(err) + ": " + string(output)) + return + } + fmt.Println(string(output)) + + time.Sleep(7 * time.Second) + + for i, address := range addresses { + cmd := exec.Command("zetacored", "q", "bank", "balances", address, "--output", "json", "--denom", "azeta", "--node", node) // #nosec G204 + output, err := cmd.CombinedOutput() + if err != nil { + fmt.Println(cmd.String()) + fmt.Println(fmt.Sprint(err) + ": " + string(output)) + return + } + balance := sdk.Coin{} + err = json.Unmarshal(output, &balance) + if err != nil { + panic(err) + } + distributionList[i].BalanceAfter = balance + } + var successfullDistributions []TokenDistribution + var failedDistributions []TokenDistribution + for _, distribution := range distributionList { + if distribution.BalanceAfter.Sub(distribution.BalanceBefore).IsEqual(distribution.TokensDistributed) { + successfullDistributions = append(successfullDistributions, distribution) + } else { + failedDistributions = append(failedDistributions, distribution) + } + } + successFile, _ := json.MarshalIndent(successfullDistributions, "", " ") + _ = os.WriteFile(fileS, successFile, 0600) + failedFile, _ := json.MarshalIndent(failedDistributions, "", " ") + _ = os.WriteFile(fileF, failedFile, 0600) + +} + +func readLines(path string) ([]string, error) { + file, err := os.Open(path) // #nosec G304 + if err != nil { + return nil, err + } + defer file.Close() + + var lines []string + scanner := bufio.NewScanner(file) + for scanner.Scan() { + lines = append(lines, scanner.Text()) + } + return lines, scanner.Err() +} + +func removeDuplicates(s []string) []string { + bucket := make(map[string]bool) + var result []string + for _, str := range s { + if _, ok := bucket[str]; !ok { + bucket[str] = true + result = append(result, str) + } + } + return result +} diff --git a/standalone-network/update_voting_period/proposal.json b/standalone-network/update_voting_period/proposal.json new file mode 100644 index 0000000000..34d1c709b6 --- /dev/null +++ b/standalone-network/update_voting_period/proposal.json @@ -0,0 +1,27 @@ +{ + "title": "Gov Param Change", + "description": "Update voting period", + "changes": [ + { + "subspace": "gov", + "key": "votingparams", + "value": { + "voting_period": "86400" + } + }, + { + "subspace": "gov", + "key": "depositparams", + "value": { + "min_deposit": [ + { + "denom": "azeta", + "amount": "1000000" + } + ], + "max_deposit_period": "86400" + } + } + ], + "deposit": "1000000zeta" +} \ No newline at end of file diff --git a/standalone-network/update_voting_period/update_voting_period.sh b/standalone-network/update_voting_period/update_voting_period.sh new file mode 100644 index 0000000000..417b0d3737 --- /dev/null +++ b/standalone-network/update_voting_period/update_voting_period.sh @@ -0,0 +1,17 @@ +#!/bin/bash +CHAINID="atheens_7001-1" +KEYRING="test" +HOSTNAME=$(hostname) +signer="operator" +proposal_count=10 + +#PID=1 + +signerAddress=$(zetacored keys show $signer -a --keyring-backend=test) +echo "signerAddress: $signerAddress" +for (( i = 0; i < proposal_count; i++ )); do + zetacored tx gov submit-legacy-proposal param-change proposal.json --from $signer --gas=auto --gas-adjustment=1.5 --gas-prices=0.001azeta --chain-id=$CHAINID --keyring-backend=$KEYRING -y --broadcast-mode=block +done + + +#zetacored tx gov vote "$PID" yes --from $signer --keyring-backend $KEYRING --chain-id $CHAINID --yes --fees=40azeta --broadcast-mode=block \ No newline at end of file