@zoralabs/protocol-sdk 0.11.3-COMMENTS.0 → 0.11.3-COMMENTS.3
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 +22 -0
- package/dist/anvil.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/types.d.ts +1 -1
- package/dist/create/types.d.ts.map +1 -1
- package/dist/fixtures/contract-setup.d.ts +2 -0
- package/dist/fixtures/contract-setup.d.ts.map +1 -1
- package/dist/fixtures/secondary.d.ts +13 -0
- package/dist/fixtures/secondary.d.ts.map +1 -0
- package/dist/index.cjs +60 -59
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +7 -6
- package/dist/index.js.map +1 -1
- package/dist/preminter.d.ts +2 -2
- package/dist/preminter.d.ts.map +1 -1
- package/dist/test-utils.d.ts +3 -1
- package/dist/test-utils.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/comments/comments.test.ts +343 -0
- package/src/create/1155-create-helper.test.ts +9 -14
- package/src/create/1155-create-helper.ts +2 -2
- package/src/create/minter-defaults.ts +3 -4
- package/src/create/types.ts +1 -1
- package/src/fixtures/contract-setup.ts +4 -4
- package/src/fixtures/secondary.ts +69 -0
- package/src/mint/subgraph-mint-getter.ts +1 -1
- package/src/rewards/rewards-client.test.ts +2 -2
- package/src/secondary/secondary-client.test.ts +39 -70
- package/src/test-utils.ts +12 -0
- package/dist/create/1155-create-helper.test.d.ts +0 -3
- package/dist/create/1155-create-helper.test.d.ts.map +0 -1
package/dist/preminter.d.ts
CHANGED
|
@@ -27,8 +27,8 @@ export declare const preminterTypedDataDefinition: ({ verifyingContract, premint
|
|
|
27
27
|
domain?: {
|
|
28
28
|
chainId?: number | undefined;
|
|
29
29
|
name?: string | undefined;
|
|
30
|
-
salt?: import("
|
|
31
|
-
verifyingContract?: Address | undefined;
|
|
30
|
+
salt?: import("viem").ResolvedRegister["bytesType"]["outputs"] | undefined;
|
|
31
|
+
verifyingContract?: import("viem").Address | undefined;
|
|
32
32
|
version?: string | undefined;
|
|
33
33
|
} | undefined;
|
|
34
34
|
message: Record<string, unknown>;
|
package/dist/preminter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preminter.d.ts","sourceRoot":"","sources":["../src/preminter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,6BAA6B,EAAE,MAAM,SAAS,CAAC;AAC5E,OAAO,EACL,qCAAqC,IAAI,YAAY,EAEtD,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAGL,GAAG,EACH,YAAY,EACb,MAAM,MAAM,CAAC;AAEd,KAAK,aAAa,GAAG,kBAAkB,CACrC,OAAO,YAAY,EACnB,WAAW,CACZ,CAAC,QAAQ,CAAC,CAAC;AAEZ,KAAK,sBAAsB,GAAG,6BAA6B,CAAC,aAAa,CAAC,CAAC;AAE3E,MAAM,MAAM,sBAAsB,GAAG,sBAAsB,CAAC,CAAC,CAAC,CAAC;AAC/D,MAAM,MAAM,aAAa,GAAG,sBAAsB,CAAC,CAAC,CAAC,CAAC;AACtD,MAAM,MAAM,mBAAmB,GAAG,aAAa,CAAC,aAAa,CAAC,CAAC;AAI/D,eAAO,MAAM,4BAA4B,mDAItC;IACD,iBAAiB,EAAE,OAAO,CAAC;IAC3B,aAAa,EAAE,aAAa,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;CACjB;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"preminter.d.ts","sourceRoot":"","sources":["../src/preminter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,6BAA6B,EAAE,MAAM,SAAS,CAAC;AAC5E,OAAO,EACL,qCAAqC,IAAI,YAAY,EAEtD,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAGL,GAAG,EACH,YAAY,EACb,MAAM,MAAM,CAAC;AAEd,KAAK,aAAa,GAAG,kBAAkB,CACrC,OAAO,YAAY,EACnB,WAAW,CACZ,CAAC,QAAQ,CAAC,CAAC;AAEZ,KAAK,sBAAsB,GAAG,6BAA6B,CAAC,aAAa,CAAC,CAAC;AAE3E,MAAM,MAAM,sBAAsB,GAAG,sBAAsB,CAAC,CAAC,CAAC,CAAC;AAC/D,MAAM,MAAM,aAAa,GAAG,sBAAsB,CAAC,CAAC,CAAC,CAAC;AACtD,MAAM,MAAM,mBAAmB,GAAG,aAAa,CAAC,aAAa,CAAC,CAAC;AAI/D,eAAO,MAAM,4BAA4B,mDAItC;IACD,iBAAiB,EAAE,OAAO,CAAC;IAC3B,aAAa,EAAE,aAAa,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;CACjB;;;;;;;;;;;;;;;;eAsGgoE,4CAA8B;;;;;CAzD9pE,CAAC;AAEF,wBAAsB,kBAAkB,CAAC,EACvC,eAAe,EACf,qBAAqB,EACrB,aAAa,EACb,SAAS,EACT,OAAO,EACP,YAAY,GACb,EAAE;IACD,eAAe,EAAE,OAAO,CAAC;IACzB,qBAAqB,EAAE,OAAO,CAAC;IAC/B,aAAa,EAAE,aAAa,CAAC;IAC7B,SAAS,EAAE,GAAG,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,YAAY,CAAC;CAC5B,GAAG,OAAO,CAAC;IACV,YAAY,EAAE,OAAO,CAAC;IACtB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC,CAqCD"}
|
package/dist/test-utils.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { zoraCreator1155FactoryImplAddress } from "@zoralabs/protocol-deployments";
|
|
2
2
|
import { Address, Hex, PublicClient } from "viem";
|
|
3
|
-
|
|
3
|
+
import { NewContractParams } from "./create/types";
|
|
4
|
+
export declare const waitForSuccess: (hash: Hex, publicClient: PublicClient) => Promise<import("viem").TransactionReceipt>;
|
|
4
5
|
export declare const getFixedPricedMinter: ({ publicClient, chainId, }: {
|
|
5
6
|
publicClient: PublicClient;
|
|
6
7
|
chainId: keyof typeof zoraCreator1155FactoryImplAddress;
|
|
@@ -8,4 +9,5 @@ export declare const getFixedPricedMinter: ({ publicClient, chainId, }: {
|
|
|
8
9
|
export declare const fixedPriceMinterMinterArguments: ({ mintRecipient, }: {
|
|
9
10
|
mintRecipient: Address;
|
|
10
11
|
}) => `0x${string}`;
|
|
12
|
+
export declare function randomNewContract(): NewContractParams;
|
|
11
13
|
//# sourceMappingURL=test-utils.d.ts.map
|
package/dist/test-utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../src/test-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iCAAiC,EAClC,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,OAAO,EACP,GAAG,EACH,YAAY,EAGb,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../src/test-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iCAAiC,EAClC,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,OAAO,EACP,GAAG,EACH,YAAY,EAGb,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAGnD,eAAO,MAAM,cAAc,SAAgB,GAAG,gBAAgB,YAAY,+CAQzE,CAAC;AAEF,eAAO,MAAM,oBAAoB,+BAG9B;IACD,YAAY,EAAE,YAAY,CAAC;IAC3B,OAAO,EAAE,MAAM,OAAO,iCAAiC,CAAC;CACzD,2BAKG,CAAC;AAEL,eAAO,MAAM,+BAA+B,uBAEzC;IACD,aAAa,EAAE,OAAO,CAAC;CACxB,kBAAwE,CAAC;AAI1E,wBAAgB,iBAAiB,IAAI,iBAAiB,CAKrD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zoralabs/protocol-sdk",
|
|
3
|
-
"version": "0.11.3-COMMENTS.
|
|
3
|
+
"version": "0.11.3-COMMENTS.3",
|
|
4
4
|
"repository": "https://github.com/ourzora/zora-protocol",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"abitype": "^1.0.2",
|
|
20
|
-
"@zoralabs/protocol-deployments": "^0.3.5-COMMENTS.
|
|
20
|
+
"@zoralabs/protocol-deployments": "^0.3.5-COMMENTS.3"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"viem": "^2.
|
|
23
|
+
"viem": "^2.21.21"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@lavamoat/preinstall-always-fail": "2.0.0",
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import { describe, expect } from "vitest";
|
|
2
|
+
import { forkUrls, makeAnvilTest, writeContractWithRetries } from "src/anvil";
|
|
3
|
+
import { base, zora, zoraSepolia } from "viem/chains";
|
|
4
|
+
import {
|
|
5
|
+
commentsABI,
|
|
6
|
+
commentsAddress,
|
|
7
|
+
emptyCommentIdentifier,
|
|
8
|
+
PermitComment,
|
|
9
|
+
PermitSparkComment,
|
|
10
|
+
sparkValue,
|
|
11
|
+
CommentIdentifier,
|
|
12
|
+
permitSparkCommentTypedDataDefinition,
|
|
13
|
+
permitTimedSaleMintAndCommentTypedDataDefinition,
|
|
14
|
+
PermitTimedSaleMintAndComment,
|
|
15
|
+
callerAndCommenterAddress as callerAndCommenterAddresses,
|
|
16
|
+
callerAndCommenterABI,
|
|
17
|
+
zoraCreator1155ImplABI,
|
|
18
|
+
} from "@zoralabs/protocol-deployments";
|
|
19
|
+
import {
|
|
20
|
+
Address,
|
|
21
|
+
keccak256,
|
|
22
|
+
toBytes,
|
|
23
|
+
zeroAddress,
|
|
24
|
+
parseEther,
|
|
25
|
+
TransactionReceipt,
|
|
26
|
+
parseEventLogs,
|
|
27
|
+
hashTypedData,
|
|
28
|
+
} from "viem";
|
|
29
|
+
import { createCreatorClient } from "src/sdk";
|
|
30
|
+
import { randomNewContract, waitForSuccess } from "src/test-utils";
|
|
31
|
+
import { permitCommentTypedDataDefinition } from "@zoralabs/protocol-deployments";
|
|
32
|
+
import { demoTokenMetadataURI } from "src/fixtures/contract-setup";
|
|
33
|
+
|
|
34
|
+
const getCommentIdentifierFromReceipt = (
|
|
35
|
+
receipt: TransactionReceipt,
|
|
36
|
+
): CommentIdentifier => {
|
|
37
|
+
const logs = parseEventLogs({
|
|
38
|
+
abi: commentsABI,
|
|
39
|
+
logs: receipt.logs,
|
|
40
|
+
eventName: "Commented",
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
if (logs.length === 0) {
|
|
44
|
+
throw new Error("No Commented event found in receipt");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return logs[0]!.args.commentIdentifier;
|
|
48
|
+
};
|
|
49
|
+
const randomNonce = () => keccak256(toBytes(Math.round(Math.random() * 1000)));
|
|
50
|
+
const thirtySecondsFromNow =
|
|
51
|
+
BigInt(Math.round(new Date().getTime() / 1000)) + 30n;
|
|
52
|
+
// todo: move this to protocol-deployments
|
|
53
|
+
describe("comments", () => {
|
|
54
|
+
makeAnvilTest({
|
|
55
|
+
forkUrl: forkUrls.zoraMainnet,
|
|
56
|
+
forkBlockNumber: 21297211,
|
|
57
|
+
anvilChainId: zora.id,
|
|
58
|
+
})(
|
|
59
|
+
"can sign and execute a cross-chain comment, and sign and execute a cross-chain spark comment",
|
|
60
|
+
async ({
|
|
61
|
+
viemClients: { publicClient, walletClient, chain, testClient },
|
|
62
|
+
}) => {
|
|
63
|
+
// Get the chain ID and set up addresses for different roles
|
|
64
|
+
const chainId = chain.id;
|
|
65
|
+
const [
|
|
66
|
+
collectorAddress,
|
|
67
|
+
creatorAddress,
|
|
68
|
+
executorAddress,
|
|
69
|
+
sparkerAddress,
|
|
70
|
+
] = (await walletClient.getAddresses()!) as [
|
|
71
|
+
Address,
|
|
72
|
+
Address,
|
|
73
|
+
Address,
|
|
74
|
+
Address,
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
// Create a creator client for interacting with the protocol
|
|
78
|
+
const creatorClient = createCreatorClient({
|
|
79
|
+
chainId,
|
|
80
|
+
publicClient,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Step 1: Create a new 1155 contract and token
|
|
84
|
+
const { contractAddress, newTokenId, parameters, prepareMint } =
|
|
85
|
+
await creatorClient.create1155({
|
|
86
|
+
contract: randomNewContract(),
|
|
87
|
+
token: {
|
|
88
|
+
tokenMetadataURI: demoTokenMetadataURI,
|
|
89
|
+
},
|
|
90
|
+
account: creatorAddress,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// Deploy the new contract
|
|
94
|
+
const { request } = await publicClient.simulateContract(parameters);
|
|
95
|
+
await writeContractWithRetries({
|
|
96
|
+
request,
|
|
97
|
+
walletClient,
|
|
98
|
+
publicClient,
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// Prepare to mint a token
|
|
102
|
+
const { parameters: collectParameters } = await prepareMint({
|
|
103
|
+
quantityToMint: 1n,
|
|
104
|
+
minterAccount: collectorAddress,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// Step 2: Mint an 1155 token on the new contract
|
|
108
|
+
const { request: mintRequest } =
|
|
109
|
+
await publicClient.simulateContract(collectParameters);
|
|
110
|
+
await writeContractWithRetries({
|
|
111
|
+
request: mintRequest,
|
|
112
|
+
walletClient,
|
|
113
|
+
publicClient,
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// Set up cross-chain comment parameters
|
|
117
|
+
const sourceChainId = base.id; // The chain ID where the comment originates
|
|
118
|
+
|
|
119
|
+
const commentsAddressForChainId =
|
|
120
|
+
commentsAddress[chainId as keyof typeof commentsAddress];
|
|
121
|
+
|
|
122
|
+
// Step 3: Prepare a cross-chain comment
|
|
123
|
+
const permitComment: PermitComment = {
|
|
124
|
+
sourceChainId,
|
|
125
|
+
contractAddress,
|
|
126
|
+
destinationChainId: chainId,
|
|
127
|
+
tokenId: newTokenId,
|
|
128
|
+
commenter: collectorAddress,
|
|
129
|
+
text: "hello world",
|
|
130
|
+
deadline: thirtySecondsFromNow,
|
|
131
|
+
nonce: randomNonce(),
|
|
132
|
+
referrer: zeroAddress,
|
|
133
|
+
commenterSmartWallet: zeroAddress,
|
|
134
|
+
replyTo: emptyCommentIdentifier(),
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// Generate typed data for signing
|
|
138
|
+
const typedData = permitCommentTypedDataDefinition(permitComment);
|
|
139
|
+
|
|
140
|
+
expect(typedData.domain!.chainId).toEqual(sourceChainId);
|
|
141
|
+
expect(typedData.account).toEqual(collectorAddress);
|
|
142
|
+
expect(typedData.domain!.verifyingContract).toEqual(
|
|
143
|
+
commentsAddressForChainId,
|
|
144
|
+
);
|
|
145
|
+
expect(typedData.domain!.verifyingContract).toEqual(
|
|
146
|
+
commentsAddressForChainId,
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
const hashed = await publicClient.readContract({
|
|
150
|
+
abi: commentsABI,
|
|
151
|
+
address: commentsAddressForChainId,
|
|
152
|
+
functionName: "hashPermitComment",
|
|
153
|
+
args: [permitComment],
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
expect(hashed).toEqual(hashTypedData(typedData));
|
|
157
|
+
|
|
158
|
+
// Ensure the commenter has enough balance for the spark value
|
|
159
|
+
await testClient.setBalance({
|
|
160
|
+
address: collectorAddress,
|
|
161
|
+
value: sparkValue(),
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
// Step 4: Sign the cross-chain comment
|
|
165
|
+
const signature = await walletClient.signTypedData(typedData);
|
|
166
|
+
|
|
167
|
+
// Ensure the executor has enough balance to execute the transaction
|
|
168
|
+
await testClient.setBalance({
|
|
169
|
+
address: executorAddress,
|
|
170
|
+
value: parseEther("1"),
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
// Step 5: Simulate and execute the cross-chain comment
|
|
174
|
+
const { request: commentRequest } = await publicClient.simulateContract({
|
|
175
|
+
abi: commentsABI,
|
|
176
|
+
address: commentsAddressForChainId,
|
|
177
|
+
functionName: "permitComment",
|
|
178
|
+
args: [permitComment, signature],
|
|
179
|
+
account: executorAddress,
|
|
180
|
+
value: sparkValue(),
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
const commentHash = await walletClient.writeContract(commentRequest);
|
|
184
|
+
const receipt = await publicClient.waitForTransactionReceipt({
|
|
185
|
+
hash: commentHash,
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
expect(receipt.status).toBe("success");
|
|
189
|
+
|
|
190
|
+
// Extract the comment identifier from the transaction receipt
|
|
191
|
+
const commentIdentifier = getCommentIdentifierFromReceipt(receipt);
|
|
192
|
+
|
|
193
|
+
// Step 6: Prepare a spark (like) for the comment
|
|
194
|
+
const sparkComment: PermitSparkComment = {
|
|
195
|
+
sparksQuantity: 3n,
|
|
196
|
+
sparker: sparkerAddress,
|
|
197
|
+
deadline: thirtySecondsFromNow,
|
|
198
|
+
nonce: randomNonce(),
|
|
199
|
+
referrer: zeroAddress,
|
|
200
|
+
sourceChainId,
|
|
201
|
+
destinationChainId: chainId,
|
|
202
|
+
comment: commentIdentifier,
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
const sparkTypedData =
|
|
206
|
+
permitSparkCommentTypedDataDefinition(sparkComment);
|
|
207
|
+
|
|
208
|
+
// Step 7: Sign the spark comment
|
|
209
|
+
const sparkSignature = await walletClient.signTypedData(sparkTypedData);
|
|
210
|
+
|
|
211
|
+
// Step 8: Simulate and execute the spark comment
|
|
212
|
+
const { request: sparkRequest } = await publicClient.simulateContract({
|
|
213
|
+
abi: commentsABI,
|
|
214
|
+
address: commentsAddressForChainId,
|
|
215
|
+
functionName: "permitSparkComment",
|
|
216
|
+
args: [sparkComment, sparkSignature],
|
|
217
|
+
account: executorAddress,
|
|
218
|
+
value: sparkValue() * sparkComment.sparksQuantity,
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
const sparkHash = await walletClient.writeContract(sparkRequest);
|
|
222
|
+
|
|
223
|
+
await waitForSuccess(sparkHash, publicClient);
|
|
224
|
+
|
|
225
|
+
// Step 9: Verify the spark count
|
|
226
|
+
const sparkCount = await publicClient.readContract({
|
|
227
|
+
abi: commentsABI,
|
|
228
|
+
address: commentsAddressForChainId,
|
|
229
|
+
functionName: "commentSparksQuantity",
|
|
230
|
+
args: [commentIdentifier],
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
expect(sparkCount).toEqual(sparkComment.sparksQuantity);
|
|
234
|
+
},
|
|
235
|
+
40_000,
|
|
236
|
+
);
|
|
237
|
+
makeAnvilTest({
|
|
238
|
+
forkUrl: forkUrls.zoraMainnet,
|
|
239
|
+
forkBlockNumber: 21297211,
|
|
240
|
+
anvilChainId: zora.id,
|
|
241
|
+
})(
|
|
242
|
+
"can sign and execute a cross-chain timed sale mint and comment",
|
|
243
|
+
async ({
|
|
244
|
+
viemClients: { publicClient, walletClient, chain, testClient },
|
|
245
|
+
}) => {
|
|
246
|
+
// Get the chain ID and set up addresses for different roles
|
|
247
|
+
const chainId = chain.id;
|
|
248
|
+
const [commenterAddress, executorAddress] =
|
|
249
|
+
(await walletClient.getAddresses()!) as [Address, Address, Address];
|
|
250
|
+
|
|
251
|
+
// Create a creator client for interacting with the protocol
|
|
252
|
+
const creatorClient = createCreatorClient({
|
|
253
|
+
chainId,
|
|
254
|
+
publicClient,
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
// Step 1: Create a new 1155 contract and token
|
|
258
|
+
const { contractAddress, newTokenId, parameters } =
|
|
259
|
+
await creatorClient.create1155({
|
|
260
|
+
contract: randomNewContract(),
|
|
261
|
+
token: {
|
|
262
|
+
tokenMetadataURI: demoTokenMetadataURI,
|
|
263
|
+
},
|
|
264
|
+
account: commenterAddress,
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
// Deploy the new contract
|
|
268
|
+
const { request } = await publicClient.simulateContract(parameters);
|
|
269
|
+
await writeContractWithRetries({
|
|
270
|
+
request,
|
|
271
|
+
walletClient,
|
|
272
|
+
publicClient,
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
// Step 2: Prepare the permit data for timed sale mint and comment
|
|
276
|
+
const thirtySecondsFromNow = BigInt(Math.floor(Date.now() / 1000) + 30);
|
|
277
|
+
const quantity = 3n;
|
|
278
|
+
const mintReferral = zeroAddress;
|
|
279
|
+
const comment = "This is a test comment for timed sale mint";
|
|
280
|
+
|
|
281
|
+
const permitTimedSaleMintAndComment: PermitTimedSaleMintAndComment = {
|
|
282
|
+
commenter: commenterAddress,
|
|
283
|
+
quantity,
|
|
284
|
+
collection: contractAddress,
|
|
285
|
+
tokenId: newTokenId,
|
|
286
|
+
mintReferral,
|
|
287
|
+
comment,
|
|
288
|
+
deadline: thirtySecondsFromNow,
|
|
289
|
+
nonce: randomNonce(),
|
|
290
|
+
sourceChainId: chainId,
|
|
291
|
+
destinationChainId: chainId,
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
// Step 3: Generate the typed data for signing
|
|
295
|
+
const typedData = permitTimedSaleMintAndCommentTypedDataDefinition(
|
|
296
|
+
permitTimedSaleMintAndComment,
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
// Step 4: Sign the typed data
|
|
300
|
+
const signature = await walletClient.signTypedData(typedData);
|
|
301
|
+
|
|
302
|
+
await testClient.setBalance({
|
|
303
|
+
address: executorAddress,
|
|
304
|
+
value: parseEther("1"),
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
// Step 5: Simulate and execute the permitTimedSaleMintAndComment function
|
|
308
|
+
const callerAndCommenterAddress =
|
|
309
|
+
callerAndCommenterAddresses[
|
|
310
|
+
chainId as keyof typeof callerAndCommenterAddresses
|
|
311
|
+
];
|
|
312
|
+
const { request: permitRequest } = await publicClient.simulateContract({
|
|
313
|
+
abi: callerAndCommenterABI,
|
|
314
|
+
address: callerAndCommenterAddress,
|
|
315
|
+
functionName: "permitTimedSaleMintAndComment",
|
|
316
|
+
args: [permitTimedSaleMintAndComment, signature],
|
|
317
|
+
account: executorAddress,
|
|
318
|
+
value: quantity * parseEther("0.000111"),
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
const receipt = await writeContractWithRetries({
|
|
322
|
+
publicClient,
|
|
323
|
+
walletClient,
|
|
324
|
+
request: permitRequest,
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
// Step 6: Verify the comment was created
|
|
328
|
+
const commentIdentifier = getCommentIdentifierFromReceipt(receipt);
|
|
329
|
+
expect(commentIdentifier).toBeDefined();
|
|
330
|
+
|
|
331
|
+
// Step 7: Verify the token was minted
|
|
332
|
+
const balance = await publicClient.readContract({
|
|
333
|
+
abi: zoraCreator1155ImplABI,
|
|
334
|
+
address: contractAddress,
|
|
335
|
+
functionName: "balanceOf",
|
|
336
|
+
args: [commenterAddress, newTokenId],
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
expect(balance).toEqual(quantity);
|
|
340
|
+
},
|
|
341
|
+
40_000, // Increased timeout to 30 seconds
|
|
342
|
+
);
|
|
343
|
+
});
|
|
@@ -16,16 +16,13 @@ import { forkUrls, makeAnvilTest, writeContractWithRetries } from "src/anvil";
|
|
|
16
16
|
import { zora } from "viem/chains";
|
|
17
17
|
import { AllowList } from "src/allow-list/types";
|
|
18
18
|
import { createAllowList } from "src/allow-list/allow-list-client";
|
|
19
|
-
import { NewContractParams } from "./types";
|
|
20
19
|
import { SubgraphContractGetter } from "./contract-getter";
|
|
21
20
|
import {
|
|
22
21
|
DEFAULT_MINIMUM_MARKET_ETH,
|
|
23
22
|
DEFAULT_MARKET_COUNTDOWN,
|
|
24
23
|
} from "./minter-defaults";
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u";
|
|
28
|
-
export const demoContractMetadataURI = "ipfs://DUMMY/contract.json";
|
|
24
|
+
import { randomNewContract } from "src/test-utils";
|
|
25
|
+
import { demoTokenMetadataURI } from "src/fixtures/contract-setup";
|
|
29
26
|
|
|
30
27
|
const anvilTest = makeAnvilTest({
|
|
31
28
|
forkUrl: forkUrls.zoraMainnet,
|
|
@@ -56,13 +53,6 @@ const minterIsMinterOnToken = async ({
|
|
|
56
53
|
});
|
|
57
54
|
};
|
|
58
55
|
|
|
59
|
-
function randomNewContract(): NewContractParams {
|
|
60
|
-
return {
|
|
61
|
-
name: `testContract-${Math.round(Math.random() * 1_000_000)}`,
|
|
62
|
-
uri: demoContractMetadataURI,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
56
|
describe("create-helper", () => {
|
|
67
57
|
anvilTest(
|
|
68
58
|
"when no sales config is provided, it creates a new 1155 contract and token using the timed sale strategy",
|
|
@@ -101,7 +91,9 @@ describe("create-helper", () => {
|
|
|
101
91
|
publicClient,
|
|
102
92
|
});
|
|
103
93
|
expect(receipt).not.toBeNull();
|
|
104
|
-
expect(receipt.to).to.equal(
|
|
94
|
+
expect(receipt.to?.toLowerCase()).to.equal(
|
|
95
|
+
"0x777777c338d93e2c7adf08d102d45ca7cc4ed021".toLowerCase(),
|
|
96
|
+
);
|
|
105
97
|
expect(getTokenIdFromCreateReceipt(receipt)).to.be.equal(1n);
|
|
106
98
|
expect(getContractAddressFromReceipt(receipt)).to.be.equal(
|
|
107
99
|
contractAddress,
|
|
@@ -299,7 +291,10 @@ describe("create-helper", () => {
|
|
|
299
291
|
walletClient,
|
|
300
292
|
publicClient,
|
|
301
293
|
});
|
|
302
|
-
|
|
294
|
+
|
|
295
|
+
expect(receipt.to?.toLowerCase()).to.equal(
|
|
296
|
+
"0x777777c338d93e2c7adf08d102d45ca7cc4ed021".toLowerCase(),
|
|
297
|
+
);
|
|
303
298
|
expect(getTokenIdFromCreateReceipt(receipt)).to.be.equal(newTokenId);
|
|
304
299
|
|
|
305
300
|
expect(
|
|
@@ -219,7 +219,7 @@ async function createNew1155ContractAndToken({
|
|
|
219
219
|
});
|
|
220
220
|
|
|
221
221
|
const contractAddress = await getDeterministicContractAddress({
|
|
222
|
-
account,
|
|
222
|
+
account: typeof account === "string" ? account : account.address,
|
|
223
223
|
publicClient,
|
|
224
224
|
setupActions: tokenSetupActions,
|
|
225
225
|
chainId,
|
|
@@ -327,7 +327,7 @@ function prepareSetupActions({
|
|
|
327
327
|
setupActions: tokenSetupActions,
|
|
328
328
|
} = constructCreate1155TokenCalls({
|
|
329
329
|
chainId: chainId,
|
|
330
|
-
ownerAddress: account,
|
|
330
|
+
ownerAddress: typeof account === "string" ? account : account.address,
|
|
331
331
|
contractVersion,
|
|
332
332
|
nextTokenId,
|
|
333
333
|
...token,
|
|
@@ -9,10 +9,9 @@ import {
|
|
|
9
9
|
ConcreteSalesConfig,
|
|
10
10
|
TimedSaleParamsType,
|
|
11
11
|
} from "./types";
|
|
12
|
-
|
|
13
|
-
//
|
|
14
|
-
export const DEFAULT_MINIMUM_MARKET_ETH =
|
|
15
|
-
|
|
12
|
+
import { parseEther } from "viem";
|
|
13
|
+
// 1111 mints worth of market reward eth - 0.0000111 eth * 1,111 = 0.0123321 eth
|
|
14
|
+
export const DEFAULT_MINIMUM_MARKET_ETH = parseEther("0.0123321");
|
|
16
15
|
// 24 hour countdown
|
|
17
16
|
export const DEFAULT_MARKET_COUNTDOWN = BigInt(24 * 60 * 60);
|
|
18
17
|
|
package/src/create/types.ts
CHANGED
|
@@ -63,7 +63,7 @@ export type SalesConfigParamsType =
|
|
|
63
63
|
| TimedSaleParamsType;
|
|
64
64
|
|
|
65
65
|
export type CreateNew1155ParamsBase = {
|
|
66
|
-
account: Address;
|
|
66
|
+
account: Address | Account;
|
|
67
67
|
getAdditionalSetupActions?: (args: { tokenId: bigint }) => Hex[];
|
|
68
68
|
token: CreateNew1155TokenProps;
|
|
69
69
|
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Address, Chain, PublicClient, WalletClient } from "viem";
|
|
2
2
|
import { simulateAndWriteContractWithRetries } from "src/anvil";
|
|
3
3
|
import { createCreatorClient } from "src/sdk";
|
|
4
|
-
import {
|
|
5
|
-
demoContractMetadataURI,
|
|
6
|
-
demoTokenMetadataURI,
|
|
7
|
-
} from "src/create/1155-create-helper.test";
|
|
8
4
|
import { SubgraphMintGetter } from "src/mint/subgraph-mint-getter";
|
|
9
5
|
import { SubgraphRewardsGetter } from "../rewards/subgraph-rewards-getter";
|
|
10
6
|
|
|
7
|
+
export const demoTokenMetadataURI =
|
|
8
|
+
"ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u";
|
|
9
|
+
export const demoContractMetadataURI = "ipfs://DUMMY/contract.json";
|
|
10
|
+
|
|
11
11
|
export async function setupContractAndToken({
|
|
12
12
|
chain,
|
|
13
13
|
publicClient,
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Address, Account, PublicClient, TestClient, WalletClient } from "viem";
|
|
2
|
+
import { CollectorClient } from "../sdk";
|
|
3
|
+
import { simulateAndWriteContractWithRetries } from "../anvil";
|
|
4
|
+
import { makeContractParameters } from "../utils";
|
|
5
|
+
import {
|
|
6
|
+
zoraTimedSaleStrategyABI,
|
|
7
|
+
zoraTimedSaleStrategyAddress,
|
|
8
|
+
} from "@zoralabs/protocol-deployments";
|
|
9
|
+
|
|
10
|
+
export async function advanceToSaleAndAndLaunchMarket({
|
|
11
|
+
contractAddress,
|
|
12
|
+
tokenId,
|
|
13
|
+
testClient,
|
|
14
|
+
publicClient,
|
|
15
|
+
walletClient,
|
|
16
|
+
collectorClient,
|
|
17
|
+
chainId,
|
|
18
|
+
account,
|
|
19
|
+
}: {
|
|
20
|
+
contractAddress: Address;
|
|
21
|
+
tokenId: bigint;
|
|
22
|
+
testClient: TestClient;
|
|
23
|
+
publicClient: PublicClient;
|
|
24
|
+
walletClient: WalletClient;
|
|
25
|
+
collectorClient: CollectorClient;
|
|
26
|
+
chainId: number;
|
|
27
|
+
account: Address | Account;
|
|
28
|
+
}) {
|
|
29
|
+
const saleInfo = await collectorClient.getSecondaryInfo({
|
|
30
|
+
contract: contractAddress,
|
|
31
|
+
tokenId,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
if (!saleInfo) {
|
|
35
|
+
throw new Error("Sale not set");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!saleInfo.saleEnd) {
|
|
39
|
+
throw new Error("Sale end not set");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const saleEnd = saleInfo.saleEnd;
|
|
43
|
+
|
|
44
|
+
// advance to end of sale
|
|
45
|
+
await testClient.setNextBlockTimestamp({
|
|
46
|
+
timestamp: saleEnd,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
await testClient.mine({
|
|
50
|
+
blocks: 1,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// advance to end of sale
|
|
54
|
+
// launch the market
|
|
55
|
+
await simulateAndWriteContractWithRetries({
|
|
56
|
+
parameters: makeContractParameters({
|
|
57
|
+
abi: zoraTimedSaleStrategyABI,
|
|
58
|
+
functionName: "launchMarket",
|
|
59
|
+
args: [contractAddress, tokenId],
|
|
60
|
+
address:
|
|
61
|
+
zoraTimedSaleStrategyAddress[
|
|
62
|
+
chainId as keyof typeof zoraTimedSaleStrategyAddress
|
|
63
|
+
],
|
|
64
|
+
account: account,
|
|
65
|
+
}),
|
|
66
|
+
publicClient,
|
|
67
|
+
walletClient,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
@@ -180,7 +180,7 @@ function getTargetStrategy({
|
|
|
180
180
|
);
|
|
181
181
|
|
|
182
182
|
const stillValidSalesStrategies = parsedStrategies.filter(
|
|
183
|
-
(strategy) => strategy.saleActive,
|
|
183
|
+
(strategy) => strategy.saleActive || strategy.secondaryMarketActive,
|
|
184
184
|
);
|
|
185
185
|
|
|
186
186
|
const saleStrategies = stillValidSalesStrategies.sort((a, b) =>
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
import { makeContractParameters } from "src/utils";
|
|
19
19
|
import { mockRewardsQueryResults } from "src/fixtures/rewards-query-results";
|
|
20
20
|
import { setupContractAndToken } from "src/fixtures/contract-setup";
|
|
21
|
-
import { advanceToSaleAndAndLaunchMarket } from "src/
|
|
21
|
+
import { advanceToSaleAndAndLaunchMarket } from "src/fixtures/secondary";
|
|
22
22
|
|
|
23
23
|
describe("rewardsClient", () => {
|
|
24
24
|
makeAnvilTest({
|
|
@@ -146,7 +146,7 @@ describe("rewardsClient", () => {
|
|
|
146
146
|
value: parseEther("100"),
|
|
147
147
|
});
|
|
148
148
|
|
|
149
|
-
const quantityToMint =
|
|
149
|
+
const quantityToMint = 1111n;
|
|
150
150
|
|
|
151
151
|
mintGetter.subgraphQuerier.query = vi
|
|
152
152
|
.fn<ISubgraphQuerier["query"]>()
|