generated from public-assembly/assemble-package
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improvements to governor provider, and more proposal hooks
- Loading branch information
1 parent
5b694d6
commit f3719c0
Showing
19 changed files
with
340 additions
and
58 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@public-assembly/builder-utils': patch | ||
--- | ||
|
||
Handles BigInt conversion natively on time based data queries. Adjust the GovernorProvider to return an array of stateful proposals and the associated type. |
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
This file was deleted.
Oops, something went wrong.
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
62 changes: 62 additions & 0 deletions
62
packages/builder-utils/src/hooks/useProposalPermissions.ts
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,62 @@ | ||
import { governorAbi } from '../abi' | ||
import { useGovernorContext } from '../context' | ||
import { useState } from 'react' | ||
import { Hex, Hash } from 'viem' | ||
import { useAccount, useContractReads } from 'wagmi' | ||
|
||
export function useProposalPermissions({ | ||
proposalId, | ||
timeCreated, | ||
}: { | ||
proposalId: Hash | ||
timeCreated: bigint | ||
}) { | ||
const { governorAddress } = useGovernorContext() | ||
const { address } = useAccount() | ||
const [canVeto, setCanVeto] = useState<boolean>(false) | ||
const [canCancel, setCanCancel] = useState<boolean>(false) | ||
const [canVote, setCanVote] = useState<boolean>(false) | ||
|
||
const governorContract = { | ||
address: governorAddress, | ||
abi: governorAbi, | ||
} | ||
|
||
useContractReads({ | ||
contracts: [ | ||
{ | ||
...governorContract, | ||
functionName: 'vetoer', | ||
}, | ||
{ | ||
...governorContract, | ||
functionName: 'getProposal', | ||
args: [proposalId], | ||
}, | ||
{ | ||
...governorContract, | ||
functionName: 'getVotes', | ||
args: [address as Hex, timeCreated], | ||
}, | ||
], | ||
onSuccess(proposalPermissions) { | ||
if (proposalPermissions[0].result === address) { | ||
setCanVeto(true) | ||
} | ||
|
||
if (proposalPermissions[1].result?.proposer === address) { | ||
setCanCancel(true) | ||
} | ||
|
||
if (Number(proposalPermissions[2].result) > 0) { | ||
setCanVote(true) | ||
} | ||
}, | ||
}) | ||
|
||
return { | ||
canVeto, | ||
canCancel, | ||
canVote, | ||
} | ||
} |
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,35 @@ | ||
import { governorAbi } from '../abi' | ||
import { Hash, Hex } from 'viem' | ||
import { readContract } from 'wagmi/actions' | ||
|
||
export enum ProposalState { | ||
Pending = 0, | ||
Active = 1, | ||
Canceled = 2, | ||
Defeated = 3, | ||
Succeeded = 4, | ||
Queued = 5, | ||
Expired = 6, | ||
Executed = 7, | ||
Vetoed = 8, | ||
} | ||
|
||
export const getProposalState = async (governorAddress: Hex, proposalId: Hash) => { | ||
return (await readContract({ | ||
address: governorAddress, | ||
abi: governorAbi, | ||
functionName: 'state', | ||
args: [proposalId], | ||
})) as ProposalState | ||
} | ||
|
||
export const getStatefulProposals = async (daoProposals, governorAddress) => { | ||
const statefulProposals = await Promise.all( | ||
daoProposals.map(async (proposal) => { | ||
const state = await getProposalState(governorAddress, proposal.id) | ||
return { ...proposal, state } | ||
}) | ||
) | ||
|
||
return statefulProposals | ||
} |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './etherscanLink' | ||
export * from './formatFromUnix' | ||
export * from './getProposalState' | ||
export * from './parseBase64String' | ||
export * from './shortenAddress' |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './hooks' | ||
export * from './types' |
Oops, something went wrong.