@artblocks/abx-sdk 0.1.0-alpha.3 → 0.1.0-alpha.30
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 +11 -0
- package/README.md +130 -0
- package/dist/abi/generated.d.ts +8502 -129
- package/dist/abi/generated.d.ts.map +1 -1
- package/dist/abi/generated.js +40 -22
- package/dist/abi/generated.js.map +1 -1
- package/dist/abi/index.d.ts +2645 -168
- package/dist/abi/index.d.ts.map +1 -1
- package/dist/abi/index.js +34 -7
- package/dist/abi/index.js.map +1 -1
- package/dist/anchors.d.ts +318 -0
- package/dist/anchors.d.ts.map +1 -0
- package/dist/anchors.js +701 -0
- package/dist/anchors.js.map +1 -0
- package/dist/chains.d.ts +19 -9
- package/dist/chains.d.ts.map +1 -1
- package/dist/chains.js +31 -15
- package/dist/chains.js.map +1 -1
- package/dist/chunks.d.ts +67 -26
- package/dist/chunks.d.ts.map +1 -1
- package/dist/chunks.js +82 -9
- package/dist/chunks.js.map +1 -1
- package/dist/clients.d.ts +23 -11
- package/dist/clients.d.ts.map +1 -1
- package/dist/clients.js +17 -18
- package/dist/clients.js.map +1 -1
- package/dist/create2.d.ts +84 -1
- package/dist/create2.d.ts.map +1 -1
- package/dist/create2.js +158 -2
- package/dist/create2.js.map +1 -1
- package/dist/creator-token.d.ts +132 -0
- package/dist/creator-token.d.ts.map +1 -0
- package/dist/creator-token.js +183 -0
- package/dist/creator-token.js.map +1 -0
- package/dist/deploy.d.ts +234 -14
- package/dist/deploy.d.ts.map +1 -1
- package/dist/deploy.js +289 -111
- package/dist/deploy.js.map +1 -1
- package/dist/deployments.d.ts +70 -5
- package/dist/deployments.d.ts.map +1 -1
- package/dist/deployments.js +139 -30
- package/dist/deployments.js.map +1 -1
- package/dist/deps.d.ts +123 -6
- package/dist/deps.d.ts.map +1 -1
- package/dist/deps.js +249 -7
- package/dist/deps.js.map +1 -1
- package/dist/env.d.ts +5 -4
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +20 -5
- package/dist/env.js.map +1 -1
- package/dist/errors.d.ts +94 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +126 -0
- package/dist/errors.js.map +1 -0
- package/dist/execute.d.ts +118 -0
- package/dist/execute.d.ts.map +1 -0
- package/dist/execute.js +159 -0
- package/dist/execute.js.map +1 -0
- package/dist/gateways.d.ts +79 -0
- package/dist/gateways.d.ts.map +1 -0
- package/dist/gateways.js +156 -0
- package/dist/gateways.js.map +1 -0
- package/dist/generator-document.d.ts +57 -0
- package/dist/generator-document.d.ts.map +1 -0
- package/dist/generator-document.js +123 -0
- package/dist/generator-document.js.map +1 -0
- package/dist/generator.d.ts +44 -2
- package/dist/generator.d.ts.map +1 -1
- package/dist/generator.js +29 -0
- package/dist/generator.js.map +1 -1
- package/dist/index.d.ts +18 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -3
- package/dist/index.js.map +1 -1
- package/dist/inspect.d.ts +48 -0
- package/dist/inspect.d.ts.map +1 -0
- package/dist/inspect.js +295 -0
- package/dist/inspect.js.map +1 -0
- package/dist/migrate.d.ts +41 -0
- package/dist/migrate.d.ts.map +1 -0
- package/dist/migrate.js +142 -0
- package/dist/migrate.js.map +1 -0
- package/dist/mime.d.ts +11 -0
- package/dist/mime.d.ts.map +1 -0
- package/dist/mime.js +40 -0
- package/dist/mime.js.map +1 -0
- package/dist/node.d.ts +10 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +24 -0
- package/dist/node.js.map +1 -0
- package/dist/onchain-uri.d.ts +110 -0
- package/dist/onchain-uri.d.ts.map +1 -0
- package/dist/onchain-uri.js +276 -0
- package/dist/onchain-uri.js.map +1 -0
- package/dist/ops.d.ts +507 -14
- package/dist/ops.d.ts.map +1 -1
- package/dist/ops.js +850 -34
- package/dist/ops.js.map +1 -1
- package/dist/policy.d.ts +57 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +35 -0
- package/dist/policy.js.map +1 -0
- package/dist/probe.d.ts +58 -0
- package/dist/probe.d.ts.map +1 -1
- package/dist/probe.js +190 -9
- package/dist/probe.js.map +1 -1
- package/dist/reconstruct.d.ts +114 -2
- package/dist/reconstruct.d.ts.map +1 -1
- package/dist/reconstruct.js +443 -98
- package/dist/reconstruct.js.map +1 -1
- package/dist/resume.d.ts +96 -0
- package/dist/resume.d.ts.map +1 -0
- package/dist/resume.js +95 -0
- package/dist/resume.js.map +1 -0
- package/dist/script-chunks.d.ts +24 -0
- package/dist/script-chunks.d.ts.map +1 -0
- package/dist/script-chunks.js +63 -0
- package/dist/script-chunks.js.map +1 -0
- package/dist/service.d.ts +151 -9
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +103 -11
- package/dist/service.js.map +1 -1
- package/dist/spine.d.ts +47 -4
- package/dist/spine.d.ts.map +1 -1
- package/dist/spine.js +0 -0
- package/dist/spine.js.map +1 -1
- package/dist/staging.d.ts +139 -0
- package/dist/staging.d.ts.map +1 -0
- package/dist/staging.js +139 -0
- package/dist/staging.js.map +1 -0
- package/dist/token.d.ts +1 -1
- package/dist/token.js +1 -1
- package/dist/tokendata.d.ts +63 -3
- package/dist/tokendata.d.ts.map +1 -1
- package/dist/tokendata.js +81 -19
- package/dist/tokendata.js.map +1 -1
- package/dist/tokens.d.ts +119 -0
- package/dist/tokens.d.ts.map +1 -0
- package/dist/tokens.js +317 -0
- package/dist/tokens.js.map +1 -0
- package/dist/types.d.ts +107 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/util.d.ts +74 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +106 -0
- package/dist/util.js.map +1 -0
- package/package.json +15 -6
package/dist/reconstruct.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { concat as concatHex, keccak256, parseEventLogs, } from 'viem';
|
|
2
|
-
import { oneOfOneImageAbi, oneOfOneImageFactoryAbi, seriesCodeAbi, spineEventAbi } from './abi/index.js';
|
|
2
|
+
import { oneOfOneEditionAbi, oneOfOneImageAbi, oneOfOneImageFactoryAbi, seriesCodeAbi, spineEventAbi } from './abi/index.js';
|
|
3
3
|
import { AUTH_OPTIONS, decodeTag, DELEGATE_REGISTRY_DEFAULT, extensionName, EXTENSION_ID, PARAM_TYPES, SPINE_EVENT_DOC, } from './spine.js';
|
|
4
|
+
import { AbxSdkError } from './errors.js';
|
|
5
|
+
import { readEnv } from './util.js';
|
|
4
6
|
/**
|
|
5
7
|
* Rebuild a project's full state from the chain alone — the canonical replay.
|
|
6
8
|
*
|
|
@@ -13,9 +15,13 @@ import { AUTH_OPTIONS, decodeTag, DELEGATE_REGISTRY_DEFAULT, extensionName, EXTE
|
|
|
13
15
|
export async function reconstructProject(client, opts) {
|
|
14
16
|
const { address, fromBlock, factory } = opts;
|
|
15
17
|
const toBlockNum = opts.toBlock === 'latest' || opts.toBlock === undefined ? await client.getBlockNumber() : opts.toBlock;
|
|
16
|
-
const rawLogs = await getLogsAdaptive(client, address, fromBlock, toBlockNum
|
|
18
|
+
const rawLogs = await getLogsAdaptive(client, address, fromBlock, toBlockNum, {
|
|
19
|
+
maxChunks: opts.maxChunks,
|
|
20
|
+
range: opts.getLogsRange,
|
|
21
|
+
onChunk: opts.onChunk,
|
|
22
|
+
});
|
|
17
23
|
const events = decodedToSpineEvents(parseEventLogs({ abi: spineEventAbi, logs: rawLogs })).sort(byOrder);
|
|
18
|
-
return assembleState(client, address, events, foldSpine(events), fromBlock, toBlockNum, factory);
|
|
24
|
+
return assembleState(client, address, events, foldSpine(events), fromBlock, toBlockNum, factory, !!opts.readUriDocuments);
|
|
19
25
|
}
|
|
20
26
|
/**
|
|
21
27
|
* The same state, but resumed from a prior reconstruction's checkpoint — so a
|
|
@@ -33,11 +39,30 @@ export async function reconstructIncremental(client, prior, opts = {}) {
|
|
|
33
39
|
const priorTo = BigInt(prior.toBlock);
|
|
34
40
|
const origin = BigInt(prior.deployBlock ?? prior.fromBlock);
|
|
35
41
|
const resumeFrom = priorTo + 1n > origin ? priorTo + 1n : origin;
|
|
36
|
-
let
|
|
42
|
+
let rawLogs = [];
|
|
37
43
|
if (head >= resumeFrom) {
|
|
38
|
-
|
|
39
|
-
|
|
44
|
+
rawLogs = await getLogsAdaptive(client, address, resumeFrom, head, {
|
|
45
|
+
maxChunks: opts.maxChunks,
|
|
46
|
+
range: opts.getLogsRange,
|
|
47
|
+
onChunk: opts.onChunk,
|
|
48
|
+
});
|
|
40
49
|
}
|
|
50
|
+
const toBlock = head >= priorTo ? head : priorTo;
|
|
51
|
+
return reconstructFromLogs(client, prior, rawLogs, { factory, readUriDocuments: opts.readUriDocuments, toBlock });
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The fold / head-read half of {@link reconstructIncremental}, given logs the caller already
|
|
55
|
+
* fetched. A multi-address watch loop (`getLogs({address: Address[]})`) holds each touched
|
|
56
|
+
* project's delta; this consumes it so that loop is the only `eth_getLogs`. Folding stays here.
|
|
57
|
+
*
|
|
58
|
+
* `toBlock` is the inclusive scan head those logs cover — required even when `logs` is empty,
|
|
59
|
+
* so a quiet window still advances the checkpoint to the range the caller scanned, and so a
|
|
60
|
+
* caller that scanned a capped window (not chain head) cannot stamp `toBlock` past the last
|
|
61
|
+
* log they actually held.
|
|
62
|
+
*/
|
|
63
|
+
export async function reconstructFromLogs(client, prior, logs, opts) {
|
|
64
|
+
const factory = opts.factory ?? prior.factory ?? undefined;
|
|
65
|
+
const fresh = decodedToSpineEvents(parseEventLogs({ abi: spineEventAbi, logs: logs }));
|
|
41
66
|
// Merge the prior log with the freshly-fetched tail, de-duping by position so an
|
|
42
67
|
// overlapping/duplicate re-run can't double-count, then fold the complete spine.
|
|
43
68
|
const seen = new Set();
|
|
@@ -50,8 +75,13 @@ export async function reconstructIncremental(client, prior, opts = {}) {
|
|
|
50
75
|
all.push(ev);
|
|
51
76
|
}
|
|
52
77
|
all.sort(byOrder);
|
|
53
|
-
|
|
54
|
-
|
|
78
|
+
// Chunk content has no log (too large); `ScriptUpdated` is the ping. A Transfer currently
|
|
79
|
+
// used to re-download every chunk. Keep the prior digest unless that ping is in `fresh`.
|
|
80
|
+
const scriptTouched = fresh.some((e) => e.name === 'ScriptUpdated');
|
|
81
|
+
const reuseScript = !scriptTouched && prior.script?.digest != null ? prior.script : undefined;
|
|
82
|
+
const priorTo = BigInt(prior.toBlock);
|
|
83
|
+
const toBlock = opts.toBlock >= priorTo ? opts.toBlock : priorTo;
|
|
84
|
+
return assembleState(client, prior.address, all, foldSpine(all), BigInt(prior.fromBlock), toBlock, factory, !!opts.readUriDocuments, reuseScript);
|
|
55
85
|
}
|
|
56
86
|
/** Turn decoded viem logs into the canonical, serializable {@link SpineEvent} list. */
|
|
57
87
|
function decodedToSpineEvents(decoded) {
|
|
@@ -73,11 +103,60 @@ function decodedToSpineEvents(decoded) {
|
|
|
73
103
|
function tokenIn(tokens, id) {
|
|
74
104
|
let t = tokens.get(id);
|
|
75
105
|
if (!t) {
|
|
76
|
-
t = { tokenId: id,
|
|
106
|
+
t = { tokenId: id, lifecycle: 'unminted', owner: null, tokenURI: null, fields: [], lockedFields: [] };
|
|
77
107
|
tokens.set(id, t);
|
|
78
108
|
}
|
|
79
109
|
return t;
|
|
80
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Fold one ERC-1155 transfer leg (a `TransferSingle`, or one element of a `TransferBatch`) into
|
|
113
|
+
* an id's per-id supply counter + holder balances. Mint = `from` the zero address (supply +=
|
|
114
|
+
* amount); burn = `to` the zero address (supply -= amount); a transfer between two live holders
|
|
115
|
+
* touches no supply, only balances — mirrors `AbxErc1155Base._afterTokenTransfer`'s own
|
|
116
|
+
* if/else-if exactly.
|
|
117
|
+
*
|
|
118
|
+
* {@link TokenState.lifecycle} is recomputed from the counter on every leg, never latched: an
|
|
119
|
+
* edition id can return to zero supply (a full burn) and mint again. `supply > 0` ⇒ `'live'`;
|
|
120
|
+
* back to zero having once been issued ⇒ `'burned'`; never issued ⇒ `'unminted'`. Same three words
|
|
121
|
+
* the 721 lane uses, which is the point — one vocabulary, whichever standard produced it.
|
|
122
|
+
*/
|
|
123
|
+
function applyEditionTransfer(tokens, id, from, to, amount) {
|
|
124
|
+
const t = tokenIn(tokens, id);
|
|
125
|
+
if (isZeroAddr(from))
|
|
126
|
+
t.supply = (BigInt(t.supply ?? '0') + amount).toString();
|
|
127
|
+
else if (isZeroAddr(to))
|
|
128
|
+
t.supply = (BigInt(t.supply ?? '0') - amount).toString();
|
|
129
|
+
// Zero live copies — and on this standard that is NOT `'burned'`, which is reserved for the
|
|
130
|
+
// terminal 721 case. An edition id at zero can mint again, whether it was never minted or fully
|
|
131
|
+
// burned, so the two have no different consequence for anything downstream and share one word.
|
|
132
|
+
// The alternative shipped for about an hour: `'burned'` on both standards, which put every
|
|
133
|
+
// consumer one forgotten `contractType` branch away from answering `410 Gone` for an id the
|
|
134
|
+
// contract still resolves and can reissue. See {@link TokenState.lifecycle}.
|
|
135
|
+
//
|
|
136
|
+
// Note this deliberately does NOT use the fold's extra knowledge (it could distinguish
|
|
137
|
+
// never-minted from fully-burned; the head-read lane cannot). Spending it here would make the two
|
|
138
|
+
// lanes disagree on the same id under one field name — the sibling-drift class — to express a
|
|
139
|
+
// distinction with no consumer. The history stays in `supply`, `holders`, and the log.
|
|
140
|
+
t.lifecycle = BigInt(t.supply ?? '0') > 0n ? 'live' : 'no-live-copies';
|
|
141
|
+
adjustHolderBalance(t, from, -amount);
|
|
142
|
+
adjustHolderBalance(t, to, amount);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Adjust one token's per-holder balance by `delta`. The zero address is never a real holder
|
|
146
|
+
* (a mint's `from` / a burn's `to`) and is skipped. A balance that reaches zero is deleted
|
|
147
|
+
* rather than kept at `"0"` — {@link TokenState.holders} lists only CURRENT holders.
|
|
148
|
+
*/
|
|
149
|
+
function adjustHolderBalance(t, addr, delta) {
|
|
150
|
+
if (isZeroAddr(addr) || delta === 0n)
|
|
151
|
+
return;
|
|
152
|
+
if (!t.holders)
|
|
153
|
+
t.holders = {};
|
|
154
|
+
const bal = BigInt(t.holders[addr] ?? '0') + delta;
|
|
155
|
+
if (bal <= 0n)
|
|
156
|
+
delete t.holders[addr];
|
|
157
|
+
else
|
|
158
|
+
t.holders[addr] = bal.toString();
|
|
159
|
+
}
|
|
81
160
|
const isZeroAddr = (v) => {
|
|
82
161
|
try {
|
|
83
162
|
return BigInt(v ?? '0') === 0n;
|
|
@@ -99,6 +178,8 @@ export function foldSpine(events) {
|
|
|
99
178
|
deployTx: null,
|
|
100
179
|
owner: null,
|
|
101
180
|
royalty: null,
|
|
181
|
+
maxRoyaltyBps: null,
|
|
182
|
+
burnable: null,
|
|
102
183
|
extById: new Map(),
|
|
103
184
|
tokens: new Map(),
|
|
104
185
|
tokenFields: new Map(),
|
|
@@ -106,6 +187,7 @@ export function foldSpine(events) {
|
|
|
106
187
|
collectionFields: new Map(),
|
|
107
188
|
collectionLocked: new Set(),
|
|
108
189
|
maxInvocations: null,
|
|
190
|
+
defaultMaxSupply: null,
|
|
109
191
|
minter: null,
|
|
110
192
|
paused: false,
|
|
111
193
|
primaryPayee: null,
|
|
@@ -113,6 +195,7 @@ export function foldSpine(events) {
|
|
|
113
195
|
contractParams: new Map(),
|
|
114
196
|
paramSchemas: new Map(),
|
|
115
197
|
paramHooks: null,
|
|
198
|
+
paramHooksFrozen: false,
|
|
116
199
|
delegateRegistry: undefined,
|
|
117
200
|
seedSource: null,
|
|
118
201
|
scriptLocked: false,
|
|
@@ -142,16 +225,74 @@ export function foldSpine(events) {
|
|
|
142
225
|
fold.royalty = isZeroAddr(receiver) && bps === 0 ? null : { receiver, bps };
|
|
143
226
|
break;
|
|
144
227
|
}
|
|
228
|
+
// The two collection-policy events. Both are Register 2 facts a buyer prices in, and both
|
|
229
|
+
// fold — being in `SPINE_EVENT_DOC` only supplies the `register`/`what` strings on the event
|
|
230
|
+
// record; it has never made anything land in state. The guard in `spine-fold-coverage.test.ts`
|
|
231
|
+
// fails if a `folds: 'state'` event has no
|
|
232
|
+
// case here.)
|
|
233
|
+
case 'MaxRoyaltyBpsUpdated':
|
|
234
|
+
// Last-writer-wins: the deploy-time ceiling, then any `reduceMaxRoyaltyBps`.
|
|
235
|
+
fold.maxRoyaltyBps = Number(a.maxBps ?? 0);
|
|
236
|
+
break;
|
|
237
|
+
case 'BurnConfigured':
|
|
238
|
+
// Emitted once at initialize and fixed thereafter; still last-writer-wins for the same
|
|
239
|
+
// reason every other fold is — a re-fold of an overlapping range must be idempotent.
|
|
240
|
+
fold.burnable = String(a.burnable) === 'true';
|
|
241
|
+
break;
|
|
145
242
|
case 'OwnershipTransferred':
|
|
146
243
|
fold.owner = a.newOwner;
|
|
147
244
|
break;
|
|
148
245
|
case 'Transfer': {
|
|
149
246
|
const t = tokenIn(fold.tokens, String(a.tokenId ?? a.id ?? '0'));
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
247
|
+
// `to == 0x0` is a BURN and nothing else: Solady's `transferFrom` reverts on a zero
|
|
248
|
+
// recipient, so the only path that emits it is `_burn` (the token's own `burn(id)`, gated
|
|
249
|
+
// on the collection having opted in). So the leg is unambiguous, and it is the whole
|
|
250
|
+
// reason this case cannot just write `a.to` into `owner` — that put the zero address in a
|
|
251
|
+
// field every consumer reads as a holder, and left `minted` latched `true` forever.
|
|
252
|
+
// `'burned'` is TERMINAL on this standard, and that is a fact about ABX's mint paths rather
|
|
253
|
+
// than about ERC-721: ids come from a monotonic `nextTokenId`, so no entrypoint can reissue
|
|
254
|
+
// a destroyed id. The branch below would still return such an id to `'live'` if a log ever
|
|
255
|
+
// showed a re-mint — the fold owes the log's meaning, not our mint policy's — but no ABX
|
|
256
|
+
// deployment can produce that log, which is what makes the word safe to act on irreversibly.
|
|
257
|
+
if (isZeroAddr(a.to)) {
|
|
258
|
+
t.lifecycle = 'burned';
|
|
259
|
+
t.owner = null;
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
t.lifecycle = 'live';
|
|
263
|
+
t.owner = a.to;
|
|
264
|
+
}
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
case 'TransferSingle': {
|
|
268
|
+
applyEditionTransfer(fold.tokens, String(a.id ?? '0'), a.from, a.to, BigInt(a.amount ?? '0'));
|
|
153
269
|
break;
|
|
154
270
|
}
|
|
271
|
+
case 'TransferBatch': {
|
|
272
|
+
const ids = parseStringArray(a.ids);
|
|
273
|
+
const amounts = parseStringArray(a.amounts);
|
|
274
|
+
const from = a.from;
|
|
275
|
+
const to = a.to;
|
|
276
|
+
for (let i = 0; i < ids.length; i++) {
|
|
277
|
+
applyEditionTransfer(fold.tokens, ids[i], from, to, BigInt(amounts[i] ?? '0'));
|
|
278
|
+
}
|
|
279
|
+
break;
|
|
280
|
+
}
|
|
281
|
+
case 'MaxSupplyUpdated': {
|
|
282
|
+
const t = tokenIn(fold.tokens, String(a.id ?? '0'));
|
|
283
|
+
t.maxSupply = String(a.cap ?? '0');
|
|
284
|
+
// An override latches: it is what makes a `'0'` cap "closed forever" rather than "open",
|
|
285
|
+
// and what puts the monotonic never-increase rule in force for this id.
|
|
286
|
+
t.maxSupplyOverridden = true;
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
// The collection-wide default, announced once at `initialize`. Last-writer-wins for the same
|
|
290
|
+
// reason as every other Register 2 setter, even though only one is emitted today. Without
|
|
291
|
+
// this case the event reached the ABI and stopped there: an id inheriting a non-zero default
|
|
292
|
+
// has no `MaxSupplyUpdated` of its own, so the fold reported it uncapped.
|
|
293
|
+
case 'DefaultMaxSupplySet':
|
|
294
|
+
fold.defaultMaxSupply = String(a.cap ?? '0');
|
|
295
|
+
break;
|
|
155
296
|
case 'TokenFieldSet': {
|
|
156
297
|
const id = String(a.tokenId ?? '0');
|
|
157
298
|
const field = decodeTag((a.field ?? '0x'));
|
|
@@ -242,6 +383,7 @@ export function foldSpine(events) {
|
|
|
242
383
|
configureHook: z(a.configureHook),
|
|
243
384
|
augmentHook: z(a.augmentHook),
|
|
244
385
|
transferHook: z(a.transferHook),
|
|
386
|
+
locked: false, // resolved from `paramHooksFrozen` at assembly — order-independent
|
|
245
387
|
};
|
|
246
388
|
break;
|
|
247
389
|
}
|
|
@@ -254,6 +396,11 @@ export function foldSpine(events) {
|
|
|
254
396
|
case 'ScriptLocked':
|
|
255
397
|
fold.scriptLocked = true;
|
|
256
398
|
break;
|
|
399
|
+
// A one-way lock like ScriptLocked/DependenciesLocked, and the one a BUYER cares about: after
|
|
400
|
+
// this the transfer hook (which can veto a transfer or a mint) can never be re-pointed.
|
|
401
|
+
case 'ParamHooksFrozen':
|
|
402
|
+
fold.paramHooksFrozen = true;
|
|
403
|
+
break;
|
|
257
404
|
case 'DependencyUpdated': {
|
|
258
405
|
const idx = Number(a.index ?? 0);
|
|
259
406
|
const raw = (a.ref ?? '0x');
|
|
@@ -285,7 +432,7 @@ export function foldSpine(events) {
|
|
|
285
432
|
return fold;
|
|
286
433
|
}
|
|
287
434
|
/** Build the full {@link ProjectState} from a fold + provenance, then overlay head reads. */
|
|
288
|
-
async function assembleState(client, address, events, fold, fromBlock, toBlock, factory) {
|
|
435
|
+
async function assembleState(client, address, events, fold, fromBlock, toBlock, factory, readUriDocuments = false, reuseScript) {
|
|
289
436
|
// ensure a TokenState exists for every token referenced by on-chain fields/locks/params
|
|
290
437
|
// (a deployed-but-unminted token can carry fields before any Transfer)
|
|
291
438
|
for (const id of fold.tokenFields.keys())
|
|
@@ -307,7 +454,9 @@ async function assembleState(client, address, events, fold, fromBlock, toBlock,
|
|
|
307
454
|
t.params = [...params.values()];
|
|
308
455
|
}
|
|
309
456
|
// A contract is a Series if it enabled the supply-cap extension; a Series that also
|
|
310
|
-
// speaks Params is a code project (SeriesCode's composition).
|
|
457
|
+
// speaks Params is a code project (SeriesCode's composition). `maxInvocations` is shared,
|
|
458
|
+
// unchanged, with the ERC-1155 editions family (EditionImage/EditionCode compose it too), so
|
|
459
|
+
// `isSeries` alone doesn't distinguish 721 from 1155 — `hasEditionSupply` does that.
|
|
311
460
|
const isSeries = fold.extById.has(EXTENSION_ID.maxInvocations.toLowerCase());
|
|
312
461
|
const has = (id) => fold.extById.has(id.toLowerCase());
|
|
313
462
|
const hasParams = has(EXTENSION_ID.params);
|
|
@@ -315,6 +464,22 @@ async function assembleState(client, address, events, fold, fromBlock, toBlock,
|
|
|
315
464
|
const hasScript = has(EXTENSION_ID.onChainScript);
|
|
316
465
|
const hasDependencies = has(EXTENSION_ID.dependencies);
|
|
317
466
|
const hasSeedSource = has(EXTENSION_ID.seedSource);
|
|
467
|
+
// Edition Supply is the ONLY extension id new to the 1155 family — its presence is the
|
|
468
|
+
// discriminator between the 721 ladder (1of1/series/code) and the 1155 one
|
|
469
|
+
// (1of1-edition/edition/edition-code); every other extension id is shared, unchanged.
|
|
470
|
+
const hasEditionSupply = has(EXTENSION_ID.editionSupply);
|
|
471
|
+
// The collection-wide per-id default, behind the same gate as every other extension-scoped field
|
|
472
|
+
// (one gate, read twice: here and on `state.defaultMaxSupply` below).
|
|
473
|
+
const defaultCap = hasEditionSupply ? fold.defaultMaxSupply : null;
|
|
474
|
+
// An id with no `MaxSupplyUpdated` of its own inherits that default, exactly as `maxSupply(id)`
|
|
475
|
+
// does on chain. The fold used to stop at the per-id event, so every `--copies N` edition — which
|
|
476
|
+
// sets the cap at `initialize` and never calls `setMaxSupply` — reported *uncapped* here while the
|
|
477
|
+
// head read said N. See {@link TokenState.maxSupply}.
|
|
478
|
+
if (defaultCap !== null) {
|
|
479
|
+
for (const t of fold.tokens.values())
|
|
480
|
+
if (t.maxSupply === undefined)
|
|
481
|
+
t.maxSupply = defaultCap;
|
|
482
|
+
}
|
|
318
483
|
const state = {
|
|
319
484
|
address,
|
|
320
485
|
chainId: client.chain?.id ?? 0,
|
|
@@ -333,17 +498,31 @@ async function assembleState(client, address, events, fold, fromBlock, toBlock,
|
|
|
333
498
|
contractURIRenderer: null,
|
|
334
499
|
contractURILocked: null,
|
|
335
500
|
royalty: fold.royalty,
|
|
501
|
+
// Both tri-state and both folded, never defaulted: `null` says the spine did not state it (an
|
|
502
|
+
// implementation from before the opt-in), which is not the same fact as `false` / a 10% ceiling.
|
|
503
|
+
maxRoyaltyBps: fold.maxRoyaltyBps,
|
|
504
|
+
burnable: fold.burnable,
|
|
336
505
|
collectionFields: [...fold.collectionFields.values()],
|
|
337
506
|
lockedCollectionFields: [...fold.collectionLocked],
|
|
338
|
-
contractType: fold.deployBlock
|
|
507
|
+
contractType: fold.deployBlock === null
|
|
508
|
+
? undefined
|
|
509
|
+
: hasEditionSupply
|
|
510
|
+
? hasParams ? 'edition-code' : isSeries ? 'edition' : '1of1-edition'
|
|
511
|
+
: isSeries ? (hasParams ? 'code' : 'series') : '1of1',
|
|
339
512
|
maxInvocations: fold.maxInvocations,
|
|
513
|
+
defaultMaxSupply: defaultCap,
|
|
340
514
|
minter: fold.minter,
|
|
341
515
|
paused: fold.paused,
|
|
342
516
|
primaryPayee: fold.primaryPayee,
|
|
343
517
|
contractParams: hasParams ? [...fold.contractParams.values()] : undefined,
|
|
344
518
|
paramSchemas: hasConfigurableParams ? [...fold.paramSchemas.values()] : undefined,
|
|
345
519
|
paramHooks: hasConfigurableParams
|
|
346
|
-
?
|
|
520
|
+
? {
|
|
521
|
+
...(fold.paramHooks ?? { configureHook: null, augmentHook: null, transferHook: null }),
|
|
522
|
+
// Read off the separate fold flag rather than the HooksConfigured branch, so a freeze
|
|
523
|
+
// survives regardless of event order (a project may freeze hooks it never set).
|
|
524
|
+
locked: fold.paramHooksFrozen,
|
|
525
|
+
}
|
|
347
526
|
: null,
|
|
348
527
|
// absence of the event ⇒ the canonical delegate.xyz default (the emit-non-default rule)
|
|
349
528
|
delegateRegistry: hasConfigurableParams
|
|
@@ -369,13 +548,16 @@ async function assembleState(client, address, events, fold, fromBlock, toBlock,
|
|
|
369
548
|
reconstructedAt: new Date().toISOString(),
|
|
370
549
|
rpcUrl: client.transport?.url,
|
|
371
550
|
};
|
|
372
|
-
await applyHeadReads(client, state, factory);
|
|
551
|
+
await applyHeadReads(client, state, factory, readUriDocuments, reuseScript);
|
|
373
552
|
return state;
|
|
374
553
|
}
|
|
375
|
-
/** Default safety cap on chunk count; raise via
|
|
554
|
+
/** Default safety cap on chunk count; raise via the `maxChunks` opt (or ABX_GETLOGS_MAX_CHUNKS —
|
|
555
|
+
* the CLI's --yes sets that). */
|
|
376
556
|
const DEFAULT_MAX_CHUNKS = 3000;
|
|
377
|
-
function
|
|
378
|
-
|
|
557
|
+
function resolveMaxChunks(override) {
|
|
558
|
+
if (override !== undefined && override > 0)
|
|
559
|
+
return override;
|
|
560
|
+
const v = Number(readEnv('ABX_GETLOGS_MAX_CHUNKS'));
|
|
379
561
|
return Number.isFinite(v) && v > 0 ? v : DEFAULT_MAX_CHUNKS;
|
|
380
562
|
}
|
|
381
563
|
/** Does this error look like an RPC rejecting the block range (vs a real failure)? */
|
|
@@ -384,7 +566,7 @@ export function isGetLogsRangeError(err) {
|
|
|
384
566
|
return /block range|range should work|too large|out of bounds|response size|query returned more|results|limited|\d+\s*block|exceeds|max(imum)?\b/.test(m);
|
|
385
567
|
}
|
|
386
568
|
/** Thrown when a reconstruction would need more getLogs requests than the cap allows. */
|
|
387
|
-
export class GetLogsScanTooLargeError extends
|
|
569
|
+
export class GetLogsScanTooLargeError extends AbxSdkError {
|
|
388
570
|
spanBlocks;
|
|
389
571
|
window;
|
|
390
572
|
estimatedRequests;
|
|
@@ -392,7 +574,7 @@ export class GetLogsScanTooLargeError extends Error {
|
|
|
392
574
|
constructor(spanBlocks, window, estimatedRequests, cap) {
|
|
393
575
|
super(`Reconstructing ${spanBlocks} blocks needs ~${estimatedRequests} eth_getLogs requests at this RPC's range limit ` +
|
|
394
576
|
`(~${window} blocks/call) — over the ${cap}-request safety cap. A higher-range RPC is the real fix ` +
|
|
395
|
-
`(set
|
|
577
|
+
`(set ABX_RPC_URLS, then re-check with \`abx doctor\`). To chunk through it anyway, raise ABX_GETLOGS_MAX_CHUNKS (the CLI's --yes does this).`);
|
|
396
578
|
this.spanBlocks = spanBlocks;
|
|
397
579
|
this.window = window;
|
|
398
580
|
this.estimatedRequests = estimatedRequests;
|
|
@@ -439,121 +621,284 @@ export async function discoverDeployBlock(client, address, toBlock) {
|
|
|
439
621
|
}
|
|
440
622
|
}
|
|
441
623
|
/**
|
|
442
|
-
*
|
|
443
|
-
*
|
|
444
|
-
*
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
*
|
|
624
|
+
* Ordinary RPC tiers cap how many addresses one `eth_getLogs` filter may carry.
|
|
625
|
+
* This is an RPC-tier opinion, not a protocol constant — callers with a dedicated
|
|
626
|
+
* node can raise it; `0` disables splitting (one filter for the whole list).
|
|
627
|
+
*/
|
|
628
|
+
export const DEFAULT_GETLOGS_ADDRESS_BATCH = 1000;
|
|
629
|
+
/**
|
|
630
|
+
* Pull logs over a block range, adapting to RPC range caps — and, when `address` is
|
|
631
|
+
* a list, splitting that list so a registered-set watch scan stays one code path for
|
|
632
|
+
* self-host and hosted. Providers cap `eth_getLogs` very differently and the numbers
|
|
633
|
+
* change, so we don't hard-code a window: try the whole range, and when the RPC
|
|
634
|
+
* rejects it, halve the window and sweep. `ABX_GETLOGS_RANGE` overrides the starting
|
|
635
|
+
* window. Address-list chunking is a separate cap (`addressBatch`); 5000-block
|
|
636
|
+
* per-tick windows belong to the caller (the watcher), not here.
|
|
449
637
|
*
|
|
450
638
|
* Once the working window is known we estimate the whole job *before* grinding it: if
|
|
451
639
|
* it would exceed the cap, we stop early (only the probe calls spent) and throw
|
|
452
640
|
* {@link GetLogsScanTooLargeError} so the caller can offer the real fix (a higher-range
|
|
453
641
|
* RPC) or an explicit opt-in to chunk through it.
|
|
454
642
|
*/
|
|
455
|
-
async function getLogsAdaptive(client, address, fromBlock, toBlock) {
|
|
643
|
+
export async function getLogsAdaptive(client, address, fromBlock, toBlock, opts = {}) {
|
|
644
|
+
const addrs = (Array.isArray(address) ? address : [address]);
|
|
645
|
+
if (addrs.length === 0)
|
|
646
|
+
return [];
|
|
647
|
+
const batchSize = opts.addressBatch === 0 ? addrs.length : Math.max(1, opts.addressBatch ?? DEFAULT_GETLOGS_ADDRESS_BATCH);
|
|
648
|
+
const batches = [];
|
|
649
|
+
for (let i = 0; i < addrs.length; i += batchSize)
|
|
650
|
+
batches.push(addrs.slice(i, i + batchSize));
|
|
456
651
|
const span = toBlock - fromBlock + 1n;
|
|
457
|
-
const envRange =
|
|
458
|
-
|
|
652
|
+
const envRange = readEnv('ABX_GETLOGS_RANGE');
|
|
653
|
+
const startWindow = opts.range && opts.range > 0n ? opts.range : envRange && BigInt(envRange) > 0n ? BigInt(envRange) : span;
|
|
459
654
|
const out = [];
|
|
460
|
-
let start = fromBlock;
|
|
461
655
|
let estimated = false;
|
|
462
|
-
|
|
463
|
-
const
|
|
464
|
-
let
|
|
656
|
+
for (const [batchIndex, batch] of batches.entries()) {
|
|
657
|
+
const filter = batch.length === 1 ? batch[0] : batch;
|
|
658
|
+
let window = startWindow;
|
|
659
|
+
let start = fromBlock;
|
|
660
|
+
while (start <= toBlock) {
|
|
661
|
+
const end = start + window - 1n < toBlock ? start + window - 1n : toBlock;
|
|
662
|
+
let logs;
|
|
663
|
+
try {
|
|
664
|
+
logs = (await client.getLogs({ address: filter, fromBlock: start, toBlock: end }));
|
|
665
|
+
}
|
|
666
|
+
catch (err) {
|
|
667
|
+
if (isGetLogsRangeError(err) && window > 1n) {
|
|
668
|
+
window = window > 2n ? window / 2n : 1n; // RPC rejected this window — shrink and retry
|
|
669
|
+
continue;
|
|
670
|
+
}
|
|
671
|
+
throw err; // genuine failure, or already at one block per call
|
|
672
|
+
}
|
|
673
|
+
out.push(...logs);
|
|
674
|
+
start = end + 1n;
|
|
675
|
+
const scannedBlocks = start - fromBlock;
|
|
676
|
+
opts.onChunk?.({
|
|
677
|
+
scanned: BigInt(batchIndex) * span + scannedBlocks,
|
|
678
|
+
span: span * BigInt(batches.length),
|
|
679
|
+
scannedBlocks,
|
|
680
|
+
blockSpan: span,
|
|
681
|
+
addressBatch: batchIndex,
|
|
682
|
+
addressBatches: batches.length,
|
|
683
|
+
});
|
|
684
|
+
// Window now proven. Estimate the whole job once (range chunks × address batches)
|
|
685
|
+
// and bail *before* grinding if absurd.
|
|
686
|
+
if (!estimated) {
|
|
687
|
+
estimated = true;
|
|
688
|
+
const remaining = toBlock - start + 1n;
|
|
689
|
+
const perBatch = (remaining > 0n ? Number(remaining / window) + 1 : 0) + 1; // +1 for the chunk just done
|
|
690
|
+
const need = perBatch * batches.length;
|
|
691
|
+
const cap = resolveMaxChunks(opts.maxChunks);
|
|
692
|
+
if (need > cap)
|
|
693
|
+
throw new GetLogsScanTooLargeError(span, window, need, cap);
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
return out;
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* How many unbounded reads (`tokenURI`, `contractURI`, a script chunk) ride one aggregate. Small on
|
|
701
|
+
* purpose: on the on-chain lane each of these can return tens of KB *assembled at read*, and the
|
|
702
|
+
* cap that matters is the node's per-`eth_call` budget for the aggregate, not the leg count. A
|
|
703
|
+
* whole-chunk failure still recovers via the per-leg retry below, so this only sets how often that
|
|
704
|
+
* costs an extra round trip.
|
|
705
|
+
*/
|
|
706
|
+
const HEAVY_READ_CHUNK = 2;
|
|
707
|
+
/**
|
|
708
|
+
* Multicall in chunks, tolerating per-leg failure — and, when a whole chunk comes back failed,
|
|
709
|
+
* retrying its legs individually before believing it.
|
|
710
|
+
*
|
|
711
|
+
* The retry is the point, and it exists to tell apart two failure modes that an aggregate throwing
|
|
712
|
+
* cannot distinguish on its own:
|
|
713
|
+
*
|
|
714
|
+
* 1. **Over budget.** `allowFailure: true` reports per-leg failures, but a multicall is ONE
|
|
715
|
+
* `eth_call`: if the aggregate exceeds the node's gas or response cap, the *whole* batch fails
|
|
716
|
+
* and every leg in it reports failure — including legs that answer fine on their own. Batching a
|
|
717
|
+
* cheap read beside an expensive one therefore turns the expensive one's cost into the cheap
|
|
718
|
+
* one's failure. Re-asking each leg alone, with no aggregate overhead, recovers this: the calls
|
|
719
|
+
* were always fine, only their batching was too big.
|
|
720
|
+
* 2. **No multicall3 on this chain.** If the aggregate fails because there's no multicall3
|
|
721
|
+
* deployment to call at all, *every* multicall — including a single-leg one — fails the identical
|
|
722
|
+
* way. Re-asking through `client.multicall` again, at any width, reproduces the same failure, so
|
|
723
|
+
* the retry must go through a call shape that has no multicall3 dependency: `client.readContract`.
|
|
724
|
+
* Skipping this means a chain lacking multicall3 reads back as "the contract answered nothing" —
|
|
725
|
+
* indistinguishable from a real revert — which is exactly the silent-blank-identity bug this
|
|
726
|
+
* retry was reported to have.
|
|
727
|
+
*
|
|
728
|
+
* So the fallback always resolves each leg with `readContract`, never with a smaller `multicall`.
|
|
729
|
+
* `readContract` throws on revert where multicall's `allowFailure` returns a `status: 'failure'`
|
|
730
|
+
* result instead, so a per-leg throw here is caught and mapped back to `null` — a genuine revert on
|
|
731
|
+
* one leg must still read as "that leg has no answer," matching the aggregate's own contract,
|
|
732
|
+
* whichever call shape actually answered it.
|
|
733
|
+
*/
|
|
734
|
+
export async function multicallChunked(client, contracts, chunkSize) {
|
|
735
|
+
const out = new Array(contracts.length).fill(null);
|
|
736
|
+
const runAggregate = async (legs) => {
|
|
465
737
|
try {
|
|
466
|
-
|
|
738
|
+
const res = (await client.multicall({ contracts: legs, allowFailure: true }));
|
|
739
|
+
return res.map((r) => (r.status === 'success' ? r.result : null));
|
|
467
740
|
}
|
|
468
|
-
catch
|
|
469
|
-
|
|
470
|
-
window = window > 2n ? window / 2n : 1n; // RPC rejected this window — shrink and retry
|
|
471
|
-
continue;
|
|
472
|
-
}
|
|
473
|
-
throw err; // genuine failure, or already at one block per call
|
|
741
|
+
catch {
|
|
742
|
+
return legs.map(() => null); // the aggregate itself failed
|
|
474
743
|
}
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
744
|
+
};
|
|
745
|
+
const readOne = async (leg) => {
|
|
746
|
+
try {
|
|
747
|
+
return await client.readContract(leg);
|
|
748
|
+
}
|
|
749
|
+
catch {
|
|
750
|
+
return null; // a genuine revert — or the fallback itself failing — reads the same as unreadable
|
|
751
|
+
}
|
|
752
|
+
};
|
|
753
|
+
for (let i = 0; i < contracts.length; i += chunkSize) {
|
|
754
|
+
const legs = contracts.slice(i, i + chunkSize);
|
|
755
|
+
let vals = await runAggregate(legs);
|
|
756
|
+
// Every leg failed: the aggregate itself is the likely cause (too costly, or no multicall3 to
|
|
757
|
+
// call at all), not the individual reads. Re-ask one at a time via `readContract` — never via
|
|
758
|
+
// `multicall` again, even for a lone leg — so the batch degrades to what genuinely can't be
|
|
759
|
+
// read, whether the original cause was cost or an absent multicall3. (A chunk can land at width
|
|
760
|
+
// 1 too, e.g. the last chunk of an odd-length list — that leg is exactly as exposed to "no
|
|
761
|
+
// multicall3 here" as any other, so it gets the same fallback, not a pass.)
|
|
762
|
+
if (vals.every((v) => v === null)) {
|
|
763
|
+
vals = await Promise.all(legs.map(readOne));
|
|
485
764
|
}
|
|
765
|
+
for (let k = 0; k < vals.length; k++)
|
|
766
|
+
out[i + k] = vals[k];
|
|
486
767
|
}
|
|
487
768
|
return out;
|
|
488
769
|
}
|
|
489
|
-
/**
|
|
490
|
-
|
|
770
|
+
/**
|
|
771
|
+
* Head-read the values the spine only pings (name/symbol/contractURI/tokenURI) plus the trust and
|
|
772
|
+
* URI-lane facts, and fold them into state.
|
|
773
|
+
*
|
|
774
|
+
* **Reads are split by cost class, and that split is load-bearing.** These used to be one multicall,
|
|
775
|
+
* which was correct for an off-chain project (every return is a short string) and quietly wrong for
|
|
776
|
+
* the flagship on-chain lane: there, `tokenURI(id)` *assembles the whole metadata document
|
|
777
|
+
* on-chain*, tens of KB per token. Four such legs in one aggregate already exceed a public node's
|
|
778
|
+
* `eth_call` budget, so the batch failed whole — and took `name`, `symbol`, `contractURI`,
|
|
779
|
+
* `isAbxClone`, and, worst, `tokenURIRenderer` down with it. A resolver then believed a
|
|
780
|
+
* fully-on-chain 32-token collection had no name, no canonical proof, and **was not in the
|
|
781
|
+
* on-chain-URI lane at all.** Reproduced on Base Sepolia at `0xB844…5E56`: 4 legs → 0/8 succeeded,
|
|
782
|
+
* while `name()` answered `"ABXdoku"` on its own.
|
|
783
|
+
*
|
|
784
|
+
* So: the cheap fixed reads — the ones that decide the project's identity and lane — go in one
|
|
785
|
+
* batch of their own and can never be collateral damage.
|
|
786
|
+
*
|
|
787
|
+
* **The unbounded pair (`contractURI` + one `tokenURI` per token) is diagnostic and opt-in
|
|
788
|
+
* (`readUriDocuments`, default `false`) — skipped ENTIRELY unless requested, not just best-effort.**
|
|
789
|
+
* Two independent reasons, not one:
|
|
790
|
+
*
|
|
791
|
+
* 1. **Size.** A real 32-token fully-on-chain project measured at 13.4 MB of serialized
|
|
792
|
+
* `ProjectState`, of which 99.8% was `tokens[].tokenURI` — ~313 KB/token, re-fetched on *every*
|
|
793
|
+
* reconstruct, full or incremental, to fold a single new mint. `contractURI` is the same shape at
|
|
794
|
+
* collection scope (~1 KB there, but proportionally as dominant once `tokenURI` is out of the
|
|
795
|
+
* picture).
|
|
796
|
+
* 2. **No settled value.** A renderer that composes these on demand can change them with **no log at
|
|
797
|
+
* all** — the refresh trigger here is `getLogs`, and there is no event for "the composed document
|
|
798
|
+
* changed." A value with no settled state and no change signal cannot be cached correctly at any
|
|
799
|
+
* refresh cadence: too eager and every tick looks different (a real incident); too lazy and the
|
|
800
|
+
* cached copy silently rots. The only correct move is not to cache it — read it live when someone
|
|
801
|
+
* actually wants to display it (`nothing served depends on it`, the one exception being a fresh
|
|
802
|
+
* `abx demo` read-back, which asks for it explicitly).
|
|
803
|
+
*/
|
|
804
|
+
async function applyHeadReads(client, state, factory, readUriDocuments = false, reuseScript) {
|
|
491
805
|
const token = { address: state.address, abi: oneOfOneImageAbi };
|
|
492
806
|
const tokenIds = state.tokens.map((t) => t.tokenId);
|
|
807
|
+
// The edition family (ERC-1155) shares every cheap fixed-return name with the 721 superset ABI
|
|
808
|
+
// used below (name/symbol/owner/tokenURIRenderer/tokenURILocked/contractURIRenderer/
|
|
809
|
+
// contractURILocked/contractURI — same signatures on both standards), EXCEPT the per-token URI
|
|
810
|
+
// getter: editions expose `uri(id)`, not `tokenURI(id)` (ERC-1155 has no `tokenURI`). Encode
|
|
811
|
+
// that one leg against an edition ABI instead; the field name on `TokenState` stays `tokenURI`
|
|
812
|
+
// either way (it's the resolved metadata pointer regardless of which standard produced it).
|
|
813
|
+
const isEdition = state.contractType === '1of1-edition' || state.contractType === 'edition' || state.contractType === 'edition-code';
|
|
814
|
+
const uriAbi = isEdition ? oneOfOneEditionAbi : oneOfOneImageAbi;
|
|
815
|
+
const uriFn = isEdition ? 'uri' : 'tokenURI';
|
|
816
|
+
// ── cheap, fixed-size returns: identity, trust, the URI lane, the script count ──
|
|
493
817
|
// Mixed-ABI multicall — type it loosely; results are validated per-call below.
|
|
494
|
-
const
|
|
818
|
+
const cheap = [
|
|
495
819
|
{ ...token, functionName: 'name' },
|
|
496
820
|
{ ...token, functionName: 'symbol' },
|
|
497
821
|
{ ...token, functionName: 'owner' },
|
|
498
|
-
{ ...token, functionName: '
|
|
499
|
-
|
|
822
|
+
{ ...token, functionName: 'tokenURIRenderer' },
|
|
823
|
+
{ ...token, functionName: 'tokenURILocked' },
|
|
824
|
+
{ ...token, functionName: 'contractURIRenderer' },
|
|
825
|
+
{ ...token, functionName: 'contractURILocked' },
|
|
500
826
|
];
|
|
827
|
+
const factoryIdx = cheap.length;
|
|
501
828
|
if (factory) {
|
|
502
|
-
|
|
829
|
+
cheap.push({ address: factory, abi: oneOfOneImageFactoryAbi, functionName: 'isAbxClone', args: [state.address] }, { address: factory, abi: oneOfOneImageFactoryAbi, functionName: 'implementation' });
|
|
503
830
|
}
|
|
504
|
-
// URI resolution config (the off-chain↔on-chain toggle + freeze)
|
|
505
|
-
const cfgBase = contracts.length;
|
|
506
|
-
contracts.push({ ...token, functionName: 'tokenURIRenderer' }, { ...token, functionName: 'tokenURILocked' }, { ...token, functionName: 'contractURIRenderer' }, { ...token, functionName: 'contractURILocked' });
|
|
507
831
|
// On-chain script: chunk content is too large to log, so the count is a head read.
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
832
|
+
// Skip when the caller already holds a digest and `fresh` had no `ScriptUpdated` —
|
|
833
|
+
// a Transfer must not re-download every chunk.
|
|
834
|
+
const keepPriorScript = !!(state.script && reuseScript?.digest != null);
|
|
835
|
+
const scriptIdx = cheap.length;
|
|
836
|
+
if (state.script && !keepPriorScript) {
|
|
837
|
+
cheap.push({ address: state.address, abi: seriesCodeAbi, functionName: 'scriptChunkCount' });
|
|
511
838
|
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
839
|
+
// ── unbounded returns: each one may assemble a whole document on-chain ──
|
|
840
|
+
// `contractURI` first so a huge per-token tokenURI can never cost us the collection's own URI.
|
|
841
|
+
// `contractURI` itself is standard-neutral (ContractURI is reused as-is on the edition family),
|
|
842
|
+
// so only the per-token leg switches ABI/function name (see `uriAbi`/`uriFn` above).
|
|
843
|
+
//
|
|
844
|
+
// Skipped ENTIRELY when `readUriDocuments` is false (the default) — not requested at reduced
|
|
845
|
+
// width, not requested-then-discarded: no `eth_call` for either leg. `state.contractURI` and
|
|
846
|
+
// every `tok.tokenURI` stay `null`, same as an off-chain project with nothing to read.
|
|
847
|
+
const heavy = readUriDocuments
|
|
848
|
+
? [
|
|
849
|
+
{ ...token, functionName: 'contractURI' },
|
|
850
|
+
...tokenIds.map((id) => ({ address: state.address, abi: uriAbi, functionName: uriFn, args: [BigInt(id)] })),
|
|
851
|
+
]
|
|
852
|
+
: [];
|
|
853
|
+
const [cheapVals, heavyVals] = await Promise.all([
|
|
854
|
+
multicallChunked(client, cheap, cheap.length), // one batch: all short returns
|
|
855
|
+
readUriDocuments ? multicallChunked(client, heavy, HEAVY_READ_CHUNK) : Promise.resolve([]),
|
|
856
|
+
]);
|
|
857
|
+
const val = (i) => cheapVals[i] ?? null;
|
|
517
858
|
state.name = val(0) ?? null;
|
|
518
859
|
state.symbol = val(1) ?? null;
|
|
519
860
|
state.owner = val(2) ?? state.owner;
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
});
|
|
861
|
+
const nonZero = (a) => a && a !== '0x0000000000000000000000000000000000000000' ? a : null;
|
|
862
|
+
state.tokenURIRenderer = nonZero(val(3));
|
|
863
|
+
state.tokenURILocked = val(4) ?? null;
|
|
864
|
+
state.contractURIRenderer = nonZero(val(5));
|
|
865
|
+
state.contractURILocked = val(6) ?? null;
|
|
526
866
|
if (factory) {
|
|
527
|
-
|
|
528
|
-
state.
|
|
529
|
-
state.implementation = val(base + 1) ?? null;
|
|
867
|
+
state.isCanonical = cheapVals[factoryIdx] ?? null;
|
|
868
|
+
state.implementation = cheapVals[factoryIdx + 1] ?? null;
|
|
530
869
|
}
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
870
|
+
// `tok.tokenURI` is already `null` from `tokenIn` — only overwrite it when we actually asked.
|
|
871
|
+
if (readUriDocuments) {
|
|
872
|
+
state.contractURI = heavyVals[0] ?? null;
|
|
873
|
+
tokenIds.forEach((id, k) => {
|
|
874
|
+
const tok = state.tokens.find((t) => t.tokenId === id);
|
|
875
|
+
if (tok)
|
|
876
|
+
tok.tokenURI = heavyVals[1 + k] ?? null;
|
|
877
|
+
});
|
|
878
|
+
}
|
|
879
|
+
if (state.script && keepPriorScript) {
|
|
880
|
+
state.script.chunkCount = reuseScript.chunkCount;
|
|
881
|
+
state.script.digest = reuseScript.digest;
|
|
882
|
+
}
|
|
883
|
+
else if (state.script) {
|
|
884
|
+
const count = cheapVals[scriptIdx] ?? null;
|
|
538
885
|
state.script.chunkCount = count === null ? null : Number(count);
|
|
539
886
|
// digest = keccak over the concatenated chunks — the content half of effect inputsHash
|
|
540
|
-
// values. Chunks are
|
|
887
|
+
// values. Chunks are bounded (~24 KB each) but there can be many, and the same aggregate cap
|
|
888
|
+
// applies, so they read through the chunked path too.
|
|
541
889
|
const n = state.script.chunkCount ?? 0;
|
|
542
890
|
if (n > 0) {
|
|
543
|
-
const chunkReads =
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
})),
|
|
550
|
-
allowFailure: true,
|
|
551
|
-
}));
|
|
891
|
+
const chunkReads = await multicallChunked(client, Array.from({ length: n }, (_, i) => ({
|
|
892
|
+
address: state.address,
|
|
893
|
+
abi: seriesCodeAbi,
|
|
894
|
+
functionName: 'scriptChunk',
|
|
895
|
+
args: [BigInt(i)],
|
|
896
|
+
})), HEAVY_READ_CHUNK);
|
|
552
897
|
const parts = [];
|
|
553
898
|
for (const r of chunkReads) {
|
|
554
|
-
if (r
|
|
899
|
+
if (r === null)
|
|
555
900
|
return; // partial read — leave digest unset rather than wrong
|
|
556
|
-
parts.push(r
|
|
901
|
+
parts.push(r);
|
|
557
902
|
}
|
|
558
903
|
state.script.digest = keccak256(concatHex(parts));
|
|
559
904
|
}
|