From 1c6b32226f5c68b6a61639fdcc614fb8388ad908 Mon Sep 17 00:00:00 2001 From: xavikh Date: Wed, 10 Apr 2024 00:21:06 +0200 Subject: [PATCH 1/7] Enable ABI types and fix erros --- artifacts/DAO.sol.ts | 5 ++--- artifacts/ERC20Permit.sol.ts | 18 +++++++++++++++--- .../OptimisticTokenVotingPlugin.sol.tsx | 3 +-- .../hooks/useCanCreateProposal.tsx | 2 +- plugins/dualGovernance/hooks/useProposal.tsx | 16 +++++++++++----- .../hooks/useProposalExecute.tsx | 4 ++-- .../dualGovernance/hooks/useProposalVeto.tsx | 2 +- .../dualGovernance/hooks/useUserCanVeto.tsx | 5 ++++- plugins/dualGovernance/utils/types.tsx | 4 ++++ .../artifacts/LockToVetoPlugin.sol.ts | 3 +-- .../OptimisticTokenVotingPlugin.sol.tsx | 3 +-- .../lockToVote/hooks/useCanCreateProposal.tsx | 2 +- plugins/lockToVote/hooks/useProposal.tsx | 4 ++-- .../lockToVote/hooks/useProposalClaimLock.tsx | 9 ++++++--- .../lockToVote/hooks/useProposalExecute.tsx | 4 ++-- plugins/lockToVote/hooks/useProposalVeto.tsx | 3 ++- plugins/lockToVote/hooks/useUserCanVeto.tsx | 5 ++++- plugins/lockToVote/pages/new.tsx | 2 +- utils/types.ts | 6 ++++-- 19 files changed, 65 insertions(+), 35 deletions(-) diff --git a/artifacts/DAO.sol.ts b/artifacts/DAO.sol.ts index a147e679..e47b78f1 100644 --- a/artifacts/DAO.sol.ts +++ b/artifacts/DAO.sol.ts @@ -1,5 +1,4 @@ -import { Abi } from "viem"; -export const DaoAbi: Abi = [ +export const DaoAbi = [ { inputs: [], stateMutability: "nonpayable", @@ -1135,4 +1134,4 @@ export const DaoAbi: Abi = [ stateMutability: "payable", type: "receive", }, -]; +] as const; diff --git a/artifacts/ERC20Permit.sol.ts b/artifacts/ERC20Permit.sol.ts index 40f835bb..f0ebeba7 100644 --- a/artifacts/ERC20Permit.sol.ts +++ b/artifacts/ERC20Permit.sol.ts @@ -1,5 +1,4 @@ -import { Abi } from "viem"; -export const ERC20PermitAbi: Abi = [ +export const ERC20PermitAbi = [ { inputs: [], stateMutability: "nonpayable", @@ -523,4 +522,17 @@ export const ERC20PermitAbi: Abi = [ stateMutability: "nonpayable", type: "function", }, -]; + { + inputs: [], + name: "version", + outputs: [ + { + internalType: "string", + name: "", + type: "string", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, +] as const; diff --git a/plugins/dualGovernance/artifacts/OptimisticTokenVotingPlugin.sol.tsx b/plugins/dualGovernance/artifacts/OptimisticTokenVotingPlugin.sol.tsx index 9a6619bd..80be1615 100644 --- a/plugins/dualGovernance/artifacts/OptimisticTokenVotingPlugin.sol.tsx +++ b/plugins/dualGovernance/artifacts/OptimisticTokenVotingPlugin.sol.tsx @@ -1,5 +1,4 @@ -import { Abi } from "viem"; -export const OptimisticTokenVotingPluginAbi: Abi = [ +export const OptimisticTokenVotingPluginAbi = [ { inputs: [ { diff --git a/plugins/dualGovernance/hooks/useCanCreateProposal.tsx b/plugins/dualGovernance/hooks/useCanCreateProposal.tsx index 3c6c6ea4..541961f7 100644 --- a/plugins/dualGovernance/hooks/useCanCreateProposal.tsx +++ b/plugins/dualGovernance/hooks/useCanCreateProposal.tsx @@ -56,7 +56,7 @@ export function useCanCreateProposal() { abi: DaoAbi, functionName: "hasPermission", // where, who, permissionId, data - args: [PUB_DUAL_GOVERNANCE_PLUGIN_ADDRESS, address, keccak256(toHex("PROPOSER_PERMISSION")), "0x"], + args: [PUB_DUAL_GOVERNANCE_PLUGIN_ADDRESS, address!, keccak256(toHex("PROPOSER_PERMISSION")), "0x"], query: { enabled: !!daoAddress && !!address, }, diff --git a/plugins/dualGovernance/hooks/useProposal.tsx b/plugins/dualGovernance/hooks/useProposal.tsx index 62beb376..41cbd1e9 100644 --- a/plugins/dualGovernance/hooks/useProposal.tsx +++ b/plugins/dualGovernance/hooks/useProposal.tsx @@ -3,7 +3,12 @@ import { useBlockNumber, usePublicClient, useReadContract } from "wagmi"; import { Hex, fromHex, getAbiItem } from "viem"; import { OptimisticTokenVotingPluginAbi } from "@/plugins/dualGovernance/artifacts/OptimisticTokenVotingPlugin.sol"; import { Action } from "@/utils/types"; -import { Proposal, ProposalMetadata, ProposalParameters } from "@/plugins/dualGovernance/utils/types"; +import { + Proposal, + ProposalMetadata, + ProposalParameters, + ProposalResultType, +} from "@/plugins/dualGovernance/utils/types"; import { PUB_CHAIN, PUB_DUAL_GOVERNANCE_PLUGIN_ADDRESS } from "@/constants"; import { useMetadata } from "@/hooks/useMetadata"; @@ -36,14 +41,15 @@ export function useProposal(proposalId: string, autoRefresh = false) { error: proposalError, fetchStatus: proposalFetchStatus, refetch: proposalRefetch, - } = useReadContract({ + } = useReadContract({ address: PUB_DUAL_GOVERNANCE_PLUGIN_ADDRESS, abi: OptimisticTokenVotingPluginAbi, functionName: "getProposal", - args: [proposalId], + args: [BigInt(proposalId)], chainId: PUB_CHAIN.id, }); - const proposalData = decodeProposalResultData(proposalResult as any); + + const proposalData = decodeProposalResultData(proposalResult); useEffect(() => { if (autoRefresh) proposalRefetch(); @@ -101,7 +107,7 @@ export function useProposal(proposalId: string, autoRefresh = false) { // Helpers -function decodeProposalResultData(data?: Array) { +function decodeProposalResultData(data: ProposalResultType) { if (!data?.length || data.length < 6) return null; return { diff --git a/plugins/dualGovernance/hooks/useProposalExecute.tsx b/plugins/dualGovernance/hooks/useProposalExecute.tsx index 0fb9d661..fa7d8d87 100644 --- a/plugins/dualGovernance/hooks/useProposalExecute.tsx +++ b/plugins/dualGovernance/hooks/useProposalExecute.tsx @@ -18,7 +18,7 @@ export function useProposalExecute(proposalId: string) { abi: OptimisticTokenVotingPluginAbi, chainId: PUB_CHAIN.id, functionName: "canExecute", - args: [proposalId], + args: [BigInt(proposalId)], }); const { writeContract: executeWrite, @@ -36,7 +36,7 @@ export function useProposalExecute(proposalId: string) { abi: OptimisticTokenVotingPluginAbi, address: PUB_DUAL_GOVERNANCE_PLUGIN_ADDRESS, functionName: "execute", - args: [proposalId], + args: [BigInt(proposalId)], }); }; diff --git a/plugins/dualGovernance/hooks/useProposalVeto.tsx b/plugins/dualGovernance/hooks/useProposalVeto.tsx index 0080cfb1..ae0c9827 100644 --- a/plugins/dualGovernance/hooks/useProposalVeto.tsx +++ b/plugins/dualGovernance/hooks/useProposalVeto.tsx @@ -56,7 +56,7 @@ export function useProposalVeto(proposalId: string) { abi: OptimisticTokenVotingPluginAbi, address: PUB_DUAL_GOVERNANCE_PLUGIN_ADDRESS, functionName: "veto", - args: [proposalId], + args: [BigInt(proposalId)], }); }; diff --git a/plugins/dualGovernance/hooks/useUserCanVeto.tsx b/plugins/dualGovernance/hooks/useUserCanVeto.tsx index e2d9d474..983172ee 100644 --- a/plugins/dualGovernance/hooks/useUserCanVeto.tsx +++ b/plugins/dualGovernance/hooks/useUserCanVeto.tsx @@ -12,7 +12,10 @@ export function useUserCanVeto(proposalId: bigint) { address: PUB_DUAL_GOVERNANCE_PLUGIN_ADDRESS, abi: OptimisticTokenVotingPluginAbi, functionName: "canVeto", - args: [proposalId, address], + args: [proposalId, address!], + query: { + enabled: !!address, + }, }); useEffect(() => { diff --git a/plugins/dualGovernance/utils/types.tsx b/plugins/dualGovernance/utils/types.tsx index 54375c62..9e1ad674 100644 --- a/plugins/dualGovernance/utils/types.tsx +++ b/plugins/dualGovernance/utils/types.tsx @@ -5,6 +5,10 @@ export type ProposalInputs = { proposalId: bigint; }; +export type ProposalResultType = + | readonly [boolean, boolean, ProposalParameters, bigint, readonly Action[], bigint] + | undefined; + export type ProposalParameters = { startDate: bigint; endDate: bigint; diff --git a/plugins/lockToVote/artifacts/LockToVetoPlugin.sol.ts b/plugins/lockToVote/artifacts/LockToVetoPlugin.sol.ts index edbaf595..13057c2f 100644 --- a/plugins/lockToVote/artifacts/LockToVetoPlugin.sol.ts +++ b/plugins/lockToVote/artifacts/LockToVetoPlugin.sol.ts @@ -1,5 +1,4 @@ -import { Abi } from "viem"; -export const LockToVetoPluginAbi: Abi = [ +export const LockToVetoPluginAbi = [ { inputs: [ { internalType: "uint256", name: "proposalId", type: "uint256" }, diff --git a/plugins/lockToVote/artifacts/OptimisticTokenVotingPlugin.sol.tsx b/plugins/lockToVote/artifacts/OptimisticTokenVotingPlugin.sol.tsx index 9a6619bd..80be1615 100644 --- a/plugins/lockToVote/artifacts/OptimisticTokenVotingPlugin.sol.tsx +++ b/plugins/lockToVote/artifacts/OptimisticTokenVotingPlugin.sol.tsx @@ -1,5 +1,4 @@ -import { Abi } from "viem"; -export const OptimisticTokenVotingPluginAbi: Abi = [ +export const OptimisticTokenVotingPluginAbi = [ { inputs: [ { diff --git a/plugins/lockToVote/hooks/useCanCreateProposal.tsx b/plugins/lockToVote/hooks/useCanCreateProposal.tsx index 5603758e..efd3e92e 100644 --- a/plugins/lockToVote/hooks/useCanCreateProposal.tsx +++ b/plugins/lockToVote/hooks/useCanCreateProposal.tsx @@ -8,7 +8,7 @@ export function useCanCreateProposal() { const [isCreator, setIsCreator] = useState(false); const [minProposerVotingPower, setMinProposerVotingPower] = useState(); const [votingToken, setVotingToken] = useState
(); - const { address, isConnecting, isDisconnected } = useAccount(); + const { address } = useAccount(); const { data: balance } = useBalance({ address, token: votingToken, diff --git a/plugins/lockToVote/hooks/useProposal.tsx b/plugins/lockToVote/hooks/useProposal.tsx index d1660604..0898f31e 100644 --- a/plugins/lockToVote/hooks/useProposal.tsx +++ b/plugins/lockToVote/hooks/useProposal.tsx @@ -36,11 +36,11 @@ export function useProposal(proposalId: string, autoRefresh = false) { error: proposalError, fetchStatus: proposalFetchStatus, refetch: proposalRefetch, - } = useReadContract({ + } = useReadContract({ address: PUB_LOCK_TO_VOTE_PLUGIN_ADDRESS, abi: LockToVetoPluginAbi, functionName: "getProposal", - args: [proposalId], + args: [BigInt(proposalId)], chainId: PUB_CHAIN.id, }); const proposalData = decodeProposalResultData(proposalResult as any); diff --git a/plugins/lockToVote/hooks/useProposalClaimLock.tsx b/plugins/lockToVote/hooks/useProposalClaimLock.tsx index 8dbcd0f5..870f8b08 100644 --- a/plugins/lockToVote/hooks/useProposalClaimLock.tsx +++ b/plugins/lockToVote/hooks/useProposalClaimLock.tsx @@ -14,12 +14,15 @@ export function useProposalClaimLock(proposalId: string) { data: hasClaimed, isError: isCanVoteError, isLoading: isCanVoteLoading, - } = useReadContract({ + } = useReadContract({ address: PUB_LOCK_TO_VOTE_PLUGIN_ADDRESS, abi: LockToVetoPluginAbi, chainId: PUB_CHAIN.id, functionName: "hasClaimedLock", - args: [proposalId, account.address], + args: [BigInt(proposalId), account.address!], + query: { + enabled: !!account.address, + }, }); const { writeContract: claimLockWrite, @@ -38,7 +41,7 @@ export function useProposalClaimLock(proposalId: string) { abi: LockToVetoPluginAbi, address: PUB_LOCK_TO_VOTE_PLUGIN_ADDRESS, functionName: "claimLock", - args: [proposalId, account.address], + args: [BigInt(proposalId), account.address!], }); }; diff --git a/plugins/lockToVote/hooks/useProposalExecute.tsx b/plugins/lockToVote/hooks/useProposalExecute.tsx index 8594b790..da3cb0e1 100644 --- a/plugins/lockToVote/hooks/useProposalExecute.tsx +++ b/plugins/lockToVote/hooks/useProposalExecute.tsx @@ -18,7 +18,7 @@ export function useProposalExecute(proposalId: string) { abi: OptimisticTokenVotingPluginAbi, chainId: PUB_CHAIN.id, functionName: "canExecute", - args: [proposalId], + args: [BigInt(proposalId)], }); const { writeContract: executeWrite, @@ -36,7 +36,7 @@ export function useProposalExecute(proposalId: string) { abi: OptimisticTokenVotingPluginAbi, address: PUB_LOCK_TO_VOTE_PLUGIN_ADDRESS, functionName: "execute", - args: [proposalId], + args: [BigInt(proposalId)], }); }; diff --git a/plugins/lockToVote/hooks/useProposalVeto.tsx b/plugins/lockToVote/hooks/useProposalVeto.tsx index 8b64c877..2a52cc17 100644 --- a/plugins/lockToVote/hooks/useProposalVeto.tsx +++ b/plugins/lockToVote/hooks/useProposalVeto.tsx @@ -72,12 +72,13 @@ export function useProposalVeto(proposalId: string) { signPermit(dest, value, deadline).then((sig) => { if (!sig) return; + if (!sig.yParity) throw new Error("Invalid signature"); vetoWrite({ abi: LockToVetoPluginAbi, address: dest, functionName: "vetoPermit", - args: [proposalId, value, deadline, sig.v, sig.r, sig.s], + args: [BigInt(proposalId), value, deadline, sig.yParity, sig.r, sig.s], }); }); }; diff --git a/plugins/lockToVote/hooks/useUserCanVeto.tsx b/plugins/lockToVote/hooks/useUserCanVeto.tsx index 415706eb..49916250 100644 --- a/plugins/lockToVote/hooks/useUserCanVeto.tsx +++ b/plugins/lockToVote/hooks/useUserCanVeto.tsx @@ -12,7 +12,10 @@ export function useUserCanVeto(proposalId: bigint) { address: PUB_LOCK_TO_VOTE_PLUGIN_ADDRESS, abi: LockToVetoPluginAbi, functionName: "canVeto", - args: [proposalId, address], + args: [proposalId, address!], + query: { + enabled: !!address, + }, }); useEffect(() => { diff --git a/plugins/lockToVote/pages/new.tsx b/plugins/lockToVote/pages/new.tsx index d9c4916e..bdfcdf59 100644 --- a/plugins/lockToVote/pages/new.tsx +++ b/plugins/lockToVote/pages/new.tsx @@ -123,7 +123,7 @@ export default function Create() { abi: OptimisticTokenVotingPluginAbi, address: PUB_LOCK_TO_VOTE_PLUGIN_ADDRESS, functionName: "createProposal", - args: [toHex(ipfsPin), actions, 0, 0, 0], + args: [toHex(ipfsPin), actions, BigInt(0), BigInt(0), BigInt(0)], }); }; diff --git a/utils/types.ts b/utils/types.ts index 3acbecba..95d0af09 100644 --- a/utils/types.ts +++ b/utils/types.ts @@ -1,7 +1,9 @@ +import { Address, Hex } from "viem"; + export type Action = { - to: string; + to: Address; value: bigint; - data: string; + data: Hex; }; export interface IAlert { From 1e402c7a65c4b7b79fb51d2e9fe383d83a8fd7fc Mon Sep 17 00:00:00 2001 From: xavikh Date: Wed, 10 Apr 2024 00:37:55 +0200 Subject: [PATCH 2/7] Fix function-call-form --- components/input/function-call-form.tsx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/components/input/function-call-form.tsx b/components/input/function-call-form.tsx index f75197c4..8830d58b 100644 --- a/components/input/function-call-form.tsx +++ b/components/input/function-call-form.tsx @@ -1,5 +1,5 @@ import { type FC, useState } from "react"; -import { type Address, type Hex } from "viem"; +import { type Address, type Hex, getAddress } from "viem"; import { AlertInline, InputText } from "@aragon/ods"; import { PleaseWaitSpinner } from "@/components/please-wait"; import { isAddress } from "@/utils/evm"; @@ -13,16 +13,17 @@ interface FunctionCallFormProps { onAddAction: (action: Action) => any; } export const FunctionCallForm: FC = ({ onAddAction }) => { - const [targetContract, setTargetContract] = useState(""); + const [targetContract, setTargetContract] = useState
(); const { abi, isLoading: loadingAbi, isProxy, implementation } = useAbi(targetContract as Address); const actionEntered = (data: Hex, value: bigint) => { + if (!targetContract) return; onAddAction({ to: targetContract, value, data, }); - setTargetContract(""); + setTargetContract(undefined); }; return ( @@ -33,7 +34,14 @@ export const FunctionCallForm: FC = ({ onAddAction }) => placeholder="0x1234..." variant={!targetContract || isAddress(targetContract) ? "default" : "critical"} value={targetContract} - onChange={(e) => setTargetContract(e.target.value || "")} + onChange={(e) => { + try { + const address = getAddress(e.target.value); + setTargetContract(address); + } catch (e) { + setTargetContract(undefined); + } + }} /> From 8f41d4efe1034727ec65ee6b0f42fb1e0c680d53 Mon Sep 17 00:00:00 2001 From: xavikh Date: Wed, 10 Apr 2024 00:40:47 +0200 Subject: [PATCH 3/7] Fix BigInt types missing --- plugins/dualGovernance/pages/new.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/dualGovernance/pages/new.tsx b/plugins/dualGovernance/pages/new.tsx index 42a4a04e..e62f57c7 100644 --- a/plugins/dualGovernance/pages/new.tsx +++ b/plugins/dualGovernance/pages/new.tsx @@ -123,7 +123,7 @@ export default function Create() { abi: OptimisticTokenVotingPluginAbi, address: PUB_DUAL_GOVERNANCE_PLUGIN_ADDRESS, functionName: "createProposal", - args: [toHex(ipfsPin), actions, 0, 0, 0], + args: [toHex(ipfsPin), actions, BigInt(0), BigInt(0), BigInt(0)], }); }; From 504621d2222871d7ae84a45176c52ec7a198c064 Mon Sep 17 00:00:00 2001 From: xavikh Date: Wed, 10 Apr 2024 09:49:18 +0200 Subject: [PATCH 4/7] Move optional --- plugins/dualGovernance/hooks/useProposal.tsx | 2 +- plugins/dualGovernance/utils/types.tsx | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/plugins/dualGovernance/hooks/useProposal.tsx b/plugins/dualGovernance/hooks/useProposal.tsx index 41cbd1e9..d62193b7 100644 --- a/plugins/dualGovernance/hooks/useProposal.tsx +++ b/plugins/dualGovernance/hooks/useProposal.tsx @@ -107,7 +107,7 @@ export function useProposal(proposalId: string, autoRefresh = false) { // Helpers -function decodeProposalResultData(data: ProposalResultType) { +function decodeProposalResultData(data?: ProposalResultType) { if (!data?.length || data.length < 6) return null; return { diff --git a/plugins/dualGovernance/utils/types.tsx b/plugins/dualGovernance/utils/types.tsx index 9e1ad674..f49ebe05 100644 --- a/plugins/dualGovernance/utils/types.tsx +++ b/plugins/dualGovernance/utils/types.tsx @@ -5,9 +5,7 @@ export type ProposalInputs = { proposalId: bigint; }; -export type ProposalResultType = - | readonly [boolean, boolean, ProposalParameters, bigint, readonly Action[], bigint] - | undefined; +export type ProposalResultType = readonly [boolean, boolean, ProposalParameters, bigint, readonly Action[], bigint]; export type ProposalParameters = { startDate: bigint; From bcf4f0d3c617ca7af71af6d53794ff8f5df40a62 Mon Sep 17 00:00:00 2001 From: xavikh Date: Tue, 16 Apr 2024 02:14:34 +0200 Subject: [PATCH 5/7] Feedback: Fix address input --- components/input/function-call-form.tsx | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/components/input/function-call-form.tsx b/components/input/function-call-form.tsx index 8830d58b..86e7ced2 100644 --- a/components/input/function-call-form.tsx +++ b/components/input/function-call-form.tsx @@ -1,5 +1,5 @@ import { type FC, useState } from "react"; -import { type Address, type Hex, getAddress } from "viem"; +import { type Address, type Hex } from "viem"; import { AlertInline, InputText } from "@aragon/ods"; import { PleaseWaitSpinner } from "@/components/please-wait"; import { isAddress } from "@/utils/evm"; @@ -13,17 +13,17 @@ interface FunctionCallFormProps { onAddAction: (action: Action) => any; } export const FunctionCallForm: FC = ({ onAddAction }) => { - const [targetContract, setTargetContract] = useState
(); + const [targetContract, setTargetContract] = useState(""); const { abi, isLoading: loadingAbi, isProxy, implementation } = useAbi(targetContract as Address); const actionEntered = (data: Hex, value: bigint) => { if (!targetContract) return; onAddAction({ - to: targetContract, + to: targetContract as Address, value, data, }); - setTargetContract(undefined); + setTargetContract(""); }; return ( @@ -35,12 +35,7 @@ export const FunctionCallForm: FC = ({ onAddAction }) => variant={!targetContract || isAddress(targetContract) ? "default" : "critical"} value={targetContract} onChange={(e) => { - try { - const address = getAddress(e.target.value); - setTargetContract(address); - } catch (e) { - setTargetContract(undefined); - } + setTargetContract(e.target.value || ""); }} /> @@ -53,7 +48,7 @@ export const FunctionCallForm: FC = ({ onAddAction }) =>

Enter the address of the contract to call in a new action

- + From ad70b61604aef71c4637a1efb1677e3b8d27620f Mon Sep 17 00:00:00 2001 From: xavikh Date: Tue, 16 Apr 2024 10:23:05 +0200 Subject: [PATCH 6/7] Feedback: not allow undefined address --- plugins/dualGovernance/hooks/useCanCreateProposal.tsx | 3 ++- utils/evm.ts | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/dualGovernance/hooks/useCanCreateProposal.tsx b/plugins/dualGovernance/hooks/useCanCreateProposal.tsx index 541961f7..2681b25e 100644 --- a/plugins/dualGovernance/hooks/useCanCreateProposal.tsx +++ b/plugins/dualGovernance/hooks/useCanCreateProposal.tsx @@ -4,6 +4,7 @@ import { useBalance, useAccount, useReadContracts, useReadContract } from "wagmi import { OptimisticTokenVotingPluginAbi } from "@/plugins/dualGovernance/artifacts/OptimisticTokenVotingPlugin.sol"; import { DaoAbi } from "@/artifacts/DAO.sol"; import { PUB_CHAIN, PUB_DUAL_GOVERNANCE_PLUGIN_ADDRESS } from "@/constants"; +import { ADDRESS_ZERO } from "@/utils/evm"; export function useCanCreateProposal() { const { address } = useAccount(); @@ -56,7 +57,7 @@ export function useCanCreateProposal() { abi: DaoAbi, functionName: "hasPermission", // where, who, permissionId, data - args: [PUB_DUAL_GOVERNANCE_PLUGIN_ADDRESS, address!, keccak256(toHex("PROPOSER_PERMISSION")), "0x"], + args: [PUB_DUAL_GOVERNANCE_PLUGIN_ADDRESS, address ?? ADDRESS_ZERO, keccak256(toHex("PROPOSER_PERMISSION")), "0x"], query: { enabled: !!daoAddress && !!address, }, diff --git a/utils/evm.ts b/utils/evm.ts index 90f90c6d..2d9c1404 100644 --- a/utils/evm.ts +++ b/utils/evm.ts @@ -12,3 +12,5 @@ export function formatHexString(address: string): string { // Take the first 5 characters (including '0x') and the last 4 characters return `${address.substring(0, 5)}...${address.substring(address.length - 4)}`; } + +export const ADDRESS_ZERO = "0x0000000000000000000000000000000000000000"; From 997ed14fa730eddacab894e2f56ed1c2f789c264 Mon Sep 17 00:00:00 2001 From: xavikh Date: Tue, 16 Apr 2024 10:25:35 +0200 Subject: [PATCH 7/7] Feedback: Better signature errors --- plugins/lockToVote/hooks/useProposalVeto.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/lockToVote/hooks/useProposalVeto.tsx b/plugins/lockToVote/hooks/useProposalVeto.tsx index 2a52cc17..cd113091 100644 --- a/plugins/lockToVote/hooks/useProposalVeto.tsx +++ b/plugins/lockToVote/hooks/useProposalVeto.tsx @@ -71,8 +71,7 @@ export function useProposalVeto(proposalId: string) { const deadline = BigInt(Math.floor(Date.now() / 1000) + 60 * 60); // 1 hour from now signPermit(dest, value, deadline).then((sig) => { - if (!sig) return; - if (!sig.yParity) throw new Error("Invalid signature"); + if (!sig?.yParity) throw new Error("Invalid signature"); vetoWrite({ abi: LockToVetoPluginAbi,