@zoralabs/protocol-sdk 0.9.2 → 0.9.4-PRE.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zoralabs/protocol-sdk",
3
- "version": "0.9.2",
3
+ "version": "0.9.4-PRE.0",
4
4
  "repository": "https://github.com/ourzora/zora-protocol",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -15,9 +15,18 @@
15
15
  "default": "./dist/index.cjs"
16
16
  }
17
17
  },
18
+ "scripts": {
19
+ "build": "pnpm tsup",
20
+ "prepack": "pnpm build",
21
+ "test:js": "vitest src",
22
+ "test:integration": "vitest test-integration",
23
+ "generate-types": "echo 'npx is used here because this is a rare operation' && npx openapi-typescript https://api.zora.co/premint/openapi.json -o src/apis/generated/premint-api-types.ts",
24
+ "prettier:write": "prettier --write 'src/**/*.ts' 'test-integration/**/*.ts'",
25
+ "lint": "prettier --check 'src/**/*.ts' 'test-integration/**/*.ts'"
26
+ },
18
27
  "dependencies": {
19
- "abitype": "^1.0.2",
20
- "@zoralabs/protocol-deployments": "^0.3.0"
28
+ "@zoralabs/protocol-deployments": "workspace:^",
29
+ "abitype": "^1.0.2"
21
30
  },
22
31
  "peerDependencies": {
23
32
  "viem": "^2.13.2"
@@ -28,6 +37,7 @@
28
37
  "@reservoir0x/reservoir-sdk": "^2.0.11",
29
38
  "@types/node": "^20.13.0",
30
39
  "@types/semver": "^7.5.8",
40
+ "@zoralabs/tsconfig": "workspace:^",
31
41
  "graphql-prettier": "^1.0.6",
32
42
  "multiformats": "^13.2.0",
33
43
  "prettier": "^3.0.3",
@@ -36,15 +46,6 @@
36
46
  "tsup": "^7.2.0",
37
47
  "typescript": "^5.2.2",
38
48
  "vite": "^4.5.0",
39
- "vitest": "^2.0.5",
40
- "@zoralabs/tsconfig": "^0.0.0"
41
- },
42
- "scripts": {
43
- "build": "pnpm tsup",
44
- "test:js": "vitest src",
45
- "test:integration": "vitest test-integration",
46
- "generate-types": "echo 'npx is used here because this is a rare operation' && npx openapi-typescript https://api.zora.co/premint/openapi.json -o src/apis/generated/premint-api-types.ts",
47
- "prettier:write": "prettier --write 'src/**/*.ts' 'test-integration/**/*.ts'",
48
- "lint": "prettier --check 'src/**/*.ts' 'test-integration/**/*.ts'"
49
+ "vitest": "^2.0.5"
49
50
  }
50
- }
51
+ }
@@ -6,10 +6,17 @@ import {
6
6
  import { createCreatorClient } from "src/sdk";
7
7
  import {
8
8
  zoraCreator1155ImplABI,
9
+ zoraTimedSaleStrategyABI,
9
10
  zoraTimedSaleStrategyAddress,
10
11
  } from "@zoralabs/protocol-deployments";
11
12
  import { waitForSuccess } from "src/test-utils";
12
- import { Address, parseEther, PublicClient, TransactionReceipt } from "viem";
13
+ import {
14
+ Address,
15
+ erc20Abi,
16
+ parseEther,
17
+ PublicClient,
18
+ TransactionReceipt,
19
+ } from "viem";
13
20
  import { makePrepareMint1155TokenParams } from "src/mint/mint-transactions";
14
21
  import { forkUrls, makeAnvilTest } from "src/anvil";
15
22
  import { zora } from "viem/chains";
@@ -67,6 +74,13 @@ function randomNewContract(): NewContractParams {
67
74
  };
68
75
  }
69
76
 
