commit inicial do projeto
This commit is contained in:
19
internal/staking/rewards.go
Normal file
19
internal/staking/rewards.go
Normal file
@ -0,0 +1,19 @@
|
||||
package staking
|
||||
|
||||
import (
|
||||
"math"
|
||||
"time"
|
||||
)
|
||||
|
||||
// CalculateRewards calcula as recompensas baseadas em tempo e APR.
|
||||
// Exemplo: APR 12% ao ano = 0.01 ao mês, 0.00033 ao dia.
|
||||
func CalculateRewards(amount uint64, startTime int64, apr float64) uint64 {
|
||||
daysStaked := float64(time.Now().Unix()-startTime) / (60 * 60 * 24)
|
||||
if daysStaked <= 0 {
|
||||
return 0
|
||||
}
|
||||
|
||||
// Fórmula de juros simples: R = P * i * t
|
||||
interest := float64(amount) * (apr / 365.0) * daysStaked
|
||||
return uint64(math.Floor(interest))
|
||||
}
|
||||
Reference in New Issue
Block a user