@6529-collections/stream-sdk 0.0.0-stage → 0.1.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.
Files changed (148) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/LICENSE +201 -0
  3. package/NOTICE +4 -0
  4. package/README.md +413 -2
  5. package/dist/actions/accounts.d.ts +58 -0
  6. package/dist/actions/accounts.js +73 -0
  7. package/dist/actions/content.d.ts +22 -0
  8. package/dist/actions/content.js +45 -0
  9. package/dist/actions/curated.d.ts +177 -0
  10. package/dist/actions/curated.js +279 -0
  11. package/dist/actions/editions.d.ts +100 -0
  12. package/dist/actions/editions.js +161 -0
  13. package/dist/actions/independent.d.ts +149 -0
  14. package/dist/actions/independent.js +274 -0
  15. package/dist/actions/money.d.ts +117 -0
  16. package/dist/actions/money.js +148 -0
  17. package/dist/actions/record.d.ts +144 -0
  18. package/dist/actions/record.js +229 -0
  19. package/dist/actions/sale.d.ts +82 -0
  20. package/dist/actions/sale.js +113 -0
  21. package/dist/actions/shared.d.ts +40 -0
  22. package/dist/actions/shared.js +70 -0
  23. package/dist/actions/vault.d.ts +58 -0
  24. package/dist/actions/vault.js +94 -0
  25. package/dist/constants.d.ts +130 -0
  26. package/dist/constants.js +65 -0
  27. package/dist/display.d.ts +31 -0
  28. package/dist/display.js +28 -0
  29. package/dist/encoding.d.ts +110 -0
  30. package/dist/encoding.js +138 -0
  31. package/dist/errors.d.ts +76 -0
  32. package/dist/errors.js +66 -0
  33. package/dist/files/fetch.d.ts +85 -0
  34. package/dist/files/fetch.js +208 -0
  35. package/dist/files/verify.d.ts +36 -0
  36. package/dist/files/verify.js +125 -0
  37. package/dist/generated/abis/AccessManager.d.ts +1125 -0
  38. package/dist/generated/abis/AccessManager.js +1471 -0
  39. package/dist/generated/abis/Accounts.d.ts +1568 -0
  40. package/dist/generated/abis/Accounts.js +2049 -0
  41. package/dist/generated/abis/ClaimRouter.d.ts +343 -0
  42. package/dist/generated/abis/ClaimRouter.js +452 -0
  43. package/dist/generated/abis/ConsolidationAdapter.d.ts +97 -0
  44. package/dist/generated/abis/ConsolidationAdapter.js +133 -0
  45. package/dist/generated/abis/ContentStore.d.ts +812 -0
  46. package/dist/generated/abis/ContentStore.js +1073 -0
  47. package/dist/generated/abis/EconomicsResolver.d.ts +586 -0
  48. package/dist/generated/abis/EconomicsResolver.js +769 -0
  49. package/dist/generated/abis/Eip712CurationVerifier.d.ts +304 -0
  50. package/dist/generated/abis/Eip712CurationVerifier.js +406 -0
  51. package/dist/generated/abis/EnglishAuction.d.ts +1435 -0
  52. package/dist/generated/abis/EnglishAuction.js +1865 -0
  53. package/dist/generated/abis/GovernedVault.d.ts +468 -0
  54. package/dist/generated/abis/GovernedVault.js +617 -0
  55. package/dist/generated/abis/IndependentEditionAuction.d.ts +2373 -0
  56. package/dist/generated/abis/IndependentEditionAuction.js +3076 -0
  57. package/dist/generated/abis/IndependentStream6529.d.ts +1408 -0
  58. package/dist/generated/abis/IndependentStream6529.js +1834 -0
  59. package/dist/generated/abis/IndependentStreamDeployer.d.ts +141 -0
  60. package/dist/generated/abis/IndependentStreamDeployer.js +188 -0
  61. package/dist/generated/abis/IndependentStreamEditions6529.d.ts +963 -0
  62. package/dist/generated/abis/IndependentStreamEditions6529.js +1253 -0
  63. package/dist/generated/abis/IndependentStreamRegistry.d.ts +1351 -0
  64. package/dist/generated/abis/IndependentStreamRegistry.js +1755 -0
  65. package/dist/generated/abis/PackageRegistry.d.ts +1205 -0
  66. package/dist/generated/abis/PackageRegistry.js +1573 -0
  67. package/dist/generated/abis/RevenueEscrow.d.ts +626 -0
  68. package/dist/generated/abis/RevenueEscrow.js +820 -0
  69. package/dist/generated/abis/SaleStarter.d.ts +48 -0
  70. package/dist/generated/abis/SaleStarter.js +67 -0
  71. package/dist/generated/abis/SepoliaOpenGate.d.ts +317 -0
  72. package/dist/generated/abis/SepoliaOpenGate.js +419 -0
  73. package/dist/generated/abis/SplitLedger.d.ts +1097 -0
  74. package/dist/generated/abis/SplitLedger.js +1438 -0
  75. package/dist/generated/abis/StatementLog.d.ts +958 -0
  76. package/dist/generated/abis/StatementLog.js +1248 -0
  77. package/dist/generated/abis/Stream6529.d.ts +1490 -0
  78. package/dist/generated/abis/Stream6529.js +1941 -0
  79. package/dist/generated/abis/StreamDirectory6529.d.ts +355 -0
  80. package/dist/generated/abis/StreamDirectory6529.js +468 -0
  81. package/dist/generated/abis/StreamEditions6529.d.ts +1240 -0
  82. package/dist/generated/abis/StreamEditions6529.js +1614 -0
  83. package/dist/generated/abis/StreamTerms.d.ts +312 -0
  84. package/dist/generated/abis/StreamTerms.js +409 -0
  85. package/dist/generated/abis/StreamWorkFacts6529.d.ts +810 -0
  86. package/dist/generated/abis/StreamWorkFacts6529.js +1049 -0
  87. package/dist/generated/abis/UniformEditionAuction.d.ts +2372 -0
  88. package/dist/generated/abis/UniformEditionAuction.js +3074 -0
  89. package/dist/generated/abis/WorkDelivery.d.ts +605 -0
  90. package/dist/generated/abis/WorkDelivery.js +786 -0
  91. package/dist/generated/abis/WorkRules.d.ts +1154 -0
  92. package/dist/generated/abis/WorkRules.js +1501 -0
  93. package/dist/generated/abis/index.d.ts +28 -0
  94. package/dist/generated/abis/index.js +31 -0
  95. package/dist/generated/instances.d.ts +7 -0
  96. package/dist/generated/instances.js +9 -0
  97. package/dist/generated/sepoliaR10.d.ts +1391 -0
  98. package/dist/generated/sepoliaR10.js +1545 -0
  99. package/dist/hashing/content.d.ts +42 -0
  100. package/dist/hashing/content.js +54 -0
  101. package/dist/hashing/ids.d.ts +67 -0
  102. package/dist/hashing/ids.js +73 -0
  103. package/dist/hashing/items.d.ts +30 -0
  104. package/dist/hashing/items.js +44 -0
  105. package/dist/hashing/packages.d.ts +35 -0
  106. package/dist/hashing/packages.js +76 -0
  107. package/dist/hashing/vault.d.ts +17 -0
  108. package/dist/hashing/vault.js +37 -0
  109. package/dist/hashing/workState.d.ts +31 -0
  110. package/dist/hashing/workState.js +37 -0
  111. package/dist/index.d.ts +44 -0
  112. package/dist/index.js +47 -0
  113. package/dist/instance.d.ts +236 -0
  114. package/dist/instance.js +99 -0
  115. package/dist/items.d.ts +85 -0
  116. package/dist/items.js +144 -0
  117. package/dist/reads/accounts.d.ts +86 -0
  118. package/dist/reads/accounts.js +121 -0
  119. package/dist/reads/chain.d.ts +54 -0
  120. package/dist/reads/chain.js +133 -0
  121. package/dist/reads/creation.d.ts +139 -0
  122. package/dist/reads/creation.js +256 -0
  123. package/dist/reads/editionSale.d.ts +120 -0
  124. package/dist/reads/editionSale.js +182 -0
  125. package/dist/reads/metadata.d.ts +195 -0
  126. package/dist/reads/metadata.js +191 -0
  127. package/dist/reads/money.d.ts +51 -0
  128. package/dist/reads/money.js +68 -0
  129. package/dist/reads/network.d.ts +137 -0
  130. package/dist/reads/network.js +157 -0
  131. package/dist/reads/sale.d.ts +94 -0
  132. package/dist/reads/sale.js +133 -0
  133. package/dist/reads/vault.d.ts +47 -0
  134. package/dist/reads/vault.js +75 -0
  135. package/dist/reads/work.d.ts +293 -0
  136. package/dist/reads/work.js +338 -0
  137. package/dist/reads/workPage.d.ts +197 -0
  138. package/dist/reads/workPage.js +169 -0
  139. package/dist/signing/messages.d.ts +679 -0
  140. package/dist/signing/messages.js +397 -0
  141. package/dist/testing.d.ts +17 -0
  142. package/dist/testing.js +18 -0
  143. package/dist/types.d.ts +167 -0
  144. package/dist/types.js +14 -0
  145. package/docs/publishing.md +54 -0
  146. package/docs/reference.md +335 -0
  147. package/docs/using-from-a-site.md +175 -0
  148. package/package.json +93 -4
