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

fix: Improve Stake Time Calculation Accuracy #119

Closed
wants to merge 18 commits into from

Conversation

izikdepth
Copy link
Collaborator

Description

Related Issue

  • Fixes #(issue number)

Types of changes

  • Bug fix (non-breaking change that solves an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update (corrections, enhancements, or additions to documentation)
  • Other (please describe):

@izikdepth izikdepth requested a review from kehiy as a code owner May 10, 2024 21:03
Copy link
Collaborator

@kehiy kehiy left a comment

Choose a reason for hiding this comment

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

Please change time to duration in sub-command struct of this command too. (you can find it in this file on the get commands function)

@@ -117,7 +116,7 @@ func (bc *Blockchain) calcRewardHandler(cmd command.Command, _ command.AppID, _

return cmd.SuccessfulResult("Approximately you earn %v PAC reward, with %v PAC stake 🔒 on your validator in one %s ⏰ with %s total power ⚡ of committee."+
"\n\n> Note📝: This number is just an estimation. It will vary depending on your stake amount and total network power.",
utils.FormatNumber(reward), utils.FormatNumber(int64(stake)), time, utils.FormatNumber(int64(amount.Amount(bi.TotalPower).ToPAC())))
utils.FormatNumber(reward), utils.FormatNumber(int64(stake)), duration, utils.FormatNumber(int64(amount.Amount(bi.TotalPower).ToPAC())))
Copy link
Contributor

@b00f b00f May 11, 2024

Choose a reason for hiding this comment

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

Why "utils.FormatNumber(int64(stake))"?

Get stake like:

 stake, err := amount.FromString(args[0])
	if err != nil {
		return cmd.ErrorResult(err)
	}
reward := stake*blocks / amount.Amount(bi.TotalPower)

Try to work with amount.Amount not int64

@izikdepth
Copy link
Collaborator Author

Please change time to duration in sub-command struct of this command too. (you can find it in this file on the get commands function)

done


return cmd.SuccessfulResult("Approximately you earn %v PAC reward, with %v PAC stake 🔒 on your validator in one %s ⏰ with %s total power ⚡ of committee."+
"\n\n> Note📝: This number is just an estimation. It will vary depending on your stake amount and total network power.",
utils.FormatNumber(reward), utils.FormatNumber(int64(stake)), time, utils.FormatNumber(int64(amount.Amount(bi.TotalPower).ToPAC())))
utils.FormatNumber(int64(reward)), utils.FormatNumber(int64(stake)), duration, utils.FormatNumber(int64(amount.Amount(bi.TotalPower).ToPAC())))
Copy link
Contributor

Choose a reason for hiding this comment

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

Try avoid this:

utils.FormatNumber(int64(reward)), utils.FormatNumber(int64(stake))

use amt.String()

@@ -8,6 +8,7 @@ import (
"github.com/pagu-project/Pagu/client"
"github.com/pagu-project/Pagu/engine/command"
"github.com/pagu-project/Pagu/utils"
// "github.com/pagu-project/Pagu/utils"
Copy link
Contributor

Choose a reason for hiding this comment

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

remove this line.

@@ -114,11 +115,12 @@ func (bc *Blockchain) calcRewardHandler(cmd command.Command, _ command.AppID, _

rewardInt := stake * blocks / int(amount.Amount(bi.TotalPower).ToPAC())

reward := amount.Amount(rewardInt)
// convert from nanoPac to PAC.
totalPowerInPAC := bi.TotalPower / 1_000_000_000
Copy link
Contributor

Choose a reason for hiding this comment

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

@izikdepth please one time read and check amount.Amount functions.
Avoid using bare operation here.

@themantre
Copy link

@akbariandev close this PR

@akbariandev akbariandev closed this Jun 6, 2024
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.

None yet

5 participants