From 2d3d3adb43bfeeb69351747685bc9bf018a18aab Mon Sep 17 00:00:00 2001 From: Noah Saso Date: Fri, 2 Aug 2024 14:47:56 -0400 Subject: [PATCH] added cwVesting/vestDuration query --- .../formulas/contract/external/cwVesting.ts | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/formulas/formulas/contract/external/cwVesting.ts b/src/formulas/formulas/contract/external/cwVesting.ts index 75b591a9..196062ca 100644 --- a/src/formulas/formulas/contract/external/cwVesting.ts +++ b/src/formulas/formulas/contract/external/cwVesting.ts @@ -4,7 +4,7 @@ import { ContractFormula } from '@/types' import { dbKeyToKeys } from '@/utils' import { makeSimpleContractFormula } from '../../utils' -import { Vest } from './cwVesting.types' +import { NullableUint64, Vest } from './cwVesting.types' type ValidatorStake = { validator: string @@ -140,6 +140,27 @@ export const totalToVest: ContractFormula = makeSimpleContractFormula< }, }) +export const vestDuration = makeSimpleContractFormula({ + transformation: 'vesting', + fallbackKeys: ['vesting'], + transform: ({ vested }) => { + if ('constant' in vested) { + return null + } else if ('saturating_linear' in vested) { + const start = BigInt(vested.saturating_linear.min_x) + const end = BigInt(vested.saturating_linear.max_x) + return (end - start).toString() + } else if ('piecewise_linear' in vested) { + const steps = vested.piecewise_linear.steps + const start = steps[0][0] + const end = steps[steps.length - 1][0] + return (end - start).toString() + } else { + throw new Error('Invalid curve') + } + }, +}) + export const unbondingDurationSeconds: ContractFormula = makeSimpleContractFormula({ transformation: 'ubs',