Skip to content

Commit

Permalink
added cwVesting/vestDuration query
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed Aug 2, 2024
1 parent f159c46 commit 2d3d3ad
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/formulas/formulas/contract/external/cwVesting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -140,6 +140,27 @@ export const totalToVest: ContractFormula<Uint128> = makeSimpleContractFormula<
},
})

export const vestDuration = makeSimpleContractFormula<Vest, NullableUint64>({
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',
Expand Down

0 comments on commit 2d3d3ad

Please sign in to comment.