Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add example reward calculator usage #3171

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions vms/platformvm/reward/example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package reward

import (
"fmt"
"time"

"github.com/ava-labs/avalanchego/utils/units"
)

func ExampleNewCalculator() {
const (
day = 24 * time.Hour
week = 7 * day
stakingDuration = 4 * week

stakeAmount = 100_000 * units.Avax // 100k AVAX

// The current supply can be fetched with the platform.getCurrentSupply API
currentSupply = 447_903_489_576_595_361 * units.NanoAvax // ~448m AVAX
)
var (
mainnetRewardConfig = Config{
MaxConsumptionRate: .12 * PercentDenominator,
MinConsumptionRate: .10 * PercentDenominator,
MintingPeriod: 365 * 24 * time.Hour,
SupplyCap: 720 * units.MegaAvax,
}
mainnetCalculator = NewCalculator(mainnetRewardConfig)
)

potentialReward := mainnetCalculator.Calculate(stakingDuration, stakeAmount, currentSupply)

fmt.Printf("Staking %d nAVAX for %s with the current supply of %d nAVAX would have a potential reward of %d nAVAX",
stakeAmount,
stakingDuration,
currentSupply,
potentialReward,
)
// Output: Staking 100000000000000 nAVAX for 672h0m0s with the current supply of 447903489576595361 nAVAX would have a potential reward of 473168956104 nAVAX
}
Loading