Skip to content

Commit

Permalink
Merge pull request #414 from rossneilson/fix/fix-voting-power-in-snap…
Browse files Browse the repository at this point in the history
…shot

fix: Fixing voting power on vote transaction for snapshot guilds
  • Loading branch information
rossneilson committed Nov 9, 2022
2 parents bfb42be + 1638b14 commit 8527018
Show file tree
Hide file tree
Showing 16 changed files with 1,590 additions and 23 deletions.
173 changes: 166 additions & 7 deletions richContracts.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,28 +101,27 @@
},
"functions": [
{
"title": "Vote on a proposal",
"title": "Vote For proposal",
"functionName": "vote",
"params": [
{
"type": "bytes32",
"component": "address",
"component": "string",
"name": "proposalId",
"title": "Proposal ID",
"defaultValue": "",
"description": "Proposal ID - found from the URL of proposal"
},
{
"type": "uint256",
"component": "integer",
"name": "vote",
"title": "Vote decision",
"defaultValue": "",
"defaultValue": "1",
"description": "Vote decision (NO(2) or YES(1))"
},
{
"type": "uint256",
"component": "integer",
"component": "tokenAmount",
"name": "amount",
"title": "Amount to vote with",
"defaultValue": "",
Expand All @@ -133,13 +132,173 @@
"component": "address",
"name": "voter",
"title": "Voter",
"defaultValue": "",
"defaultValue": "0x99Fa013188d5f1dB6836Ee8805Ef37BE70ff10BE",
"description": "The guild's address"
}
],
"shortDescription": "Votes on a proposal with the guild's power",
"longDescription": "Creates a mirror proposal to use this guild's power to vote on a DXdao proposal. Care needs to be taken to finish this proposal before the DXdao proposal finishes.",
"templateLiteral": "Vote {proposalId}",
"templateLiteral": "Vote ${vote} with ${amount} REP on ${proposalId}",
"spendsTokens": false
},
{
"title": "Vote Against proposal",
"functionName": "vote",
"params": [
{
"type": "bytes32",
"component": "string",
"name": "proposalId",
"title": "Proposal ID",
"description": "Proposal ID - found from the URL of proposal"
},
{
"type": "uint256",
"component": "integer",
"name": "vote",
"title": "Vote decision",
"defaultValue": "2",
"description": "Vote decision (NO(2) or YES(1))"
},
{
"type": "uint256",
"component": "tokenAmount",
"name": "amount",
"title": "Amount of REP to vote with",
"defaultValue": "",
"description": "Amount to vote with"
},
{
"type": "address",
"component": "address",
"name": "voter",
"title": "Voter",
"defaultValue": "0x99Fa013188d5f1dB6836Ee8805Ef37BE70ff10BE",
"description": "The guild's address"
}
],
"shortDescription": "Votes on a proposal with the guild's power",
"longDescription": "Creates a mirror proposal to use this guild's power to vote on a DXdao proposal. Care needs to be taken to finish this proposal before the DXdao proposal finishes.",
"templateLiteral": "Vote ${vote} with ${amount} REP on ${proposalId}",
"spendsTokens": false
}
]
},
{
"title": "ENS Registry",
"tags": ["ens"],
"networks": {
"1": "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"
},
"functions": [
{
"title": "Create subdomain",
"functionName": "setSubnodeRecord",
"params": [
{
"type": "bytes32",
"component": "text",
"name": "node",
"title": "Subdomain node",
"defaultValue": "",
"description": "Name of parent ENS to set (e.g. projectdavi.eth)"
},
{
"type": "bytes32",
"component": "text",
"name": "label",
"title": "Subdomain label",
"defaultValue": "",
"description": "Name of new subdomain label"
},
{
"type": "address",
"component": "address",
"name": "owner",
"title": "ENS owner (the guild)",
"defaultValue": "",
"description": "Address of ENS owner"
},
{
"type": "address",
"component": "address",
"name": "resolver",
"title": "ENS Resolver",
"defaultValue": "0x4976fb03c32e5b8cfe2b6ccb31c09ba78ebaba41",
"description": "Address of ENS resolver"
},
{
"type": "uint64",
"component": "integer",
"name": "ttl",
"title": "Time to live",
"defaultValue": "0",
"description": "Time to live"
}
],
"shortDescription": "Creates a subdomain",
"longDescription": "Creates a subdomain from an ENS name the guild is controller of",
"templateLiteral": "Create an ENS subdomain",
"spendsTokens": false
},
{
"title": "Transfer subdomain",
"functionName": "setSubnodeOwner",
"params": [
{
"type": "bytes32",
"component": "text",
"name": "node",
"title": "Subdomain node",
"defaultValue": "",
"description": "Name of parent ENS to set (e.g. projectdavi.eth)"
},
{
"type": "bytes32",
"component": "text",
"name": "label",
"title": "Subdomain label",
"defaultValue": "",
"description": "Name of subdomain label"
},
{
"type": "address",
"component": "address",
"name": "owner",
"title": "ENS owner (the guild)",
"defaultValue": "",
"description": "Address of new ENS owner"
}
],
"shortDescription": "Transfers ENS subdomain",
"longDescription": "Transfers ENS subdomain",
"templateLiteral": "Transfer ENS subdomain to ${owner}",
"spendsTokens": false
},
{
"title": "Transfer ENS",
"functionName": "setOwner",
"params": [
{
"type": "bytes32",
"component": "text",
"name": "node",
"title": "Subdomain node",
"defaultValue": "",
"description": "Name of parent ENS to set (e.g. projectdavi.eth)"
},
{
"type": "address",
"component": "address",
"name": "owner",
"title": "ENS owner (the guild)",
"defaultValue": "",
"description": "Address of new ENS owner"
}
],
"shortDescription": "Transfers a root ENS domain",
"longDescription": "Transfers a root ENS domain",
"templateLiteral": "Transfer ENS to ${owner}",
"spendsTokens": false
}
]
Expand Down
8 changes: 6 additions & 2 deletions src/Modules/Guilds/Wrappers/ProposalVoteCardWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ProposalVoteCard } from 'components/ProposalVoteCard';
import { useTransactions } from 'contexts/Guilds';
import { useAccount } from 'wagmi';
import useProposalVotesOfVoter from 'Modules/Guilds/Hooks/useProposalVotesOfVoter';
import useGuildImplementationTypeConfig from '../Hooks/useGuildImplementationType';

