From b3a4c58875dfc962a45f012699925f0a598a204f Mon Sep 17 00:00:00 2001 From: Lee ByeongJun Date: Mon, 21 Oct 2024 15:02:37 +0900 Subject: [PATCH 1/5] governance --- gov/governance/parameter_change.gno | 62 +++++++---- gov/governance/util.gno | 154 ---------------------------- setup.py | 4 +- 3 files changed, 45 insertions(+), 175 deletions(-) diff --git a/gov/governance/parameter_change.gno b/gov/governance/parameter_change.gno index a095392e..99cf1609 100644 --- a/gov/governance/parameter_change.gno +++ b/gov/governance/parameter_change.gno @@ -2,6 +2,7 @@ package governance import ( "std" + "strconv" "strings" "gno.land/r/gnoswap/v2/consts" @@ -287,8 +288,11 @@ func executeParameterChange(msgs []string) { } func handleCommunityPoolTransferToken(params []string) (string, std.Address, uint64) { - - return params[0], std.Address(params[1]), parseUint(params[2], 10, 64) + parsed, err := strconv.ParseUint(params[2], 10, 64) + if err != nil { + panic(err) + } + return params[0], std.Address(params[1]), parsed } func handleEmissionChangeDistributionPct(params []string) ( @@ -298,55 +302,75 @@ func handleEmissionChangeDistributionPct(params []string) ( int, uint64, ) { target01 := strToInt(params[0]) - pct01 := parseUint(params[1], 10, 64) + pct01, _ := strconv.ParseUint(params[1], 10, 64) target02 := strToInt(params[2]) - pct02 := parseUint(params[3], 10, 64) + pct02, _ := strconv.ParseUint(params[3], 10, 64) target03 := strToInt(params[4]) - pct03 := parseUint(params[5], 10, 64) + pct03, _ := strconv.ParseUint(params[5], 10, 64) target04 := strToInt(params[6]) - pct04 := parseUint(params[7], 10, 64) + pct04, _ := strconv.ParseUint(params[7], 10, 64) return target01, pct01, target02, pct02, target03, pct03, target04, pct04 } func handleGnsSetAvgBlockTimeInMs(params []string) int64 { - return int64(parseUint(params[0], 10, 64)) + parsed, err := strconv.ParseUint(params[0], 10, 64) + if err != nil { + panic(err) + } + return int64(parsed) } func handleGovernanceReconfigure(params []string) ( uint64, uint64, uint64, uint64, uint64, uint64, uint64, ) { - votingStartDelay := parseUint(params[0], 10, 64) - votingPeriod := parseUint(params[1], 10, 64) - votingWeightSmoothingDuration := parseUint(params[2], 10, 64) - quorum := parseUint(params[3], 10, 64) - proposalCreationThreshold := parseUint(params[4], 10, 64) - executionDelay := parseUint(params[5], 10, 64) - executionWindow := parseUint(params[6], 10, 64) + votingStartDelay, _ := strconv.ParseUint(params[0], 10, 64) + votingPeriod, _ := strconv.ParseUint(params[1], 10, 64) + votingWeightSmoothingDuration, _ := strconv.ParseUint(params[2], 10, 64) + quorum, _ := strconv.ParseUint(params[3], 10, 64) + proposalCreationThreshold, _ := strconv.ParseUint(params[4], 10, 64) + executionDelay, _ := strconv.ParseUint(params[5], 10, 64) + executionWindow, _ := strconv.ParseUint(params[6], 10, 64) return votingStartDelay, votingPeriod, votingWeightSmoothingDuration, quorum, proposalCreationThreshold, executionDelay, executionWindow } func handlePoolSetFeeProtocol(params []string) (uint8, uint8) { - feeProtocol0 := parseUint(params[0], 10, 64) - feeProtocol1 := parseUint(params[1], 10, 64) + feeProtocol0, _ := strconv.ParseUint(params[0], 10, 64) + feeProtocol1, _ := strconv.ParseUint(params[1], 10, 64) return uint8(feeProtocol0), uint8(feeProtocol1) } func handleSingleUint64(params []string) uint64 { - return parseUint(params[0], 10, 64) + parsed, err := strconv.ParseUint(params[0], 10, 64) + if err != nil { + panic(err) + } + return parsed } func handlePoolPathTier(params []string) (string, uint64) { - return params[0], parseUint(params[1], 10, 64) + parsed, err := strconv.ParseUint(params[1], 10, 64) + if err != nil { + panic(err) + } + return params[0], parsed } func handleTwoInt64(params []string) (int64, int64) { - return int64(parseUint(params[0], 10, 64)), int64(parseUint(params[1], 10, 64)) + parsed0, err := strconv.ParseUint(params[0], 10, 64) + if err != nil { + panic(err) + } + parsed1, err := strconv.ParseUint(params[1], 10, 64) + if err != nil { + panic(err) + } + return int64(parsed0), int64(parsed1) } func handleSingleBool(params []string) bool { diff --git a/gov/governance/util.gno b/gov/governance/util.gno index 084c3b1d..55f4fbd5 100644 --- a/gov/governance/util.gno +++ b/gov/governance/util.gno @@ -18,160 +18,6 @@ const ( uintSize = 32 << (^uint(0) >> 63) ) -func lower(c byte) byte { - return c | ('x' - 'X') -} - -// TODO: Remove parseUint after gno supports strconv.ParseUint -func parseUint(s string, base int, bitSize int) uint64 { - const fnParseUint = "ParseUint" - - if s == "" { - panic(ufmt.Errorf("%s: parsing \"\": invalid syntax", fnParseUint)) - } - - base0 := base == 0 - - s0 := s - switch { - case 2 <= base && base <= 36: - // valid base; nothing to do - - case base == 0: - // Look for octal, hex prefix. - base = 10 - if s[0] == '0' { - switch { - case len(s) >= 3 && lower(s[1]) == 'b': - base = 2 - s = s[2:] - case len(s) >= 3 && lower(s[1]) == 'o': - base = 8 - s = s[2:] - case len(s) >= 3 && lower(s[1]) == 'x': - base = 16 - s = s[2:] - default: - base = 8 - s = s[1:] - } - } - - default: - panic(ufmt.Errorf("%s: invalid base %d", fnParseUint, base)) - } - - if bitSize == 0 { - bitSize = uintSize - } else if bitSize < 0 || bitSize > 64 { - panic(ufmt.Errorf("%s: invalid bit size %d", fnParseUint, bitSize)) - } - - // Cutoff is the smallest number such that cutoff*base > maxUint64. - // Use compile-time constants for common cases. - var cutoff uint64 - switch base { - case 10: - cutoff = MaxUint64/10 + 1 - case 16: - cutoff = MaxUint64/16 + 1 - default: - cutoff = MaxUint64/uint64(base) + 1 - } - - maxVal := uint64(1)<= byte(base) { - panic(ufmt.Errorf("%s: invalid character", fnParseUint)) - } - - if n >= cutoff { - // n*base overflows - panic(ufmt.Errorf("%s: value out of range", fnParseUint)) - // return maxVal, ufmt.Errorf("%s: value out of range", fnParseUint) - } - n *= uint64(base) - - n1 := n + uint64(d) - if n1 < n || n1 > maxVal { - // n+d overflows - panic(ufmt.Errorf("%s: value out of range", fnParseUint)) - // return maxVal, ufmt.Errorf("%s: value out of range", fnParseUint) - } - n = n1 - } - - if underscores && !underscoreOK(s0) { - panic(ufmt.Errorf("%s: invalid underscore", fnParseUint)) - } - - return n -} - -func underscoreOK(s string) bool { - // saw tracks the last character (class) we saw: - // ^ for beginning of number, - // 0 for a digit or base prefix, - // _ for an underscore, - // ! for none of the above. - saw := '^' - i := 0 - - // Optional sign. - if len(s) >= 1 && (s[0] == '-' || s[0] == '+') { - s = s[1:] - } - - // Optional base prefix. - hex := false - if len(s) >= 2 && s[0] == '0' && (lower(s[1]) == 'b' || lower(s[1]) == 'o' || lower(s[1]) == 'x') { - i = 2 - saw = '0' // base prefix counts as a digit for "underscore as digit separator" - hex = lower(s[1]) == 'x' - } - - // Number proper. - for ; i < len(s); i++ { - // Digits are always okay. - if '0' <= s[i] && s[i] <= '9' || hex && 'a' <= lower(s[i]) && lower(s[i]) <= 'f' { - saw = '0' - continue - } - // Underscore must follow digit. - if s[i] == '_' { - if saw != '0' { - return false - } - saw = '_' - continue - } - // Underscore must also be followed by digit. - if saw == '_' { - return false - } - // Saw non-digit, non-underscore. - saw = '!' - } - - return saw != '_' -} - func strToInt(str string) int { res, err := strconv.Atoi(str) if err != nil { diff --git a/setup.py b/setup.py index 8c2b1ace..f53fdbdc 100644 --- a/setup.py +++ b/setup.py @@ -36,14 +36,14 @@ def copy_contracts(workdir): # Copy gnoswap realms # TODO: Detect realms automatically - for realm in ["pool", "position", "router", "staker", "emission", "community_pool", "protocol_fee"]: + for realm in ["pool", "position", "router", "staker", "emission", "community_pool", "protocol_fee", "launchpad", "gov"]: shutil.copytree(realm, os.path.join(gno_dir, "r", "gnoswap", "v2", realm), dirs_exist_ok=True) def move_tests(workdir): gno_dir = os.path.join(workdir, "gno", "examples", "gno.land", "r", "gnoswap", "v2") print(f"GNO_DIR IS {gno_dir}") - for realm in ["pool", "position", "router", "staker", "emission", "community_pool", "gns", "gnft"]: + for realm in ["pool", "position", "router", "staker", "emission", "community_pool", "gns", "gnft", "launchpad", "gov"]: test_dir = os.path.join(gno_dir, realm, "tests") if os.path.exists(test_dir): print(f"{test_dir} exists") From 8e8b762449bc0c6447a91627272f4ee60089d4d5 Mon Sep 17 00:00:00 2001 From: Lee ByeongJun Date: Mon, 21 Oct 2024 15:08:18 +0900 Subject: [PATCH 2/5] launchpad --- launchpad/launchpad_init.gno | 8 +- launchpad/util.gno | 154 ----------------------------------- 2 files changed, 7 insertions(+), 155 deletions(-) diff --git a/launchpad/launchpad_init.gno b/launchpad/launchpad_init.gno index 27ce8c5a..752b6ae0 100644 --- a/launchpad/launchpad_init.gno +++ b/launchpad/launchpad_init.gno @@ -2,6 +2,7 @@ package launchpad import ( "std" + "strconv" "strings" "time" @@ -229,9 +230,14 @@ func makeConditions(conditionsToken string, conditionsAmount string) map[string] } for i, token := range tokens { + minAmount, err := strconv.ParseUint(amounts[i], 10, 64) + if err != nil { + panic(err) + } + conditions[token] = Condition{ tokenPath: token, - minAmount: parseUint(amounts[i], 10, 64), + minAmount: minAmount, } } return conditions diff --git a/launchpad/util.gno b/launchpad/util.gno index f84e6e08..c9207580 100644 --- a/launchpad/util.gno +++ b/launchpad/util.gno @@ -18,160 +18,6 @@ const ( uintSize = 32 << (^uint(0) >> 63) ) -func lower(c byte) byte { - return c | ('x' - 'X') -} - -// TODO: Remove parseUint after gno supports strconv.ParseUint -func parseUint(s string, base int, bitSize int) uint64 { - const fnParseUint = "ParseUint" - - if s == "" { - panic(ufmt.Errorf("%s: parsing \"\": invalid syntax", fnParseUint)) - } - - base0 := base == 0 - - s0 := s - switch { - case 2 <= base && base <= 36: - // valid base; nothing to do - - case base == 0: - // Look for octal, hex prefix. - base = 10 - if s[0] == '0' { - switch { - case len(s) >= 3 && lower(s[1]) == 'b': - base = 2 - s = s[2:] - case len(s) >= 3 && lower(s[1]) == 'o': - base = 8 - s = s[2:] - case len(s) >= 3 && lower(s[1]) == 'x': - base = 16 - s = s[2:] - default: - base = 8 - s = s[1:] - } - } - - default: - panic(ufmt.Errorf("%s: invalid base %d", fnParseUint, base)) - } - - if bitSize == 0 { - bitSize = uintSize - } else if bitSize < 0 || bitSize > 64 { - panic(ufmt.Errorf("%s: invalid bit size %d", fnParseUint, bitSize)) - } - - // Cutoff is the smallest number such that cutoff*base > maxUint64. - // Use compile-time constants for common cases. - var cutoff uint64 - switch base { - case 10: - cutoff = MaxUint64/10 + 1 - case 16: - cutoff = MaxUint64/16 + 1 - default: - cutoff = MaxUint64/uint64(base) + 1 - } - - maxVal := uint64(1)<= byte(base) { - panic(ufmt.Errorf("%s: invalid character", fnParseUint)) - } - - if n >= cutoff { - // n*base overflows - panic(ufmt.Errorf("%s: value out of range", fnParseUint)) - // return maxVal, ufmt.Errorf("%s: value out of range", fnParseUint) - } - n *= uint64(base) - - n1 := n + uint64(d) - if n1 < n || n1 > maxVal { - // n+d overflows - panic(ufmt.Errorf("%s: value out of range", fnParseUint)) - // return maxVal, ufmt.Errorf("%s: value out of range", fnParseUint) - } - n = n1 - } - - if underscores && !underscoreOK(s0) { - panic(ufmt.Errorf("%s: invalid underscore", fnParseUint)) - } - - return n -} - -func underscoreOK(s string) bool { - // saw tracks the last character (class) we saw: - // ^ for beginning of number, - // 0 for a digit or base prefix, - // _ for an underscore, - // ! for none of the above. - saw := '^' - i := 0 - - // Optional sign. - if len(s) >= 1 && (s[0] == '-' || s[0] == '+') { - s = s[1:] - } - - // Optional base prefix. - hex := false - if len(s) >= 2 && s[0] == '0' && (lower(s[1]) == 'b' || lower(s[1]) == 'o' || lower(s[1]) == 'x') { - i = 2 - saw = '0' // base prefix counts as a digit for "underscore as digit separator" - hex = lower(s[1]) == 'x' - } - - // Number proper. - for ; i < len(s); i++ { - // Digits are always okay. - if '0' <= s[i] && s[i] <= '9' || hex && 'a' <= lower(s[i]) && lower(s[i]) <= 'f' { - saw = '0' - continue - } - // Underscore must follow digit. - if s[i] == '_' { - if saw != '0' { - return false - } - saw = '_' - continue - } - // Underscore must also be followed by digit. - if saw == '_' { - return false - } - // Saw non-digit, non-underscore. - saw = '!' - } - - return saw != '_' -} - func strToInt(str string) int { res, err := strconv.Atoi(str) if err != nil { From 6cc3d4993d39849399d3d8d23a49ae16319bb328 Mon Sep 17 00:00:00 2001 From: Lee ByeongJun Date: Mon, 21 Oct 2024 15:11:39 +0900 Subject: [PATCH 3/5] uint256 --- _deploy/p/gnoswap/uint256/uint256.gno | 5 +- _deploy/p/gnoswap/uint256/utils.gno | 160 -------------------------- 2 files changed, 3 insertions(+), 162 deletions(-) diff --git a/_deploy/p/gnoswap/uint256/uint256.gno b/_deploy/p/gnoswap/uint256/uint256.gno index 80da0ba8..9ab3b10f 100644 --- a/_deploy/p/gnoswap/uint256/uint256.gno +++ b/_deploy/p/gnoswap/uint256/uint256.gno @@ -4,6 +4,7 @@ package uint256 import ( "errors" + "strconv" "math/bits" ) @@ -143,10 +144,10 @@ func (z *Uint) fromDecimal(bs string) error { if remaining <= 0 { return nil // Done } else if remaining > 19 { - num, err = parseUint(bs[remaining-19:remaining], 10, 64) + num, err = strconv.ParseUint(bs[remaining-19:remaining], 10, 64) } else { // Final round - num, err = parseUint(bs, 10, 64) + num, err = strconv.ParseUint(bs, 10, 64) } if err != nil { return err diff --git a/_deploy/p/gnoswap/uint256/utils.gno b/_deploy/p/gnoswap/uint256/utils.gno index 969728f3..bcc7bb28 100644 --- a/_deploy/p/gnoswap/uint256/utils.gno +++ b/_deploy/p/gnoswap/uint256/utils.gno @@ -1,63 +1,5 @@ package uint256 -// lower(c) is a lower-case letter if and only if -// c is either that lower-case letter or the equivalent upper-case letter. -// Instead of writing c == 'x' || c == 'X' one can write lower(c) == 'x'. -// Note that lower of non-letters can produce other non-letters. -func lower(c byte) byte { - return c | ('x' - 'X') -} - -// underscoreOK reports whether the underscores in s are allowed. -// Checking them in this one function lets all the parsers skip over them simply. -// Underscore must appear only between digits or between a base prefix and a digit. -func underscoreOK(s string) bool { - // saw tracks the last character (class) we saw: - // ^ for beginning of number, - // 0 for a digit or base prefix, - // _ for an underscore, - // ! for none of the above. - saw := '^' - i := 0 - - // Optional sign. - if len(s) >= 1 && (s[0] == '-' || s[0] == '+') { - s = s[1:] - } - - // Optional base prefix. - hex := false - if len(s) >= 2 && s[0] == '0' && (lower(s[1]) == 'b' || lower(s[1]) == 'o' || lower(s[1]) == 'x') { - i = 2 - saw = '0' // base prefix counts as a digit for "underscore as digit separator" - hex = lower(s[1]) == 'x' - } - - // Number proper. - for ; i < len(s); i++ { - // Digits are always okay. - if '0' <= s[i] && s[i] <= '9' || hex && 'a' <= lower(s[i]) && lower(s[i]) <= 'f' { - saw = '0' - continue - } - // Underscore must follow digit. - if s[i] == '_' { - if saw != '0' { - return false - } - saw = '_' - continue - } - // Underscore must also be followed by digit. - if saw == '_' { - return false - } - // Saw non-digit, non-underscore. - saw = '!' - } - return saw != '_' -} - func checkNumberS(input string) error { const fn = "UnmarshalText" l := len(input) @@ -76,105 +18,3 @@ func checkNumberS(input string) error { } return nil } - -// ParseUint is like ParseUint but for unsigned numbers. -// -// A sign prefix is not permitted. -func parseUint(s string, base int, bitSize int) (uint64, error) { - const fnParseUint = "ParseUint" - - if s == "" { - return 0, errSyntax(fnParseUint, s) - } - - base0 := base == 0 - - s0 := s - switch { - case 2 <= base && base <= 36: - // valid base; nothing to do - - case base == 0: - // Look for octal, hex prefix. - base = 10 - if s[0] == '0' { - switch { - case len(s) >= 3 && lower(s[1]) == 'b': - base = 2 - s = s[2:] - case len(s) >= 3 && lower(s[1]) == 'o': - base = 8 - s = s[2:] - case len(s) >= 3 && lower(s[1]) == 'x': - base = 16 - s = s[2:] - default: - base = 8 - s = s[1:] - } - } - - default: - return 0, errInvalidBase(fnParseUint, base) - } - - if bitSize == 0 { - bitSize = uintSize - } else if bitSize < 0 || bitSize > 64 { - return 0, errInvalidBitSize(fnParseUint, bitSize) - } - - // Cutoff is the smallest number such that cutoff*base > maxUint64. - // Use compile-time constants for common cases. - var cutoff uint64 - switch base { - case 10: - cutoff = MaxUint64/10 + 1 - case 16: - cutoff = MaxUint64/16 + 1 - default: - cutoff = MaxUint64/uint64(base) + 1 - } - - maxVal := uint64(1)<= byte(base) { - return 0, errSyntax(fnParseUint, s0) - } - - if n >= cutoff { - // n*base overflows - return maxVal, errRange(fnParseUint, s0) - } - n *= uint64(base) - - n1 := n + uint64(d) - if n1 < n || n1 > maxVal { - // n+d overflows - return maxVal, errRange(fnParseUint, s0) - } - n = n1 - } - - if underscores && !underscoreOK(s0) { - return 0, errSyntax(fnParseUint, s0) - } - - return n, nil -} From 7955fe7e66c06dd66c1800146232b0a5994b9c63 Mon Sep 17 00:00:00 2001 From: Lee ByeongJun Date: Thu, 7 Nov 2024 18:45:14 +0900 Subject: [PATCH 4/5] fix --- gov/governance/execute.gno | 137 ++++++++++++++++++++++++++++--------- 1 file changed, 105 insertions(+), 32 deletions(-) diff --git a/gov/governance/execute.gno b/gov/governance/execute.gno index d8a5cef9..a6e5b86c 100644 --- a/gov/governance/execute.gno +++ b/gov/governance/execute.gno @@ -2,6 +2,7 @@ package governance import ( "std" + "strconv" "strings" "time" @@ -316,14 +317,14 @@ func callableMsg(pkgPath, function, params string) bool { } return true - case "GnsSetAvgBlockTimeInMs": - if len(param) != 1 { - panic(addDetailToError( - errInvalidFunctionParameters, - ufmt.Sprintf("execute.gno__callableMsg() || len(param) should be 1 but got %d, for param %s (pkgPath %s and function %s)", len(param), params, pkgPath, function), - )) - } - return true + // case "GnsSetAvgBlockTimeInMs": + // if len(param) != 1 { + // panic(addDetailToError( + // errInvalidFunctionParameters, + // ufmt.Sprintf("execute.gno__callableMsg() || len(param) should be 1 but got %d, for param %s (pkgPath %s and function %s)", len(param), params, pkgPath, function), + // )) + // } + // return true default: panic(addDetailToError( @@ -464,9 +465,9 @@ func executeParameterChange(msgs []string) { case "SetWarmUp": percent, block := handleTwoInt64(params) sr.SetWarmUp(percent, block) - case "GnsSetAvgBlockTimeInMs": - ms := handleGnsSetAvgBlockTimeInMs(params) - sr.GnsSetAvgBlockTimeInMs(ms) + // case "GnsSetAvgBlockTimeInMs": + // ms := handleGnsSetAvgBlockTimeInMs(params) + // sr.GnsSetAvgBlockTimeInMs(ms) } case consts.COMMON_PATH: @@ -487,8 +488,11 @@ func executeParameterChange(msgs []string) { } func handleCommunityPoolTransferToken(params []string) (string, std.Address, uint64) { - - return params[0], std.Address(params[1]), parseUint(params[2], 10, 64) + p2, err := strconv.ParseUint(params[2], 10, 64) + if err != nil { + panic(err) + } + return params[0], std.Address(params[1]), p2 } func handleEmissionChangeDistributionPct(params []string) ( @@ -497,56 +501,125 @@ func handleEmissionChangeDistributionPct(params []string) ( int, uint64, int, uint64, ) { - target01 := strToInt(params[0]) - pct01 := parseUint(params[1], 10, 64) + target01, err := strconv.ParseInt(params[0], 10, 64) + if err != nil { + panic(err) + } + pct01, err := strconv.ParseUint(params[1], 10, 64) + if err != nil { + panic(err) + } target02 := strToInt(params[2]) - pct02 := parseUint(params[3], 10, 64) + pct02, err := strconv.ParseUint(params[3], 10, 64) + if err != nil { + panic(err) + } target03 := strToInt(params[4]) - pct03 := parseUint(params[5], 10, 64) + pct03, err := strconv.ParseUint(params[5], 10, 64) + if err != nil { + panic(err) + } target04 := strToInt(params[6]) - pct04 := parseUint(params[7], 10, 64) + pct04, err := strconv.ParseUint(params[7], 10, 64) + if err != nil { + panic(err) + } - return target01, pct01, target02, pct02, target03, pct03, target04, pct04 + return int(target01), pct01, target02, pct02, target03, pct03, target04, pct04 } func handleGnsSetAvgBlockTimeInMs(params []string) int64 { - return int64(parseUint(params[0], 10, 64)) + res, err := strconv.ParseInt(params[0], 10, 64) + if err != nil { + panic(err) + } + return res } func handleGovernanceReconfigure(params []string) ( uint64, uint64, uint64, uint64, uint64, uint64, uint64, ) { - votingStartDelay := parseUint(params[0], 10, 64) - votingPeriod := parseUint(params[1], 10, 64) - votingWeightSmoothingDuration := parseUint(params[2], 10, 64) - quorum := parseUint(params[3], 10, 64) - proposalCreationThreshold := parseUint(params[4], 10, 64) - executionDelay := parseUint(params[5], 10, 64) - executionWindow := parseUint(params[6], 10, 64) + votingStartDelay, err := strconv.ParseUint(params[0], 10, 64) + if err != nil { + panic(err) + } + + votingPeriod, err := strconv.ParseUint(params[1], 10, 64) + if err != nil { + panic(err) + } + + votingWeightSmoothingDuration, err := strconv.ParseUint(params[2], 10, 64) + if err != nil { + panic(err) + } + + quorum, err := strconv.ParseUint(params[3], 10, 64) + if err != nil { + panic(err) + } + + proposalCreationThreshold, err := strconv.ParseUint(params[4], 10, 64) + if err != nil { + panic(err) + } + + executionDelay, err := strconv.ParseUint(params[5], 10, 64) + if err != nil { + panic(err) + } + + executionWindow, err := strconv.ParseUint(params[6], 10, 64) + if err != nil { + panic(err) + } return votingStartDelay, votingPeriod, votingWeightSmoothingDuration, quorum, proposalCreationThreshold, executionDelay, executionWindow } func handlePoolSetFeeProtocol(params []string) (uint8, uint8) { - feeProtocol0 := parseUint(params[0], 10, 64) - feeProtocol1 := parseUint(params[1], 10, 64) + feeProtocol0, err := strconv.ParseUint(params[0], 10, 64) + if err != nil { + panic(err) + } + + feeProtocol1, err := strconv.ParseUint(params[1], 10, 64) + if err != nil { + panic(err) + } return uint8(feeProtocol0), uint8(feeProtocol1) } func handleSingleUint64(params []string) uint64 { - return parseUint(params[0], 10, 64) + res, err := strconv.ParseUint(params[0], 10, 64) + if err != nil { + panic(err) + } + return res } func handlePoolPathTier(params []string) (string, uint64) { - return params[0], parseUint(params[1], 10, 64) + res, err := strconv.ParseUint(params[1], 10, 64) + if err != nil { + panic(err) + } + return params[0], res } func handleTwoInt64(params []string) (int64, int64) { - return int64(parseUint(params[0], 10, 64)), int64(parseUint(params[1], 10, 64)) + res0, err := strconv.ParseInt(params[0], 10, 64) + if err != nil { + panic(err) + } + res1, err := strconv.ParseInt(params[1], 10, 64) + if err != nil { + panic(err) + } + return res0, res1 } func handleSingleBool(params []string) bool { From f114bc428dd1e91275fc0e70a959f59470292da4 Mon Sep 17 00:00:00 2001 From: Lee ByeongJun Date: Tue, 12 Nov 2024 14:48:07 +0900 Subject: [PATCH 5/5] fix --- gov/governance/execute.gno | 42 +++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/gov/governance/execute.gno b/gov/governance/execute.gno index a6e5b86c..ea178dbd 100644 --- a/gov/governance/execute.gno +++ b/gov/governance/execute.gno @@ -317,14 +317,14 @@ func callableMsg(pkgPath, function, params string) bool { } return true - // case "GnsSetAvgBlockTimeInMs": - // if len(param) != 1 { - // panic(addDetailToError( - // errInvalidFunctionParameters, - // ufmt.Sprintf("execute.gno__callableMsg() || len(param) should be 1 but got %d, for param %s (pkgPath %s and function %s)", len(param), params, pkgPath, function), - // )) - // } - // return true + case "GnsSetAvgBlockTimeInMs": + if len(param) != 1 { + panic(addDetailToError( + errInvalidFunctionParameters, + ufmt.Sprintf("execute.gno__callableMsg() || len(param) should be 1 but got %d, for param %s (pkgPath %s and function %s)", len(param), params, pkgPath, function), + )) + } + return true default: panic(addDetailToError( @@ -544,37 +544,37 @@ func handleGovernanceReconfigure(params []string) ( ) { votingStartDelay, err := strconv.ParseUint(params[0], 10, 64) if err != nil { - panic(err) + panic(err.Error()) } votingPeriod, err := strconv.ParseUint(params[1], 10, 64) if err != nil { - panic(err) + panic(err.Error()) } votingWeightSmoothingDuration, err := strconv.ParseUint(params[2], 10, 64) if err != nil { - panic(err) + panic(err.Error()) } quorum, err := strconv.ParseUint(params[3], 10, 64) if err != nil { - panic(err) + panic(err.Error()) } proposalCreationThreshold, err := strconv.ParseUint(params[4], 10, 64) if err != nil { - panic(err) + panic(err.Error()) } executionDelay, err := strconv.ParseUint(params[5], 10, 64) if err != nil { - panic(err) + panic(err.Error()) } executionWindow, err := strconv.ParseUint(params[6], 10, 64) if err != nil { - panic(err) + panic(err.Error()) } return votingStartDelay, votingPeriod, votingWeightSmoothingDuration, quorum, proposalCreationThreshold, executionDelay, executionWindow @@ -583,12 +583,12 @@ func handleGovernanceReconfigure(params []string) ( func handlePoolSetFeeProtocol(params []string) (uint8, uint8) { feeProtocol0, err := strconv.ParseUint(params[0], 10, 64) if err != nil { - panic(err) + panic(err.Error()) } feeProtocol1, err := strconv.ParseUint(params[1], 10, 64) if err != nil { - panic(err) + panic(err.Error()) } return uint8(feeProtocol0), uint8(feeProtocol1) @@ -597,7 +597,7 @@ func handlePoolSetFeeProtocol(params []string) (uint8, uint8) { func handleSingleUint64(params []string) uint64 { res, err := strconv.ParseUint(params[0], 10, 64) if err != nil { - panic(err) + panic(err.Error()) } return res } @@ -605,7 +605,7 @@ func handleSingleUint64(params []string) uint64 { func handlePoolPathTier(params []string) (string, uint64) { res, err := strconv.ParseUint(params[1], 10, 64) if err != nil { - panic(err) + panic(err.Error()) } return params[0], res } @@ -613,11 +613,11 @@ func handlePoolPathTier(params []string) (string, uint64) { func handleTwoInt64(params []string) (int64, int64) { res0, err := strconv.ParseInt(params[0], 10, 64) if err != nil { - panic(err) + panic(err.Error()) } res1, err := strconv.ParseInt(params[1], 10, 64) if err != nil { - panic(err) + panic(err.Error()) } return res0, res1 }