Skip to content

Commit

Permalink
New protocol-deployments package - separate versioning of contracts…
Browse files Browse the repository at this point in the history
… from publishing deployment updates (#305)

Created new package `protocol-deployments`

* deployment scripts for 1155 contracts have been moved from `1155-contracts` to this new package
* deployed 1155 contract addresses have been moved from `1155-contracts` to this new package.

Problem this solves:
* every time we deployed a contract and want to to publish the changes in a package we had to bump the contract version, since we require the package version to match the contract version.

With this change, we can version the contracts independently from the deployed addresses.

You can see this in action in the upstream branch "Deploy zora sepolia" where we deployed the contracts to the new Zora Sepolia chain, and just bumped the `protocol-deployments` version without needing to bump the `1155-contracts` version.

* The `1155-contracts` wagmi generator now just generates abis to bundle in the package json.
* The `protocol-deployments` wagmi generator imports the abis from `1155-contracts` and bundles them with the deployed addresses.
* `premint-sdk` imports from `protocol-deployments` to get contract abis and addresses from it
  • Loading branch information
oveddan authored Nov 1, 2023
1 parent d789935 commit b62e471
Show file tree
Hide file tree
Showing 71 changed files with 427 additions and 319 deletions.
9 changes: 9 additions & 0 deletions .changeset/lazy-experts-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@zoralabs/protocol-deployments": patch
"@zoralabs/premint-sdk": patch
---

created new package `protocol-deployments` that includes the deployed contract addresses.

* 1155-contracts js no longer exports deployed addresses, just the abis
* premint-sdk imports deployed addresses from `protocol-deployments
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ abis/
# /broadcast/**/dry-run/

# Remove broadcast logs
/broadcast/
**/*/broadcast

# Docs
docs/
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ In it you will find:

- [Zora 1155 Contracts](./packages/1155-contracts)
- [Protocol Rewards](./packages/protocol-rewards)
- [Procotol Deployments](./packages/protocol-deployments)

## Official docs

Expand Down
17 changes: 4 additions & 13 deletions packages/1155-contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,17 @@
"test-gas": "forge test --gas-report",
"prettier:check": "prettier --check 'src/**/*.sol' 'test/**/*.sol' 'package/**/*.ts' 'wagmi.config.ts'",
"prettier": "prettier --write 'src/**/*.sol' 'test/**/*.sol' 'package/**/*.ts' 'script/**/*.ts' 'wagmi.config.ts'",
"copy-abis": "tsx script/bundle-abis.ts",
"lint": "yarn run prettier:check",
"coverage": "forge coverage --report lcov",
"write-gas-report": "forge test --gas-report > gasreport.ansi",
"copy-abis": "tsx script/bundle-abis.ts",
"update-new-deployment-addresses": "node script/copy-deployed-contracts.mjs deploy",
"update-contract-version": "node script/update-contract-version.mjs",
"build:contracts": "forge build",
"build": "yarn wagmi && yarn copy-abis && yarn bundle-configs && tsup",
"build:sizes": "forge build --sizes",
"bundle-configs": "node script/bundle-chainConfigs.mjs && yarn prettier",
"build": "yarn wagmi && yarn copy-abis && tsup",
"wagmi": "FOUNDRY_PROFILE=dev forge build && wagmi generate",
"build:sizes": "forge build --sizes",
"storage-inspect:check": "./script/storage-check.sh check ZoraCreator1155Impl ZoraCreator1155FactoryImpl",
"storage-inspect:generate": "./script/storage-check.sh generate ZoraCreator1155Impl ZoraCreator1155FactoryImpl",
"js-test:watch": "vitest dev",
"anvil": "source .env.anvil && anvil --fork-url $FORK_RPC_URL --fork-block-number $FORK_BLOCK_NUMBER --chain-id 31337",
"unlink-contracts": "rm -rf ./node_modules/@zoralabs/protocol-rewards && cp -r ../protocol-rewards ./node_modules/@zoralabs/protocol-rewards",
"link-contracts": "rm -rf ./node_modules && cd .. && yarn"
"update-contract-version": "node script/update-contract-version.mjs"
},
"files": [
"dist/",
Expand All @@ -57,10 +51,7 @@
"glob": "^10.2.2",
"prettier": "^2.8.8",
"es-main": "^1.2.0",
"@turnkey/api-key-stamper": "^0.1.1",
"prettier-plugin-solidity": "^1.1.3",
"@turnkey/http": "^1.2.0",
"@turnkey/viem": "^0.2.4",
"@types/node": "^20.1.2",
"tsup": "^7.2.0",
"typescript": "^5.0.4"
Expand Down
1 change: 0 additions & 1 deletion packages/1155-contracts/package/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
// built at build time. They are not checked in to git.
// The can be generated by running `yarn prepack` in the root
export * from "./wagmiGenerated";
export { chainConfigs } from "./chainConfigs";
27 changes: 0 additions & 27 deletions packages/1155-contracts/script/DeployUpgradeGate.s.sol

This file was deleted.

67 changes: 0 additions & 67 deletions packages/1155-contracts/script/TestCreateDeterministic.sol

This file was deleted.

43 changes: 0 additions & 43 deletions packages/1155-contracts/script/TestUpgrade.s.sol

This file was deleted.

2 changes: 1 addition & 1 deletion packages/1155-contracts/script/storage-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ generate() {
for contract in ${contracts[@]}
do
{ echo -e "\n======================="; echo "$contract" ; echo -e "=======================\n"; } >> "$file"
forge inspect --pretty "$contract" storage-layout >> "$file"
FOUNDRY_PROFILE=dev forge inspect --pretty "$contract" storage-layout >> "$file"
done
if [[ $func == "generate" ]]; then
echo "Storage layout snapshot stored at $file"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ pragma solidity ^0.8.13;
import "forge-std/Script.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";

import {IZoraCreator1155Factory} from "../src/interfaces/IZoraCreator1155Factory.sol";
import {ZoraCreator1155Impl} from "../src/nft/ZoraCreator1155Impl.sol";
import {Zora1155Factory} from "../src/proxies/Zora1155Factory.sol";
import {ICreatorRoyaltiesControl} from "../src/interfaces/ICreatorRoyaltiesControl.sol";
import {ScriptDeploymentConfig, Deployment, ChainConfig} from "../src/deployment/DeploymentConfig.sol";
import {ZoraDeployerUtils} from "../src/deployment/ZoraDeployerUtils.sol";
import {IMinter1155} from "../src/interfaces/IMinter1155.sol";
import {DeterministicDeployerScript} from "../src/deployment/DeterministicDeployerScript.sol";
import {ZoraCreator1155FactoryImpl} from "../src/factory/ZoraCreator1155FactoryImpl.sol";
import {IZoraCreator1155Factory} from "../interfaces/IZoraCreator1155Factory.sol";
import {ZoraCreator1155Impl} from "../nft/ZoraCreator1155Impl.sol";
import {Zora1155Factory} from "../proxies/Zora1155Factory.sol";
import {ICreatorRoyaltiesControl} from "../interfaces/ICreatorRoyaltiesControl.sol";
import {ScriptDeploymentConfig, Deployment, ChainConfig} from "../deployment/DeploymentConfig.sol";
import {ZoraDeployerUtils} from "../deployment/ZoraDeployerUtils.sol";
import {IMinter1155} from "../interfaces/IMinter1155.sol";
import {DeterministicDeployerScript} from "../deployment/DeterministicDeployerScript.sol";
import {ZoraCreator1155FactoryImpl} from "../factory/ZoraCreator1155FactoryImpl.sol";

/// @notice Deployment drops for base where
abstract contract ZoraDeployerBase is ScriptDeploymentConfig, DeterministicDeployerScript {
Expand Down
116 changes: 11 additions & 105 deletions packages/1155-contracts/wagmi.config.ts
Original file line number Diff line number Diff line change
@@ -1,118 +1,24 @@
import { defineConfig } from "@wagmi/cli";
import { foundry } from "@wagmi/cli/plugins";
import { readdirSync, readFileSync } from "fs";
import { publishAbisJson } from "./publishAbisPlugin";

type ContractNames =
| "ZoraCreator1155FactoryImpl"
| "ZoraCreator1155Impl"
| "ZoraCreatorFixedPriceSaleStrategy"
| "ZoraCreatorMerkleMinterStrategy"
| "ZoraCreatorRedeemMinterFactory"
| "ZoraCreatorRedeemMinterStrategy"
| "ZoraCreator1155PremintExecutorImpl"
| "DeterministicProxyDeployer"
| "IImmutableCreate2Factory";

type Address = `0x${string}`;

const contractFilesToInclude: ContractNames[] = [
"ZoraCreator1155FactoryImpl",
"ZoraCreator1155Impl",
"ZoraCreatorFixedPriceSaleStrategy",
"ZoraCreatorMerkleMinterStrategy",
"ZoraCreatorRedeemMinterFactory",
"ZoraCreatorRedeemMinterStrategy",
"ZoraCreator1155PremintExecutorImpl",
"DeterministicProxyDeployer",
"IImmutableCreate2Factory",
];

type Addresses = {
[key in ContractNames]?: {
[chainId: number]: Address;
};
};

const getAddresses = () => {
const addresses: Addresses = {};

const addressesFiles = readdirSync("./addresses");

const addAddress = (
contractName: ContractNames,
chainId: number,
address?: Address
) => {
if (!address) return;
if (!addresses[contractName]) {
addresses[contractName] = {};
}

addresses[contractName]![chainId] = address;
};

for (const addressesFile of addressesFiles) {
const jsonAddress = JSON.parse(
readFileSync(`./addresses/${addressesFile}`, "utf-8")
) as {
FIXED_PRICE_SALE_STRATEGY: Address;
MERKLE_MINT_SALE_STRATEGY: Address;
REDEEM_MINTER_FACTORY: Address;
"1155_IMPL": Address;
FACTORY_IMPL: Address;
FACTORY_PROXY: Address;
PREMINTER_PROXY?: Address;
};

const chainId = parseInt(addressesFile.split(".")[0]);

addAddress(
"ZoraCreatorFixedPriceSaleStrategy",
chainId,
jsonAddress.FIXED_PRICE_SALE_STRATEGY
);
addAddress(
"ZoraCreatorMerkleMinterStrategy",
chainId,
jsonAddress.MERKLE_MINT_SALE_STRATEGY
);
addAddress(
"ZoraCreator1155FactoryImpl",
chainId,
jsonAddress.FACTORY_PROXY
);
addAddress(
"ZoraCreatorRedeemMinterFactory",
chainId,
jsonAddress.REDEEM_MINTER_FACTORY
);
addAddress(
"ZoraCreator1155PremintExecutorImpl",
chainId,
jsonAddress.PREMINTER_PROXY
),
addAddress(
"IImmutableCreate2Factory",
chainId,
"0x0000000000FFe8B47B3e2130213B802212439497"
);
}

return addresses;
};

export default defineConfig({
out: "package/wagmiGenerated.ts",
plugins: [
foundry({
deployments: getAddresses(),
forge: {
build: false,
},
include: contractFilesToInclude.map(
(contractName) => `${contractName}.json`
),
include: [
"ZoraCreator1155FactoryImpl",
"ZoraCreator1155Impl",
"ZoraCreatorFixedPriceSaleStrategy",
"ZoraCreatorMerkleMinterStrategy",
"ZoraCreatorRedeemMinterFactory",
"ZoraCreatorRedeemMinterStrategy",
"ZoraCreator1155PremintExecutorImpl",
"DeterministicProxyDeployer",
"IImmutableCreate2Factory",
].map((contractName) => `${contractName}.json`),
}),
],
});
5 changes: 2 additions & 3 deletions packages/premint-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
"anvil": "source .env.anvil && anvil --fork-url $FORK_RPC_URL --fork-block-number $FORK_BLOCK_NUMBER --chain-id 31337"
},
"dependencies": {
"@zoralabs/zora-1155-contracts": "*",
"@zoralabs/protocol-deployments": "*",
"abitype": "^0.8.7",
"vite": "4.5.0",
"vitest": "0.34.6"
"vite": "4.5.0"
},
"peerDependencies": {
"viem": "^1.16.6"
Expand Down
2 changes: 1 addition & 1 deletion packages/premint-sdk/src/premint-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
zoraCreator1155PremintExecutorImplABI,
zoraCreator1155PremintExecutorImplAddress,
zoraCreatorFixedPriceSaleStrategyAddress,
} from "@zoralabs/zora-1155-contracts";
} from "@zoralabs/protocol-deployments";
import { foundry, zora, zoraTestnet } from "viem/chains";
import { PremintConfig, preminterTypedDataDefinition } from "./preminter";
import type {
Expand Down
Loading

0 comments on commit b62e471

Please sign in to comment.