diff --git a/src/hooks/DAO/loaders/governance/useAzoriusProposals.ts b/src/hooks/DAO/loaders/governance/useAzoriusProposals.ts index d28c336c82..d74573d77a 100644 --- a/src/hooks/DAO/loaders/governance/useAzoriusProposals.ts +++ b/src/hooks/DAO/loaders/governance/useAzoriusProposals.ts @@ -1,6 +1,8 @@ import { LinearERC20Voting, LinearERC721Voting } from '@fractal-framework/fractal-contracts'; import { TypedListener } from '@fractal-framework/fractal-contracts/dist/typechain-types/common'; +import { ProposalExecutedEvent } from '@fractal-framework/fractal-contracts/dist/typechain-types/contracts/azorius/Azorius'; import { ProposalCreatedEvent } from '@fractal-framework/fractal-contracts/dist/typechain-types/contracts/azorius/Azorius'; +import { VotedEvent } from '@fractal-framework/fractal-contracts/dist/typechain-types/contracts/azorius/LinearERC20Voting'; import { VotedEvent as ERC20VotedEvent } from '@fractal-framework/fractal-contracts/dist/typechain-types/contracts/azorius/LinearERC20Voting'; import { VotedEvent as ERC721VotedEvent } from '@fractal-framework/fractal-contracts/dist/typechain-types/contracts/azorius/LinearERC721Voting'; import { BigNumber } from 'ethers'; @@ -78,7 +80,11 @@ export const useAzoriusProposals = () => { return []; } - const loadProposalFromEvent = async ({ args }: ProposalCreatedEvent) => { + const loadProposalFromEvent = async ( + { args }: ProposalCreatedEvent, + votedEvents: VotedEvent[], + executedEvents: ProposalExecutedEvent[], + ) => { let proposalData; if (args.metadata) { const metadataEvent: ProposalMetadata = JSON.parse(args.metadata); @@ -93,6 +99,7 @@ export const useAzoriusProposals = () => { decodedTransactions, }; } + return mapProposalCreatedEventToProposal( strategyContract, strategyType, @@ -100,16 +107,32 @@ export const useAzoriusProposals = () => { args.proposer, azoriusContract, provider, + votedEvents, + executedEvents, proposalData, ); }; const loadProposalSynchronously = async ( _proposalCreatedEvents: ProposalCreatedEvent[], - _loadProposalFromEvent: ({ args }: ProposalCreatedEvent) => Promise, + _loadProposalFromEvent: ( + { args }: ProposalCreatedEvent, + votedEvents: VotedEvent[], + executedEvents: ProposalExecutedEvent[], + ) => Promise, ) => { + const votedEventFilter = strategyContract.filters.Voted(); + const votedEvents = await strategyContract.queryFilter(votedEventFilter); + + const executedEventFilter = azoriusContract.filters.ProposalExecuted(); + const executedEvents = await azoriusContract.queryFilter(executedEventFilter); + for (const proposalCreatedEvent of _proposalCreatedEvents) { - const proposal = await _loadProposalFromEvent(proposalCreatedEvent); + const proposal = await _loadProposalFromEvent( + proposalCreatedEvent, + votedEvents, + executedEvents, + ); action.dispatch({ type: FractalGovernanceAction.SET_AZORIUS_PROPOSAL, payload: proposal, diff --git a/src/utils/azorius.ts b/src/utils/azorius.ts index 1061d44e8e..a986baa871 100644 --- a/src/utils/azorius.ts +++ b/src/utils/azorius.ts @@ -3,6 +3,8 @@ import { LinearERC20Voting, LinearERC721Voting, } from '@fractal-framework/fractal-contracts'; +import { ProposalExecutedEvent } from '@fractal-framework/fractal-contracts/dist/typechain-types/contracts/azorius/Azorius'; +import { VotedEvent } from '@fractal-framework/fractal-contracts/dist/typechain-types/contracts/azorius/LinearERC20Voting'; import { SafeMultisigTransactionWithTransfersResponse } from '@safe-global/safe-service-client'; import { BigNumber } from 'ethers'; import { strategyFractalProposalStates } from '../constants/strategy'; @@ -90,12 +92,13 @@ export const getProposalVotesSummary = async ( } }; -export const getProposalVotes = async ( - strategyContract: LinearERC20Voting | LinearERC721Voting, +const getProposalVotes = ( + // strategyContract: LinearERC20Voting | LinearERC721Voting, + votes: VotedEvent[], proposalId: BigNumber, -): Promise => { - const voteEventFilter = strategyContract.filters.Voted(); - const votes = await strategyContract.queryFilter(voteEventFilter); +): ProposalVote[] | ERC721ProposalVote[] => { + // const voteEventFilter = strategyContract.filters.Voted(); + // const votes = await strategyContract.queryFilter(voteEventFilter); const proposalVotesEvent = votes.filter(voteEvent => proposalId.eq(voteEvent.args.proposalId)); return proposalVotesEvent.map(({ args: { voter, voteType, ...rest } }) => { @@ -114,6 +117,8 @@ export const mapProposalCreatedEventToProposal = async ( proposer: string, azoriusContract: Azorius, provider: Providers, + votedEvents: VotedEvent[], + executedEvents: ProposalExecutedEvent[], data?: ProposalData, ) => { const { endBlock, startBlock, abstainVotes, yesVotes, noVotes } = @@ -121,9 +126,11 @@ export const mapProposalCreatedEventToProposal = async ( const quorum = await getQuorum(strategyContract, strategyType, proposalId); const deadlineSeconds = await getTimeStamp(endBlock, provider); - const state = await getAzoriusProposalState(azoriusContract, proposalId); - const votes = await getProposalVotes(strategyContract, proposalId); const block = await provider.getBlock(startBlock); + + const state = await getAzoriusProposalState(azoriusContract, proposalId); + const votes = getProposalVotes(votedEvents, proposalId); + const votesSummary = { yes: yesVotes, no: noVotes, @@ -135,9 +142,7 @@ export const mapProposalCreatedEventToProposal = async ( let transactionHash: string | undefined; if (state === FractalProposalState.EXECUTED) { - const proposalExecutedFilter = azoriusContract.filters.ProposalExecuted(); - const proposalExecutedEvents = await azoriusContract.queryFilter(proposalExecutedFilter); - const executedEvent = proposalExecutedEvents.find(event => + const executedEvent = executedEvents.find(event => BigNumber.from(event.args[0]).eq(proposalId), ); transactionHash = executedEvent?.transactionHash;