From a1c08d3c9bdb4d6e0a02eba59c6ad4bc03c6439f Mon Sep 17 00:00:00 2001 From: johnnyd-eth Date: Tue, 19 Nov 2024 18:11:06 +1100 Subject: [PATCH 1/2] feat: NFTs in v4 create --- .../hooks/NFT/useDeployNftProject.ts | 14 +++++++------ .../transactor}/useLaunchProjectWithNftsTx.ts | 21 ++++--------------- src/packages/v4/models/nfts.ts | 3 ++- .../v4/utils/launchProjectTransformers.ts | 9 +++++--- 4 files changed, 20 insertions(+), 27 deletions(-) rename src/packages/v4/hooks/{ => JB721Delegate/transactor}/useLaunchProjectWithNftsTx.ts (95%) diff --git a/src/packages/v4/components/Create/hooks/DeployProject/hooks/NFT/useDeployNftProject.ts b/src/packages/v4/components/Create/hooks/DeployProject/hooks/NFT/useDeployNftProject.ts index da471c5c53..0e1be3423a 100644 --- a/src/packages/v4/components/Create/hooks/DeployProject/hooks/NFT/useDeployNftProject.ts +++ b/src/packages/v4/components/Create/hooks/DeployProject/hooks/NFT/useDeployNftProject.ts @@ -1,21 +1,23 @@ -import { ONE_BILLION } from 'constants/numbers' -import { DEFAULT_JB_721_TIER_CATEGORY } from 'constants/transactionDefaults' import { JBTiered721Flags, NftRewardTier } from 'models/nftRewards' -import { LaunchTxOpts } from 'packages/v4/hooks/useLaunchProjectTx' -import { useLaunchProjectWithNftsTx } from 'packages/v4/hooks/useLaunchProjectWithNftsTx' import { JB721TierConfig, JB721TiersHookFlags } from 'packages/v4/models/nfts' -import { useCallback } from 'react' import { useAppSelector, useEditingV2V3FundAccessConstraintsSelector, useEditingV2V3FundingCycleDataSelector, useEditingV2V3FundingCycleMetadataSelector, } from 'redux/hooks/useAppSelector' +import { Address, parseEther, zeroAddress } from 'viem' + +import { ONE_BILLION } from 'constants/numbers' +import { DEFAULT_JB_721_TIER_CATEGORY } from 'constants/transactionDefaults' +import { useLaunchProjectWithNftsTx } from 'packages/v4/hooks/JB721Delegate/transactor/useLaunchProjectWithNftsTx' +import { LaunchTxOpts } from 'packages/v4/hooks/useLaunchProjectTx' +import { useCallback } from 'react' import { DEFAULT_NFT_FLAGS } from 'redux/slices/editingV2Project' import { encodeIpfsUri } from 'utils/ipfs' import { NFT_FUNDING_CYCLE_METADATA_OVERRIDES } from 'utils/nftFundingCycleMetadataOverrides' import { sortNftsByContributionFloor } from 'utils/nftRewards' -import { Address, parseEther, zeroAddress } from 'viem' + export const DEFAULT_NFT_MAX_SUPPLY = ONE_BILLION - 1 function nftRewardTierToJB721TierConfig( diff --git a/src/packages/v4/hooks/useLaunchProjectWithNftsTx.ts b/src/packages/v4/hooks/JB721Delegate/transactor/useLaunchProjectWithNftsTx.ts similarity index 95% rename from src/packages/v4/hooks/useLaunchProjectWithNftsTx.ts rename to src/packages/v4/hooks/JB721Delegate/transactor/useLaunchProjectWithNftsTx.ts index bf24a7ccc1..562557dfa0 100644 --- a/src/packages/v4/hooks/useLaunchProjectWithNftsTx.ts +++ b/src/packages/v4/hooks/JB721Delegate/transactor/useLaunchProjectWithNftsTx.ts @@ -12,37 +12,28 @@ import { import { Address, WaitForTransactionReceiptReturnType, - toBytes, - toHex, - zeroAddress, + zeroAddress } from 'viem' import { LaunchV2V3ProjectArgs, transformV2V3CreateArgsToV4, -} from '../utils/launchProjectTransformers' +} from '../../../utils/launchProjectTransformers' import { LaunchTxOpts, SUPPORTED_JB_CONTROLLER_ADDRESS, SUPPORTED_JB_MULTITERMINAL_ADDRESS -} from './useLaunchProjectTx' +} from '../../useLaunchProjectTx' import { waitForTransactionReceipt } from '@wagmi/core' import { JUICEBOX_MONEY_PROJECT_METADATA_DOMAIN } from 'constants/metadataDomain' import { TxHistoryContext } from 'contexts/Transaction/TxHistoryContext' import { useWallet } from 'hooks/Wallet' import { isValidMustStartAtOrAfter } from 'packages/v2v3/utils/fundingCycle' +import { wagmiConfig } from 'packages/v4/wagmiConfig' import { useContext } from 'react' import { DEFAULT_MUST_START_AT_OR_AFTER } from 'redux/slices/editingV2Project' import { ipfsUri } from 'utils/ipfs' import { useChainId } from 'wagmi' -import { wagmiConfig } from '../wagmiConfig' - -function createSalt() { - const base: string = '0x' + Math.random().toString(16).slice(2) // idk lol - const salt = toHex(toBytes(base, { size: 32 })) - - return salt -} /** * Return the project ID created from a `launchProjectFor` transaction. @@ -70,10 +61,6 @@ export const SUPPORTED_JB_721_TIER_STORE = { '11155420': '0x4DeF0AA5B9CA095d11705284221b2878731ab4EF' as Address, } -/** - * - * TODO still wip - */ export function useLaunchProjectWithNftsTx() { const { contracts } = useJBContractContext() const { addTransaction } = useContext(TxHistoryContext) diff --git a/src/packages/v4/models/nfts.ts b/src/packages/v4/models/nfts.ts index f0fcdd7ec1..df7026a90f 100644 --- a/src/packages/v4/models/nfts.ts +++ b/src/packages/v4/models/nfts.ts @@ -1,7 +1,8 @@ import { JBRulesetData, JBRulesetMetadata } from 'juice-sdk-core' +import { Address, ContractFunctionReturnType } from 'viem' + import { jb721TiersHookStoreAbi } from 'juice-sdk-react' import { LaunchV2V3ProjectData } from 'packages/v2v3/hooks/transactor/useLaunchProjectTx' -import { Address, ContractFunctionReturnType } from 'viem' import { LaunchV4ProjectGroupedSplit } from '../utils/launchProjectTransformers' import { FundAccessLimitGroup } from './fundAccessLimits' import { LaunchProjectJBTerminal } from './terminals' diff --git a/src/packages/v4/utils/launchProjectTransformers.ts b/src/packages/v4/utils/launchProjectTransformers.ts index d5cfb39edb..066ea2d678 100644 --- a/src/packages/v4/utils/launchProjectTransformers.ts +++ b/src/packages/v4/utils/launchProjectTransformers.ts @@ -4,12 +4,13 @@ import { NATIVE_TOKEN_DECIMALS, SplitGroup, } from 'juice-sdk-core' -import round from 'lodash/round' -import { V2FundingCycleMetadata } from 'packages/v2/models/fundingCycle' import { V2V3FundAccessConstraint, V2V3FundingCycleData, } from 'packages/v2v3/models/fundingCycle' + +import round from 'lodash/round' +import { V2FundingCycleMetadata } from 'packages/v2/models/fundingCycle' import { GroupedSplits as V2V3GroupedSplits } from 'packages/v2v3/models/splits' import { V3FundingCycleMetadata } from 'packages/v3/models/fundingCycle' import { Address } from 'viem' @@ -136,7 +137,9 @@ export function transformV2V3SplitsToV4({ }): LaunchV4ProjectGroupedSplit[] { return v2v3Splits.map(group => ({ groupId: - group.group === SplitGroup.ETHPayout ? BigInt(NATIVE_TOKEN) : 1n, // TODO dont hardcode reserved token group as 1n + group.group === SplitGroup.ETHPayout + ? BigInt(NATIVE_TOKEN) + : 1n, // TODO dont hardcode reserved token group as 1n splits: group.splits.map(split => ({ preferAddToBalance: Boolean(split.preferClaimed), percent: split.percent, From 2c17d4c705b4bd1772f40b048260c72ba8031d8c Mon Sep 17 00:00:00 2001 From: johnnyd-eth Date: Wed, 20 Nov 2024 09:40:37 +1100 Subject: [PATCH 2/2] feat: read chainId from connectedWallet to launch v4 projects --- src/hooks/Wallet/useWallet.ts | 2 +- .../components/pages/ReviewDeploy/ReviewDeployPage.tsx | 7 ++++--- .../hooks/DeployProject/hooks/useDeployStandardProject.ts | 4 +++- src/packages/v4/hooks/useLaunchProjectTx.ts | 1 - 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/hooks/Wallet/useWallet.ts b/src/hooks/Wallet/useWallet.ts index 3d01614a7e..e97d72250a 100644 --- a/src/hooks/Wallet/useWallet.ts +++ b/src/hooks/Wallet/useWallet.ts @@ -15,7 +15,7 @@ export function useWallet() { const userAddress = useUserAddress() const isConnected = useIsConnected() const chain = useChain() - const chainUnsupported = false//useChainUnsupported() + const chainUnsupported = false //useChainUnsupported() const balance = useWalletBalance() const [, connect] = useConnectWallet() diff --git a/src/packages/v4/components/Create/components/pages/ReviewDeploy/ReviewDeployPage.tsx b/src/packages/v4/components/Create/components/pages/ReviewDeploy/ReviewDeployPage.tsx index 7302f3591b..2fc63d316b 100644 --- a/src/packages/v4/components/Create/components/pages/ReviewDeploy/ReviewDeployPage.tsx +++ b/src/packages/v4/components/Create/components/pages/ReviewDeploy/ReviewDeployPage.tsx @@ -1,6 +1,8 @@ +import { Checkbox, Form } from 'antd' +import { useCallback, useContext, useEffect, useMemo, useState } from 'react' + import { CheckCircleFilled } from '@ant-design/icons' import { Trans } from '@lingui/macro' -import { Checkbox, Form } from 'antd' import { Callout } from 'components/Callout/Callout' import ExternalLink from 'components/ExternalLink' import TransactionModal from 'components/modals/TransactionModal' @@ -10,7 +12,6 @@ import { emitConfirmationDeletionModal } from 'hooks/emitConfirmationDeletionMod import useMobile from 'hooks/useMobile' import { useModal } from 'hooks/useModal' import { useRouter } from 'next/router' -import { useCallback, useContext, useEffect, useMemo, useState } from 'react' import { useDispatch } from 'react-redux' import { useAppSelector } from 'redux/hooks/useAppSelector' import { useSetCreateFurthestPageReached } from 'redux/hooks/useEditingCreateFurthestPageReached' @@ -80,8 +81,8 @@ export const ReviewDeployPage = () => { goToPage?.('projectDetails') dispatch(editingV2ProjectActions.resetState()) }, [dispatch, goToPage, router]) - const onFinish = useCallback(async () => { + if (chainUnsupported) { await changeNetworks() return diff --git a/src/packages/v4/components/Create/hooks/DeployProject/hooks/useDeployStandardProject.ts b/src/packages/v4/components/Create/hooks/DeployProject/hooks/useDeployStandardProject.ts index 2ec6c7a771..a110af0b1e 100644 --- a/src/packages/v4/components/Create/hooks/DeployProject/hooks/useDeployStandardProject.ts +++ b/src/packages/v4/components/Create/hooks/DeployProject/hooks/useDeployStandardProject.ts @@ -1,5 +1,4 @@ import { LaunchTxOpts, useLaunchProjectTx } from 'packages/v4/hooks/useLaunchProjectTx' -import { useCallback } from 'react' import { useAppSelector, useEditingV2V3FundAccessConstraintsSelector, @@ -7,6 +6,8 @@ import { useEditingV2V3FundingCycleMetadataSelector, } from 'redux/hooks/useAppSelector' +import { useCallback } from 'react' + /** * Hook that returns a function that deploys a v4 project. * @@ -35,6 +36,7 @@ export const useDeployStandardProject = () => { metadataCid: string } & LaunchTxOpts) => { const groupedSplits = [payoutGroupedSplits, reservedTokensGroupedSplits] + return await launchProjectTx( { owner: inputProjectOwner?.length ? inputProjectOwner : undefined, diff --git a/src/packages/v4/hooks/useLaunchProjectTx.ts b/src/packages/v4/hooks/useLaunchProjectTx.ts index e2817e6740..df905ddffd 100644 --- a/src/packages/v4/hooks/useLaunchProjectTx.ts +++ b/src/packages/v4/hooks/useLaunchProjectTx.ts @@ -135,7 +135,6 @@ export function useLaunchProjectTx() { // functionName: 'launchProjectFor', // args, // }) - const hash = await writeLaunchProject({ chainId, address: controllerAddress,