@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,121 @@
|
|
|
1
|
+
import { readContract } from "viem/actions";
|
|
2
|
+
import { CURRENCY_ETH } from "../constants.js";
|
|
3
|
+
import { accountsAbi } from "../generated/abis/Accounts.js";
|
|
4
|
+
import { englishAuctionAbi } from "../generated/abis/EnglishAuction.js";
|
|
5
|
+
import { uniformEditionAuctionAbi } from "../generated/abis/UniformEditionAuction.js";
|
|
6
|
+
import { newArtistId } from "../hashing/ids.js";
|
|
7
|
+
import { assertInstanceChain } from "../instance.js";
|
|
8
|
+
import { orOnRevert } from "./chain.js";
|
|
9
|
+
/**
|
|
10
|
+
* The artist ID recorded for an address: the account it is (or was) the root of, or, with none,
|
|
11
|
+
* the ID a new account for it gets (the address as a number).
|
|
12
|
+
*
|
|
13
|
+
* This is a lookup by ROOT. A wallet that acts for an account only through consolidation is
|
|
14
|
+
* not a root: it reads as "no account" here, although the contracts accept its signatures for
|
|
15
|
+
* that account. There is no on-chain lookup from such a wallet to its account, so when a
|
|
16
|
+
* wallet may be consolidated, take the account's ID from where it is recorded (a work's
|
|
17
|
+
* `artistId`, `PackageRegistry.acceptedAs`, a token's `artistId()`) and check it with
|
|
18
|
+
* `readIsWallet`. An account whose root was replaced keeps its ID, so the old root still
|
|
19
|
+
* reads that ID here: `readIsWallet` says who acts for it now.
|
|
20
|
+
*
|
|
21
|
+
* Contract: [`Accounts.artistIdOf`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/identity/Accounts.sol).
|
|
22
|
+
*/
|
|
23
|
+
export async function readArtistId(client, instance, wallet) {
|
|
24
|
+
await assertInstanceChain(client, instance);
|
|
25
|
+
const stored = await readContract(client, {
|
|
26
|
+
address: instance.addresses.accounts,
|
|
27
|
+
abi: accountsAbi,
|
|
28
|
+
functionName: "artistIdOf",
|
|
29
|
+
args: [wallet],
|
|
30
|
+
});
|
|
31
|
+
return stored === 0n ? { artistId: newArtistId(wallet), exists: false } : { artistId: stored, exists: true };
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The account a wallet acts for, or null. This is the one place the library answers "whose
|
|
35
|
+
* wallet is this", so that a change in the contracts is a change here only.
|
|
36
|
+
*
|
|
37
|
+
* Today the contracts can only say it for a root (`artistIdOf`). For a wallet that acts for an
|
|
38
|
+
* account through consolidation there is no lookup, so the caller names the accounts it could
|
|
39
|
+
* be (`candidates`: for example the artist of the work or contract in question) and each is
|
|
40
|
+
* checked with `isWallet`. Without a candidate that matches, the answer for such a wallet is
|
|
41
|
+
* null, which does not prove it acts for nobody.
|
|
42
|
+
*
|
|
43
|
+
* Contract: [`Accounts.artistIdOf`, `isWallet`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/identity/Accounts.sol).
|
|
44
|
+
*/
|
|
45
|
+
export async function readAccountOf(client, instance, wallet, options = {}) {
|
|
46
|
+
await assertInstanceChain(client, instance);
|
|
47
|
+
const accounts = { address: instance.addresses.accounts, abi: accountsAbi };
|
|
48
|
+
const asRoot = await readContract(client, { ...accounts, functionName: "artistIdOf", args: [wallet] });
|
|
49
|
+
// A former root still reads its old account: only a wallet the account accepts now counts.
|
|
50
|
+
for (const [artistId, via] of [...(asRoot === 0n ? [] : [[asRoot, "root"]]), ...(options.candidates ?? []).map((id) => [id, "consolidation"])]) {
|
|
51
|
+
const acts = await orOnRevert(readContract(client, { ...accounts, functionName: "isWallet", args: [artistId, wallet] }), false);
|
|
52
|
+
if (acts)
|
|
53
|
+
return { artistId, via: artistId === asRoot ? "root" : via };
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* An account's identity, authority and payout address, or null when no account has this ID.
|
|
59
|
+
*
|
|
60
|
+
* Contract: [`Accounts.artist`, `activeAuthorityOf`, `payoutAddress`, `changeNonce`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/identity/Accounts.sol).
|
|
61
|
+
*/
|
|
62
|
+
export async function readAccount(client, instance, artistId) {
|
|
63
|
+
await assertInstanceChain(client, instance);
|
|
64
|
+
const base = { address: instance.addresses.accounts, abi: accountsAbi };
|
|
65
|
+
// `Accounts.artist` reverts with UnknownArtist for an ID it does not know.
|
|
66
|
+
const known = await orOnRevert(readContract(client, { ...base, functionName: "artist", args: [artistId] }), null);
|
|
67
|
+
if (!known)
|
|
68
|
+
return null;
|
|
69
|
+
const [identity, frozenUntil] = known;
|
|
70
|
+
const [activeAuthority, payoutAddress, changeNonce] = await Promise.all([
|
|
71
|
+
readContract(client, { ...base, functionName: "activeAuthorityOf", args: [artistId] }),
|
|
72
|
+
readContract(client, { ...base, functionName: "payoutAddress", args: [artistId] }),
|
|
73
|
+
readContract(client, { ...base, functionName: "changeNonce", args: [artistId] }),
|
|
74
|
+
]);
|
|
75
|
+
return { artistId, identity, activeAuthority, frozenUntil, payoutAddress, changeNonce };
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Whether `wallet` acts for the account `artistId` (its root, or a wallet consolidated with it).
|
|
79
|
+
*
|
|
80
|
+
* Contract: [`Accounts.isWallet`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/identity/Accounts.sol).
|
|
81
|
+
*/
|
|
82
|
+
export async function readIsWallet(client, instance, artistId, wallet) {
|
|
83
|
+
await assertInstanceChain(client, instance);
|
|
84
|
+
return readContract(client, {
|
|
85
|
+
address: instance.addresses.accounts,
|
|
86
|
+
abi: accountsAbi,
|
|
87
|
+
functionName: "isWallet",
|
|
88
|
+
args: [artistId, wallet],
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The ETH credited to `account` on the three auction contracts: outbid 1/1 bids and edition
|
|
93
|
+
* refunds are credited, never pushed, and wait to be withdrawn.
|
|
94
|
+
*
|
|
95
|
+
* Contract: [`EnglishAuction.claimable`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/EnglishAuction.sol),
|
|
96
|
+
* [`UniformEditionAuction.claimable`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/UniformEditionAuction.sol).
|
|
97
|
+
*/
|
|
98
|
+
export async function readClaimable(client, instance, account) {
|
|
99
|
+
await assertInstanceChain(client, instance);
|
|
100
|
+
const [englishAuction, editionAuction, independentEditionAuction] = await Promise.all([
|
|
101
|
+
readContract(client, {
|
|
102
|
+
address: instance.addresses.englishAuction,
|
|
103
|
+
abi: englishAuctionAbi,
|
|
104
|
+
functionName: "claimable",
|
|
105
|
+
args: [account],
|
|
106
|
+
}),
|
|
107
|
+
readContract(client, {
|
|
108
|
+
address: instance.addresses.editionAuction,
|
|
109
|
+
abi: uniformEditionAuctionAbi,
|
|
110
|
+
functionName: "claimable",
|
|
111
|
+
args: [account, CURRENCY_ETH],
|
|
112
|
+
}),
|
|
113
|
+
readContract(client, {
|
|
114
|
+
address: instance.addresses.independentEditionAuction,
|
|
115
|
+
abi: uniformEditionAuctionAbi,
|
|
116
|
+
functionName: "claimable",
|
|
117
|
+
args: [account, CURRENCY_ETH],
|
|
118
|
+
}),
|
|
119
|
+
]);
|
|
120
|
+
return { englishAuction, editionAuction, independentEditionAuction };
|
|
121
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type AbiEvent, type Address, type Client, type GetLogsReturnType } from "viem";
|
|
2
|
+
import type { StreamInstance } from "../instance.js";
|
|
3
|
+
/**
|
|
4
|
+
* The chain's clock: the timestamp of the latest block, in Unix seconds.
|
|
5
|
+
*
|
|
6
|
+
* The contracts compare every deadline with `block.timestamp`. A deadline taken from the
|
|
7
|
+
* computer's clock can already be over, or last far longer than meant, when that clock is wrong.
|
|
8
|
+
*/
|
|
9
|
+
export declare function chainTime(client: Client): Promise<bigint>;
|
|
10
|
+
/** How far the chain's clock and this computer's may differ before a deadline is refused: one day. */
|
|
11
|
+
export declare const MAX_CLOCK_DIFFERENCE_SECONDS = 86400;
|
|
12
|
+
/**
|
|
13
|
+
* A signature deadline on the chain's clock: the latest block's time plus `lifetimeSeconds`.
|
|
14
|
+
*
|
|
15
|
+
* The block time comes from the RPC, and a deadline is part of what gets signed, so it is
|
|
16
|
+
* checked against this computer's clock: if the two differ by more than a day the call throws
|
|
17
|
+
* instead of producing a signature that lives far longer (or shorter) than asked. A local
|
|
18
|
+
* fork whose clock was moved needs `allowClockDifference`.
|
|
19
|
+
*/
|
|
20
|
+
export declare function chainDeadline(client: Client, lifetimeSeconds: number, options?: {
|
|
21
|
+
readonly allowClockDifference?: boolean;
|
|
22
|
+
}): Promise<bigint>;
|
|
23
|
+
/**
|
|
24
|
+
* Turns the clock check of `chainDeadline` off for the whole process. FOR LOCAL FORKS ONLY,
|
|
25
|
+
* where tests move the chain's clock by days; never in a page or a script that signs for real.
|
|
26
|
+
*/
|
|
27
|
+
export declare function allowClockDifferenceForTests(allowed: boolean): void;
|
|
28
|
+
/** Whether `error` is a revert of the contract itself (not a network failure), optionally one named `errorName`. */
|
|
29
|
+
export declare function isContractRevert(error: unknown, errorName?: string): boolean;
|
|
30
|
+
/** The name of the custom error a contract reverted with, or null when it is not a named revert. */
|
|
31
|
+
export declare function revertName(error: unknown): string | null;
|
|
32
|
+
/** Runs a read and answers `fallback` when the contract reverts. Any other failure is thrown. */
|
|
33
|
+
export declare function orOnRevert<T, F>(read: Promise<T>, fallback: F): Promise<T | F>;
|
|
34
|
+
/** How event scans are cut into block ranges. */
|
|
35
|
+
export interface LogScanOptions {
|
|
36
|
+
/** The first block to scan. Default: the instance's start block. */
|
|
37
|
+
readonly fromBlock?: bigint;
|
|
38
|
+
/** The last block to scan. Default: the latest block. */
|
|
39
|
+
readonly toBlock?: bigint;
|
|
40
|
+
/** The most blocks per request. Public RPCs refuse wide ranges. Default: 40,000. */
|
|
41
|
+
readonly blockWindow?: bigint;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* One event's logs from one contract, since the instance was deployed, fetched in block
|
|
45
|
+
* windows so that public RPCs accept the requests. `args` filters by indexed arguments.
|
|
46
|
+
*
|
|
47
|
+
* The provider must serve logs back to the first block scanned. One that has pruned them
|
|
48
|
+
* (EIP-4444, error 4444) gets a `HistoryUnavailableError` (`HISTORY_UNAVAILABLE`).
|
|
49
|
+
*/
|
|
50
|
+
export declare function scanEvents<const TEvent extends AbiEvent>(client: Client, instance: StreamInstance, query: {
|
|
51
|
+
readonly address: Address;
|
|
52
|
+
readonly event: TEvent;
|
|
53
|
+
readonly args?: Record<string, unknown>;
|
|
54
|
+
}, options?: LogScanOptions): Promise<GetLogsReturnType<TEvent, [TEvent], true>>;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { BaseError, ContractFunctionRevertedError } from "viem";
|
|
3
|
+
import { getBlock, getBlockNumber, getLogs } from "viem/actions";
|
|
4
|
+
import { HistoryUnavailableError, StreamSdkError } from "../errors.js";
|
|
5
|
+
/**
|
|
6
|
+
* The chain's clock: the timestamp of the latest block, in Unix seconds.
|
|
7
|
+
*
|
|
8
|
+
* The contracts compare every deadline with `block.timestamp`. A deadline taken from the
|
|
9
|
+
* computer's clock can already be over, or last far longer than meant, when that clock is wrong.
|
|
10
|
+
*/
|
|
11
|
+
export async function chainTime(client) {
|
|
12
|
+
const block = await getBlock(client, { blockTag: "latest" });
|
|
13
|
+
return block.timestamp;
|
|
14
|
+
}
|
|
15
|
+
/** How far the chain's clock and this computer's may differ before a deadline is refused: one day. */
|
|
16
|
+
export const MAX_CLOCK_DIFFERENCE_SECONDS = 86_400;
|
|
17
|
+
/**
|
|
18
|
+
* A signature deadline on the chain's clock: the latest block's time plus `lifetimeSeconds`.
|
|
19
|
+
*
|
|
20
|
+
* The block time comes from the RPC, and a deadline is part of what gets signed, so it is
|
|
21
|
+
* checked against this computer's clock: if the two differ by more than a day the call throws
|
|
22
|
+
* instead of producing a signature that lives far longer (or shorter) than asked. A local
|
|
23
|
+
* fork whose clock was moved needs `allowClockDifference`.
|
|
24
|
+
*/
|
|
25
|
+
export async function chainDeadline(client, lifetimeSeconds, options = {}) {
|
|
26
|
+
if (!Number.isSafeInteger(lifetimeSeconds) || lifetimeSeconds <= 0) {
|
|
27
|
+
throw new RangeError("A deadline's lifetime is a positive whole number of seconds.");
|
|
28
|
+
}
|
|
29
|
+
const now = await chainTime(client);
|
|
30
|
+
const local = BigInt(Math.floor(Date.now() / 1000));
|
|
31
|
+
const difference = now > local ? now - local : local - now;
|
|
32
|
+
if (!options.allowClockDifference && !clockDifferenceAllowed && difference > BigInt(MAX_CLOCK_DIFFERENCE_SECONDS)) {
|
|
33
|
+
throw new StreamSdkError("CLOCK_MISMATCH", `The chain's clock, as the RPC reports it, and this computer's differ by ${difference} seconds. Refusing to set a signature deadline from it.`);
|
|
34
|
+
}
|
|
35
|
+
return now + BigInt(lifetimeSeconds);
|
|
36
|
+
}
|
|
37
|
+
let clockDifferenceAllowed = false;
|
|
38
|
+
/**
|
|
39
|
+
* Turns the clock check of `chainDeadline` off for the whole process. FOR LOCAL FORKS ONLY,
|
|
40
|
+
* where tests move the chain's clock by days; never in a page or a script that signs for real.
|
|
41
|
+
*/
|
|
42
|
+
export function allowClockDifferenceForTests(allowed) {
|
|
43
|
+
clockDifferenceAllowed = allowed;
|
|
44
|
+
}
|
|
45
|
+
/** Whether `error` is a revert of the contract itself (not a network failure), optionally one named `errorName`. */
|
|
46
|
+
export function isContractRevert(error, errorName) {
|
|
47
|
+
if (!(error instanceof BaseError))
|
|
48
|
+
return false;
|
|
49
|
+
const revert = error.walk((cause) => cause instanceof ContractFunctionRevertedError);
|
|
50
|
+
if (!(revert instanceof ContractFunctionRevertedError))
|
|
51
|
+
return false;
|
|
52
|
+
return errorName === undefined || revert.data?.errorName === errorName;
|
|
53
|
+
}
|
|
54
|
+
/** The name of the custom error a contract reverted with, or null when it is not a named revert. */
|
|
55
|
+
export function revertName(error) {
|
|
56
|
+
if (!(error instanceof BaseError))
|
|
57
|
+
return null;
|
|
58
|
+
const revert = error.walk((cause) => cause instanceof ContractFunctionRevertedError);
|
|
59
|
+
return revert instanceof ContractFunctionRevertedError ? (revert.data?.errorName ?? null) : null;
|
|
60
|
+
}
|
|
61
|
+
/** Runs a read and answers `fallback` when the contract reverts. Any other failure is thrown. */
|
|
62
|
+
export async function orOnRevert(read, fallback) {
|
|
63
|
+
try {
|
|
64
|
+
return await read;
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
if (isContractRevert(error))
|
|
68
|
+
return fallback;
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/** Whether a provider's error says the range is past its head: one of its nodes is a block behind another. */
|
|
73
|
+
function isPastHead(error) {
|
|
74
|
+
return error instanceof BaseError && /beyond current head|block range is in the future/i.test(`${error.details} ${error.message}`);
|
|
75
|
+
}
|
|
76
|
+
/** Whether a provider's error says it has pruned the history asked for (EIP-4444: code 4444). */
|
|
77
|
+
function isPrunedHistory(error) {
|
|
78
|
+
if (!(error instanceof BaseError))
|
|
79
|
+
return false;
|
|
80
|
+
if (error.walk((cause) => cause?.code === 4444) !== null)
|
|
81
|
+
return true;
|
|
82
|
+
return /pruned history|history (is )?(unavailable|pruned)/i.test(`${error.details} ${error.message}`);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Runs one log request, and again (up to three more times, a little later each time) when
|
|
86
|
+
* the answer is one that another node of the same provider may not give. A public RPC is many
|
|
87
|
+
* nodes: the one asked for the logs can be a block behind the one that gave the block number,
|
|
88
|
+
* and some keep less history than others. A provider that still says it has pruned the range
|
|
89
|
+
* gets a `HistoryUnavailableError`.
|
|
90
|
+
*/
|
|
91
|
+
async function logsRetried(fromBlock, toBlock, request) {
|
|
92
|
+
for (let attempt = 0;; attempt++) {
|
|
93
|
+
try {
|
|
94
|
+
return await request();
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
const pruned = isPrunedHistory(error);
|
|
98
|
+
if (attempt === 3 || !(pruned || isPastHead(error))) {
|
|
99
|
+
if (pruned)
|
|
100
|
+
throw new HistoryUnavailableError(fromBlock, toBlock, { cause: error });
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
await new Promise((resolve) => setTimeout(resolve, 400 * (attempt + 1)));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* One event's logs from one contract, since the instance was deployed, fetched in block
|
|
109
|
+
* windows so that public RPCs accept the requests. `args` filters by indexed arguments.
|
|
110
|
+
*
|
|
111
|
+
* The provider must serve logs back to the first block scanned. One that has pruned them
|
|
112
|
+
* (EIP-4444, error 4444) gets a `HistoryUnavailableError` (`HISTORY_UNAVAILABLE`).
|
|
113
|
+
*/
|
|
114
|
+
export async function scanEvents(client, instance, query, options = {}) {
|
|
115
|
+
const window = options.blockWindow ?? 40000n;
|
|
116
|
+
// Asked fresh: viem remembers the block number for a few seconds, and a scan right after a
|
|
117
|
+
// transaction must see that transaction's block.
|
|
118
|
+
const last = options.toBlock ?? (await getBlockNumber(client, { cacheTime: 0 }));
|
|
119
|
+
const logs = [];
|
|
120
|
+
for (let from = options.fromBlock ?? instance.startBlock; from <= last; from += window) {
|
|
121
|
+
const to = from + window - 1n > last ? last : from + window - 1n;
|
|
122
|
+
const page = await logsRetried(from, to, () => getLogs(client, {
|
|
123
|
+
address: query.address,
|
|
124
|
+
event: query.event,
|
|
125
|
+
args: query.args,
|
|
126
|
+
fromBlock: from,
|
|
127
|
+
toBlock: to,
|
|
128
|
+
strict: true,
|
|
129
|
+
}));
|
|
130
|
+
logs.push(...page);
|
|
131
|
+
}
|
|
132
|
+
return logs;
|
|
133
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { type Address, type Client, type Hex } from "viem";
|
|
2
|
+
import { type StreamInstance } from "../instance.js";
|
|
3
|
+
import type { PackageItem } from "../types.js";
|
|
4
|
+
/**
|
|
5
|
+
* What a creation flow reads before it acts: whether the test gate is open, the state of a
|
|
6
|
+
* package, whether an item is minted already, what a listing will record. They are reads; the
|
|
7
|
+
* actions call them, and a page can call them to show the same facts.
|
|
8
|
+
*/
|
|
9
|
+
/** The test gate of an instance, or an error saying it has none. */
|
|
10
|
+
export declare function gateOf(instance: StreamInstance): Address;
|
|
11
|
+
/**
|
|
12
|
+
* Whether the test gate of an instance is open for `account` right now: it can create a
|
|
13
|
+
* collection and its approval of a package is accepted. The network can close the gate at any
|
|
14
|
+
* time, so ask before a run that stores files.
|
|
15
|
+
*
|
|
16
|
+
* Both answers come from simulating the real calls, so they hold for the block read.
|
|
17
|
+
*
|
|
18
|
+
* Contract: [`SepoliaOpenGate.createCollection`, `attestationOf`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/script/sepolia/SepoliaOpenGate.sol),
|
|
19
|
+
* [`PackageRegistry.registerPackage`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/curation/PackageRegistry.sol).
|
|
20
|
+
* A TEST CONVENIENCE: with the gate open nothing is curated.
|
|
21
|
+
*/
|
|
22
|
+
export declare function readGate(client: Client, instance: StreamInstance, account: Address): Promise<{
|
|
23
|
+
collections: boolean;
|
|
24
|
+
packages: boolean;
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* The state of a package root in the registry: not registered, approved, or revoked (also
|
|
28
|
+
* when its signer's approvals were stopped).
|
|
29
|
+
*
|
|
30
|
+
* Contract: [`PackageRegistry.packageOf`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/curation/PackageRegistry.sol).
|
|
31
|
+
*/
|
|
32
|
+
export declare function readPackageStatus(client: Client, instance: StreamInstance, packageRoot: Hex): Promise<"none" | "approved" | "revoked">;
|
|
33
|
+
/**
|
|
34
|
+
* The profile fields an acceptance by `account` must carry: the stored ones if the wallet has
|
|
35
|
+
* an account (every later acceptance must repeat them), otherwise null, and the caller decides
|
|
36
|
+
* what the new account's fields are.
|
|
37
|
+
*
|
|
38
|
+
* Contract: [`Accounts.artistIdOf`, `artist`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/identity/Accounts.sol).
|
|
39
|
+
*/
|
|
40
|
+
export declare function readStoredProfile(client: Client, instance: StreamInstance, account: Address): Promise<{
|
|
41
|
+
profileId: Hex;
|
|
42
|
+
profileDocHash: Hex;
|
|
43
|
+
} | null>;
|
|
44
|
+
/**
|
|
45
|
+
* An artist's first unused move nonce, counting up from 0. Any unused number is valid; small
|
|
46
|
+
* ones share storage words, which costs the least gas.
|
|
47
|
+
*
|
|
48
|
+
* Contract: [`PackageRegistry.isMoveNonceUsed`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/curation/PackageRegistry.sol).
|
|
49
|
+
*
|
|
50
|
+
* @throws FlowError `NO_MOVE_NONCE` when the first `limit` (default 1,024) are all used.
|
|
51
|
+
*/
|
|
52
|
+
export declare function readNextMoveNonce(client: Client, instance: StreamInstance, artistId: bigint, limit?: number): Promise<bigint>;
|
|
53
|
+
/**
|
|
54
|
+
* The token already minted from `item` on `token`, or null.
|
|
55
|
+
*
|
|
56
|
+
* A token contract mints a content hash once, so finding the primary file's hash minted is
|
|
57
|
+
* not enough to know it is this work: another artist, collection or record makes another
|
|
58
|
+
* item. The minted token's item hash must be this item's, or the content is taken.
|
|
59
|
+
*
|
|
60
|
+
* A burned token still holds its content hash, and the contract accepts the content again
|
|
61
|
+
* once the network released it. A burned token therefore answers null here: whether the
|
|
62
|
+
* content may be minted again is the contract's decision when the sale starts.
|
|
63
|
+
*
|
|
64
|
+
* Contract: [`Stream6529.tokenOfContent`, `itemHashOf`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/core/StreamBase.sol).
|
|
65
|
+
*
|
|
66
|
+
* @throws FlowError `CONTENT_ALREADY_MINTED` when the content is minted as another item.
|
|
67
|
+
*/
|
|
68
|
+
export declare function readMintedToken(client: Client, instance: StreamInstance, token: Address, item: PackageItem): Promise<bigint | null>;
|
|
69
|
+
/** What the registry answers for an item it would accept. */
|
|
70
|
+
export interface ItemPreview {
|
|
71
|
+
readonly itemHash: Hex;
|
|
72
|
+
/**
|
|
73
|
+
* The lead artist's ID: its account's, or, while it has no account, the ID its first
|
|
74
|
+
* acceptance will give it (its own address as a number).
|
|
75
|
+
*/
|
|
76
|
+
readonly artistId: bigint | null;
|
|
77
|
+
/** The vault the artist portion of the first sale will go to, and the royalty vault. */
|
|
78
|
+
readonly seller: Address | null;
|
|
79
|
+
readonly royaltyReceiver: Address | null;
|
|
80
|
+
/** The royalty rate the work will get, out of 100,000. */
|
|
81
|
+
readonly royaltyRate: number | null;
|
|
82
|
+
/**
|
|
83
|
+
* True: the registry itself was asked and accepted the item. (An earlier instance could not
|
|
84
|
+
* be asked before the lead artist's first acceptance, and this was then false.)
|
|
85
|
+
*/
|
|
86
|
+
readonly checkedOnChain: boolean;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Checks a curated item before anyone signs for it. An item that breaks a rule is approved
|
|
90
|
+
* and accepted all the same and only refused when the sale starts, with no reason given; by
|
|
91
|
+
* then the first acceptance has stored each new party's profile for good.
|
|
92
|
+
*
|
|
93
|
+
* First the rules that need no chain, each named (`itemProblems`). Then the registry's own
|
|
94
|
+
* dry run, which runs every item check the start runs, with the same errors: the item rules,
|
|
95
|
+
* the party and payee rules, the license against the instance's CC0 text, and that the
|
|
96
|
+
* economics give usable terms. It answers before any party has accepted: a party without an
|
|
97
|
+
* account counts as the artist its first acceptance will make it.
|
|
98
|
+
*
|
|
99
|
+
* The dry run does not check that the root is approved, that every party has accepted, the
|
|
100
|
+
* item's proof (checked here), the media files, or whether the content was minted before
|
|
101
|
+
* (`readMintedToken` answers that): the start itself checks those.
|
|
102
|
+
*
|
|
103
|
+
* Contract: [`PackageRegistry.preview`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/curation/PackageRegistry.sol).
|
|
104
|
+
*
|
|
105
|
+
* @throws FlowError `INVALID_INPUT`, naming the broken rule or the registry's error.
|
|
106
|
+
*/
|
|
107
|
+
export declare function previewCuratedItem(client: Client, instance: StreamInstance, args: {
|
|
108
|
+
readonly packageRoot: Hex;
|
|
109
|
+
readonly item: PackageItem;
|
|
110
|
+
readonly proof: readonly Hex[];
|
|
111
|
+
}): Promise<ItemPreview>;
|
|
112
|
+
/** What a listing will record, for showing to the artist before they sign. */
|
|
113
|
+
export interface ListingPlan {
|
|
114
|
+
readonly token: Address;
|
|
115
|
+
/** `INDEPENDENT_FORM`: 0 a 1/1 contract, 1 an editions contract. */
|
|
116
|
+
readonly form: number;
|
|
117
|
+
/** The deployer that recorded the contract. */
|
|
118
|
+
readonly deployer: Address;
|
|
119
|
+
/** For an editions contract, its 1/1 contract; otherwise the zero address. */
|
|
120
|
+
readonly partner: Address;
|
|
121
|
+
/** The network's share of sales and royalties, out of 100,000: recorded at listing, only ever lowered. */
|
|
122
|
+
readonly feeShare: number;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* What listing `token` will record: which template deployed it, its partner, and the network
|
|
126
|
+
* share the listing fixes. Show `feeShare` to the artist: the consent they sign names it.
|
|
127
|
+
*
|
|
128
|
+
* Contract: [`IndependentStreamDeployer.deployed`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/independent/IndependentStreamDeployer.sol),
|
|
129
|
+
* [`IndependentStreamEditions6529.stream`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/independent/IndependentStreamEditions6529.sol),
|
|
130
|
+
* [`EconomicsResolver.economics`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/economics/EconomicsResolver.sol).
|
|
131
|
+
*/
|
|
132
|
+
export declare function readListingPlan(client: Client, instance: StreamInstance, token: Address): Promise<ListingPlan>;
|
|
133
|
+
/**
|
|
134
|
+
* Whether a file is registered in the content store.
|
|
135
|
+
*
|
|
136
|
+
* Contract: [`ContentStore.fileInfo`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/content/ContentStore.sol),
|
|
137
|
+
* which reverts for an unknown file.
|
|
138
|
+
*/
|
|
139
|
+
export declare function isFileRegistered(client: Client, instance: StreamInstance, fileId: Hex): Promise<boolean>;
|