Skip to content

Commit

Permalink
move premint and mints typed data definitions to protocol-deployments (
Browse files Browse the repository at this point in the history
  • Loading branch information
oveddan authored May 14, 2024
1 parent 54d6af6 commit 16deff0
Show file tree
Hide file tree
Showing 8 changed files with 280 additions and 205 deletions.
6 changes: 6 additions & 0 deletions .changeset/lucky-books-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@zoralabs/protocol-deployments": patch
"@zoralabs/protocol-sdk": patch
---

Moved typed data definitions from protocol-sdk to protocol-deployments
14 changes: 7 additions & 7 deletions packages/protocol-deployments/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
},
"dependencies": {},
"devDependencies": {
"zoralabs-tsconfig": "*",
"typescript": "^5.2.2",
"tsx": "^3.13.0",
"tsup": "^7.2.0",
"glob": "^10.2.2",
"es-main": "^1.2.0",
"@lavamoat/preinstall-always-fail": "2.0.0",
"@types/node": "^20.1.2",
"@lavamoat/preinstall-always-fail": "2.0.0"
"es-main": "^1.2.0",
"tsup": "^7.2.0",
"tsx": "^3.13.0",
"typescript": "^5.2.2",
"viem": "^2.9.18",
"zoralabs-tsconfig": "*"
}
}
1 change: 1 addition & 0 deletions packages/protocol-deployments/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
// built at build time. They are not checked in to git.
// The can be generated by running `yarn prepack` in the root
export * from "./generated/wagmi";
export * from "./typedData";
export * as contracts1155 from "./generated/1155";
export * as mints from "./generated/mints";
226 changes: 226 additions & 0 deletions packages/protocol-deployments/src/typedData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
import {
Address,
TypedDataDomain,
TypedData,
TypedDataToPrimitiveTypes,
} from "abitype";
import { TypedDataDefinition } from "viem";
import { zoraMints1155Address } from "./generated/wagmi";

const premintTypedDataDomain = ({
chainId,
version,
creator1155Contract: verifyingContract,
}: {
chainId: number;
version: "1" | "2";
creator1155Contract: Address;
}): TypedDataDomain => ({
chainId,
name: "Preminter",
version,
verifyingContract,
});

const premintV1TypedDataType = {
CreatorAttribution: [
{ name: "tokenConfig", type: "TokenCreationConfig" },
// unique id scoped to the contract and token to create.
// ensure that a signature can be replaced, as long as the replacement
// has the same uid, and a newer version.
{ name: "uid", type: "uint32" },
{ name: "version", type: "uint32" },
// if this update should result in the signature being deleted.
{ name: "deleted", type: "bool" },
],
TokenCreationConfig: [
{ name: "tokenURI", type: "string" },
{ name: "maxSupply", type: "uint256" },
{ name: "maxTokensPerAddress", type: "uint64" },
{ name: "pricePerToken", type: "uint96" },
{ name: "mintStart", type: "uint64" },
{ name: "mintDuration", type: "uint64" },
{ name: "royaltyMintSchedule", type: "uint32" },
{ name: "royaltyBPS", type: "uint32" },
{ name: "royaltyRecipient", type: "address" },
{ name: "fixedPriceMinter", type: "address" },
],
} as const satisfies TypedData;

/**
* Builds a typed data definition for a PremintConfigV1 to be signed
* @returns
*/
export const premintV1TypedDataDefinition = ({
chainId,
creator1155Contract,
message,
}: {
chainId: number;
creator1155Contract: Address;
message: TypedDataToPrimitiveTypes<
typeof premintV1TypedDataType
>["CreatorAttribution"];
}): TypedDataDefinition<
typeof premintV1TypedDataType,
"CreatorAttribution"
> => ({
types: premintV1TypedDataType,
primaryType: "CreatorAttribution",
domain: premintTypedDataDomain({
chainId,
version: "1",
creator1155Contract,
}),
message,
});

