Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable ABI types and fix erros #104

Merged
merged 7 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions artifacts/DAO.sol.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Abi } from "viem";
export const DaoAbi: Abi = [
export const DaoAbi = [
{
inputs: [],
stateMutability: "nonpayable",
Expand Down Expand Up @@ -1135,4 +1134,4 @@ export const DaoAbi: Abi = [
stateMutability: "payable",
type: "receive",
},
];
] as const;
18 changes: 15 additions & 3 deletions artifacts/ERC20Permit.sol.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Abi } from "viem";
export const ERC20PermitAbi: Abi = [
export const ERC20PermitAbi = [
{
inputs: [],
stateMutability: "nonpayable",
Expand Down Expand Up @@ -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;
16 changes: 12 additions & 4 deletions components/input/function-call-form.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -13,16 +13,17 @@ interface FunctionCallFormProps {
onAddAction: (action: Action) => any;
}
export const FunctionCallForm: FC<FunctionCallFormProps> = ({ onAddAction }) => {
const [targetContract, setTargetContract] = useState<string>("");
const [targetContract, setTargetContract] = useState<Address>();
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 (
Expand All @@ -33,7 +34,14 @@ export const FunctionCallForm: FC<FunctionCallFormProps> = ({ 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will work if you copy the address. But if for some reason you entered it manually, it would always reset the value to undefined.

We could show an error alert instead and simply assume that you will always copy addresses. But I would never change the user's value without proper feedback about what happened

Copy link
Contributor Author

@xavikh xavikh Apr 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, I rolled back the targetContract type to string and now I use as Address where is needed.

Maybe for another ticket: I noticed that we are using our own isAddress function instead of the provided by Viem. Is there any reason for this? I found out the Viem checker also checks for checksums.

Copy link
Contributor

@brickpop brickpop Apr 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't aware of viem's version, so it would be ideal if we switch into using it.
However, there's a great chance that people copy an address without the checksum, so I would be cautious with how strict we are with the checksum errors

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Np, I'll open a ticket for it 🎫

}
}}
/>
</div>
<If condition={loadingAbi}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Abi } from "viem";
export const OptimisticTokenVotingPluginAbi: Abi = [
export const OptimisticTokenVotingPluginAbi = [
{
inputs: [
{
Expand Down
2 changes: 1 addition & 1 deletion plugins/dualGovernance/hooks/useCanCreateProposal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
brickpop marked this conversation as resolved.
Show resolved Hide resolved
query: {
enabled: !!daoAddress && !!address,
},
Expand Down
16 changes: 11 additions & 5 deletions plugins/dualGovernance/hooks/useProposal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -36,14 +41,15 @@ export function useProposal(proposalId: string, autoRefresh = false) {
error: proposalError,
fetchStatus: proposalFetchStatus,
refetch: proposalRefetch,
} = useReadContract<typeof OptimisticTokenVotingPluginAbi, "getProposal", any[]>({
} = 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();
Expand Down Expand Up @@ -101,7 +107,7 @@ export function useProposal(proposalId: string, autoRefresh = false) {

// Helpers

function decodeProposalResultData(data?: Array<any>) {
function decodeProposalResultData(data?: ProposalResultType) {
if (!data?.length || data.length < 6) return null;

return {
Expand Down
4 changes: 2 additions & 2 deletions plugins/dualGovernance/hooks/useProposalExecute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -36,7 +36,7 @@ export function useProposalExecute(proposalId: string) {
abi: OptimisticTokenVotingPluginAbi,
address: PUB_DUAL_GOVERNANCE_PLUGIN_ADDRESS,
functionName: "execute",
args: [proposalId],
args: [BigInt(proposalId)],
});
};

Expand Down
2 changes: 1 addition & 1 deletion plugins/dualGovernance/hooks/useProposalVeto.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function useProposalVeto(proposalId: string) {
abi: OptimisticTokenVotingPluginAbi,
address: PUB_DUAL_GOVERNANCE_PLUGIN_ADDRESS,
functionName: "veto",
args: [proposalId],
args: [BigInt(proposalId)],
});
};

Expand Down
5 changes: 4 additions & 1 deletion plugins/dualGovernance/hooks/useUserCanVeto.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
2 changes: 1 addition & 1 deletion plugins/dualGovernance/pages/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)],
});
};

Expand Down
2 changes: 2 additions & 0 deletions plugins/dualGovernance/utils/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export type ProposalInputs = {
proposalId: bigint;
};

export type ProposalResultType = readonly [boolean, boolean, ProposalParameters, bigint, readonly Action[], bigint];

export type ProposalParameters = {
startDate: bigint;
endDate: bigint;
Expand Down
3 changes: 1 addition & 2 deletions plugins/lockToVote/artifacts/LockToVetoPlugin.sol.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Abi } from "viem";
export const LockToVetoPluginAbi: Abi = [
export const LockToVetoPluginAbi = [
{
inputs: [
{ internalType: "uint256", name: "proposalId", type: "uint256" },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Abi } from "viem";
export const OptimisticTokenVotingPluginAbi: Abi = [
export const OptimisticTokenVotingPluginAbi = [
{
inputs: [
{
Expand Down
2 changes: 1 addition & 1 deletion plugins/lockToVote/hooks/useCanCreateProposal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function useCanCreateProposal() {
const [isCreator, setIsCreator] = useState<boolean>(false);
const [minProposerVotingPower, setMinProposerVotingPower] = useState<bigint>();
const [votingToken, setVotingToken] = useState<Address>();
const { address, isConnecting, isDisconnected } = useAccount();
const { address } = useAccount();
const { data: balance } = useBalance({
address,
token: votingToken,
Expand Down
4 changes: 2 additions & 2 deletions plugins/lockToVote/hooks/useProposal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ export function useProposal(proposalId: string, autoRefresh = false) {
error: proposalError,
fetchStatus: proposalFetchStatus,
refetch: proposalRefetch,
} = useReadContract<typeof LockToVetoPluginAbi, "getProposal", any[]>({
} = 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);
Expand Down
9 changes: 6 additions & 3 deletions plugins/lockToVote/hooks/useProposalClaimLock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ export function useProposalClaimLock(proposalId: string) {
data: hasClaimed,
isError: isCanVoteError,
isLoading: isCanVoteLoading,
} = useReadContract<typeof LockToVetoPluginAbi, "hasClaimedLock", any[]>({
} = 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,
Expand All @@ -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!],
});
};

Expand Down
4 changes: 2 additions & 2 deletions plugins/lockToVote/hooks/useProposalExecute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)],
});
};

Expand Down
3 changes: 2 additions & 1 deletion plugins/lockToVote/hooks/useProposalVeto.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@ export function useProposalVeto(proposalId: string) {

signPermit(dest, value, deadline).then((sig) => {
if (!sig) return;
brickpop marked this conversation as resolved.
Show resolved Hide resolved
if (!sig.yParity) throw new Error("Invalid signature");
brickpop marked this conversation as resolved.
Show resolved Hide resolved

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],
});
});
};
Expand Down
5 changes: 4 additions & 1 deletion plugins/lockToVote/hooks/useUserCanVeto.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
2 changes: 1 addition & 1 deletion plugins/lockToVote/pages/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)],
});
};

Expand Down
6 changes: 4 additions & 2 deletions utils/types.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Loading