Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Remove erc20claim typechain #1665

Merged
merged 4 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
316 changes: 316 additions & 0 deletions src/assets/abi/ERC20Claim.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,316 @@
const ERC20ClaimAbi = [
{
inputs: [],
stateMutability: 'nonpayable',
type: 'constructor',
},
{
inputs: [],
name: 'AllocationClaimed',
type: 'error',
},
{
inputs: [],
name: 'DeadlinePending',
type: 'error',
},
{
inputs: [],
name: 'NoAllocation',
type: 'error',
},
{
inputs: [],
name: 'NoDeadline',
type: 'error',
},
{
inputs: [],
name: 'NotTheFunder',
type: 'error',
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: 'address',
name: 'parentToken',
type: 'address',
},
{
indexed: false,
internalType: 'address',
name: 'childToken',
type: 'address',
},
{
indexed: false,
internalType: 'uint256',
name: 'parentAllocation',
type: 'uint256',
},
{
indexed: false,
internalType: 'uint256',
name: 'snapshotId',
type: 'uint256',
},
{
indexed: false,
internalType: 'uint256',
name: 'deadline',
type: 'uint256',
},
],
name: 'ERC20ClaimCreated',
type: 'event',
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: 'address',
name: 'pToken',
type: 'address',
},
{
indexed: true,
internalType: 'address',
name: 'cToken',
type: 'address',
},
{
indexed: true,
internalType: 'address',
name: 'claimer',
type: 'address',
},
{
indexed: false,
internalType: 'uint256',
name: 'amount',
type: 'uint256',
},
],
name: 'ERC20Claimed',
type: 'event',
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: 'uint8',
name: 'version',
type: 'uint8',
},
],
name: 'Initialized',
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',
},
{
inputs: [],
name: 'childERC20',
outputs: [
{
internalType: 'address',
name: '',
type: 'address',
},
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{
internalType: 'address',
name: 'claimer',
type: 'address',
},
],
name: 'claimTokens',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [
{
internalType: 'address',
name: '',
type: 'address',
},
],
name: 'claimed',
outputs: [
{
internalType: 'bool',
name: '',
type: 'bool',
},
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'deadlineBlock',
outputs: [
{
internalType: 'uint32',
name: '',
type: 'uint32',
},
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'funder',
outputs: [
{
internalType: 'address',
name: '',
type: 'address',
},
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{
internalType: 'address',
name: 'claimer',
type: 'address',
},
],
name: 'getClaimAmount',
outputs: [
{
internalType: 'uint256',
name: '',
type: 'uint256',
},
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'owner',
outputs: [
{
internalType: 'address',
name: '',
type: 'address',
},
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'parentAllocation',
outputs: [
{
internalType: 'uint256',
name: '',
type: 'uint256',
},
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'parentERC20',
outputs: [
{
internalType: 'address',
name: '',
type: 'address',
},
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'reclaim',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [],
name: 'renounceOwnership',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [
{
internalType: 'bytes',
name: 'initializeParams',
type: 'bytes',
},
],
name: 'setUp',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [],
name: 'snapShotId',
outputs: [
{
internalType: 'uint256',
name: '',
type: 'uint256',
},
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{
internalType: 'address',
name: 'newOwner',
type: 'address',
},
],
name: 'transferOwnership',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
] as const;

export default ERC20ClaimAbi;
31 changes: 23 additions & 8 deletions src/components/pages/DaoDashboard/ERC20Claim.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { Alert, AlertTitle, Button, Flex, Text } from '@chakra-ui/react';
import { Alert as AlertIcon } from '@decent-org/fractal-ui';
import { useCallback, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { getAddress, getContract } from 'viem';
import { usePublicClient, useWalletClient } from 'wagmi';
import ERC20ClaimAbi from '../../../assets/abi/ERC20Claim';
import { useTransaction } from '../../../hooks/utils/useTransaction';
import { useFractal } from '../../../providers/App/AppProvider';
import { AzoriusGovernance } from '../../../types';
Expand All @@ -14,25 +17,32 @@ export function ERCO20Claim() {
readOnly: { user },
} = useFractal();
const account = user.address;
const { tokenClaimContract, type } = governance;
const { tokenClaimContractAddress, type } = governance;
const { t } = useTranslation(['dashboard', 'transaction']);
const [contractCall, pending] = useTransaction();
const [, pending, contractCallViem] = useTransaction();
const azoriusGovernance = governance as AzoriusGovernance;
const publicClient = usePublicClient();
const { data: walletClient } = useWalletClient();

const loadClaim = useCallback(async () => {
if (!tokenClaimContract || !type || !account) {
if (!tokenClaimContractAddress || !type || !account || !publicClient) {
return;
}
const claimableAmount = (await tokenClaimContract.getClaimAmount(account)).toBigInt();
const tokenClaimContract = getContract({
abi: ERC20ClaimAbi,
address: tokenClaimContractAddress,
client: publicClient,
});
const claimableAmount = await tokenClaimContract.read.getClaimAmount([getAddress(account)]);
setUserClaimable(claimableAmount);
}, [tokenClaimContract, type, account]);
}, [account, publicClient, tokenClaimContractAddress, type]);

useEffect(() => {
loadClaim();
}, [loadClaim]);

const claimToken = async () => {
if (!tokenClaimContract || !azoriusGovernance.votesToken || !account) {
if (!tokenClaimContractAddress || !azoriusGovernance.votesToken || !account || !walletClient) {
return;
}
const claimableString = formatCoin(
Expand All @@ -41,8 +51,13 @@ export function ERCO20Claim() {
azoriusGovernance.votesToken.decimals,
azoriusGovernance.votesToken.symbol,
);
contractCall({
contractFn: () => tokenClaimContract.claimTokens(account),
const tokenClaimContract = getContract({
abi: ERC20ClaimAbi,
address: tokenClaimContractAddress,
client: walletClient,
});
contractCallViem({
contractFn: () => tokenClaimContract.write.claimTokens([getAddress(account)]),
pendingMessage: t('pendingTokenClaim', {
symbol: azoriusGovernance.votesToken.symbol,
ns: 'transaction',
Expand Down
2 changes: 0 additions & 2 deletions src/components/pages/DaoDashboard/Info/DaoInfoHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Box, Flex, Text } from '@chakra-ui/react';
import useDAOMetadata from '../../../../hooks/DAO/useDAOMetadata';
import { useFractal } from '../../../../providers/App/AppProvider';
import { DAOInfoCard } from '../../../ui/cards/DAOInfoCard';
import { InfoBox } from '../../../ui/containers/InfoBox';
import ExternalLink from '../../../ui/links/ExternalLink';
Expand All @@ -10,7 +9,6 @@ import { InfoTreasury } from './InfoTreasury';
import { ParentLink } from './ParentLink';

export function DaoInfoHeader() {
const { node, guardContracts, guard } = useFractal();
const daoMetadata = useDAOMetadata();

// using this gap method instead of 'gap' to make width percentages more precise, since they
Expand Down
Loading