Skip to content

Commit

Permalink
feat: handle zksync direct deploys in deployContract (#5002)
Browse files Browse the repository at this point in the history
## Problem solved

Short description of the bug fixed or feature added

<!-- start pr-codex -->

---

## PR-Codex overview
This PR focuses on enhancing the `thirdweb` library with new features and bug fixes, particularly for zkSync deployments and improvements to various ERC1155 and ERC721 modules.

### Detailed summary
- Added support for zkSync direct deploys in `deployContract`.
- Updated `SequentialTokenIdERC1155` to include `startTokenId` in its module.
- Modified event signatures for `BatchMetadataUpdate` in both ERC721 and ERC1155.
- Increased test retry count and max concurrency in `vitest.config.ts`.
- Introduced new methods for batch metadata handling, including `getBatchIndex` and `getMetadataBatch`.
- Added `setBaseURI` functionality for both `BatchMetadataERC721` and `BatchMetadataERC1155`.
- Created parameter encoding functions for `updateTokenIdERC1155`.
- Enhanced error handling and configuration retrieval methods in modules.

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}`

<!-- end pr-codex -->
  • Loading branch information
joaquim-verges committed Oct 13, 2024
1 parent 4f346e6 commit cd2c0f3
Show file tree
Hide file tree
Showing 24 changed files with 1,400 additions and 111 deletions.
5 changes: 5 additions & 0 deletions .changeset/rich-steaks-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Handle zk sync direct deploys in `deployContract`
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
[
"function encodeBytesOnInstall() pure returns (bytes)",
"function getAllMetadataBatches() view returns ((uint256 startTokenIdInclusive, uint256 endTokenIdInclusive, string baseURI)[])",
"function getBatchIndex(uint256 _tokenId) view returns (uint256)",
"function getMetadataBatch(uint256 _batchIndex) view returns ((uint256 startTokenIdInclusive, uint256 endTokenIdInclusive, string baseURI))",
"function getModuleConfig() pure returns ((bool registerInstallationCallback, bytes4[] requiredInterfaces, bytes4[] supportedInterfaces, (bytes4 selector)[] callbackFunctions, (bytes4 selector, uint256 permissionBits)[] fallbackFunctions) config)",
"function setBaseURI(uint256 _batchIndex, string _baseURI)",
"function uploadMetadata(uint256 _amount, string _baseURI)",
"event BatchMetadataUpdate(uint256 _fromTokenId, uint256 _toTokenId)"
"event BatchMetadataUpdate(uint256 startTokenIdIncluside, uint256 endTokenIdInclusive, string baseURI)"
]
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
[
"function encodeBytesOnInstall() pure returns (bytes)",
"function getAllMetadataBatches() view returns ((uint256 startTokenIdInclusive, uint256 endTokenIdInclusive, string baseURI)[])",
"function getBatchIndex(uint256 _tokenId) view returns (uint256)",
"function getMetadataBatch(uint256 _batchIndex) view returns ((uint256 startTokenIdInclusive, uint256 endTokenIdInclusive, string baseURI))",
"function getModuleConfig() pure returns ((bool registerInstallationCallback, bytes4[] requiredInterfaces, bytes4[] supportedInterfaces, (bytes4 selector)[] callbackFunctions, (bytes4 selector, uint256 permissionBits)[] fallbackFunctions) config)",
"function setBaseURI(uint256 _batchIndex, string _baseURI)",
"function uploadMetadata(uint256 _amount, string _baseURI)",
"event BatchMetadataUpdate(uint256 _fromTokenId, uint256 _toTokenId)"
"event BatchMetadataUpdate(uint256 startTokenIdIncluside, uint256 endTokenIdInclusive, string baseURI)"
]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
"function encodeBytesOnInstall() pure returns (bytes)",
"function encodeBytesOnInstall(uint256 startTokenId) pure returns (bytes)",
"function getModuleConfig() pure returns ((bool registerInstallationCallback, bytes4[] requiredInterfaces, bytes4[] supportedInterfaces, (bytes4 selector)[] callbackFunctions, (bytes4 selector, uint256 permissionBits)[] fallbackFunctions) config)",
"function getNextTokenId() view returns (uint256)",
"error SequentialTokenIdInvalidTokenId()",
"error UpdateTokenIdCallbackERC1155NotImplemented()"
"function updateTokenIdERC1155(uint256 _tokenId) payable returns (uint256)"
]
14 changes: 14 additions & 0 deletions packages/thirdweb/src/contract/deployment/deploy-with-abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { encodeAbiParameters } from "../../utils/abi/encodeAbiParameters.js";
import { normalizeFunctionParams } from "../../utils/abi/normalizeFunctionParams.js";
import { computeDeploymentAddress } from "../../utils/any-evm/compute-deployment-address.js";
import { computeDeploymentInfoFromBytecode } from "../../utils/any-evm/compute-published-contract-deploy-info.js";
import { isZkSyncChain } from "../../utils/any-evm/zksync/isZkSyncChain.js";
import { isContractDeployed } from "../../utils/bytecode/is-contract-deployed.js";
import { ensureBytecodePrefix } from "../../utils/bytecode/prefix.js";
import { concatHex } from "../../utils/encoding/helpers/concat-hex.js";
Expand All @@ -13,6 +14,7 @@ import type { Prettify } from "../../utils/type-utils.js";
import type { ClientAndChain } from "../../utils/types.js";
import type { Account } from "../../wallets/interfaces/wallet.js";
import { getContract } from "../contract.js";
import { zkDeployContract } from "./zksync/zkDeployContract.js";

/**
* @extension DEPLOY
Expand Down Expand Up @@ -121,6 +123,18 @@ export async function deployContract(
salt?: string;
},
) {
if (await isZkSyncChain(options.chain)) {
return zkDeployContract({
account: options.account,
client: options.client,
chain: options.chain,
bytecode: options.bytecode,
abi: options.abi,
params: options.constructorParams,
salt: options.salt,
});
}

Check warning on line 136 in packages/thirdweb/src/contract/deployment/deploy-with-abi.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/contract/deployment/deploy-with-abi.ts#L127-L136

Added lines #L127 - L136 were not covered by tests

if (options.salt !== undefined) {
// Deploy with CREATE2 if salt is provided
const info = await computeDeploymentInfoFromBytecode(options);
Expand Down
5 changes: 1 addition & 4 deletions packages/thirdweb/src/extensions/ens/resolve-avatar.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { describe, expect, it } from "vitest";

import { TEST_CLIENT } from "../../../test/src/test-clients.js";
import { resolveAvatar } from "./resolve-avatar.js";

Expand All @@ -22,9 +21,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("ENS:resolve-avatar", () => {
client: TEST_CLIENT,
name: "vitalik.eth",
});
expect(avatarUri?.split("/ipfs/")[1]).toMatchInlineSnapshot(
`"QmSP4nq9fnN9dAiCj42ug9Wa79rqmQerZXZch82VqpiH7U/image.gif"`,
);
expect(avatarUri).toMatchInlineSnapshot(`"https://euc.li/vitalik.eth"`);
});

it("resolves name without avatar record to null", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ describe.runIf(process.env.TW_SECRET_KEY)("ModularTokenERC1155", () => {
primarySaleRecipient: TEST_ACCOUNT_A.address,
}),
BatchMetadataERC1155.module(),
SequentialTokenIdERC1155.module(),
SequentialTokenIdERC1155.module({
startTokenId: 0n,
}),
],
});
contract = getContract({
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cd2c0f3

Please sign in to comment.