@zoralabs/protocol-sdk 0.6.0 → 0.7.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/.turbo/turbo-build.log +6 -6
- package/CHANGELOG.md +6 -0
- package/dist/constants.d.ts +0 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/index.cjs +845 -407
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +829 -391
- package/dist/index.js.map +1 -1
- package/dist/mint/mint-client.d.ts +28 -4071
- package/dist/mint/mint-client.d.ts.map +1 -1
- package/dist/mint/mint-queries.d.ts +38 -0
- package/dist/mint/mint-queries.d.ts.map +1 -0
- package/dist/mint/mint-transactions.d.ts +20 -0
- package/dist/mint/mint-transactions.d.ts.map +1 -0
- package/dist/mint/subgraph-mint-getter.d.ts +14 -7
- package/dist/mint/subgraph-mint-getter.d.ts.map +1 -1
- package/dist/mint/subgraph-queries.d.ts +55 -0
- package/dist/mint/subgraph-queries.d.ts.map +1 -0
- package/dist/mint/types.d.ts +117 -19
- package/dist/mint/types.d.ts.map +1 -1
- package/dist/mint/utils.d.ts +2 -0
- package/dist/mint/utils.d.ts.map +1 -0
- package/dist/mints/mints-contracts.d.ts +3 -4494
- package/dist/mints/mints-contracts.d.ts.map +1 -1
- package/dist/premint/conversions.d.ts +12 -15
- package/dist/premint/conversions.d.ts.map +1 -1
- package/dist/premint/premint-api-client.d.ts +14 -11
- package/dist/premint/premint-api-client.d.ts.map +1 -1
- package/dist/premint/premint-client.d.ts +15 -5
- package/dist/premint/premint-client.d.ts.map +1 -1
- package/dist/premint/preminter.d.ts +1 -1
- package/dist/premint/preminter.d.ts.map +1 -1
- package/dist/sdk.d.ts +4 -2
- package/dist/sdk.d.ts.map +1 -1
- package/dist/types.d.ts +3 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +10 -2
- package/dist/utils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/constants.ts +0 -36
- package/src/create/1155-create-helper.test.ts +9 -7
- package/src/mint/mint-client.test.ts +96 -47
- package/src/mint/mint-client.ts +75 -343
- package/src/mint/mint-queries.ts +320 -0
- package/src/mint/mint-transactions.ts +253 -0
- package/src/mint/subgraph-mint-getter.ts +216 -123
- package/src/mint/subgraph-queries.ts +170 -0
- package/src/mint/types.ts +140 -23
- package/src/mint/utils.ts +14 -0
- package/src/premint/conversions.ts +26 -2
- package/src/premint/premint-api-client.ts +48 -16
- package/src/premint/premint-client.test.ts +29 -23
- package/src/premint/premint-client.ts +64 -36
- package/src/premint/preminter.ts +2 -3
- package/src/sdk.ts +7 -4
- package/src/types.ts +18 -0
- package/src/utils.ts +29 -28
- package/test-integration/setup-test-contracts.ts +96 -0
- package/test-integration/premint-client.test.ts +0 -148
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { describe, expect } from "vitest";
|
|
2
2
|
import { Address, erc20Abi, parseAbi, parseEther } from "viem";
|
|
3
|
-
import { zora } from "viem/chains";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
erc20MinterAddress as erc20MinterAddresses,
|
|
7
|
-
} from "@zoralabs/protocol-deployments";
|
|
8
|
-
import { anvilTest, forkUrls, makeAnvilTest } from "src/anvil";
|
|
3
|
+
import { zora, zoraSepolia } from "viem/chains";
|
|
4
|
+
import { zoraCreator1155ImplABI } from "@zoralabs/protocol-deployments";
|
|
5
|
+
import { forkUrls, makeAnvilTest } from "src/anvil";
|
|
9
6
|
import { createCollectorClient } from "src/sdk";
|
|
10
|
-
import { requestErc20ApprovalForMint } from "./mint-client";
|
|
11
7
|
|
|
12
8
|
const erc721ABI = parseAbi([
|
|
13
9
|
"function balanceOf(address owner) public view returns (uint256)",
|
|
14
10
|
] as const);
|
|
15
11
|
|
|
16
12
|
describe("mint-helper", () => {
|
|
17
|
-
|
|
13
|
+
makeAnvilTest({
|
|
14
|
+
forkBlockNumber: 16028671,
|
|
15
|
+
forkUrl: forkUrls.zoraMainnet,
|
|
16
|
+
anvilChainId: zora.id,
|
|
17
|
+
})(
|
|
18
18
|
"mints a new 1155 token",
|
|
19
19
|
async ({ viemClients }) => {
|
|
20
20
|
const { testClient, walletClient, publicClient } = viemClients;
|
|
@@ -31,15 +31,24 @@ describe("mint-helper", () => {
|
|
|
31
31
|
publicClient,
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
-
const {
|
|
35
|
-
minterAccount: creatorAccount,
|
|
36
|
-
tokenId: targetTokenId,
|
|
34
|
+
const { token: mintable, prepareMint } = await collectorClient.getToken({
|
|
37
35
|
tokenContract: targetContract,
|
|
38
36
|
mintType: "1155",
|
|
39
|
-
|
|
37
|
+
tokenId: targetTokenId,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
mintable.maxSupply;
|
|
41
|
+
mintable.totalMinted;
|
|
42
|
+
mintable.tokenURI;
|
|
43
|
+
mintable;
|
|
44
|
+
|
|
45
|
+
const { parameters, costs } = prepareMint({
|
|
46
|
+
minterAccount: creatorAccount,
|
|
40
47
|
quantityToMint: 1,
|
|
41
48
|
});
|
|
42
49
|
|
|
50
|
+
expect(costs.totalCostEth).toBe(1n * parseEther("0.000777"));
|
|
51
|
+
|
|
43
52
|
const oldBalance = await publicClient.readContract({
|
|
44
53
|
abi: zoraCreator1155ImplABI,
|
|
45
54
|
address: targetContract,
|
|
@@ -85,13 +94,24 @@ describe("mint-helper", () => {
|
|
|
85
94
|
publicClient,
|
|
86
95
|
});
|
|
87
96
|
|
|
88
|
-
const {
|
|
97
|
+
const { prepareMint } = await collectorClient.getToken({
|
|
89
98
|
tokenContract: targetContract,
|
|
99
|
+
mintType: "721",
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const quantityToMint = 3n;
|
|
103
|
+
|
|
104
|
+
const { parameters, costs } = prepareMint({
|
|
90
105
|
minterAccount: creatorAccount,
|
|
91
106
|
mintRecipient: creatorAccount,
|
|
92
|
-
quantityToMint
|
|
93
|
-
mintType: "721",
|
|
107
|
+
quantityToMint,
|
|
94
108
|
});
|
|
109
|
+
|
|
110
|
+
expect(costs.totalPurchaseCost).toBe(quantityToMint * parseEther(".08"));
|
|
111
|
+
expect(costs.totalCostEth).toBe(
|
|
112
|
+
quantityToMint * (parseEther("0.08") + parseEther("0.000777")),
|
|
113
|
+
);
|
|
114
|
+
|
|
95
115
|
const oldBalance = await publicClient.readContract({
|
|
96
116
|
abi: erc721ABI,
|
|
97
117
|
address: targetContract,
|
|
@@ -114,7 +134,7 @@ describe("mint-helper", () => {
|
|
|
114
134
|
});
|
|
115
135
|
|
|
116
136
|
expect(oldBalance).to.be.equal(0n);
|
|
117
|
-
expect(newBalance).to.be.equal(
|
|
137
|
+
expect(newBalance).to.be.equal(quantityToMint);
|
|
118
138
|
},
|
|
119
139
|
12 * 1000,
|
|
120
140
|
);
|
|
@@ -139,42 +159,47 @@ describe("mint-helper", () => {
|
|
|
139
159
|
address: mockCollector,
|
|
140
160
|
});
|
|
141
161
|
|
|
142
|
-
const
|
|
143
|
-
|
|
162
|
+
const { prepareMint } = await minter.getToken({
|
|
163
|
+
mintType: "1155",
|
|
164
|
+
tokenContract: targetContract,
|
|
165
|
+
tokenId: targetTokenId,
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
const quantityToMint = 1n;
|
|
169
|
+
|
|
170
|
+
const { parameters, erc20Approval, costs } = prepareMint({
|
|
171
|
+
minterAccount: mockCollector,
|
|
172
|
+
quantityToMint,
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
expect(erc20Approval).toBeDefined();
|
|
176
|
+
expect(costs.totalCostEth).toBe(0n);
|
|
177
|
+
expect(costs.totalPurchaseCost).toBe(
|
|
178
|
+
quantityToMint * 1000000000000000000n,
|
|
179
|
+
);
|
|
180
|
+
expect(costs.totalPurchaseCostCurrency).toBe(
|
|
181
|
+
"0xa6b280b42cb0b7c4a4f789ec6ccc3a7609a1bc39",
|
|
182
|
+
);
|
|
144
183
|
|
|
145
184
|
const beforeERC20Balance = await publicClient.readContract({
|
|
146
185
|
abi: erc20Abi,
|
|
147
|
-
address:
|
|
186
|
+
address: erc20Approval!.erc20,
|
|
148
187
|
functionName: "balanceOf",
|
|
149
188
|
args: [mockCollector],
|
|
150
189
|
});
|
|
151
190
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
erc20MinterAddresses[chain.id as keyof typeof erc20MinterAddresses],
|
|
160
|
-
tokenAddress: erc20Currency,
|
|
161
|
-
account: mockCollector,
|
|
162
|
-
quantityErc20,
|
|
163
|
-
}),
|
|
164
|
-
);
|
|
165
|
-
const approveHash = await walletClient.writeContract(request);
|
|
166
|
-
const approveTxReciept = await publicClient.waitForTransactionReceipt({
|
|
167
|
-
hash: approveHash,
|
|
191
|
+
// execute the erc20 approval
|
|
192
|
+
const { request: erc20Request } = await publicClient.simulateContract({
|
|
193
|
+
abi: erc20Abi,
|
|
194
|
+
address: erc20Approval!.erc20,
|
|
195
|
+
functionName: "approve",
|
|
196
|
+
args: [erc20Approval!.approveTo, erc20Approval!.quantity],
|
|
197
|
+
account: mockCollector,
|
|
168
198
|
});
|
|
169
|
-
expect(approveTxReciept).to.not.be.null;
|
|
170
199
|
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
tokenContract: targetContract,
|
|
175
|
-
mintRecipient: mockCollector,
|
|
176
|
-
quantityToMint,
|
|
177
|
-
mintType: "1155",
|
|
200
|
+
const approveHash = await walletClient.writeContract(erc20Request);
|
|
201
|
+
await publicClient.waitForTransactionReceipt({
|
|
202
|
+
hash: approveHash,
|
|
178
203
|
});
|
|
179
204
|
|
|
180
205
|
const beforeCollector1155Balance = await publicClient.readContract({
|
|
@@ -185,20 +210,20 @@ describe("mint-helper", () => {
|
|
|
185
210
|
});
|
|
186
211
|
expect(beforeCollector1155Balance).to.be.equal(0n);
|
|
187
212
|
|
|
213
|
+
// execute the mint
|
|
188
214
|
const simulationResult = await publicClient.simulateContract(parameters);
|
|
189
215
|
const hash = await walletClient.writeContract(simulationResult.request);
|
|
190
|
-
|
|
191
|
-
expect(receipt).to.not.be.null;
|
|
216
|
+
await publicClient.waitForTransactionReceipt({ hash });
|
|
192
217
|
|
|
193
218
|
const afterERC20Balance = await publicClient.readContract({
|
|
194
219
|
abi: erc20Abi,
|
|
195
|
-
address:
|
|
220
|
+
address: erc20Approval!.erc20,
|
|
196
221
|
functionName: "balanceOf",
|
|
197
222
|
args: [mockCollector],
|
|
198
223
|
});
|
|
199
224
|
|
|
200
225
|
expect(beforeERC20Balance - afterERC20Balance).to.be.equal(
|
|
201
|
-
|
|
226
|
+
erc20Approval!.quantity,
|
|
202
227
|
);
|
|
203
228
|
|
|
204
229
|
const afterCollector1155Balance = await publicClient.readContract({
|
|
@@ -211,4 +236,28 @@ describe("mint-helper", () => {
|
|
|
211
236
|
},
|
|
212
237
|
12 * 1000,
|
|
213
238
|
);
|
|
239
|
+
|
|
240
|
+
makeAnvilTest({
|
|
241
|
+
forkUrl: forkUrls.zoraSepolia,
|
|
242
|
+
forkBlockNumber: 10294670,
|
|
243
|
+
anvilChainId: zoraSepolia.id,
|
|
244
|
+
})(
|
|
245
|
+
"gets onchain and premint mintables",
|
|
246
|
+
async ({ viemClients }) => {
|
|
247
|
+
const { publicClient, chain } = viemClients;
|
|
248
|
+
|
|
249
|
+
const targetContract: Address =
|
|
250
|
+
"0xa33e4228843092bb0f2fcbb2eb237bcefc1046b3";
|
|
251
|
+
|
|
252
|
+
const minter = createCollectorClient({ chainId: chain.id, publicClient });
|
|
253
|
+
|
|
254
|
+
const { tokens: mintables, contract } = await minter.getTokensOfContract({
|
|
255
|
+
tokenContract: targetContract,
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
expect(mintables.length).toBe(4);
|
|
259
|
+
expect(contract).toBeDefined();
|
|
260
|
+
},
|
|
261
|
+
12 * 1000,
|
|
262
|
+
);
|
|
214
263
|
});
|