Files
dejo-node/internal/staking/rewards.go
2025-05-23 10:44:32 -03:00

19 lines
495 B
Go

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))
}