const ProposalVoteCardWrapper = () => {
const { guildId, proposalId } = useTypedParams();
Expand All @@ -26,6 +27,8 @@ const ProposalVoteCardWrapper = () => {

const timestamp = useTimedRerender(10000);

const { isSnapshotGuild } = useGuildImplementationTypeConfig(guildId);

const { data: userVotingPower } = useVotingPowerOf({
contractAddress: guildId,
userAddress,
Expand Down Expand Up @@ -65,9 +68,10 @@ const ProposalVoteCardWrapper = () => {
proposal={{ ...proposal, id: proposalId, metadata: proposalMetadata }}
timestamp={timestamp}
votingPower={{
userVotingPower,
userVotingPower: isSnapshotGuild
? votingPowerAtProposalSnapshot
: userVotingPower,
percent: votingPowerPercent,
atSnapshot: votingPowerAtProposalSnapshot,
atCurrentSnapshot: votingPowerAtProposalCurrentSnapshot,
}}
contract={contract}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ jest.mock('hooks/Guilds/erc20/useERC20Info', () => ({
}));

jest.mock('wagmi', () => ({
useContractRead: () => ({ data: '' }),
useEnsResolver: () => ({
data: {
name: 'name.eth',
address: '0x0000000000000000000000000000000000000000',
contentHash: '0x0',
},
}),
useNetwork: () => ({ chain: mockChain, chains: [mockChain] }),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ jest.mock('hooks/Guilds/ens/useENS', () => ({
}));

jest.mock('wagmi', () => ({
useContractRead: () => ({ data: '' }),
useEnsResolver: () => ({
data: {
name: 'name.eth',
address: '0x0000000000000000000000000000000000000000',
contentHash: '0x0',
},
}),
useAccount: () => ({ isConnected: false }),
useNetwork: () => ({ chain: mockChain, chains: [mockChain] }),
useContractReads: () => ({ data: [] }),
Expand Down
8 changes: 8 additions & 0 deletions src/components/ActionsModal/ActionsModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ jest.mock('Modules/Guilds/Hooks/useGuildConfig', () => ({
const mockChainId = 123456;

jest.mock('wagmi', () => ({
useContractRead: () => ({ data: '' }),
useEnsResolver: () => ({
data: {
name: 'name.eth',
address: '0x0000000000000000000000000000000000000000',
contentHash: '0x0',
},
}),
useNetwork: () => ({ chain: { id: mockChainId } }),
useAccount: () => ({ isConnected: true }),
chain: {
Expand Down
8 changes: 8 additions & 0 deletions src/components/ProposalCard/ProposalCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ jest.mock('hooks/Guilds/erc20/useERC20Info', () => ({

jest.mock('wagmi', () => ({
chain: {},
useContractRead: () => ({ data: '' }),
useEnsResolver: () => ({
data: {
name: 'name.eth',
address: '0x0000000000000000000000000000000000000000',
contentHash: '0x0',
},
}),
useNetwork: () => ({ chain: mockChain, chains: [mockChain] }),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ jest.mock('hooks/Guilds/erc20/useERC20Info', () => ({

jest.mock('wagmi', () => ({
chain: {},
useContractRead: () => ({ data: '' }),
useEnsResolver: () => ({
data: {
name: 'name.eth',
address: '0x0000000000000000000000000000000000000000',
contentHash: '0x0',
},
}),
useNetwork: () => ({ chain: mockChain, chains: [mockChain] }),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const VoteQuorumContainer = styled.div<{ quorum: number }>`
? `${quorum}%`
: quorum > 90
? `calc(${quorum}% - 65px)`
: `calc(${quorum}% - 22px)`};
: `calc(${quorum}% - 32px)`};
`;

export const PaddedFlagCheckered = styled(FaFlagCheckered)`
Expand Down
2 changes: 1 addition & 1 deletion src/components/ProposalVoteCard/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface hasVotingPowerProps {
interface VotingPower {
percent: number;
userVotingPower: BigNumber;
atSnapshot: BigNumber;
atSnapshot?: BigNumber;
atCurrentSnapshot: BigNumber;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/TokenPicker/TokenPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const TokenPicker: React.FC<TokenPickerProps> = ({
/>
</SearchWrapper>
<TokenList>
{(searchQuery ? searchResults : tokens)?.slice(0, 4).map(token => (
{(searchQuery ? searchResults : tokens)?.map(token => (
<TokenListItem
key={token.id}
token={token}
Expand Down
2 changes: 1 addition & 1 deletion src/configs/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const RICH_CONTRACT_DATA_REGISTRY = 'QmPuywuaNbfVoTCm12J6UgkcJVkEjjEh9k6y9t8gakCbJj';
export const RICH_CONTRACT_DATA_REGISTRY = 'QmVyXJyemNzvnb7cGEjVdAphxa79jA83aL1nCdHUnc3jKx';
export const SITE_ID = 'NYKJUYYQ'
8 changes: 8 additions & 0 deletions src/hooks/Guilds/contracts/useRichContractRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ jest.mock('hooks/Guilds/ipfs/useIPFSFile', () => ({
}));

jest.mock('wagmi', () => ({
useContractRead: () => ({ data: '' }),
useEnsResolver: () => ({
data: {
name: 'name.eth',
address: '0x0000000000000000000000000000000000000000',
contentHash: '0x0',
},
}),
useNetwork: () => ({ chain: mockChain }),
}));

Expand Down
8 changes: 4 additions & 4 deletions src/hooks/Guilds/contracts/useRichContractRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { utils } from 'ethers';
import { useMemo } from 'react';
import { useNetwork } from 'wagmi';
import useIPFSFile from '../ipfs/useIPFSFile';
import { RICH_CONTRACT_DATA_REGISTRY } from 'configs';
import { useENSContentHash } from '../ens/useENSPublicResolverContract';

export interface RichContractFunctionParam {
type: string;
Expand Down Expand Up @@ -39,9 +39,9 @@ export type IPFSRichContractData = Omit<
export const useRichContractRegistry = (chainId?: number) => {
const { chain: activeChain } = useNetwork();

const { data, error } = useIPFSFile<IPFSRichContractData[]>(
RICH_CONTRACT_DATA_REGISTRY
);
const { ipfsHash } = useENSContentHash('contracts.projectdavi.eth', 1);

const { data, error } = useIPFSFile<IPFSRichContractData[]>(ipfsHash);

const registryContracts: RichContractData[] = useMemo(() => {
if (error || !data) return null;
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/Guilds/erc20/useAllERC20Balances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const useAllERC20Balances = (
if (!erc20TokensWithBalance) return tokens || undefined;

const tokensWithBalances = nativeTokenWithBalance
? [...erc20TokensWithBalance, nativeTokenWithBalance]
? [nativeTokenWithBalance, ...erc20TokensWithBalance]
: erc20TokensWithBalance;

return tokensWithBalances.sort((a, b) => {
Expand Down

0 comments on commit 8527018

Please sign in to comment.