From ee8d34579f0f24fe33064fea4874f7f071c197ee Mon Sep 17 00:00:00 2001 From: Milton Date: Thu, 7 Apr 2022 17:48:34 -0300 Subject: [PATCH] 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;