diff --git a/packages/contract-helpers/src/governance-v3/governance-data-helper/index.ts b/packages/contract-helpers/src/governance-v3/governance-data-helper/index.ts index 58737694..3c7abb78 100644 --- a/packages/contract-helpers/src/governance-v3/governance-data-helper/index.ts +++ b/packages/contract-helpers/src/governance-v3/governance-data-helper/index.ts @@ -51,6 +51,7 @@ export type ProposalV3 = { forVotes: string; againstVotes: string; cancellationFee: string; + payloads: ProposalPayload[]; }; export type ProposalData = { @@ -183,6 +184,16 @@ export class GovernanceDataHelperService forVotes: proposalData.proposalData.forVotes.toString(), againstVotes: proposalData.proposalData.againstVotes.toString(), cancellationFee: proposalData.proposalData.cancellationFee.toString(), + payloads: proposalData.proposalData.payloads.map( + payload => { + return { + chain: payload.chain.toNumber(), + accessLevel: payload.accessLevel, + payloadsController: payload.payloadsController, + payloadId: payload.payloadId, + }; + }, + ), }, }; }); diff --git a/packages/contract-helpers/src/governance-v3/payloads-data-helper/index.ts b/packages/contract-helpers/src/governance-v3/payloads-data-helper/index.ts new file mode 100644 index 00000000..0c6e96e4 --- /dev/null +++ b/packages/contract-helpers/src/governance-v3/payloads-data-helper/index.ts @@ -0,0 +1,88 @@ +import { providers } from 'ethers'; +import { AccessLevel } from '../governance-data-helper'; +import { PayloadsControllerDataHelper } from '../typechain/PayloadsControllerDataHelper'; +import { PayloadsControllerDataHelper__factory } from '../typechain/factories/PayloadsControllerDataHelper__factory'; + +export enum PayloadState { + None, + Created, + Queued, + Executed, + Cancelled, + Expired, +} + +export type ExecutionAction = { + target: string; + withDelegateCall: boolean; + accessLevel: AccessLevel; + value: string; + signature: string; + callData: string; +}; + +export type Payload = { + id: string; + creator: string; + maximumAccessLevelRequired: AccessLevel; + state: PayloadState; + createdAt: number; + queuedAt: number; + executedAt: number; + cancelledAt: number; + expirationTime: number; + delay: number; + gracePeriod: number; + actions: ExecutionAction[]; +}; +export class PayloadsDataHelperService { + private readonly _contract: PayloadsControllerDataHelper; + + constructor( + payloadsHelperContracAddress: string, + provider: providers.Provider, + ) { + this._contract = PayloadsControllerDataHelper__factory.connect( + payloadsHelperContracAddress, + provider, + ); + } + + public async getPayloadsData( + payloadsControllerAddress: string, + payloadsIds: number[], + ): Promise { + const data = await this._contract.getPayloadsData( + payloadsControllerAddress, + payloadsIds, + ); + + const payloads = data.map(payload => { + return { + id: payload.id.toString(), + creator: payload.data.creator, + maximumAccessLevelRequired: payload.data.maximumAccessLevelRequired, + state: payload.data.state, + createdAt: payload.data.createdAt, + queuedAt: payload.data.queuedAt, + executedAt: payload.data.executedAt, + cancelledAt: payload.data.cancelledAt, + expirationTime: payload.data.expirationTime, + delay: payload.data.delay, + gracePeriod: payload.data.gracePeriod, + actions: payload.data.actions.map(action => { + return { + target: action.target, + withDelegateCall: action.withDelegateCall, + accessLevel: action.accessLevel, + value: action.value.toString(), + signature: action.signature, + callData: action.callData, + }; + }), + }; + }); + + return payloads; + } +} diff --git a/packages/contract-helpers/src/governance-v3/typechain/PayloadsControllerDataHelper.d.ts b/packages/contract-helpers/src/governance-v3/typechain/PayloadsControllerDataHelper.d.ts new file mode 100644 index 00000000..51a1db6f --- /dev/null +++ b/packages/contract-helpers/src/governance-v3/typechain/PayloadsControllerDataHelper.d.ts @@ -0,0 +1,247 @@ +/* Autogenerated file. Do not edit manually. */ +/* eslint-disable */ +import type { + BaseContract, + BigNumber, + BigNumberish, + BytesLike, + CallOverrides, + PopulatedTransaction, + Signer, + utils, +} from 'ethers'; +import type { FunctionFragment, Result } from '@ethersproject/abi'; +import type { Listener, Provider } from '@ethersproject/providers'; +import type { + TypedEventFilter, + TypedEvent, + TypedListener, + OnEvent, +} from './common'; + +export declare namespace IPayloadsControllerCore { + export type ExecutorConfigStruct = { executor: string; delay: BigNumberish }; + + export type ExecutorConfigStructOutput = [string, number] & { + executor: string; + delay: number; + }; + + export type ExecutionActionStruct = { + target: string; + withDelegateCall: boolean; + accessLevel: BigNumberish; + value: BigNumberish; + signature: string; + callData: BytesLike; + }; + + export type ExecutionActionStructOutput = [ + string, + boolean, + number, + BigNumber, + string, + string, + ] & { + target: string; + withDelegateCall: boolean; + accessLevel: number; + value: BigNumber; + signature: string; + callData: string; + }; + + export type PayloadStruct = { + creator: string; + maximumAccessLevelRequired: BigNumberish; + state: BigNumberish; + createdAt: BigNumberish; + queuedAt: BigNumberish; + executedAt: BigNumberish; + cancelledAt: BigNumberish; + expirationTime: BigNumberish; + delay: BigNumberish; + gracePeriod: BigNumberish; + actions: IPayloadsControllerCore.ExecutionActionStruct[]; + }; + + export type PayloadStructOutput = [ + string, + number, + number, + number, + number, + number, + number, + number, + number, + number, + IPayloadsControllerCore.ExecutionActionStructOutput[], + ] & { + creator: string; + maximumAccessLevelRequired: number; + state: number; + createdAt: number; + queuedAt: number; + executedAt: number; + cancelledAt: number; + expirationTime: number; + delay: number; + gracePeriod: number; + actions: IPayloadsControllerCore.ExecutionActionStructOutput[]; + }; +} + +export declare namespace IPayloadsControllerDataHelper { + export type ExecutorConfigStruct = { + accessLevel: BigNumberish; + config: IPayloadsControllerCore.ExecutorConfigStruct; + }; + + export type ExecutorConfigStructOutput = [ + number, + IPayloadsControllerCore.ExecutorConfigStructOutput, + ] & { + accessLevel: number; + config: IPayloadsControllerCore.ExecutorConfigStructOutput; + }; + + export type PayloadStruct = { + id: BigNumberish; + data: IPayloadsControllerCore.PayloadStruct; + }; + + export type PayloadStructOutput = [ + BigNumber, + IPayloadsControllerCore.PayloadStructOutput, + ] & { id: BigNumber; data: IPayloadsControllerCore.PayloadStructOutput }; +} + +export interface PayloadsControllerDataHelperInterface extends utils.Interface { + functions: { + 'getExecutorConfigs(address,uint8[])': FunctionFragment; + 'getPayloadsData(address,uint40[])': FunctionFragment; + }; + + getFunction( + nameOrSignatureOrTopic: 'getExecutorConfigs' | 'getPayloadsData', + ): FunctionFragment; + + encodeFunctionData( + functionFragment: 'getExecutorConfigs', + values: [string, BigNumberish[]], + ): string; + encodeFunctionData( + functionFragment: 'getPayloadsData', + values: [string, BigNumberish[]], + ): string; + + decodeFunctionResult( + functionFragment: 'getExecutorConfigs', + data: BytesLike, + ): Result; + decodeFunctionResult( + functionFragment: 'getPayloadsData', + data: BytesLike, + ): Result; + + events: {}; +} + +export interface PayloadsControllerDataHelper extends BaseContract { + connect(signerOrProvider: Signer | Provider | string): this; + attach(addressOrName: string): this; + deployed(): Promise; + + interface: PayloadsControllerDataHelperInterface; + + queryFilter( + event: TypedEventFilter, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined, + ): Promise>; + + listeners( + eventFilter?: TypedEventFilter, + ): Array>; + listeners(eventName?: string): Array; + removeAllListeners( + eventFilter: TypedEventFilter, + ): this; + removeAllListeners(eventName?: string): this; + off: OnEvent; + on: OnEvent; + once: OnEvent; + removeListener: OnEvent; + + functions: { + getExecutorConfigs( + payloadsController: string, + accessLevels: BigNumberish[], + overrides?: CallOverrides, + ): Promise<[IPayloadsControllerDataHelper.ExecutorConfigStructOutput[]]>; + + getPayloadsData( + payloadsController: string, + payloadsIds: BigNumberish[], + overrides?: CallOverrides, + ): Promise<[IPayloadsControllerDataHelper.PayloadStructOutput[]]>; + }; + + getExecutorConfigs( + payloadsController: string, + accessLevels: BigNumberish[], + overrides?: CallOverrides, + ): Promise; + + getPayloadsData( + payloadsController: string, + payloadsIds: BigNumberish[], + overrides?: CallOverrides, + ): Promise; + + callStatic: { + getExecutorConfigs( + payloadsController: string, + accessLevels: BigNumberish[], + overrides?: CallOverrides, + ): Promise; + + getPayloadsData( + payloadsController: string, + payloadsIds: BigNumberish[], + overrides?: CallOverrides, + ): Promise; + }; + + filters: {}; + + estimateGas: { + getExecutorConfigs( + payloadsController: string, + accessLevels: BigNumberish[], + overrides?: CallOverrides, + ): Promise; + + getPayloadsData( + payloadsController: string, + payloadsIds: BigNumberish[], + overrides?: CallOverrides, + ): Promise; + }; + + populateTransaction: { + getExecutorConfigs( + payloadsController: string, + accessLevels: BigNumberish[], + overrides?: CallOverrides, + ): Promise; + + getPayloadsData( + payloadsController: string, + payloadsIds: BigNumberish[], + overrides?: CallOverrides, + ): Promise; + }; +} diff --git a/packages/contract-helpers/src/governance-v3/typechain/factories/PayloadsControllerDataHelper__factory.ts b/packages/contract-helpers/src/governance-v3/typechain/factories/PayloadsControllerDataHelper__factory.ts new file mode 100644 index 00000000..de700c18 --- /dev/null +++ b/packages/contract-helpers/src/governance-v3/typechain/factories/PayloadsControllerDataHelper__factory.ts @@ -0,0 +1,203 @@ +/* Autogenerated file. Do not edit manually. */ +/* eslint-disable */ + +import { Contract, Signer, utils } from 'ethers'; +import type { Provider } from '@ethersproject/providers'; +import type { + PayloadsControllerDataHelper, + PayloadsControllerDataHelperInterface, +} from '../PayloadsControllerDataHelper'; + +const _abi = [ + { + inputs: [ + { + internalType: 'contract IPayloadsController', + name: 'payloadsController', + type: 'address', + }, + { + internalType: 'enum PayloadsControllerUtils.AccessControl[]', + name: 'accessLevels', + type: 'uint8[]', + }, + ], + name: 'getExecutorConfigs', + outputs: [ + { + components: [ + { + internalType: 'enum PayloadsControllerUtils.AccessControl', + name: 'accessLevel', + type: 'uint8', + }, + { + components: [ + { + internalType: 'address', + name: 'executor', + type: 'address', + }, + { + internalType: 'uint40', + name: 'delay', + type: 'uint40', + }, + ], + internalType: 'struct IPayloadsControllerCore.ExecutorConfig', + name: 'config', + type: 'tuple', + }, + ], + internalType: 'struct IPayloadsControllerDataHelper.ExecutorConfig[]', + name: '', + type: 'tuple[]', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'contract IPayloadsController', + name: 'payloadsController', + type: 'address', + }, + { + internalType: 'uint40[]', + name: 'payloadsIds', + type: 'uint40[]', + }, + ], + name: 'getPayloadsData', + outputs: [ + { + components: [ + { + internalType: 'uint256', + name: 'id', + type: 'uint256', + }, + { + components: [ + { + internalType: 'address', + name: 'creator', + type: 'address', + }, + { + internalType: 'enum PayloadsControllerUtils.AccessControl', + name: 'maximumAccessLevelRequired', + type: 'uint8', + }, + { + internalType: 'enum IPayloadsControllerCore.PayloadState', + name: 'state', + type: 'uint8', + }, + { + internalType: 'uint40', + name: 'createdAt', + type: 'uint40', + }, + { + internalType: 'uint40', + name: 'queuedAt', + type: 'uint40', + }, + { + internalType: 'uint40', + name: 'executedAt', + type: 'uint40', + }, + { + internalType: 'uint40', + name: 'cancelledAt', + type: 'uint40', + }, + { + internalType: 'uint40', + name: 'expirationTime', + type: 'uint40', + }, + { + internalType: 'uint40', + name: 'delay', + type: 'uint40', + }, + { + internalType: 'uint40', + name: 'gracePeriod', + type: 'uint40', + }, + { + components: [ + { + internalType: 'address', + name: 'target', + type: 'address', + }, + { + internalType: 'bool', + name: 'withDelegateCall', + type: 'bool', + }, + { + internalType: 'enum PayloadsControllerUtils.AccessControl', + name: 'accessLevel', + type: 'uint8', + }, + { + internalType: 'uint256', + name: 'value', + type: 'uint256', + }, + { + internalType: 'string', + name: 'signature', + type: 'string', + }, + { + internalType: 'bytes', + name: 'callData', + type: 'bytes', + }, + ], + internalType: + 'struct IPayloadsControllerCore.ExecutionAction[]', + name: 'actions', + type: 'tuple[]', + }, + ], + internalType: 'struct IPayloadsControllerCore.Payload', + name: 'data', + type: 'tuple', + }, + ], + internalType: 'struct IPayloadsControllerDataHelper.Payload[]', + name: '', + type: 'tuple[]', + }, + ], + stateMutability: 'view', + type: 'function', + }, +] as const; + +export class PayloadsControllerDataHelper__factory { + static readonly abi = _abi; + static createInterface(): PayloadsControllerDataHelperInterface { + return new utils.Interface(_abi) as PayloadsControllerDataHelperInterface; + } + static connect( + address: string, + signerOrProvider: Signer | Provider, + ): PayloadsControllerDataHelper { + return new Contract( + address, + _abi, + signerOrProvider, + ) as PayloadsControllerDataHelper; + } +}