Skip to content

Commit

Permalink
added daoVoteDelegation/registration query
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed Nov 27, 2024
1 parent dbe09c5 commit cd3f33a
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions src/formulas/formulas/contract/delegation/daoVoteDelegation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,74 @@ const CODE_IDS_KEYS: string[] = ['dao-vote-delegation']

export { info } from '../common'

export const registration: ContractFormula<
{
registered: boolean
power: string
height: number
},
{
delegate: string
height?: string
}
> = {
docs: {
description:
'retrieves whether or not a delegate is registered, optionally at a given block height',
args: [
{
name: 'delegate',
description: 'address of the delegate',
required: true,
schema: {
type: 'string',
},
},
{
name: 'height',
description: 'block height to retrieve delegate registration at',
required: false,
schema: {
type: 'integer',
},
},
],
},
filter: {
codeIdsKeys: CODE_IDS_KEYS,
},
compute: async (env) => {
if (!env.args.delegate) {
throw new Error('delegate is required')
}

const height = env.args.height
? Number(env.args.height)
: Number(env.block.height)

const registered = !!(await snapshotMapMayLoadAtHeight({
env,
name: 'delegates',
key: env.args.delegate,
height,
}))

const power =
(await wormholeLoad<string, string>({
env,
name: 'delegatedVotingPower',
key: env.args.delegate,
timestamp: height,
})) || '0'

return {
registered,
power,
height,
}
},
}

export const delegates: ContractFormula<
{
delegates: {
Expand Down

0 comments on commit cd3f33a

Please sign in to comment.