const premintV2TypedDataType = {
CreatorAttribution: [
{ name: "tokenConfig", type: "TokenCreationConfig" },
// unique id scoped to the contract and token to create.
// ensure that a signature can be replaced, as long as the replacement
// has the same uid, and a newer version.
{ name: "uid", type: "uint32" },
{ name: "version", type: "uint32" },
// if this update should result in the signature being deleted.
{ name: "deleted", type: "bool" },
],
TokenCreationConfig: [
{ name: "tokenURI", type: "string" },
{ name: "maxSupply", type: "uint256" },
{ name: "maxTokensPerAddress", type: "uint64" },
{ name: "pricePerToken", type: "uint96" },
{ name: "mintStart", type: "uint64" },
{ name: "mintDuration", type: "uint64" },
{ name: "royaltyBPS", type: "uint32" },
{ name: "payoutRecipient", type: "address" },
{ name: "fixedPriceMinter", type: "address" },
{ name: "createReferral", type: "address" },
],
} as const satisfies TypedData;

/**
* Builds a typed data definition for a PremintConfigV2 to be signed
*/
export const premintV2TypedDataDefinition = ({
chainId,
creator1155Contract,
message,
}: {
chainId: number;
creator1155Contract: Address;
message: TypedDataToPrimitiveTypes<
typeof premintV2TypedDataType
>["CreatorAttribution"];
}): TypedDataDefinition<
typeof premintV2TypedDataType,
"CreatorAttribution"
> => ({
types: premintV2TypedDataType,
primaryType: "CreatorAttribution",
domain: premintTypedDataDomain({
chainId,
version: "2",
creator1155Contract,
}),
message,
});

const permitSafeTransferTypedDataType = {
PermitSafeTransfer: [
{ name: "owner", type: "address" },
{ name: "to", type: "address" },
{ name: "tokenId", type: "uint256" },
{ name: "quantity", type: "uint256" },
{ name: "safeTransferData", type: "bytes" },
{ name: "nonce", type: "uint256" },
{ name: "deadline", type: "uint256" },
],
} as const;

/**
* Builds a typed data definition for a PermitSafeTransfer on the Mints1155 contract to be signed
*/
export const mintsSafeTransferTypedDataDefinition = ({
chainId,
message,
}: {
chainId: keyof typeof zoraMints1155Address;
message: TypedDataToPrimitiveTypes<
typeof permitSafeTransferTypedDataType
>["PermitSafeTransfer"];
}): TypedDataDefinition<
typeof permitSafeTransferTypedDataType,
"PermitSafeTransfer"
> => ({
types: permitSafeTransferTypedDataType,
message,
primaryType: "PermitSafeTransfer",
domain: {
chainId,
name: "Mints",
version: "1",
verifyingContract: zoraMints1155Address[chainId],
},
});

const permitSafeBatchTransferTypedDataType = {
Permit: [
{
name: "owner",
type: "address",
},
{
name: "to",
type: "address",
},
{
name: "tokenIds",
type: "uint256[]",
},
{
name: "quantities",
type: "uint256[]",
},
{
name: "safeTransferData",
type: "bytes",
},
{
name: "nonce",
type: "uint256",
},
{
name: "deadline",
type: "uint256",
},
],
} as const;

/**
* Builds a typed data definition for a PermitSafeTransferBatch on the Mints1155 contract to be signed
* @returns
*/
export const mintsSafeTransferBatchTypedDataDefinition = ({
chainId,
message,
}: {
chainId: keyof typeof zoraMints1155Address;
message: TypedDataToPrimitiveTypes<
typeof permitSafeBatchTransferTypedDataType
>["Permit"];
}): TypedDataDefinition<
typeof permitSafeBatchTransferTypedDataType,
"Permit"
> => ({
types: permitSafeBatchTransferTypedDataType,
message,
primaryType: "Permit",
domain: {
chainId,
name: "Mints",
version: "1",
verifyingContract: zoraMints1155Address[chainId],
},
});
Loading

0 comments on commit 16deff0

Please sign in to comment.