Skip to content

Commit

Permalink
added dao rewards distributor transformers and formulas
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed Sep 11, 2024
1 parent 7303100 commit 18fb3ff
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { ContractFormula } from '@/types'

const CODE_IDS_KEYS: string[] = ['dao-rewards-distributor']

export const distribution: ContractFormula<
any,
{
id: string
}
> = {
filter: {
codeIdsKeys: CODE_IDS_KEYS,
},
compute: async ({
contractAddress,
getTransformationMatch,
args: { id },
}) => {
if (!id) {
throw new Error('missing `id`')
}

const distribution = (
await getTransformationMatch(contractAddress, `distribution:${id}`)
)?.value

if (!distribution) {
throw new Error(`distribution not found for id: ${id}`)
}

return distribution
},
}

export const distributions: ContractFormula<
{
distributions: any[]
},
{
limit?: string
startAfter?: string
}
> = {
filter: {
codeIdsKeys: CODE_IDS_KEYS,
},
compute: async ({
contractAddress,
getTransformationMap,
args: { limit, startAfter },
}) => {
const limitNum = limit ? Math.max(0, Number(limit)) : Infinity
const startAfterNum = startAfter ? Number(startAfter) : -1

const map =
(await getTransformationMap<number, any>(
contractAddress,
'distribution'
)) ?? {}
const distributions = Object.entries(map)
// Ascending by ID.
.sort(([a], [b]) => Number(a) - Number(b))
.filter(([id]) => Number(id) > startAfterNum)
.slice(0, limitNum)
.map(([, distribution]) => distribution)

return {
distributions,
}
},
}
1 change: 1 addition & 0 deletions src/formulas/formulas/contract/distribution/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * as daoRewardsDistributor from './daoRewardsDistributor'
1 change: 1 addition & 0 deletions src/formulas/formulas/contract/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './daoCore'
export * from './distribution'
export * from './external'
export * as neutron from './neutron'
export * from './polytone'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { makeTransformerForMap } from '@/transformers/utils'
import { Transformer } from '@/types'

const CODE_IDS_KEYS: string[] = ['dao-rewards-distributor']

const distributions: Transformer = makeTransformerForMap(
CODE_IDS_KEYS,
'distribution',
'd',
{ numericKey: true }
)

export default [distributions]
3 changes: 3 additions & 0 deletions src/transformers/transformers/distribution/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import daoRewardsDistributor from './daoRewardsDistributor'

export default [...daoRewardsDistributor]
2 changes: 2 additions & 0 deletions src/transformers/transformers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {

import common from './common'
import dao from './dao'
import distribution from './distribution'
import external from './external'
import polytone from './polytone'
import prePropose from './prePropose'
Expand All @@ -31,6 +32,7 @@ export const getProcessedTransformers = (
// Add transformers here.
...common,
...dao,
...distribution,
...external,
...polytone,
...prePropose,
Expand Down

0 comments on commit 18fb3ff

Please sign in to comment.