@zoralabs/protocol-sdk 0.5.9 → 0.5.11
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 +17 -1
- package/README.md +10 -0
- package/dist/create/1155-create-helper.d.ts +2 -2
- package/dist/create/1155-create-helper.d.ts.map +1 -1
- package/dist/index.cjs +11619 -1707
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11621 -1680
- package/dist/index.js.map +1 -1
- package/dist/mint/mint-client.d.ts +3 -4
- package/dist/mint/mint-client.d.ts.map +1 -1
- package/dist/mints/mints-contracts.d.ts +2868 -2027
- package/dist/mints/mints-contracts.d.ts.map +1 -1
- package/dist/mints/mints-eth-unwrapper-and-caller.d.ts +78 -0
- package/dist/mints/mints-eth-unwrapper-and-caller.d.ts.map +1 -0
- package/dist/mints/mints-queries.d.ts +0 -27
- package/dist/mints/mints-queries.d.ts.map +1 -1
- package/dist/mints/mints-relay-example.d.ts +60 -0
- package/dist/mints/mints-relay-example.d.ts.map +1 -0
- package/dist/premint/premint-client.d.ts +1 -1
- package/dist/premint/premint-client.d.ts.map +1 -1
- package/dist/preminter.d.ts +23 -11
- package/dist/preminter.d.ts.map +1 -1
- package/dist/test-utils.d.ts +11 -0
- package/dist/test-utils.d.ts.map +1 -0
- package/dist/utils.d.ts +3 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +7 -5
- package/src/create/1155-create-helper.ts +14 -11
- package/src/index.ts +2 -0
- package/src/mint/mint-client.ts +16 -19
- package/src/mints/mints-contracts.test.ts +36 -224
- package/src/mints/mints-contracts.ts +200 -281
- package/src/mints/mints-eth-unwrapper-and-caller.test.ts +467 -0
- package/src/mints/mints-eth-unwrapper-and-caller.ts +83 -0
- package/src/mints/mints-queries.ts +1 -65
- package/src/mints/mints-relay-example.ts +313 -0
- package/src/premint/premint-client.ts +15 -11
- package/src/test-utils.ts +39 -0
- package/src/utils.ts +30 -0
|
@@ -6,9 +6,6 @@ import {
|
|
|
6
6
|
defaultPremintConfigV2,
|
|
7
7
|
} from "src/premint/preminter.test";
|
|
8
8
|
import {
|
|
9
|
-
mintsEthUnwrapperAndCallerConfig,
|
|
10
|
-
zoraCreator1155FactoryImplAddress,
|
|
11
|
-
zoraCreator1155FactoryImplConfig,
|
|
12
9
|
zoraCreator1155ImplABI,
|
|
13
10
|
zoraMints1155ABI,
|
|
14
11
|
zoraMints1155Address,
|
|
@@ -19,24 +16,18 @@ import {
|
|
|
19
16
|
Address,
|
|
20
17
|
BaseError,
|
|
21
18
|
ContractFunctionRevertedError,
|
|
22
|
-
Hex,
|
|
23
19
|
PublicClient,
|
|
24
20
|
WalletClient,
|
|
25
|
-
encodeFunctionData,
|
|
26
21
|
parseEther,
|
|
27
22
|
} from "viem";
|
|
28
23
|
import {
|
|
29
24
|
collectPremintV2WithMintsParams,
|
|
30
25
|
collectWithMintsParams,
|
|
31
26
|
mintWithEthParams,
|
|
32
|
-
permitTransferBatchToManagerAndCallParams,
|
|
33
27
|
mintsBalanceOfAccountParams,
|
|
34
|
-
collectPremintWithMintsTypedDataDefinition,
|
|
35
28
|
CollectMintArguments,
|
|
36
|
-
fixedPriceMinterMinterArguments,
|
|
37
29
|
decodeCallFailedError,
|
|
38
|
-
|
|
39
|
-
safeTransferAndUnwrapTypedDataDefinition,
|
|
30
|
+
makePermitToCollectPremintOrNonPremint,
|
|
40
31
|
} from "./mints-contracts";
|
|
41
32
|
import { getPremintCollectionAddress } from "src/premint/preminter";
|
|
42
33
|
import {
|
|
@@ -44,27 +35,21 @@ import {
|
|
|
44
35
|
PremintConfigVersion,
|
|
45
36
|
} from "src/premint/contract-types";
|
|
46
37
|
import { premintTypedDataDefinition } from "src/premint/preminter";
|
|
47
|
-
import {
|
|
38
|
+
import { zora } from "viem/chains";
|
|
39
|
+
import {
|
|
40
|
+
fixedPriceMinterMinterArguments,
|
|
41
|
+
getFixedPricedMinter,
|
|
42
|
+
waitForSuccess,
|
|
43
|
+
} from "src/test-utils";
|
|
44
|
+
|
|
45
|
+
const mintsMainnetDeployedBlock = 12990454;
|
|
48
46
|
|
|
49
47
|
const anvilTest = makeAnvilTest({
|
|
50
|
-
forkUrl: forkUrls.
|
|
51
|
-
forkBlockNumber:
|
|
52
|
-
anvilChainId:
|
|
48
|
+
forkUrl: forkUrls.zoraMainnet,
|
|
49
|
+
forkBlockNumber: mintsMainnetDeployedBlock,
|
|
50
|
+
anvilChainId: zora.id,
|
|
53
51
|
});
|
|
54
52
|
|
|
55
|
-
const getFixedPricedMinter = async ({
|
|
56
|
-
publicClient,
|
|
57
|
-
chainId,
|
|
58
|
-
}: {
|
|
59
|
-
publicClient: PublicClient;
|
|
60
|
-
chainId: keyof typeof zoraCreator1155FactoryImplAddress;
|
|
61
|
-
}) =>
|
|
62
|
-
await publicClient.readContract({
|
|
63
|
-
abi: zoraCreator1155FactoryImplConfig.abi,
|
|
64
|
-
address: zoraCreator1155FactoryImplAddress[chainId],
|
|
65
|
-
functionName: "fixedPriceMinter",
|
|
66
|
-
});
|
|
67
|
-
|
|
68
53
|
const setupContractUsingPremint = async ({
|
|
69
54
|
walletClient,
|
|
70
55
|
publicClient,
|
|
@@ -117,15 +102,7 @@ const setupContractUsingPremint = async ({
|
|
|
117
102
|
};
|
|
118
103
|
};
|
|
119
104
|
|
|
120
|
-
const
|
|
121
|
-
const receipt = await publicClient.waitForTransactionReceipt({
|
|
122
|
-
hash,
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
expect(receipt.status).toBe("success");
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
const collectMINTsWithEth = async ({
|
|
105
|
+
export const collectMINTsWithEth = async ({
|
|
129
106
|
publicClient,
|
|
130
107
|
walletClient,
|
|
131
108
|
chainId,
|
|
@@ -144,7 +121,7 @@ const collectMINTsWithEth = async ({
|
|
|
144
121
|
functionName: "getEthPrice",
|
|
145
122
|
});
|
|
146
123
|
|
|
147
|
-
const
|
|
124
|
+
const { request } = await publicClient.simulateContract(
|
|
148
125
|
mintWithEthParams({
|
|
149
126
|
chainId: chainId,
|
|
150
127
|
quantity: quantityToMint,
|
|
@@ -154,10 +131,7 @@ const collectMINTsWithEth = async ({
|
|
|
154
131
|
}),
|
|
155
132
|
);
|
|
156
133
|
|
|
157
|
-
await waitForSuccess(
|
|
158
|
-
await walletClient.writeContract(simulated.request),
|
|
159
|
-
publicClient,
|
|
160
|
-
);
|
|
134
|
+
await waitForSuccess(await walletClient.writeContract(request), publicClient);
|
|
161
135
|
const mintsTokenId = await publicClient.readContract({
|
|
162
136
|
abi: zoraMintsManagerImplABI,
|
|
163
137
|
address: zoraMintsManagerImplAddress[chainId],
|
|
@@ -193,7 +167,6 @@ describe("MINTs collecting and redeeming.", () => {
|
|
|
193
167
|
mintWithEthParams({
|
|
194
168
|
chainId: chainId,
|
|
195
169
|
quantity: initialMintsQuantityToMint,
|
|
196
|
-
recipient: collectorAccount!,
|
|
197
170
|
pricePerMint,
|
|
198
171
|
account: collectorAccount!,
|
|
199
172
|
}),
|
|
@@ -214,9 +187,10 @@ describe("MINTs collecting and redeeming.", () => {
|
|
|
214
187
|
|
|
215
188
|
expect(totalMintsBalance).toEqual(initialMintsQuantityToMint);
|
|
216
189
|
},
|
|
190
|
+
20_000,
|
|
217
191
|
);
|
|
218
192
|
anvilTest(
|
|
219
|
-
"can use
|
|
193
|
+
"can use MINTs to collect premint and non-premint",
|
|
220
194
|
async ({
|
|
221
195
|
viemClients: { walletClient, publicClient, testClient, chain },
|
|
222
196
|
}) => {
|
|
@@ -362,6 +336,7 @@ describe("MINTs collecting and redeeming.", () => {
|
|
|
362
336
|
(firstQuantityToCollect + secondQuantityToCollect),
|
|
363
337
|
);
|
|
364
338
|
},
|
|
339
|
+
20_000,
|
|
365
340
|
);
|
|
366
341
|
anvilTest(
|
|
367
342
|
"can decode errors from transferBatchToManagerAndCall",
|
|
@@ -440,6 +415,7 @@ describe("MINTs collecting and redeeming.", () => {
|
|
|
440
415
|
}
|
|
441
416
|
}
|
|
442
417
|
},
|
|
418
|
+
20_000,
|
|
443
419
|
);
|
|
444
420
|
anvilTest(
|
|
445
421
|
"can use MINTs to gaslessly collect premint",
|
|
@@ -507,179 +483,32 @@ describe("MINTs collecting and redeeming.", () => {
|
|
|
507
483
|
const deadline = blockTime + 10n;
|
|
508
484
|
|
|
509
485
|
// get typed data to sign, as well as permit to collect with
|
|
510
|
-
const { typedData, permit } =
|
|
511
|
-
|
|
512
|
-
chainId
|
|
513
|
-
mintArguments,
|
|
514
|
-
nonce,
|
|
486
|
+
const { typedData, permit } = makePermitToCollectPremintOrNonPremint({
|
|
487
|
+
mintsOwner: collectorAccount!,
|
|
488
|
+
chainId,
|
|
515
489
|
deadline,
|
|
516
490
|
tokenIds: [mintsTokenId],
|
|
491
|
+
// this quantity of MINTs will be used to collect premint
|
|
492
|
+
// and will be burned. This same quantity is the quantity of
|
|
493
|
+
// premint to collect.
|
|
517
494
|
quantities: [premintQuantityToCollect],
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
495
|
+
nonce,
|
|
496
|
+
premint: {
|
|
497
|
+
contractCreationConfig: contractConfig,
|
|
498
|
+
mintArguments,
|
|
499
|
+
premintConfig,
|
|
500
|
+
premintSignature,
|
|
501
|
+
},
|
|
521
502
|
});
|
|
522
503
|
|
|
523
504
|
const permitSignature = await walletClient.signTypedData(typedData);
|
|
524
505
|
|
|
525
506
|
// now simulate and execute the transaction
|
|
526
|
-
const permitSimulated = await publicClient.simulateContract({
|
|
527
|
-
...permitTransferBatchToManagerAndCallParams({
|
|
528
|
-
permit,
|
|
529
|
-
chainId: chainId,
|
|
530
|
-
signature: permitSignature,
|
|
531
|
-
}),
|
|
532
|
-
account: permitExecutorAccount,
|
|
533
|
-
});
|
|
534
|
-
|
|
535
|
-
await waitForSuccess(
|
|
536
|
-
await walletClient.writeContract(permitSimulated.request),
|
|
537
|
-
publicClient,
|
|
538
|
-
);
|
|
539
|
-
|
|
540
|
-
expect(
|
|
541
|
-
await publicClient.readContract(
|
|
542
|
-
mintsBalanceOfAccountParams({
|
|
543
|
-
account: collectorAccount!,
|
|
544
|
-
chainId: chainId,
|
|
545
|
-
}),
|
|
546
|
-
),
|
|
547
|
-
).toBe(initialMintsBalance - premintQuantityToCollect);
|
|
548
|
-
},
|
|
549
|
-
);
|
|
550
|
-
|
|
551
|
-
anvilTest(
|
|
552
|
-
"can use MINTs to gaslessly collect on legacy 1155 contracts",
|
|
553
|
-
async ({ viemClients: { walletClient, publicClient, chain } }) => {
|
|
554
|
-
const [collectorAccount, permitExecutorAccount] =
|
|
555
|
-
await walletClient.getAddresses();
|
|
556
|
-
|
|
557
|
-
const chainId = chain.id as keyof typeof zoraMintsManagerImplAddress;
|
|
558
|
-
|
|
559
|
-
// 1. Collect some MINTs
|
|
560
|
-
const initialMintsQuantityToMint = 20n;
|
|
561
|
-
|
|
562
|
-
const mintsTokenId = await collectMINTsWithEth({
|
|
563
|
-
publicClient,
|
|
564
|
-
walletClient,
|
|
565
|
-
chainId,
|
|
566
|
-
collectorAccount: collectorAccount!,
|
|
567
|
-
quantityToMint: initialMintsQuantityToMint,
|
|
568
|
-
});
|
|
569
|
-
|
|
570
|
-
const initialMintsBalance = await publicClient.readContract(
|
|
571
|
-
mintsBalanceOfAccountParams({
|
|
572
|
-
account: collectorAccount!,
|
|
573
|
-
chainId: chainId,
|
|
574
|
-
}),
|
|
575
|
-
);
|
|
576
|
-
|
|
577
|
-
// now sign a message to collect.
|
|
578
|
-
let nonce = BigInt(Math.round(Math.random() * 1_000_000));
|
|
579
|
-
|
|
580
|
-
const blockTime = (await publicClient.getBlock()).timestamp;
|
|
581
|
-
|
|
582
|
-
const quantityToMintOn1155 = 3n;
|
|
583
|
-
|
|
584
|
-
// make signature deadline 10 seconds from now
|
|
585
|
-
const deadline = blockTime + 10n;
|
|
586
|
-
|
|
587
|
-
const fixedPriceMinter = await getFixedPricedMinter({
|
|
588
|
-
publicClient,
|
|
589
|
-
chainId,
|
|
590
|
-
});
|
|
591
|
-
|
|
592
|
-
const tokenId = 1n;
|
|
593
|
-
|
|
594
|
-
const minterArguments = fixedPriceMinterMinterArguments({
|
|
595
|
-
mintRecipient: collectorAccount!,
|
|
596
|
-
});
|
|
597
|
-
|
|
598
|
-
// this is the external contract that will be called
|
|
599
|
-
const legacy1155Address = "0x2988C3b4F3A823488e4E2d70F23bD66366639b81";
|
|
600
|
-
|
|
601
|
-
// this is the external contract funciton that will be called
|
|
602
|
-
const contractCall = encodeFunctionData({
|
|
603
|
-
abi: zoraCreator1155ImplABI,
|
|
604
|
-
functionName: "mint",
|
|
605
|
-
args: [
|
|
606
|
-
fixedPriceMinter,
|
|
607
|
-
tokenId,
|
|
608
|
-
quantityToMintOn1155,
|
|
609
|
-
[],
|
|
610
|
-
minterArguments,
|
|
611
|
-
],
|
|
612
|
-
});
|
|
613
|
-
|
|
614
|
-
// get typed data to sign, as well as permit to collect with
|
|
615
|
-
const { typedData: batchTransferTypeData, permit: bathTransferPermit } =
|
|
616
|
-
safeTransferBatchAndUnwrapTypedDataDefinition({
|
|
617
|
-
from: collectorAccount!,
|
|
618
|
-
chainId: chainId,
|
|
619
|
-
nonce,
|
|
620
|
-
deadline,
|
|
621
|
-
// token ids to unwrap and burn - must be eth based token ids
|
|
622
|
-
tokenIds: [mintsTokenId],
|
|
623
|
-
// quantities to unwrap and burn
|
|
624
|
-
quantities: [quantityToMintOn1155],
|
|
625
|
-
// external address to call
|
|
626
|
-
addressToCall: legacy1155Address,
|
|
627
|
-
// external contract call
|
|
628
|
-
functionToCall: contractCall,
|
|
629
|
-
// value to send to external contract, extra value from mints
|
|
630
|
-
// will be refunded
|
|
631
|
-
valueToSend: parseEther("0.000777") * quantityToMintOn1155,
|
|
632
|
-
});
|
|
633
|
-
|
|
634
|
-
const permitBatchSignature = await walletClient.signTypedData(
|
|
635
|
-
batchTransferTypeData,
|
|
636
|
-
);
|
|
637
|
-
|
|
638
|
-
// now simulate and execute the transaction
|
|
639
|
-
const permitBatchSimulated = await publicClient.simulateContract({
|
|
640
|
-
...permitTransferBatchToManagerAndCallParams({
|
|
641
|
-
permit: bathTransferPermit,
|
|
642
|
-
chainId: chainId,
|
|
643
|
-
signature: permitBatchSignature,
|
|
644
|
-
}),
|
|
645
|
-
account: permitExecutorAccount,
|
|
646
|
-
});
|
|
647
|
-
|
|
648
|
-
await waitForSuccess(
|
|
649
|
-
await walletClient.writeContract(permitBatchSimulated.request),
|
|
650
|
-
publicClient,
|
|
651
|
-
);
|
|
652
|
-
|
|
653
|
-
nonce = BigInt(Math.round(Math.random() * 1_000_000));
|
|
654
|
-
|
|
655
|
-
// make non-batch permit and signtarue
|
|
656
|
-
const { typedData: transferTypeData, permit: transferPermit } =
|
|
657
|
-
safeTransferAndUnwrapTypedDataDefinition({
|
|
658
|
-
from: collectorAccount!,
|
|
659
|
-
chainId: chainId,
|
|
660
|
-
nonce,
|
|
661
|
-
deadline,
|
|
662
|
-
// token ids to unwrap and burn - must be eth based token ids
|
|
663
|
-
tokenId: mintsTokenId,
|
|
664
|
-
// quantities to unwrap and burn
|
|
665
|
-
quantity: quantityToMintOn1155,
|
|
666
|
-
// external address to call
|
|
667
|
-
addressToCall: legacy1155Address,
|
|
668
|
-
// external contract call
|
|
669
|
-
functionToCall: contractCall,
|
|
670
|
-
// value to send to external contract, extra value from mints
|
|
671
|
-
// will be refunded
|
|
672
|
-
valueToSend: parseEther("0.000777") * quantityToMintOn1155,
|
|
673
|
-
});
|
|
674
|
-
|
|
675
|
-
const permitSignature =
|
|
676
|
-
await walletClient.signTypedData(transferTypeData);
|
|
677
|
-
|
|
678
507
|
const permitSimulated = await publicClient.simulateContract({
|
|
679
508
|
abi: zoraMints1155ABI,
|
|
680
509
|
address: zoraMints1155Address[chainId],
|
|
681
|
-
functionName: "
|
|
682
|
-
args: [
|
|
510
|
+
functionName: "permitSafeTransferBatch",
|
|
511
|
+
args: [permit, permitSignature],
|
|
683
512
|
account: permitExecutorAccount,
|
|
684
513
|
});
|
|
685
514
|
|
|
@@ -695,25 +524,8 @@ describe("MINTs collecting and redeeming.", () => {
|
|
|
695
524
|
chainId: chainId,
|
|
696
525
|
}),
|
|
697
526
|
),
|
|
698
|
-
).toBe(initialMintsBalance -
|
|
699
|
-
|
|
700
|
-
expect(
|
|
701
|
-
await publicClient.readContract(
|
|
702
|
-
mintsBalanceOfAccountParams({
|
|
703
|
-
account: mintsEthUnwrapperAndCallerConfig.address[chainId],
|
|
704
|
-
chainId: chainId,
|
|
705
|
-
}),
|
|
706
|
-
),
|
|
707
|
-
).toBe(0n);
|
|
708
|
-
|
|
709
|
-
const tokenBalance = await publicClient.readContract({
|
|
710
|
-
abi: zoraCreator1155ImplABI,
|
|
711
|
-
address: legacy1155Address,
|
|
712
|
-
functionName: "balanceOf",
|
|
713
|
-
args: [collectorAccount!, tokenId],
|
|
714
|
-
});
|
|
715
|
-
|
|
716
|
-
expect(tokenBalance).toBe(quantityToMintOn1155 * 2n);
|
|
527
|
+
).toBe(initialMintsBalance - premintQuantityToCollect);
|
|
717
528
|
},
|
|
529
|
+
20_000,
|
|
718
530
|
);
|
|
719
531
|
});
|