diff --git a/package.json b/package.json index cac1152577..5a43f03eec 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,9 @@ "prebuild": "yarn predev", "build": "NEXT_PUBLIC_VERSION=$(git rev-parse --short HEAD) next build", "analyze": "ANALYZE=true yarn build", + "abi:codegen": "node ./scripts/abi-codegen.js", "codegen-v1": "graphql-code-generator --config codegen.yml -r dotenv/config && node ./scripts/graphql-codegen-override-pv.js", - "codegen": "yarn codegen-v1 && yarn codegen-v4", + "codegen": "yarn codegen-v1 && yarn codegen-v4 && yarn abi:codegen", "codegen-v4": "graphql-code-generator --config src/packages/v4/graphql/codegen.yml -r dotenv/config", "css:compile": "lessc ./node_modules/antd/dist/antd.less ./src/styles/antd.css --js", "predev": "yarn css:compile && yarn i18n:compile && yarn codegen", diff --git a/scripts/abi-codegen.js b/scripts/abi-codegen.js new file mode 100644 index 0000000000..a48885b50f --- /dev/null +++ b/scripts/abi-codegen.js @@ -0,0 +1,377 @@ +/** + * A script to generate a selection of typescript files that contain the ABI and address of JB contracts. + * + * Behaviour differs slightly, depending on what contract we're importing. + * + * The idea is: instead asyncronously importing the JSON files at runtime, we bundle them into a TS file, and import that instead. + * + * There a multiple TS files generated. Again, behaviour differs slightly depending on the contract. + * + * This way: + * - we reduce the number of individual files that Next/webpack builds + * - we save on some total bundle size (the total TS files < the total JSON files) + * - src code is simpler to read and understand + * + * Code ain't great; heads up! + */ + +const fs = require('fs') + +const core = [ + 'JBDirectory', + 'JBProjects', + 'JBFundingCycleStore', + 'JBFundAccessConstraintsStore', + 'JBOperatorStore', + 'JBSplitsStore', + 'JBTokenStore', + 'JBSingleTokenPaymentTerminalStore', + 'JBSingleTokenPaymentTerminalStore3_1', + 'JBSingleTokenPaymentTerminalStore3_1_1', + 'JBETHERC20ProjectPayerDeployer', + 'JBController', + 'JBController3_1', + 'JBETHPaymentTerminal', + 'JBETHPaymentTerminal3_1', + 'JBETHPaymentTerminal3_1_1', + 'JBETHPaymentTerminal3_1_2', +] + +const coreV1 = [ + 'FundingCycles', + 'TerminalV1', + 'TerminalV1_1', + 'TerminalDirectory', + 'ModStore', + 'OperatorStore', + 'Projects', + 'TicketBooth', +] + +const juice721DelegateInterfaces = [ + 'JB721TieredGovernance', + 'IJBTiered721DelegateStore', + 'IJBTiered721Delegate', + 'IJBTiered721DelegateProjectDeployer', +] + +const V2_ADDRESS_OVERRIDES = { + JBETHERC20ProjectPayerDeployer: { + /** + * This deployment of the JBETHERC20ProjectPayerDeployer has slightly different + * internals to the one in the contracts-v2-latest package. + * + * It sets the beneficiary to tx.origin, instead of msg.sender. + * + * It was only deployed on mainnet, so we'll override it for mainnet only. + */ + addresses: { + mainnet: '0x325Ba0eFC2c750e0317561e79cFa6911e29B24CC', + }, + }, + JBOperatorStore: { + addresses: { + sepolia: '0x8f63c744c0280ef4b32af1f821c65e0fd4150ab3', + }, + }, + JBProjects: { + addresses: { + sepolia: '0x43CB8FCe4F0d61579044342A5d5A027aB7aE4D63', + }, + }, + JBDirectory: { + addresses: { + sepolia: '0x3B3Bd16cc76cd53218e00b600bFCa27aA5057794', + }, + }, + JBFundingCycleStore: { + addresses: { + sepolia: '0xCb881e166d527010B9eF11159b487f907040D7C4', + }, + }, + JBTokenStore: { + addresses: { + sepolia: '0x25fdda0eBD9e979b8c1657780045Cf87392a14E4', + }, + }, + JBSplitsStore: { + addresses: { + sepolia: '0xEdE89dB755855aF041b5f100B39db9324b5227Ac', + }, + }, + JBController: { + addresses: { + sepolia: '0x0c750ac5805AC3357b72554e3AE70840BBD09A98', + }, + }, + JBSingleTokenPaymentTerminalStore: { + addresses: { + sepolia: '0x981c8ECD009E3E84eE1fF99266BF1461a12e5c68', + }, + }, + JBETHPaymentTerminal: { + addresses: { + sepolia: '0x55FF1D8093166c1fF9664efd613D8C543b95feFc', + }, + }, +} + +const importV3Contract = (contract, network) => { + try { + const jsonData = require(`@jbx-protocol/juice-contracts-v3/deployments/${network}/${contract}.json`) + return { + address: jsonData.address, + abi: jsonData.abi, + } + } catch (e) { + return null + } +} + +const importV2Contract = (contract, network) => { + try { + // load the mainnet abi for v2. Sepolia addresses supplied in V2_ADDRESS_OVERRIDES + const jsonData = require(`@jbx-protocol/contracts-v2-latest/deployments/mainnet/${contract}.json`) + return { + address: + V2_ADDRESS_OVERRIDES[contract]?.addresses?.[network] ?? + jsonData.address, + abi: jsonData.abi, + } + } catch (e) { + return null + } +} + +const importV1Contract = (contract, network) => { + try { + const jsonData = require(`@jbx-protocol/contracts-v1/deployments/${network}/${contract}.json`) + return { + address: jsonData.address, + abi: jsonData.abi, + } + } catch (e) { + return null + } +} + +const importJuice721DelegateInterface = (interfaceName, version) => { + try { + const jsonData = require(`@jbx-protocol/juice-721-delegate-v${version}/out/${interfaceName}.sol/${interfaceName}.json`) + return { + abi: jsonData.abi, + } + } catch (e) { + return null + } +} + +const importJuice721DelegateDeployment = (version, chainId) => { + try { + const jsonData = require(`@jbx-protocol/juice-721-delegate-v${version}/broadcast/Deploy.s.sol/${chainId}/run-latest.json`) + return { + transactions: jsonData.transactions.map(t => { + return { + contractName: t.contractName, + contractAddress: t.contractAddress, + } + }), + } + } catch (e) { + return null + } +} + +const codegenJuice721DelegateInterfaces = version => { + return juice721DelegateInterfaces + .map(contract => ({ + name: contract, + contract: importJuice721DelegateInterface(contract, version), + })) + .map(({ name, contract }) => { + if (!contract) { + return null + } + + return `export const ${name} = { + address: undefined, + abi: ${JSON.stringify(contract.abi)} + } as const` + }) + .filter(Boolean) + .join('\n') +} + + +const codegenJuice721DelegateDeployment = (version) => { + // mainnnet, sepolia + return [1, 11155111] + .map(chainId => ({chainId, deployment: importJuice721DelegateDeployment(version, chainId)})) + .map((data) => { + if (!data?.deployment) { + return null + } + + return `export const chain${data.chainId} = ${JSON.stringify(data.deployment)} as const` + }) + .filter(Boolean) + .join('\n') +} + + +const codegenV1 = network => { + return coreV1 + .map(contract => ({ + name: contract, + contract: importV1Contract(contract, network), + })) + .map(({ name, contract }) => { + if (!contract) { + return null + } + + return `export const ${name} = { + address: '${contract.address}', + abi: ${JSON.stringify(contract.abi)} + } as const` + }) + .filter(Boolean) + .join('\n') +} + +const codegenV2 = network => { + return core + .map(contract => ({ + name: contract, + contract: importV2Contract(contract, network), + })) + .map(({ name, contract }) => { + if (!contract) { + return null + } + + return `export const ${name} = { + address: '${contract.address}', + abi: ${JSON.stringify(contract.abi)} + } as const` + }) + .filter(Boolean) + .join('\n') +} + +const codegenV3 = network => { + return core + .map(contract => ({ + name: contract, + contract: importV3Contract(contract, network), + })) + .map(({ name, contract }) => { + if (!contract) { + return null + } + + return `export const ${name} = { + address: '${contract.address}', + abi: ${JSON.stringify(contract.abi)} + } as const` + }) + .filter(Boolean) + .join('\n') +} + +// eslint-disable-next-line no-console +console.log('🧃 Generating Typescript files for contract deployment JSONs...') + +const mainnetV1 = codegenV1('mainnet') +const mainnetV2 = codegenV2('mainnet') +const sepoliaV2 = codegenV2('sepolia') +const mainnetV3 = codegenV3('mainnet') +const sepoliaV3 = codegenV3('sepolia') + +const juice721DelegateInterfacesV3 = codegenJuice721DelegateInterfaces('3') +const juice721DelegateInterfacesV3_1 = codegenJuice721DelegateInterfaces('3-1') +const juice721DelegateInterfacesV3_2 = codegenJuice721DelegateInterfaces('3-2') +const juice721DelegateInterfacesV3_3 = codegenJuice721DelegateInterfaces('3-3') +const juice721DelegateInterfacesV3_4 = codegenJuice721DelegateInterfaces('3-4') + +const juice721DelegateDeploymentV3 = codegenJuice721DelegateDeployment('3') +const juice721DelegateDeploymentV3_1 = codegenJuice721DelegateDeployment('3-1') +const juice721DelegateDeploymentV3_2 = codegenJuice721DelegateDeployment('3-2') +const juice721DelegateDeploymentV3_3 = codegenJuice721DelegateDeployment('3-3') +const juice721DelegateDeploymentV3_4 = codegenJuice721DelegateDeployment('3-4') + +fs.writeFileSync( + 'src/packages/v1/contexts/User/juice-contracts-v1-mainnet.ts', + mainnetV1, +) + +fs.writeFileSync( + 'src/packages/v2v3/utils/contractLoaders/contracts/juice-contracts-v2-mainnet.ts', + mainnetV2, +) +fs.writeFileSync( + 'src/packages/v2v3/utils/contractLoaders/contracts/juice-contracts-v2-sepolia.ts', + sepoliaV2, +) + +fs.writeFileSync( + 'src/packages/v2v3/utils/contractLoaders/contracts/juice-contracts-v3-mainnet.ts', + mainnetV3, +) +fs.writeFileSync( + 'src/packages/v2v3/utils/contractLoaders/contracts/juice-contracts-v3-sepolia.ts', + sepoliaV3, +) + +fs.writeFileSync( + 'src/packages/v2v3/hooks/JB721Delegate/contracts/interfaceAbis/juice-721-delegate-interfaces-v3.ts', + juice721DelegateInterfacesV3, +) +fs.writeFileSync( + 'src/packages/v2v3/hooks/JB721Delegate/contracts/interfaceAbis/juice-721-delegate-interfaces-v3-1.ts', + juice721DelegateInterfacesV3_1, +) +fs.writeFileSync( + 'src/packages/v2v3/hooks/JB721Delegate/contracts/interfaceAbis/juice-721-delegate-interfaces-v3-2.ts', + juice721DelegateInterfacesV3_2, +) +fs.writeFileSync( + 'src/packages/v2v3/hooks/JB721Delegate/contracts/interfaceAbis/juice-721-delegate-interfaces-v3-3.ts', + juice721DelegateInterfacesV3_3, +) +fs.writeFileSync( + 'src/packages/v2v3/hooks/JB721Delegate/contracts/interfaceAbis/juice-721-delegate-interfaces-v3-4.ts', + juice721DelegateInterfacesV3_4, +) + +fs.writeFileSync( + 'src/packages/v2v3/hooks/JB721Delegate/contracts/interfaceAbis/juice-721-delegate-interfaces-v3.ts', + juice721DelegateInterfacesV3, +) + +fs.writeFileSync( + 'src/packages/v2v3/hooks/JB721Delegate/contracts/deployments/juice-721-delegate-deployment-v3.ts', + juice721DelegateDeploymentV3, +) + +fs.writeFileSync( + 'src/packages/v2v3/hooks/JB721Delegate/contracts/deployments/juice-721-delegate-deployment-v3-1.ts', + juice721DelegateDeploymentV3_1, +) +fs.writeFileSync( + 'src/packages/v2v3/hooks/JB721Delegate/contracts/deployments/juice-721-delegate-deployment-v3-2.ts', + juice721DelegateDeploymentV3_2, +) +fs.writeFileSync( + 'src/packages/v2v3/hooks/JB721Delegate/contracts/deployments/juice-721-delegate-deployment-v3-3.ts', + juice721DelegateDeploymentV3_3, +) +fs.writeFileSync( + 'src/packages/v2v3/hooks/JB721Delegate/contracts/deployments/juice-721-delegate-deployment-v3-4.ts', + juice721DelegateDeploymentV3_4, +) + + + +// eslint-disable-next-line no-console +console.log('🧃 Done') diff --git a/src/hooks/ENS/useRegistry.ts b/src/hooks/ENS/useRegistry.ts deleted file mode 100644 index 800cb3d383..0000000000 --- a/src/hooks/ENS/useRegistry.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { readNetwork } from 'constants/networks' -import { ContractInterface } from 'ethers' -import { useLoadContractFromAddress } from 'hooks/useLoadContractFromAddress' -import { ContractJson } from 'models/contracts' -import { NetworkName } from 'models/networkName' -import { useEffect, useState } from 'react' - -async function loadENSRegistryContract(): Promise { - const { name } = readNetwork - - if ( - name === NetworkName.mainnet || - name === NetworkName.sepolia - ) { - // Registry address is the same for both mainnet + sepolia - return await import('hooks/ENS/contracts/ENSRegistry.json') - } -} - -export function useENSRegistry() { - const [abi, setAbi] = useState(undefined) - const [address, setAddress] = useState(undefined) - - useEffect(() => { - async function load() { - const json = await loadENSRegistryContract() - setAbi(json?.abi) - setAddress(json?.address) - } - load() - }, []) - - return useLoadContractFromAddress({ address, abi }) -} diff --git a/src/hooks/ENS/useResolver.ts b/src/hooks/ENS/useResolver.ts deleted file mode 100644 index 2a4dce933d..0000000000 --- a/src/hooks/ENS/useResolver.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { ContractInterface } from 'ethers' -import { useLoadContractFromAddress } from 'hooks/useLoadContractFromAddress' -import { ContractJson } from 'models/contracts' -import { useEffect, useState } from 'react' - -async function loadPublicResolverContractAbi(): Promise< - Omit | undefined -> { - return await import('hooks/ENS/contracts/PublicResolverAbi.json') -} - -export function useResolver(address: string | undefined) { - const [abi, setAbi] = useState(undefined) - - useEffect(() => { - async function load() { - const json = await loadPublicResolverContractAbi() - setAbi(json?.abi) - } - load() - }, []) - - return useLoadContractFromAddress({ address, abi }) -} diff --git a/src/packages/v1/contexts/User/.gitignore b/src/packages/v1/contexts/User/.gitignore new file mode 100644 index 0000000000..cff3b7d11d --- /dev/null +++ b/src/packages/v1/contexts/User/.gitignore @@ -0,0 +1 @@ +juice-contracts-v1-mainnet.ts \ No newline at end of file diff --git a/src/packages/v1/contexts/User/useV1ContractLoader.ts b/src/packages/v1/contexts/User/useV1ContractLoader.ts index 8882059e90..cb81cfc2a9 100644 --- a/src/packages/v1/contexts/User/useV1ContractLoader.ts +++ b/src/packages/v1/contexts/User/useV1ContractLoader.ts @@ -6,59 +6,16 @@ import { NetworkName } from 'models/networkName' import { SignerOrProvider } from 'models/signerOrProvider' import { V1ContractName, V1Contracts } from 'packages/v1/models/contracts' import { useEffect, useState } from 'react' +import * as mainnet from './juice-contracts-v1-mainnet' const loadV1Contract = async ( contractName: V1ContractName, network: NetworkName, signerOrProvider: SignerOrProvider, ): Promise => { - let contract: Contract | undefined - - if (network === NetworkName.sepolia) return - - switch (contractName) { - case V1ContractName.FundingCycles: - contract = await import( - `@jbx-protocol/contracts-v1/deployments/${network}/FundingCycles.json` - ) - break - case V1ContractName.TerminalV1: - contract = await import( - `@jbx-protocol/contracts-v1/deployments/${network}/TerminalV1.json` - ) - break - case V1ContractName.TerminalV1_1: - contract = await import( - `@jbx-protocol/contracts-v1/deployments/${network}/TerminalV1_1.json` - ) - break - case V1ContractName.TerminalDirectory: - contract = await import( - `@jbx-protocol/contracts-v1/deployments/${network}/TerminalDirectory.json` - ) - break - case V1ContractName.ModStore: - contract = await import( - `@jbx-protocol/contracts-v1/deployments/${network}/ModStore.json` - ) - break - case V1ContractName.OperatorStore: - contract = await import( - `@jbx-protocol/contracts-v1/deployments/${network}/OperatorStore.json` - ) - break - case V1ContractName.Projects: - contract = await import( - `@jbx-protocol/contracts-v1/deployments/${network}/Projects.json` - ) - break - case V1ContractName.TicketBooth: - contract = await import( - `@jbx-protocol/contracts-v1/deployments/${network}/TicketBooth.json` - ) - break - } + if (network !== NetworkName.mainnet) return + const contract = mainnet[contractName] if (!contract) return return new Contract(contract.address, contract.abi, signerOrProvider) diff --git a/src/packages/v2v3/hooks/JB721Delegate/contracts/deployments/.gitignore b/src/packages/v2v3/hooks/JB721Delegate/contracts/deployments/.gitignore new file mode 100644 index 0000000000..b0a155ec1b --- /dev/null +++ b/src/packages/v2v3/hooks/JB721Delegate/contracts/deployments/.gitignore @@ -0,0 +1 @@ +*.ts \ No newline at end of file diff --git a/src/packages/v2v3/hooks/JB721Delegate/contracts/interfaceAbis/.gitignore b/src/packages/v2v3/hooks/JB721Delegate/contracts/interfaceAbis/.gitignore new file mode 100644 index 0000000000..b0a155ec1b --- /dev/null +++ b/src/packages/v2v3/hooks/JB721Delegate/contracts/interfaceAbis/.gitignore @@ -0,0 +1 @@ +*.ts \ No newline at end of file diff --git a/src/packages/v2v3/hooks/JB721Delegate/contracts/useJB721DelegateAbi.ts b/src/packages/v2v3/hooks/JB721Delegate/contracts/useJB721DelegateAbi.ts index b8fe9e5f3d..e6215a2a7d 100644 --- a/src/packages/v2v3/hooks/JB721Delegate/contracts/useJB721DelegateAbi.ts +++ b/src/packages/v2v3/hooks/JB721Delegate/contracts/useJB721DelegateAbi.ts @@ -15,30 +15,20 @@ export async function loadJB721DelegateJson( ): Promise { console.info('Loading JB721Delegate contract json', version, contractName) - // NOTE: imports are specified explicitly to avoid Webpack causing V8 to run out of memory and crash during compilation. - if (contractName === 'JB721TieredGovernance') { - return await import( - `@jbx-protocol/juice-721-delegate-v${version}/out/JB721TieredGovernance.sol/JB721TieredGovernance.json` - ) - } - - if (contractName === 'IJBTiered721DelegateStore') { - return await import( - `@jbx-protocol/juice-721-delegate-v${version}/out/IJBTiered721DelegateStore.sol/IJBTiered721DelegateStore.json` - ) - } - - if (contractName === 'IJBTiered721Delegate') { - return await import( - `@jbx-protocol/juice-721-delegate-v${version}/out/IJBTiered721Delegate.sol/IJBTiered721Delegate.json` - ) - } - - if (contractName === 'IJBTiered721DelegateProjectDeployer') { - return await import( - `@jbx-protocol/juice-721-delegate-v${version}/out/IJBTiered721DelegateProjectDeployer.sol/IJBTiered721DelegateProjectDeployer.json` - ) - } + const contractSet = + version === '3' + ? await import('./interfaceAbis/juice-721-delegate-interfaces-v3') + : version === '3-1' + ? await import('./interfaceAbis/juice-721-delegate-interfaces-v3-1') + : version === '3-2' + ? await import('./interfaceAbis/juice-721-delegate-interfaces-v3-2') + : version === '3-3' + ? await import('./interfaceAbis/juice-721-delegate-interfaces-v3-3') + : version === '3-4' + ? await import('./interfaceAbis/juice-721-delegate-interfaces-v3-4') + : undefined + + return contractSet?.[contractName] } export function useJB721DelegateAbi( diff --git a/src/packages/v2v3/hooks/JB721Delegate/contracts/useJB721DelegateContractAddress.ts b/src/packages/v2v3/hooks/JB721Delegate/contracts/useJB721DelegateContractAddress.ts index d883ebe226..7d70c88f0a 100644 --- a/src/packages/v2v3/hooks/JB721Delegate/contracts/useJB721DelegateContractAddress.ts +++ b/src/packages/v2v3/hooks/JB721Delegate/contracts/useJB721DelegateContractAddress.ts @@ -29,9 +29,9 @@ const ADDRESSES: { } async function loadJB721DelegateDeployment(version: JB721DelegateVersion) { - return (await import( - `@jbx-protocol/juice-721-delegate-v${version}/broadcast/Deploy.s.sol/${readNetwork.chainId}/run-latest.json` - )) as ForgeDeploy + return ( + await import(`./deployments/juice-721-delegate-deployment-v${version}`) + )[readNetwork.chainId] as ForgeDeploy } export async function loadJB721DelegateAddress( @@ -40,7 +40,9 @@ export async function loadJB721DelegateAddress( ) { const hardcodedAddress = ADDRESSES[version]?.[readNetwork.name]?.[contractName] - if (hardcodedAddress) return hardcodedAddress + if (hardcodedAddress) { + return hardcodedAddress + } const forgeGeployment = await loadJB721DelegateDeployment(version) const forgeAddress = addressFor(contractName, forgeGeployment) diff --git a/src/packages/v2v3/hooks/useENSResolver.ts b/src/packages/v2v3/hooks/useENSResolver.ts index 39b4be41d5..460efe0a9c 100644 --- a/src/packages/v2v3/hooks/useENSResolver.ts +++ b/src/packages/v2v3/hooks/useENSResolver.ts @@ -1,6 +1,7 @@ import { namehash } from 'ethers/lib/utils' -import { useENSRegistry } from 'hooks/ENS/useRegistry' -import { useResolver } from 'hooks/ENS/useResolver' +import ENSRegistryData from 'hooks/ENS/contracts/ENSRegistry.json' +import ENSResolverData from 'hooks/ENS/contracts/PublicResolverAbi.json' +import { useLoadContractFromAddress } from 'hooks/useLoadContractFromAddress' import useV2ContractReader from './contractReader/useV2ContractReader' /** @@ -9,17 +10,24 @@ import useV2ContractReader from './contractReader/useV2ContractReader' * @returns ENS Resolver contract */ export function useResolverForENS(ensName: string | undefined) { - const ENSRegistry = useENSRegistry() - const node = ensName ? namehash(ensName + (ensName.endsWith('.eth') ? '' : '.eth')) : undefined + // Registry address is the same for both mainnet + sepolia + const ENSRegistry = useLoadContractFromAddress({ + address: ENSRegistryData.address, + abi: ENSRegistryData.abi, + }) + const { data: resolverAddress } = useV2ContractReader({ contract: ENSRegistry, functionName: 'resolver', args: node ? [node] : null, }) - return useResolver(resolverAddress) + return useLoadContractFromAddress({ + address: resolverAddress, + abi: ENSResolverData.abi, + }) } diff --git a/src/packages/v2v3/utils/contractLoaders/JuiceboxV2.ts b/src/packages/v2v3/utils/contractLoaders/JuiceboxV2.ts index f4dff22707..068bc831b7 100644 --- a/src/packages/v2v3/utils/contractLoaders/JuiceboxV2.ts +++ b/src/packages/v2v3/utils/contractLoaders/JuiceboxV2.ts @@ -2,163 +2,19 @@ import { ContractJson } from 'models/contracts' import { NetworkName } from 'models/networkName' import { V2V3ContractName } from 'packages/v2v3/models/contracts' -/** - * Defines the ABI filename to use for a given V2V3ContractName. - */ -const V2_CONTRACT_ABI_OVERRIDES: { - [k in V2V3ContractName]?: { - addresses?: { - [k in NetworkName]?: string - } - } -} = { - JBETHERC20ProjectPayerDeployer: { - /** - * This deployment of the JBETHERC20ProjectPayerDeployer has slightly different - * internals to the one in the contracts-v2-latest package. - * - * It sets the beneficiary to tx.origin, instead of msg.sender. - * - * It was only deployed on mainnet, so we'll override it for mainnet only. - */ - addresses: { - [NetworkName.mainnet]: '0x325Ba0eFC2c750e0317561e79cFa6911e29B24CC', - }, - }, - JBOperatorStore: { - addresses: { - [NetworkName.sepolia]: '0x8f63c744c0280ef4b32af1f821c65e0fd4150ab3', - }, - }, - JBProjects: { - addresses: { - [NetworkName.sepolia]: '0x43CB8FCe4F0d61579044342A5d5A027aB7aE4D63', - }, - }, - JBDirectory: { - addresses: { - [NetworkName.sepolia]: '0x3B3Bd16cc76cd53218e00b600bFCa27aA5057794', - }, - }, - JBFundingCycleStore: { - addresses: { - [NetworkName.sepolia]: '0xCb881e166d527010B9eF11159b487f907040D7C4', - }, - }, - JBTokenStore: { - addresses: { - [NetworkName.sepolia]: '0x25fdda0eBD9e979b8c1657780045Cf87392a14E4', - }, - }, - JBSplitsStore: { - addresses: { - [NetworkName.sepolia]: '0xEdE89dB755855aF041b5f100B39db9324b5227Ac', - }, - }, - JBController: { - addresses: { - [NetworkName.sepolia]: '0x0c750ac5805AC3357b72554e3AE70840BBD09A98', - }, - }, - JBSingleTokenPaymentTerminalStore: { - addresses: { - [NetworkName.sepolia]: '0x981c8ECD009E3E84eE1fF99266BF1461a12e5c68', - }, - }, - JBETHPaymentTerminal: { - addresses: { - [NetworkName.sepolia]: '0x55FF1D8093166c1fF9664efd613D8C543b95feFc', - }, - }, -} - -/** - * Note: the v2 contracts npm package doesn't contain the goerli deployment. - * So, we just assume mainnet abi's are the same on goerli and mainnet, and import - * the mainnet ones. - * - */ export const loadJuiceboxV2Contract = async ( contractName: V2V3ContractName, network: NetworkName, ): Promise => { - const contractOverride = V2_CONTRACT_ABI_OVERRIDES[contractName] + const contractSet = + network === 'sepolia' + ? await import('./contracts/juice-contracts-v2-sepolia') + : await import('./contracts/juice-contracts-v2-mainnet') try { - let contractJson: ContractJson | undefined - switch (contractName) { - case V2V3ContractName.JBController: { - contractJson = (await import( - `@jbx-protocol/contracts-v2-latest/deployments/mainnet/JBController.json` - )) as ContractJson - break - } - case V2V3ContractName.JBDirectory: { - contractJson = (await import( - `@jbx-protocol/contracts-v2-latest/deployments/mainnet/JBDirectory.json` - )) as ContractJson - break - } - case V2V3ContractName.JBETHPaymentTerminal: { - contractJson = (await import( - `@jbx-protocol/contracts-v2-latest/deployments/mainnet/JBETHPaymentTerminal.json` - )) as ContractJson - break - } - case V2V3ContractName.JBFundingCycleStore: { - contractJson = (await import( - `@jbx-protocol/contracts-v2-latest/deployments/mainnet/JBFundingCycleStore.json` - )) as ContractJson - break - } - case V2V3ContractName.JBOperatorStore: { - contractJson = (await import( - `@jbx-protocol/contracts-v2-latest/deployments/mainnet/JBOperatorStore.json` - )) as ContractJson - break - } - case V2V3ContractName.JBProjects: { - contractJson = (await import( - `@jbx-protocol/contracts-v2-latest/deployments/mainnet/JBProjects.json` - )) as ContractJson - break - } - case V2V3ContractName.JBSplitsStore: { - contractJson = (await import( - `@jbx-protocol/contracts-v2-latest/deployments/mainnet/JBSplitsStore.json` - )) as ContractJson - break - } - case V2V3ContractName.JBTokenStore: { - contractJson = (await import( - `@jbx-protocol/contracts-v2-latest/deployments/mainnet/JBTokenStore.json` - )) as ContractJson - break - } - case V2V3ContractName.JBSingleTokenPaymentTerminalStore: { - contractJson = (await import( - `@jbx-protocol/contracts-v2-latest/deployments/mainnet/JBSingleTokenPaymentTerminalStore.json` - )) as ContractJson - break - } - case V2V3ContractName.JBETHERC20ProjectPayerDeployer: { - contractJson = (await import( - `@jbx-protocol/contracts-v2-latest/deployments/mainnet/JBETHERC20ProjectPayerDeployer.json` - )) as ContractJson - break - } - } - - if (!contractJson) return - - const address = - contractOverride?.addresses?.[network] ?? contractJson.address - - return { - ...contractJson, - address, - } - } catch (e) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return (contractSet as any)[contractName] as ContractJson + } catch { return undefined } } diff --git a/src/packages/v2v3/utils/contractLoaders/JuiceboxV3.ts b/src/packages/v2v3/utils/contractLoaders/JuiceboxV3.ts index 6640a9b47c..f818cbc158 100644 --- a/src/packages/v2v3/utils/contractLoaders/JuiceboxV3.ts +++ b/src/packages/v2v3/utils/contractLoaders/JuiceboxV3.ts @@ -6,115 +6,15 @@ export const loadJuiceboxV3Contract = async ( contractName: V2V3ContractName, network: NetworkName, ): Promise => { - try { - let contractJson: ContractJson | undefined - switch (contractName) { - case V2V3ContractName.JBController: { - contractJson = (await import( - `@jbx-protocol/juice-contracts-v3/deployments/${network}/JBController.json` - )) as ContractJson - break - } - case V2V3ContractName.JBController3_1: { - contractJson = (await import( - `@jbx-protocol/juice-contracts-v3/deployments/${network}/JBController3_1.json` - )) as ContractJson - break - } - case V2V3ContractName.JBDirectory: { - contractJson = (await import( - `@jbx-protocol/juice-contracts-v3/deployments/${network}/JBDirectory.json` - )) as ContractJson - break - } - case V2V3ContractName.JBETHPaymentTerminal: { - contractJson = (await import( - `@jbx-protocol/juice-contracts-v3/deployments/${network}/JBETHPaymentTerminal.json` - )) as ContractJson - break - } - case V2V3ContractName.JBETHPaymentTerminal3_1: { - contractJson = (await import( - `@jbx-protocol/juice-contracts-v3/deployments/${network}/JBETHPaymentTerminal3_1.json` - )) as ContractJson - break - } - case V2V3ContractName.JBETHPaymentTerminal3_1_1: { - contractJson = (await import( - `@jbx-protocol/juice-contracts-v3/deployments/${network}/JBETHPaymentTerminal3_1_1.json` - )) as ContractJson - break - } - case V2V3ContractName.JBETHPaymentTerminal3_1_2: { - contractJson = (await import( - `@jbx-protocol/juice-contracts-v3/deployments/${network}/JBETHPaymentTerminal3_1_2.json` - )) as ContractJson - break - } - case V2V3ContractName.JBFundingCycleStore: { - contractJson = (await import( - `@jbx-protocol/juice-contracts-v3/deployments/${network}/JBFundingCycleStore.json` - )) as ContractJson - break - } - case V2V3ContractName.JBFundAccessConstraintsStore: { - contractJson = (await import( - `@jbx-protocol/juice-contracts-v3/deployments/${network}/JBFundAccessConstraintsStore.json` - )) as ContractJson - break - } - case V2V3ContractName.JBOperatorStore: { - contractJson = (await import( - `@jbx-protocol/juice-contracts-v3/deployments/${network}/JBOperatorStore.json` - )) as ContractJson - break - } - case V2V3ContractName.JBProjects: { - contractJson = (await import( - `@jbx-protocol/juice-contracts-v3/deployments/${network}/JBProjects.json` - )) as ContractJson - break - } - case V2V3ContractName.JBSplitsStore: { - contractJson = (await import( - `@jbx-protocol/juice-contracts-v3/deployments/${network}/JBSplitsStore.json` - )) as ContractJson - break - } - case V2V3ContractName.JBTokenStore: { - contractJson = (await import( - `@jbx-protocol/juice-contracts-v3/deployments/${network}/JBTokenStore.json` - )) as ContractJson - break - } - case V2V3ContractName.JBSingleTokenPaymentTerminalStore: { - contractJson = (await import( - `@jbx-protocol/juice-contracts-v3/deployments/${network}/JBSingleTokenPaymentTerminalStore.json` - )) as ContractJson - break - } - case V2V3ContractName.JBSingleTokenPaymentTerminalStore3_1: { - contractJson = (await import( - `@jbx-protocol/juice-contracts-v3/deployments/${network}/JBSingleTokenPaymentTerminalStore3_1.json` - )) as ContractJson - break - } - case V2V3ContractName.JBSingleTokenPaymentTerminalStore3_1_1: { - contractJson = (await import( - `@jbx-protocol/juice-contracts-v3/deployments/${network}/JBSingleTokenPaymentTerminalStore3_1_1.json` - )) as ContractJson - break - } - case V2V3ContractName.JBETHERC20ProjectPayerDeployer: { - contractJson = (await import( - `@jbx-protocol/juice-contracts-v3/deployments/${network}/JBETHERC20ProjectPayerDeployer.json` - )) as ContractJson - break - } - } + const contractSet = + network === 'sepolia' + ? await import('./contracts/juice-contracts-v3-sepolia') + : await import('./contracts/juice-contracts-v3-mainnet') - return contractJson - } catch (_) { + try { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return (contractSet as any)[contractName] as ContractJson + } catch { return undefined } } diff --git a/src/packages/v2v3/utils/contractLoaders/contracts/.gitignore b/src/packages/v2v3/utils/contractLoaders/contracts/.gitignore new file mode 100644 index 0000000000..b0a155ec1b --- /dev/null +++ b/src/packages/v2v3/utils/contractLoaders/contracts/.gitignore @@ -0,0 +1 @@ +*.ts \ No newline at end of file