Skip to content

Commit

Permalink
refactor(neuron-ui): improve precision of calculateAPY (#1102)
Browse files Browse the repository at this point in the history
* refactor(neuron-ui): improve precision of calculateAPY

* fix(neuron-ui): display percentage of apy

* test(neuron-ui): fix tests of calculateGlobalAPY
  • Loading branch information
Keith-CY committed Nov 14, 2019
1 parent 46a15b0 commit 8e2d505
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
Expand Up @@ -7,6 +7,6 @@ export default {
'one period and one handrand days': {
currentTime: new Date('2023-04-10').getTime(),
genesisTime: new Date('2019-01-01').getTime(),
expectAPY: 0.02369552868619654,
expectAPY: 2.369552868619654,
},
}
6 changes: 3 additions & 3 deletions packages/neuron-ui/src/utils/calculateAPY.ts
@@ -1,7 +1,7 @@
const YEAR = 365 * 24 * 60 * 60 * 1000
const BASE = 10000000

export default (interest: string, amount: string, duration: string) => {
const BASE = 10000
const v = +((BigInt(interest) * BigInt(BASE)) / BigInt(amount)).toString() * (YEAR / +duration)
return `${(v / BASE).toFixed(2)}`
const v = (BigInt(interest) * BigInt(YEAR) * BigInt(BASE)) / (BigInt(amount) * BigInt(duration))
return `${(Number(v) / (BASE / 100)).toFixed(2)}`
}
2 changes: 1 addition & 1 deletion packages/neuron-ui/src/utils/calculateGlobalAPY.ts
Expand Up @@ -44,5 +44,5 @@ export default async (now: number, initialTimestamp: number | undefined = cached
realPrimaryOffer += primaryOfferFraction

const totalOffer = INITIAL_OFFER + realPrimaryOffer + realSecondaryOffer
return +(Number(SECONDARY_OFFER) / Number(totalOffer)).toFixed(2)
return +(Number(SECONDARY_OFFER) / (Number(totalOffer) / 100)).toFixed(2)
}

0 comments on commit 8e2d505

Please sign in to comment.