@t3foundry/tasra-sdk 0.0.0-stage → 0.3.0-next.1
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 +148 -0
- package/LICENSE +202 -0
- package/NOTICE +94 -0
- package/README.md +137 -2
- package/SECURITY.md +115 -0
- package/dist/app/approvals.d.ts +50 -0
- package/dist/app/approvals.js +90 -0
- package/dist/app/authorization.d.ts +19 -0
- package/dist/app/authorization.js +20 -0
- package/dist/app/client.d.ts +231 -0
- package/dist/app/client.js +272 -0
- package/dist/app/creation.d.ts +73 -0
- package/dist/app/creation.js +77 -0
- package/dist/app/deployment.d.ts +36 -0
- package/dist/app/deployment.js +18 -0
- package/dist/app/identity.d.ts +211 -0
- package/dist/app/identity.js +287 -0
- package/dist/app/index.d.ts +22 -0
- package/dist/app/index.js +12 -0
- package/dist/app/manifest.d.ts +74 -0
- package/dist/app/manifest.js +120 -0
- package/dist/app/node.d.ts +30 -0
- package/dist/app/node.js +159 -0
- package/dist/app/ready-slot.d.ts +157 -0
- package/dist/app/ready-slot.js +199 -0
- package/dist/app/tasra-client.d.ts +125 -0
- package/dist/app/tasra-client.js +79 -0
- package/dist/app/viem.d.ts +10 -0
- package/dist/app/viem.js +32 -0
- package/dist/app/wallet.d.ts +126 -0
- package/dist/app/wallet.js +137 -0
- package/dist/auth/dpop.d.ts +86 -0
- package/dist/auth/dpop.js +142 -0
- package/dist/auth/holderProof.d.ts +102 -0
- package/dist/auth/holderProof.js +161 -0
- package/dist/auth/identityScope.d.ts +19 -0
- package/dist/auth/identityScope.js +82 -0
- package/dist/auth/index.d.ts +11 -0
- package/dist/auth/index.js +13 -0
- package/dist/auth/oid4vp.d.ts +230 -0
- package/dist/auth/oid4vp.js +780 -0
- package/dist/auth/rego/wasm/PINS.json +11 -0
- package/dist/auth/rego/wasm/keykeeper_rego_wasm.d.ts +76 -0
- package/dist/auth/rego/wasm/keykeeper_rego_wasm.js +379 -0
- package/dist/auth/rego/wasm/keykeeper_rego_wasm_bg.wasm +0 -0
- package/dist/auth/rego.d.ts +192 -0
- package/dist/auth/rego.js +492 -0
- package/dist/auth/verifier.d.ts +166 -0
- package/dist/auth/verifier.js +211 -0
- package/dist/chain/abis/accountantSetRegistry.d.ts +441 -0
- package/dist/chain/abis/accountantSetRegistry.js +574 -0
- package/dist/chain/abis/accountantSlashing.d.ts +2071 -0
- package/dist/chain/abis/accountantSlashing.js +2670 -0
- package/dist/chain/abis/bondingCurve.d.ts +398 -0
- package/dist/chain/abis/bondingCurve.js +521 -0
- package/dist/chain/abis/equivocationSlasher.d.ts +292 -0
- package/dist/chain/abis/equivocationSlasher.js +379 -0
- package/dist/chain/abis/fixedTasraPriceOracle.d.ts +52 -0
- package/dist/chain/abis/fixedTasraPriceOracle.js +72 -0
- package/dist/chain/abis/index.d.ts +12801 -0
- package/dist/chain/abis/index.js +64 -0
- package/dist/chain/abis/keeperShareRegistry.d.ts +519 -0
- package/dist/chain/abis/keeperShareRegistry.js +675 -0
- package/dist/chain/abis/keyRegistry.d.ts +2421 -0
- package/dist/chain/abis/keyRegistry.js +3114 -0
- package/dist/chain/abis/livenessRegistry.d.ts +402 -0
- package/dist/chain/abis/livenessRegistry.js +524 -0
- package/dist/chain/abis/mockEurc.d.ts +210 -0
- package/dist/chain/abis/mockEurc.js +276 -0
- package/dist/chain/abis/nodeRegistry.d.ts +1630 -0
- package/dist/chain/abis/nodeRegistry.js +2113 -0
- package/dist/chain/abis/platformExecutor.d.ts +328 -0
- package/dist/chain/abis/platformExecutor.js +429 -0
- package/dist/chain/abis/prevrandaoSaltBeacon.d.ts +16 -0
- package/dist/chain/abis/prevrandaoSaltBeacon.js +24 -0
- package/dist/chain/abis/serviceRegistry.d.ts +556 -0
- package/dist/chain/abis/serviceRegistry.js +719 -0
- package/dist/chain/abis/settlement.d.ts +1624 -0
- package/dist/chain/abis/settlement.js +2096 -0
- package/dist/chain/abis/tasraSwapRouter.d.ts +92 -0
- package/dist/chain/abis/tasraSwapRouter.js +122 -0
- package/dist/chain/abis/tasraToken.d.ts +455 -0
- package/dist/chain/abis/tasraToken.js +599 -0
- package/dist/chain/abis/tasraVestingVault.d.ts +165 -0
- package/dist/chain/abis/tasraVestingVault.js +215 -0
- package/dist/chain/abis/thresholdRandomBeacon.d.ts +378 -0
- package/dist/chain/abis/thresholdRandomBeacon.js +494 -0
- package/dist/chain/abis/treasury.d.ts +301 -0
- package/dist/chain/abis/treasury.js +390 -0
- package/dist/chain/abis/verifierSetRegistry.d.ts +445 -0
- package/dist/chain/abis/verifierSetRegistry.js +579 -0
- package/dist/chain/client.d.ts +212 -0
- package/dist/chain/client.js +576 -0
- package/dist/chain/commitmentRecovery.d.ts +21 -0
- package/dist/chain/commitmentRecovery.js +44 -0
- package/dist/chain/committeeClient.d.ts +102 -0
- package/dist/chain/committeeClient.js +137 -0
- package/dist/chain/deployments.d.ts +56 -0
- package/dist/chain/deployments.js +269 -0
- package/dist/chain/discovery.d.ts +49 -0
- package/dist/chain/discovery.js +107 -0
- package/dist/chain/events.d.ts +58 -0
- package/dist/chain/events.js +125 -0
- package/dist/chain/format.d.ts +25 -0
- package/dist/chain/format.js +51 -0
- package/dist/chain/index.d.ts +41 -0
- package/dist/chain/index.js +56 -0
- package/dist/chain/manifest.d.ts +165 -0
- package/dist/chain/manifest.js +132 -0
- package/dist/chain/network-profiles.json +75 -0
- package/dist/chain/networks.d.ts +73 -0
- package/dist/chain/networks.js +62 -0
- package/dist/chain/node.d.ts +44 -0
- package/dist/chain/node.js +176 -0
- package/dist/chain/offchain.d.ts +149 -0
- package/dist/chain/offchain.js +73 -0
- package/dist/chain/provisionRule.d.ts +164 -0
- package/dist/chain/provisionRule.js +212 -0
- package/dist/chain/registeredAgent.d.ts +64 -0
- package/dist/chain/registeredAgent.js +140 -0
- package/dist/chain/registeredOperation.d.ts +49 -0
- package/dist/chain/registeredOperation.js +136 -0
- package/dist/chain/registeredRelay.d.ts +206 -0
- package/dist/chain/registeredRelay.js +312 -0
- package/dist/chain/revertReason.d.ts +14 -0
- package/dist/chain/revertReason.js +62 -0
- package/dist/chain/ruleAmendment.d.ts +80 -0
- package/dist/chain/ruleAmendment.js +195 -0
- package/dist/chain/ruleAmendmentCore.d.ts +129 -0
- package/dist/chain/ruleAmendmentCore.js +152 -0
- package/dist/chain/ruleInput.d.ts +10 -0
- package/dist/chain/ruleInput.js +13 -0
- package/dist/chain/serviceIdentity.d.ts +176 -0
- package/dist/chain/serviceIdentity.js +237 -0
- package/dist/chain/serviceProfiles.d.ts +39 -0
- package/dist/chain/serviceProfiles.js +74 -0
- package/dist/chain/services.d.ts +141 -0
- package/dist/chain/services.js +79 -0
- package/dist/chain/slotClient.d.ts +55 -0
- package/dist/chain/slotClient.js +62 -0
- package/dist/chain/slotSeed.d.ts +31 -0
- package/dist/chain/slotSeed.js +98 -0
- package/dist/chain/write.d.ts +431 -0
- package/dist/chain/write.js +958 -0
- package/dist/client/client.d.ts +112 -0
- package/dist/client/client.js +111 -0
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.js +2 -0
- package/dist/client/session.d.ts +67 -0
- package/dist/client/session.js +238 -0
- package/dist/committee/client.d.ts +284 -0
- package/dist/committee/client.js +351 -0
- package/dist/committee/dual-sign.d.ts +110 -0
- package/dist/committee/dual-sign.js +202 -0
- package/dist/committee/ecdsa.d.ts +36 -0
- package/dist/committee/ecdsa.js +45 -0
- package/dist/committee/extraction.d.ts +82 -0
- package/dist/committee/extraction.js +96 -0
- package/dist/committee/index.d.ts +19 -0
- package/dist/committee/index.js +13 -0
- package/dist/committee/oauth.d.ts +51 -0
- package/dist/committee/oauth.js +90 -0
- package/dist/committee/receipts.d.ts +51 -0
- package/dist/committee/receipts.js +59 -0
- package/dist/committee/request.d.ts +264 -0
- package/dist/committee/request.js +305 -0
- package/dist/committee/token.d.ts +274 -0
- package/dist/committee/token.js +418 -0
- package/dist/crypto/constants.d.ts +10 -0
- package/dist/crypto/constants.js +32 -0
- package/dist/crypto/detect.d.ts +20 -0
- package/dist/crypto/detect.js +44 -0
- package/dist/crypto/envelope.d.ts +60 -0
- package/dist/crypto/envelope.js +243 -0
- package/dist/crypto/frost.d.ts +49 -0
- package/dist/crypto/frost.js +152 -0
- package/dist/crypto/hex.d.ts +7 -0
- package/dist/crypto/hex.js +24 -0
- package/dist/crypto/ibe-blob.d.ts +114 -0
- package/dist/crypto/ibe-blob.js +208 -0
- package/dist/crypto/ibe.d.ts +88 -0
- package/dist/crypto/ibe.js +262 -0
- package/dist/crypto/index.d.ts +12 -0
- package/dist/crypto/index.js +12 -0
- package/dist/crypto/kem.d.ts +55 -0
- package/dist/crypto/kem.js +241 -0
- package/dist/decryption/client.d.ts +64 -0
- package/dist/decryption/client.js +82 -0
- package/dist/decryption/index.d.ts +2 -0
- package/dist/decryption/index.js +2 -0
- package/dist/errors.d.ts +124 -0
- package/dist/errors.js +167 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.js +98 -0
- package/dist/keys/index.d.ts +1 -0
- package/dist/keys/index.js +4 -0
- package/dist/keys/node-client.d.ts +27 -0
- package/dist/keys/node-client.js +97 -0
- package/dist/oid4vp/binding.d.ts +76 -0
- package/dist/oid4vp/binding.js +118 -0
- package/dist/oid4vp/did-web.d.ts +49 -0
- package/dist/oid4vp/did-web.js +57 -0
- package/dist/oid4vp/index.d.ts +9 -0
- package/dist/oid4vp/index.js +10 -0
- package/dist/oid4vp/jose.d.ts +166 -0
- package/dist/oid4vp/jose.js +242 -0
- package/dist/oid4vp/jwe.d.ts +30 -0
- package/dist/oid4vp/jwe.js +93 -0
- package/dist/oid4vp/oid4vci.d.ts +84 -0
- package/dist/oid4vp/oid4vci.js +85 -0
- package/dist/oid4vp/request-object.d.ts +109 -0
- package/dist/oid4vp/request-object.js +96 -0
- package/dist/oid4vp/sd-jwt.d.ts +177 -0
- package/dist/oid4vp/sd-jwt.js +208 -0
- package/dist/oid4vp/verifier-agent.d.ts +161 -0
- package/dist/oid4vp/verifier-agent.js +132 -0
- package/dist/oid4vp/wallet.d.ts +116 -0
- package/dist/oid4vp/wallet.js +108 -0
- package/dist/recipient/store.d.ts +67 -0
- package/dist/recipient/store.js +98 -0
- package/dist/signing/ecdsa.d.ts +49 -0
- package/dist/signing/ecdsa.js +79 -0
- package/dist/signing/frost.d.ts +88 -0
- package/dist/signing/frost.js +145 -0
- package/dist/signing/index.d.ts +4 -0
- package/dist/signing/index.js +3 -0
- package/dist/slots/faucet.d.ts +23 -0
- package/dist/slots/faucet.js +35 -0
- package/dist/slots/index.d.ts +2 -0
- package/dist/slots/index.js +4 -0
- package/dist/verifier-agent/index.d.ts +241 -0
- package/dist/verifier-agent/index.js +411 -0
- package/docs/DEVELOPER-EXPERIENCE.md +62 -0
- package/docs/README.md +33 -0
- package/docs/access-control.md +76 -0
- package/docs/ai-development.md +292 -0
- package/docs/api.md +338 -0
- package/docs/application-api.md +335 -0
- package/docs/architecture.md +65 -0
- package/docs/basics.md +48 -0
- package/docs/capabilities.md +86 -0
- package/docs/chain.md +153 -0
- package/docs/compatibility.md +36 -0
- package/docs/consumer-migrations.md +80 -0
- package/docs/create-slot.md +104 -0
- package/docs/document-signing.md +243 -0
- package/docs/encrypted-notes.md +129 -0
- package/docs/encryption.md +100 -0
- package/docs/errors.md +76 -0
- package/docs/flows.md +289 -0
- package/docs/fuji.md +127 -0
- package/docs/funding.md +126 -0
- package/docs/getting-started.md +94 -0
- package/docs/glossary.md +44 -0
- package/docs/installation.md +132 -0
- package/docs/manage-slot.md +95 -0
- package/docs/native-approvals.md +124 -0
- package/docs/prerequisites.md +137 -0
- package/docs/read-slot.md +41 -0
- package/docs/reference/README.md +30 -0
- package/docs/reference/app-node.md +102 -0
- package/docs/reference/app.md +1737 -0
- package/docs/reference/chain-node.md +159 -0
- package/docs/reference/chain.md +3609 -0
- package/docs/reference/committee.md +2176 -0
- package/docs/reference/main.md +4068 -0
- package/docs/reference/oid4vp.md +2547 -0
- package/docs/reference/verifier-agent.md +498 -0
- package/docs/shared-account.md +168 -0
- package/docs/signing-and-encryption.md +52 -0
- package/docs/signing.md +172 -0
- package/examples/committee-slot.ts +16 -0
- package/examples/connect-fuji.ts +41 -0
- package/examples/connect-network.ts +14 -0
- package/examples/credential-approvals.ts +46 -0
- package/examples/document-signing/README.md +59 -0
- package/examples/document-signing/backend.ts +132 -0
- package/examples/document-signing/build.mjs +19 -0
- package/examples/document-signing/config.ts +34 -0
- package/examples/document-signing/gitignore.template +9 -0
- package/examples/document-signing/model.ts +140 -0
- package/examples/document-signing/network.ts +58 -0
- package/examples/document-signing/package.json +25 -0
- package/examples/document-signing/public/index.html +27 -0
- package/examples/document-signing/public/sample.pdf +31 -0
- package/examples/document-signing/public/styles.css +531 -0
- package/examples/document-signing/server.ts +358 -0
- package/examples/document-signing/setup.ts +111 -0
- package/examples/document-signing/store.ts +105 -0
- package/examples/document-signing/tsconfig.json +24 -0
- package/examples/document-signing/verify.ts +24 -0
- package/examples/document-signing/web/app.ts +312 -0
- package/examples/document-signing/web/preview.ts +67 -0
- package/examples/document-signing/web/wallet.ts +146 -0
- package/examples/document-signing/workflow.test.ts +228 -0
- package/examples/document-signing/workflow.ts +241 -0
- package/examples/document-signing.ts +96 -0
- package/examples/encrypted-notes.ts +86 -0
- package/examples/ethers-signer.ts +204 -0
- package/examples/fund-slot.ts +73 -0
- package/examples/getting-started.ts +25 -0
- package/examples/learning-authorize.ts +23 -0
- package/examples/learning-cancel-slot.ts +11 -0
- package/examples/learning-context.ts +28 -0
- package/examples/learning-create-slot.ts +25 -0
- package/examples/learning-read-slot.ts +8 -0
- package/examples/learning-renew-slot.ts +12 -0
- package/examples/learning-sign.ts +8 -0
- package/examples/live-config.ts +71 -0
- package/examples/minimal.ts +6 -0
- package/examples/native-approvals.ts +57 -0
- package/examples/network.ts +58 -0
- package/examples/offline.ts +16 -0
- package/examples/personal-vault.ts +20 -0
- package/examples/provision-slot.ts +47 -0
- package/examples/shared-account.ts +46 -0
- package/examples/slot-address.ts +13 -0
- package/examples/slot-creation.ts +9 -0
- package/examples/tutorial-negative.ts +26 -0
- package/examples/tutorial-support.ts +76 -0
- package/examples/viem-account.ts +203 -0
- package/package.json +303 -4
|
@@ -0,0 +1,576 @@
|
|
|
1
|
+
// viem-based read client for a Tasra Network deployment. Provides:
|
|
2
|
+
// - a configured PublicClient
|
|
3
|
+
// - windowed log fetching + decoding (for the indexer backfill/tail)
|
|
4
|
+
// - block-timestamp lookups
|
|
5
|
+
// - typed view-function readers for the entities the explorer cares about
|
|
6
|
+
//
|
|
7
|
+
// Read-only: no wallet, no signing. The explorer never writes to the chain.
|
|
8
|
+
import { createPublicClient, http, defineChain, } from 'viem';
|
|
9
|
+
import { CONTRACT_ABIS } from './abis/index.js';
|
|
10
|
+
import { createServiceRegistryReaders } from './services.js';
|
|
11
|
+
import { nodeRegistryAbi } from './abis/nodeRegistry.js';
|
|
12
|
+
import { keyRegistryAbi } from './abis/keyRegistry.js';
|
|
13
|
+
import { settlementAbi } from './abis/settlement.js';
|
|
14
|
+
import { tasraTokenAbi } from './abis/tasraToken.js';
|
|
15
|
+
import { bondingCurveAbi } from './abis/bondingCurve.js';
|
|
16
|
+
import { treasuryAbi } from './abis/treasury.js';
|
|
17
|
+
import { tasraVestingVaultAbi } from './abis/tasraVestingVault.js';
|
|
18
|
+
import { thresholdRandomBeaconAbi } from './abis/thresholdRandomBeacon.js';
|
|
19
|
+
import { verifierSetRegistryAbi } from './abis/verifierSetRegistry.js';
|
|
20
|
+
import { DEFAULT_CHAIN_ID, VAULT_TRANCHES, requireAddress, requireVaultAddress, vaultKey, } from './deployments.js';
|
|
21
|
+
import { decodeContractLogs } from './events.js';
|
|
22
|
+
/**
|
|
23
|
+
* Calldata BYTES per Multicall3 aggregate - viem's unit here is bytes, not items, and
|
|
24
|
+
* it chunks the list for us at this size.
|
|
25
|
+
*
|
|
26
|
+
* A cap, not a target. The point is to stop a 10k-operator registry becoming 10k round
|
|
27
|
+
* trips, but one unbounded aggregate is a payload an RPC rejects and an `eth_call` gas
|
|
28
|
+
* budget a node refuses. At ~68 bytes for a one-address view call this is ~480 items per
|
|
29
|
+
* request, so 10k reads become ~21 requests - the win is already three orders of
|
|
30
|
+
* magnitude, and raising it further buys little for real risk.
|
|
31
|
+
*
|
|
32
|
+
* viem's own default is 1024 bytes (~15 items), which is too small to matter here.
|
|
33
|
+
*/
|
|
34
|
+
const MULTICALL_BATCH_BYTES = 32_768;
|
|
35
|
+
/** Multicall3's canonical, deterministic-deployment address. */
|
|
36
|
+
export const MULTICALL3_ADDRESS = '0xcA11bde05977b3631167028862bE2a173976CA11';
|
|
37
|
+
/**
|
|
38
|
+
* Create a read-only chain client with typed contract readers and windowed event queries. Configure addresses and the chain ID from a network manifest downloaded from tasra-releases.
|
|
39
|
+
* @param cfg RPC endpoint, deployed addresses, chain ID and optional batching limits.
|
|
40
|
+
* @returns Client exposing the viem public client, readers, event queries and address book.
|
|
41
|
+
*/
|
|
42
|
+
export function createTasraChainClient(cfg) {
|
|
43
|
+
const chain = defineChain({
|
|
44
|
+
id: cfg.chainId ?? DEFAULT_CHAIN_ID,
|
|
45
|
+
name: 'keykeeper',
|
|
46
|
+
nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
|
|
47
|
+
rpcUrls: { default: { http: [cfg.rpcUrl] } },
|
|
48
|
+
});
|
|
49
|
+
// No `batch: {multicall}` here, deliberately. viem's client-level batching is
|
|
50
|
+
// driven by the CHAIN definition naming a multicall3 address, and it does not
|
|
51
|
+
// degrade: where Multicall3 is absent the aggregate call returns empty data and
|
|
52
|
+
// EVERY read in the batch fails to decode, which a bare local chain would hit on
|
|
53
|
+
// its first read. Worse, once it is on there is no way back - an individual-read
|
|
54
|
+
// fallback goes through the same broken batch.
|
|
55
|
+
//
|
|
56
|
+
// So batching is applied explicitly in `readMany`, gated on a one-off `eth_getCode`
|
|
57
|
+
// probe and with a fallback that can actually run. See `multicallAddress`.
|
|
58
|
+
const client = createPublicClient({
|
|
59
|
+
chain,
|
|
60
|
+
transport: http(cfg.rpcUrl),
|
|
61
|
+
});
|
|
62
|
+
const addresses = cfg.addresses;
|
|
63
|
+
const defaultWindow = cfg.logWindow ?? 2000;
|
|
64
|
+
/**
|
|
65
|
+
* Resolved ONCE per client: the Multicall3 address to batch through, or null.
|
|
66
|
+
*
|
|
67
|
+
* Cached as the promise, not the value, so concurrent first calls share one probe
|
|
68
|
+
* instead of racing several. Latched to null if a batch ever fails at the aggregate
|
|
69
|
+
* level (a wrong address, or something at that address that is not Multicall3), so one
|
|
70
|
+
* bad batch does not cost a failed attempt on every later call.
|
|
71
|
+
*/
|
|
72
|
+
/**
|
|
73
|
+
* Set once a batch has returned at least one SUCCESSFUL item, i.e. the thing at the
|
|
74
|
+
* batch address has demonstrably behaved like Multicall3.
|
|
75
|
+
*
|
|
76
|
+
* Needed because `eth_getCode` cannot tell Multicall3 from any other contract at that
|
|
77
|
+
* address, and viem does not throw when the aggregate is answered by something else -
|
|
78
|
+
* it reports every item as failed. All-failed is therefore ambiguous: either the batch
|
|
79
|
+
* mechanism is broken, or the items are unreadable. Until one success has been
|
|
80
|
+
* seen, that case is resolved by reading the items individually and comparing, rather
|
|
81
|
+
* than by guessing (guessing wrong means silently returning nulls for readable state).
|
|
82
|
+
*/
|
|
83
|
+
let batchProven = false;
|
|
84
|
+
let multicallProbe;
|
|
85
|
+
function multicallAddress() {
|
|
86
|
+
return (multicallProbe ??= (async () => {
|
|
87
|
+
if (cfg.multicall3 === false)
|
|
88
|
+
return null;
|
|
89
|
+
const at = cfg.multicall3 ?? MULTICALL3_ADDRESS;
|
|
90
|
+
try {
|
|
91
|
+
const code = await client.getCode({ address: at });
|
|
92
|
+
// An address with no contract answers '0x' (or undefined), which is the bare-chain
|
|
93
|
+
// case. Probing beats assuming: assuming is what breaks every read.
|
|
94
|
+
return code && code !== '0x' ? at : null;
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
// A probe that cannot complete must not decide the reads are impossible.
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
})());
|
|
101
|
+
}
|
|
102
|
+
const disableMulticall = () => {
|
|
103
|
+
multicallProbe = Promise.resolve(null);
|
|
104
|
+
};
|
|
105
|
+
/** Which of the known contracts have an address in this deployment. */
|
|
106
|
+
function deployedContracts() {
|
|
107
|
+
return Object.keys(CONTRACT_ABIS).filter(c => !!addresses[c]);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Every address whose logs this deployment can decode, paired with the ABI to
|
|
111
|
+
* decode them against.
|
|
112
|
+
*
|
|
113
|
+
* not the same as {@link deployedContracts}: that maps one canonical contract
|
|
114
|
+
* NAME to one address, but the vesting vaults are one ABI over up to three
|
|
115
|
+
* TRANCHE addresses (`TasraVestingVault_investor`, `_team`, `_community`),
|
|
116
|
+
* which are deliberately not contract names. Scanning by name alone therefore
|
|
117
|
+
* misses every vault log - the tranche keys are invisible to it - so an
|
|
118
|
+
* indexer must enumerate log sources through here instead.
|
|
119
|
+
*
|
|
120
|
+
* Addresses are de-duplicated: a single-vault deployment that only sets the
|
|
121
|
+
* bare `TasraVestingVault` key must be scanned once, not once per tranche.
|
|
122
|
+
*/
|
|
123
|
+
function logSources(contracts) {
|
|
124
|
+
const want = contracts ?? deployedContracts();
|
|
125
|
+
const out = [];
|
|
126
|
+
const seen = new Set();
|
|
127
|
+
const push = (address, contract) => {
|
|
128
|
+
const k = address.toLowerCase();
|
|
129
|
+
if (seen.has(k))
|
|
130
|
+
return;
|
|
131
|
+
seen.add(k);
|
|
132
|
+
out.push({ address, contract });
|
|
133
|
+
};
|
|
134
|
+
for (const c of want) {
|
|
135
|
+
const a = addresses[c];
|
|
136
|
+
if (a)
|
|
137
|
+
push(a, c);
|
|
138
|
+
}
|
|
139
|
+
if (!contracts || contracts.includes('TasraVestingVault')) {
|
|
140
|
+
for (const t of VAULT_TRANCHES) {
|
|
141
|
+
const a = addresses[vaultKey(t)];
|
|
142
|
+
if (a)
|
|
143
|
+
push(a, 'TasraVestingVault');
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return out;
|
|
147
|
+
}
|
|
148
|
+
async function getBlockNumber() {
|
|
149
|
+
return client.getBlockNumber();
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Fetch + decode logs for the given contracts over [fromBlock, toBlock] in
|
|
153
|
+
* windows. Logs are grouped by emitting address and decoded with the right
|
|
154
|
+
* contract ABI (so shared signatures like OwnerChanged are attributed
|
|
155
|
+
* correctly).
|
|
156
|
+
*/
|
|
157
|
+
async function getLogsWindowed(opts) {
|
|
158
|
+
const sources = logSources(opts.contracts);
|
|
159
|
+
const addrToContract = new Map();
|
|
160
|
+
const addressList = [];
|
|
161
|
+
for (const { address, contract } of sources) {
|
|
162
|
+
addrToContract.set(address.toLowerCase(), contract);
|
|
163
|
+
addressList.push(address);
|
|
164
|
+
}
|
|
165
|
+
if (addressList.length === 0)
|
|
166
|
+
return [];
|
|
167
|
+
const windowSize = BigInt(opts.windowSize ?? defaultWindow);
|
|
168
|
+
const all = [];
|
|
169
|
+
for (let from = opts.fromBlock; from <= opts.toBlock; from += windowSize) {
|
|
170
|
+
const to = from + windowSize - 1n > opts.toBlock
|
|
171
|
+
? opts.toBlock
|
|
172
|
+
: from + windowSize - 1n;
|
|
173
|
+
const logs = (await client.getLogs({
|
|
174
|
+
address: addressList,
|
|
175
|
+
fromBlock: from,
|
|
176
|
+
toBlock: to,
|
|
177
|
+
}));
|
|
178
|
+
const byAddr = new Map();
|
|
179
|
+
for (const log of logs) {
|
|
180
|
+
const k = (log.address ?? '').toLowerCase();
|
|
181
|
+
const arr = byAddr.get(k);
|
|
182
|
+
if (arr)
|
|
183
|
+
arr.push(log);
|
|
184
|
+
else
|
|
185
|
+
byAddr.set(k, [log]);
|
|
186
|
+
}
|
|
187
|
+
const windowEvents = [];
|
|
188
|
+
for (const [addr, ls] of byAddr) {
|
|
189
|
+
const c = addrToContract.get(addr);
|
|
190
|
+
if (!c)
|
|
191
|
+
continue;
|
|
192
|
+
// Appended one by one: spreading a large window into push() overflows the stack.
|
|
193
|
+
for (const event of decodeContractLogs(c, addr, ls))
|
|
194
|
+
windowEvents.push(event);
|
|
195
|
+
}
|
|
196
|
+
for (const event of windowEvents)
|
|
197
|
+
all.push(event);
|
|
198
|
+
opts.onWindow?.(to, windowEvents);
|
|
199
|
+
}
|
|
200
|
+
return all;
|
|
201
|
+
}
|
|
202
|
+
/** Resolve block timestamps (seconds) for a set of block numbers. */
|
|
203
|
+
async function getBlockTimestamps(blockNumbers) {
|
|
204
|
+
const unique = [...new Set([...blockNumbers].map(b => b.toString()))];
|
|
205
|
+
const out = new Map();
|
|
206
|
+
await Promise.all(unique.map(async (n) => {
|
|
207
|
+
const block = await client.getBlock({ blockNumber: BigInt(n) });
|
|
208
|
+
out.set(n, Number(block.timestamp));
|
|
209
|
+
}));
|
|
210
|
+
return out;
|
|
211
|
+
}
|
|
212
|
+
/** Generic typed-ish read against a known contract. */
|
|
213
|
+
async function read(contract, functionName, args = []) {
|
|
214
|
+
return client.readContract({
|
|
215
|
+
address: requireAddress(addresses, contract),
|
|
216
|
+
abi: CONTRACT_ABIS[contract],
|
|
217
|
+
functionName,
|
|
218
|
+
args: args,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
// Typed domain readers (precise return types via specific ABIs)
|
|
222
|
+
const nodeRegistry = {
|
|
223
|
+
nodeOf: (op) => client.readContract({
|
|
224
|
+
address: requireAddress(addresses, 'NodeRegistry'),
|
|
225
|
+
abi: nodeRegistryAbi,
|
|
226
|
+
functionName: 'nodeOf',
|
|
227
|
+
args: [op],
|
|
228
|
+
}),
|
|
229
|
+
isActive: (op) => client.readContract({
|
|
230
|
+
address: requireAddress(addresses, 'NodeRegistry'),
|
|
231
|
+
abi: nodeRegistryAbi,
|
|
232
|
+
functionName: 'isActive',
|
|
233
|
+
args: [op],
|
|
234
|
+
}),
|
|
235
|
+
operatorCount: () => client.readContract({
|
|
236
|
+
address: requireAddress(addresses, 'NodeRegistry'),
|
|
237
|
+
abi: nodeRegistryAbi,
|
|
238
|
+
functionName: 'operatorCount',
|
|
239
|
+
}),
|
|
240
|
+
operatorAt: (i) => client.readContract({
|
|
241
|
+
address: requireAddress(addresses, 'NodeRegistry'),
|
|
242
|
+
abi: nodeRegistryAbi,
|
|
243
|
+
functionName: 'operatorAt',
|
|
244
|
+
args: [i],
|
|
245
|
+
}),
|
|
246
|
+
activeCount: () => client.readContract({
|
|
247
|
+
address: requireAddress(addresses, 'NodeRegistry'),
|
|
248
|
+
abi: nodeRegistryAbi,
|
|
249
|
+
functionName: 'activeCount',
|
|
250
|
+
}),
|
|
251
|
+
attributesOf: (op) => client.readContract({
|
|
252
|
+
address: requireAddress(addresses, 'NodeRegistry'),
|
|
253
|
+
abi: nodeRegistryAbi,
|
|
254
|
+
functionName: 'attributesOf',
|
|
255
|
+
args: [op],
|
|
256
|
+
}),
|
|
257
|
+
rewardBalanceOf: (op) => client.readContract({
|
|
258
|
+
address: requireAddress(addresses, 'NodeRegistry'),
|
|
259
|
+
abi: nodeRegistryAbi,
|
|
260
|
+
functionName: 'rewardBalanceOf',
|
|
261
|
+
args: [op],
|
|
262
|
+
}),
|
|
263
|
+
requiredStake: () => client.readContract({
|
|
264
|
+
address: requireAddress(addresses, 'NodeRegistry'),
|
|
265
|
+
abi: nodeRegistryAbi,
|
|
266
|
+
functionName: 'requiredStake',
|
|
267
|
+
}),
|
|
268
|
+
// Phase-2 Option B: the operator's stable, immutable global FROST identifier.
|
|
269
|
+
operatorIdOf: (op) => client.readContract({
|
|
270
|
+
address: requireAddress(addresses, 'NodeRegistry'),
|
|
271
|
+
abi: nodeRegistryAbi,
|
|
272
|
+
functionName: 'operatorIdOf',
|
|
273
|
+
args: [op],
|
|
274
|
+
}),
|
|
275
|
+
// Whether an operator carries a given attribute tag (e.g. the keeper tag the
|
|
276
|
+
// committee draw selects by).
|
|
277
|
+
hasTag: (op, tag) => client.readContract({
|
|
278
|
+
address: requireAddress(addresses, 'NodeRegistry'),
|
|
279
|
+
abi: nodeRegistryAbi,
|
|
280
|
+
functionName: 'hasTag',
|
|
281
|
+
args: [op, tag],
|
|
282
|
+
}),
|
|
283
|
+
// The full active operator set in one call (avoids operatorCount+operatorAt fan-out).
|
|
284
|
+
activeOperators: () => client.readContract({
|
|
285
|
+
address: requireAddress(addresses, 'NodeRegistry'),
|
|
286
|
+
abi: nodeRegistryAbi,
|
|
287
|
+
functionName: 'activeOperators',
|
|
288
|
+
}),
|
|
289
|
+
};
|
|
290
|
+
const keyRegistry = {
|
|
291
|
+
getKeySlot: (id) => client.readContract({
|
|
292
|
+
address: requireAddress(addresses, 'KeyRegistry'),
|
|
293
|
+
abi: keyRegistryAbi,
|
|
294
|
+
functionName: 'getKeySlot',
|
|
295
|
+
args: [id],
|
|
296
|
+
}),
|
|
297
|
+
assignedNodes: (id) => client.readContract({
|
|
298
|
+
address: requireAddress(addresses, 'KeyRegistry'),
|
|
299
|
+
abi: keyRegistryAbi,
|
|
300
|
+
functionName: 'assignedNodes',
|
|
301
|
+
args: [id],
|
|
302
|
+
}),
|
|
303
|
+
/**
|
|
304
|
+
* Does this deployment refuse one-shot slot creation? A registry with `requireCommitReveal` set
|
|
305
|
+
* - every production genesis has it - reverts `createKeySlotFiltered*` with
|
|
306
|
+
* `CommitRevealRequired()` and accepts only the commit-then-reveal pair. Ask before creating: the
|
|
307
|
+
* answer decides between `createSlot` and `createSlotCommitReveal`, and costs one read.
|
|
308
|
+
*/
|
|
309
|
+
requiresCommitReveal: () => client.readContract({
|
|
310
|
+
address: requireAddress(addresses, 'KeyRegistry'),
|
|
311
|
+
abi: keyRegistryAbi,
|
|
312
|
+
functionName: 'requireCommitReveal',
|
|
313
|
+
}),
|
|
314
|
+
// The slot's per-request verifier-committee policy to `[committee, quorum]`
|
|
315
|
+
// (both `uint16`). `committee == 0` to the slot has no policy (committee path not wired);
|
|
316
|
+
// fall back to the legacy JWT path. Needed by the committee-authorization flow.
|
|
317
|
+
verifierPolicy: (id) => client.readContract({
|
|
318
|
+
address: requireAddress(addresses, 'KeyRegistry'),
|
|
319
|
+
abi: keyRegistryAbi,
|
|
320
|
+
functionName: 'verifierPolicy',
|
|
321
|
+
args: [id],
|
|
322
|
+
}),
|
|
323
|
+
};
|
|
324
|
+
const settlement = {
|
|
325
|
+
balanceOf: (slot) => client.readContract({
|
|
326
|
+
address: requireAddress(addresses, 'Settlement'),
|
|
327
|
+
abi: settlementAbi,
|
|
328
|
+
functionName: 'balanceOf',
|
|
329
|
+
args: [slot],
|
|
330
|
+
}),
|
|
331
|
+
lastNonce: (slot) => client.readContract({
|
|
332
|
+
address: requireAddress(addresses, 'Settlement'),
|
|
333
|
+
abi: settlementAbi,
|
|
334
|
+
functionName: 'lastNonce',
|
|
335
|
+
args: [slot],
|
|
336
|
+
}),
|
|
337
|
+
revenueSplit: () => client.readContract({
|
|
338
|
+
address: requireAddress(addresses, 'Settlement'),
|
|
339
|
+
abi: settlementAbi,
|
|
340
|
+
functionName: 'revenueSplit',
|
|
341
|
+
}),
|
|
342
|
+
totalHeld: () => client.readContract({
|
|
343
|
+
address: requireAddress(addresses, 'Settlement'),
|
|
344
|
+
abi: settlementAbi,
|
|
345
|
+
functionName: 'totalHeld',
|
|
346
|
+
}),
|
|
347
|
+
};
|
|
348
|
+
const token = {
|
|
349
|
+
totalSupply: () => client.readContract({
|
|
350
|
+
address: requireAddress(addresses, 'TasraToken'),
|
|
351
|
+
abi: tasraTokenAbi,
|
|
352
|
+
functionName: 'totalSupply',
|
|
353
|
+
}),
|
|
354
|
+
balanceOf: (a) => client.readContract({
|
|
355
|
+
address: requireAddress(addresses, 'TasraToken'),
|
|
356
|
+
abi: tasraTokenAbi,
|
|
357
|
+
functionName: 'balanceOf',
|
|
358
|
+
args: [a],
|
|
359
|
+
}),
|
|
360
|
+
symbol: () => client.readContract({
|
|
361
|
+
address: requireAddress(addresses, 'TasraToken'),
|
|
362
|
+
abi: tasraTokenAbi,
|
|
363
|
+
functionName: 'symbol',
|
|
364
|
+
}),
|
|
365
|
+
decimals: () => client.readContract({
|
|
366
|
+
address: requireAddress(addresses, 'TasraToken'),
|
|
367
|
+
abi: tasraTokenAbi,
|
|
368
|
+
functionName: 'decimals',
|
|
369
|
+
}),
|
|
370
|
+
};
|
|
371
|
+
const bondingCurve = {
|
|
372
|
+
spotPrice: () => client.readContract({
|
|
373
|
+
address: requireAddress(addresses, 'BondingCurve'),
|
|
374
|
+
abi: bondingCurveAbi,
|
|
375
|
+
functionName: 'spotPrice',
|
|
376
|
+
}),
|
|
377
|
+
weightedAvgPrice365d: () => client.readContract({
|
|
378
|
+
address: requireAddress(addresses, 'BondingCurve'),
|
|
379
|
+
abi: bondingCurveAbi,
|
|
380
|
+
functionName: 'weightedAvgPrice365d',
|
|
381
|
+
}),
|
|
382
|
+
soldTokens: () => client.readContract({
|
|
383
|
+
address: requireAddress(addresses, 'BondingCurve'),
|
|
384
|
+
abi: bondingCurveAbi,
|
|
385
|
+
functionName: 'soldTokens',
|
|
386
|
+
}),
|
|
387
|
+
reserve: () => client.readContract({
|
|
388
|
+
address: requireAddress(addresses, 'BondingCurve'),
|
|
389
|
+
abi: bondingCurveAbi,
|
|
390
|
+
functionName: 'reserve',
|
|
391
|
+
}),
|
|
392
|
+
};
|
|
393
|
+
const treasury = {
|
|
394
|
+
balance: () => client.readContract({
|
|
395
|
+
address: requireAddress(addresses, 'Treasury'),
|
|
396
|
+
abi: treasuryAbi,
|
|
397
|
+
functionName: 'balance',
|
|
398
|
+
}),
|
|
399
|
+
};
|
|
400
|
+
// The deploy creates one vesting vault per tranche, so the tranche is
|
|
401
|
+
// explicit: there is no "the vault" to default to.
|
|
402
|
+
//
|
|
403
|
+
// Two tranches can resolve to the same address when the book only carries
|
|
404
|
+
// the bare `TasraVestingVault` key (see `requireVaultAddress`). Anything that
|
|
405
|
+
// AGGREGATES across tranches must therefore de-duplicate on `address()` first,
|
|
406
|
+
// or it reports a multiple of the real locked supply.
|
|
407
|
+
/**
|
|
408
|
+
* Read one view function across many argument lists - the registry fan-out, and the
|
|
409
|
+
* only place in this client where the number of round trips is worth engineering.
|
|
410
|
+
*
|
|
411
|
+
* Where Multicall3 is deployed the whole list is one `eth_call` per chunk; where it is
|
|
412
|
+
* not, the reads are issued CONCURRENTLY rather than in a loop, so they overlap
|
|
413
|
+
* instead of queueing. Which mode is in use comes from a single cached
|
|
414
|
+
* {@link multicallAddress} probe, never from an assumption about the chain.
|
|
415
|
+
*
|
|
416
|
+
* Why it matters: a 10k-operator registry is ~40,000 view calls, which as sequential
|
|
417
|
+
* round trips is tens of minutes on any real RPC.
|
|
418
|
+
*
|
|
419
|
+
* A failing item is `null` in place - one unreadable operator must not blank the whole
|
|
420
|
+
* set. Pass `allowFailure: false` where POSITION carries meaning (an ordered operator
|
|
421
|
+
* set, whose indexes shift if one item is dropped); that rejects instead.
|
|
422
|
+
*/
|
|
423
|
+
async function readMany(contract, functionName, argsList, opts) {
|
|
424
|
+
if (argsList.length === 0)
|
|
425
|
+
return [];
|
|
426
|
+
const allowFailure = opts?.allowFailure ?? true;
|
|
427
|
+
// Resolved up front, and not swallowed: a missing address is a deployment mistake,
|
|
428
|
+
// not an unreadable item, and it must not come back as a list of nulls.
|
|
429
|
+
const address = requireAddress(addresses, contract);
|
|
430
|
+
const abi = CONTRACT_ABIS[contract];
|
|
431
|
+
/** The per-item path: one request each, concurrently. */
|
|
432
|
+
const individually = async () => Promise.all(argsList.map(args => client
|
|
433
|
+
.readContract({ address, abi, functionName, args: args })
|
|
434
|
+
.then(v => v)
|
|
435
|
+
.catch((error) => {
|
|
436
|
+
if (!allowFailure)
|
|
437
|
+
throw error;
|
|
438
|
+
return null;
|
|
439
|
+
})));
|
|
440
|
+
// One item is one call either way, so skip the probe rather than pay for it.
|
|
441
|
+
const at = argsList.length > 1 ? await multicallAddress() : null;
|
|
442
|
+
if (!at)
|
|
443
|
+
return individually();
|
|
444
|
+
// `allowFailure` at the viem layer is always true, whatever the caller asked for: a
|
|
445
|
+
// per-item revert must come back as a result we can inspect rather than as a thrown
|
|
446
|
+
// batch. Our own `allowFailure` then decides what that means.
|
|
447
|
+
//
|
|
448
|
+
// There is no try/catch here on purpose. Under `allowFailure: true` viem does not
|
|
449
|
+
// throw when the aggregate call itself is rejected - out of gas, payload refused,
|
|
450
|
+
// nothing at the address - it reports every ITEM as failed. So a catch block would be
|
|
451
|
+
// a guard that never fires, and the all-failed branch below is the one real recovery
|
|
452
|
+
// path. That behaviour is pinned by test/chain.read-client.ts, which is what would
|
|
453
|
+
// fail loudly if a viem upgrade ever changed it.
|
|
454
|
+
const results = await client.multicall({
|
|
455
|
+
contracts: argsList.map(args => ({ address, abi, functionName, args: args })),
|
|
456
|
+
allowFailure: true,
|
|
457
|
+
multicallAddress: at,
|
|
458
|
+
batchSize: MULTICALL_BATCH_BYTES,
|
|
459
|
+
});
|
|
460
|
+
if (results.some(r => r.status === 'success')) {
|
|
461
|
+
batchProven = true;
|
|
462
|
+
}
|
|
463
|
+
else if (!batchProven) {
|
|
464
|
+
// Everything failed on the first batch this client ever sent, which is ambiguous:
|
|
465
|
+
// either the batch mechanism is broken, or the items are unreadable.
|
|
466
|
+
// Settle it by reading them individually - once per client, only in this case. If
|
|
467
|
+
// they read fine the batch is at fault and must be abandoned; if they fail too, the
|
|
468
|
+
// batch was telling the truth and batching stays on.
|
|
469
|
+
const direct = await individually();
|
|
470
|
+
if (direct.some(v => v !== null)) {
|
|
471
|
+
disableMulticall();
|
|
472
|
+
return direct;
|
|
473
|
+
}
|
|
474
|
+
batchProven = true;
|
|
475
|
+
return direct;
|
|
476
|
+
}
|
|
477
|
+
if (!allowFailure) {
|
|
478
|
+
const failed = results.findIndex(r => r.status !== 'success');
|
|
479
|
+
if (failed >= 0) {
|
|
480
|
+
throw new Error(`readMany(${contract}.${functionName}): item ${failed} of ${argsList.length} failed and ` +
|
|
481
|
+
'allowFailure is false, so the result would misreport every later index', { cause: results[failed].error });
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
return results.map(r => (r.status === 'success' ? r.result : null));
|
|
485
|
+
}
|
|
486
|
+
const vault = (tranche) => {
|
|
487
|
+
const at = () => requireVaultAddress(addresses, tranche);
|
|
488
|
+
const get = (functionName) => () => client.readContract({ address: at(), abi: tasraVestingVaultAbi, functionName });
|
|
489
|
+
const getU64 = (functionName) => () => client.readContract({ address: at(), abi: tasraVestingVaultAbi, functionName });
|
|
490
|
+
return {
|
|
491
|
+
/** Which address this tranche resolves to - the de-duplication key. */
|
|
492
|
+
address: at,
|
|
493
|
+
released: get('released'),
|
|
494
|
+
remaining: get('remaining'),
|
|
495
|
+
totalLocked: get('totalLocked'),
|
|
496
|
+
startTime: getU64('startTime'),
|
|
497
|
+
cliffDuration: getU64('cliffDuration'),
|
|
498
|
+
linearDuration: getU64('linearDuration'),
|
|
499
|
+
/** Cumulative amount unlocked as of `ts`: 0 during the cliff, then linear. */
|
|
500
|
+
unlockedAt: (ts) => client.readContract({
|
|
501
|
+
address: at(),
|
|
502
|
+
abi: tasraVestingVaultAbi,
|
|
503
|
+
functionName: 'unlockedAt',
|
|
504
|
+
args: [ts],
|
|
505
|
+
}),
|
|
506
|
+
beneficiary: () => client.readContract({
|
|
507
|
+
address: at(),
|
|
508
|
+
abi: tasraVestingVaultAbi,
|
|
509
|
+
functionName: 'beneficiary',
|
|
510
|
+
}),
|
|
511
|
+
};
|
|
512
|
+
};
|
|
513
|
+
const beacon = {
|
|
514
|
+
seed: () => client.readContract({
|
|
515
|
+
address: requireAddress(addresses, 'ThresholdRandomBeacon'),
|
|
516
|
+
abi: thresholdRandomBeaconAbi,
|
|
517
|
+
functionName: 'seed',
|
|
518
|
+
}),
|
|
519
|
+
epoch: () => client.readContract({
|
|
520
|
+
address: requireAddress(addresses, 'ThresholdRandomBeacon'),
|
|
521
|
+
abi: thresholdRandomBeaconAbi,
|
|
522
|
+
functionName: 'epoch',
|
|
523
|
+
}),
|
|
524
|
+
/** The seed of a past epoch - what a committee draw pinned to `latest - 1` needs. */
|
|
525
|
+
seedAt: (epoch) => client.readContract({
|
|
526
|
+
address: requireAddress(addresses, 'ThresholdRandomBeacon'),
|
|
527
|
+
abi: thresholdRandomBeaconAbi,
|
|
528
|
+
functionName: 'seedAt',
|
|
529
|
+
args: [epoch],
|
|
530
|
+
}),
|
|
531
|
+
lastUpdate: () => client.readContract({
|
|
532
|
+
address: requireAddress(addresses, 'ThresholdRandomBeacon'),
|
|
533
|
+
abi: thresholdRandomBeaconAbi,
|
|
534
|
+
functionName: 'lastUpdate',
|
|
535
|
+
}),
|
|
536
|
+
mpk: () => client.readContract({
|
|
537
|
+
address: requireAddress(addresses, 'ThresholdRandomBeacon'),
|
|
538
|
+
abi: thresholdRandomBeaconAbi,
|
|
539
|
+
functionName: 'mpk',
|
|
540
|
+
}),
|
|
541
|
+
};
|
|
542
|
+
// W1 verifier-set snapshot - `size` is the committee draw's
|
|
543
|
+
// registrySize, `root` the Merkle root for trustless verifier proofs.
|
|
544
|
+
const verifierSet = {
|
|
545
|
+
snapshotAt: (epoch) => client.readContract({
|
|
546
|
+
address: requireAddress(addresses, 'VerifierSetRegistry'),
|
|
547
|
+
abi: verifierSetRegistryAbi,
|
|
548
|
+
functionName: 'snapshotAt',
|
|
549
|
+
args: [epoch],
|
|
550
|
+
}),
|
|
551
|
+
};
|
|
552
|
+
return {
|
|
553
|
+
client,
|
|
554
|
+
addresses,
|
|
555
|
+
deployedContracts,
|
|
556
|
+
logSources,
|
|
557
|
+
readMany: readMany,
|
|
558
|
+
multicallAddress,
|
|
559
|
+
getBlockNumber,
|
|
560
|
+
getLogsWindowed,
|
|
561
|
+
getBlockTimestamps,
|
|
562
|
+
read,
|
|
563
|
+
readers: {
|
|
564
|
+
serviceRegistry: createServiceRegistryReaders(client, () => requireAddress(addresses, 'ServiceRegistry')),
|
|
565
|
+
nodeRegistry,
|
|
566
|
+
keyRegistry,
|
|
567
|
+
settlement,
|
|
568
|
+
token,
|
|
569
|
+
bondingCurve,
|
|
570
|
+
treasury,
|
|
571
|
+
vault,
|
|
572
|
+
beacon,
|
|
573
|
+
verifierSet,
|
|
574
|
+
},
|
|
575
|
+
};
|
|
576
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Address, Hex } from 'viem';
|
|
2
|
+
import type { TasraChainClient } from './client.js';
|
|
3
|
+
/** A creation may keep its slot/rule inputs, but needs a durably saved new commit salt. */
|
|
4
|
+
export declare class SlotCommitmentExpiredError extends Error {
|
|
5
|
+
readonly chainId: number;
|
|
6
|
+
readonly keyRegistry: Address;
|
|
7
|
+
readonly slotId: Hex;
|
|
8
|
+
/** Expired commit-reveal commitment hash. */
|
|
9
|
+
readonly commitment: Hex;
|
|
10
|
+
readonly creator: Address;
|
|
11
|
+
readonly salt: Hex;
|
|
12
|
+
constructor(/** Chain containing the expired creation commitment. */ chainId: number, /** KeyRegistry contract that stores the commitment. */ keyRegistry: Address, /** Slot identifier reserved by the original creation intent. */ slotId: Hex,
|
|
13
|
+
/** Expired commit-reveal commitment hash. */
|
|
14
|
+
commitment: Hex, /** Account that submitted the original commitment. */ creator: Address, /** Original private commit salt; preserve it until outstanding requests are reconciled. */ salt: Hex);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Read-only recovery gate. The caller must also reconcile every outstanding signed request.
|
|
18
|
+
* @param chain Reader for the deployment owning the expired commitment.
|
|
19
|
+
* @param error Saved commitment context to check before replacing its commit salt.
|
|
20
|
+
*/
|
|
21
|
+
export declare function assertExpiredSlotCommitment(chain: TasraChainClient, error: SlotCommitmentExpiredError): Promise<void>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { keyRegistryAbi } from './abis/keyRegistry.js';
|
|
2
|
+
import { thresholdRandomBeaconAbi } from './abis/thresholdRandomBeacon.js';
|
|
3
|
+
/** A creation may keep its slot/rule inputs, but needs a durably saved new commit salt. */
|
|
4
|
+
export class SlotCommitmentExpiredError extends Error {
|
|
5
|
+
chainId;
|
|
6
|
+
keyRegistry;
|
|
7
|
+
slotId;
|
|
8
|
+
commitment;
|
|
9
|
+
creator;
|
|
10
|
+
salt;
|
|
11
|
+
constructor(/** Chain containing the expired creation commitment. */ chainId, /** KeyRegistry contract that stores the commitment. */ keyRegistry, /** Slot identifier reserved by the original creation intent. */ slotId,
|
|
12
|
+
/** Expired commit-reveal commitment hash. */
|
|
13
|
+
commitment, /** Account that submitted the original commitment. */ creator, /** Original private commit salt; preserve it until outstanding requests are reconciled. */ salt) {
|
|
14
|
+
super('Slot commitment expired; reconcile outstanding relay requests before replacing its commit salt');
|
|
15
|
+
this.chainId = chainId;
|
|
16
|
+
this.keyRegistry = keyRegistry;
|
|
17
|
+
this.slotId = slotId;
|
|
18
|
+
this.commitment = commitment;
|
|
19
|
+
this.creator = creator;
|
|
20
|
+
this.salt = salt;
|
|
21
|
+
this.name = 'SlotCommitmentExpiredError';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Read-only recovery gate. The caller must also reconcile every outstanding signed request.
|
|
26
|
+
* @param chain Reader for the deployment owning the expired commitment.
|
|
27
|
+
* @param error Saved commitment context to check before replacing its commit salt.
|
|
28
|
+
*/
|
|
29
|
+
export async function assertExpiredSlotCommitment(chain, error) {
|
|
30
|
+
const registry = chain.addresses.KeyRegistry;
|
|
31
|
+
if (registry?.toLowerCase() !== error.keyRegistry.toLowerCase() || await chain.client.getChainId() !== error.chainId) {
|
|
32
|
+
throw new Error('Commitment recovery belongs to a different deployment');
|
|
33
|
+
}
|
|
34
|
+
const blockNumber = await chain.client.getBlockNumber({ cacheTime: 0 });
|
|
35
|
+
const [slot, commit, beacon] = await Promise.all([
|
|
36
|
+
chain.client.readContract({ address: registry, abi: keyRegistryAbi, functionName: 'getKeySlot', args: [error.slotId], blockNumber }),
|
|
37
|
+
chain.client.readContract({ address: registry, abi: keyRegistryAbi, functionName: 'slotCommits', args: [error.commitment], blockNumber }),
|
|
38
|
+
chain.client.readContract({ address: registry, abi: keyRegistryAbi, functionName: 'randomBeacon', blockNumber }),
|
|
39
|
+
]);
|
|
40
|
+
const epoch = await chain.client.readContract({ address: beacon, abi: thresholdRandomBeaconAbi, functionName: 'epoch', blockNumber });
|
|
41
|
+
if (slot.exists || commit[3] || commit[2].toLowerCase() !== error.creator.toLowerCase() || commit[0] === 0n || epoch <= commit[1]) {
|
|
42
|
+
throw new Error('Commitment recovery requires an expired unused commitment and an absent slot');
|
|
43
|
+
}
|
|
44
|
+
}
|