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 6, 2024
1 parent 99604b9 commit cbb870f
Show file tree
Hide file tree
Showing 40 changed files with 1,079 additions and 115 deletions.
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,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,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,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,40 @@
import { useReadJbPermissionsHasPermissions } from 'juice-sdk-react'
import { V4OperatorPermission } from 'packages/v4/models/v4Permissions'
import { zeroAddress } from 'viem'
import { useChainId } from 'wagmi'
import { SUPPORTED_JB_MULTITERMINAL_ADDRESS } from '../../useLaunchProjectTx'
import { SUPPORTED_JB_721_TIER_STORE } from '../transactor/useLaunchProjectWithNftsTx'

/**
* 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({
projectOwnerAddress = zeroAddress,
projectId,
}: {
projectOwnerAddress: `0x${string}` | undefined
projectId: number | undefined
}) {
const chainId = useChainId()
const chainIdStr =
chainId?.toString() as keyof typeof SUPPORTED_JB_MULTITERMINAL_ADDRESS

const JBTiered721DelegateStoreAddress = chainId
? SUPPORTED_JB_721_TIER_STORE[chainIdStr]
: zeroAddress

const { data: JBTiered721DelegateProjectDeployerCanReconfigure } =
useReadJbPermissionsHasPermissions({
operator: JBTiered721DelegateStoreAddress,

Check failure on line 33 in src/packages/v4/hooks/JB721Delegate/contractReader/useNftDeployerCanReconfigure.ts

View workflow job for this annotation

GitHub Actions / Compile Typescript

Object literal may only specify known properties, and 'operator' does not exist in type '{ address?: `0x${string}` | undefined; value?: undefined; args?: readonly [`0x${string}`, `0x${string}`, bigint, readonly bigint[], Widen<boolean>, Widen<boolean>] | (readonly [`0x${string}`, `0x${string}`, bigint, readonly bigint[], boolean, boolean] & readonly [...]) | undefined; ... 7 more ...; query?: StrictOmit...'.
account: projectOwnerAddress,
domain: projectId,
permissions: [V4OperatorPermission.QUEUE_RULESETS],
})

return JBTiered721DelegateProjectDeployerCanReconfigure
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
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 {
DEFAULT_MEMO,
NATIVE_TOKEN,
Expand All @@ -10,20 +6,13 @@ import {
import {
jbPricesAddress,
useJBContractContext,
useReadJb721TiersHookStoreTiersOf,
useWriteJb721TiersHookProjectDeployerLaunchProjectFor,
useWriteJb721TiersHookProjectDeployerLaunchProjectFor
} from 'juice-sdk-react'
import { isValidMustStartAtOrAfter } from 'packages/v2v3/utils/fundingCycle'
import {
JBDeploy721TiersHookConfig,
LaunchProjectWithNftsTxArgs,
} from 'packages/v4/models/nfts'
import { wagmiConfig } from 'packages/v4/wagmiConfig'
import { useContext } from 'react'
import { DEFAULT_MUST_START_AT_OR_AFTER } from 'redux/slices/shared/v2ProjectDefaultState'
import { ipfsUri } from 'utils/ipfs'
import { Address, WaitForTransactionReceiptReturnType, zeroAddress } from 'viem'
import { useChainId } from 'wagmi'
import {
LaunchV2V3ProjectArgs,
transformV2V3CreateArgsToV4,
Expand All @@ -34,6 +23,17 @@ import {
SUPPORTED_JB_MULTITERMINAL_ADDRESS,
} 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/shared/v2ProjectDefaultState'
import { ipfsUri } from 'utils/ipfs'
import { useChainId } from 'wagmi'

/**
* Return the project ID created from a `launchProjectFor` transaction.
* @param txReceipt receipt of `launchProjectFor` transaction
Expand Down Expand Up @@ -201,8 +201,6 @@ export function useLaunchProjectWithNftsTx() {
args,
})

type x = typeof useReadJb721TiersHookStoreTiersOf

onTransactionPendingCallback(hash)
addTransaction?.('Launch Project', { hash })
const transactionReceipt: WaitForTransactionReceiptReturnType =
Expand Down
11 changes: 11 additions & 0 deletions src/packages/v4/hooks/useHasNftRewards.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { useJBRulesetContext } from "juice-sdk-react"
import { zeroAddress } from "viem"

export function useHasNftRewards() {
const { rulesetMetadata: { data: _rulesetMetadata }} =
useJBRulesetContext()
return (
_rulesetMetadata?.dataHook &&
_rulesetMetadata.dataHook !== zeroAddress
)
}
Loading

0 comments on commit cbb870f

Please sign in to comment.