From 4b23c7b0d96ea5ab072db07dd3bead22582b6a1f Mon Sep 17 00:00:00 2001 From: Noah Saso Date: Mon, 4 Dec 2023 15:02:35 -0800 Subject: [PATCH] Filter out DAOs with no vetoable proposals. --- src/data/formulas/contract/daoCore/veto.ts | 140 +++++++++++---------- 1 file changed, 71 insertions(+), 69 deletions(-) diff --git a/src/data/formulas/contract/daoCore/veto.ts b/src/data/formulas/contract/daoCore/veto.ts index 895da711..a609aae9 100644 --- a/src/data/formulas/contract/daoCore/veto.ts +++ b/src/data/formulas/contract/daoCore/veto.ts @@ -71,78 +71,80 @@ export const vetoableProposals: ContractFormula = { ) ) - const vetoableProposalDaos = await Promise.all( - daos.map( - async (dao, index): Promise => ({ - dao, - proposalsWithModule: ( - await Promise.all( - daoActiveProposalModules[index].map( - async ( - proposalModule - ): Promise => { - const contractName = - proposalModule.info && - proposalModule.info.contract.replace('crates.io:', '') - - const configFormula = - contractName && PROPOSAL_MODULE_CONFIG_MAP[contractName] - const proposalFormula = - contractName && PROPOSAL_MAP[contractName] - - if (!configFormula || !proposalFormula) { - return - } - - const config = await configFormula.compute({ - ...env, - contractAddress: proposalModule.address, - }) - - if (!config?.veto) { - return - } - - return { - proposalModule, - proposals: ( - await Promise.all( - proposalsWithThisVetoer - .filter( - ({ proposalModuleAddress }) => - proposalModule.address === proposalModuleAddress - ) - .map(({ proposalId }) => - proposalFormula.compute({ - ...env, - contractAddress: proposalModule.address, - args: { - id: Number(proposalId).toString(), - }, - }) - ) - ) - ).filter( - (proposal): proposal is ProposalResponse => - !!proposal && - // Only include open proposals if early execute enabled. - ((proposal.proposal.status === StatusEnum.Open && - config.veto?.early_execute) || - // Include all veto timelock proposals. - (typeof proposal.proposal.status === 'object' && - 'veto_timelock' in proposal.proposal.status)) - ), + const vetoableProposalDaos = ( + await Promise.all( + daos.map( + async (dao, index): Promise => ({ + dao, + proposalsWithModule: ( + await Promise.all( + daoActiveProposalModules[index].map( + async ( + proposalModule + ): Promise => { + const contractName = + proposalModule.info && + proposalModule.info.contract.replace('crates.io:', '') + + const configFormula = + contractName && PROPOSAL_MODULE_CONFIG_MAP[contractName] + const proposalFormula = + contractName && PROPOSAL_MAP[contractName] + + if (!configFormula || !proposalFormula) { + return + } + + const config = await configFormula.compute({ + ...env, + contractAddress: proposalModule.address, + }) + + if (!config?.veto) { + return + } + + return { + proposalModule, + proposals: ( + await Promise.all( + proposalsWithThisVetoer + .filter( + ({ proposalModuleAddress }) => + proposalModule.address === proposalModuleAddress + ) + .map(({ proposalId }) => + proposalFormula.compute({ + ...env, + contractAddress: proposalModule.address, + args: { + id: Number(proposalId).toString(), + }, + }) + ) + ) + ).filter( + (proposal): proposal is ProposalResponse => + !!proposal && + // Only include open proposals if early execute enabled. + ((proposal.proposal.status === StatusEnum.Open && + config.veto?.early_execute) || + // Include all veto timelock proposals. + (typeof proposal.proposal.status === 'object' && + 'veto_timelock' in proposal.proposal.status)) + ), + } } - } + ) ) - ) - ).filter( - (proposalModule): proposalModule is VetoableProposalsWithModule => - !!proposalModule?.proposals.length - ), - }) + ).filter( + (proposalModule): proposalModule is VetoableProposalsWithModule => + !!proposalModule?.proposals.length + ), + }) + ) ) - ) + ).filter(({ proposalsWithModule }) => proposalsWithModule.length > 0) return vetoableProposalDaos },