From 8015860d079e96dcdb10a95180bac42da183e7c4 Mon Sep 17 00:00:00 2001 From: Cameron Gilbert Date: Mon, 29 Apr 2024 11:52:56 -0400 Subject: [PATCH] fix: simplify --- src/sdk/utils/math.test.ts | 93 ++++++++++---------------------------- 1 file changed, 25 insertions(+), 68 deletions(-) diff --git a/src/sdk/utils/math.test.ts b/src/sdk/utils/math.test.ts index 22c8ec49..3285e718 100644 --- a/src/sdk/utils/math.test.ts +++ b/src/sdk/utils/math.test.ts @@ -3,6 +3,27 @@ import { calculateEpochMintProvision, computeAPR, polynomial } from "./math" import { Params } from "src/protojs/nibiru/inflation/v1/genesis" import Long from "long" +const params = { + inflationEnabled: true, + polynomialFactors: [ + "-0.000147085524000000", + "0.074291982762000000", + "-18.867415611180000000", + "3128.641926954698000000", + "-334834.740631598223000000", + "17827464.906540066004000000", + ], + inflationDistribution: { + stakingRewards: "0.281250000000000000", + communityPool: "0.354825000000000000", + strategicReserves: "0.363925000000000000", + }, + epochsPerPeriod: new Long(30), + periodsPerYear: new Long(12), + maxPeriod: new Long(96), + hasInflationStarted: true, +} + describe("polynomial", () => { interface TestCase { name: string @@ -20,14 +41,7 @@ describe("polynomial", () => { { name: "real", in: { - factors: [ - "-0.000147085524000000", - "0.074291982762000000", - "-18.867415611180000000", - "3128.641926954698000000", - "-334834.740631598223000000", - "17827464.906540066004000000", - ], + factors: params.polynomialFactors, x: BigNumber(0), }, expected: BigNumber("17827464.906540066004000000"), @@ -69,26 +83,7 @@ describe("calculateEpochMintProvision", () => { { name: "real", in: { - params: { - inflationEnabled: true, - polynomialFactors: [ - "-0.000147085524000000", - "0.074291982762000000", - "-18.867415611180000000", - "3128.641926954698000000", - "-334834.740631598223000000", - "17827464.906540066004000000", - ], - inflationDistribution: { - stakingRewards: "0.281250000000000000", - communityPool: "0.354825000000000000", - strategicReserves: "0.363925000000000000", - }, - epochsPerPeriod: new Long(30), - periodsPerYear: new Long(12), - maxPeriod: new Long(96), - hasInflationStarted: true, - }, + params, period: BigNumber(0), }, expected: BigNumber("17827464.906540066004"), @@ -149,26 +144,7 @@ describe("computeAPR", () => { in: { myStake: 10, totalStaked: 10_000_000, - params: { - inflationEnabled: true, - polynomialFactors: [ - "-0.000147085524000000", - "0.074291982762000000", - "-18.867415611180000000", - "3128.641926954698000000", - "-334834.740631598223000000", - "17827464.906540066004000000", - ], - inflationDistribution: { - stakingRewards: "0.281250000000000000", - communityPool: "0.354825000000000000", - strategicReserves: "0.363925000000000000", - }, - epochsPerPeriod: new Long(30), - periodsPerYear: new Long(12), - maxPeriod: new Long(96), - hasInflationStarted: true, - }, + params, period: 0, }, expected: 6.016763389193883, @@ -178,26 +154,7 @@ describe("computeAPR", () => { in: { myStake: 0, totalStaked: 0, - params: { - inflationEnabled: true, - polynomialFactors: [ - "-0.000147085524000000", - "0.074291982762000000", - "-18.867415611180000000", - "3128.641926954698000000", - "-334834.740631598223000000", - "17827464.906540066004000000", - ], - inflationDistribution: { - stakingRewards: "0.281250000000000000", - communityPool: "0.354825000000000000", - strategicReserves: "0.363925000000000000", - }, - epochsPerPeriod: new Long(30), - periodsPerYear: new Long(12), - maxPeriod: new Long(96), - hasInflationStarted: true, - }, + params, period: 0, }, expected: NaN,