From fcd0b70fb488ec3fc5ddc2837a0ebc01a6128b9e Mon Sep 17 00:00:00 2001 From: neokry Date: Fri, 24 Mar 2023 14:52:42 -0700 Subject: [PATCH 1/4] Add edit founder controls to DAO admin section --- .../AllocationForm/AllocationForm.schema.ts | 2 +- .../components/AdminForm/AdminForm.schema.ts | 14 +- .../dao/components/AdminForm/AdminForm.tsx | 67 +++++++- .../AdminFounderAllocationFields.tsx | 149 ++++++++++++++++++ .../dao/utils/adminFormFieldToTransaction.tsx | 9 ++ 5 files changed, 233 insertions(+), 8 deletions(-) create mode 100644 apps/web/src/modules/dao/components/AdminForm/AdminFounderAllocationFields.tsx diff --git a/apps/web/src/modules/create-dao/components/AllocationForm/AllocationForm.schema.ts b/apps/web/src/modules/create-dao/components/AllocationForm/AllocationForm.schema.ts index 886818cae..9aa11c969 100644 --- a/apps/web/src/modules/create-dao/components/AllocationForm/AllocationForm.schema.ts +++ b/apps/web/src/modules/create-dao/components/AllocationForm/AllocationForm.schema.ts @@ -3,7 +3,7 @@ import * as Yup from 'yup' import { isValidAddress } from 'src/utils/ens' import { getProvider } from 'src/utils/provider' -const allocationSchema = Yup.object().shape({ +export const allocationSchema = Yup.object().shape({ founderAddress: Yup.string() .test( 'isValidAddress', diff --git a/apps/web/src/modules/dao/components/AdminForm/AdminForm.schema.ts b/apps/web/src/modules/dao/components/AdminForm/AdminForm.schema.ts index a5766ff70..84915c66f 100644 --- a/apps/web/src/modules/dao/components/AdminForm/AdminForm.schema.ts +++ b/apps/web/src/modules/dao/components/AdminForm/AdminForm.schema.ts @@ -1,7 +1,8 @@ import { Provider } from '@ethersproject/abstract-provider' import * as Yup from 'yup' -import { auctionSettingsValidationSchema } from 'src/modules/create-dao' +import { TokenAllocation, auctionSettingsValidationSchema } from 'src/modules/create-dao' +import { allocationSchema } from 'src/modules/create-dao/components/AllocationForm/AllocationForm.schema' import { Duration } from 'src/typings' import { isValidAddress } from 'src/utils/ens' import { durationValidationSchema, urlValidationSchema } from 'src/utils/yup' @@ -17,6 +18,7 @@ export interface AdminFormValues { quorumThreshold: number votingPeriod: Duration votingDelay: Duration + founderAllocation: TokenAllocation[] vetoPower: boolean vetoer: string } @@ -48,6 +50,16 @@ export const adminValidationSchema = (provider: Provider | undefined) => { value: tenMinutes, description: '10 minutes' }, { value: twentyFourWeeks, description: '24 weeks' } ), + founderAllocation: Yup.array() + .of(allocationSchema) + .test( + 'unique', + 'Founder allocation addresses should be unique.', + function (values) { + const addresses = values?.map((v) => v.founderAddress) + return values?.length === new Set(addresses)?.size + } + ), vetoPower: Yup.bool().required('*'), }) ) diff --git a/apps/web/src/modules/dao/components/AdminForm/AdminForm.tsx b/apps/web/src/modules/dao/components/AdminForm/AdminForm.tsx index fefa2c15b..214756feb 100644 --- a/apps/web/src/modules/dao/components/AdminForm/AdminForm.tsx +++ b/apps/web/src/modules/dao/components/AdminForm/AdminForm.tsx @@ -1,6 +1,6 @@ import { Flex, Stack } from '@zoralabs/zord' -import { Contract, ethers } from 'ethers' -import { Formik, FormikValues } from 'formik' +import { BigNumber, Contract, ethers } from 'ethers' +import { FieldArray, Formik, FormikValues } from 'formik' import { AnimatePresence, motion } from 'framer-motion' import isEqual from 'lodash/isEqual' import { useRouter } from 'next/router' @@ -15,7 +15,8 @@ import TextArea from 'src/components/Fields/TextArea' import { NUMBER, TEXT } from 'src/components/Fields/types' import SingleImageUpload from 'src/components/SingleImageUpload/SingleImageUpload' import { NULL_ADDRESS } from 'src/constants/addresses' -import { auctionAbi, governorAbi, metadataAbi } from 'src/data/contract/abis' +import { auctionAbi, governorAbi, metadataAbi, tokenAbi } from 'src/data/contract/abis' +import { TokenAllocation } from 'src/modules/create-dao' import { BuilderTransaction, TransactionType, @@ -24,11 +25,13 @@ import { import { formValuesToTransactionMap } from 'src/modules/dao/utils/adminFormFieldToTransaction' import { useLayoutStore } from 'src/stores' import { sectionWrapperStyle } from 'src/styles/dao.css' +import { AddressType } from 'src/typings' import { getEnsAddress } from 'src/utils/ens' import { compareAndReturn, fromSeconds, unpackOptionalArray } from 'src/utils/helpers' import { DaoContracts, useDaoStore } from '../../stores' import { AdminFormValues, adminValidationSchema } from './AdminForm.schema' +import { AdminFounderAllocationFields } from './AdminFounderAllocationFields' interface AdminFormProps { collectionAddress: string @@ -66,9 +69,15 @@ export const AdminForm: React.FC = ({ collectionAddress }) => { address: addresses?.metadata as Address, } + const tokenContractParams = { + abi: tokenAbi, + address: addresses?.token as Address, + } + const auctionContract = useContract(auctionContractParams) const governorContract = useContract(governorContractParams) const metadataContract = useContract(metadataContractParams) + const tokenContract = useContract(tokenContractParams) const { data } = useContractReads({ contracts: [ @@ -83,6 +92,7 @@ export const AdminForm: React.FC = ({ collectionAddress }) => { { ...metadataContractParams, functionName: 'projectURI' }, { ...metadataContractParams, functionName: 'rendererBase' }, { ...metadataContractParams, functionName: 'description' }, + { ...tokenContractParams, functionName: 'getFounders' }, ], }) @@ -98,12 +108,14 @@ export const AdminForm: React.FC = ({ collectionAddress }) => { daoWebsite, rendererBase, description, - ] = unpackOptionalArray(data, 11) + founders, + ] = unpackOptionalArray(data, 12) const contracts: DaoContracts = { auctionContract: auctionContract ?? undefined, governorContract: governorContract ?? undefined, metadataContract: metadataContract ?? undefined, + tokenContract: tokenContract ?? undefined, } const initialValues: AdminFormValues = { @@ -121,6 +133,12 @@ export const AdminForm: React.FC = ({ collectionAddress }) => { quorumThreshold: Number(quorumVotesBps) / 100 || 0, votingPeriod: fromSeconds(votingPeriod && Number(votingPeriod)), votingDelay: fromSeconds(votingDelay && Number(votingDelay)), + founderAllocation: + founders?.map((x) => ({ + founderAddress: x.wallet, + allocationPercentage: x.ownershipPct, + endDate: new Date(x.vestExpiry * 1000).toISOString(), + })) || [], vetoPower: !!vetoer && vetoer !== NULL_ADDRESS, vetoer: vetoer || '', @@ -189,6 +207,19 @@ export const AdminForm: React.FC = ({ collectionAddress }) => { value = await getEnsAddress(value as string, provider) } + if (field === 'founderAllocation') { + // @ts-ignore + value = (value as TokenAllocation[]).map( + ({ founderAddress, allocationPercentage, endDate }) => ({ + wallet: founderAddress as AddressType, + ownershipPct: allocationPercentage + ? BigNumber.from(allocationPercentage) + : BigNumber.from(0), + vestExpiry: BigNumber.from(Math.floor(new Date(endDate).getTime() / 1000)), + }) + ) + } + const transactionProperties = formValuesToTransactionMap[field] // @ts-ignore const calldata = transactionProperties.constructCalldata(contracts, value) @@ -253,8 +284,15 @@ export const AdminForm: React.FC = ({ collectionAddress }) => { validateOnMount > {(formik) => { - const changes = compareAndReturn(formik.initialValues, formik.values).length - + const founderChanges = isEqual( + formik.initialValues.founderAllocation, + formik.values.founderAllocation + ) + ? 0 + : 1 + const changes = + compareAndReturn(formik.initialValues, formik.values).length + + founderChanges return ( @@ -390,6 +428,23 @@ export const AdminForm: React.FC = ({ collectionAddress }) => { onBlur={formik.handleBlur} errorMessage={formik.errors['votingDelay']} /> + + + {({ remove, push }) => ( + + push({ founderAddress: '', allocation: '', endDate: '' }) + } + /> + )} + + + touched: FormikTouched + formik: FormikProps + removeFounderAddress: (index: number) => void + addFounderAddress: () => void +} + +export const AdminFounderAllocationFields = ({ + values, + auctionDuration, + errors, + touched, + formik, + removeFounderAddress, + addFounderAddress, +}: AdminFounderAllocationFieldsProps) => { + return ( + + + {values.founderAllocation.map((founder, index) => { + const error = + typeof errors?.founderAllocation === 'object' + ? (errors?.founderAllocation?.[index] as FormikErrors) + : undefined + + const touchedField = touched?.founderAllocation?.[index] + + return ( + + + + + + + + + + + + + + + + + + + {founder?.allocationPercentage && founder?.endDate ? ( + + ~{' '} + {calculateMaxAllocation( + founder?.allocationPercentage, + founder?.endDate, + auctionDuration + )}{' '} + Tokens + + ) : null} + + + ) + })} + + + + + + + {typeof errors?.founderAllocation === 'string' && ( + + {errors?.founderAllocation} + + )} + + ) +} diff --git a/apps/web/src/modules/dao/utils/adminFormFieldToTransaction.tsx b/apps/web/src/modules/dao/utils/adminFormFieldToTransaction.tsx index 86614e0d9..5d3b639d7 100644 --- a/apps/web/src/modules/dao/utils/adminFormFieldToTransaction.tsx +++ b/apps/web/src/modules/dao/utils/adminFormFieldToTransaction.tsx @@ -106,6 +106,15 @@ export const formValuesToTransactionMap: FormValuesTransactionMap = { toSeconds(value), ]), }, + founderAllocation: { + functionSignature: 'updateFounders', + getTarget: (addresses) => addresses.token as AddressType, + constructCalldata: ({ tokenContract }, value) => + tokenContract?.interface.encodeFunctionData( + 'updateFounders((address,uint256,uint256)[])', + [value] + ), + }, vetoPower: { functionSignature: 'burnVetoer', getTarget: (addresses) => addresses.governor as AddressType, From f13b1e74b4106f1c66155882c19369bdb8ae1659 Mon Sep 17 00:00:00 2001 From: neokry Date: Fri, 24 Mar 2023 14:53:53 -0700 Subject: [PATCH 2/4] Remove unused components --- .../dao/components/AdminForm/AdminFounderAllocationFields.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/web/src/modules/dao/components/AdminForm/AdminFounderAllocationFields.tsx b/apps/web/src/modules/dao/components/AdminForm/AdminFounderAllocationFields.tsx index 8833ccee8..c2dd91489 100644 --- a/apps/web/src/modules/dao/components/AdminForm/AdminFounderAllocationFields.tsx +++ b/apps/web/src/modules/dao/components/AdminForm/AdminFounderAllocationFields.tsx @@ -1,4 +1,4 @@ -import { Button, Flex, Heading, Paragraph, Stack, Text } from '@zoralabs/zord' +import { Button, Flex, Stack, Text } from '@zoralabs/zord' import { FormikErrors, FormikProps, FormikTouched } from 'formik' import React from 'react' From 08274544aa5cbe11581b708034516ba38ffb2a36 Mon Sep 17 00:00:00 2001 From: neokry Date: Mon, 27 Mar 2023 13:23:38 -0700 Subject: [PATCH 3/4] Adds sections to admin form --- .../AllocationForm/AllocationForm.schema.ts | 4 +- .../dao/components/AdminForm/AdminForm.tsx | 396 ++++++++++-------- .../AdminFounderAllocationFields.tsx | 4 +- .../dao/components/AdminForm/Section.tsx | 28 ++ 4 files changed, 244 insertions(+), 188 deletions(-) create mode 100644 apps/web/src/modules/dao/components/AdminForm/Section.tsx diff --git a/apps/web/src/modules/create-dao/components/AllocationForm/AllocationForm.schema.ts b/apps/web/src/modules/create-dao/components/AllocationForm/AllocationForm.schema.ts index 9aa11c969..90a70d83a 100644 --- a/apps/web/src/modules/create-dao/components/AllocationForm/AllocationForm.schema.ts +++ b/apps/web/src/modules/create-dao/components/AllocationForm/AllocationForm.schema.ts @@ -14,9 +14,9 @@ export const allocationSchema = Yup.object().shape({ allocationPercentage: Yup.number() .transform((value) => (isNaN(value) ? undefined : value)) .required('*') + .integer('Must be whole number') .min(1, '> 0') // (condition, errorMessage) - allocation represented as % must be greater than or equal to 0 - .max(100, '< 100') - .integer('Must be whole number'), + .max(100, '< 100'), endDate: Yup.string() .required('*') .test('isDateInFuture', 'Must be in future', (value: string | undefined) => { diff --git a/apps/web/src/modules/dao/components/AdminForm/AdminForm.tsx b/apps/web/src/modules/dao/components/AdminForm/AdminForm.tsx index 214756feb..9a46d29df 100644 --- a/apps/web/src/modules/dao/components/AdminForm/AdminForm.tsx +++ b/apps/web/src/modules/dao/components/AdminForm/AdminForm.tsx @@ -1,4 +1,4 @@ -import { Flex, Stack } from '@zoralabs/zord' +import { Flex, Stack, Text } from '@zoralabs/zord' import { BigNumber, Contract, ethers } from 'ethers' import { FieldArray, Formik, FormikValues } from 'formik' import { AnimatePresence, motion } from 'framer-motion' @@ -32,6 +32,7 @@ import { compareAndReturn, fromSeconds, unpackOptionalArray } from 'src/utils/he import { DaoContracts, useDaoStore } from '../../stores' import { AdminFormValues, adminValidationSchema } from './AdminForm.schema' import { AdminFounderAllocationFields } from './AdminFounderAllocationFields' +import { Section } from './Section' interface AdminFormProps { collectionAddress: string @@ -296,192 +297,219 @@ export const AdminForm: React.FC = ({ collectionAddress }) => { return ( - - -