Skip to content

Commit

Permalink
Add example reward calculator usage (#3171)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored Jul 4, 2024
1 parent 891ba52 commit 0bc4617
Showing 1 changed file with 43 additions and 0 deletions.
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
}

0 comments on commit 0bc4617

Please # to comment.