@zoralabs/protocol-sdk 0.9.3 → 0.9.4
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/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +10 -0
- package/dist/anvil.d.ts +2 -2
- package/dist/anvil.d.ts.map +1 -1
- package/dist/apis/http-api-base.d.ts +1 -1
- package/dist/apis/http-api-base.d.ts.map +1 -1
- package/dist/create/minter-defaults.d.ts +1 -1
- package/dist/create/minter-defaults.d.ts.map +1 -1
- package/dist/create/token-setup.d.ts +2 -2
- package/dist/create/token-setup.d.ts.map +1 -1
- package/dist/index.cjs +14 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +14 -17
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/apis/http-api-base.ts +5 -4
- package/src/create/1155-create-helper.test.ts +31 -46
- package/src/create/1155-create-helper.ts +4 -4
- package/src/create/minter-defaults.ts +4 -4
- package/src/create/token-setup.ts +7 -10
- package/src/mint/mint-client.test.ts +2 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zoralabs/protocol-sdk",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.4",
|
|
4
4
|
"repository": "https://github.com/ourzora/zora-protocol",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"abitype": "^1.0.2",
|
|
20
|
-
"@zoralabs/protocol-deployments": "^0.3.
|
|
20
|
+
"@zoralabs/protocol-deployments": "^0.3.1"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"viem": "^2.13.2"
|
|
@@ -79,15 +79,16 @@ export const post = async <T>(url: string, data: any) => {
|
|
|
79
79
|
return (await response.json()) as T;
|
|
80
80
|
};
|
|
81
81
|
|
|
82
|
+
const defaultShouldRetry = (err: any) => {
|
|
83
|
+
return err instanceof BadResponseError && err.status >= 500;
|
|
84
|
+
};
|
|
85
|
+
|
|
82
86
|
export const retries = async <T>(
|
|
83
87
|
tryFn: () => T,
|
|
84
88
|
maxTries: number = 3,
|
|
85
89
|
linearBackoffMS: number = 200,
|
|
90
|
+
shouldRetry: (err: any) => boolean = defaultShouldRetry,
|
|
86
91
|
): Promise<T> => {
|
|
87
|
-
const shouldRetry = (err: any) => {
|
|
88
|
-
return err instanceof BadResponseError && err.status >= 500;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
92
|
return retriesGeneric({
|
|
92
93
|
tryFn,
|
|
93
94
|
maxTries,
|
|
@@ -10,21 +10,14 @@ import {
|
|
|
10
10
|
zoraTimedSaleStrategyAddress,
|
|
11
11
|
} from "@zoralabs/protocol-deployments";
|
|
12
12
|
import { waitForSuccess } from "src/test-utils";
|
|
13
|
-
import {
|
|
14
|
-
Address,
|
|
15
|
-
erc20Abi,
|
|
16
|
-
parseEther,
|
|
17
|
-
PublicClient,
|
|
18
|
-
TransactionReceipt,
|
|
19
|
-
} from "viem";
|
|
13
|
+
import { Address, erc20Abi, parseEther, PublicClient } from "viem";
|
|
20
14
|
import { makePrepareMint1155TokenParams } from "src/mint/mint-transactions";
|
|
21
|
-
import { forkUrls, makeAnvilTest } from "src/anvil";
|
|
15
|
+
import { forkUrls, makeAnvilTest, writeContractWithRetries } from "src/anvil";
|
|
22
16
|
import { zora } from "viem/chains";
|
|
23
17
|
import { AllowList } from "src/allow-list/types";
|
|
24
18
|
import { createAllowList } from "src/allow-list/allow-list-client";
|
|
25
19
|
import { NewContractParams } from "./types";
|
|
26
20
|
import { SubgraphContractGetter } from "./contract-getter";
|
|
27
|
-
import { inspect } from "util";
|
|
28
21
|
|
|
29
22
|
export const demoTokenMetadataURI =
|
|
30
23
|
"ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u";
|
|
@@ -59,14 +52,6 @@ const minterIsMinterOnToken = async ({
|
|
|
59
52
|
});
|
|
60
53
|
};
|
|
61
54
|
|
|
62
|
-
function logFailure(receipt: TransactionReceipt) {
|
|
63
|
-
if (receipt.status !== "success") {
|
|
64
|
-
console.log("transaction failed");
|
|
65
|
-
console.log(receipt.logs);
|
|
66
|
-
console.log(inspect(receipt, { depth: 10 }));
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
55
|
function randomNewContract(): NewContractParams {
|
|
71
56
|
return {
|
|
72
57
|
name: `testContract-${Math.round(Math.random() * 1_000_000)}`,
|
|
@@ -115,10 +100,11 @@ describe("create-helper", () => {
|
|
|
115
100
|
});
|
|
116
101
|
|
|
117
102
|
const { request } = await publicClient.simulateContract(parameters);
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
103
|
+
const receipt = await writeContractWithRetries(
|
|
104
|
+
request,
|
|
105
|
+
walletClient,
|
|
106
|
+
publicClient,
|
|
107
|
+
);
|
|
122
108
|
expect(receipt).not.toBeNull();
|
|
123
109
|
expect(receipt.to).to.equal("0x777777c338d93e2c7adf08d102d45ca7cc4ed021");
|
|
124
110
|
expect(getTokenIdFromCreateReceipt(receipt)).to.be.equal(1n);
|
|
@@ -187,12 +173,8 @@ describe("create-helper", () => {
|
|
|
187
173
|
});
|
|
188
174
|
|
|
189
175
|
const { request } = await publicClient.simulateContract(parameters);
|
|
190
|
-
const hash = await walletClient.writeContract(request);
|
|
191
|
-
const receipt = await publicClient.waitForTransactionReceipt({ hash });
|
|
192
176
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
expect(receipt.status).toBe("success");
|
|
177
|
+
await writeContractWithRetries(request, walletClient, publicClient);
|
|
196
178
|
|
|
197
179
|
expect(
|
|
198
180
|
await minterIsMinterOnToken({
|
|
@@ -234,13 +216,13 @@ describe("create-helper", () => {
|
|
|
234
216
|
});
|
|
235
217
|
const { request: simulateResponse } =
|
|
236
218
|
await publicClient.simulateContract(request);
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
219
|
+
const receipt = await writeContractWithRetries(
|
|
220
|
+
simulateResponse,
|
|
221
|
+
walletClient,
|
|
222
|
+
publicClient,
|
|
223
|
+
);
|
|
241
224
|
const firstTokenId = getTokenIdFromCreateReceipt(receipt);
|
|
242
225
|
expect(firstTokenId).to.be.equal(1n);
|
|
243
|
-
expect(receipt).not.toBeNull();
|
|
244
226
|
|
|
245
227
|
// creator should have mint to creator count balance
|
|
246
228
|
expect(
|
|
@@ -279,18 +261,16 @@ describe("create-helper", () => {
|
|
|
279
261
|
const { request: simulateRequest } = await publicClient.simulateContract(
|
|
280
262
|
newTokenOnExistingContract.parameters,
|
|
281
263
|
);
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
logFailure(receipt);
|
|
264
|
+
const newReceipt = await writeContractWithRetries(
|
|
265
|
+
simulateRequest,
|
|
266
|
+
walletClient,
|
|
267
|
+
publicClient,
|
|
268
|
+
);
|
|
288
269
|
|
|
289
|
-
expect(newReceipt.status).toBe("success");
|
|
290
270
|
const tokenId = getTokenIdFromCreateReceipt(newReceipt);
|
|
291
271
|
expect(tokenId).to.be.equal(2n);
|
|
292
272
|
},
|
|
293
|
-
|
|
273
|
+
30 * 1000,
|
|
294
274
|
);
|
|
295
275
|
anvilTest(
|
|
296
276
|
"creates a new token with a create referral address",
|
|
@@ -317,9 +297,11 @@ describe("create-helper", () => {
|
|
|
317
297
|
});
|
|
318
298
|
const { request: simulationResponse } =
|
|
319
299
|
await publicClient.simulateContract(request);
|
|
320
|
-
const
|
|
321
|
-
|
|
322
|
-
|
|
300
|
+
const receipt = await writeContractWithRetries(
|
|
301
|
+
simulationResponse,
|
|
302
|
+
walletClient,
|
|
303
|
+
publicClient,
|
|
304
|
+
);
|
|
323
305
|
expect(receipt.to).to.equal("0x777777c338d93e2c7adf08d102d45ca7cc4ed021");
|
|
324
306
|
expect(getTokenIdFromCreateReceipt(receipt)).to.be.equal(newTokenId);
|
|
325
307
|
|
|
@@ -357,8 +339,10 @@ describe("create-helper", () => {
|
|
|
357
339
|
});
|
|
358
340
|
const { request: createSimulation } =
|
|
359
341
|
await publicClient.simulateContract(request);
|
|
360
|
-
|
|
361
|
-
|
|
342
|
+
|
|
343
|
+
await writeContractWithRetries(
|
|
344
|
+
createSimulation,
|
|
345
|
+
walletClient,
|
|
362
346
|
publicClient,
|
|
363
347
|
);
|
|
364
348
|
|
|
@@ -420,8 +404,9 @@ describe("create-helper", () => {
|
|
|
420
404
|
});
|
|
421
405
|
const { request: createSimulation } =
|
|
422
406
|
await publicClient.simulateContract(request);
|
|
423
|
-
await
|
|
424
|
-
|
|
407
|
+
await writeContractWithRetries(
|
|
408
|
+
createSimulation,
|
|
409
|
+
walletClient,
|
|
425
410
|
publicClient,
|
|
426
411
|
);
|
|
427
412
|
|
|
@@ -199,7 +199,7 @@ async function createNew1155ContractAndToken({
|
|
|
199
199
|
minter,
|
|
200
200
|
newToken,
|
|
201
201
|
setupActions: tokenSetupActions,
|
|
202
|
-
} =
|
|
202
|
+
} = prepareSetupActions({
|
|
203
203
|
chainId,
|
|
204
204
|
account,
|
|
205
205
|
contractVersion,
|
|
@@ -271,7 +271,7 @@ async function createNew1155Token({
|
|
|
271
271
|
minter,
|
|
272
272
|
newToken,
|
|
273
273
|
setupActions: tokenSetupActions,
|
|
274
|
-
} =
|
|
274
|
+
} = prepareSetupActions({
|
|
275
275
|
chainId,
|
|
276
276
|
account,
|
|
277
277
|
contractVersion,
|
|
@@ -307,7 +307,7 @@ async function createNew1155Token({
|
|
|
307
307
|
};
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
-
|
|
310
|
+
function prepareSetupActions({
|
|
311
311
|
chainId,
|
|
312
312
|
account,
|
|
313
313
|
contractVersion,
|
|
@@ -325,7 +325,7 @@ async function prepareSetupActions({
|
|
|
325
325
|
minter,
|
|
326
326
|
newToken,
|
|
327
327
|
setupActions: tokenSetupActions,
|
|
328
|
-
} =
|
|
328
|
+
} = constructCreate1155TokenCalls({
|
|
329
329
|
chainId: chainId,
|
|
330
330
|
ownerAddress: account,
|
|
331
331
|
contractVersion,
|
|
@@ -74,10 +74,10 @@ export const parseNameIntoSymbol = (name: string) => {
|
|
|
74
74
|
return result;
|
|
75
75
|
};
|
|
76
76
|
|
|
77
|
-
const timedSaleSettingsWithDefaults =
|
|
77
|
+
const timedSaleSettingsWithDefaults = (
|
|
78
78
|
params: TimedSaleParamsType,
|
|
79
79
|
contractName: string,
|
|
80
|
-
):
|
|
80
|
+
): Concrete<TimedSaleParamsType> => {
|
|
81
81
|
// If the name is not provided, try to fetch it from the metadata
|
|
82
82
|
const erc20Name = params.erc20Name || contractName;
|
|
83
83
|
const symbol = params.erc20Symbol || parseNameIntoSymbol(erc20Name);
|
|
@@ -106,10 +106,10 @@ const isFixedPrice = (
|
|
|
106
106
|
);
|
|
107
107
|
};
|
|
108
108
|
|
|
109
|
-
export const getSalesConfigWithDefaults =
|
|
109
|
+
export const getSalesConfigWithDefaults = (
|
|
110
110
|
salesConfig: SalesConfigParamsType | undefined,
|
|
111
111
|
contractName: string,
|
|
112
|
-
):
|
|
112
|
+
): ConcreteSalesConfig => {
|
|
113
113
|
if (!salesConfig) return timedSaleSettingsWithDefaults({}, contractName);
|
|
114
114
|
if (isAllowList(salesConfig)) {
|
|
115
115
|
return allowListWithDefaults(salesConfig);
|
|
@@ -6,11 +6,11 @@ import { OPEN_EDITION_MINT_SIZE } from "src/constants";
|
|
|
6
6
|
import { getSalesConfigWithDefaults } from "./minter-defaults";
|
|
7
7
|
import { setupMinters } from "./minter-setup";
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
function applyNew1155Defaults(
|
|
10
10
|
props: CreateNew1155TokenProps,
|
|
11
11
|
ownerAddress: Address,
|
|
12
12
|
contractName: string,
|
|
13
|
-
):
|
|
13
|
+
): New1155Token {
|
|
14
14
|
const { payoutRecipient: fundsRecipient } = props;
|
|
15
15
|
const fundsRecipientOrOwner =
|
|
16
16
|
fundsRecipient && fundsRecipient !== zeroAddress
|
|
@@ -25,10 +25,7 @@ async function applyNew1155Defaults(
|
|
|
25
25
|
: BigInt(props.maxSupply),
|
|
26
26
|
royaltyBPS: props.royaltyBPS || 1000,
|
|
27
27
|
tokenMetadataURI: props.tokenMetadataURI,
|
|
28
|
-
salesConfig:
|
|
29
|
-
props.salesConfig,
|
|
30
|
-
contractName,
|
|
31
|
-
),
|
|
28
|
+
salesConfig: getSalesConfigWithDefaults(props.salesConfig, contractName),
|
|
32
29
|
};
|
|
33
30
|
}
|
|
34
31
|
|
|
@@ -113,7 +110,7 @@ function makeAdminMintCall({
|
|
|
113
110
|
});
|
|
114
111
|
}
|
|
115
112
|
|
|
116
|
-
export
|
|
113
|
+
export function constructCreate1155TokenCalls(
|
|
117
114
|
props: CreateNew1155TokenProps &
|
|
118
115
|
ContractProps & {
|
|
119
116
|
ownerAddress: Address;
|
|
@@ -121,11 +118,11 @@ export async function constructCreate1155TokenCalls(
|
|
|
121
118
|
} & {
|
|
122
119
|
contractName: string;
|
|
123
120
|
},
|
|
124
|
-
):
|
|
121
|
+
): {
|
|
125
122
|
setupActions: `0x${string}`[];
|
|
126
123
|
newToken: New1155Token;
|
|
127
124
|
minter: Address;
|
|
128
|
-
}
|
|
125
|
+
} {
|
|
129
126
|
const {
|
|
130
127
|
chainId,
|
|
131
128
|
nextTokenId,
|
|
@@ -134,7 +131,7 @@ export async function constructCreate1155TokenCalls(
|
|
|
134
131
|
contractVersion,
|
|
135
132
|
} = props;
|
|
136
133
|
|
|
137
|
-
const new1155TokenPropsWithDefaults =
|
|
134
|
+
const new1155TokenPropsWithDefaults = applyNew1155Defaults(
|
|
138
135
|
props,
|
|
139
136
|
ownerAddress,
|
|
140
137
|
props.contractName,
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
zoraCreator1155ImplABI,
|
|
6
6
|
zoraTimedSaleStrategyAddress,
|
|
7
7
|
} from "@zoralabs/protocol-deployments";
|
|
8
|
-
import { forkUrls, makeAnvilTest } from "src/anvil";
|
|
8
|
+
import { forkUrls, makeAnvilTest, writeContractWithRetries } from "src/anvil";
|
|
9
9
|
import { createCollectorClient, createCreatorClient } from "src/sdk";
|
|
10
10
|
import { getAllowListEntry } from "src/allow-list/allow-list-client";
|
|
11
11
|
import {
|
|
@@ -370,11 +370,7 @@ describe("mint-helper", () => {
|
|
|
370
370
|
|
|
371
371
|
const { request: createRequest } =
|
|
372
372
|
await publicClient.simulateContract(parameters);
|
|
373
|
-
|
|
374
|
-
const createReceipt = await publicClient.waitForTransactionReceipt({
|
|
375
|
-
hash: createHash,
|
|
376
|
-
});
|
|
377
|
-
expect(createReceipt.status).toBe("success");
|
|
373
|
+
await writeContractWithRetries(createRequest, walletClient, publicClient);
|
|
378
374
|
|
|
379
375
|
const zoraCreateToken: TokenQueryResult = {
|
|
380
376
|
contract: {
|