@@ -0,0 +1,177 @@
1
+ import { type Address, type Hex } from "viem";
2
+ import { type StreamInstance } from "../instance.js";
3
+ import type { MediaFile, PackageItem } from "../types.js";
4
+ import { type Sent, type StreamClients } from "./shared.js";
5
+ /**
6
+ * Creates a collection of the curated Stream contract through the test gate. Anyone may; a
7
+ * collection has no owner, and any later item may name it.
8
+ *
9
+ * `metadataHash` is the hash of the collection's metadata document. No contract reads it.
10
+ *
11
+ * Contract: [`SepoliaOpenGate.createCollection`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/script/sepolia/SepoliaOpenGate.sol),
12
+ * which forwards to `Stream6529.createCollection`. On an instance without a gate only the
13
+ * platform role can create collections.
14
+ */
15
+ export declare function createCollectionThroughGate(clients: StreamClients, instance: StreamInstance, collection: {
16
+ readonly name: string;
17
+ readonly metadataHash: Hex;
18
+ }): Promise<Sent & {
19
+ collectionId: bigint;
20
+ }>;
21
+ /**
22
+ * Registers a package root with the test gate's approval, so no curation signer is needed.
23
+ * Anyone may send it. A root registers once: when it is approved already, nothing is sent.
24
+ *
25
+ * Contract: [`SepoliaOpenGate.attestationOf`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/script/sepolia/SepoliaOpenGate.sol)
26
+ * supplies the evidence hash and the attestation, passed unchanged to
27
+ * [`PackageRegistry.registerPackage`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/curation/PackageRegistry.sol).
28
+ * On an instance without a gate, the attestation is `abi.encode(signer, signature)` of a
29
+ * curation signer's `PackageApproval` (`packageApprovalTypedData`).
30
+ *
31
+ * @returns the transaction, or null when the package was approved already.
32
+ * @throws FlowError `PACKAGE_REVOKED` when the root was revoked.
33
+ */
34
+ export declare function registerPackageThroughGate(clients: StreamClients, instance: StreamInstance, packageRoot: Hex): Promise<Sent | null>;
35
+ /**
36
+ * The wallet accepts a package root as one of its parties: it signs a `PackageAcceptance` and
37
+ * sends it. A wallet's first acceptance creates its account. Every party of every item must
38
+ * accept before an item can be minted.
39
+ *
40
+ * Pass `items` (the package's items this wallet is a party of): each is checked against the
41
+ * registry's rules before the wallet is asked to sign, because a broken item is otherwise
42
+ * found only when its sale starts.
43
+ *
44
+ * `profile` is used only when the wallet has no account yet, and is then stored for good: its
45
+ * 6529 profile ID and the hash of its profile document. An existing account's stored fields
46
+ * are always used. The deadline is `lifetimeSeconds` (default one hour) after the chain's
47
+ * latest block.
48
+ *
49
+ * Contract: [`PackageRegistry.acceptPackage`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/curation/PackageRegistry.sol);
50
+ * message `PackageAcceptance` (`packageAcceptanceTypedData`).
51
+ *
52
+ * @returns the transaction, or null when the wallet had accepted this root already.
53
+ */
54
+ export declare function acceptPackage(clients: StreamClients, instance: StreamInstance, args: {
55
+ readonly packageRoot: Hex;
56
+ /**
57
+ * The items of the package this wallet is a party of, each with its proof. An acceptance
58
+ * covers the whole root, and the wallet shows only that hash, so each item given is
59
+ * checked first (`previewCuratedItem`) and nothing is signed if one would be refused.
60
+ */
61
+ readonly items?: readonly {
62
+ readonly item: PackageItem;
63
+ readonly proof: readonly Hex[];
64
+ }[];
65
+ readonly profile?: {
66
+ readonly profileId: Hex;
67
+ readonly profileDocHash: Hex;
68
+ };
69
+ readonly lifetimeSeconds?: number;
70
+ }): Promise<Sent | null>;
71
+ /** A signed authorization to mint one item, ready for a start request. */
72
+ export interface SignedMove {
73
+ readonly nonce: bigint;
74
+ readonly deadline: bigint;
75
+ /** `walletProof(wallet, signature)`. */
76
+ readonly signature: Hex;
77
+ }
78
+ /**
79
+ * The lead artist signs the move of one approved item to Stream. Whoever holds the result can
80
+ * start the item's sale, once, until the deadline; the artist can cancel it before with
81
+ * `PackageRegistry.revokeMove`.
82
+ *
83
+ * The item hash is computed here from the item given, and the item must be in the package
84
+ * (`proof`). The lead artist must have accepted the package, and the wallet must act for the
85
+ * account it accepted as: its root, or a wallet consolidated with it.
86
+ *
87
+ * To sign several moves before any is used, pass a different `nonce` for each: the default is
88
+ * the first nonce unused on chain, which stays the same until a move is consumed.
89
+ *
90
+ * Contract: message `MoveToStream` (`moveToStreamTypedData`), checked by
91
+ * [`PackageRegistry.authorize`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/curation/PackageRegistry.sol).
92
+ */
93
+ export declare function signMove(clients: StreamClients, instance: StreamInstance, args: {
94
+ readonly packageRoot: Hex;
95
+ readonly item: PackageItem;
96
+ readonly proof: readonly Hex[];
97
+ /** Default: the artist's first unused nonce. */
98
+ readonly nonce?: bigint;
99
+ /** Default: one hour. */
100
+ readonly lifetimeSeconds?: number;
101
+ }): Promise<SignedMove>;
102
+ /** The token a start minted, read from the receipt's `SaleStarted` log. */
103
+ export declare function startedTokenId(sent: Sent, instance: StreamInstance, token: Address): bigint;
104
+ /** A started sale. */
105
+ export interface StartedSale {
106
+ readonly tokenId: bigint;
107
+ readonly saleId: bigint;
108
+ /** The start transaction, or null when the work had been started already. */
109
+ readonly sent: Sent | null;
110
+ }
111
+ /**
112
+ * Starts the sale of an approved, accepted curated item: the work is minted into the English
113
+ * auction and its 24-hour sale begins (the duration is the auction's setting; r10 runs one
114
+ * hour). Anyone may send it; the artist's signed move is what authorizes it.
115
+ *
116
+ * Without `firstBid` it goes through `SaleStarter.start`, which also deploys the payout vaults
117
+ * and opens the work's record in the same transaction. With `firstBid` (wei, at least the
118
+ * opening bid) it is `EnglishAuction.startWithBid`, and the record is opened afterwards with
119
+ * `openRecord`.
120
+ *
121
+ * If the item is minted already nothing is sent and its token is returned. The check compares
122
+ * item hashes, not only the content (`readMintedToken`).
123
+ *
124
+ * Contract: [`SaleStarter.start`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/SaleStarter.sol),
125
+ * [`EnglishAuction.startWithBid`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/EnglishAuction.sol);
126
+ * the request is `encodeStreamMintRequest`.
127
+ */
128
+ export declare function startCuratedSale(clients: StreamClients, instance: StreamInstance, args: {
129
+ readonly packageRoot: Hex;
130
+ readonly item: PackageItem;
131
+ readonly proof: readonly Hex[];
132
+ /** The item's media list; it must hash to the item's `mediaHash`. */
133
+ readonly media: readonly MediaFile[];
134
+ /** From `signMove`. Omit it and the connected wallet signs now. */
135
+ readonly move?: SignedMove;
136
+ readonly firstBid?: bigint;
137
+ }): Promise<StartedSale>;
138
+ /**
139
+ * Publishes a work's record: its files, license and descriptive record become readable on
140
+ * chain (`open`), and, when every file is stored in full, it is marked complete on chain so
141
+ * the renderer can serve the art (`markOnChainComplete`). Anyone may send both; each is
142
+ * skipped when done. The item and media must be the ones the work was minted from.
143
+ *
144
+ * `SaleStarter.start` opens the record itself; a work started with `startWithBid` or any
145
+ * Independent Stream work needs this call.
146
+ *
147
+ * Contract: [`StreamWorkFacts6529.open`, `markOnChainComplete`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/core/StreamWorkFacts6529.sol).
148
+ */
149
+ export declare function openRecord(clients: StreamClients, instance: StreamInstance, args: {
150
+ readonly token?: Address;
151
+ readonly tokenId: bigint;
152
+ readonly item: PackageItem;
153
+ readonly media: readonly MediaFile[];
154
+ }): Promise<{
155
+ opened: Sent | null;
156
+ completed: Sent | null;
157
+ }>;
158
+ /**
159
+ * Opens the edition sale of a curated edition master, beside its 1/1 sale. Anyone may send
160
+ * it, from the start of the 1/1 until 15 minutes after the 1/1 ends, which is when the edition
161
+ * sale closes. Until someone opens it, nobody can bid on the editions. Nothing is sent when it
162
+ * is open already.
163
+ *
164
+ * Contract: [`UniformEditionAuction.open`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/UniformEditionAuction.sol)
165
+ * with `encodeCuratedEditionOpen(item, packageRoot, proof)`.
166
+ *
167
+ * @returns the edition sale's ID and the transaction (null when it was open already).
168
+ */
169
+ export declare function openCuratedEditionSale(clients: StreamClients, instance: StreamInstance, args: {
170
+ readonly tokenId: bigint;
171
+ readonly item: PackageItem;
172
+ readonly packageRoot: Hex;
173
+ readonly proof: readonly Hex[];
174
+ }): Promise<{
175
+ saleId: bigint;
176
+ sent: Sent | null;
177
+ }>;
@@ -0,0 +1,279 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { isAddressEqual, parseEventLogs, zeroAddress } from "viem";
3
+ import { readContract, simulateContract } from "viem/actions";
4
+ import { encodeCuratedEditionOpen, encodeStreamMintRequest } from "../encoding.js";
5
+ import { FlowError } from "../errors.js";
6
+ import { englishAuctionAbi } from "../generated/abis/EnglishAuction.js";
7
+ import { packageRegistryAbi } from "../generated/abis/PackageRegistry.js";
8
+ import { saleStarterAbi } from "../generated/abis/SaleStarter.js";
9
+ import { sepoliaOpenGateAbi } from "../generated/abis/SepoliaOpenGate.js";
10
+ import { stream6529Abi } from "../generated/abis/Stream6529.js";
11
+ import { streamWorkFacts6529Abi } from "../generated/abis/StreamWorkFacts6529.js";
12
+ import { uniformEditionAuctionAbi } from "../generated/abis/UniformEditionAuction.js";
13
+ import { saleId as saleIdOf } from "../hashing/ids.js";
14
+ import { mediaHash } from "../hashing/items.js";
15
+ import {} from "../instance.js";
16
+ import { readIsWallet } from "../reads/accounts.js";
17
+ import { gateOf, previewCuratedItem, readMintedToken, readNextMoveNonce, readPackageStatus, readStoredProfile } from "../reads/creation.js";
18
+ import { chainDeadline, isContractRevert, orOnRevert } from "../reads/chain.js";
19
+ import { moveToStreamTypedData, packageAcceptanceTypedData, signingDomains, walletProof } from "../signing/messages.js";
20
+ import { accountOf, assertReady, send, sign } from "./shared.js";
21
+ /** How long a signature made by these actions is valid, on the chain's clock, unless said otherwise. */
22
+ const DEFAULT_SIGNATURE_LIFETIME = 3_600;
23
+ /**
24
+ * Creates a collection of the curated Stream contract through the test gate. Anyone may; a
25
+ * collection has no owner, and any later item may name it.
26
+ *
27
+ * `metadataHash` is the hash of the collection's metadata document. No contract reads it.
28
+ *
29
+ * Contract: [`SepoliaOpenGate.createCollection`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/script/sepolia/SepoliaOpenGate.sol),
30
+ * which forwards to `Stream6529.createCollection`. On an instance without a gate only the
31
+ * platform role can create collections.
32
+ */
33
+ export async function createCollectionThroughGate(clients, instance, collection) {
34
+ const sent = await send(clients, instance, {
35
+ address: gateOf(instance),
36
+ abi: sepoliaOpenGateAbi,
37
+ functionName: "createCollection",
38
+ args: [collection.name, collection.metadataHash],
39
+ });
40
+ const created = parseEventLogs({ abi: stream6529Abi, logs: sent.receipt.logs, eventName: "CollectionCreated" }).find((log) => isAddressEqual(log.address, instance.addresses.stream));
41
+ if (!created)
42
+ throw new FlowError("MISSING_EVENT", "The transaction emitted no CollectionCreated from the Stream contract.");
43
+ return { ...sent, collectionId: created.args.collectionId };
44
+ }
45
+ /**
46
+ * Registers a package root with the test gate's approval, so no curation signer is needed.
47
+ * Anyone may send it. A root registers once: when it is approved already, nothing is sent.
48
+ *
49
+ * Contract: [`SepoliaOpenGate.attestationOf`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/script/sepolia/SepoliaOpenGate.sol)
50
+ * supplies the evidence hash and the attestation, passed unchanged to
51
+ * [`PackageRegistry.registerPackage`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/curation/PackageRegistry.sol).
52
+ * On an instance without a gate, the attestation is `abi.encode(signer, signature)` of a
53
+ * curation signer's `PackageApproval` (`packageApprovalTypedData`).
54
+ *
55
+ * @returns the transaction, or null when the package was approved already.
56
+ * @throws FlowError `PACKAGE_REVOKED` when the root was revoked.
57
+ */
58
+ export async function registerPackageThroughGate(clients, instance, packageRoot) {
59
+ await assertReady(clients, instance);
60
+ const approved = async () => {
61
+ const status = await readPackageStatus(clients.public, instance, packageRoot);
62
+ if (status === "revoked")
63
+ throw new FlowError("PACKAGE_REVOKED", `Package ${packageRoot} was revoked.`);
64
+ return status === "approved";
65
+ };
66
+ if (await approved())
67
+ return null;
68
+ const [evidenceHash, attestation] = await readContract(clients.public, {
69
+ address: gateOf(instance),
70
+ abi: sepoliaOpenGateAbi,
71
+ functionName: "attestationOf",
72
+ args: [packageRoot],
73
+ });
74
+ try {
75
+ return await send(clients, instance, {
76
+ address: instance.addresses.packageRegistry,
77
+ abi: packageRegistryAbi,
78
+ functionName: "registerPackage",
79
+ args: [packageRoot, evidenceHash, attestation],
80
+ });
81
+ }
82
+ catch (error) {
83
+ // Someone registered the same root in between: done, if it is approved.
84
+ if (isContractRevert(error, "PackageExists") && (await approved()))
85
+ return null;
86
+ throw error;
87
+ }
88
+ }
89
+ /**
90
+ * The wallet accepts a package root as one of its parties: it signs a `PackageAcceptance` and
91
+ * sends it. A wallet's first acceptance creates its account. Every party of every item must
92
+ * accept before an item can be minted.
93
+ *
94
+ * Pass `items` (the package's items this wallet is a party of): each is checked against the
95
+ * registry's rules before the wallet is asked to sign, because a broken item is otherwise
96
+ * found only when its sale starts.
97
+ *
98
+ * `profile` is used only when the wallet has no account yet, and is then stored for good: its
99
+ * 6529 profile ID and the hash of its profile document. An existing account's stored fields
100
+ * are always used. The deadline is `lifetimeSeconds` (default one hour) after the chain's
101
+ * latest block.
102
+ *
103
+ * Contract: [`PackageRegistry.acceptPackage`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/curation/PackageRegistry.sol);
104
+ * message `PackageAcceptance` (`packageAcceptanceTypedData`).
105
+ *
106
+ * @returns the transaction, or null when the wallet had accepted this root already.
107
+ */
108
+ export async function acceptPackage(clients, instance, args) {
109
+ const account = await assertReady(clients, instance);
110
+ for (const entry of args.items ?? []) {
111
+ await previewCuratedItem(clients.public, instance, { packageRoot: args.packageRoot, item: entry.item, proof: entry.proof });
112
+ }
113
+ const registry = { address: instance.addresses.packageRegistry, abi: packageRegistryAbi };
114
+ const accepted = await readContract(clients.public, { ...registry, functionName: "acceptedAs", args: [args.packageRoot, account] });
115
+ if (accepted !== 0n)
116
+ return null;
117
+ const profile = (await readStoredProfile(clients.public, instance, account)) ?? args.profile;
118
+ if (!profile) {
119
+ throw new FlowError("INVALID_INPUT", "This wallet has no account yet: pass the profile fields its first acceptance will store.");
120
+ }
121
+ const acceptance = {
122
+ account,
123
+ profileId: profile.profileId,
124
+ profileDocHash: profile.profileDocHash,
125
+ deadline: await chainDeadline(clients.public, args.lifetimeSeconds ?? DEFAULT_SIGNATURE_LIFETIME),
126
+ };
127
+ const signature = await sign(clients, packageAcceptanceTypedData(signingDomains(instance).packageRegistry, args.packageRoot, acceptance));
128
+ return send(clients, instance, {
129
+ ...registry,
130
+ functionName: "acceptPackage",
131
+ args: [args.packageRoot, acceptance, walletProof(account, signature)],
132
+ });
133
+ }
134
+ /**
135
+ * The lead artist signs the move of one approved item to Stream. Whoever holds the result can
136
+ * start the item's sale, once, until the deadline; the artist can cancel it before with
137
+ * `PackageRegistry.revokeMove`.
138
+ *
139
+ * The item hash is computed here from the item given, and the item must be in the package
140
+ * (`proof`). The lead artist must have accepted the package, and the wallet must act for the
141
+ * account it accepted as: its root, or a wallet consolidated with it.
142
+ *
143
+ * To sign several moves before any is used, pass a different `nonce` for each: the default is
144
+ * the first nonce unused on chain, which stays the same until a move is consumed.
145
+ *
146
+ * Contract: message `MoveToStream` (`moveToStreamTypedData`), checked by
147
+ * [`PackageRegistry.authorize`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/curation/PackageRegistry.sol).
148
+ */
149
+ export async function signMove(clients, instance, args) {
150
+ const account = await assertReady(clients, instance);
151
+ // The local rules, the proof and the registry's own dry run, before the wallet is asked.
152
+ const { itemHash: hash } = await previewCuratedItem(clients.public, instance, args);
153
+ const lead = args.item.parties[0]?.account;
154
+ if (!lead)
155
+ throw new FlowError("INVALID_INPUT", "The item has no parties.");
156
+ // The registry checks the move against the account the lead accepted the package as.
157
+ const artistId = await readContract(clients.public, {
158
+ address: instance.addresses.packageRegistry,
159
+ abi: packageRegistryAbi,
160
+ functionName: "acceptedAs",
161
+ args: [args.packageRoot, lead],
162
+ });
163
+ if (artistId === 0n) {
164
+ throw new FlowError("INVALID_INPUT", `The lead artist ${lead} has not accepted this package yet.`);
165
+ }
166
+ if (!(await readIsWallet(clients.public, instance, artistId, account))) {
167
+ throw new FlowError("INVALID_INPUT", `Wallet ${account} does not act for the item's lead artist ${lead}.`);
168
+ }
169
+ const nonce = args.nonce ?? (await readNextMoveNonce(clients.public, instance, artistId));
170
+ const deadline = await chainDeadline(clients.public, args.lifetimeSeconds ?? DEFAULT_SIGNATURE_LIFETIME);
171
+ const signature = await sign(clients, moveToStreamTypedData(signingDomains(instance).packageRegistry, { packageRoot: args.packageRoot, itemHash: hash, nonce, deadline }));
172
+ return { nonce, deadline, signature: walletProof(account, signature) };
173
+ }
174
+ /** The token a start minted, read from the receipt's `SaleStarted` log. */
175
+ export function startedTokenId(sent, instance, token) {
176
+ const started = parseEventLogs({ abi: englishAuctionAbi, logs: sent.receipt.logs, eventName: "SaleStarted" }).find((log) => isAddressEqual(log.address, instance.addresses.englishAuction) && isAddressEqual(log.args.token, token));
177
+ if (!started)
178
+ throw new FlowError("MISSING_EVENT", "The transaction emitted no SaleStarted for this token contract.");
179
+ return started.args.tokenId;
180
+ }
181
+ /**
182
+ * Starts the sale of an approved, accepted curated item: the work is minted into the English
183
+ * auction and its 24-hour sale begins (the duration is the auction's setting; r10 runs one
184
+ * hour). Anyone may send it; the artist's signed move is what authorizes it.
185
+ *
186
+ * Without `firstBid` it goes through `SaleStarter.start`, which also deploys the payout vaults
187
+ * and opens the work's record in the same transaction. With `firstBid` (wei, at least the
188
+ * opening bid) it is `EnglishAuction.startWithBid`, and the record is opened afterwards with
189
+ * `openRecord`.
190
+ *
191
+ * If the item is minted already nothing is sent and its token is returned. The check compares
192
+ * item hashes, not only the content (`readMintedToken`).
193
+ *
194
+ * Contract: [`SaleStarter.start`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/SaleStarter.sol),
195
+ * [`EnglishAuction.startWithBid`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/EnglishAuction.sol);
196
+ * the request is `encodeStreamMintRequest`.
197
+ */
198
+ export async function startCuratedSale(clients, instance, args) {
199
+ await assertReady(clients, instance);
200
+ const token = instance.addresses.stream;
201
+ if (mediaHash(instance.protocol, args.media) !== args.item.mediaHash) {
202
+ throw new FlowError("INVALID_INPUT", "The media list does not hash to the item's mediaHash.");
203
+ }
204
+ const minted = await readMintedToken(clients.public, instance, token, args.item);
205
+ if (minted !== null)
206
+ return { tokenId: minted, saleId: saleIdOf(token, minted), sent: null };
207
+ const move = args.move ?? (await signMove(clients, instance, args));
208
+ const request = encodeStreamMintRequest({ packageRoot: args.packageRoot, item: args.item, proof: args.proof, move });
209
+ const sent = args.firstBid === undefined
210
+ ? await send(clients, instance, {
211
+ address: instance.addresses.saleStarter,
212
+ abi: saleStarterAbi,
213
+ functionName: "start",
214
+ args: [instance.addresses.englishAuction, token, request, args.media],
215
+ })
216
+ : await send(clients, instance, {
217
+ address: instance.addresses.englishAuction,
218
+ abi: englishAuctionAbi,
219
+ functionName: "startWithBid",
220
+ args: [token, request, zeroAddress],
221
+ value: args.firstBid,
222
+ });
223
+ const tokenId = startedTokenId(sent, instance, token);
224
+ return { tokenId, saleId: saleIdOf(token, tokenId), sent };
225
+ }
226
+ /**
227
+ * Publishes a work's record: its files, license and descriptive record become readable on
228
+ * chain (`open`), and, when every file is stored in full, it is marked complete on chain so
229
+ * the renderer can serve the art (`markOnChainComplete`). Anyone may send both; each is
230
+ * skipped when done. The item and media must be the ones the work was minted from.
231
+ *
232
+ * `SaleStarter.start` opens the record itself; a work started with `startWithBid` or any
233
+ * Independent Stream work needs this call.
234
+ *
235
+ * Contract: [`StreamWorkFacts6529.open`, `markOnChainComplete`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/core/StreamWorkFacts6529.sol).
236
+ */
237
+ export async function openRecord(clients, instance, args) {
238
+ await assertReady(clients, instance);
239
+ const token = args.token ?? instance.addresses.stream;
240
+ const facts = { address: instance.addresses.workFacts, abi: streamWorkFacts6529Abi };
241
+ const read = () => readContract(clients.public, { ...facts, functionName: "factsOf", args: [token, args.tokenId] });
242
+ let opened = null;
243
+ if (!(await read()).opened) {
244
+ opened = await send(clients, instance, { ...facts, functionName: "open", args: [token, args.tokenId, args.item, args.media] });
245
+ }
246
+ // Read again: someone may have completed it in between, and completion needs every chunk stored.
247
+ let completed = null;
248
+ if (!(await read()).onChainComplete) {
249
+ const possible = await orOnRevert(simulateContract(clients.public, { ...facts, functionName: "markOnChainComplete", args: [token, args.tokenId], account: accountOf(clients) }), null);
250
+ if (possible)
251
+ completed = await send(clients, instance, { ...facts, functionName: "markOnChainComplete", args: [token, args.tokenId] });
252
+ }
253
+ return { opened, completed };
254
+ }
255
+ /**
256
+ * Opens the edition sale of a curated edition master, beside its 1/1 sale. Anyone may send
257
+ * it, from the start of the 1/1 until 15 minutes after the 1/1 ends, which is when the edition
258
+ * sale closes. Until someone opens it, nobody can bid on the editions. Nothing is sent when it
259
+ * is open already.
260
+ *
261
+ * Contract: [`UniformEditionAuction.open`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/UniformEditionAuction.sol)
262
+ * with `encodeCuratedEditionOpen(item, packageRoot, proof)`.
263
+ *
264
+ * @returns the edition sale's ID and the transaction (null when it was open already).
265
+ */
266
+ export async function openCuratedEditionSale(clients, instance, args) {
267
+ await assertReady(clients, instance);
268
+ const auction = { address: instance.addresses.editionAuction, abi: uniformEditionAuctionAbi };
269
+ const editionSaleId = saleIdOf(instance.addresses.streamEditions, args.tokenId);
270
+ const existing = await orOnRevert(readContract(clients.public, { ...auction, functionName: "auction", args: [editionSaleId] }), null);
271
+ if (existing && existing.status !== 0)
272
+ return { saleId: editionSaleId, sent: null };
273
+ const sent = await send(clients, instance, {
274
+ ...auction,
275
+ functionName: "open",
276
+ args: [instance.addresses.streamEditions, args.tokenId, encodeCuratedEditionOpen(args.item, args.packageRoot, args.proof)],
277
+ });
278
+ return { saleId: editionSaleId, sent };
279
+ }
@@ -0,0 +1,100 @@
1
+ import { type Address } from "viem";
2
+ import type { StreamInstance } from "../instance.js";
3
+ import type { EditionVenue } from "../reads/editionSale.js";
4
+ import { type Sent, type StreamClients } from "./shared.js";
5
+ /** Which edition sale: the auction contract (`readEditionSale(...).auction`) and the sale ID. */
6
+ export interface EditionSaleRef {
7
+ readonly auction: EditionVenue["auction"];
8
+ readonly saleId: bigint;
9
+ }
10
+ /**
11
+ * Bids for `quantity` copies at price step `step` of the sale's ladder. The bid pays exactly
12
+ * `stepPrice(step) * quantity`, read from the contract here. Every winner pays the one
13
+ * clearing price in the end; what was paid above it comes back when the bid is claimed.
14
+ *
15
+ * Contract: [`UniformEditionAuction.bid`, `stepPrice`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/UniformEditionAuction.sol).
16
+ *
17
+ * @returns the transaction, the bid's ID (needed to raise and to claim) and what was paid.
18
+ */
19
+ export declare function bidEdition(clients: StreamClients, instance: StreamInstance, args: EditionSaleRef & {
20
+ readonly step: number;
21
+ readonly quantity: number;
22
+ }): Promise<Sent & {
23
+ bidId: bigint;
24
+ paid: bigint;
25
+ }>;
26
+ /**
27
+ * Moves the wallet's bid up to a higher price step, paying exactly the difference for every
28
+ * unit. A raised bid joins the back of its new step.
29
+ *
30
+ * Contract: [`UniformEditionAuction.raise`, `bidOf`, `stepPrice`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/UniformEditionAuction.sol).
31
+ */
32
+ export declare function raiseEditionBid(clients: StreamClients, instance: StreamInstance, args: EditionSaleRef & {
33
+ readonly bidId: bigint;
34
+ readonly newStep: number;
35
+ }): Promise<Sent & {
36
+ paid: bigint;
37
+ }>;
38
+ /**
39
+ * Settles a closed edition sale. Anyone may. Settlement runs in calls of bounded gas, so this
40
+ * sends as many transactions as it takes (at most `maxTransactions`, default 20): the
41
+ * contract is asked for the caller's next slice of the order before each one.
42
+ *
43
+ * It can settle only after the sale closed and its 1/1 was settled or cancelled.
44
+ *
45
+ * Contract: [`UniformEditionAuction.settle`, `settlementOrderFor`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/UniformEditionAuction.sol).
46
+ *
47
+ * @returns the transactions sent, whether the sale is settled now, and whether it ended void
48
+ * instead (its 1/1 was cancelled: every bidder takes their ETH back with `claimEditionBid`).
49
+ */
50
+ export declare function settleEditionSale(clients: StreamClients, instance: StreamInstance, args: EditionSaleRef & {
51
+ readonly maxTransactions?: number;
52
+ }): Promise<{
53
+ settled: boolean;
54
+ voided: boolean;
55
+ transactions: Sent[];
56
+ }>;
57
+ /**
58
+ * Claims the wallet's bid after settlement: the copies it won are minted to `to` (default:
59
+ * the wallet itself), and the ETH it did not spend is paid back.
60
+ *
61
+ * Contract: [`UniformEditionAuction.claimBid`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/UniformEditionAuction.sol).
62
+ *
63
+ * @returns the transaction, the copies won and the ETH returned.
64
+ */
65
+ export declare function claimEditionBid(clients: StreamClients, instance: StreamInstance, args: EditionSaleRef & {
66
+ readonly bidId: bigint;
67
+ readonly to?: Address;
68
+ }): Promise<Sent & {
69
+ unitsWon: bigint;
70
+ refund: bigint;
71
+ }>;
72
+ /**
73
+ * Claims someone else's bid for them. Anyone may: the copies go to the bidder, and the refund
74
+ * is credited to the bidder, who withdraws it with `claimEditionCredit`.
75
+ *
76
+ * Contract: [`UniformEditionAuction.claimBidFor`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/UniformEditionAuction.sol).
77
+ */
78
+ export declare function claimEditionBidFor(clients: StreamClients, instance: StreamInstance, args: EditionSaleRef & {
79
+ readonly bidId: bigint;
80
+ }): Promise<Sent & {
81
+ unitsWon: bigint;
82
+ refund: bigint;
83
+ }>;
84
+ /**
85
+ * Withdraws the ETH credited to the connected wallet on an edition auction (refunds that were
86
+ * credited instead of paid), to `to` (default: the wallet itself).
87
+ *
88
+ * Contract: [`UniformEditionAuction.claim`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/UniformEditionAuction.sol)
89
+ * with the ETH currency (the zero address).
90
+ */
91
+ export declare function claimEditionCredit(clients: StreamClients, instance: StreamInstance, args: Pick<EditionSaleRef, "auction"> & {
92
+ readonly to?: Address;
93
+ }): Promise<Sent>;
94
+ /**
95
+ * Voids an edition sale that can no longer settle (`readEditionSale(...).abandonable`), so
96
+ * every bidder can take their ETH back. Anyone may.
97
+ *
98
+ * Contract: [`UniformEditionAuction.abandon`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/UniformEditionAuction.sol).
99
+ */
100
+ export declare function abandonEditionSale(clients: StreamClients, instance: StreamInstance, args: EditionSaleRef): Promise<Sent>;