@6529-collections/stream-sdk 0.0.0-stage → 0.1.0-bootstrap.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,117 @@
1
+ import { type Address, type Hex } from "viem";
2
+ import type { StreamInstance } from "../instance.js";
3
+ import { type ReleaseAuthorization } from "../signing/messages.js";
4
+ import type { ArtistIdentity, Payee } from "../types.js";
5
+ import { type Sent, type StreamClients } from "./shared.js";
6
+ /**
7
+ * Pays out everything the escrow holds for `wallet` to that wallet. Anyone may call it; the
8
+ * money can only go to the wallet it was credited to.
9
+ *
10
+ * Contract: [`RevenueEscrow.flush`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/economics/RevenueEscrow.sol).
11
+ *
12
+ * @returns the transaction and the amount paid.
13
+ */
14
+ export declare function flushEscrow(clients: StreamClients, instance: StreamInstance, args: {
15
+ readonly wallet: Address;
16
+ readonly asset?: Address;
17
+ }): Promise<Sent & {
18
+ amount: bigint;
19
+ }>;
20
+ /**
21
+ * Moves the part of an account's escrow credit that has waited the unclaimed period to the
22
+ * network's fee vault. Anyone may call it, and it reverts while no part has waited long
23
+ * enough (`readEscrow(...).expirableNow` says how much has).
24
+ *
25
+ * Contract: [`RevenueEscrow.expire`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/economics/RevenueEscrow.sol).
26
+ */
27
+ export declare function expireEscrow(clients: StreamClients, instance: StreamInstance, args: {
28
+ readonly wallet: Address;
29
+ readonly asset?: Address;
30
+ }): Promise<Sent>;
31
+ /**
32
+ * Forwards what a network vault holds to its destination. Anyone may call it; the vault can
33
+ * send nowhere else. `amount` is in wei (or the asset's smallest unit).
34
+ *
35
+ * Contract: [`GovernedVault.forward`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/economics/GovernedVault.sol).
36
+ */
37
+ export declare function forwardVault(clients: StreamClients, instance: StreamInstance, args: {
38
+ readonly vault: "fee" | "museum";
39
+ readonly amount: bigint;
40
+ readonly asset?: Address;
41
+ }): Promise<Sent>;
42
+ /** One claim of a batch: a vault's payee list and the payee's position in it. */
43
+ export interface VaultClaim {
44
+ readonly payees: readonly Payee[];
45
+ readonly index: number;
46
+ readonly asset?: Address;
47
+ }
48
+ /**
49
+ * Pays out several fixed-address payees of several vaults in one transaction. Anyone may call
50
+ * it. Only payees named by a fixed address can be paid this way (a payee named by artist ID
51
+ * must call `releaseFromVault` from its payout address, or sign with
52
+ * `signReleaseAuthorization`). With `continueOnFailure` an item that fails is skipped and
53
+ * reported as zero; without it one failure reverts the batch.
54
+ *
55
+ * Contract: [`ClaimRouter.claim`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/economics/ClaimRouter.sol).
56
+ */
57
+ export declare function claimMany(clients: StreamClients, instance: StreamInstance, args: {
58
+ readonly claims: readonly VaultClaim[];
59
+ readonly continueOnFailure?: boolean;
60
+ }): Promise<Sent>;
61
+ /** A payee's signed permission for someone else to send its share to a recipient. */
62
+ export interface SignedRelease {
63
+ readonly authorization: ReleaseAuthorization;
64
+ /** The payee's signature (65 bytes; not a wallet proof). */
65
+ readonly signature: Hex;
66
+ readonly payees: readonly Payee[];
67
+ }
68
+ /**
69
+ * A payee signs a permission to release its share of a vault to `recipient`, for anyone to
70
+ * send (`releaseSigned`). The connected wallet must be the payee's own address: the payout
71
+ * address of its account, or the fixed address.
72
+ *
73
+ * Every field of the signed message comes from the caller or is computed here: the vault
74
+ * address is derived locally from the payee list (`vaultAddress`), never read from an RPC,
75
+ * and the amount is stated by the caller, `"all"` included. Only the deadline rests on the
76
+ * chain's clock (`chainDeadline`). The result carries the message, so a page can show the
77
+ * vault, recipient and amount before the wallet is asked.
78
+ *
79
+ * Contract: message `ReleaseAuthorization` (`releaseAuthorizationTypedData`), checked by
80
+ * [`SplitLedger.releaseWithAuthorization`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/economics/SplitLedger.sol).
81
+ */
82
+ export declare function signReleaseAuthorization(clients: StreamClients, instance: StreamInstance, args: {
83
+ readonly payees: readonly Payee[];
84
+ readonly index: number;
85
+ readonly recipient: Address;
86
+ readonly nonce: bigint;
87
+ /** The exact amount, or `"all"` for everything releasable when the release is sent. */
88
+ readonly amount: bigint | "all";
89
+ readonly asset?: Address;
90
+ readonly lifetimeSeconds?: number;
91
+ }): Promise<SignedRelease>;
92
+ /**
93
+ * Sends a release a payee signed (`signReleaseAuthorization`). Anyone may; the money goes to
94
+ * the recipient the payee named.
95
+ *
96
+ * Contract: [`SplitLedger.releaseWithAuthorization`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/economics/SplitLedger.sol).
97
+ */
98
+ export declare function releaseSigned(clients: StreamClients, instance: StreamInstance, release: SignedRelease): Promise<Sent>;
99
+ /**
100
+ * The new root of an account signs its acceptance of a replacement of the root by the
101
+ * network. The network stages the replacement with this proof; it takes effect after its
102
+ * notice period unless a wallet of the account contests it (`cancelIdentityChange`).
103
+ *
104
+ * Contract: message `ReplacementAcceptance` (`replacementAcceptanceTypedData`), checked by
105
+ * [`Accounts.stageReplacement`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/identity/Accounts.sol).
106
+ *
107
+ * @returns the deadline signed and the new root's signature, as `stageReplacement` takes them.
108
+ */
109
+ export declare function signReplacementAcceptance(clients: StreamClients, instance: StreamInstance, args: {
110
+ readonly artistId: bigint;
111
+ readonly next: ArtistIdentity;
112
+ readonly evidenceHash: Hex;
113
+ readonly lifetimeSeconds?: number;
114
+ }): Promise<{
115
+ deadline: bigint;
116
+ signature: Hex;
117
+ }>;
@@ -0,0 +1,148 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { isAddressEqual, parseEventLogs } from "viem";
3
+ import { readContract } from "viem/actions";
4
+ import { CURRENCY_ETH, ZERO_HASH } from "../constants.js";
5
+ import { FlowError } from "../errors.js";
6
+ import { claimRouterAbi } from "../generated/abis/ClaimRouter.js";
7
+ import { governedVaultAbi } from "../generated/abis/GovernedVault.js";
8
+ import { revenueEscrowAbi } from "../generated/abis/RevenueEscrow.js";
9
+ import { splitLedgerAbi } from "../generated/abis/SplitLedger.js";
10
+ import { vaultAddress } from "../hashing/vault.js";
11
+ import { chainDeadline } from "../reads/chain.js";
12
+ import { releaseAuthorizationTypedData, replacementAcceptanceTypedData, signingDomains } from "../signing/messages.js";
13
+ import { assertReady, send, sign } from "./shared.js";
14
+ /**
15
+ * Pays out everything the escrow holds for `wallet` to that wallet. Anyone may call it; the
16
+ * money can only go to the wallet it was credited to.
17
+ *
18
+ * Contract: [`RevenueEscrow.flush`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/economics/RevenueEscrow.sol).
19
+ *
20
+ * @returns the transaction and the amount paid.
21
+ */
22
+ export async function flushEscrow(clients, instance, args) {
23
+ const sent = await send(clients, instance, {
24
+ address: instance.addresses.revenueEscrow,
25
+ abi: revenueEscrowAbi,
26
+ functionName: "flush",
27
+ args: [args.wallet, args.asset ?? CURRENCY_ETH],
28
+ });
29
+ const flushed = parseEventLogs({ abi: revenueEscrowAbi, logs: sent.receipt.logs, eventName: "Flushed" }).filter((log) => isAddressEqual(log.address, instance.addresses.revenueEscrow));
30
+ return { ...sent, amount: flushed.reduce((sum, log) => sum + log.args.amount, 0n) };
31
+ }
32
+ /**
33
+ * Moves the part of an account's escrow credit that has waited the unclaimed period to the
34
+ * network's fee vault. Anyone may call it, and it reverts while no part has waited long
35
+ * enough (`readEscrow(...).expirableNow` says how much has).
36
+ *
37
+ * Contract: [`RevenueEscrow.expire`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/economics/RevenueEscrow.sol).
38
+ */
39
+ export async function expireEscrow(clients, instance, args) {
40
+ return send(clients, instance, {
41
+ address: instance.addresses.revenueEscrow,
42
+ abi: revenueEscrowAbi,
43
+ functionName: "expire",
44
+ args: [args.wallet, args.asset ?? CURRENCY_ETH],
45
+ });
46
+ }
47
+ /**
48
+ * Forwards what a network vault holds to its destination. Anyone may call it; the vault can
49
+ * send nowhere else. `amount` is in wei (or the asset's smallest unit).
50
+ *
51
+ * Contract: [`GovernedVault.forward`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/economics/GovernedVault.sol).
52
+ */
53
+ export async function forwardVault(clients, instance, args) {
54
+ return send(clients, instance, {
55
+ address: args.vault === "fee" ? instance.addresses.feeVault : instance.addresses.museumVault,
56
+ abi: governedVaultAbi,
57
+ functionName: "forward",
58
+ args: [args.asset ?? CURRENCY_ETH, args.amount],
59
+ });
60
+ }
61
+ /**
62
+ * Pays out several fixed-address payees of several vaults in one transaction. Anyone may call
63
+ * it. Only payees named by a fixed address can be paid this way (a payee named by artist ID
64
+ * must call `releaseFromVault` from its payout address, or sign with
65
+ * `signReleaseAuthorization`). With `continueOnFailure` an item that fails is skipped and
66
+ * reported as zero; without it one failure reverts the batch.
67
+ *
68
+ * Contract: [`ClaimRouter.claim`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/economics/ClaimRouter.sol).
69
+ */
70
+ export async function claimMany(clients, instance, args) {
71
+ if (args.claims.some((claim) => claim.payees[claim.index]?.artistId !== 0n)) {
72
+ throw new FlowError("INVALID_INPUT", "A batch claim pays only payees named by a fixed address.");
73
+ }
74
+ return send(clients, instance, {
75
+ address: instance.addresses.claimRouter,
76
+ abi: claimRouterAbi,
77
+ functionName: "claim",
78
+ args: [args.claims.map((claim) => ({ payees: claim.payees, salt: ZERO_HASH, asset: claim.asset ?? CURRENCY_ETH, payee: BigInt(claim.index) })), args.continueOnFailure ?? false],
79
+ });
80
+ }
81
+ /**
82
+ * A payee signs a permission to release its share of a vault to `recipient`, for anyone to
83
+ * send (`releaseSigned`). The connected wallet must be the payee's own address: the payout
84
+ * address of its account, or the fixed address.
85
+ *
86
+ * Every field of the signed message comes from the caller or is computed here: the vault
87
+ * address is derived locally from the payee list (`vaultAddress`), never read from an RPC,
88
+ * and the amount is stated by the caller, `"all"` included. Only the deadline rests on the
89
+ * chain's clock (`chainDeadline`). The result carries the message, so a page can show the
90
+ * vault, recipient and amount before the wallet is asked.
91
+ *
92
+ * Contract: message `ReleaseAuthorization` (`releaseAuthorizationTypedData`), checked by
93
+ * [`SplitLedger.releaseWithAuthorization`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/economics/SplitLedger.sol).
94
+ */
95
+ export async function signReleaseAuthorization(clients, instance, args) {
96
+ const account = await assertReady(clients, instance);
97
+ const ledger = { address: instance.addresses.splitLedger, abi: splitLedgerAbi };
98
+ const wallet = vaultAddress(instance, args.payees);
99
+ // Only a courtesy check: a used nonce makes the release fail, it cannot change what is signed.
100
+ const used = await readContract(clients.public, { ...ledger, functionName: "nonceUsed", args: [account, args.nonce] });
101
+ if (used)
102
+ throw new FlowError("INVALID_INPUT", `Nonce ${args.nonce} was used already by ${account}.`);
103
+ const authorization = {
104
+ wallet,
105
+ asset: args.asset ?? CURRENCY_ETH,
106
+ payee: BigInt(args.index),
107
+ account,
108
+ recipient: args.recipient,
109
+ amount: args.amount === "all" ? 2n ** 256n - 1n : args.amount,
110
+ nonce: args.nonce,
111
+ deadline: await chainDeadline(clients.public, args.lifetimeSeconds ?? 3_600),
112
+ };
113
+ const signature = await sign(clients, releaseAuthorizationTypedData(signingDomains(instance).splitLedger, authorization));
114
+ return { authorization, signature, payees: args.payees };
115
+ }
116
+ /**
117
+ * Sends a release a payee signed (`signReleaseAuthorization`). Anyone may; the money goes to
118
+ * the recipient the payee named.
119
+ *
120
+ * Contract: [`SplitLedger.releaseWithAuthorization`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/economics/SplitLedger.sol).
121
+ */
122
+ export async function releaseSigned(clients, instance, release) {
123
+ return send(clients, instance, {
124
+ address: instance.addresses.splitLedger,
125
+ abi: splitLedgerAbi,
126
+ functionName: "releaseWithAuthorization",
127
+ args: [release.payees, ZERO_HASH, release.authorization, release.signature],
128
+ });
129
+ }
130
+ /**
131
+ * The new root of an account signs its acceptance of a replacement of the root by the
132
+ * network. The network stages the replacement with this proof; it takes effect after its
133
+ * notice period unless a wallet of the account contests it (`cancelIdentityChange`).
134
+ *
135
+ * Contract: message `ReplacementAcceptance` (`replacementAcceptanceTypedData`), checked by
136
+ * [`Accounts.stageReplacement`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/identity/Accounts.sol).
137
+ *
138
+ * @returns the deadline signed and the new root's signature, as `stageReplacement` takes them.
139
+ */
140
+ export async function signReplacementAcceptance(clients, instance, args) {
141
+ const account = await assertReady(clients, instance);
142
+ if (!isAddressEqual(account, args.next.root)) {
143
+ throw new FlowError("INVALID_INPUT", "The acceptance is signed by the new root itself.");
144
+ }
145
+ const deadline = await chainDeadline(clients.public, args.lifetimeSeconds ?? 30 * 86_400);
146
+ const signature = await sign(clients, replacementAcceptanceTypedData(signingDomains(instance).accounts, { artistId: args.artistId, next: args.next, evidenceHash: args.evidenceHash, deadline }));
147
+ return { deadline, signature };
148
+ }
@@ -0,0 +1,144 @@
1
+ import type { Address, Client, Hex } from "viem";
2
+ import { type WorkState } from "../hashing/workState.js";
3
+ import { type StreamInstance } from "../instance.js";
4
+ import type { WorkRef } from "../reads/work.js";
5
+ import type { License } from "../types.js";
6
+ import { type Sent, type StreamClients } from "./shared.js";
7
+ /** A work's changeable state and the hash that names it. */
8
+ export interface WorkStateRead extends WorkState {
9
+ /** `workStateHash` of the fields above, computed here. */
10
+ readonly stateHash: Hex;
11
+ /** `WORK_POWERS` bits the artist has given up for good. */
12
+ readonly renouncedPowers: number;
13
+ /** When someone other than the artist asked to finalize (Unix seconds), or 0. */
14
+ readonly finalizeNoticeAt: number;
15
+ readonly finalized: boolean;
16
+ }
17
+ /**
18
+ * A work's changeable state (record file, license, royalty rate, renderer, version) and its
19
+ * state hash, computed here from the fields read and checked against the contract's own
20
+ * answer. Every signature over a change to a work names this hash, so the signer can see
21
+ * which state they sign for.
22
+ *
23
+ * Contract: [`WorkRules.versionOf`, `workStateHash`, `renouncedPowers`, `finalizeNoticeAt`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/records/WorkRules.sol),
24
+ * `StreamWorkFacts6529.factsOf`, `Stream6529.workOf`, `moduleOf`.
25
+ *
26
+ * @throws StreamSdkError `MISMATCH` if the hash computed here is not the contract's.
27
+ */
28
+ export declare function readWorkState(client: Client, instance: StreamInstance, ref: WorkRef): Promise<WorkStateRead>;
29
+ /**
30
+ * The lead artist points a work at a new descriptive record, until the record is finalized.
31
+ * The new record must be stored in full in the content store as one chunk, as it is
32
+ * (`storeFile` of a small JSON does that). Any wallet of the lead artist's account may send it.
33
+ *
34
+ * The call names the state it was made for (read and computed here), so it fails instead of
35
+ * overwriting a change someone made in between.
36
+ *
37
+ * Contract: [`WorkRules.setRecord`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/records/WorkRules.sol).
38
+ */
39
+ export declare function setRecord(clients: StreamClients, instance: StreamInstance, args: WorkRef & {
40
+ readonly recordFileId: Hex;
41
+ }): Promise<Sent>;
42
+ /**
43
+ * Finalizes a work's record: from then on its descriptive record and its renderer are fixed.
44
+ * A wallet of the lead artist's account finalizes at once. Anyone else may, once the first
45
+ * sale has an outcome: their first call only records a notice, and a call from 14 days later
46
+ * (`WorkRules.FINALIZE_NOTICE`) finalizes the record as it then stands.
47
+ *
48
+ * Contract: [`WorkRules.finalize`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/records/WorkRules.sol).
49
+ *
50
+ * @returns the transaction, and whether the record is finalized now (false after a notice).
51
+ */
52
+ export declare function finalizeRecord(clients: StreamClients, instance: StreamInstance, ref: WorkRef): Promise<Sent & {
53
+ finalized: boolean;
54
+ }>;
55
+ /** A party's signed consent to a change, bound to the work's state and a deadline. */
56
+ export interface WorkConsent {
57
+ /** The state the consent is for: the change must be made at this state. */
58
+ readonly stateHash: Hex;
59
+ readonly deadline: bigint;
60
+ /** `walletProof(wallet, signature)`: one entry of the call's `partySignatures`. */
61
+ readonly proof: Hex;
62
+ }
63
+ /**
64
+ * A party of a work consents to relicensing it. Every party must consent, in the order the
65
+ * item lists them, and the network then makes the call (`WorkRules.relicense`): a relicense
66
+ * is never the artist's decision alone, and never the network's alone. CC0 is never left.
67
+ *
68
+ * Contract: message `Relicense` (`relicenseTypedData`), checked by
69
+ * [`WorkRules.relicense`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/records/WorkRules.sol).
70
+ */
71
+ export declare function signRelicenseConsent(clients: StreamClients, instance: StreamInstance, args: WorkRef & {
72
+ readonly license: License;
73
+ readonly lifetimeSeconds?: number;
74
+ readonly deadline?: bigint;
75
+ }): Promise<WorkConsent>;
76
+ /**
77
+ * A party of a work consents to a new royalty rate (out of 100,000). Every party must
78
+ * consent, and the network then makes the call (`WorkRules.setRoyaltyRate`).
79
+ *
80
+ * Contract: message `RoyaltyRateChange` (`royaltyRateChangeTypedData`), checked by
81
+ * [`WorkRules.setRoyaltyRate`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/records/WorkRules.sol).
82
+ */
83
+ export declare function signRoyaltyRateConsent(clients: StreamClients, instance: StreamInstance, args: WorkRef & {
84
+ readonly rate: number;
85
+ readonly lifetimeSeconds?: number;
86
+ readonly deadline?: bigint;
87
+ }): Promise<WorkConsent>;
88
+ /**
89
+ * The lead artist signs away powers over a work, for good: `powers` is a mask of
90
+ * `WORK_POWERS`. The result is what `renouncePowers` sends.
91
+ *
92
+ * Contract: message `RenouncePowers` (`renouncePowersTypedData`), checked by
93
+ * [`WorkRules.renounce`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/records/WorkRules.sol).
94
+ */
95
+ export declare function signRenounce(clients: StreamClients, instance: StreamInstance, args: WorkRef & {
96
+ readonly powers: number;
97
+ readonly lifetimeSeconds?: number;
98
+ readonly deadline?: bigint;
99
+ }): Promise<WorkConsent>;
100
+ /**
101
+ * Sends a renunciation the lead artist signed (`signRenounce`). Giving up the power to repin
102
+ * the renderer (`WORK_POWERS.RENDERER_REPIN`) needs the artist's signature only, on a
103
+ * finalized work, and anyone may send it. Giving up the royalty-rate or relicense power also
104
+ * needs the network to make the call.
105
+ *
106
+ * Contract: [`WorkRules.renounce`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/records/WorkRules.sol).
107
+ */
108
+ export declare function renouncePowers(clients: StreamClients, instance: StreamInstance, args: WorkRef & {
109
+ readonly powers: number;
110
+ readonly consent: WorkConsent;
111
+ }): Promise<Sent>;
112
+ /**
113
+ * Registers a copy of one of a work's files outside the chain: `ar://<43-character
114
+ * transaction ID>` (kind `LOCATOR_KIND.ARWEAVE`) or `ipfs://<CIDv1>` (kind `LOCATOR_KIND.IPFS`).
115
+ * A wallet of the work's artist account may add locators until the record is finalized;
116
+ * after that only the platform role. Locators are never removed. `fetchFile` checks whatever
117
+ * a locator serves against the file's hash, so a wrong copy is skipped, not shown.
118
+ *
119
+ * Contract: [`WorkDelivery.addLocator`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/stream/WorkDelivery.sol).
120
+ */
121
+ export declare function addLocator(clients: StreamClients, instance: StreamInstance, args: WorkRef & {
122
+ readonly fileId: Hex;
123
+ readonly kind: number;
124
+ readonly uri: string;
125
+ }): Promise<Sent>;
126
+ /**
127
+ * Attests that the content store holds every chunk of a file, so the file counts as on chain.
128
+ * Anyone may. A large file is attested over several calls of `chunksPerCall` chunks (default
129
+ * 64); this sends them until the file is attested. Nothing is sent when it already is.
130
+ *
131
+ * Contract: [`ContentStore.attestComplete`, `isComplete`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/content/ContentStore.sol).
132
+ *
133
+ * @throws from the simulation, with `ContentChunkMissing`, if a chunk was never written.
134
+ */
135
+ export declare function attestFileComplete(clients: StreamClients, instance: StreamInstance, args: {
136
+ readonly fileId: Hex;
137
+ readonly chunksPerCall?: number;
138
+ readonly maxTransactions?: number;
139
+ }): Promise<{
140
+ complete: boolean;
141
+ transactions: Sent[];
142
+ }>;
143
+ /** The token contract of a work reference. */
144
+ export declare function tokenOfRef(instance: StreamInstance, ref: WorkRef): Address;
@@ -0,0 +1,229 @@
1
+ import { readContract } from "viem/actions";
2
+ import { SLOT_RENDERER } from "../constants.js";
3
+ import { StreamSdkError } from "../errors.js";
4
+ import { contentStoreAbi } from "../generated/abis/ContentStore.js";
5
+ import { stream6529Abi } from "../generated/abis/Stream6529.js";
6
+ import { streamWorkFacts6529Abi } from "../generated/abis/StreamWorkFacts6529.js";
7
+ import { workDeliveryAbi } from "../generated/abis/WorkDelivery.js";
8
+ import { workRulesAbi } from "../generated/abis/WorkRules.js";
9
+ import { licenseKey } from "../hashing/items.js";
10
+ import { workStateHash } from "../hashing/workState.js";
11
+ import { assertInstanceChain } from "../instance.js";
12
+ import { chainDeadline } from "../reads/chain.js";
13
+ import { relicenseTypedData, renouncePowersTypedData, royaltyRateChangeTypedData, signingDomains, walletProof } from "../signing/messages.js";
14
+ import { assertReady, send, sign } from "./shared.js";
15
+ /**
16
+ * A work's changeable state (record file, license, royalty rate, renderer, version) and its
17
+ * state hash, computed here from the fields read and checked against the contract's own
18
+ * answer. Every signature over a change to a work names this hash, so the signer can see
19
+ * which state they sign for.
20
+ *
21
+ * Contract: [`WorkRules.versionOf`, `workStateHash`, `renouncedPowers`, `finalizeNoticeAt`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/records/WorkRules.sol),
22
+ * `StreamWorkFacts6529.factsOf`, `Stream6529.workOf`, `moduleOf`.
23
+ *
24
+ * @throws StreamSdkError `MISMATCH` if the hash computed here is not the contract's.
25
+ */
26
+ export async function readWorkState(client, instance, ref) {
27
+ await assertInstanceChain(client, instance);
28
+ const token = ref.token ?? instance.addresses.stream;
29
+ const rules = { address: instance.addresses.workRules, abi: workRulesAbi };
30
+ const at = [token, ref.tokenId];
31
+ const [facts, work, module, version, expected, renouncedPowers, finalizeNoticeAt] = await Promise.all([
32
+ readContract(client, { address: instance.addresses.workFacts, abi: streamWorkFacts6529Abi, functionName: "factsOf", args: at }),
33
+ readContract(client, { address: token, abi: stream6529Abi, functionName: "workOf", args: [ref.tokenId] }),
34
+ readContract(client, { address: token, abi: stream6529Abi, functionName: "moduleOf", args: [SLOT_RENDERER] }),
35
+ readContract(client, { ...rules, functionName: "versionOf", args: at }),
36
+ readContract(client, { ...rules, functionName: "workStateHash", args: at }),
37
+ readContract(client, { ...rules, functionName: "renouncedPowers", args: at }),
38
+ readContract(client, { ...rules, functionName: "finalizeNoticeAt", args: at }),
39
+ ]);
40
+ const state = {
41
+ rules: instance.addresses.workRules,
42
+ token,
43
+ tokenId: ref.tokenId,
44
+ version,
45
+ recordFileId: facts.recordFileId,
46
+ licenseId: facts.licenseId,
47
+ licenseTextFileId: facts.licenseTextFileId,
48
+ royaltyRate: work.royaltyRate,
49
+ renderer: facts.finalized ? facts.renderer : module,
50
+ };
51
+ const stateHash = workStateHash(instance.protocol, state);
52
+ if (stateHash !== expected) {
53
+ throw new StreamSdkError("MISMATCH", "The work state hash computed here is not the one WorkRules answers.");
54
+ }
55
+ return { ...state, stateHash, renouncedPowers, finalizeNoticeAt, finalized: facts.finalized };
56
+ }
57
+ /**
58
+ * The lead artist points a work at a new descriptive record, until the record is finalized.
59
+ * The new record must be stored in full in the content store as one chunk, as it is
60
+ * (`storeFile` of a small JSON does that). Any wallet of the lead artist's account may send it.
61
+ *
62
+ * The call names the state it was made for (read and computed here), so it fails instead of
63
+ * overwriting a change someone made in between.
64
+ *
65
+ * Contract: [`WorkRules.setRecord`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/records/WorkRules.sol).
66
+ */
67
+ export async function setRecord(clients, instance, args) {
68
+ await assertReady(clients, instance);
69
+ const state = await readWorkState(clients.public, instance, args);
70
+ return send(clients, instance, {
71
+ address: instance.addresses.workRules,
72
+ abi: workRulesAbi,
73
+ functionName: "setRecord",
74
+ args: [state.token, args.tokenId, args.recordFileId, state.stateHash],
75
+ });
76
+ }
77
+ /**
78
+ * Finalizes a work's record: from then on its descriptive record and its renderer are fixed.
79
+ * A wallet of the lead artist's account finalizes at once. Anyone else may, once the first
80
+ * sale has an outcome: their first call only records a notice, and a call from 14 days later
81
+ * (`WorkRules.FINALIZE_NOTICE`) finalizes the record as it then stands.
82
+ *
83
+ * Contract: [`WorkRules.finalize`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/records/WorkRules.sol).
84
+ *
85
+ * @returns the transaction, and whether the record is finalized now (false after a notice).
86
+ */
87
+ export async function finalizeRecord(clients, instance, ref) {
88
+ await assertReady(clients, instance);
89
+ const state = await readWorkState(clients.public, instance, ref);
90
+ const sent = await send(clients, instance, {
91
+ address: instance.addresses.workRules,
92
+ abi: workRulesAbi,
93
+ functionName: "finalize",
94
+ args: [state.token, ref.tokenId, state.stateHash],
95
+ });
96
+ const facts = await readContract(clients.public, {
97
+ address: instance.addresses.workFacts,
98
+ abi: streamWorkFacts6529Abi,
99
+ functionName: "factsOf",
100
+ args: [state.token, ref.tokenId],
101
+ });
102
+ return { ...sent, finalized: facts.finalized };
103
+ }
104
+ /**
105
+ * Thirty days: consents wait for the other parties and for the network's call. Every party of
106
+ * one change signs the same deadline: the first signer's result carries it, and the others
107
+ * pass it as `deadline`.
108
+ */
109
+ const CONSENT_LIFETIME = 30 * 86_400;
110
+ /**
111
+ * A party of a work consents to relicensing it. Every party must consent, in the order the
112
+ * item lists them, and the network then makes the call (`WorkRules.relicense`): a relicense
113
+ * is never the artist's decision alone, and never the network's alone. CC0 is never left.
114
+ *
115
+ * Contract: message `Relicense` (`relicenseTypedData`), checked by
116
+ * [`WorkRules.relicense`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/records/WorkRules.sol).
117
+ */
118
+ export async function signRelicenseConsent(clients, instance, args) {
119
+ const account = await assertReady(clients, instance);
120
+ const state = await readWorkState(clients.public, instance, args);
121
+ const deadline = args.deadline ?? (await chainDeadline(clients.public, args.lifetimeSeconds ?? CONSENT_LIFETIME));
122
+ const signature = await sign(clients, relicenseTypedData(signingDomains(instance).workRules, {
123
+ token: state.token,
124
+ tokenId: args.tokenId,
125
+ licenseKey: licenseKey(args.license.spdxId),
126
+ textFileId: args.license.textFileId,
127
+ stateHash: state.stateHash,
128
+ deadline,
129
+ }));
130
+ return { stateHash: state.stateHash, deadline, proof: walletProof(account, signature) };
131
+ }
132
+ /**
133
+ * A party of a work consents to a new royalty rate (out of 100,000). Every party must
134
+ * consent, and the network then makes the call (`WorkRules.setRoyaltyRate`).
135
+ *
136
+ * Contract: message `RoyaltyRateChange` (`royaltyRateChangeTypedData`), checked by
137
+ * [`WorkRules.setRoyaltyRate`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/records/WorkRules.sol).
138
+ */
139
+ export async function signRoyaltyRateConsent(clients, instance, args) {
140
+ const account = await assertReady(clients, instance);
141
+ const state = await readWorkState(clients.public, instance, args);
142
+ const deadline = args.deadline ?? (await chainDeadline(clients.public, args.lifetimeSeconds ?? CONSENT_LIFETIME));
143
+ const signature = await sign(clients, royaltyRateChangeTypedData(signingDomains(instance).workRules, {
144
+ token: state.token,
145
+ tokenId: args.tokenId,
146
+ rate: args.rate,
147
+ stateHash: state.stateHash,
148
+ deadline,
149
+ }));
150
+ return { stateHash: state.stateHash, deadline, proof: walletProof(account, signature) };
151
+ }
152
+ /**
153
+ * The lead artist signs away powers over a work, for good: `powers` is a mask of
154
+ * `WORK_POWERS`. The result is what `renouncePowers` sends.
155
+ *
156
+ * Contract: message `RenouncePowers` (`renouncePowersTypedData`), checked by
157
+ * [`WorkRules.renounce`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/records/WorkRules.sol).
158
+ */
159
+ export async function signRenounce(clients, instance, args) {
160
+ const account = await assertReady(clients, instance);
161
+ const state = await readWorkState(clients.public, instance, args);
162
+ const deadline = args.deadline ?? (await chainDeadline(clients.public, args.lifetimeSeconds ?? CONSENT_LIFETIME));
163
+ const signature = await sign(clients, renouncePowersTypedData(signingDomains(instance).workRules, {
164
+ token: state.token,
165
+ tokenId: args.tokenId,
166
+ powers: args.powers,
167
+ stateHash: state.stateHash,
168
+ deadline,
169
+ }));
170
+ return { stateHash: state.stateHash, deadline, proof: walletProof(account, signature) };
171
+ }
172
+ /**
173
+ * Sends a renunciation the lead artist signed (`signRenounce`). Giving up the power to repin
174
+ * the renderer (`WORK_POWERS.RENDERER_REPIN`) needs the artist's signature only, on a
175
+ * finalized work, and anyone may send it. Giving up the royalty-rate or relicense power also
176
+ * needs the network to make the call.
177
+ *
178
+ * Contract: [`WorkRules.renounce`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/records/WorkRules.sol).
179
+ */
180
+ export async function renouncePowers(clients, instance, args) {
181
+ return send(clients, instance, {
182
+ address: instance.addresses.workRules,
183
+ abi: workRulesAbi,
184
+ functionName: "renounce",
185
+ args: [args.token ?? instance.addresses.stream, args.tokenId, args.powers, args.consent.stateHash, args.consent.deadline, args.consent.proof],
186
+ });
187
+ }
188
+ /**
189
+ * Registers a copy of one of a work's files outside the chain: `ar://<43-character
190
+ * transaction ID>` (kind `LOCATOR_KIND.ARWEAVE`) or `ipfs://<CIDv1>` (kind `LOCATOR_KIND.IPFS`).
191
+ * A wallet of the work's artist account may add locators until the record is finalized;
192
+ * after that only the platform role. Locators are never removed. `fetchFile` checks whatever
193
+ * a locator serves against the file's hash, so a wrong copy is skipped, not shown.
194
+ *
195
+ * Contract: [`WorkDelivery.addLocator`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/stream/WorkDelivery.sol).
196
+ */
197
+ export async function addLocator(clients, instance, args) {
198
+ return send(clients, instance, {
199
+ address: instance.addresses.workDelivery,
200
+ abi: workDeliveryAbi,
201
+ functionName: "addLocator",
202
+ args: [args.token ?? instance.addresses.stream, args.tokenId, args.fileId, { kind: args.kind, uri: args.uri }],
203
+ });
204
+ }
205
+ /**
206
+ * Attests that the content store holds every chunk of a file, so the file counts as on chain.
207
+ * Anyone may. A large file is attested over several calls of `chunksPerCall` chunks (default
208
+ * 64); this sends them until the file is attested. Nothing is sent when it already is.
209
+ *
210
+ * Contract: [`ContentStore.attestComplete`, `isComplete`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/content/ContentStore.sol).
211
+ *
212
+ * @throws from the simulation, with `ContentChunkMissing`, if a chunk was never written.
213
+ */
214
+ export async function attestFileComplete(clients, instance, args) {
215
+ await assertReady(clients, instance);
216
+ const store = { address: instance.addresses.contentStore, abi: contentStoreAbi };
217
+ const isComplete = () => readContract(clients.public, { ...store, functionName: "isComplete", args: [args.fileId] });
218
+ const transactions = [];
219
+ for (let round = 0; round < (args.maxTransactions ?? 80); round++) {
220
+ if (await isComplete())
221
+ return { complete: true, transactions };
222
+ transactions.push(await send(clients, instance, { ...store, functionName: "attestComplete", args: [args.fileId, BigInt(args.chunksPerCall ?? 64)] }));
223
+ }
224
+ return { complete: await isComplete(), transactions };
225
+ }
226
+ /** The token contract of a work reference. */
227
+ export function tokenOfRef(instance, ref) {
228
+ return ref.token ?? instance.addresses.stream;
229
+ }