Skip to content

Commit

Permalink
moved active threshold formula to common voting route and added activ…
Browse files Browse the repository at this point in the history
…e threshold transformers
  • Loading branch information
NoahSaso committed Jun 2, 2024
1 parent 14052db commit c38f122
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 7 deletions.
7 changes: 7 additions & 0 deletions src/data/formulas/contract/voting/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ContractFormula } from '@/core/types'

export const activeThreshold: ContractFormula = {
compute: async ({ contractAddress, get, getTransformationMatch }) =>
(await getTransformationMatch(contractAddress, 'activeThreshold'))?.value ||
(await get(contractAddress, 'active_threshold')),
}
7 changes: 2 additions & 5 deletions src/data/formulas/contract/voting/daoVotingCw20Staked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
totalStaked,
} from '../staking/cw20Stake'

export { activeThreshold } from './common'

export const tokenContract: ContractFormula<string | undefined> = {
compute: async ({ contractAddress, get, getTransformationMatch }) =>
(await getTransformationMatch<string>(contractAddress, 'token'))?.value ??
Expand Down Expand Up @@ -74,11 +76,6 @@ export const dao: ContractFormula<string | undefined> = {
(await get<string>(contractAddress, 'dao')),
}

export const activeThreshold: ContractFormula = {
compute: async ({ contractAddress, get }) =>
await get(contractAddress, 'active_threshold'),
}

type Staker = StakerBalance & {
votingPowerPercent: number
}
Expand Down
1 change: 1 addition & 0 deletions src/data/formulas/contract/voting/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * as daoVoting from './common'
export * as daoVotingCw20Staked from './daoVotingCw20Staked'
export * as daoVotingCw4 from './daoVotingCw4'
export * as daoVotingCw721Staked from './daoVotingCw721Staked'
Expand Down
7 changes: 6 additions & 1 deletion src/data/transformers/voting/daoVotingCw20Staked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@ const stakingContract = makeTransformer(
)
const dao = makeTransformer(CODE_IDS_KEYS, 'dao')
const token = makeTransformer(CODE_IDS_KEYS, 'token')
const activeThreshold = makeTransformer(
CODE_IDS_KEYS,
'activeThreshold',
'active_threshold'
)

export default [stakingContract, dao, token]
export default [stakingContract, dao, token, activeThreshold]
6 changes: 6 additions & 0 deletions src/data/transformers/voting/daoVotingCw721Staked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ const KEY_PREFIX_NB = dbKeyForKeys('nb', '')
const config = makeTransformer(CODE_IDS_KEYS, 'config')
const dao = makeTransformer(CODE_IDS_KEYS, 'dao')
const totalStakedNfts = makeTransformer(CODE_IDS_KEYS, 'tsn')
const activeThreshold = makeTransformer(
CODE_IDS_KEYS,
'activeThreshold',
'active_threshold'
)

const stakedNftPerOwner: Transformer = {
filter: {
Expand Down Expand Up @@ -63,4 +68,5 @@ export default [
stakedNftPerOwner,
stakedNftOwner,
stakedCount,
activeThreshold,
]
7 changes: 6 additions & 1 deletion src/data/transformers/voting/daoVotingNativeStaked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@ const totalStaked = makeTransformer(
'totalStaked',
'total_staked'
)
const activeThreshold = makeTransformer(
CODE_IDS_KEYS,
'activeThreshold',
'active_threshold'
)

export default [config, dao, stakedBalance, totalStaked]
export default [config, dao, stakedBalance, totalStaked, activeThreshold]
6 changes: 6 additions & 0 deletions src/data/transformers/voting/daoVotingTokenStaked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ const totalStaked = makeTransformer(
'totalStaked',
'total_staked'
)
const activeThreshold = makeTransformer(
CODE_IDS_KEYS,
'activeThreshold',
'active_threshold'
)

export default [
config,
Expand All @@ -28,4 +33,5 @@ export default [
tokenIssuerContract,
stakedBalance,
totalStaked,
activeThreshold,
]

0 comments on commit c38f122

Please sign in to comment.