Skip to content

Commit

Permalink
feat: adjust tiers in v4 settings
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyd-eth committed Dec 7, 2024
1 parent 99604b9 commit 3465bbd
Show file tree
Hide file tree
Showing 44 changed files with 1,086 additions and 145 deletions.
2 changes: 1 addition & 1 deletion src/components/Project/ProjectTabs/EmptyScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const EmptyScreen = ({
<div className="font-heading text-2xl font-medium dark:text-slate-200">
{title}
</div>
{subtitle && (
{subtitle || (
<div className="mt-3 text-base dark:text-slate-300">
This project has no description.
</div>
Expand Down
8 changes: 8 additions & 0 deletions src/models/JB721Delegate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export enum JB721DelegateVersion {
JB721DELEGATE_V3 = '3',
JB721DELEGATE_V3_1 = '3-1',
JB721DELEGATE_V3_2 = '3-2',
JB721DELEGATE_V3_3 = '3-3',
JB721DELEGATE_V3_4 = '3-4',
JB721DELEGATE_V4 = '4',
}
20 changes: 19 additions & 1 deletion src/models/nftRewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,24 @@ export type JB_721_TIER_PARAMS_V3_2 = Omit<
useVotingUnits: boolean
}

// v4TODO: add to SDK
export type JB_721_TIER_PARAMS_V4 = {
price: bigint
initialSupply: number
votingUnits: number
reserveFrequency: number
reserveBeneficiary: `0x${string}`
encodedIPFSUri: `0x${string}`
category: number
discountPercent: number
allowOwnerMint: boolean
useReserveBeneficiaryAsDefault: boolean
transfersPausable: boolean
useVotingUnits: boolean
cannotBeRemoved: boolean
cannotIncreaseDiscountPercent: boolean
}

// Tiers as they are stored on-chain.
export type JB721TierV3 = JB721TierParams & {
id: BigNumber
Expand Down Expand Up @@ -126,7 +144,7 @@ export enum JB721GovernanceType {
}

export interface JB721PricingParams {
tiers: (JB721TierParams | JB_721_TIER_PARAMS_V3_1 | JB_721_TIER_PARAMS_V3_2)[]
tiers: (JB721TierParams | JB_721_TIER_PARAMS_V3_1 | JB_721_TIER_PARAMS_V3_2 | JB_721_TIER_PARAMS_V4)[]
currency: CurrencyOption
decimals: number
prices: string // address
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { t } from '@lingui/macro'
import { NEW_NFT_ID_LOWER_LIMIT } from 'components/NftRewards/RewardsList/AddEditRewardModal'
import { NftRewardTier } from 'models/nftRewards'
import { JB721DelegateContractsContext } from 'packages/v2v3/contexts/NftRewards/JB721DelegateContracts/JB721DelegateContractsContext'
import { useAdjustTiersTx } from 'packages/v2v3/hooks/JB721Delegate/transactor/useAdjustTiersTx'
import { useCallback, useContext, useState } from 'react'
import { JB721TierParams, JB_721_TIER_PARAMS_V3_1, JB_721_TIER_PARAMS_V3_2, NftRewardTier } from 'models/nftRewards'
import { buildJB721TierParams, pinNftRewards } from 'utils/nftRewards'
import { useCallback, useContext, useState } from 'react'

import { JB721DelegateContractsContext } from 'packages/v2v3/contexts/NftRewards/JB721DelegateContracts/JB721DelegateContractsContext'
import { NEW_NFT_ID_LOWER_LIMIT } from 'components/NftRewards/RewardsList/AddEditRewardModal'
import { emitErrorNotification } from 'utils/notifications'
import { t } from '@lingui/macro'
import { useAdjustTiersTx } from 'packages/v2v3/hooks/JB721Delegate/transactor/useAdjustTiersTx'

export function useUpdateCurrentCollection({
rewardTiers,
Expand Down Expand Up @@ -40,7 +41,7 @@ export function useUpdateCurrentCollection({
cids: rewardTiersCIDs,
rewardTiers: newRewardTiers,
version,
})
}) as (JB721TierParams | JB_721_TIER_PARAMS_V3_1 | JB_721_TIER_PARAMS_V3_2)[]

if (!newTiers) {
emitErrorNotification(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Contract } from 'ethers'
import { JB721DelegateVersion } from 'packages/v2v3/models/contracts'
import { JB721DelegateVersion } from 'models/JB721Delegate'
import { createContext } from 'react'

interface JB721DelegateContracts {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQuery } from '@tanstack/react-query'
import axios from 'axios'
import { JB721DelegateVersion } from 'packages/v2v3/models/contracts'
import { JB721DelegateVersion } from 'models/JB721Delegate'
import { isZeroAddress } from 'utils/address'

export function useJB721DelegateVersion({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { JB721DelegateVersion } from 'models/JB721Delegate'
import { JB721DelegateContractsContext } from 'packages/v2v3/contexts/NftRewards/JB721DelegateContracts/JB721DelegateContractsContext'
import useV2ContractReader from 'packages/v2v3/hooks/contractReader/useV2ContractReader'
import { JB721DelegateVersion } from 'packages/v2v3/models/contracts'
import { useContext } from 'react'

export function useNftCollectionMetadataUri(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { JB721TierV3, JB_721_TIER_V3_2 } from 'models/nftRewards'

import { JB721DelegateVersion } from 'models/JB721Delegate'
import { MAX_NFT_REWARD_TIERS } from 'packages/v2v3/constants/nftRewards'
import { JB721DelegateContractsContext } from 'packages/v2v3/contexts/NftRewards/JB721DelegateContracts/JB721DelegateContractsContext'
import useV2ContractReader from 'packages/v2v3/hooks/contractReader/useV2ContractReader'
import { JB721DelegateVersion } from 'packages/v2v3/models/contracts'
import { useContext } from 'react'

function buildArgs(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useEffect, useState } from 'react'

import { ContractInterface } from 'ethers'
import { ContractJson } from 'models/contracts'
import { JB721DelegateVersion } from 'packages/v2v3/models/contracts'
import { useEffect, useState } from 'react'
import { JB721DelegateVersion } from 'models/JB721Delegate'

type JB721DelegateContractName =
| 'JB721TieredGovernance'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { readNetwork } from 'constants/networks'
import { ForgeDeploy, addressFor } from 'forge-run-parser'
import { NetworkName } from 'models/networkName'
import { JB721DelegateVersion } from 'packages/v2v3/models/contracts'
import { useEffect, useState } from 'react'

import { readNetwork } from 'constants/networks'
import { JB721DelegateVersion } from 'models/JB721Delegate'
import { NetworkName } from 'models/networkName'

/**
* Some addresses aren't in the forge deployment manifests, so we have to hardcode them here.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Contract } from 'ethers'
import { useLoadContractFromAddress } from 'hooks/useLoadContractFromAddress'
import { JB721DelegateVersion } from 'packages/v2v3/models/contracts'
import { JB721DelegateVersion } from 'models/JB721Delegate'
import { useJB721DelegateAbi } from './useJB721DelegateAbi'

export function useJB721TieredDelegate({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Contract } from 'ethers'
import { useLoadContractFromAddress } from 'hooks/useLoadContractFromAddress'
import { JB721DelegateVersion } from 'packages/v2v3/models/contracts'
import { JB721DelegateVersion } from 'models/JB721Delegate'
import { useJB721DelegateAbi } from './useJB721DelegateAbi'

export function useJB721TieredDelegateStore({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Contract } from 'ethers'
import { useLoadContractFromAddress } from 'hooks/useLoadContractFromAddress'
import { JB721DelegateVersion } from 'models/JB721Delegate'
import { useJB721DelegateAbi } from 'packages/v2v3/hooks/JB721Delegate/contracts/useJB721DelegateAbi'
import { JB721DelegateVersion } from 'packages/v2v3/models/contracts'
import { useJB721DelegateContractAddress } from './useJB721DelegateContractAddress'

export function useJBTiered721DelegateProjectDeployer({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { V2V3ProjectContractsContext } from 'packages/v2v3/contexts/ProjectContracts/V2V3ProjectContractsContext'
import { DEFAULT_JB_721_DELEGATE_VERSION } from 'packages/v2v3/hooks/defaultContracts/useDefaultJB721Delegate'
import { JB721DelegateVersion } from 'models/JB721Delegate'
import {
JB721DelegateVersion,
V2V3ContractName,
} from 'packages/v2v3/models/contracts'
import { V2V3ProjectContractsContext } from 'packages/v2v3/contexts/ProjectContracts/V2V3ProjectContractsContext'
import { useContext } from 'react'

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Contract } from 'ethers'
import { useContractReadValue } from 'hooks/ContractReader'
import { JB721DelegateVersion } from 'packages/v2v3/models/contracts'
import { JB721DelegateVersion } from 'models/JB721Delegate'
import { useJB721TieredDelegateStore } from './useJB721TieredDelegateStore'

export function useStoreOfJB721TieredDelegate({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,50 @@
import { t } from '@lingui/macro'
import { JUICEBOX_MONEY_PROJECT_METADATA_DOMAIN } from 'constants/metadataDomain'
import { DEFAULT_MEMO } from 'constants/transactionDefaults'
import { TransactionContext } from 'contexts/Transaction/TransactionContext'
import { getAddress } from 'ethers/lib/utils'
import { useWallet } from 'hooks/Wallet'
import { TransactorInstance } from 'hooks/useTransactor'
import omit from 'lodash/omit'
import { GroupedSplits, SplitGroup } from 'packages/v2v3/models/splits'
import {
JB721GovernanceType,
JB721TierParams,
JBDeployTiered721DelegateData,
JBTiered721Flags,
JB_721_TIER_PARAMS_V3_1,
JB_721_TIER_PARAMS_V3_2,
JB_721_TIER_PARAMS_V4,
JB_DEPLOY_TIERED_721_DELEGATE_DATA_V3_1,
} from 'models/nftRewards'
import { V2V3ContractsContext } from 'packages/v2v3/contexts/Contracts/V2V3ContractsContext'
import { useJBPrices } from 'packages/v2v3/hooks/JBPrices'
import { DEFAULT_JB_721_DELEGATE_VERSION } from 'packages/v2v3/hooks/defaultContracts/useDefaultJB721Delegate'
import { useDefaultJBController } from 'packages/v2v3/hooks/defaultContracts/useDefaultJBController'
import { useDefaultJBETHPaymentTerminal } from 'packages/v2v3/hooks/defaultContracts/useDefaultJBETHPaymentTerminal'
import { LaunchV2V3ProjectData } from 'packages/v2v3/hooks/transactor/useLaunchProjectTx'
import { useV2ProjectTitle } from 'packages/v2v3/hooks/useProjectTitle'
import { V2V3CurrencyOption } from 'packages/v2v3/models/currencyOption'
import {
JBPayDataSourceFundingCycleMetadata,
V2V3FundAccessConstraint,
V2V3FundingCycleData,
} from 'packages/v2v3/models/fundingCycle'
import { GroupedSplits, SplitGroup } from 'packages/v2v3/models/splits'
import { isValidMustStartAtOrAfter } from 'packages/v2v3/utils/fundingCycle'
import { useContext } from 'react'

import { DEFAULT_JB_721_DELEGATE_VERSION } from 'packages/v2v3/hooks/defaultContracts/useDefaultJB721Delegate'
import { DEFAULT_MEMO } from 'constants/transactionDefaults'
import { DEFAULT_MUST_START_AT_OR_AFTER } from 'redux/slices/shared/v2ProjectDefaultState'
import { JUICEBOX_MONEY_PROJECT_METADATA_DOMAIN } from 'constants/metadataDomain'
import { LaunchV2V3ProjectData } from 'packages/v2v3/hooks/transactor/useLaunchProjectTx'
import { TransactionContext } from 'contexts/Transaction/TransactionContext'
import { TransactorInstance } from 'hooks/useTransactor'
import { V2V3ContractsContext } from 'packages/v2v3/contexts/Contracts/V2V3ContractsContext'
import { V2V3CurrencyOption } from 'packages/v2v3/models/currencyOption'
import { buildDeployTiered721DelegateData } from 'utils/nftRewards'
import { getAddress } from 'ethers/lib/utils'
import { isValidMustStartAtOrAfter } from 'packages/v2v3/utils/fundingCycle'
import omit from 'lodash/omit'
import { t } from '@lingui/macro'
import { useContext } from 'react'
import { useDefaultJBController } from 'packages/v2v3/hooks/defaultContracts/useDefaultJBController'
import { useDefaultJBETHPaymentTerminal } from 'packages/v2v3/hooks/defaultContracts/useDefaultJBETHPaymentTerminal'
import { useJB721DelegateContractAddress } from '../contracts/useJB721DelegateContractAddress'
import { useJBPrices } from 'packages/v2v3/hooks/JBPrices'
import { useJBTiered721DelegateProjectDeployer } from '../contracts/useJBTiered721DelegateProjectDeployer'
import { useV2ProjectTitle } from 'packages/v2v3/hooks/useProjectTitle'
import { useWallet } from 'hooks/Wallet'

interface DeployTiered721DelegateData {
collectionUri: string
collectionName: string
collectionSymbol: string
currency: V2V3CurrencyOption
governanceType: JB721GovernanceType
tiers: (JB721TierParams | JB_721_TIER_PARAMS_V3_1 | JB_721_TIER_PARAMS_V3_2)[]
tiers: (JB721TierParams | JB_721_TIER_PARAMS_V3_1 | JB_721_TIER_PARAMS_V3_2 | JB_721_TIER_PARAMS_V4)[]
flags: JBTiered721Flags
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
import {
JBDeployTiered721DelegateData,
JB_DEPLOY_TIERED_721_DELEGATE_DATA_V3_1,
} from 'models/nftRewards'
import {
JBPayDataSourceFundingCycleMetadata,
V2V3FundAccessConstraint,
V2V3FundingCycleData,
} from 'packages/v2v3/models/fundingCycle'
import { GroupedSplits, SplitGroup } from 'packages/v2v3/models/splits'
import {
buildDeployTiered721DelegateData,
buildJB721TierParams,
defaultNftCollectionName,
} from 'utils/nftRewards'

import { t } from '@lingui/macro'
import { ProjectMetadataContext } from 'contexts/ProjectMetadataContext'
import { TransactionContext } from 'contexts/Transaction/TransactionContext'
import { getAddress } from 'ethers/lib/utils'
import { TransactorInstance } from 'hooks/useTransactor'
import omit from 'lodash/omit'
import {
JBDeployTiered721DelegateData,
JB_DEPLOY_TIERED_721_DELEGATE_DATA_V3_1,
} from 'models/nftRewards'
import { JB721DelegateVersion } from 'models/JB721Delegate'
import { V2V3ContractsContext } from 'packages/v2v3/contexts/Contracts/V2V3ContractsContext'
import { V2V3ProjectContext } from 'packages/v2v3/contexts/Project/V2V3ProjectContext'
import { V2V3ProjectContractsContext } from 'packages/v2v3/contexts/ProjectContracts/V2V3ProjectContractsContext'
import { useJBPrices } from 'packages/v2v3/hooks/JBPrices'
import { ReconfigureFundingCycleTxParams } from 'packages/v2v3/hooks/transactor/useReconfigureV2V3FundingCycleTx'
import { useV2ProjectTitle } from 'packages/v2v3/hooks/useProjectTitle'
import { JB721DelegateVersion } from 'packages/v2v3/models/contracts'
import {
JBPayDataSourceFundingCycleMetadata,
V2V3FundAccessConstraint,
V2V3FundingCycleData,
} from 'packages/v2v3/models/fundingCycle'
import { GroupedSplits, SplitGroup } from 'packages/v2v3/models/splits'
import { V2V3_CURRENCY_ETH } from 'packages/v2v3/utils/currency'
import { isValidMustStartAtOrAfter } from 'packages/v2v3/utils/fundingCycle'
import { useContext } from 'react'
import { DEFAULT_MUST_START_AT_OR_AFTER } from 'redux/slices/shared/v2ProjectDefaultState'
import { NftRewardsData } from 'redux/slices/shared/v2ProjectTypes'
import {
buildDeployTiered721DelegateData,
buildJB721TierParams,
defaultNftCollectionName,
} from 'utils/nftRewards'
import { useJB721DelegateContractAddress } from '../contracts/useJB721DelegateContractAddress'
import { useJBTiered721DelegateProjectDeployer } from '../contracts/useJBTiered721DelegateProjectDeployer'
import { useProjectControllerJB721DelegateVersion } from '../contracts/useProjectJB721DelegateVersion'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { JB721DelegateVersion } from 'packages/v2v3/models/contracts'
import { JB721DelegateVersion } from 'models/JB721Delegate'

/**
* The version of the JB721Delegate contracts (NFT Rewards) that should be used to launch projects, funding cycles, etc.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import * as constants from '@ethersproject/constants'

import { cidFromUrl, encodeIpfsUri, ipfsUri } from 'utils/ipfs'

import { t } from '@lingui/macro'
import { ProjectMetadataContext } from 'contexts/ProjectMetadataContext'
import { TransactionContext } from 'contexts/Transaction/TransactionContext'
import { useDefaultTokenUriResolver } from 'hooks/DefaultTokenUriResolver/contracts/useDefaultTokenUriResolver'
import { TransactorInstance } from 'hooks/useTransactor'
import { JB721DelegateVersion } from 'models/JB721Delegate'
import { NftCollectionMetadata } from 'models/nftRewards'
import { JB721DelegateContractsContext } from 'packages/v2v3/contexts/NftRewards/JB721DelegateContracts/JB721DelegateContractsContext'
import { JB721DelegateVersion } from 'packages/v2v3/models/contracts'
import { useContext } from 'react'
import { cidFromUrl, encodeIpfsUri, ipfsUri } from 'utils/ipfs'
import { pinNftCollectionMetadata } from 'utils/nftRewards'
import { useV2ProjectTitle } from '../useProjectTitle'

Expand Down
8 changes: 0 additions & 8 deletions src/packages/v2v3/models/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,3 @@ export const SUPPORTED_CONTROLLERS = [
V2V3ContractName.JBController3_1,
] as const
export type ControllerVersion = (typeof SUPPORTED_CONTROLLERS)[number]

export enum JB721DelegateVersion {
JB721DELEGATE_V3 = '3',
JB721DELEGATE_V3_1 = '3-1',
JB721DELEGATE_V3_2 = '3-2',
JB721DELEGATE_V3_3 = '3-3',
JB721DELEGATE_V3_4 = '3-4',
}
21 changes: 12 additions & 9 deletions src/packages/v4/contexts/V4SettingsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { WagmiProvider } from 'wagmi'
import { chainNameMap } from '../utils/networks'
import { EditCycleFormProvider } from '../views/V4ProjectSettings/EditCyclePage/EditCycleFormContext'
import { wagmiConfig } from '../wagmiConfig'
import { V4NftRewardsProvider } from './V4NftRewards/V4NftRewardsProvider'
import V4ProjectMetadataProvider from './V4ProjectMetadataProvider'

export const V4SettingsProvider: React.FC<React.PropsWithChildren> = ({
Expand All @@ -33,15 +34,17 @@ export const V4SettingsProvider: React.FC<React.PropsWithChildren> = ({
metadata: { ipfsGatewayHostname: OPEN_IPFS_GATEWAY_HOSTNAME },
}}
>
<V4ProjectMetadataProvider projectId={projectIdBigInt}>
<Provider store={store}>
<TransactionProvider>
<EditCycleFormProvider>
{children}
</EditCycleFormProvider>
</TransactionProvider>
</Provider>
</V4ProjectMetadataProvider>
<V4NftRewardsProvider>
<V4ProjectMetadataProvider projectId={projectIdBigInt}>
<Provider store={store}>
<TransactionProvider>
<EditCycleFormProvider>
{children}
</EditCycleFormProvider>
</TransactionProvider>
</Provider>
</V4ProjectMetadataProvider>
</V4NftRewardsProvider>
</JBProjectProvider>
</WagmiProvider>
</AppWrapper>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { V4OperatorPermission } from 'packages/v4/models/v4Permissions'
import { useV4WalletHasPermission } from '../../useV4WalletHasPermission'

/**
* Checks whether the given [projectOwnerAddress] has given the JBTiered721DelegateProjectDeployer
* permission to queue rulesets for the given [projectId].
*
* This must be true for the following circumstances (non-exhaustive):
* - A project is reconfiguring their FC to include NFTs
* - A project is launching their V3 FC with NFTs
*/
export function useNftDeployerCanReconfigure() {
const JBTiered721DelegateProjectDeployerCanReconfigure = useV4WalletHasPermission(V4OperatorPermission.QUEUE_RULESETS)

return JBTiered721DelegateProjectDeployerCanReconfigure
}
Loading

0 comments on commit 3465bbd

Please sign in to comment.