-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: update caching * fix: remoe obsolete stuff * fix: add export * fix: migrate to new js-utils * fix: remove ipfs cache from governance
- Loading branch information
Showing
27 changed files
with
512 additions
and
342 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,5 @@ node_modules | |
yarn-error.log | ||
|
||
# proposal cache | ||
cache | ||
/cache | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { IGovernanceCore_ABI } from '@bgd-labs/aave-address-book'; | ||
import { strategicGetLogs } from '@bgd-labs/js-utils'; | ||
import { Address, Client, getAbiItem } from 'viem'; | ||
import type { ExtractAbiEvent } from 'abitype'; | ||
import { getBlock } from 'viem/actions'; | ||
import { LogWithTimestamp } from '../../../utils/logs'; | ||
|
||
export type ProposalCreatedEvent = LogWithTimestamp<ExtractAbiEvent<typeof IGovernanceCore_ABI, 'ProposalCreated'>>; | ||
export type ProposalQueuedEvent = LogWithTimestamp<ExtractAbiEvent<typeof IGovernanceCore_ABI, 'ProposalQueued'>>; | ||
export type ProposalCanceledEvent = LogWithTimestamp<ExtractAbiEvent<typeof IGovernanceCore_ABI, 'ProposalCanceled'>>; | ||
export type ProposalExecutedEvent = LogWithTimestamp<ExtractAbiEvent<typeof IGovernanceCore_ABI, 'ProposalExecuted'>>; | ||
export type ProposalPayloadSentEvent = LogWithTimestamp<ExtractAbiEvent<typeof IGovernanceCore_ABI, 'PayloadSent'>>; | ||
export type ProposalVotingActivatedEvent = LogWithTimestamp< | ||
ExtractAbiEvent<typeof IGovernanceCore_ABI, 'VotingActivated'> | ||
>; | ||
|
||
export enum ProposalState { | ||
Null, // proposal does not exists | ||
Created, // created, waiting for a cooldown to initiate the balances snapshot | ||
Active, // balances snapshot set, voting in progress | ||
Queued, // voting results submitted, but proposal is under grace period when guardian can cancel it | ||
Executed, // results sent to the execution chain(s) | ||
Failed, // voting was not successful | ||
Cancelled, // got cancelled by guardian, or because proposition power of creator dropped below allowed minimum | ||
Expired, | ||
} | ||
|
||
export function isProposalFinal(state: ProposalState) { | ||
return [ProposalState.Executed, ProposalState.Failed, ProposalState.Cancelled, ProposalState.Expired].includes(state); | ||
} | ||
|
||
export async function getGovernanceEvents( | ||
governanceAddress: Address, | ||
client: Client, | ||
fromBlockNumber: bigint, | ||
toBlockNumber: bigint | ||
) { | ||
const logs = await strategicGetLogs({ | ||
client, | ||
events: [ | ||
getAbiItem({ abi: IGovernanceCore_ABI, name: 'ProposalCreated' }), | ||
getAbiItem({ abi: IGovernanceCore_ABI, name: 'ProposalQueued' }), | ||
getAbiItem({ abi: IGovernanceCore_ABI, name: 'ProposalExecuted' }), | ||
getAbiItem({ abi: IGovernanceCore_ABI, name: 'PayloadSent' }), | ||
getAbiItem({ abi: IGovernanceCore_ABI, name: 'VotingActivated' }), | ||
getAbiItem({ abi: IGovernanceCore_ABI, name: 'ProposalCanceled' }), | ||
], | ||
address: governanceAddress, | ||
fromBlock: fromBlockNumber, | ||
toBlock: toBlockNumber, | ||
}); | ||
return await Promise.all( | ||
logs.map(async (l) => ({ | ||
...l, | ||
timestamp: Number((await getBlock(client, { blockNumber: l.blockNumber as bigint })).timestamp), | ||
})) | ||
); | ||
} | ||
|
||
export async function findProposalLogs(logs: Awaited<ReturnType<typeof getGovernanceEvents>>, proposalId: bigint) { | ||
const proposalLogs = logs.filter((log) => String(log.args.proposalId) === String(proposalId)); | ||
return { | ||
createdLog: proposalLogs.find((log) => log.eventName === 'ProposalCreated') as ProposalCreatedEvent, | ||
votingActivatedLog: proposalLogs.find((log) => log.eventName === 'VotingActivated') as ProposalVotingActivatedEvent, | ||
queuedLog: proposalLogs.find((log) => log.eventName === 'ProposalQueued') as ProposalQueuedEvent, | ||
executedLog: proposalLogs.find((log) => log.eventName === 'ProposalExecuted') as ProposalExecutedEvent, | ||
payloadSentLog: proposalLogs.filter((log) => log.eventName === 'PayloadSent') as ProposalPayloadSentEvent[], | ||
canceledLog: proposalLogs.find((log) => log.eventName === 'ProposalCanceled') as ProposalCanceledEvent, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { IPayloadsControllerCore_ABI } from '@bgd-labs/aave-address-book'; | ||
import { strategicGetLogs } from '@bgd-labs/js-utils'; | ||
import { Address, Client, getAbiItem } from 'viem'; | ||
import { getBlock } from 'viem/actions'; | ||
import type { ExtractAbiEvent } from 'abitype'; | ||
import { LogWithTimestamp } from '../../../utils/logs'; | ||
|
||
export type PayloadCreatedEvent = LogWithTimestamp< | ||
ExtractAbiEvent<typeof IPayloadsControllerCore_ABI, 'PayloadCreated'> | ||
>; | ||
export type PayloadQueuedEvent = LogWithTimestamp<ExtractAbiEvent<typeof IPayloadsControllerCore_ABI, 'PayloadQueued'>>; | ||
export type PayloadExecutedEvent = LogWithTimestamp< | ||
ExtractAbiEvent<typeof IPayloadsControllerCore_ABI, 'PayloadExecuted'> | ||
>; | ||
|
||
export enum PayloadState { | ||
None, | ||
Created, | ||
Queued, | ||
Executed, | ||
Cancelled, | ||
Expired, | ||
} | ||
|
||
export const HUMAN_READABLE_PAYLOAD_STATE = { | ||
[PayloadState.None]: 'None', | ||
[PayloadState.Created]: 'Created', | ||
[PayloadState.Queued]: 'Queued', | ||
[PayloadState.Executed]: 'Executed', | ||
[PayloadState.Cancelled]: 'Cancelled', | ||
[PayloadState.Expired]: 'Expired', | ||
}; | ||
|
||
export function isPayloadFinal(state: number) { | ||
return [ | ||
PayloadState.Cancelled, | ||
PayloadState.Executed, | ||
PayloadState.Expired, | ||
// -1, // error | ||
].includes(state); | ||
} | ||
|
||
export async function getPayloadsControllerEvents( | ||
payloadsControllerAddress: Address, | ||
client: Client, | ||
fromBlockNumber: bigint, | ||
toBlockNumber: bigint | ||
) { | ||
const logs = await strategicGetLogs({ | ||
client, | ||
events: [ | ||
getAbiItem({ abi: IPayloadsControllerCore_ABI, name: 'PayloadCreated' }), | ||
getAbiItem({ abi: IPayloadsControllerCore_ABI, name: 'PayloadQueued' }), | ||
getAbiItem({ abi: IPayloadsControllerCore_ABI, name: 'PayloadExecuted' }), | ||
], | ||
address: payloadsControllerAddress, | ||
fromBlock: fromBlockNumber, | ||
toBlock: toBlockNumber, | ||
}); | ||
return await Promise.all( | ||
logs.map(async (l) => ({ | ||
...l, | ||
timestamp: Number((await getBlock(client, { blockNumber: l.blockNumber as bigint })).timestamp), | ||
})) | ||
); | ||
} | ||
|
||
export async function findPayloadLogs( | ||
logs: Awaited<ReturnType<typeof getPayloadsControllerEvents>>, | ||
payloadId: number | ||
) { | ||
const proposalLogs = logs.filter((log) => String(log.args.payloadId) === String(payloadId)); | ||
return { | ||
createdLog: proposalLogs.find((log) => log.eventName === 'PayloadCreated') as PayloadCreatedEvent, | ||
queuedLog: proposalLogs.find((log) => log.eventName === 'PayloadQueued') as PayloadQueuedEvent, | ||
executedLog: proposalLogs.find((log) => log.eventName === 'PayloadExecuted') as PayloadExecutedEvent, | ||
}; | ||
} |
Oops, something went wrong.