-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
apply default denomination to stake setting for pos (#2418)
Co-authored-by: sukantoraymond <[email protected]>
- Loading branch information
1 parent
5897809
commit 0cfa00f
Showing
3 changed files
with
33 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (C) 2023, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
package utils | ||
|
||
import ( | ||
"math/big" | ||
) | ||
|
||
const defaultDenomination = 18 | ||
|
||
// Convert an integed amount of the given denomination to base units | ||
// (i.e. An amount of 54 with a decimals value of 3 results in 54000) | ||
func ApplyDenomination(amount uint64, decimals uint8) *big.Int { | ||
multiplier := new(big.Int).Exp( | ||
big.NewInt(10), | ||
big.NewInt(int64(decimals)), | ||
nil, | ||
) | ||
return new(big.Int).Mul( | ||
big.NewInt(int64(amount)), | ||
multiplier, | ||
) | ||
} | ||
|
||
// Convert an integed amount of the default denomination to base units | ||
func ApplyDefaultDenomination(amount uint64) *big.Int { | ||
return ApplyDenomination(amount, defaultDenomination) | ||
} |