Skip to content

Commit

Permalink
fix apy to match android
Browse files Browse the repository at this point in the history
  • Loading branch information
ERussel committed Nov 19, 2024
1 parent 71a6427 commit 91a4d48
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,20 @@ final class PolkadotRewardEngine: RewardCalculatorEngine {
}

override func calculateEraReturn(from annualReturn: Decimal) -> Decimal {
guard eraDurationInSeconds > 0 else {
return 0
}

let daysInYear = TimeInterval(CalculationPeriod.year.inDays)
let erasInYear = daysInYear * TimeInterval.secondsInDay / eraDurationInSeconds

guard erasInYear > 0 else {
return 0
}

return annualReturn / Decimal(erasInYear)
let rawAnnualReturn = (annualReturn as NSDecimalNumber).doubleValue
let result = pow(rawAnnualReturn + 1.0, 1.0 / Double(erasInYear)) - 1.0

return Decimal(result)
}
}

0 comments on commit 91a4d48

Please sign in to comment.