@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.
- package/CHANGELOG.md +46 -0
- package/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +413 -2
- package/dist/actions/accounts.d.ts +58 -0
- package/dist/actions/accounts.js +73 -0
- package/dist/actions/content.d.ts +22 -0
- package/dist/actions/content.js +45 -0
- package/dist/actions/curated.d.ts +177 -0
- package/dist/actions/curated.js +279 -0
- package/dist/actions/editions.d.ts +100 -0
- package/dist/actions/editions.js +161 -0
- package/dist/actions/independent.d.ts +149 -0
- package/dist/actions/independent.js +274 -0
- package/dist/actions/money.d.ts +117 -0
- package/dist/actions/money.js +148 -0
- package/dist/actions/record.d.ts +144 -0
- package/dist/actions/record.js +229 -0
- package/dist/actions/sale.d.ts +82 -0
- package/dist/actions/sale.js +113 -0
- package/dist/actions/shared.d.ts +40 -0
- package/dist/actions/shared.js +70 -0
- package/dist/actions/vault.d.ts +58 -0
- package/dist/actions/vault.js +94 -0
- package/dist/constants.d.ts +130 -0
- package/dist/constants.js +65 -0
- package/dist/display.d.ts +31 -0
- package/dist/display.js +28 -0
- package/dist/encoding.d.ts +110 -0
- package/dist/encoding.js +138 -0
- package/dist/errors.d.ts +76 -0
- package/dist/errors.js +66 -0
- package/dist/files/fetch.d.ts +85 -0
- package/dist/files/fetch.js +208 -0
- package/dist/files/verify.d.ts +36 -0
- package/dist/files/verify.js +125 -0
- package/dist/generated/abis/AccessManager.d.ts +1125 -0
- package/dist/generated/abis/AccessManager.js +1471 -0
- package/dist/generated/abis/Accounts.d.ts +1568 -0
- package/dist/generated/abis/Accounts.js +2049 -0
- package/dist/generated/abis/ClaimRouter.d.ts +343 -0
- package/dist/generated/abis/ClaimRouter.js +452 -0
- package/dist/generated/abis/ConsolidationAdapter.d.ts +97 -0
- package/dist/generated/abis/ConsolidationAdapter.js +133 -0
- package/dist/generated/abis/ContentStore.d.ts +812 -0
- package/dist/generated/abis/ContentStore.js +1073 -0
- package/dist/generated/abis/EconomicsResolver.d.ts +586 -0
- package/dist/generated/abis/EconomicsResolver.js +769 -0
- package/dist/generated/abis/Eip712CurationVerifier.d.ts +304 -0
- package/dist/generated/abis/Eip712CurationVerifier.js +406 -0
- package/dist/generated/abis/EnglishAuction.d.ts +1435 -0
- package/dist/generated/abis/EnglishAuction.js +1865 -0
- package/dist/generated/abis/GovernedVault.d.ts +468 -0
- package/dist/generated/abis/GovernedVault.js +617 -0
- package/dist/generated/abis/IndependentEditionAuction.d.ts +2373 -0
- package/dist/generated/abis/IndependentEditionAuction.js +3076 -0
- package/dist/generated/abis/IndependentStream6529.d.ts +1408 -0
- package/dist/generated/abis/IndependentStream6529.js +1834 -0
- package/dist/generated/abis/IndependentStreamDeployer.d.ts +141 -0
- package/dist/generated/abis/IndependentStreamDeployer.js +188 -0
- package/dist/generated/abis/IndependentStreamEditions6529.d.ts +963 -0
- package/dist/generated/abis/IndependentStreamEditions6529.js +1253 -0
- package/dist/generated/abis/IndependentStreamRegistry.d.ts +1351 -0
- package/dist/generated/abis/IndependentStreamRegistry.js +1755 -0
- package/dist/generated/abis/PackageRegistry.d.ts +1205 -0
- package/dist/generated/abis/PackageRegistry.js +1573 -0
- package/dist/generated/abis/RevenueEscrow.d.ts +626 -0
- package/dist/generated/abis/RevenueEscrow.js +820 -0
- package/dist/generated/abis/SaleStarter.d.ts +48 -0
- package/dist/generated/abis/SaleStarter.js +67 -0
- package/dist/generated/abis/SepoliaOpenGate.d.ts +317 -0
- package/dist/generated/abis/SepoliaOpenGate.js +419 -0
- package/dist/generated/abis/SplitLedger.d.ts +1097 -0
- package/dist/generated/abis/SplitLedger.js +1438 -0
- package/dist/generated/abis/StatementLog.d.ts +958 -0
- package/dist/generated/abis/StatementLog.js +1248 -0
- package/dist/generated/abis/Stream6529.d.ts +1490 -0
- package/dist/generated/abis/Stream6529.js +1941 -0
- package/dist/generated/abis/StreamDirectory6529.d.ts +355 -0
- package/dist/generated/abis/StreamDirectory6529.js +468 -0
- package/dist/generated/abis/StreamEditions6529.d.ts +1240 -0
- package/dist/generated/abis/StreamEditions6529.js +1614 -0
- package/dist/generated/abis/StreamTerms.d.ts +312 -0
- package/dist/generated/abis/StreamTerms.js +409 -0
- package/dist/generated/abis/StreamWorkFacts6529.d.ts +810 -0
- package/dist/generated/abis/StreamWorkFacts6529.js +1049 -0
- package/dist/generated/abis/UniformEditionAuction.d.ts +2372 -0
- package/dist/generated/abis/UniformEditionAuction.js +3074 -0
- package/dist/generated/abis/WorkDelivery.d.ts +605 -0
- package/dist/generated/abis/WorkDelivery.js +786 -0
- package/dist/generated/abis/WorkRules.d.ts +1154 -0
- package/dist/generated/abis/WorkRules.js +1501 -0
- package/dist/generated/abis/index.d.ts +28 -0
- package/dist/generated/abis/index.js +31 -0
- package/dist/generated/instances.d.ts +7 -0
- package/dist/generated/instances.js +9 -0
- package/dist/generated/sepoliaR10.d.ts +1391 -0
- package/dist/generated/sepoliaR10.js +1545 -0
- package/dist/hashing/content.d.ts +42 -0
- package/dist/hashing/content.js +54 -0
- package/dist/hashing/ids.d.ts +67 -0
- package/dist/hashing/ids.js +73 -0
- package/dist/hashing/items.d.ts +30 -0
- package/dist/hashing/items.js +44 -0
- package/dist/hashing/packages.d.ts +35 -0
- package/dist/hashing/packages.js +76 -0
- package/dist/hashing/vault.d.ts +17 -0
- package/dist/hashing/vault.js +37 -0
- package/dist/hashing/workState.d.ts +31 -0
- package/dist/hashing/workState.js +37 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.js +47 -0
- package/dist/instance.d.ts +236 -0
- package/dist/instance.js +99 -0
- package/dist/items.d.ts +85 -0
- package/dist/items.js +144 -0
- package/dist/reads/accounts.d.ts +86 -0
- package/dist/reads/accounts.js +121 -0
- package/dist/reads/chain.d.ts +54 -0
- package/dist/reads/chain.js +133 -0
- package/dist/reads/creation.d.ts +139 -0
- package/dist/reads/creation.js +256 -0
- package/dist/reads/editionSale.d.ts +120 -0
- package/dist/reads/editionSale.js +182 -0
- package/dist/reads/metadata.d.ts +195 -0
- package/dist/reads/metadata.js +191 -0
- package/dist/reads/money.d.ts +51 -0
- package/dist/reads/money.js +68 -0
- package/dist/reads/network.d.ts +137 -0
- package/dist/reads/network.js +157 -0
- package/dist/reads/sale.d.ts +94 -0
- package/dist/reads/sale.js +133 -0
- package/dist/reads/vault.d.ts +47 -0
- package/dist/reads/vault.js +75 -0
- package/dist/reads/work.d.ts +293 -0
- package/dist/reads/work.js +338 -0
- package/dist/reads/workPage.d.ts +197 -0
- package/dist/reads/workPage.js +169 -0
- package/dist/signing/messages.d.ts +679 -0
- package/dist/signing/messages.js +397 -0
- package/dist/testing.d.ts +17 -0
- package/dist/testing.js +18 -0
- package/dist/types.d.ts +167 -0
- package/dist/types.js +14 -0
- package/docs/publishing.md +54 -0
- package/docs/reference.md +335 -0
- package/docs/using-from-a-site.md +175 -0
- package/package.json +93 -4
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { bytesToHex, keccak256, toBytes, zeroAddress } from "viem";
|
|
3
|
+
import { readContract, simulateContract } from "viem/actions";
|
|
4
|
+
import { INDEPENDENT_FORM, PACKAGE_STATUS, PRODUCT } from "../constants.js";
|
|
5
|
+
import { encodeStreamMintRequest } from "../encoding.js";
|
|
6
|
+
import { FlowError } from "../errors.js";
|
|
7
|
+
import { accountsAbi } from "../generated/abis/Accounts.js";
|
|
8
|
+
import { contentStoreAbi } from "../generated/abis/ContentStore.js";
|
|
9
|
+
import { economicsResolverAbi } from "../generated/abis/EconomicsResolver.js";
|
|
10
|
+
import { independentStreamDeployerAbi } from "../generated/abis/IndependentStreamDeployer.js";
|
|
11
|
+
import { independentStreamEditions6529Abi } from "../generated/abis/IndependentStreamEditions6529.js";
|
|
12
|
+
import { packageRegistryAbi } from "../generated/abis/PackageRegistry.js";
|
|
13
|
+
import { sepoliaOpenGateAbi } from "../generated/abis/SepoliaOpenGate.js";
|
|
14
|
+
import { stream6529Abi } from "../generated/abis/Stream6529.js";
|
|
15
|
+
import { itemHash } from "../hashing/items.js";
|
|
16
|
+
import { isPackageItem } from "../hashing/packages.js";
|
|
17
|
+
import { assertInstanceChain } from "../instance.js";
|
|
18
|
+
import { itemProblems } from "../items.js";
|
|
19
|
+
import { readArtistId } from "./accounts.js";
|
|
20
|
+
import { isContractRevert, orOnRevert, revertName } from "./chain.js";
|
|
21
|
+
/**
|
|
22
|
+
* What a creation flow reads before it acts: whether the test gate is open, the state of a
|
|
23
|
+
* package, whether an item is minted already, what a listing will record. They are reads; the
|
|
24
|
+
* actions call them, and a page can call them to show the same facts.
|
|
25
|
+
*/
|
|
26
|
+
/** The test gate of an instance, or an error saying it has none. */
|
|
27
|
+
export function gateOf(instance) {
|
|
28
|
+
if (!instance.openGate)
|
|
29
|
+
throw new FlowError("GATE_CLOSED", `Instance ${instance.name} has no open gate.`);
|
|
30
|
+
return instance.openGate;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Whether the test gate of an instance is open for `account` right now: it can create a
|
|
34
|
+
* collection and its approval of a package is accepted. The network can close the gate at any
|
|
35
|
+
* time, so ask before a run that stores files.
|
|
36
|
+
*
|
|
37
|
+
* Both answers come from simulating the real calls, so they hold for the block read.
|
|
38
|
+
*
|
|
39
|
+
* Contract: [`SepoliaOpenGate.createCollection`, `attestationOf`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/script/sepolia/SepoliaOpenGate.sol),
|
|
40
|
+
* [`PackageRegistry.registerPackage`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/curation/PackageRegistry.sol).
|
|
41
|
+
* A TEST CONVENIENCE: with the gate open nothing is curated.
|
|
42
|
+
*/
|
|
43
|
+
export async function readGate(client, instance, account) {
|
|
44
|
+
await assertInstanceChain(client, instance);
|
|
45
|
+
const gate = gateOf(instance);
|
|
46
|
+
// A fresh random root each time: nobody can have registered it, which would make the probe revert.
|
|
47
|
+
const probeRoot = bytesToHex(crypto.getRandomValues(new Uint8Array(32)));
|
|
48
|
+
const [evidenceHash, attestation] = await readContract(client, {
|
|
49
|
+
address: gate,
|
|
50
|
+
abi: sepoliaOpenGateAbi,
|
|
51
|
+
functionName: "attestationOf",
|
|
52
|
+
args: [probeRoot],
|
|
53
|
+
});
|
|
54
|
+
const passes = (simulation) => simulation.then(() => true, (error) => {
|
|
55
|
+
if (isContractRevert(error))
|
|
56
|
+
return false;
|
|
57
|
+
throw error;
|
|
58
|
+
});
|
|
59
|
+
const [collections, packages] = await Promise.all([
|
|
60
|
+
passes(simulateContract(client, {
|
|
61
|
+
address: gate,
|
|
62
|
+
abi: sepoliaOpenGateAbi,
|
|
63
|
+
functionName: "createCollection",
|
|
64
|
+
args: ["gate check", keccak256(toBytes("gate check"))],
|
|
65
|
+
account,
|
|
66
|
+
})),
|
|
67
|
+
passes(simulateContract(client, {
|
|
68
|
+
address: instance.addresses.packageRegistry,
|
|
69
|
+
abi: packageRegistryAbi,
|
|
70
|
+
functionName: "registerPackage",
|
|
71
|
+
args: [probeRoot, evidenceHash, attestation],
|
|
72
|
+
account,
|
|
73
|
+
})),
|
|
74
|
+
]);
|
|
75
|
+
return { collections, packages };
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The state of a package root in the registry: not registered, approved, or revoked (also
|
|
79
|
+
* when its signer's approvals were stopped).
|
|
80
|
+
*
|
|
81
|
+
* Contract: [`PackageRegistry.packageOf`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/curation/PackageRegistry.sol).
|
|
82
|
+
*/
|
|
83
|
+
export async function readPackageStatus(client, instance, packageRoot) {
|
|
84
|
+
await assertInstanceChain(client, instance);
|
|
85
|
+
const [status] = await readContract(client, {
|
|
86
|
+
address: instance.addresses.packageRegistry,
|
|
87
|
+
abi: packageRegistryAbi,
|
|
88
|
+
functionName: "packageOf",
|
|
89
|
+
args: [packageRoot],
|
|
90
|
+
});
|
|
91
|
+
if (status === PACKAGE_STATUS.NONE)
|
|
92
|
+
return "none";
|
|
93
|
+
return status === PACKAGE_STATUS.APPROVED ? "approved" : "revoked";
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The profile fields an acceptance by `account` must carry: the stored ones if the wallet has
|
|
97
|
+
* an account (every later acceptance must repeat them), otherwise null, and the caller decides
|
|
98
|
+
* what the new account's fields are.
|
|
99
|
+
*
|
|
100
|
+
* Contract: [`Accounts.artistIdOf`, `artist`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/identity/Accounts.sol).
|
|
101
|
+
*/
|
|
102
|
+
export async function readStoredProfile(client, instance, account) {
|
|
103
|
+
const { artistId, exists } = await readArtistId(client, instance, account);
|
|
104
|
+
if (!exists)
|
|
105
|
+
return null;
|
|
106
|
+
const [identity] = await readContract(client, {
|
|
107
|
+
address: instance.addresses.accounts,
|
|
108
|
+
abi: accountsAbi,
|
|
109
|
+
functionName: "artist",
|
|
110
|
+
args: [artistId],
|
|
111
|
+
});
|
|
112
|
+
return { profileId: identity.profileId, profileDocHash: identity.profileDocHash };
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* An artist's first unused move nonce, counting up from 0. Any unused number is valid; small
|
|
116
|
+
* ones share storage words, which costs the least gas.
|
|
117
|
+
*
|
|
118
|
+
* Contract: [`PackageRegistry.isMoveNonceUsed`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/curation/PackageRegistry.sol).
|
|
119
|
+
*
|
|
120
|
+
* @throws FlowError `NO_MOVE_NONCE` when the first `limit` (default 1,024) are all used.
|
|
121
|
+
*/
|
|
122
|
+
export async function readNextMoveNonce(client, instance, artistId, limit = 1_024) {
|
|
123
|
+
await assertInstanceChain(client, instance);
|
|
124
|
+
const batch = 32;
|
|
125
|
+
for (let start = 0; start < limit; start += batch) {
|
|
126
|
+
const nonces = Array.from({ length: Math.min(batch, limit - start) }, (_, index) => BigInt(start + index));
|
|
127
|
+
const used = await Promise.all(nonces.map((nonce) => readContract(client, {
|
|
128
|
+
address: instance.addresses.packageRegistry,
|
|
129
|
+
abi: packageRegistryAbi,
|
|
130
|
+
functionName: "isMoveNonceUsed",
|
|
131
|
+
args: [artistId, nonce],
|
|
132
|
+
})));
|
|
133
|
+
const free = nonces[used.indexOf(false)];
|
|
134
|
+
if (free !== undefined)
|
|
135
|
+
return free;
|
|
136
|
+
}
|
|
137
|
+
throw new FlowError("NO_MOVE_NONCE", `Artist ${artistId} has no unused move nonce below ${limit}.`);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* The token already minted from `item` on `token`, or null.
|
|
141
|
+
*
|
|
142
|
+
* A token contract mints a content hash once, so finding the primary file's hash minted is
|
|
143
|
+
* not enough to know it is this work: another artist, collection or record makes another
|
|
144
|
+
* item. The minted token's item hash must be this item's, or the content is taken.
|
|
145
|
+
*
|
|
146
|
+
* A burned token still holds its content hash, and the contract accepts the content again
|
|
147
|
+
* once the network released it. A burned token therefore answers null here: whether the
|
|
148
|
+
* content may be minted again is the contract's decision when the sale starts.
|
|
149
|
+
*
|
|
150
|
+
* Contract: [`Stream6529.tokenOfContent`, `itemHashOf`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/core/StreamBase.sol).
|
|
151
|
+
*
|
|
152
|
+
* @throws FlowError `CONTENT_ALREADY_MINTED` when the content is minted as another item.
|
|
153
|
+
*/
|
|
154
|
+
export async function readMintedToken(client, instance, token, item) {
|
|
155
|
+
await assertInstanceChain(client, instance);
|
|
156
|
+
const onToken = { address: token, abi: stream6529Abi };
|
|
157
|
+
const minted = await readContract(client, { ...onToken, functionName: "tokenOfContent", args: [item.contentHash] });
|
|
158
|
+
if (minted === 0n)
|
|
159
|
+
return null;
|
|
160
|
+
// `itemHashOf` reverts for a token that was burned.
|
|
161
|
+
const mintedItem = await orOnRevert(readContract(client, { ...onToken, functionName: "itemHashOf", args: [minted] }), null);
|
|
162
|
+
if (mintedItem === null)
|
|
163
|
+
return null;
|
|
164
|
+
if (mintedItem !== itemHash(instance.protocol, item)) {
|
|
165
|
+
throw new FlowError("CONTENT_ALREADY_MINTED", `This primary file is already token ${minted} of ${token}, minted from another item.`);
|
|
166
|
+
}
|
|
167
|
+
return minted;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Checks a curated item before anyone signs for it. An item that breaks a rule is approved
|
|
171
|
+
* and accepted all the same and only refused when the sale starts, with no reason given; by
|
|
172
|
+
* then the first acceptance has stored each new party's profile for good.
|
|
173
|
+
*
|
|
174
|
+
* First the rules that need no chain, each named (`itemProblems`). Then the registry's own
|
|
175
|
+
* dry run, which runs every item check the start runs, with the same errors: the item rules,
|
|
176
|
+
* the party and payee rules, the license against the instance's CC0 text, and that the
|
|
177
|
+
* economics give usable terms. It answers before any party has accepted: a party without an
|
|
178
|
+
* account counts as the artist its first acceptance will make it.
|
|
179
|
+
*
|
|
180
|
+
* The dry run does not check that the root is approved, that every party has accepted, the
|
|
181
|
+
* item's proof (checked here), the media files, or whether the content was minted before
|
|
182
|
+
* (`readMintedToken` answers that): the start itself checks those.
|
|
183
|
+
*
|
|
184
|
+
* Contract: [`PackageRegistry.preview`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/curation/PackageRegistry.sol).
|
|
185
|
+
*
|
|
186
|
+
* @throws FlowError `INVALID_INPUT`, naming the broken rule or the registry's error.
|
|
187
|
+
*/
|
|
188
|
+
export async function previewCuratedItem(client, instance, args) {
|
|
189
|
+
await assertInstanceChain(client, instance);
|
|
190
|
+
const problems = itemProblems(args.item);
|
|
191
|
+
if (problems.length > 0) {
|
|
192
|
+
throw new FlowError("INVALID_INPUT", `The item breaks ${problems.length === 1 ? "a rule" : "rules"} of the package registry: ${problems.map((problem) => `${problem.message} (${problem.rule})`).join(" ")}`);
|
|
193
|
+
}
|
|
194
|
+
const hash = itemHash(instance.protocol, args.item);
|
|
195
|
+
if (!isPackageItem(args.proof, args.packageRoot, hash)) {
|
|
196
|
+
throw new FlowError("INVALID_INPUT", "The item is not in the package: the proof does not lead to the root.");
|
|
197
|
+
}
|
|
198
|
+
// The dry run decodes a whole start request; the move is not looked at.
|
|
199
|
+
const request = encodeStreamMintRequest({ ...args, move: { nonce: 0n, deadline: 0n, signature: "0x" } });
|
|
200
|
+
try {
|
|
201
|
+
const [facts] = await readContract(client, {
|
|
202
|
+
address: instance.addresses.packageRegistry,
|
|
203
|
+
abi: packageRegistryAbi,
|
|
204
|
+
functionName: "preview",
|
|
205
|
+
args: [instance.addresses.stream, request],
|
|
206
|
+
});
|
|
207
|
+
return { itemHash: hash, artistId: facts.artistId, seller: facts.seller, royaltyReceiver: facts.royaltyReceiver, royaltyRate: facts.royaltyRate, checkedOnChain: true };
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
if (!isContractRevert(error))
|
|
211
|
+
throw error;
|
|
212
|
+
const name = revertName(error);
|
|
213
|
+
throw new FlowError("INVALID_INPUT", `The package registry refuses this item${name ? ` (${name})` : ""}. Nobody should sign for it as it is.`);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* What listing `token` will record: which template deployed it, its partner, and the network
|
|
218
|
+
* share the listing fixes. Show `feeShare` to the artist: the consent they sign names it.
|
|
219
|
+
*
|
|
220
|
+
* Contract: [`IndependentStreamDeployer.deployed`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/independent/IndependentStreamDeployer.sol),
|
|
221
|
+
* [`IndependentStreamEditions6529.stream`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/independent/IndependentStreamEditions6529.sol),
|
|
222
|
+
* [`EconomicsResolver.economics`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/economics/EconomicsResolver.sol).
|
|
223
|
+
*/
|
|
224
|
+
export async function readListingPlan(client, instance, token) {
|
|
225
|
+
await assertInstanceChain(client, instance);
|
|
226
|
+
const recordedBy = (deployer) => readContract(client, { address: deployer, abi: independentStreamDeployerAbi, functionName: "deployed", args: [token] });
|
|
227
|
+
const [is721, isEditions, economics] = await Promise.all([
|
|
228
|
+
recordedBy(instance.addresses.independent721Deployer),
|
|
229
|
+
recordedBy(instance.addresses.independentEditionsDeployer),
|
|
230
|
+
readContract(client, {
|
|
231
|
+
address: instance.addresses.economics,
|
|
232
|
+
abi: economicsResolverAbi,
|
|
233
|
+
functionName: "economics",
|
|
234
|
+
args: [PRODUCT.INDEPENDENT],
|
|
235
|
+
}),
|
|
236
|
+
]);
|
|
237
|
+
if (is721 === isEditions) {
|
|
238
|
+
throw new FlowError("INVALID_INPUT", `${token} was not deployed by this instance's Independent Stream deployers.`);
|
|
239
|
+
}
|
|
240
|
+
if (is721) {
|
|
241
|
+
return { token, form: INDEPENDENT_FORM.ERC721, deployer: instance.addresses.independent721Deployer, partner: zeroAddress, feeShare: economics.feeShare };
|
|
242
|
+
}
|
|
243
|
+
const partner = await readContract(client, { address: token, abi: independentStreamEditions6529Abi, functionName: "stream" });
|
|
244
|
+
return { token, form: INDEPENDENT_FORM.ERC1155, deployer: instance.addresses.independentEditionsDeployer, partner, feeShare: economics.feeShare };
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Whether a file is registered in the content store.
|
|
248
|
+
*
|
|
249
|
+
* Contract: [`ContentStore.fileInfo`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/content/ContentStore.sol),
|
|
250
|
+
* which reverts for an unknown file.
|
|
251
|
+
*/
|
|
252
|
+
export async function isFileRegistered(client, instance, fileId) {
|
|
253
|
+
await assertInstanceChain(client, instance);
|
|
254
|
+
const info = await orOnRevert(readContract(client, { address: instance.addresses.contentStore, abi: contentStoreAbi, functionName: "fileInfo", args: [fileId] }), null);
|
|
255
|
+
return info !== null;
|
|
256
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { type Address, type Client, type Hex } from "viem";
|
|
2
|
+
import { type StreamInstance } from "../instance.js";
|
|
3
|
+
import { type LogScanOptions } from "./chain.js";
|
|
4
|
+
import type { WorkRef } from "./work.js";
|
|
5
|
+
/** Where the editions of a 1/1 contract are sold. */
|
|
6
|
+
export interface EditionVenue {
|
|
7
|
+
/** The edition auction contract: curated or Independent. Both answer the same ABI. */
|
|
8
|
+
readonly auction: Address;
|
|
9
|
+
/** The ERC-1155 editions contract. An edition's ID is its master's token ID. */
|
|
10
|
+
readonly editions: Address;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The editions contract and the edition auction of a 1/1 contract: the instance's own pair
|
|
14
|
+
* for `Stream6529`, or the artist's listed editions contract and the Independent edition
|
|
15
|
+
* auction. Returns null for an artist's contract with no editions contract listed.
|
|
16
|
+
*
|
|
17
|
+
* Contract: [`IndependentStreamRegistry.listingOf`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/independent/IndependentStreamRegistry.sol).
|
|
18
|
+
*/
|
|
19
|
+
export declare function readEditionVenue(client: Client, instance: StreamInstance, token?: Address): Promise<EditionVenue | null>;
|
|
20
|
+
/** The status of an edition sale. */
|
|
21
|
+
export type EditionStatus = "notOpened" | "open" | "closed" | "settling" | "settled" | "void" | "unknown";
|
|
22
|
+
/** The result of an edition sale: how many copies exist and their one price. */
|
|
23
|
+
export interface EditionClearing {
|
|
24
|
+
/** Copies sold. */
|
|
25
|
+
readonly count: bigint;
|
|
26
|
+
/** The price step every winner pays, and its price in wei. */
|
|
27
|
+
readonly step: number;
|
|
28
|
+
readonly price: bigint;
|
|
29
|
+
readonly revenue: bigint;
|
|
30
|
+
readonly networkFee: bigint;
|
|
31
|
+
/** True when bids at the clearing step are only partly filled, in the order they were placed. */
|
|
32
|
+
readonly rationed: boolean;
|
|
33
|
+
}
|
|
34
|
+
/** The edition sale of a master work. */
|
|
35
|
+
export interface EditionSale extends EditionVenue {
|
|
36
|
+
readonly saleId: bigint;
|
|
37
|
+
/** The master's token ID, which is also the edition's ID. */
|
|
38
|
+
readonly editionId: bigint;
|
|
39
|
+
readonly status: EditionStatus;
|
|
40
|
+
readonly statusCode: number;
|
|
41
|
+
/** The creator's cap on the count; 0 for no cap. */
|
|
42
|
+
readonly maxCount: number;
|
|
43
|
+
/** The price ladder: `ladder[step]` is the price of one copy at that step, in wei. */
|
|
44
|
+
readonly ladder: readonly bigint[];
|
|
45
|
+
/** Units bid at each step from `lowStep` upward. */
|
|
46
|
+
readonly lowStep: number;
|
|
47
|
+
readonly unitsByStep: readonly bigint[];
|
|
48
|
+
readonly bidCount: number;
|
|
49
|
+
readonly liveUnits: number;
|
|
50
|
+
/** The network's share of the revenue, out of 100,000. */
|
|
51
|
+
readonly feeShare: number;
|
|
52
|
+
readonly seller: Address;
|
|
53
|
+
/** Seconds of the soft close: a bid inside it moves the end. */
|
|
54
|
+
readonly softWindow: number;
|
|
55
|
+
/** Unix seconds: the 1/1's end, the edition's close, its end with extensions, and the last possible end. */
|
|
56
|
+
readonly oneOfOneEnd: bigint;
|
|
57
|
+
readonly closeAt: bigint;
|
|
58
|
+
readonly endTime: bigint;
|
|
59
|
+
readonly backstop: bigint;
|
|
60
|
+
/** The contract's own answer to "are bids taken now". Use this, not the clock. */
|
|
61
|
+
readonly biddingOpen: boolean;
|
|
62
|
+
/** The result if bidding closed now, or the final result once settled; null with no bids. */
|
|
63
|
+
readonly clearing: EditionClearing | null;
|
|
64
|
+
/** True when anyone may void a sale that can no longer settle (`abandon`). */
|
|
65
|
+
readonly abandonable: boolean;
|
|
66
|
+
/** The contract's pause: it stops new sales only. */
|
|
67
|
+
readonly contractPaused: boolean;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The edition sale of a master work: status, ladder, bids per step, end times and the result
|
|
71
|
+
* so far. Returns null when the 1/1 contract has no editions contract. A sale nobody opened
|
|
72
|
+
* yet comes back with status `"notOpened"`.
|
|
73
|
+
*
|
|
74
|
+
* Contract: [`UniformEditionAuction.auction`, `endTimes`, `clearing`, `ladder`, `stepTotals`, `abandonable`, `paused`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/UniformEditionAuctionLens.sol)
|
|
75
|
+
* (the auction forwards its read functions to its lens; call them on the auction's address).
|
|
76
|
+
*/
|
|
77
|
+
export declare function readEditionSale(client: Client, instance: StreamInstance, ref: WorkRef): Promise<EditionSale | null>;
|
|
78
|
+
/** One edition bid and what it wins. */
|
|
79
|
+
export interface EditionBid {
|
|
80
|
+
readonly bidId: bigint;
|
|
81
|
+
readonly bidder: Address;
|
|
82
|
+
readonly step: number;
|
|
83
|
+
readonly quantity: number;
|
|
84
|
+
/** Units won, the price each, and the refund, at the result as it stands; final once `isFinal`. */
|
|
85
|
+
readonly unitsWon: bigint;
|
|
86
|
+
readonly price: bigint;
|
|
87
|
+
readonly refund: bigint;
|
|
88
|
+
readonly isFinal: boolean;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* One edition bid and its outcome. Returns null once the bid was claimed (the contract
|
|
92
|
+
* deletes it) or if it never existed.
|
|
93
|
+
*
|
|
94
|
+
* Contract: [`UniformEditionAuction.bidOf`, `bidOutcome`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/UniformEditionAuctionLens.sol).
|
|
95
|
+
*/
|
|
96
|
+
export declare function readEditionBid(client: Client, instance: StreamInstance, venue: Pick<EditionVenue, "auction">, editionSaleId: bigint, bidId: bigint): Promise<EditionBid | null>;
|
|
97
|
+
/** An edition bid as its events tell it. */
|
|
98
|
+
export interface EditionBidRecord {
|
|
99
|
+
readonly bidId: bigint;
|
|
100
|
+
readonly bidder: Address;
|
|
101
|
+
/** The step now: where it was placed, or where it was last raised to. */
|
|
102
|
+
readonly step: number;
|
|
103
|
+
readonly quantity: number;
|
|
104
|
+
/** Set once claimed: the units won and the ETH returned. */
|
|
105
|
+
readonly claimed: {
|
|
106
|
+
readonly unitsWon: bigint;
|
|
107
|
+
readonly refund: bigint;
|
|
108
|
+
readonly to: Address;
|
|
109
|
+
} | null;
|
|
110
|
+
readonly transactionHash: Hex;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Every bid of an edition sale, from its events, optionally only one bidder's. Use it to find
|
|
114
|
+
* a wallet's bid IDs for `claimEditionBid`.
|
|
115
|
+
*
|
|
116
|
+
* Contract: the `BidPlaced`, `BidRaised` and `BidClaimed` events of [`UniformEditionAuction`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/UniformEditionAuction.sol).
|
|
117
|
+
*/
|
|
118
|
+
export declare function readEditionBids(client: Client, instance: StreamInstance, venue: Pick<EditionVenue, "auction">, editionSaleId: bigint, options?: LogScanOptions & {
|
|
119
|
+
readonly bidder?: Address;
|
|
120
|
+
}): Promise<EditionBidRecord[]>;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { getAbiItem, isAddressEqual, zeroAddress } from "viem";
|
|
3
|
+
import { readContract } from "viem/actions";
|
|
4
|
+
import { EDITION_STATUS } from "../constants.js";
|
|
5
|
+
import { independentStreamRegistryAbi } from "../generated/abis/IndependentStreamRegistry.js";
|
|
6
|
+
import { uniformEditionAuctionAbi } from "../generated/abis/UniformEditionAuction.js";
|
|
7
|
+
import { saleId as saleIdOf } from "../hashing/ids.js";
|
|
8
|
+
import { assertInstanceChain } from "../instance.js";
|
|
9
|
+
import { orOnRevert, scanEvents } from "./chain.js";
|
|
10
|
+
/**
|
|
11
|
+
* The editions contract and the edition auction of a 1/1 contract: the instance's own pair
|
|
12
|
+
* for `Stream6529`, or the artist's listed editions contract and the Independent edition
|
|
13
|
+
* auction. Returns null for an artist's contract with no editions contract listed.
|
|
14
|
+
*
|
|
15
|
+
* Contract: [`IndependentStreamRegistry.listingOf`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/independent/IndependentStreamRegistry.sol).
|
|
16
|
+
*/
|
|
17
|
+
export async function readEditionVenue(client, instance, token) {
|
|
18
|
+
await assertInstanceChain(client, instance);
|
|
19
|
+
if (token === undefined || isAddressEqual(token, instance.addresses.stream)) {
|
|
20
|
+
return { auction: instance.addresses.editionAuction, editions: instance.addresses.streamEditions };
|
|
21
|
+
}
|
|
22
|
+
const listing = await readContract(client, {
|
|
23
|
+
address: instance.addresses.independentRegistry,
|
|
24
|
+
abi: independentStreamRegistryAbi,
|
|
25
|
+
functionName: "listingOf",
|
|
26
|
+
args: [token],
|
|
27
|
+
});
|
|
28
|
+
if (isAddressEqual(listing.partner, zeroAddress))
|
|
29
|
+
return null;
|
|
30
|
+
return { auction: instance.addresses.independentEditionAuction, editions: listing.partner };
|
|
31
|
+
}
|
|
32
|
+
const STATUS_NAMES = {
|
|
33
|
+
[EDITION_STATUS.NONE]: "notOpened",
|
|
34
|
+
[EDITION_STATUS.OPEN]: "open",
|
|
35
|
+
[EDITION_STATUS.CLOSED]: "closed",
|
|
36
|
+
[EDITION_STATUS.SETTLING]: "settling",
|
|
37
|
+
[EDITION_STATUS.SETTLED]: "settled",
|
|
38
|
+
[EDITION_STATUS.VOID]: "void",
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* The edition sale of a master work: status, ladder, bids per step, end times and the result
|
|
42
|
+
* so far. Returns null when the 1/1 contract has no editions contract. A sale nobody opened
|
|
43
|
+
* yet comes back with status `"notOpened"`.
|
|
44
|
+
*
|
|
45
|
+
* Contract: [`UniformEditionAuction.auction`, `endTimes`, `clearing`, `ladder`, `stepTotals`, `abandonable`, `paused`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/UniformEditionAuctionLens.sol)
|
|
46
|
+
* (the auction forwards its read functions to its lens; call them on the auction's address).
|
|
47
|
+
*/
|
|
48
|
+
export async function readEditionSale(client, instance, ref) {
|
|
49
|
+
const venue = await readEditionVenue(client, instance, ref.token);
|
|
50
|
+
if (!venue)
|
|
51
|
+
return null;
|
|
52
|
+
const id = saleIdOf(venue.editions, ref.tokenId);
|
|
53
|
+
const auction = { address: venue.auction, abi: uniformEditionAuctionAbi };
|
|
54
|
+
const [sale, contractPaused] = await Promise.all([
|
|
55
|
+
// The lens reverts with UnknownAuction for a sale nobody opened.
|
|
56
|
+
orOnRevert(readContract(client, { ...auction, functionName: "auction", args: [id] }), null),
|
|
57
|
+
readContract(client, { ...auction, functionName: "paused" }),
|
|
58
|
+
]);
|
|
59
|
+
if (!sale || sale.status === EDITION_STATUS.NONE) {
|
|
60
|
+
return {
|
|
61
|
+
...venue,
|
|
62
|
+
saleId: id,
|
|
63
|
+
editionId: ref.tokenId,
|
|
64
|
+
status: "notOpened",
|
|
65
|
+
statusCode: EDITION_STATUS.NONE,
|
|
66
|
+
maxCount: 0,
|
|
67
|
+
ladder: [],
|
|
68
|
+
lowStep: 0,
|
|
69
|
+
unitsByStep: [],
|
|
70
|
+
bidCount: 0,
|
|
71
|
+
liveUnits: 0,
|
|
72
|
+
feeShare: 0,
|
|
73
|
+
seller: zeroAddress,
|
|
74
|
+
softWindow: 0,
|
|
75
|
+
oneOfOneEnd: 0n,
|
|
76
|
+
closeAt: 0n,
|
|
77
|
+
endTime: 0n,
|
|
78
|
+
backstop: 0n,
|
|
79
|
+
biddingOpen: false,
|
|
80
|
+
clearing: null,
|
|
81
|
+
abandonable: false,
|
|
82
|
+
contractPaused,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
const [endTimes, clearing, ladder, totals, abandonable] = await Promise.all([
|
|
86
|
+
readContract(client, { ...auction, functionName: "endTimes", args: [id] }),
|
|
87
|
+
orOnRevert(readContract(client, { ...auction, functionName: "clearing", args: [id] }), null),
|
|
88
|
+
readContract(client, { ...auction, functionName: "ladder", args: [id] }),
|
|
89
|
+
readContract(client, { ...auction, functionName: "stepTotals", args: [id] }),
|
|
90
|
+
readContract(client, { ...auction, functionName: "abandonable", args: [id] }),
|
|
91
|
+
]);
|
|
92
|
+
return {
|
|
93
|
+
...venue,
|
|
94
|
+
saleId: id,
|
|
95
|
+
editionId: ref.tokenId,
|
|
96
|
+
status: STATUS_NAMES[sale.status] ?? "unknown",
|
|
97
|
+
statusCode: sale.status,
|
|
98
|
+
maxCount: sale.maxCount,
|
|
99
|
+
ladder,
|
|
100
|
+
lowStep: Number(totals[0]),
|
|
101
|
+
unitsByStep: totals[1],
|
|
102
|
+
bidCount: sale.bidCount,
|
|
103
|
+
liveUnits: sale.liveUnits,
|
|
104
|
+
feeShare: sale.feeShare,
|
|
105
|
+
seller: sale.seller,
|
|
106
|
+
softWindow: sale.terms.softWindow,
|
|
107
|
+
oneOfOneEnd: endTimes.oneOfOneEnd,
|
|
108
|
+
closeAt: endTimes.closeAt,
|
|
109
|
+
endTime: endTimes.endTime,
|
|
110
|
+
backstop: endTimes.backstop,
|
|
111
|
+
biddingOpen: endTimes.biddingOpen,
|
|
112
|
+
clearing: clearing && clearing.count > 0n
|
|
113
|
+
? {
|
|
114
|
+
count: clearing.count,
|
|
115
|
+
step: Number(clearing.step),
|
|
116
|
+
price: clearing.price,
|
|
117
|
+
revenue: clearing.revenue,
|
|
118
|
+
networkFee: clearing.networkFee,
|
|
119
|
+
rationed: clearing.rationed,
|
|
120
|
+
}
|
|
121
|
+
: null,
|
|
122
|
+
abandonable: abandonable[0],
|
|
123
|
+
contractPaused,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* One edition bid and its outcome. Returns null once the bid was claimed (the contract
|
|
128
|
+
* deletes it) or if it never existed.
|
|
129
|
+
*
|
|
130
|
+
* Contract: [`UniformEditionAuction.bidOf`, `bidOutcome`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/UniformEditionAuctionLens.sol).
|
|
131
|
+
*/
|
|
132
|
+
export async function readEditionBid(client, instance, venue, editionSaleId, bidId) {
|
|
133
|
+
await assertInstanceChain(client, instance);
|
|
134
|
+
const auction = { address: venue.auction, abi: uniformEditionAuctionAbi };
|
|
135
|
+
const bid = await orOnRevert(readContract(client, { ...auction, functionName: "bidOf", args: [editionSaleId, bidId] }), null);
|
|
136
|
+
if (!bid || isAddressEqual(bid.bidder, zeroAddress))
|
|
137
|
+
return null;
|
|
138
|
+
const outcome = await readContract(client, { ...auction, functionName: "bidOutcome", args: [editionSaleId, bidId] });
|
|
139
|
+
return {
|
|
140
|
+
bidId,
|
|
141
|
+
bidder: bid.bidder,
|
|
142
|
+
step: bid.step,
|
|
143
|
+
quantity: bid.quantity,
|
|
144
|
+
unitsWon: outcome.unitsWon,
|
|
145
|
+
price: outcome.price,
|
|
146
|
+
refund: outcome.refund,
|
|
147
|
+
isFinal: outcome.isFinal,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
const BID_PLACED = /*#__PURE__*/ getAbiItem({ abi: uniformEditionAuctionAbi, name: "BidPlaced" });
|
|
151
|
+
const BID_RAISED = /*#__PURE__*/ getAbiItem({ abi: uniformEditionAuctionAbi, name: "BidRaised" });
|
|
152
|
+
const BID_CLAIMED = /*#__PURE__*/ getAbiItem({ abi: uniformEditionAuctionAbi, name: "BidClaimed" });
|
|
153
|
+
/**
|
|
154
|
+
* Every bid of an edition sale, from its events, optionally only one bidder's. Use it to find
|
|
155
|
+
* a wallet's bid IDs for `claimEditionBid`.
|
|
156
|
+
*
|
|
157
|
+
* Contract: the `BidPlaced`, `BidRaised` and `BidClaimed` events of [`UniformEditionAuction`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/UniformEditionAuction.sol).
|
|
158
|
+
*/
|
|
159
|
+
export async function readEditionBids(client, instance, venue, editionSaleId, options = {}) {
|
|
160
|
+
await assertInstanceChain(client, instance);
|
|
161
|
+
const args = { saleId: editionSaleId };
|
|
162
|
+
const [placed, raised, claimed] = await Promise.all([
|
|
163
|
+
scanEvents(client, instance, { address: venue.auction, event: BID_PLACED, args }, options),
|
|
164
|
+
scanEvents(client, instance, { address: venue.auction, event: BID_RAISED, args }, options),
|
|
165
|
+
scanEvents(client, instance, { address: venue.auction, event: BID_CLAIMED, args }, options),
|
|
166
|
+
]);
|
|
167
|
+
const raisedTo = new Map(raised.map((log) => [log.args.bidId, Number(log.args.toStep)]));
|
|
168
|
+
const claims = new Map(claimed.map((log) => [log.args.bidId, log.args]));
|
|
169
|
+
return placed
|
|
170
|
+
.filter((log) => options.bidder === undefined || isAddressEqual(log.args.bidder, options.bidder))
|
|
171
|
+
.map((log) => {
|
|
172
|
+
const claim = claims.get(log.args.bidId);
|
|
173
|
+
return {
|
|
174
|
+
bidId: log.args.bidId,
|
|
175
|
+
bidder: log.args.bidder,
|
|
176
|
+
step: raisedTo.get(log.args.bidId) ?? Number(log.args.step),
|
|
177
|
+
quantity: Number(log.args.quantity),
|
|
178
|
+
claimed: claim ? { unitsWon: claim.unitsWon, refund: claim.refund, to: claim.to } : null,
|
|
179
|
+
transactionHash: log.transactionHash,
|
|
180
|
+
};
|
|
181
|
+
});
|
|
182
|
+
}
|