From 69a9dca53f013d9c1ecf7b4375e6b5582ca1ed7a Mon Sep 17 00:00:00 2001 From: Milton Date: Wed, 6 Apr 2022 17:24:13 -0300 Subject: [PATCH 1/5] Refactor useGuildConfig to use diff guild implementations returning totalLocked value --- scripts/dev.ts | 142 +- .../ProposalPage/ProposalVoteCard/index.tsx | 1 - src/contracts/SnapshotERC20Guild.json | 1146 +++++++++++++++++ .../Guilds/ether-swr/guild/useGuildConfig.ts | 9 +- .../Guilds/ether-swr/guild/useSnapshotId.ts | 25 + .../Guilds/ether-swr/guild/useTotalLocked.ts | 43 + .../guild/useTotalLockedAtSnapshot.ts | 38 + .../guild/useGuildImplementationType.ts | 9 +- src/pages/Guilds/Proposal.tsx | 10 +- 9 files changed, 1374 insertions(+), 49 deletions(-) create mode 100644 src/contracts/SnapshotERC20Guild.json create mode 100644 src/hooks/Guilds/ether-swr/guild/useSnapshotId.ts create mode 100644 src/hooks/Guilds/ether-swr/guild/useTotalLocked.ts create mode 100644 src/hooks/Guilds/ether-swr/guild/useTotalLockedAtSnapshot.ts diff --git a/scripts/dev.ts b/scripts/dev.ts index 964681f36a..22df50d816 100644 --- a/scripts/dev.ts +++ b/scripts/dev.ts @@ -9,23 +9,47 @@ import { const hre = require('hardhat'); const moment = require('moment'); +const accounts = [ + '0x79706c8e413cdaee9e63f282507287b9ea9c0928', + '0xc73480525e9d1198d448ece4a01daea851f72a9d', + '0x3f943f38b2fbe1ee5daf0516cecfe4e0f8734351', + '0xaf1a6415202453d79b84d8a9d055b8f9141f696b', + '0x02803e2cdff171d1910d178dac948c711937bd3f', + '0x797c62953ef866a1ece855c4033cc5dc3c11290b', + '0x016f70459e4ba98e0d60a5f5855e117e8ff39cae', + '0x073f4fdc12f805b8d98e58551fc10d0a71bbc7db', + '0x6829556f30899d70403947590ffe8900e8c0d0d7', + '0x2b410bcb3b8096164fa8c6a06220a66bfb77058d', + '0x309f75c54a57937a7a0c6eb9b36eb1dbca82407e', + '0xec9d2d34ad6acda19ab8afe71595051b206e3e4d', + '0x40c23c536bad1fe206ce911114f2c70309a7e487', + '0x28d254f2ddb522c43a21d338e337fd8d2f820db2', + '0xaf7386ce842cc0cffef91361059b0ca9ae48d6a0', + '0x46c18451aaead6a2cb888b5bd6193c0f2c402329', + '0xc707c8143a6e1274ae7f637946f685870925261f', + '0x5b14a88dbbb04abcb6e5bf6384491be8d939cf57', + '0x92d356240dda25d050aa441690b92b2fa0011b84', + '0x5a485c203d9537095a6be2acc5a7ad83805d301d', +]; + async function main() { const web3 = hre.web3; const PermissionRegistry = await hre.artifacts.require('PermissionRegistry'); const ERC20Guild = await hre.artifacts.require('ERC20Guild'); + const SnapshotERC20Guild = await hre.artifacts.require('SnapshotERC20Guild'); const deployconfig = { reputation: [ { - address: '0x79706c8e413cdaee9e63f282507287b9ea9c0928', + address: accounts[0], amount: 6000, }, { - address: '0xc73480525e9d1198d448ece4a01daea851f72a9d', + address: accounts[1], amount: 4000, }, { - address: '0x3f943f38b2fbe1ee5daf0516cecfe4e0f8734351', + address: accounts[2], amount: 1000, }, ], @@ -36,15 +60,15 @@ async function main() { symbol: 'DXD', distribution: [ { - address: '0x79706c8e413cdaee9e63f282507287b9ea9c0928', + address: accounts[0], amount: web3.utils.toWei('220'), }, { - address: '0xc73480525e9d1198d448ece4a01daea851f72a9d', + address: accounts[1], amount: web3.utils.toWei('50'), }, { - address: '0x3f943f38b2fbe1ee5daf0516cecfe4e0f8734351', + address: accounts[2], amount: web3.utils.toWei('10'), }, ], @@ -54,15 +78,15 @@ async function main() { symbol: 'RGT', distribution: [ { - address: '0x79706c8e413cdaee9e63f282507287b9ea9c0928', + address: accounts[0], amount: web3.utils.toWei('200'), }, { - address: '0xc73480525e9d1198d448ece4a01daea851f72a9d', + address: accounts[1], amount: web3.utils.toWei('50'), }, { - address: '0x3f943f38b2fbe1ee5daf0516cecfe4e0f8734351', + address: accounts[2], amount: web3.utils.toWei('10'), }, ], @@ -72,15 +96,15 @@ async function main() { symbol: 'SGT', distribution: [ { - address: '0x79706c8e413cdaee9e63f282507287b9ea9c0928', + address: accounts[0], amount: web3.utils.toWei('200'), }, { - address: '0xc73480525e9d1198d448ece4a01daea851f72a9d', + address: accounts[1], amount: web3.utils.toWei('40'), }, { - address: '0x3f943f38b2fbe1ee5daf0516cecfe4e0f8734351', + address: accounts[2], amount: web3.utils.toWei('10'), }, ], @@ -248,7 +272,7 @@ async function main() { { token: 'SGT', contractName: 'SnapshotERC20Guild', - name: 'SnapshotGuild', + name: 'SnapshotERC20Guild', proposalTime: moment.duration(5, 'minutes').asSeconds(), timeForExecution: moment.duration(2, 'minutes').asSeconds(), votingPowerForProposalExecution: '50', @@ -265,7 +289,7 @@ async function main() { actions: [ { type: 'transfer', - from: '0x79706c8e413cdaee9e63f282507287b9ea9c0928', + from: accounts[0], data: { asset: ZERO_ADDRESS, address: 'Avatar', @@ -274,7 +298,7 @@ async function main() { }, { type: 'transfer', - from: '0x79706c8e413cdaee9e63f282507287b9ea9c0928', + from: accounts[0], data: { asset: 'DXD', address: 'Avatar', @@ -284,7 +308,7 @@ async function main() { { type: 'transfer', - from: '0x79706c8e413cdaee9e63f282507287b9ea9c0928', + from: accounts[0], data: { asset: ZERO_ADDRESS, address: 'DXDGuild', @@ -293,7 +317,7 @@ async function main() { }, { type: 'transfer', - from: '0x79706c8e413cdaee9e63f282507287b9ea9c0928', + from: accounts[0], data: { asset: 'DXD', address: 'DXDGuild', @@ -303,7 +327,26 @@ async function main() { { type: 'transfer', - from: '0x79706c8e413cdaee9e63f282507287b9ea9c0928', + from: accounts[1], + data: { + asset: ZERO_ADDRESS, + address: 'SnapshotERC20Guild', + amount: web3.utils.toWei('10'), + }, + }, + { + type: 'transfer', + from: accounts[1], + data: { + asset: 'SGT', + address: 'SnapshotERC20Guild', + amount: web3.utils.toWei('10'), + }, + }, + + { + type: 'transfer', + from: accounts[0], data: { asset: ZERO_ADDRESS, address: 'REPGuild', @@ -313,7 +356,7 @@ async function main() { { type: 'proposal', - from: '0x3f943f38b2fbe1ee5daf0516cecfe4e0f8734351', + from: accounts[2], data: { to: ['PermissionRegistry'], callData: [ @@ -337,7 +380,7 @@ async function main() { }, { type: 'stake', - from: '0x3f943f38b2fbe1ee5daf0516cecfe4e0f8734351', + from: accounts[2], data: { proposal: '0', decision: '1', @@ -347,7 +390,7 @@ async function main() { { type: 'vote', time: moment.duration(1, 'minutes').asSeconds(), - from: '0x3f943f38b2fbe1ee5daf0516cecfe4e0f8734351', + from: accounts[2], data: { proposal: '0', decision: '1', @@ -357,14 +400,14 @@ async function main() { { type: 'execute', time: moment.duration(3, 'minutes').asSeconds(), - from: '0x3f943f38b2fbe1ee5daf0516cecfe4e0f8734351', + from: accounts[2], data: { proposal: '0', }, }, { type: 'redeem', - from: '0x3f943f38b2fbe1ee5daf0516cecfe4e0f8734351', + from: accounts[2], data: { proposal: '0', }, @@ -372,7 +415,7 @@ async function main() { { type: 'proposal', - from: '0x3f943f38b2fbe1ee5daf0516cecfe4e0f8734351', + from: accounts[2], data: { to: ['QuickWalletScheme'], callData: ['0x0'], @@ -385,7 +428,7 @@ async function main() { }, { type: 'stake', - from: '0x3f943f38b2fbe1ee5daf0516cecfe4e0f8734351', + from: accounts[2], data: { proposal: '1', decision: '1', @@ -395,7 +438,7 @@ async function main() { { type: 'vote', time: moment.duration(1, 'minutes').asSeconds(), - from: '0x3f943f38b2fbe1ee5daf0516cecfe4e0f8734351', + from: accounts[2], data: { proposal: '1', decision: '1', @@ -404,7 +447,7 @@ async function main() { }, { type: 'vote', - from: '0xc73480525e9d1198d448ece4a01daea851f72a9d', + from: accounts[1], data: { proposal: '1', decision: '2', @@ -414,9 +457,9 @@ async function main() { { type: 'proposal', - from: '0x3f943f38b2fbe1ee5daf0516cecfe4e0f8734351', + from: accounts[2], data: { - to: ['0x3f943f38b2fbe1ee5daf0516cecfe4e0f8734351'], + to: [accounts[2]], callData: ['0x0'], value: [web3.utils.toWei('1.5')], title: 'Proposal Test #2', @@ -429,7 +472,7 @@ async function main() { { type: 'approve', - from: '0x79706c8e413cdaee9e63f282507287b9ea9c0928', + from: accounts[0], data: { asset: 'DXD', address: 'DXDGuild-vault', @@ -438,7 +481,7 @@ async function main() { }, { type: 'guild-lockTokens', - from: '0x79706c8e413cdaee9e63f282507287b9ea9c0928', + from: accounts[0], data: { guildName: 'DXDGuild', amount: web3.utils.toWei('100'), @@ -446,7 +489,7 @@ async function main() { }, { type: 'guild-withdrawTokens', - from: '0x79706c8e413cdaee9e63f282507287b9ea9c0928', + from: accounts[0], data: { guildName: 'DXDGuild', amount: web3.utils.toWei('10'), @@ -455,7 +498,7 @@ async function main() { }, { type: 'guild-createProposal', - from: '0x79706c8e413cdaee9e63f282507287b9ea9c0928', + from: accounts[0], data: { guildName: 'DXDGuild', to: ['DXDGuild'], @@ -479,7 +522,7 @@ async function main() { }, { type: 'guild-voteProposal', - from: '0xc73480525e9d1198d448ece4a01daea851f72a9d', + from: accounts[1], data: { guildName: 'DXDGuild', proposal: 0, @@ -490,18 +533,43 @@ async function main() { { time: moment.duration(10, 'minutes').asSeconds(), type: 'guild-endProposal', - from: '0xc73480525e9d1198d448ece4a01daea851f72a9d', + from: accounts[1], data: { guildName: 'DXDGuild', proposal: 0, }, }, + { + type: 'guild-createProposal', + from: accounts[1], + data: { + guildName: 'SnapshotERC20Guild', + to: ['SnapshotERC20Guild'], + callData: [ + new web3.eth.Contract(SnapshotERC20Guild.abi).methods + .setPermission( + [ZERO_ADDRESS], + [ANY_ADDRESS], + [ANY_FUNC_SIGNATURE], + [web3.utils.toWei('5').toString()], + [true] + ) + .encodeABI(), + ], + value: ['0'], + totalActions: '1', + title: 'Proposal Test #1 to SnapshotERC20Guild', + description: + 'Allow call any address and function and send a max of 5 ETH per proposal', + }, + }, + { type: 'proposal', - from: '0x3f943f38b2fbe1ee5daf0516cecfe4e0f8734351', + from: accounts[2], data: { - to: ['0x3f943f38b2fbe1ee5daf0516cecfe4e0f8734351'], + to: [accounts[2]], callData: ['0x0'], value: [web3.utils.toWei('1.5')], title: 'Proposal Test #3', diff --git a/src/components/Guilds/ProposalPage/ProposalVoteCard/index.tsx b/src/components/Guilds/ProposalPage/ProposalVoteCard/index.tsx index b84009e26e..992058c69f 100644 --- a/src/components/Guilds/ProposalPage/ProposalVoteCard/index.tsx +++ b/src/components/Guilds/ProposalPage/ProposalVoteCard/index.tsx @@ -101,7 +101,6 @@ const ProposalVoteCard = () => { contract.setVote(proposalId, selectedAction, userVotingPower) ); }; - return ( { [guildAddress, 'getVotingPowerForProposalExecution'], [guildAddress, 'getTokenVault'], [guildAddress, 'getLockTime'], - [guildAddress, 'getTotalLocked'], ] : [], { @@ -40,6 +40,8 @@ export const useGuildConfig = (guildAddress: string) => { } ); + const { data: totalLocked } = useTotalLocked(guildAddress); + // TODO: Move this into a SWR middleware const transformedData: GuildConfig = useMemo(() => { if (!data) return undefined; @@ -55,7 +57,6 @@ export const useGuildConfig = (guildAddress: string) => { votingPowerForProposalExecution, tokenVault, lockTime, - totalLocked, ] = data; return { @@ -73,9 +74,9 @@ export const useGuildConfig = (guildAddress: string) => { ), tokenVault, lockTime: BigNumber.from(lockTime), - totalLocked: BigNumber.from(totalLocked), + totalLocked: totalLocked, }; - }, [data]); + }, [data, totalLocked]); return { error, diff --git a/src/hooks/Guilds/ether-swr/guild/useSnapshotId.ts b/src/hooks/Guilds/ether-swr/guild/useSnapshotId.ts new file mode 100644 index 0000000000..25e8a5070b --- /dev/null +++ b/src/hooks/Guilds/ether-swr/guild/useSnapshotId.ts @@ -0,0 +1,25 @@ +import { BigNumber } from 'ethers'; +import { SWRResponse } from 'swr'; +import useEtherSWR from '../useEtherSWR'; +import SnapshotERC20Guild from 'contracts/SnapshotERC20Guild.json'; + +interface UseSnapshotIdProps { + contractAddress: string; + proposalId: string; +} + +type UseSnapshotIdHook = (args: UseSnapshotIdProps) => SWRResponse; + +const useSnapshotId: UseSnapshotIdHook = ({ contractAddress, proposalId }) => { + return useEtherSWR( + proposalId && contractAddress + ? [contractAddress, 'getProposalSnapshotId', proposalId] + : [], + { + ABIs: new Map([[contractAddress, SnapshotERC20Guild.abi]]), + } + ); +}; + +export default useSnapshotId; + diff --git a/src/hooks/Guilds/ether-swr/guild/useTotalLocked.ts b/src/hooks/Guilds/ether-swr/guild/useTotalLocked.ts new file mode 100644 index 0000000000..97e2498eb7 --- /dev/null +++ b/src/hooks/Guilds/ether-swr/guild/useTotalLocked.ts @@ -0,0 +1,43 @@ +import { useParams } from 'react-router-dom'; +import ERC20GuildContract from 'contracts/ERC20Guild.json'; +import useEtherSWR from '../useEtherSWR'; +import useTotalLockedAtSnapshot from 'hooks/Guilds/ether-swr/guild/useTotalLockedAtSnapshot'; +import useGuildImplementationType from 'hooks/Guilds/guild/useGuildImplementationType'; + +const useTotalLocked = (guildAddress: string) => { + // Hooks call + const { proposal_id: proposalId } = useParams<{ proposal_id?: string }>(); + const { isSnapshotGuild, isRepGuild, isSnapshotRepGuild } = + useGuildImplementationType(guildAddress); + + const totalLockedResponse = useEtherSWR( + guildAddress ? [guildAddress, 'getTotalLocked'] : [], + { + ABIs: new Map([[guildAddress, ERC20GuildContract.abi]]), + refreshInterval: 0, + } + ); + + const totalLockedAtProposalSnapshotResponse = useTotalLockedAtSnapshot({ + contractAddress: guildAddress, + proposalId, + }); + + // console.log({ + // isSnapshotGuild, + // isRepGuild, + // isSnapshotRepGuild, + // 'totalLockedResponse.data': totalLockedResponse.data, + // 'totalLockedAtProposalSnapshotResponse.data': + // totalLockedAtProposalSnapshotResponse.data, + // }); + + // Return response based on implementation type + if (isSnapshotGuild) return totalLockedAtProposalSnapshotResponse; + if (isRepGuild) return totalLockedResponse; // TODO: replace with rep implementation totalLocked call + if (isSnapshotRepGuild) return totalLockedResponse; // TODO: replace with rep implementation totalLocked call + return totalLockedResponse; +}; + +export default useTotalLocked; + diff --git a/src/hooks/Guilds/ether-swr/guild/useTotalLockedAtSnapshot.ts b/src/hooks/Guilds/ether-swr/guild/useTotalLockedAtSnapshot.ts new file mode 100644 index 0000000000..037400c3de --- /dev/null +++ b/src/hooks/Guilds/ether-swr/guild/useTotalLockedAtSnapshot.ts @@ -0,0 +1,38 @@ +import { BigNumber } from 'ethers'; +import { SWRResponse } from 'swr'; +import useEtherSWR from '../useEtherSWR'; +import useSnapshotId from './useSnapshotId'; +import SnapshotERC20Guild from 'contracts/SnapshotERC20Guild.json'; + +interface UseTotalLockedAtSnapshotProps { + contractAddress: string; + proposalId: string; +} + +type UseTotalLockedAtSnapshotHook = ( + args: UseTotalLockedAtSnapshotProps +) => SWRResponse; + +const useTotalLockedAtSnapshot: UseTotalLockedAtSnapshotHook = ({ + contractAddress, + proposalId, +}) => { + const { data: snapshotId } = useSnapshotId({ contractAddress, proposalId }); + return useEtherSWR( + snapshotId && contractAddress + ? [contractAddress, 'totalLockedAt', snapshotId.toString()] + : [], + { + ABIs: new Map([[contractAddress, SnapshotERC20Guild.abi]]), + } + ); +}; + +export default useTotalLockedAtSnapshot; + +// Create useSnapshotIf hook +// Create useTotalLockedAtSnapshot hook +// Create snapshotERC20Guild instance with proposal in dev script. +// Create useTotalLocked hook to use with multiple implementations +// Remove getTotalLocked call from useGuildConfig hook + diff --git a/src/hooks/Guilds/guild/useGuildImplementationType.ts b/src/hooks/Guilds/guild/useGuildImplementationType.ts index 1ccd2e2d2e..4098514539 100644 --- a/src/hooks/Guilds/guild/useGuildImplementationType.ts +++ b/src/hooks/Guilds/guild/useGuildImplementationType.ts @@ -21,14 +21,19 @@ interface ImplementationTypeConfig { interface ImplementationTypeConfigReturn extends ImplementationTypeConfig { isRepGuild: boolean; isSnapshotGuild: boolean; + isSnapshotRepGuild: boolean; } const parseConfig = ( config: ImplementationTypeConfig ): ImplementationTypeConfigReturn => { return { ...config, - isRepGuild: config.features.includes('REP'), - isSnapshotGuild: config.features.includes('SNAPSHOT'), + isRepGuild: + config.features.includes('REP') && !config.features.includes('SNAPSHOT'), + isSnapshotGuild: + config.features.includes('SNAPSHOT') && !config.features.includes('REP'), + isSnapshotRepGuild: + config.features.includes('SNAPSHOT') && config.features.includes('REP'), }; }; diff --git a/src/pages/Guilds/Proposal.tsx b/src/pages/Guilds/Proposal.tsx index c95c90cc26..e0753e74e1 100644 --- a/src/pages/Guilds/Proposal.tsx +++ b/src/pages/Guilds/Proposal.tsx @@ -13,11 +13,11 @@ import UnstyledLink from '../../components/Guilds/common/UnstyledLink'; import AddressButton from '../../components/Guilds/AddressButton'; import ProposalDescription from '../../components/Guilds/ProposalPage/ProposalDescription'; import { useProposal } from '../../hooks/Guilds/ether-swr/guild/useProposal'; -import { ActionsBuilder } from 'components/Guilds/CreateProposalPage'; +// import { ActionsBuilder } from 'components/Guilds/CreateProposalPage'; import { GuildAvailabilityContext } from 'contexts/Guilds/guildAvailability'; import Result, { ResultState } from 'components/Guilds/common/Result'; import { useGuildProposalIds } from 'hooks/Guilds/ether-swr/guild/useGuildProposalIds'; -import useProposalCalls from 'hooks/Guilds/guild/useProposalCalls'; +// import useProposalCalls from 'hooks/Guilds/guild/useProposalCalls'; const PageContainer = styled(Box)` display: grid; @@ -94,8 +94,8 @@ const ProposalPage: React.FC = () => { ); const { data: proposalIds } = useGuildProposalIds(guildId); const { data: proposal, error } = useProposal(guildId, proposalId); - const { options } = useProposalCalls(guildId, proposalId); - + // const { options } = useProposalCalls(guildId, proposalId); + // console.log('options', options); if (!isGuildAvailabilityLoading) { if (!proposalIds?.includes(proposalId)) { return ( @@ -150,7 +150,7 @@ const ProposalPage: React.FC = () => { - + {/* */} From 1c6a5746b606c90a87af65f88ca19326429f9596 Mon Sep 17 00:00:00 2001 From: Milton Date: Wed, 6 Apr 2022 17:24:40 -0300 Subject: [PATCH 2/5] format --- src/contracts/SnapshotERC20Guild.json | 2291 ++++++++--------- .../Guilds/ether-swr/guild/useSnapshotId.ts | 49 +- .../Guilds/ether-swr/guild/useTotalLocked.ts | 85 +- .../guild/useTotalLockedAtSnapshot.ts | 75 +- 4 files changed, 1248 insertions(+), 1252 deletions(-) diff --git a/src/contracts/SnapshotERC20Guild.json b/src/contracts/SnapshotERC20Guild.json index 02bebde9aa..c9bba32d29 100644 --- a/src/contracts/SnapshotERC20Guild.json +++ b/src/contracts/SnapshotERC20Guild.json @@ -1,1146 +1,1145 @@ -{ - "_format": "hh-sol-artifact-1", - "contractName": "SnapshotERC20Guild", - "sourceName": "dxdao-contracts/contracts/erc20guild/implementations/SnapshotERC20Guild.sol", - "abi": [ - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "bytes32", - "name": "proposalId", - "type": "bytes32" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "newState", - "type": "uint256" - } - ], - "name": "ProposalStateChanged", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "voter", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "value", - "type": "uint256" - } - ], - "name": "TokensLocked", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "voter", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "value", - "type": "uint256" - } - ], - "name": "TokensWithdrawn", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "bytes32", - "name": "proposalId", - "type": "bytes32" - }, - { - "indexed": true, - "internalType": "uint256", - "name": "action", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "address", - "name": "voter", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "votingPower", - "type": "uint256" - } - ], - "name": "VoteAdded", - "type": "event" - }, - { - "stateMutability": "payable", - "type": "fallback" - }, - { - "inputs": [], - "name": "ANY_SIGNATURE", - "outputs": [ - { - "internalType": "bytes4", - "name": "", - "type": "bytes4" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "ERC20_APPROVE_SIGNATURE", - "outputs": [ - { - "internalType": "bytes4", - "name": "", - "type": "bytes4" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "ERC20_TRANSFER_SIGNATURE", - "outputs": [ - { - "internalType": "bytes4", - "name": "", - "type": "bytes4" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address[]", - "name": "to", - "type": "address[]" - }, - { - "internalType": "bytes[]", - "name": "data", - "type": "bytes[]" - }, - { - "internalType": "uint256[]", - "name": "value", - "type": "uint256[]" - }, - { - "internalType": "uint256", - "name": "totalActions", - "type": "uint256" - }, - { - "internalType": "string", - "name": "title", - "type": "string" - }, - { - "internalType": "string", - "name": "contentHash", - "type": "string" - } - ], - "name": "createProposal", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "proposalId", - "type": "bytes32" - } - ], - "name": "endProposal", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes", - "name": "_data", - "type": "bytes" - } - ], - "name": "erc20TransferOrApproveDecode", - "outputs": [ - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "value", - "type": "uint256" - } - ], - "stateMutability": "pure", - "type": "function" - }, - { - "inputs": [], - "name": "getActiveProposalsNow", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "getCurrentSnapshotId", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "_hash", - "type": "bytes32" - } - ], - "name": "getEIP1271SignedHash", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes", - "name": "data", - "type": "bytes" - } - ], - "name": "getFuncSignature", - "outputs": [ - { - "internalType": "bytes4", - "name": "", - "type": "bytes4" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "getLockTime", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "getMaxActiveProposals", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "getMaxGasPrice", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "getName", - "outputs": [ - { - "internalType": "string", - "name": "", - "type": "string" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "getPermissionRegistry", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "proposalId", - "type": "bytes32" - } - ], - "name": "getProposal", - "outputs": [ - { - "internalType": "address", - "name": "creator", - "type": "address" - }, - { - "internalType": "uint256", - "name": "startTime", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "endTime", - "type": "uint256" - }, - { - "internalType": "address[]", - "name": "to", - "type": "address[]" - }, - { - "internalType": "bytes[]", - "name": "data", - "type": "bytes[]" - }, - { - "internalType": "uint256[]", - "name": "value", - "type": "uint256[]" - }, - { - "internalType": "uint256", - "name": "totalActions", - "type": "uint256" - }, - { - "internalType": "string", - "name": "title", - "type": "string" - }, - { - "internalType": "string", - "name": "contentHash", - "type": "string" - }, - { - "internalType": "enum ERC20Guild.ProposalState", - "name": "state", - "type": "uint8" - }, - { - "internalType": "uint256[]", - "name": "totalVotes", - "type": "uint256[]" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "proposalId", - "type": "bytes32" - } - ], - "name": "getProposalSnapshotId", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "getProposalTime", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "proposalId", - "type": "bytes32" - }, - { - "internalType": "address", - "name": "voter", - "type": "address" - } - ], - "name": "getProposalVotesOfVoter", - "outputs": [ - { - "internalType": "uint256", - "name": "action", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "votingPower", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "getProposalsIds", - "outputs": [ - { - "internalType": "bytes32[]", - "name": "", - "type": "bytes32[]" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "getProposalsIdsLength", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "signedVoteHash", - "type": "bytes32" - } - ], - "name": "getSignedVote", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "getTimeForExecution", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "getToken", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "getTokenVault", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "getTotalLocked", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "getTotalProposals", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "getVoteGas", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "voter", - "type": "address" - } - ], - "name": "getVoterLockTimestamp", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "getVotingPowerForProposalCreation", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "getVotingPowerForProposalExecution", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "proposalId", - "type": "uint256" - } - ], - "name": "getVotingPowerForProposalExecution", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "voter", - "type": "address" - }, - { - "internalType": "bytes32", - "name": "proposalId", - "type": "bytes32" - }, - { - "internalType": "uint256", - "name": "action", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "votingPower", - "type": "uint256" - } - ], - "name": "hashVote", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "stateMutability": "pure", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_token", - "type": "address" - }, - { - "internalType": "uint256", - "name": "_proposalTime", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_timeForExecution", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_votingPowerForProposalExecution", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_votingPowerForProposalCreation", - "type": "uint256" - }, - { - "internalType": "string", - "name": "_name", - "type": "string" - }, - { - "internalType": "uint256", - "name": "_voteGas", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_maxGasPrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_maxActiveProposals", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_lockTime", - "type": "uint256" - }, - { - "internalType": "address", - "name": "_permissionRegistry", - "type": "address" - } - ], - "name": "initialize", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "hash", - "type": "bytes32" - }, - { - "internalType": "bytes", - "name": "signature", - "type": "bytes" - } - ], - "name": "isValidSignature", - "outputs": [ - { - "internalType": "bytes4", - "name": "magicValue", - "type": "bytes4" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "tokenAmount", - "type": "uint256" - } - ], - "name": "lockTokens", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "_proposalTime", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_timeForExecution", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_votingPowerForProposalExecution", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_votingPowerForProposalCreation", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_voteGas", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_maxGasPrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_maxActiveProposals", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_lockTime", - "type": "uint256" - } - ], - "name": "setConfig", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "_hash", - "type": "bytes32" - }, - { - "internalType": "bool", - "name": "isValid", - "type": "bool" - } - ], - "name": "setEIP1271SignedHash", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address[]", - "name": "asset", - "type": "address[]" - }, - { - "internalType": "address[]", - "name": "to", - "type": "address[]" - }, - { - "internalType": "bytes4[]", - "name": "functionSignature", - "type": "bytes4[]" - }, - { - "internalType": "uint256[]", - "name": "valueAllowed", - "type": "uint256[]" - }, - { - "internalType": "bool[]", - "name": "allowance", - "type": "bool[]" - } - ], - "name": "setPermission", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "permissionDelay", - "type": "uint256" - } - ], - "name": "setPermissionDelay", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "proposalId", - "type": "bytes32" - }, - { - "internalType": "uint256", - "name": "action", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "votingPower", - "type": "uint256" - }, - { - "internalType": "address", - "name": "voter", - "type": "address" - }, - { - "internalType": "bytes", - "name": "signature", - "type": "bytes" - } - ], - "name": "setSignedVote", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32[]", - "name": "proposalIds", - "type": "bytes32[]" - }, - { - "internalType": "uint256[]", - "name": "actions", - "type": "uint256[]" - }, - { - "internalType": "uint256[]", - "name": "votingPowers", - "type": "uint256[]" - }, - { - "internalType": "address[]", - "name": "voters", - "type": "address[]" - }, - { - "internalType": "bytes[]", - "name": "signatures", - "type": "bytes[]" - } - ], - "name": "setSignedVotes", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "proposalId", - "type": "bytes32" - }, - { - "internalType": "uint256", - "name": "action", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "votingPower", - "type": "uint256" - } - ], - "name": "setVote", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32[]", - "name": "proposalIds", - "type": "bytes32[]" - }, - { - "internalType": "uint256[]", - "name": "actions", - "type": "uint256[]" - }, - { - "internalType": "uint256[]", - "name": "votingPowers", - "type": "uint256[]" - } - ], - "name": "setVotes", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "snapshotId", - "type": "uint256" - } - ], - "name": "totalLockedAt", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "votingPowerOf", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "account", - "type": "address" - }, - { - "internalType": "uint256", - "name": "snapshotId", - "type": "uint256" - } - ], - "name": "votingPowerOfAt", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address[]", - "name": "accounts", - "type": "address[]" - } - ], - "name": "votingPowerOfMultiple", - "outputs": [ - { - "internalType": "uint256[]", - "name": "", - "type": "uint256[]" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address[]", - "name": "accounts", - "type": "address[]" - }, - { - "internalType": "uint256[]", - "name": "snapshotIds", - "type": "uint256[]" - } - ], - "name": "votingPowerOfMultipleAt", - "outputs": [ - { - "internalType": "uint256[]", - "name": "", - "type": "uint256[]" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "tokenAmount", - "type": "uint256" - } - ], - "name": "withdrawTokens", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "stateMutability": "payable", - "type": "receive" - } - ] -} - +{ + "_format": "hh-sol-artifact-1", + "contractName": "SnapshotERC20Guild", + "sourceName": "dxdao-contracts/contracts/erc20guild/implementations/SnapshotERC20Guild.sol", + "abi": [ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "proposalId", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "newState", + "type": "uint256" + } + ], + "name": "ProposalStateChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "voter", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "TokensLocked", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "voter", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "TokensWithdrawn", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "proposalId", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "action", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "address", + "name": "voter", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "votingPower", + "type": "uint256" + } + ], + "name": "VoteAdded", + "type": "event" + }, + { + "stateMutability": "payable", + "type": "fallback" + }, + { + "inputs": [], + "name": "ANY_SIGNATURE", + "outputs": [ + { + "internalType": "bytes4", + "name": "", + "type": "bytes4" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ERC20_APPROVE_SIGNATURE", + "outputs": [ + { + "internalType": "bytes4", + "name": "", + "type": "bytes4" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ERC20_TRANSFER_SIGNATURE", + "outputs": [ + { + "internalType": "bytes4", + "name": "", + "type": "bytes4" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address[]", + "name": "to", + "type": "address[]" + }, + { + "internalType": "bytes[]", + "name": "data", + "type": "bytes[]" + }, + { + "internalType": "uint256[]", + "name": "value", + "type": "uint256[]" + }, + { + "internalType": "uint256", + "name": "totalActions", + "type": "uint256" + }, + { + "internalType": "string", + "name": "title", + "type": "string" + }, + { + "internalType": "string", + "name": "contentHash", + "type": "string" + } + ], + "name": "createProposal", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "proposalId", + "type": "bytes32" + } + ], + "name": "endProposal", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes", + "name": "_data", + "type": "bytes" + } + ], + "name": "erc20TransferOrApproveDecode", + "outputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [], + "name": "getActiveProposalsNow", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getCurrentSnapshotId", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "_hash", + "type": "bytes32" + } + ], + "name": "getEIP1271SignedHash", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "getFuncSignature", + "outputs": [ + { + "internalType": "bytes4", + "name": "", + "type": "bytes4" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getLockTime", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getMaxActiveProposals", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getMaxGasPrice", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getName", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getPermissionRegistry", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "proposalId", + "type": "bytes32" + } + ], + "name": "getProposal", + "outputs": [ + { + "internalType": "address", + "name": "creator", + "type": "address" + }, + { + "internalType": "uint256", + "name": "startTime", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "endTime", + "type": "uint256" + }, + { + "internalType": "address[]", + "name": "to", + "type": "address[]" + }, + { + "internalType": "bytes[]", + "name": "data", + "type": "bytes[]" + }, + { + "internalType": "uint256[]", + "name": "value", + "type": "uint256[]" + }, + { + "internalType": "uint256", + "name": "totalActions", + "type": "uint256" + }, + { + "internalType": "string", + "name": "title", + "type": "string" + }, + { + "internalType": "string", + "name": "contentHash", + "type": "string" + }, + { + "internalType": "enum ERC20Guild.ProposalState", + "name": "state", + "type": "uint8" + }, + { + "internalType": "uint256[]", + "name": "totalVotes", + "type": "uint256[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "proposalId", + "type": "bytes32" + } + ], + "name": "getProposalSnapshotId", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getProposalTime", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "proposalId", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "voter", + "type": "address" + } + ], + "name": "getProposalVotesOfVoter", + "outputs": [ + { + "internalType": "uint256", + "name": "action", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "votingPower", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getProposalsIds", + "outputs": [ + { + "internalType": "bytes32[]", + "name": "", + "type": "bytes32[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getProposalsIdsLength", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "signedVoteHash", + "type": "bytes32" + } + ], + "name": "getSignedVote", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getTimeForExecution", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getToken", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getTokenVault", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getTotalLocked", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getTotalProposals", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getVoteGas", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "voter", + "type": "address" + } + ], + "name": "getVoterLockTimestamp", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getVotingPowerForProposalCreation", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getVotingPowerForProposalExecution", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "proposalId", + "type": "uint256" + } + ], + "name": "getVotingPowerForProposalExecution", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "voter", + "type": "address" + }, + { + "internalType": "bytes32", + "name": "proposalId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "action", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "votingPower", + "type": "uint256" + } + ], + "name": "hashVote", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_token", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_proposalTime", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_timeForExecution", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_votingPowerForProposalExecution", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_votingPowerForProposalCreation", + "type": "uint256" + }, + { + "internalType": "string", + "name": "_name", + "type": "string" + }, + { + "internalType": "uint256", + "name": "_voteGas", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_maxGasPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_maxActiveProposals", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_lockTime", + "type": "uint256" + }, + { + "internalType": "address", + "name": "_permissionRegistry", + "type": "address" + } + ], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "hash", + "type": "bytes32" + }, + { + "internalType": "bytes", + "name": "signature", + "type": "bytes" + } + ], + "name": "isValidSignature", + "outputs": [ + { + "internalType": "bytes4", + "name": "magicValue", + "type": "bytes4" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenAmount", + "type": "uint256" + } + ], + "name": "lockTokens", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_proposalTime", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_timeForExecution", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_votingPowerForProposalExecution", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_votingPowerForProposalCreation", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_voteGas", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_maxGasPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_maxActiveProposals", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_lockTime", + "type": "uint256" + } + ], + "name": "setConfig", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "_hash", + "type": "bytes32" + }, + { + "internalType": "bool", + "name": "isValid", + "type": "bool" + } + ], + "name": "setEIP1271SignedHash", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address[]", + "name": "asset", + "type": "address[]" + }, + { + "internalType": "address[]", + "name": "to", + "type": "address[]" + }, + { + "internalType": "bytes4[]", + "name": "functionSignature", + "type": "bytes4[]" + }, + { + "internalType": "uint256[]", + "name": "valueAllowed", + "type": "uint256[]" + }, + { + "internalType": "bool[]", + "name": "allowance", + "type": "bool[]" + } + ], + "name": "setPermission", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "permissionDelay", + "type": "uint256" + } + ], + "name": "setPermissionDelay", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "proposalId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "action", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "votingPower", + "type": "uint256" + }, + { + "internalType": "address", + "name": "voter", + "type": "address" + }, + { + "internalType": "bytes", + "name": "signature", + "type": "bytes" + } + ], + "name": "setSignedVote", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32[]", + "name": "proposalIds", + "type": "bytes32[]" + }, + { + "internalType": "uint256[]", + "name": "actions", + "type": "uint256[]" + }, + { + "internalType": "uint256[]", + "name": "votingPowers", + "type": "uint256[]" + }, + { + "internalType": "address[]", + "name": "voters", + "type": "address[]" + }, + { + "internalType": "bytes[]", + "name": "signatures", + "type": "bytes[]" + } + ], + "name": "setSignedVotes", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "proposalId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "action", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "votingPower", + "type": "uint256" + } + ], + "name": "setVote", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32[]", + "name": "proposalIds", + "type": "bytes32[]" + }, + { + "internalType": "uint256[]", + "name": "actions", + "type": "uint256[]" + }, + { + "internalType": "uint256[]", + "name": "votingPowers", + "type": "uint256[]" + } + ], + "name": "setVotes", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "snapshotId", + "type": "uint256" + } + ], + "name": "totalLockedAt", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "votingPowerOf", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "internalType": "uint256", + "name": "snapshotId", + "type": "uint256" + } + ], + "name": "votingPowerOfAt", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address[]", + "name": "accounts", + "type": "address[]" + } + ], + "name": "votingPowerOfMultiple", + "outputs": [ + { + "internalType": "uint256[]", + "name": "", + "type": "uint256[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address[]", + "name": "accounts", + "type": "address[]" + }, + { + "internalType": "uint256[]", + "name": "snapshotIds", + "type": "uint256[]" + } + ], + "name": "votingPowerOfMultipleAt", + "outputs": [ + { + "internalType": "uint256[]", + "name": "", + "type": "uint256[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenAmount", + "type": "uint256" + } + ], + "name": "withdrawTokens", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "stateMutability": "payable", + "type": "receive" + } + ] +} diff --git a/src/hooks/Guilds/ether-swr/guild/useSnapshotId.ts b/src/hooks/Guilds/ether-swr/guild/useSnapshotId.ts index 25e8a5070b..0b8f20e520 100644 --- a/src/hooks/Guilds/ether-swr/guild/useSnapshotId.ts +++ b/src/hooks/Guilds/ether-swr/guild/useSnapshotId.ts @@ -1,25 +1,24 @@ -import { BigNumber } from 'ethers'; -import { SWRResponse } from 'swr'; -import useEtherSWR from '../useEtherSWR'; -import SnapshotERC20Guild from 'contracts/SnapshotERC20Guild.json'; - -interface UseSnapshotIdProps { - contractAddress: string; - proposalId: string; -} - -type UseSnapshotIdHook = (args: UseSnapshotIdProps) => SWRResponse; - -const useSnapshotId: UseSnapshotIdHook = ({ contractAddress, proposalId }) => { - return useEtherSWR( - proposalId && contractAddress - ? [contractAddress, 'getProposalSnapshotId', proposalId] - : [], - { - ABIs: new Map([[contractAddress, SnapshotERC20Guild.abi]]), - } - ); -}; - -export default useSnapshotId; - +import { BigNumber } from 'ethers'; +import { SWRResponse } from 'swr'; +import useEtherSWR from '../useEtherSWR'; +import SnapshotERC20Guild from 'contracts/SnapshotERC20Guild.json'; + +interface UseSnapshotIdProps { + contractAddress: string; + proposalId: string; +} + +type UseSnapshotIdHook = (args: UseSnapshotIdProps) => SWRResponse; + +const useSnapshotId: UseSnapshotIdHook = ({ contractAddress, proposalId }) => { + return useEtherSWR( + proposalId && contractAddress + ? [contractAddress, 'getProposalSnapshotId', proposalId] + : [], + { + ABIs: new Map([[contractAddress, SnapshotERC20Guild.abi]]), + } + ); +}; + +export default useSnapshotId; diff --git a/src/hooks/Guilds/ether-swr/guild/useTotalLocked.ts b/src/hooks/Guilds/ether-swr/guild/useTotalLocked.ts index 97e2498eb7..b2d1b6b5ca 100644 --- a/src/hooks/Guilds/ether-swr/guild/useTotalLocked.ts +++ b/src/hooks/Guilds/ether-swr/guild/useTotalLocked.ts @@ -1,43 +1,42 @@ -import { useParams } from 'react-router-dom'; -import ERC20GuildContract from 'contracts/ERC20Guild.json'; -import useEtherSWR from '../useEtherSWR'; -import useTotalLockedAtSnapshot from 'hooks/Guilds/ether-swr/guild/useTotalLockedAtSnapshot'; -import useGuildImplementationType from 'hooks/Guilds/guild/useGuildImplementationType'; - -const useTotalLocked = (guildAddress: string) => { - // Hooks call - const { proposal_id: proposalId } = useParams<{ proposal_id?: string }>(); - const { isSnapshotGuild, isRepGuild, isSnapshotRepGuild } = - useGuildImplementationType(guildAddress); - - const totalLockedResponse = useEtherSWR( - guildAddress ? [guildAddress, 'getTotalLocked'] : [], - { - ABIs: new Map([[guildAddress, ERC20GuildContract.abi]]), - refreshInterval: 0, - } - ); - - const totalLockedAtProposalSnapshotResponse = useTotalLockedAtSnapshot({ - contractAddress: guildAddress, - proposalId, - }); - - // console.log({ - // isSnapshotGuild, - // isRepGuild, - // isSnapshotRepGuild, - // 'totalLockedResponse.data': totalLockedResponse.data, - // 'totalLockedAtProposalSnapshotResponse.data': - // totalLockedAtProposalSnapshotResponse.data, - // }); - - // Return response based on implementation type - if (isSnapshotGuild) return totalLockedAtProposalSnapshotResponse; - if (isRepGuild) return totalLockedResponse; // TODO: replace with rep implementation totalLocked call - if (isSnapshotRepGuild) return totalLockedResponse; // TODO: replace with rep implementation totalLocked call - return totalLockedResponse; -}; - -export default useTotalLocked; - +import { useParams } from 'react-router-dom'; +import ERC20GuildContract from 'contracts/ERC20Guild.json'; +import useEtherSWR from '../useEtherSWR'; +import useTotalLockedAtSnapshot from 'hooks/Guilds/ether-swr/guild/useTotalLockedAtSnapshot'; +import useGuildImplementationType from 'hooks/Guilds/guild/useGuildImplementationType'; + +const useTotalLocked = (guildAddress: string) => { + // Hooks call + const { proposal_id: proposalId } = useParams<{ proposal_id?: string }>(); + const { isSnapshotGuild, isRepGuild, isSnapshotRepGuild } = + useGuildImplementationType(guildAddress); + + const totalLockedResponse = useEtherSWR( + guildAddress ? [guildAddress, 'getTotalLocked'] : [], + { + ABIs: new Map([[guildAddress, ERC20GuildContract.abi]]), + refreshInterval: 0, + } + ); + + const totalLockedAtProposalSnapshotResponse = useTotalLockedAtSnapshot({ + contractAddress: guildAddress, + proposalId, + }); + + // console.log({ + // isSnapshotGuild, + // isRepGuild, + // isSnapshotRepGuild, + // 'totalLockedResponse.data': totalLockedResponse.data, + // 'totalLockedAtProposalSnapshotResponse.data': + // totalLockedAtProposalSnapshotResponse.data, + // }); + + // Return response based on implementation type + if (isSnapshotGuild) return totalLockedAtProposalSnapshotResponse; + if (isRepGuild) return totalLockedResponse; // TODO: replace with rep implementation totalLocked call + if (isSnapshotRepGuild) return totalLockedResponse; // TODO: replace with rep implementation totalLocked call + return totalLockedResponse; +}; + +export default useTotalLocked; diff --git a/src/hooks/Guilds/ether-swr/guild/useTotalLockedAtSnapshot.ts b/src/hooks/Guilds/ether-swr/guild/useTotalLockedAtSnapshot.ts index 037400c3de..c3bda22a58 100644 --- a/src/hooks/Guilds/ether-swr/guild/useTotalLockedAtSnapshot.ts +++ b/src/hooks/Guilds/ether-swr/guild/useTotalLockedAtSnapshot.ts @@ -1,38 +1,37 @@ -import { BigNumber } from 'ethers'; -import { SWRResponse } from 'swr'; -import useEtherSWR from '../useEtherSWR'; -import useSnapshotId from './useSnapshotId'; -import SnapshotERC20Guild from 'contracts/SnapshotERC20Guild.json'; - -interface UseTotalLockedAtSnapshotProps { - contractAddress: string; - proposalId: string; -} - -type UseTotalLockedAtSnapshotHook = ( - args: UseTotalLockedAtSnapshotProps -) => SWRResponse; - -const useTotalLockedAtSnapshot: UseTotalLockedAtSnapshotHook = ({ - contractAddress, - proposalId, -}) => { - const { data: snapshotId } = useSnapshotId({ contractAddress, proposalId }); - return useEtherSWR( - snapshotId && contractAddress - ? [contractAddress, 'totalLockedAt', snapshotId.toString()] - : [], - { - ABIs: new Map([[contractAddress, SnapshotERC20Guild.abi]]), - } - ); -}; - -export default useTotalLockedAtSnapshot; - -// Create useSnapshotIf hook -// Create useTotalLockedAtSnapshot hook -// Create snapshotERC20Guild instance with proposal in dev script. -// Create useTotalLocked hook to use with multiple implementations -// Remove getTotalLocked call from useGuildConfig hook - +import { BigNumber } from 'ethers'; +import { SWRResponse } from 'swr'; +import useEtherSWR from '../useEtherSWR'; +import useSnapshotId from './useSnapshotId'; +import SnapshotERC20Guild from 'contracts/SnapshotERC20Guild.json'; + +interface UseTotalLockedAtSnapshotProps { + contractAddress: string; + proposalId: string; +} + +type UseTotalLockedAtSnapshotHook = ( + args: UseTotalLockedAtSnapshotProps +) => SWRResponse; + +const useTotalLockedAtSnapshot: UseTotalLockedAtSnapshotHook = ({ + contractAddress, + proposalId, +}) => { + const { data: snapshotId } = useSnapshotId({ contractAddress, proposalId }); + return useEtherSWR( + snapshotId && contractAddress + ? [contractAddress, 'totalLockedAt', snapshotId.toString()] + : [], + { + ABIs: new Map([[contractAddress, SnapshotERC20Guild.abi]]), + } + ); +}; + +export default useTotalLockedAtSnapshot; + +// Create useSnapshotIf hook +// Create useTotalLockedAtSnapshot hook +// Create snapshotERC20Guild instance with proposal in dev script. +// Create useTotalLocked hook to use with multiple implementations +// Remove getTotalLocked call from useGuildConfig hook From 8389cf3a2630a2dc87e43612ea64bd2b2b9ade92 Mon Sep 17 00:00:00 2001 From: Milton Date: Wed, 6 Apr 2022 18:20:00 -0300 Subject: [PATCH 3/5] Remove logs --- src/hooks/Guilds/ether-swr/guild/useTotalLocked.ts | 9 --------- .../Guilds/ether-swr/guild/useTotalLockedAtSnapshot.ts | 6 ------ src/pages/Guilds/Proposal.tsx | 10 +++++----- 3 files changed, 5 insertions(+), 20 deletions(-) diff --git a/src/hooks/Guilds/ether-swr/guild/useTotalLocked.ts b/src/hooks/Guilds/ether-swr/guild/useTotalLocked.ts index b2d1b6b5ca..84203092aa 100644 --- a/src/hooks/Guilds/ether-swr/guild/useTotalLocked.ts +++ b/src/hooks/Guilds/ether-swr/guild/useTotalLocked.ts @@ -23,15 +23,6 @@ const useTotalLocked = (guildAddress: string) => { proposalId, }); - // console.log({ - // isSnapshotGuild, - // isRepGuild, - // isSnapshotRepGuild, - // 'totalLockedResponse.data': totalLockedResponse.data, - // 'totalLockedAtProposalSnapshotResponse.data': - // totalLockedAtProposalSnapshotResponse.data, - // }); - // Return response based on implementation type if (isSnapshotGuild) return totalLockedAtProposalSnapshotResponse; if (isRepGuild) return totalLockedResponse; // TODO: replace with rep implementation totalLocked call diff --git a/src/hooks/Guilds/ether-swr/guild/useTotalLockedAtSnapshot.ts b/src/hooks/Guilds/ether-swr/guild/useTotalLockedAtSnapshot.ts index c3bda22a58..087bac0f72 100644 --- a/src/hooks/Guilds/ether-swr/guild/useTotalLockedAtSnapshot.ts +++ b/src/hooks/Guilds/ether-swr/guild/useTotalLockedAtSnapshot.ts @@ -29,9 +29,3 @@ const useTotalLockedAtSnapshot: UseTotalLockedAtSnapshotHook = ({ }; export default useTotalLockedAtSnapshot; - -// Create useSnapshotIf hook -// Create useTotalLockedAtSnapshot hook -// Create snapshotERC20Guild instance with proposal in dev script. -// Create useTotalLocked hook to use with multiple implementations -// Remove getTotalLocked call from useGuildConfig hook diff --git a/src/pages/Guilds/Proposal.tsx b/src/pages/Guilds/Proposal.tsx index e0753e74e1..c95c90cc26 100644 --- a/src/pages/Guilds/Proposal.tsx +++ b/src/pages/Guilds/Proposal.tsx @@ -13,11 +13,11 @@ import UnstyledLink from '../../components/Guilds/common/UnstyledLink'; import AddressButton from '../../components/Guilds/AddressButton'; import ProposalDescription from '../../components/Guilds/ProposalPage/ProposalDescription'; import { useProposal } from '../../hooks/Guilds/ether-swr/guild/useProposal'; -// import { ActionsBuilder } from 'components/Guilds/CreateProposalPage'; +import { ActionsBuilder } from 'components/Guilds/CreateProposalPage'; import { GuildAvailabilityContext } from 'contexts/Guilds/guildAvailability'; import Result, { ResultState } from 'components/Guilds/common/Result'; import { useGuildProposalIds } from 'hooks/Guilds/ether-swr/guild/useGuildProposalIds'; -// import useProposalCalls from 'hooks/Guilds/guild/useProposalCalls'; +import useProposalCalls from 'hooks/Guilds/guild/useProposalCalls'; const PageContainer = styled(Box)` display: grid; @@ -94,8 +94,8 @@ const ProposalPage: React.FC = () => { ); const { data: proposalIds } = useGuildProposalIds(guildId); const { data: proposal, error } = useProposal(guildId, proposalId); - // const { options } = useProposalCalls(guildId, proposalId); - // console.log('options', options); + const { options } = useProposalCalls(guildId, proposalId); + if (!isGuildAvailabilityLoading) { if (!proposalIds?.includes(proposalId)) { return ( @@ -150,7 +150,7 @@ const ProposalPage: React.FC = () => { - {/* */} + From 7a57bdf6a29d7403d49a9165693d54191151289a Mon Sep 17 00:00:00 2001 From: Milton Date: Wed, 6 Apr 2022 18:42:35 -0300 Subject: [PATCH 4/5] create useVotingPowerOfAt hook and refactor --- .../Guilds/ether-swr/guild/useTotalLocked.ts | 13 ++++++-- .../ether-swr/guild/useTotalLockedAt.ts | 33 +++++++++++++++++++ .../guild/useTotalLockedAtSnapshot.ts | 31 ----------------- .../ether-swr/guild/useVotingPowerOfAt.ts | 31 +++++++++++++++++ 4 files changed, 74 insertions(+), 34 deletions(-) create mode 100644 src/hooks/Guilds/ether-swr/guild/useTotalLockedAt.ts delete mode 100644 src/hooks/Guilds/ether-swr/guild/useTotalLockedAtSnapshot.ts create mode 100644 src/hooks/Guilds/ether-swr/guild/useVotingPowerOfAt.ts diff --git a/src/hooks/Guilds/ether-swr/guild/useTotalLocked.ts b/src/hooks/Guilds/ether-swr/guild/useTotalLocked.ts index 84203092aa..8ed376415d 100644 --- a/src/hooks/Guilds/ether-swr/guild/useTotalLocked.ts +++ b/src/hooks/Guilds/ether-swr/guild/useTotalLocked.ts @@ -1,12 +1,19 @@ import { useParams } from 'react-router-dom'; import ERC20GuildContract from 'contracts/ERC20Guild.json'; import useEtherSWR from '../useEtherSWR'; -import useTotalLockedAtSnapshot from 'hooks/Guilds/ether-swr/guild/useTotalLockedAtSnapshot'; +import useTotalLockedAt from 'hooks/Guilds/ether-swr/guild/useTotalLockedAt'; +import useSnapshotId from 'hooks/Guilds/ether-swr/guild/useSnapshotId'; import useGuildImplementationType from 'hooks/Guilds/guild/useGuildImplementationType'; const useTotalLocked = (guildAddress: string) => { // Hooks call const { proposal_id: proposalId } = useParams<{ proposal_id?: string }>(); + + const { data: snapshotId } = useSnapshotId({ + contractAddress: guildAddress, + proposalId, + }); + const { isSnapshotGuild, isRepGuild, isSnapshotRepGuild } = useGuildImplementationType(guildAddress); @@ -18,9 +25,9 @@ const useTotalLocked = (guildAddress: string) => { } ); - const totalLockedAtProposalSnapshotResponse = useTotalLockedAtSnapshot({ + const totalLockedAtProposalSnapshotResponse = useTotalLockedAt({ contractAddress: guildAddress, - proposalId, + snapshotId: snapshotId?.toString(), }); // Return response based on implementation type diff --git a/src/hooks/Guilds/ether-swr/guild/useTotalLockedAt.ts b/src/hooks/Guilds/ether-swr/guild/useTotalLockedAt.ts new file mode 100644 index 0000000000..f5c3f5bae2 --- /dev/null +++ b/src/hooks/Guilds/ether-swr/guild/useTotalLockedAt.ts @@ -0,0 +1,33 @@ +import { BigNumber } from 'ethers'; +import { SWRResponse } from 'swr'; +import useEtherSWR from '../useEtherSWR'; +// import useSnapshotId from './useSnapshotId'; +import SnapshotERC20Guild from 'contracts/SnapshotERC20Guild.json'; + +interface UseTotalLockedAtProps { + contractAddress: string; + snapshotId: string; +} + +type UseTotalLockedAtHook = ( + args: UseTotalLockedAtProps +) => SWRResponse; + +/** + * Get the total locked amount at snapshot + */ +const useTotalLockedAt: UseTotalLockedAtHook = ({ + contractAddress, + snapshotId, +}) => { + return useEtherSWR( + snapshotId && contractAddress + ? [contractAddress, 'totalLockedAt', snapshotId] + : [], + { + ABIs: new Map([[contractAddress, SnapshotERC20Guild.abi]]), + } + ); +}; + +export default useTotalLockedAt; diff --git a/src/hooks/Guilds/ether-swr/guild/useTotalLockedAtSnapshot.ts b/src/hooks/Guilds/ether-swr/guild/useTotalLockedAtSnapshot.ts deleted file mode 100644 index 087bac0f72..0000000000 --- a/src/hooks/Guilds/ether-swr/guild/useTotalLockedAtSnapshot.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { BigNumber } from 'ethers'; -import { SWRResponse } from 'swr'; -import useEtherSWR from '../useEtherSWR'; -import useSnapshotId from './useSnapshotId'; -import SnapshotERC20Guild from 'contracts/SnapshotERC20Guild.json'; - -interface UseTotalLockedAtSnapshotProps { - contractAddress: string; - proposalId: string; -} - -type UseTotalLockedAtSnapshotHook = ( - args: UseTotalLockedAtSnapshotProps -) => SWRResponse; - -const useTotalLockedAtSnapshot: UseTotalLockedAtSnapshotHook = ({ - contractAddress, - proposalId, -}) => { - const { data: snapshotId } = useSnapshotId({ contractAddress, proposalId }); - return useEtherSWR( - snapshotId && contractAddress - ? [contractAddress, 'totalLockedAt', snapshotId.toString()] - : [], - { - ABIs: new Map([[contractAddress, SnapshotERC20Guild.abi]]), - } - ); -}; - -export default useTotalLockedAtSnapshot; diff --git a/src/hooks/Guilds/ether-swr/guild/useVotingPowerOfAt.ts b/src/hooks/Guilds/ether-swr/guild/useVotingPowerOfAt.ts new file mode 100644 index 0000000000..bb979b1290 --- /dev/null +++ b/src/hooks/Guilds/ether-swr/guild/useVotingPowerOfAt.ts @@ -0,0 +1,31 @@ +import { BigNumber } from 'ethers'; +import { SWRResponse } from 'swr'; +import useEtherSWR from '../useEtherSWR'; +import SnapshotERC20Guild from 'contracts/SnapshotERC20Guild.json'; + +interface useVotingPowerOfAtProps { + contractAddress: string; + userAddress: string; + snapshotId: string; +} + +type useVotingPowerOfAtHook = ( + args: useVotingPowerOfAtProps +) => SWRResponse; + +/** + * Get the voting power of an account at snapshot id + */ +export const useVotingPowerOfAt: useVotingPowerOfAtHook = ({ + contractAddress, + userAddress, + snapshotId, +}) => + useEtherSWR( + contractAddress && snapshotId && userAddress + ? [contractAddress, 'votingPowerOf', userAddress, snapshotId] + : [], + { + ABIs: new Map([[contractAddress, SnapshotERC20Guild.abi]]), + } + ); From ee8d34579f0f24fe33064fea4874f7f071c197ee Mon Sep 17 00:00:00 2001 From: Milton Date: Thu, 7 Apr 2022 17:48:34 -0300 Subject: [PATCH 5/5] Add json contracts, pull out token from guild config by creating useGuildToken hook, create a useTotalSupplyAt hook. --- src/contracts/ERC20SnapshotRep.json | 459 +++++++ src/contracts/SnapshotRepERC20Guild.json | 1146 +++++++++++++++++ .../Guilds/ether-swr/guild/useGuildConfig.ts | 18 +- .../Guilds/ether-swr/guild/useGuildToken.ts | 11 + .../Guilds/ether-swr/guild/useTotalLocked.ts | 21 +- .../ether-swr/guild/useTotalSupplyAt.ts | 32 + 6 files changed, 1673 insertions(+), 14 deletions(-) create mode 100644 src/contracts/ERC20SnapshotRep.json create mode 100644 src/contracts/SnapshotRepERC20Guild.json create mode 100644 src/hooks/Guilds/ether-swr/guild/useGuildToken.ts create mode 100644 src/hooks/Guilds/ether-swr/guild/useTotalSupplyAt.ts diff --git a/src/contracts/ERC20SnapshotRep.json b/src/contracts/ERC20SnapshotRep.json new file mode 100644 index 0000000000..0c9ed2433f --- /dev/null +++ b/src/contracts/ERC20SnapshotRep.json @@ -0,0 +1,459 @@ +{ + "_format": "hh-sol-artifact-1", + "contractName": "ERC20SnapshotRep", + "sourceName": "dxdao-contracts/contracts/utils/ERC20/ERC20SnapshotRep.sol", + "abi": [ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "id", + "type": "uint256" + } + ], + "name": "Snapshot", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "internalType": "address", + "name": "spender", + "type": "address" + } + ], + "name": "allowance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "approve", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "balanceOf", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "internalType": "uint256", + "name": "snapshotId", + "type": "uint256" + } + ], + "name": "balanceOfAt", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "burn", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "decimals", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "subtractedValue", + "type": "uint256" + } + ], + "name": "decreaseAllowance", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "getCurrentSnapshotId", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "addedValue", + "type": "uint256" + } + ], + "name": "increaseAllowance", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "name", + "type": "string" + }, + { + "internalType": "string", + "name": "symbol", + "type": "string" + } + ], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "mint", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "name", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "snapshot", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "symbol", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalSupply", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "snapshotId", + "type": "uint256" + } + ], + "name": "totalSupplyAt", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "transfer", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "transferFrom", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } + ] +} diff --git a/src/contracts/SnapshotRepERC20Guild.json b/src/contracts/SnapshotRepERC20Guild.json new file mode 100644 index 0000000000..6726d51dba --- /dev/null +++ b/src/contracts/SnapshotRepERC20Guild.json @@ -0,0 +1,1146 @@ +{ + "_format": "hh-sol-artifact-1", + "contractName": "SnapshotRepERC20Guild", + "sourceName": "dxdao-contracts/contracts/erc20guild/implementations/SnapshotRepERC20Guild.sol", + "abi": [ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "proposalId", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "newState", + "type": "uint256" + } + ], + "name": "ProposalStateChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "voter", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "TokensLocked", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "voter", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "TokensWithdrawn", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "proposalId", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "action", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "address", + "name": "voter", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "votingPower", + "type": "uint256" + } + ], + "name": "VoteAdded", + "type": "event" + }, + { + "stateMutability": "payable", + "type": "fallback" + }, + { + "inputs": [], + "name": "ANY_SIGNATURE", + "outputs": [ + { + "internalType": "bytes4", + "name": "", + "type": "bytes4" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ERC20_APPROVE_SIGNATURE", + "outputs": [ + { + "internalType": "bytes4", + "name": "", + "type": "bytes4" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ERC20_TRANSFER_SIGNATURE", + "outputs": [ + { + "internalType": "bytes4", + "name": "", + "type": "bytes4" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address[]", + "name": "to", + "type": "address[]" + }, + { + "internalType": "bytes[]", + "name": "data", + "type": "bytes[]" + }, + { + "internalType": "uint256[]", + "name": "value", + "type": "uint256[]" + }, + { + "internalType": "uint256", + "name": "totalActions", + "type": "uint256" + }, + { + "internalType": "string", + "name": "title", + "type": "string" + }, + { + "internalType": "string", + "name": "contentHash", + "type": "string" + } + ], + "name": "createProposal", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "proposalId", + "type": "bytes32" + } + ], + "name": "endProposal", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes", + "name": "_data", + "type": "bytes" + } + ], + "name": "erc20TransferOrApproveDecode", + "outputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [], + "name": "getActiveProposalsNow", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "_hash", + "type": "bytes32" + } + ], + "name": "getEIP1271SignedHash", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "getFuncSignature", + "outputs": [ + { + "internalType": "bytes4", + "name": "", + "type": "bytes4" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getLockTime", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getMaxActiveProposals", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getMaxGasPrice", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getName", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getPermissionRegistry", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "proposalId", + "type": "bytes32" + } + ], + "name": "getProposal", + "outputs": [ + { + "internalType": "address", + "name": "creator", + "type": "address" + }, + { + "internalType": "uint256", + "name": "startTime", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "endTime", + "type": "uint256" + }, + { + "internalType": "address[]", + "name": "to", + "type": "address[]" + }, + { + "internalType": "bytes[]", + "name": "data", + "type": "bytes[]" + }, + { + "internalType": "uint256[]", + "name": "value", + "type": "uint256[]" + }, + { + "internalType": "uint256", + "name": "totalActions", + "type": "uint256" + }, + { + "internalType": "string", + "name": "title", + "type": "string" + }, + { + "internalType": "string", + "name": "contentHash", + "type": "string" + }, + { + "internalType": "enum ERC20Guild.ProposalState", + "name": "state", + "type": "uint8" + }, + { + "internalType": "uint256[]", + "name": "totalVotes", + "type": "uint256[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "proposalId", + "type": "bytes32" + } + ], + "name": "getProposalSnapshotId", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getProposalTime", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "proposalId", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "voter", + "type": "address" + } + ], + "name": "getProposalVotesOfVoter", + "outputs": [ + { + "internalType": "uint256", + "name": "action", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "votingPower", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getProposalsIds", + "outputs": [ + { + "internalType": "bytes32[]", + "name": "", + "type": "bytes32[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getProposalsIdsLength", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "signedVoteHash", + "type": "bytes32" + } + ], + "name": "getSignedVote", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getTimeForExecution", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getToken", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getTokenVault", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getTotalLocked", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getTotalProposals", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getVoteGas", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "voter", + "type": "address" + } + ], + "name": "getVoterLockTimestamp", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getVotingPowerForProposalCreation", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getVotingPowerForProposalExecution", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "voter", + "type": "address" + }, + { + "internalType": "bytes32", + "name": "proposalId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "action", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "votingPower", + "type": "uint256" + } + ], + "name": "hashVote", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_token", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_proposalTime", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_timeForExecution", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_votingPowerForProposalExecution", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_votingPowerForProposalCreation", + "type": "uint256" + }, + { + "internalType": "string", + "name": "_name", + "type": "string" + }, + { + "internalType": "uint256", + "name": "_voteGas", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_maxGasPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_maxActiveProposals", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_lockTime", + "type": "uint256" + }, + { + "internalType": "address", + "name": "_permissionRegistry", + "type": "address" + } + ], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "hash", + "type": "bytes32" + }, + { + "internalType": "bytes", + "name": "signature", + "type": "bytes" + } + ], + "name": "isValidSignature", + "outputs": [ + { + "internalType": "bytes4", + "name": "magicValue", + "type": "bytes4" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenAmount", + "type": "uint256" + } + ], + "name": "lockTokens", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_proposalTime", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_timeForExecution", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_votingPowerForProposalExecution", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_votingPowerForProposalCreation", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_voteGas", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_maxGasPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_maxActiveProposals", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_lockTime", + "type": "uint256" + } + ], + "name": "setConfig", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "_hash", + "type": "bytes32" + }, + { + "internalType": "bool", + "name": "isValid", + "type": "bool" + } + ], + "name": "setEIP1271SignedHash", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address[]", + "name": "asset", + "type": "address[]" + }, + { + "internalType": "address[]", + "name": "to", + "type": "address[]" + }, + { + "internalType": "bytes4[]", + "name": "functionSignature", + "type": "bytes4[]" + }, + { + "internalType": "uint256[]", + "name": "valueAllowed", + "type": "uint256[]" + }, + { + "internalType": "bool[]", + "name": "allowance", + "type": "bool[]" + } + ], + "name": "setPermission", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "permissionDelay", + "type": "uint256" + } + ], + "name": "setPermissionDelay", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "proposalId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "action", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "votingPower", + "type": "uint256" + }, + { + "internalType": "address", + "name": "voter", + "type": "address" + }, + { + "internalType": "bytes", + "name": "signature", + "type": "bytes" + } + ], + "name": "setSignedVote", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32[]", + "name": "proposalIds", + "type": "bytes32[]" + }, + { + "internalType": "uint256[]", + "name": "actions", + "type": "uint256[]" + }, + { + "internalType": "uint256[]", + "name": "votingPowers", + "type": "uint256[]" + }, + { + "internalType": "address[]", + "name": "voters", + "type": "address[]" + }, + { + "internalType": "bytes[]", + "name": "signatures", + "type": "bytes[]" + } + ], + "name": "setSignedVotes", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "proposalId", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "action", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "votingPower", + "type": "uint256" + } + ], + "name": "setVote", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32[]", + "name": "proposalIds", + "type": "bytes32[]" + }, + { + "internalType": "uint256[]", + "name": "actions", + "type": "uint256[]" + }, + { + "internalType": "uint256[]", + "name": "votingPowers", + "type": "uint256[]" + } + ], + "name": "setVotes", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "votingPowerOf", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "internalType": "uint256", + "name": "snapshotId", + "type": "uint256" + } + ], + "name": "votingPowerOfAt", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address[]", + "name": "accounts", + "type": "address[]" + } + ], + "name": "votingPowerOfMultiple", + "outputs": [ + { + "internalType": "uint256[]", + "name": "", + "type": "uint256[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address[]", + "name": "accounts", + "type": "address[]" + }, + { + "internalType": "uint256[]", + "name": "snapshotIds", + "type": "uint256[]" + } + ], + "name": "votingPowerOfMultipleAt", + "outputs": [ + { + "internalType": "uint256[]", + "name": "", + "type": "uint256[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenAmount", + "type": "uint256" + } + ], + "name": "withdrawTokens", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "stateMutability": "payable", + "type": "receive" + } + ] +} diff --git a/src/hooks/Guilds/ether-swr/guild/useGuildConfig.ts b/src/hooks/Guilds/ether-swr/guild/useGuildConfig.ts index c237077e0e..36064bad6b 100644 --- a/src/hooks/Guilds/ether-swr/guild/useGuildConfig.ts +++ b/src/hooks/Guilds/ether-swr/guild/useGuildConfig.ts @@ -1,8 +1,10 @@ import { BigNumber } from 'ethers'; import { useMemo } from 'react'; +import { SWRResponse } from 'swr'; import ERC20GuildContract from 'contracts/ERC20Guild.json'; import useEtherSWR from '../useEtherSWR'; import useTotalLocked from './useTotalLocked'; +import useGuildToken from './useGuildToken'; type GuildConfig = { name: string; @@ -18,11 +20,12 @@ type GuildConfig = { totalLocked: BigNumber; }; -export const useGuildConfig = (guildAddress: string) => { +export const useGuildConfig = ( + guildAddress: string +): SWRResponse => { const { data, error, isValidating, mutate } = useEtherSWR( guildAddress ? [ - [guildAddress, 'getToken'], // Get the address of the ERC20Token used for voting [guildAddress, 'getPermissionRegistry'], // Get the address of the permission registry contract [guildAddress, 'getName'], // Get the name of the ERC20Guild [guildAddress, 'getProposalTime'], // Get the proposalTime (seconds) @@ -39,15 +42,14 @@ export const useGuildConfig = (guildAddress: string) => { refreshInterval: 0, } ); - + const { data: token } = useGuildToken(guildAddress); const { data: totalLocked } = useTotalLocked(guildAddress); // TODO: Move this into a SWR middleware - const transformedData: GuildConfig = useMemo(() => { + const transformedData = useMemo(() => { if (!data) return undefined; const [ - token, permissionRegistry, name, proposalTime, @@ -60,7 +62,6 @@ export const useGuildConfig = (guildAddress: string) => { ] = data; return { - token, permissionRegistry, name, proposalTime: BigNumber.from(proposalTime), @@ -74,14 +75,13 @@ export const useGuildConfig = (guildAddress: string) => { ), tokenVault, lockTime: BigNumber.from(lockTime), - totalLocked: totalLocked, }; - }, [data, totalLocked]); + }, [data]); return { error, isValidating, mutate, - data: transformedData, + data: { ...transformedData, totalLocked, token }, }; }; diff --git a/src/hooks/Guilds/ether-swr/guild/useGuildToken.ts b/src/hooks/Guilds/ether-swr/guild/useGuildToken.ts new file mode 100644 index 0000000000..fbc6617b1b --- /dev/null +++ b/src/hooks/Guilds/ether-swr/guild/useGuildToken.ts @@ -0,0 +1,11 @@ +import useEtherSWR from '../useEtherSWR'; +import ERC20Guild from 'contracts/ERC20Guild.json'; + +const useGuildToken = (guildAddress: string) => { + return useEtherSWR(guildAddress ? [guildAddress, 'getToken'] : [], { + ABIs: new Map([[guildAddress, ERC20Guild.abi]]), + refreshInterval: 0, + }); +}; + +export default useGuildToken; diff --git a/src/hooks/Guilds/ether-swr/guild/useTotalLocked.ts b/src/hooks/Guilds/ether-swr/guild/useTotalLocked.ts index 8ed376415d..6f24e4d412 100644 --- a/src/hooks/Guilds/ether-swr/guild/useTotalLocked.ts +++ b/src/hooks/Guilds/ether-swr/guild/useTotalLocked.ts @@ -4,16 +4,20 @@ import useEtherSWR from '../useEtherSWR'; import useTotalLockedAt from 'hooks/Guilds/ether-swr/guild/useTotalLockedAt'; import useSnapshotId from 'hooks/Guilds/ether-swr/guild/useSnapshotId'; import useGuildImplementationType from 'hooks/Guilds/guild/useGuildImplementationType'; +import useGuildToken from './useGuildToken'; +import useTotalSupplyAt from './useTotalSupplyAt'; -const useTotalLocked = (guildAddress: string) => { +const useTotalLocked = (guildAddress: string, snapshotId?: string) => { // Hooks call const { proposal_id: proposalId } = useParams<{ proposal_id?: string }>(); - const { data: snapshotId } = useSnapshotId({ + const { data: _snapshotId } = useSnapshotId({ contractAddress: guildAddress, proposalId, }); + const SNAPSHOT_ID = snapshotId ? snapshotId : _snapshotId?.toString(); + const { isSnapshotGuild, isRepGuild, isSnapshotRepGuild } = useGuildImplementationType(guildAddress); @@ -27,13 +31,20 @@ const useTotalLocked = (guildAddress: string) => { const totalLockedAtProposalSnapshotResponse = useTotalLockedAt({ contractAddress: guildAddress, - snapshotId: snapshotId?.toString(), + snapshotId: SNAPSHOT_ID, + }); + + const { data: guildTokenAddress } = useGuildToken(guildAddress); + + const totalSupplyAtSnapshotResponse = useTotalSupplyAt({ + contractAddress: guildTokenAddress, + snapshotId: SNAPSHOT_ID, }); // Return response based on implementation type if (isSnapshotGuild) return totalLockedAtProposalSnapshotResponse; - if (isRepGuild) return totalLockedResponse; // TODO: replace with rep implementation totalLocked call - if (isSnapshotRepGuild) return totalLockedResponse; // TODO: replace with rep implementation totalLocked call + if (isSnapshotRepGuild) return totalSupplyAtSnapshotResponse; + if (isRepGuild) return totalLockedResponse; return totalLockedResponse; }; diff --git a/src/hooks/Guilds/ether-swr/guild/useTotalSupplyAt.ts b/src/hooks/Guilds/ether-swr/guild/useTotalSupplyAt.ts new file mode 100644 index 0000000000..2f1f913aa6 --- /dev/null +++ b/src/hooks/Guilds/ether-swr/guild/useTotalSupplyAt.ts @@ -0,0 +1,32 @@ +import { BigNumber } from 'ethers'; +import { SWRResponse } from 'swr'; +import useEtherSWR from '../useEtherSWR'; +import ERC20SnapshotRep from 'contracts/ERC20SnapshotRep.json'; + +interface UseTotalSupplyAtProps { + contractAddress: string; + snapshotId: string; +} + +type UseTotalSupplyAtHook = ( + args: UseTotalSupplyAtProps +) => SWRResponse; + +/** + * Get the total supply amount at snapshot + */ +const useTotalSupplyAt: UseTotalSupplyAtHook = ({ + contractAddress, // tokenAddress, + snapshotId, +}) => { + return useEtherSWR( + snapshotId && contractAddress + ? [contractAddress, 'totalSupplyAt', snapshotId] + : [], + { + ABIs: new Map([[contractAddress, ERC20SnapshotRep.abi]]), + } + ); +}; + +export default useTotalSupplyAt;