77
+ const add24HoursToNowInSeconds = (): number => {
78
+ const currentTimeInSeconds = Math.floor(Date.now() / 1000);
79
+ const add24Hours = 24 * 60 * 60;
80
+
81
+ return currentTimeInSeconds + add24Hours;
82
+ };
83
+
70
84
  describe("create-helper", () => {
71
85
  anvilTest(
72
86
  "when no sales config is provided, it creates a new 1155 contract and token using the timed sale strategy",
@@ -78,15 +92,24 @@ describe("create-helper", () => {
78
92
  chainId: chain.id,
79
93
  publicClient: publicClient,
80
94
  });
95
+
96
+ const saleStart = 5n;
97
+ const saleEnd = BigInt(add24HoursToNowInSeconds());
98
+ const contract = randomNewContract();
81
99
  const {
82
100
  parameters: parameters,
83
101
  contractAddress,
84
102
  newTokenId,
85
103
  } = await creatorClient.create1155({
86
- contract: randomNewContract(),
104
+ contract,
87
105
  token: {
88
106
  tokenMetadataURI: demoTokenMetadataURI,
89
107
  mintToCreatorCount: 1,
108
+ salesConfig: {
109
+ saleStart,
110
+ saleEnd,
111
+ type: "timed",
112
+ },
90
113
  },
91
114
  account: creatorAddress,
92
115
  });
@@ -103,6 +126,27 @@ describe("create-helper", () => {
103
126
  contractAddress,
104
127
  );
105
128
 
129
+ const salesConfig = await publicClient.readContract({
130
+ abi: zoraTimedSaleStrategyABI,
131
+ address:
132
+ zoraTimedSaleStrategyAddress[
133
+ chain.id as keyof typeof zoraTimedSaleStrategyAddress
134
+ ],
135
+ functionName: "sale",
136
+ args: [contractAddress, newTokenId],
137
+ });
138
+
139
+ expect(salesConfig.saleEnd).toBe(saleEnd);
140
+ expect(salesConfig.saleStart).toBe(saleStart);
141
+
142
+ const erc20Name = await publicClient.readContract({
143
+ abi: erc20Abi,
144
+ address: salesConfig.erc20zAddress,
145
+ functionName: "name",
146
+ });
147
+
148
+ expect(erc20Name).toBe(contract.name);
149
+
106
150
  expect(
107
151
  await minterIsMinterOnToken({
108
152
  contractAddress,
@@ -206,6 +206,7 @@ async function createNew1155ContractAndToken({
206
206
  nextTokenId,
207
207
  token,
208
208
  getAdditionalSetupActions,
209
+ contractName: contract.name,
209
210
  });
210
211
 
211
212
  const request = makeCreateContractAndTokenCall({
@@ -263,7 +264,7 @@ async function createNew1155Token({
263
264
  chainId: number;
264
265
  contractGetter: IContractGetter;
265
266
  }): Promise<CreateNew1155TokenReturn> {
266
- const { nextTokenId, contractVersion, mintFee } =
267
+ const { nextTokenId, contractVersion, mintFee, name } =
267
268
  await contractGetter.getContractInfo({ contractAddress, retries: 5 });
268
269
 
269
270
  const {
@@ -277,6 +278,7 @@ async function createNew1155Token({
277
278
  nextTokenId,
278
279
  token,
279
280
  getAdditionalSetupActions,
281
+ contractName: name,
280
282
  });
281
283
 
282
284
  const request = makeCreateTokenCall({
@@ -311,11 +313,13 @@ async function prepareSetupActions({
311
313
  contractVersion,
312
314
  nextTokenId,
313
315
  token,
316
+ contractName,
314
317
  getAdditionalSetupActions,
315
318
  }: {
316
319
  chainId: number;
317
320
  contractVersion: string;
318
321
  nextTokenId: bigint;
322
+ contractName: string;
319
323
  } & CreateNew1155ParamsBase) {
320
324
  const {
321
325
  minter,
@@ -327,6 +331,7 @@ async function prepareSetupActions({
327
331
  contractVersion,
328
332
  nextTokenId,
329
333
  ...token,
334
+ contractName,
330
335
  });
331
336
 
332
337
  const setupActions = getAdditionalSetupActions
@@ -9,7 +9,6 @@ import {
9
9
  ConcreteSalesConfig,
10
10
  TimedSaleParamsType,
11
11
  } from "./types";
12
- import { fetchTokenMetadata } from "src/ipfs/token-metadata";
13
12
 
14
13
  // Sales end forever amount (uint64 max)
15
14
  export const SALE_END_FOREVER = 18446744073709551615n;
@@ -75,30 +74,19 @@ export const parseNameIntoSymbol = (name: string) => {
75
74
  return result;
76
75
  };
77
76
 
78
- async function fetchTokenNameFromMetadata(
79
- tokenMetadataURI: string,
80
- ): Promise<string> {
81
- const tokenMetadata = await fetchTokenMetadata(tokenMetadataURI);
82
-
83
- if (!tokenMetadata.name) {
84
- throw new Error("No name found in token metadata");
85
- }
86
-
87
- return tokenMetadata.name;
88
- }
89
77
  const timedSaleSettingsWithDefaults = async (
90
78
  params: TimedSaleParamsType,
91
- tokenMetadataURI: string,
79
+ contractName: string,
92
80
  ): Promise<Concrete<TimedSaleParamsType>> => {
93
81
  // If the name is not provided, try to fetch it from the metadata
94
- const erc20Name =
95
- params.erc20Name || (await fetchTokenNameFromMetadata(tokenMetadataURI));
82
+ const erc20Name = params.erc20Name || contractName;
96
83
  const symbol = params.erc20Symbol || parseNameIntoSymbol(erc20Name);
97
84
 
98
85
  return {
99
86
  type: "timed",
100
87
  ...DEFAULT_SALE_START_AND_END,
101
- erc20Name,
88
+ ...params,
89
+ erc20Name: erc20Name,
102
90
  erc20Symbol: symbol,
103
91
  };
104
92
  };
@@ -112,14 +100,17 @@ const isErc20 = (
112
100
  const isFixedPrice = (
113
101
  salesConfig: SalesConfigParamsType,
114
102
  ): salesConfig is FixedPriceParamsType => {
115
- return (salesConfig as FixedPriceParamsType).pricePerToken > 0n;
103
+ return (
104
+ salesConfig.type === "fixedPrice" ||
105
+ (salesConfig as FixedPriceParamsType).pricePerToken > 0n
106
+ );
116
107
  };
117
108
 
118
109
  export const getSalesConfigWithDefaults = async (
119
110
  salesConfig: SalesConfigParamsType | undefined,
120
- tokenMetadataURI: string,
111
+ contractName: string,
121
112
  ): Promise<ConcreteSalesConfig> => {
122
- if (!salesConfig) return timedSaleSettingsWithDefaults({}, tokenMetadataURI);
113
+ if (!salesConfig) return timedSaleSettingsWithDefaults({}, contractName);
123
114
  if (isAllowList(salesConfig)) {
124
115
  return allowListWithDefaults(salesConfig);
125
116
  }
@@ -130,5 +121,5 @@ export const getSalesConfigWithDefaults = async (
130
121
  return fixedPriceSettingsWithDefaults(salesConfig);
131
122
  }
132
123
 
133
- return timedSaleSettingsWithDefaults(salesConfig, tokenMetadataURI);
124
+ return timedSaleSettingsWithDefaults(salesConfig, contractName);
134
125
  };
@@ -9,6 +9,7 @@ import { setupMinters } from "./minter-setup";
9
9
  async function applyNew1155Defaults(
10
10
  props: CreateNew1155TokenProps,
11
11
  ownerAddress: Address,
12
+ contractName: string,
12
13
  ): Promise<New1155Token> {
13
14
  const { payoutRecipient: fundsRecipient } = props;
14
15
  const fundsRecipientOrOwner =
@@ -26,7 +27,7 @@ async function applyNew1155Defaults(
26
27
  tokenMetadataURI: props.tokenMetadataURI,
27
28
  salesConfig: await getSalesConfigWithDefaults(
28
29
  props.salesConfig,
29
- props.tokenMetadataURI,
30
+ contractName,
30
31
  ),
31
32
  };
32
33
  }
@@ -117,6 +118,8 @@ export async function constructCreate1155TokenCalls(
117
118
  ContractProps & {
118
119
  ownerAddress: Address;
119
120
  chainId: number;
121
+ } & {
122
+ contractName: string;
120
123
  },
121
124
  ): Promise<{
122
125
  setupActions: `0x${string}`[];
@@ -134,6 +137,7 @@ export async function constructCreate1155TokenCalls(
134
137
  const new1155TokenPropsWithDefaults = await applyNew1155Defaults(
135
138
  props,
136
139
  ownerAddress,
140
+ props.contractName,
137
141
  );
138
142
 
139
143
  const verifyTokenIdExpected = encodeFunctionData({
@@ -29,7 +29,7 @@ export type FixedPriceParamsType = SaleStartAndEnd &
29
29
 
30
30
  export type TimedSaleParamsType = SaleStartAndEnd & {
31
31
  type?: "timed";
32
- // Name of the erc20z token to create for the secondary sale. If not provided, fetches the metadata from the tokenMetadataURI and uses the name from it.
32
+ // Name of the erc20z token to create for the secondary sale. If not provided, uses the contract name
33
33
  erc20Name?: string;
34
34
  // Symbol of the erc20z token to create for the secondary sale. If not provided, extracts it from the name.
35
35
  erc20Symbol?: string;