@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,82 @@
1
+ import { type Address } from "viem";
2
+ import type { StreamInstance } from "../instance.js";
3
+ import type { WorkRef } from "../reads/work.js";
4
+ import { type Sent, type StreamClients } from "./shared.js";
5
+ /**
6
+ * Bids on a 1/1. `amount` is the whole bid in wei and must be at least
7
+ * `readSale(...).minimumBid`. The bidder it outbids is credited, not paid: they withdraw with
8
+ * `claimAuctionCredit`. A bid in the last minutes moves the end (the auction's extension window).
9
+ *
10
+ * `recipient` receives the work if the bid wins. Default: the bidder.
11
+ *
12
+ * Contract: [`EnglishAuction.bid`, `minimumBid`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/EnglishAuction.sol).
13
+ */
14
+ export declare function placeBid(clients: StreamClients, instance: StreamInstance, args: WorkRef & {
15
+ readonly amount: bigint;
16
+ readonly recipient?: Address;
17
+ }): Promise<Sent>;
18
+ /**
19
+ * Finishes a sale after its end. Anyone may send it. A sold work goes to the winner (or waits
20
+ * for `claimDelivery` if it could not be delivered) and the price is split; an unsold curated
21
+ * work goes to the museum; an unsold Independent Stream work stays in the auction and can be
22
+ * offered again (`restartSale`).
23
+ *
24
+ * Contract: [`EnglishAuction.settle`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/EnglishAuction.sol).
25
+ */
26
+ export declare function settleSale(clients: StreamClients, instance: StreamInstance, ref: WorkRef): Promise<Sent>;
27
+ /**
28
+ * Withdraws the ETH credited to the connected wallet on the English auction (outbid bids),
29
+ * to `to` (default: the wallet itself).
30
+ *
31
+ * Contract: [`EnglishAuction.claim`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/EnglishAuction.sol).
32
+ *
33
+ * @returns the transaction and the amount withdrawn in wei.
34
+ */
35
+ export declare function claimAuctionCredit(clients: StreamClients, instance: StreamInstance, to?: Address): Promise<Sent & {
36
+ amount: bigint;
37
+ }>;
38
+ /**
39
+ * Collects a work whose delivery did not go through at settlement, to `to` (default: the
40
+ * wallet itself). The recipient the bid named may (`readSale(...).pendingDelivery`), and so may
41
+ * the bidder.
42
+ *
43
+ * Contract: [`EnglishAuction.claimDelivery`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/EnglishAuction.sol).
44
+ */
45
+ export declare function claimDelivery(clients: StreamClients, instance: StreamInstance, args: WorkRef & {
46
+ readonly to?: Address;
47
+ }): Promise<Sent>;
48
+ /**
49
+ * Offers an unsold Independent Stream work again: a new sale under the same sale ID. Anyone
50
+ * may send it, from `restartDelay` seconds after the end. Curated works are never offered
51
+ * again: unsold, they go to the museum.
52
+ *
53
+ * Contract: [`EnglishAuction.restart`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/EnglishAuction.sol).
54
+ */
55
+ export declare function restartSale(clients: StreamClients, instance: StreamInstance, ref: WorkRef & {
56
+ readonly token: Address;
57
+ }): Promise<Sent>;
58
+ /**
59
+ * Settles an ended Independent Stream sale, or, if its token contract refuses the settlement,
60
+ * returns the top bid to its bidder as a credit and leaves the work to be offered again.
61
+ * Accepted from `readSale(...).refusableAt`. Anyone may send it.
62
+ *
63
+ * Contract: [`EnglishAuction.settleOrRefund`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/EnglishAuction.sol).
64
+ */
65
+ export declare function settleOrRefund(clients: StreamClients, instance: StreamInstance, ref: WorkRef & {
66
+ readonly token: Address;
67
+ }): Promise<Sent>;
68
+ /**
69
+ * Sends a rescued work the auction still holds to the museum. Anyone may. It applies only to
70
+ * a work whose recorded outcome is "rescued" (the network moved it out of a removed sale
71
+ * contract) and that sits in this auction; any other work is left alone and the call reverts.
72
+ *
73
+ * Contract: [`EnglishAuction.sendRescuedToMuseum`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/EnglishAuction.sol).
74
+ */
75
+ export declare function sendRescuedToMuseum(clients: StreamClients, instance: StreamInstance, ref: WorkRef): Promise<Sent>;
76
+ /**
77
+ * The top bidder takes their bid back from a sale the network paused. Not possible in a
78
+ * running sale. The bid is credited, not paid: withdraw it with `claimAuctionCredit`.
79
+ *
80
+ * Contract: [`EnglishAuction.withdrawBid`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/EnglishAuction.sol).
81
+ */
82
+ export declare function withdrawBid(clients: StreamClients, instance: StreamInstance, ref: WorkRef): Promise<Sent>;
@@ -0,0 +1,113 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { isAddressEqual, parseEventLogs, zeroAddress } from "viem";
3
+ import { readContract } from "viem/actions";
4
+ import { FlowError } from "../errors.js";
5
+ import { englishAuctionAbi } from "../generated/abis/EnglishAuction.js";
6
+ import { saleId as saleIdOf } from "../hashing/ids.js";
7
+ import { accountOf, send } from "./shared.js";
8
+ function auctionOf(instance) {
9
+ return { address: instance.addresses.englishAuction, abi: englishAuctionAbi };
10
+ }
11
+ function idOf(instance, ref) {
12
+ return saleIdOf(ref.token ?? instance.addresses.stream, ref.tokenId);
13
+ }
14
+ /**
15
+ * Bids on a 1/1. `amount` is the whole bid in wei and must be at least
16
+ * `readSale(...).minimumBid`. The bidder it outbids is credited, not paid: they withdraw with
17
+ * `claimAuctionCredit`. A bid in the last minutes moves the end (the auction's extension window).
18
+ *
19
+ * `recipient` receives the work if the bid wins. Default: the bidder.
20
+ *
21
+ * Contract: [`EnglishAuction.bid`, `minimumBid`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/EnglishAuction.sol).
22
+ */
23
+ export async function placeBid(clients, instance, args) {
24
+ const id = idOf(instance, args);
25
+ const minimum = await readContract(clients.public, { ...auctionOf(instance), functionName: "minimumBid", args: [id] });
26
+ if (args.amount < minimum) {
27
+ throw new FlowError("INVALID_INPUT", `The bid must be at least ${minimum} wei.`);
28
+ }
29
+ return send(clients, instance, {
30
+ ...auctionOf(instance),
31
+ functionName: "bid",
32
+ args: [id, args.recipient ?? zeroAddress],
33
+ value: args.amount,
34
+ });
35
+ }
36
+ /**
37
+ * Finishes a sale after its end. Anyone may send it. A sold work goes to the winner (or waits
38
+ * for `claimDelivery` if it could not be delivered) and the price is split; an unsold curated
39
+ * work goes to the museum; an unsold Independent Stream work stays in the auction and can be
40
+ * offered again (`restartSale`).
41
+ *
42
+ * Contract: [`EnglishAuction.settle`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/EnglishAuction.sol).
43
+ */
44
+ export async function settleSale(clients, instance, ref) {
45
+ return send(clients, instance, { ...auctionOf(instance), functionName: "settle", args: [idOf(instance, ref)] });
46
+ }
47
+ /**
48
+ * Withdraws the ETH credited to the connected wallet on the English auction (outbid bids),
49
+ * to `to` (default: the wallet itself).
50
+ *
51
+ * Contract: [`EnglishAuction.claim`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/EnglishAuction.sol).
52
+ *
53
+ * @returns the transaction and the amount withdrawn in wei.
54
+ */
55
+ export async function claimAuctionCredit(clients, instance, to) {
56
+ const account = accountOf(clients);
57
+ const sent = await send(clients, instance, { ...auctionOf(instance), functionName: "claim", args: [to ?? account] });
58
+ const claimed = parseEventLogs({ abi: englishAuctionAbi, logs: sent.receipt.logs, eventName: "Claimed" }).filter((log) => isAddressEqual(log.address, instance.addresses.englishAuction));
59
+ return { ...sent, amount: claimed.reduce((sum, log) => sum + log.args.amount, 0n) };
60
+ }
61
+ /**
62
+ * Collects a work whose delivery did not go through at settlement, to `to` (default: the
63
+ * wallet itself). The recipient the bid named may (`readSale(...).pendingDelivery`), and so may
64
+ * the bidder.
65
+ *
66
+ * Contract: [`EnglishAuction.claimDelivery`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/EnglishAuction.sol).
67
+ */
68
+ export async function claimDelivery(clients, instance, args) {
69
+ return send(clients, instance, {
70
+ ...auctionOf(instance),
71
+ functionName: "claimDelivery",
72
+ args: [idOf(instance, args), args.to ?? accountOf(clients)],
73
+ });
74
+ }
75
+ /**
76
+ * Offers an unsold Independent Stream work again: a new sale under the same sale ID. Anyone
77
+ * may send it, from `restartDelay` seconds after the end. Curated works are never offered
78
+ * again: unsold, they go to the museum.
79
+ *
80
+ * Contract: [`EnglishAuction.restart`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/EnglishAuction.sol).
81
+ */
82
+ export async function restartSale(clients, instance, ref) {
83
+ return send(clients, instance, { ...auctionOf(instance), functionName: "restart", args: [idOf(instance, ref)] });
84
+ }
85
+ /**
86
+ * Settles an ended Independent Stream sale, or, if its token contract refuses the settlement,
87
+ * returns the top bid to its bidder as a credit and leaves the work to be offered again.
88
+ * Accepted from `readSale(...).refusableAt`. Anyone may send it.
89
+ *
90
+ * Contract: [`EnglishAuction.settleOrRefund`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/EnglishAuction.sol).
91
+ */
92
+ export async function settleOrRefund(clients, instance, ref) {
93
+ return send(clients, instance, { ...auctionOf(instance), functionName: "settleOrRefund", args: [idOf(instance, ref)] });
94
+ }
95
+ /**
96
+ * Sends a rescued work the auction still holds to the museum. Anyone may. It applies only to
97
+ * a work whose recorded outcome is "rescued" (the network moved it out of a removed sale
98
+ * contract) and that sits in this auction; any other work is left alone and the call reverts.
99
+ *
100
+ * Contract: [`EnglishAuction.sendRescuedToMuseum`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/EnglishAuction.sol).
101
+ */
102
+ export async function sendRescuedToMuseum(clients, instance, ref) {
103
+ return send(clients, instance, { ...auctionOf(instance), functionName: "sendRescuedToMuseum", args: [idOf(instance, ref)] });
104
+ }
105
+ /**
106
+ * The top bidder takes their bid back from a sale the network paused. Not possible in a
107
+ * running sale. The bid is credited, not paid: withdraw it with `claimAuctionCredit`.
108
+ *
109
+ * Contract: [`EnglishAuction.withdrawBid`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/EnglishAuction.sol).
110
+ */
111
+ export async function withdrawBid(clients, instance, ref) {
112
+ return send(clients, instance, { ...auctionOf(instance), functionName: "withdrawBid", args: [idOf(instance, ref)] });
113
+ }
@@ -0,0 +1,40 @@
1
+ import type { Abi, Address, Client, ContractFunctionArgs, ContractFunctionName, Hex, TransactionReceipt, TypedDataDefinition } from "viem";
2
+ import { type StreamInstance } from "../instance.js";
3
+ /**
4
+ * The two viem clients an action uses. They may be the same object (a wallet client extended
5
+ * with public actions).
6
+ */
7
+ export interface StreamClients {
8
+ /** Reads the chain, simulates each call before it is sent, and waits for receipts. */
9
+ readonly public: Client;
10
+ /** Signs and sends. It must have an account: the wallet that acts. */
11
+ readonly wallet: Client;
12
+ }
13
+ /** A transaction that was sent, mined and succeeded. */
14
+ export interface Sent {
15
+ readonly hash: Hex;
16
+ readonly receipt: TransactionReceipt;
17
+ }
18
+ /** The address of the wallet client's account. */
19
+ export declare function accountOf(clients: StreamClients): Address;
20
+ /**
21
+ * Checks both clients are on the instance's chain. The wallet is asked every time, never from
22
+ * memory: a browser wallet can switch network between two steps.
23
+ */
24
+ export declare function assertReady(clients: StreamClients, instance: StreamInstance): Promise<Address>;
25
+ type Writes = "nonpayable" | "payable";
26
+ /**
27
+ * Simulates a contract call as the wallet's account, sends it, waits for it to be mined and
28
+ * checks that it succeeded. A call that would revert is never sent: the simulation throws
29
+ * first, with the contract's own error.
30
+ */
31
+ export declare function send<const TAbi extends Abi, TName extends ContractFunctionName<TAbi, Writes>>(clients: StreamClients, instance: StreamInstance, call: {
32
+ readonly address: Address;
33
+ readonly abi: TAbi;
34
+ readonly functionName: TName;
35
+ readonly args: ContractFunctionArgs<TAbi, Writes, TName>;
36
+ readonly value?: bigint;
37
+ }): Promise<Sent>;
38
+ /** Asks the wallet to sign an EIP-712 message as its account. */
39
+ export declare function sign(clients: StreamClients, typedData: TypedDataDefinition): Promise<Hex>;
40
+ export {};
@@ -0,0 +1,70 @@
1
+ import { getChainId, signTypedData, simulateContract, waitForTransactionReceipt, writeContract } from "viem/actions";
2
+ import { NoAccountError, StreamSdkError, WrongChainError } from "../errors.js";
3
+ import { assertInstanceChain } from "../instance.js";
4
+ /** The address of the wallet client's account. */
5
+ export function accountOf(clients) {
6
+ const account = clients.wallet.account;
7
+ if (!account)
8
+ throw new NoAccountError();
9
+ return account.address;
10
+ }
11
+ /**
12
+ * Checks both clients are on the instance's chain. The wallet is asked every time, never from
13
+ * memory: a browser wallet can switch network between two steps.
14
+ */
15
+ export async function assertReady(clients, instance) {
16
+ const account = accountOf(clients);
17
+ await assertInstanceChain(clients.public, instance);
18
+ const walletChain = await getChainId(clients.wallet);
19
+ if (walletChain !== instance.chainId)
20
+ throw new WrongChainError(instance.chainId, walletChain);
21
+ return account;
22
+ }
23
+ /** The instance's chain for viem: the wallet client's own if it is that chain, else a bare one with the right ID. */
24
+ function chainOf(clients, instance) {
25
+ const own = clients.wallet.chain;
26
+ if (own?.id === instance.chainId)
27
+ return own;
28
+ return {
29
+ id: instance.chainId,
30
+ name: instance.name,
31
+ nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
32
+ rpcUrls: { default: { http: [] } },
33
+ };
34
+ }
35
+ /**
36
+ * Simulates a contract call as the wallet's account, sends it, waits for it to be mined and
37
+ * checks that it succeeded. A call that would revert is never sent: the simulation throws
38
+ * first, with the contract's own error.
39
+ */
40
+ export async function send(clients, instance, call) {
41
+ const account = clients.wallet.account;
42
+ if (!account)
43
+ throw new NoAccountError();
44
+ await assertReady(clients, instance);
45
+ // viem cannot narrow a generic ABI inside a wrapper; the call was type-checked where it was built.
46
+ const simulate = simulateContract;
47
+ const { request } = await simulate(clients.public, {
48
+ address: call.address,
49
+ abi: call.abi,
50
+ functionName: call.functionName,
51
+ args: call.args,
52
+ account,
53
+ ...(call.value === undefined ? {} : { value: call.value }),
54
+ });
55
+ // Naming the chain makes viem check the wallet's chain once more as it sends, so a switch
56
+ // between the check above and the send is refused too.
57
+ const hash = await writeContract(clients.wallet, { ...request, account, chain: chainOf(clients, instance) });
58
+ const receipt = await waitForTransactionReceipt(clients.public, { hash });
59
+ if (receipt.status !== "success") {
60
+ throw new StreamSdkError("TRANSACTION_REVERTED", `Transaction ${hash} was mined but reverted.`);
61
+ }
62
+ return { hash, receipt };
63
+ }
64
+ /** Asks the wallet to sign an EIP-712 message as its account. */
65
+ export async function sign(clients, typedData) {
66
+ const account = clients.wallet.account;
67
+ if (!account)
68
+ throw new NoAccountError();
69
+ return signTypedData(clients.wallet, { ...typedData, account });
70
+ }
@@ -0,0 +1,58 @@
1
+ import { type Address } from "viem";
2
+ import type { StreamInstance } from "../instance.js";
3
+ import type { Payee } from "../types.js";
4
+ import { type Sent, type StreamClients } from "./shared.js";
5
+ /** Which payee of which vault: the vault's payee list and the payee's position in it. */
6
+ export interface VaultRelease {
7
+ /** The vault's payees, exactly as the item lists them (`readWorkItem(...).item.payees`). */
8
+ readonly payees: readonly Payee[];
9
+ /** The payee's index in `payees`. */
10
+ readonly index: number;
11
+ /** The asset to release. Default: ETH. */
12
+ readonly asset?: Address;
13
+ }
14
+ /**
15
+ * Pays a payee its share of what a vault holds. Sale proceeds are held in a work's seller
16
+ * vault until each payee takes its part; royalties arrive there through the royalty vault
17
+ * (`collectRoyalties`). The money goes to the payee: an artist account's payout address, or
18
+ * the fixed address. For a payee named by artist ID the call must come from that account's
19
+ * payout address; a payee named by a fixed address can be paid out by anyone.
20
+ *
21
+ * Contract: [`SplitLedger.release`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/economics/SplitLedger.sol)
22
+ * with salt zero, as a work's seller vault is derived. `readSplit` shows what is releasable.
23
+ *
24
+ * @returns the transaction and the amount paid, in the asset's smallest unit.
25
+ */
26
+ export declare function releaseFromVault(clients: StreamClients, instance: StreamInstance, args: VaultRelease): Promise<Sent & {
27
+ amount: bigint;
28
+ }>;
29
+ /**
30
+ * As `releaseFromVault`, but the payee sends its share to `recipient` instead of its own
31
+ * address. Only the payee itself may: the account's payout address, or the fixed address.
32
+ *
33
+ * Contract: [`SplitLedger.releaseTo`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/economics/SplitLedger.sol).
34
+ */
35
+ export declare function releaseFromVaultTo(clients: StreamClients, instance: StreamInstance, args: VaultRelease & {
36
+ readonly recipient: Address;
37
+ }): Promise<Sent & {
38
+ amount: bigint;
39
+ }>;
40
+ /**
41
+ * Moves a work's royalties on from its royalty vault to its seller vault. Royalties from
42
+ * marketplaces are paid to the royalty vault, which splits them between the network and the
43
+ * work's seller vault; this pays out the seller vault's part (and the network's with it).
44
+ * Anyone may call it. The work's payees then take their shares with `releaseFromVault`.
45
+ *
46
+ * Contract: [`SplitLedger.release`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/economics/SplitLedger.sol)
47
+ * on the royalty vault, whose payees are `Splits.royaltyPayees(sellerVault, feeRecipient, feeShare)`.
48
+ *
49
+ * @returns the transaction and the amount moved to the seller vault, or null when the work
50
+ * has no separate royalty vault or nothing waits there.
51
+ */
52
+ export declare function collectRoyalties(clients: StreamClients, instance: StreamInstance, args: {
53
+ readonly token?: Address;
54
+ readonly tokenId: bigint;
55
+ readonly asset?: Address;
56
+ }): Promise<(Sent & {
57
+ amount: bigint;
58
+ }) | null>;
@@ -0,0 +1,94 @@
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 { accountsAbi } from "../generated/abis/Accounts.js";
7
+ import { splitLedgerAbi } from "../generated/abis/SplitLedger.js";
8
+ import { readRoyaltyVault } from "../reads/vault.js";
9
+ import { accountOf, send } from "./shared.js";
10
+ /**
11
+ * Refuses, with the reason, a release the ledger would refuse: for a payee named by artist ID
12
+ * the caller must be the account's payout address (the artist's other wallets cannot), and a
13
+ * release to another recipient must come from the payee itself.
14
+ */
15
+ async function assertPayee(clients, instance, args, toRecipient) {
16
+ const payee = args.payees[args.index];
17
+ if (!payee)
18
+ throw new FlowError("INVALID_INPUT", `The vault has no payee ${args.index}.`);
19
+ const caller = accountOf(clients);
20
+ if (payee.artistId === 0n) {
21
+ if (toRecipient && !isAddressEqual(caller, payee.account)) {
22
+ throw new FlowError("INVALID_INPUT", `Only ${payee.account}, the payee, can send its share to another address.`);
23
+ }
24
+ return;
25
+ }
26
+ const payout = await readContract(clients.public, { address: instance.addresses.accounts, abi: accountsAbi, functionName: "payoutAddress", args: [payee.artistId] });
27
+ if (!isAddressEqual(caller, payout)) {
28
+ throw new FlowError("INVALID_INPUT", `Only the account's payout address ${payout} can take this share out. From another wallet, have the payout address sign with signReleaseAuthorization and send it with releaseSigned.`);
29
+ }
30
+ }
31
+ function amountOf(sent, instance, index) {
32
+ return parseEventLogs({ abi: splitLedgerAbi, logs: sent.receipt.logs, eventName: "Released" })
33
+ .filter((log) => isAddressEqual(log.address, instance.addresses.splitLedger) && log.args.payee === BigInt(index))
34
+ .reduce((sum, log) => sum + log.args.amount, 0n);
35
+ }
36
+ /**
37
+ * Pays a payee its share of what a vault holds. Sale proceeds are held in a work's seller
38
+ * vault until each payee takes its part; royalties arrive there through the royalty vault
39
+ * (`collectRoyalties`). The money goes to the payee: an artist account's payout address, or
40
+ * the fixed address. For a payee named by artist ID the call must come from that account's
41
+ * payout address; a payee named by a fixed address can be paid out by anyone.
42
+ *
43
+ * Contract: [`SplitLedger.release`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/economics/SplitLedger.sol)
44
+ * with salt zero, as a work's seller vault is derived. `readSplit` shows what is releasable.
45
+ *
46
+ * @returns the transaction and the amount paid, in the asset's smallest unit.
47
+ */
48
+ export async function releaseFromVault(clients, instance, args) {
49
+ await assertPayee(clients, instance, args, false);
50
+ const sent = await send(clients, instance, {
51
+ address: instance.addresses.splitLedger,
52
+ abi: splitLedgerAbi,
53
+ functionName: "release",
54
+ args: [args.payees, ZERO_HASH, args.asset ?? CURRENCY_ETH, BigInt(args.index)],
55
+ });
56
+ return { ...sent, amount: amountOf(sent, instance, args.index) };
57
+ }
58
+ /**
59
+ * As `releaseFromVault`, but the payee sends its share to `recipient` instead of its own
60
+ * address. Only the payee itself may: the account's payout address, or the fixed address.
61
+ *
62
+ * Contract: [`SplitLedger.releaseTo`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/economics/SplitLedger.sol).
63
+ */
64
+ export async function releaseFromVaultTo(clients, instance, args) {
65
+ await assertPayee(clients, instance, args, true);
66
+ const sent = await send(clients, instance, {
67
+ address: instance.addresses.splitLedger,
68
+ abi: splitLedgerAbi,
69
+ functionName: "releaseTo",
70
+ args: [args.payees, ZERO_HASH, args.asset ?? CURRENCY_ETH, BigInt(args.index), args.recipient],
71
+ });
72
+ return { ...sent, amount: amountOf(sent, instance, args.index) };
73
+ }
74
+ /**
75
+ * Moves a work's royalties on from its royalty vault to its seller vault. Royalties from
76
+ * marketplaces are paid to the royalty vault, which splits them between the network and the
77
+ * work's seller vault; this pays out the seller vault's part (and the network's with it).
78
+ * Anyone may call it. The work's payees then take their shares with `releaseFromVault`.
79
+ *
80
+ * Contract: [`SplitLedger.release`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/economics/SplitLedger.sol)
81
+ * on the royalty vault, whose payees are `Splits.royaltyPayees(sellerVault, feeRecipient, feeShare)`.
82
+ *
83
+ * @returns the transaction and the amount moved to the seller vault, or null when the work
84
+ * has no separate royalty vault or nothing waits there.
85
+ */
86
+ export async function collectRoyalties(clients, instance, args) {
87
+ const vault = await readRoyaltyVault(clients.public, instance, args);
88
+ if (!vault.split || !vault.sellerShare)
89
+ return null;
90
+ if ((args.asset === undefined || isAddressEqual(args.asset, CURRENCY_ETH)) && vault.sellerShare.releasable === 0n)
91
+ return null;
92
+ const payees = vault.split.payees.map((payee) => payee.listed);
93
+ return releaseFromVault(clients, instance, { payees, index: vault.sellerShare.index, ...(args.asset ? { asset: args.asset } : {}) });
94
+ }
@@ -0,0 +1,130 @@
1
+ import { type Address, type Hex } from "viem";
2
+ /**
3
+ * Constants of the 6529 Stream contracts. Each one is checked in the tests against the value
4
+ * the Solidity code produces (`test/vectors/<instance>.json`).
5
+ *
6
+ * Source: https://github.com/6529-Collections/6529-stream/tree/c6d4965861907841519cf3878c9db7052424a9a0/src/interfaces/types
7
+ */
8
+ /** `bytes32(0)`. */
9
+ export declare const ZERO_HASH: Hex;
10
+ /** Rates and shares are out of this (`Core.DENOMINATOR`): 100,000 is 100%. */
11
+ export declare const DENOMINATOR = 100000;
12
+ /** `StreamHashing.CC0_LICENSE_KEY`: the key of CC0 1.0. */
13
+ export declare const CC0_LICENSE_KEY: `0x${string}`;
14
+ /** The SPDX identifier of CC0 1.0, in the case the contracts store it. */
15
+ export declare const CC0_SPDX_ID = "CC0-1.0";
16
+ /** `SaleKind`: the labels of the sale methods (`SaleTypes.sol`). */
17
+ export declare const SALE_KIND: {
18
+ /** The English auction: how a 1/1 is first sold. */
19
+ readonly ENGLISH_AUCTION: `0x${string}`;
20
+ /** The uniform-price edition auction. */
21
+ readonly UNIFORM_AUCTION: `0x${string}`;
22
+ };
23
+ /** Product identifiers (`EconomicsTypes.sol`). */
24
+ export declare const PRODUCT: {
25
+ readonly STREAM: `0x${string}`;
26
+ readonly EDITIONS: `0x${string}`;
27
+ readonly INDEPENDENT: `0x${string}`;
28
+ };
29
+ /** The currency value meaning ETH (`CURRENCY_ETH`). */
30
+ export declare const CURRENCY_ETH: Address;
31
+ /** The currency value meaning "the product's default", which is ETH (`CURRENCY_DEFAULT`). */
32
+ export declare const CURRENCY_DEFAULT: Address;
33
+ /** `ItemKind` (`PackageTypes.sol`). An item's kind is an open `uint8`: later values may exist. */
34
+ export declare const ITEM_KIND: {
35
+ readonly ORIGINAL: 0;
36
+ readonly EDITION_MASTER: 1;
37
+ };
38
+ /** `PartyRole` (`PackageTypes.sol`). The first party of every item is the lead ARTIST. */
39
+ export declare const PARTY_ROLE: {
40
+ readonly ARTIST: 0;
41
+ readonly COLLABORATOR: 1;
42
+ };
43
+ /** `SeedPolicy` (`PackageTypes.sol`). */
44
+ export declare const SEED_POLICY: {
45
+ readonly NONE: 0;
46
+ readonly ARTIST: 1;
47
+ readonly VRF: 2;
48
+ };
49
+ /** `FileRole` (`ContentTypes.sol`). Treat a role you do not know as AUXILIARY. */
50
+ export declare const FILE_ROLE: {
51
+ readonly PRIMARY: 0;
52
+ readonly PREVIEW: 1;
53
+ readonly AUXILIARY: 2;
54
+ };
55
+ /** `LocatorKind` (`ContentTypes.sol`). */
56
+ export declare const LOCATOR_KIND: {
57
+ readonly NONE: 0;
58
+ readonly ARWEAVE: 1;
59
+ readonly IPFS: 2;
60
+ readonly ONCHAIN: 3;
61
+ };
62
+ /** `IContentStore.Encoding`: how a file's stored bytes relate to the media. */
63
+ export declare const ENCODING: {
64
+ readonly IDENTITY: 0;
65
+ readonly GZIP: 1;
66
+ readonly BASE64: 2;
67
+ readonly GZIP_BASE64: 3;
68
+ };
69
+ /** `Outcome` (`CoreTypes.sol`): how a 1/1's first sale ended, as the token records it in `workOf`. */
70
+ export declare const OUTCOME: {
71
+ readonly NONE: 0;
72
+ readonly SOLD: 1;
73
+ readonly UNSOLD: 2;
74
+ readonly RESCUED: 3;
75
+ };
76
+ /** `IEnglishAuction.AuctionState`. */
77
+ export declare const AUCTION_STATE: {
78
+ readonly NONE: 0;
79
+ readonly ACTIVE: 1;
80
+ readonly PAUSED: 2;
81
+ readonly ENDED: 3;
82
+ readonly SETTLED: 4;
83
+ readonly CANCELLED: 5;
84
+ };
85
+ /** `IUniformEditionAuction.AuctionStatus`. */
86
+ export declare const EDITION_STATUS: {
87
+ readonly NONE: 0;
88
+ readonly OPEN: 1;
89
+ readonly CLOSED: 2;
90
+ readonly SETTLING: 3;
91
+ readonly SETTLED: 4;
92
+ readonly VOID: 5;
93
+ };
94
+ /** The package status `PackageRegistry.packageOf` answers. */
95
+ export declare const PACKAGE_STATUS: {
96
+ readonly NONE: 0;
97
+ readonly APPROVED: 1;
98
+ readonly REVOKED: 2;
99
+ };
100
+ /** `IIndependentStreamRegistry.Form`. `PAIR` is not used by the contracts; it keeps the numbering. */
101
+ export declare const INDEPENDENT_FORM: {
102
+ readonly ERC721: 0;
103
+ readonly ERC1155: 1;
104
+ readonly PAIR: 2;
105
+ };
106
+ /** `IIndependentStreamRegistry.Status`. */
107
+ export declare const LISTING_STATUS: {
108
+ readonly NONE: 0;
109
+ readonly ACTIVE: 1;
110
+ readonly DELISTED: 2;
111
+ };
112
+ /** `WorkPowers`: the bits of the `powers` mask an artist can renounce. */
113
+ export declare const WORK_POWERS: {
114
+ readonly ROYALTY_RATE: 1;
115
+ readonly RELICENSE: 2;
116
+ readonly RENDERER_REPIN: 4;
117
+ readonly ALL: 7;
118
+ };
119
+ /** `IStatementLog.Role`. */
120
+ export declare const STATEMENT_ROLE: {
121
+ readonly NONE: 0;
122
+ readonly ARTIST: 1;
123
+ readonly OWNER: 2;
124
+ readonly CURATOR: 3;
125
+ readonly PLATFORM: 4;
126
+ };
127
+ /** `Slots.RENDERER`: the module slot of a token's renderer (the ASCII name, right-padded). */
128
+ export declare const SLOT_RENDERER: Hex;
129
+ /** `ContentStore.CHUNK_SIZE`: the most bytes one stored chunk holds. */
130
+ export declare const CHUNK_SIZE = 24575;
@@ -0,0 +1,65 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { keccak256, toBytes, zeroAddress } from "viem";
3
+ /**
4
+ * Constants of the 6529 Stream contracts. Each one is checked in the tests against the value
5
+ * the Solidity code produces (`test/vectors/<instance>.json`).
6
+ *
7
+ * Source: https://github.com/6529-Collections/6529-stream/tree/c6d4965861907841519cf3878c9db7052424a9a0/src/interfaces/types
8
+ */
9
+ /** `bytes32(0)`. */
10
+ export const ZERO_HASH = "0x0000000000000000000000000000000000000000000000000000000000000000";
11
+ /** Rates and shares are out of this (`Core.DENOMINATOR`): 100,000 is 100%. */
12
+ export const DENOMINATOR = 100_000;
13
+ /** `StreamHashing.CC0_LICENSE_KEY`: the key of CC0 1.0. */
14
+ export const CC0_LICENSE_KEY = keccak256(toBytes("cc0-1.0"));
15
+ /** The SPDX identifier of CC0 1.0, in the case the contracts store it. */
16
+ export const CC0_SPDX_ID = "CC0-1.0";
17
+ /** `SaleKind`: the labels of the sale methods (`SaleTypes.sol`). */
18
+ export const SALE_KIND = {
19
+ /** The English auction: how a 1/1 is first sold. */
20
+ ENGLISH_AUCTION: keccak256(toBytes("ENGLISH_AUCTION")),
21
+ /** The uniform-price edition auction. */
22
+ UNIFORM_AUCTION: keccak256(toBytes("UNIFORM_AUCTION")),
23
+ };
24
+ /** Product identifiers (`EconomicsTypes.sol`). */
25
+ export const PRODUCT = {
26
+ STREAM: keccak256(toBytes("PRODUCT_STREAM")),
27
+ EDITIONS: keccak256(toBytes("PRODUCT_EDITIONS")),
28
+ INDEPENDENT: keccak256(toBytes("PRODUCT_INDEPENDENT")),
29
+ };
30
+ /** The currency value meaning ETH (`CURRENCY_ETH`). */
31
+ export const CURRENCY_ETH = zeroAddress;
32
+ /** The currency value meaning "the product's default", which is ETH (`CURRENCY_DEFAULT`). */
33
+ export const CURRENCY_DEFAULT = "0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF";
34
+ /** `ItemKind` (`PackageTypes.sol`). An item's kind is an open `uint8`: later values may exist. */
35
+ export const ITEM_KIND = { ORIGINAL: 0, EDITION_MASTER: 1 };
36
+ /** `PartyRole` (`PackageTypes.sol`). The first party of every item is the lead ARTIST. */
37
+ export const PARTY_ROLE = { ARTIST: 0, COLLABORATOR: 1 };
38
+ /** `SeedPolicy` (`PackageTypes.sol`). */
39
+ export const SEED_POLICY = { NONE: 0, ARTIST: 1, VRF: 2 };
40
+ /** `FileRole` (`ContentTypes.sol`). Treat a role you do not know as AUXILIARY. */
41
+ export const FILE_ROLE = { PRIMARY: 0, PREVIEW: 1, AUXILIARY: 2 };
42
+ /** `LocatorKind` (`ContentTypes.sol`). */
43
+ export const LOCATOR_KIND = { NONE: 0, ARWEAVE: 1, IPFS: 2, ONCHAIN: 3 };
44
+ /** `IContentStore.Encoding`: how a file's stored bytes relate to the media. */
45
+ export const ENCODING = { IDENTITY: 0, GZIP: 1, BASE64: 2, GZIP_BASE64: 3 };
46
+ /** `Outcome` (`CoreTypes.sol`): how a 1/1's first sale ended, as the token records it in `workOf`. */
47
+ export const OUTCOME = { NONE: 0, SOLD: 1, UNSOLD: 2, RESCUED: 3 };
48
+ /** `IEnglishAuction.AuctionState`. */
49
+ export const AUCTION_STATE = { NONE: 0, ACTIVE: 1, PAUSED: 2, ENDED: 3, SETTLED: 4, CANCELLED: 5 };
50
+ /** `IUniformEditionAuction.AuctionStatus`. */
51
+ export const EDITION_STATUS = { NONE: 0, OPEN: 1, CLOSED: 2, SETTLING: 3, SETTLED: 4, VOID: 5 };
52
+ /** The package status `PackageRegistry.packageOf` answers. */
53
+ export const PACKAGE_STATUS = { NONE: 0, APPROVED: 1, REVOKED: 2 };
54
+ /** `IIndependentStreamRegistry.Form`. `PAIR` is not used by the contracts; it keeps the numbering. */
55
+ export const INDEPENDENT_FORM = { ERC721: 0, ERC1155: 1, PAIR: 2 };
56
+ /** `IIndependentStreamRegistry.Status`. */
57
+ export const LISTING_STATUS = { NONE: 0, ACTIVE: 1, DELISTED: 2 };
58
+ /** `WorkPowers`: the bits of the `powers` mask an artist can renounce. */
59
+ export const WORK_POWERS = { ROYALTY_RATE: 1, RELICENSE: 2, RENDERER_REPIN: 4, ALL: 7 };
60
+ /** `IStatementLog.Role`. */
61
+ export const STATEMENT_ROLE = { NONE: 0, ARTIST: 1, OWNER: 2, CURATOR: 3, PLATFORM: 4 };
62
+ /** `Slots.RENDERER`: the module slot of a token's renderer (the ASCII name, right-padded). */
63
+ export const SLOT_RENDERER = "0x52454e4445524552000000000000000000000000000000000000000000000000";
64
+ /** `ContentStore.CHUNK_SIZE`: the most bytes one stored chunk holds. */
65
+ export const CHUNK_SIZE = 24_575;