diff --git a/backend/src/graphql/models/Decay.ts b/backend/src/graphql/models/Decay.ts index 17ee8fbac..860580e8f 100644 --- a/backend/src/graphql/models/Decay.ts +++ b/backend/src/graphql/models/Decay.ts @@ -15,13 +15,6 @@ export class Decay { } } - static async getDecayStartBlock(): Promise { - if (!this.decayStartBlockTransaction) { - this.decayStartBlockTransaction = await Transaction.getDecayStartBlock() - } - return this.decayStartBlockTransaction - } - @Field(() => Number) balance: number @@ -38,6 +31,4 @@ export class Decay { @Field(() => Int, { nullable: true }) decayStartBlock?: string - - static decayStartBlockTransaction: Transaction | undefined } diff --git a/backend/src/util/decay.ts b/backend/src/util/decay.ts index ea5f6dafe..9da1d3909 100644 --- a/backend/src/util/decay.ts +++ b/backend/src/util/decay.ts @@ -1,4 +1,6 @@ +import { getCustomRepository } from 'typeorm' import { Decay } from '../graphql/models/Decay' +import { TransactionRepository } from '../typeorm/repository/Transaction' function decayFormula(amount: number, durationInSeconds: number): number { return amount * Math.pow(0.99999997802044727, durationInSeconds) @@ -6,7 +8,8 @@ function decayFormula(amount: number, durationInSeconds: number): number { async function calculateDecay(amount: number, from: Date, to: Date): Promise { // load decay start block - const decayStartBlock = await Decay.getDecayStartBlock() + const transactionRepository = getCustomRepository(TransactionRepository) + const decayStartBlock = await transactionRepository.findDecayStartBlock() // if decay hasn't started yet we return input amount if (!decayStartBlock) return amount @@ -22,7 +25,8 @@ async function calculateDecayWithInterval( from: number | Date, to: number | Date, ): Promise { - const decayStartBlock = await Decay.getDecayStartBlock() + const transactionRepository = getCustomRepository(TransactionRepository) + const decayStartBlock = await transactionRepository.findDecayStartBlock() const result = new Decay(undefined) result.balance = amount