Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index delegations #11

Merged
merged 14 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/transformers.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ const subDaoMap = await getTransformationMap(contractAddress, 'subDao')

This function also has some options:

- `numericKey` will interpret the map keys as numbers instead of strings.
- `namer` lets you customize the count and types of keys that are used to derive
the name.
- `getValue` lets you override the default behavior of returning the value of
the map item.

Expand Down
2 changes: 1 addition & 1 deletion src/formulas/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ export const getEnv = ({
)

// If transformations found, create map.
const map: Record<string | number, any> = {}
const map: Record<string, any> = {}
for (const transformation of definedTransformations) {
map[transformation.name.slice(mapNamePrefix.length)] =
transformation.value
Expand Down
40 changes: 24 additions & 16 deletions src/formulas/formulas/contract/daoCore/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const proposalModules: ContractFormula<ProposalModuleWithInfo[]> = {

const proposalModules: ProposalModule[] = []

const transformedMap = await getTransformationMap<string, ProposalModule>(
const transformedMap = await getTransformationMap<ProposalModule>(
contractAddress,
'proposalModule'
)
Expand Down Expand Up @@ -355,10 +355,7 @@ export const listSubDaos: ContractFormula<SubDao[]> = {
compute: async ({ contractAddress, getTransformationMap, getMap }) => {
// V2. V1 doesn't have sub DAOs; use empty map if undefined.
const subDaoMap =
(await getTransformationMap<string, string | null>(
contractAddress,
'subDao'
)) ??
(await getTransformationMap<string | null>(contractAddress, 'subDao')) ??
// Fallback to events.
(await getMap<string, string | null>(contractAddress, 'sub_daos')) ??
{}
Expand All @@ -381,7 +378,7 @@ export const daoUri: ContractFormula<{ dao_uri: string | null }> = {

const VOTING_POWER_AT_HEIGHT_FORMULAS: ContractFormula<
VotingPowerAtHeight,
{ address: string }
{ address: string; height?: string }
>[] = [
daoVotingCw4VotingPowerAtHeight,
daoVotingCw20StakedVotingPowerAtHeight,
Expand All @@ -394,11 +391,11 @@ const VOTING_POWER_AT_HEIGHT_FORMULAS: ContractFormula<

export const votingPowerAtHeight: ContractFormula<
VotingPowerAtHeight,
{ address: string }
{ address: string; height?: string }
> = {
docs: {
description:
'retrieves the voting power at a specific block height for a given address',
'retrieves the voting power for a given address, optionally at a specific block height for a given address',
args: [
{
name: 'address',
Expand All @@ -409,9 +406,9 @@ export const votingPowerAtHeight: ContractFormula<
},
},
{
name: 'block',
name: 'height',
description: 'block height to check voting power at',
required: true,
required: false,
schema: {
type: 'integer',
},
Expand Down Expand Up @@ -463,7 +460,12 @@ export const votingPower: ContractFormula<string, { address: string }> = {
compute: async (env) => (await votingPowerAtHeight.compute(env)).power,
}

const TOTAL_POWER_AT_HEIGHT_FORMULAS: ContractFormula<TotalPowerAtHeight>[] = [
const TOTAL_POWER_AT_HEIGHT_FORMULAS: ContractFormula<
TotalPowerAtHeight,
{
height?: string
}
>[] = [
daoVotingCw4TotalPowerAtHeight,
daoVotingCw20StakedTotalPowerAtHeight,
daoVotingCw721StakedTotalPowerAtHeight,
Expand All @@ -473,14 +475,20 @@ const TOTAL_POWER_AT_HEIGHT_FORMULAS: ContractFormula<TotalPowerAtHeight>[] = [
daoVotingSgCommunityNftTotalPowerAtHeight,
]

export const totalPowerAtHeight: ContractFormula<TotalPowerAtHeight> = {
export const totalPowerAtHeight: ContractFormula<
TotalPowerAtHeight,
{
height?: string
}
> = {
docs: {
description: 'retrieves the total voting power at a specific block height',
description:
'retrieves the total voting power, optionally at a specific block height',
args: [
{
name: 'block',
name: 'height',
description: 'block height to check voting power at',
required: true,
required: false,
schema: {
type: 'integer',
},
Expand Down Expand Up @@ -514,7 +522,7 @@ export const totalPowerAtHeight: ContractFormula<TotalPowerAtHeight> = {
},
}

export const totalPower: ContractFormula<string, { address: string }> = {
export const totalPower: ContractFormula<string> = {
docs: {
description: 'retrieves the total voting power at the current block height',
},
Expand Down
Loading
Loading