@ocap/tx-pipeline 1.30.25 → 1.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/appchain-sovereign-hub.d.mts +160 -0
- package/esm/appchain-sovereign-hub.mjs +348 -0
- package/esm/arcvault-external-adapter.d.mts +166 -0
- package/esm/arcvault-external-adapter.mjs +376 -0
- package/esm/encrypted-nft-envelope.d.mts +172 -0
- package/esm/encrypted-nft-envelope.mjs +458 -0
- package/esm/evm-simplified-bridge.d.mts +1370 -0
- package/esm/evm-simplified-bridge.mjs +3875 -0
- package/esm/give-to-mint-karma.d.mts +472 -0
- package/esm/give-to-mint-karma.mjs +1057 -0
- package/esm/helpers/replay-guard.d.mts +15 -0
- package/esm/helpers/replay-guard.mjs +23 -0
- package/esm/index.d.mts +10 -5
- package/esm/index.mjs +14 -10
- package/esm/legacy-protocol-sunset.d.mts +251 -0
- package/esm/legacy-protocol-sunset.mjs +1519 -0
- package/esm/library.d.mts +16 -0
- package/esm/library.mjs +17 -0
- package/esm/native-abt-exchange.d.mts +2055 -0
- package/esm/native-abt-exchange.mjs +7250 -0
- package/esm/ofac-screening.d.mts +17 -0
- package/esm/ofac-screening.mjs +39 -0
- package/esm/pipes/anti-land-attack.mjs +1 -1
- package/esm/pipes/decode-itx.mjs +43 -4
- package/esm/pipes/decode-tx.d.mts +2 -3
- package/esm/pipes/decode-tx.mjs +53 -115
- package/esm/pipes/extract-signer.mjs +2 -2
- package/esm/pipes/extract-state.mjs +14 -3
- package/esm/pipes/post-execution-invariant-gate.d.mts +61 -0
- package/esm/pipes/post-execution-invariant-gate.mjs +789 -0
- package/esm/pipes/pre-flight-waf.d.mts +34 -0
- package/esm/pipes/pre-flight-waf.mjs +603 -0
- package/esm/pipes/take-state-snapshot.mjs +3 -2
- package/esm/pipes/update-owner.mjs +39 -4
- package/esm/pipes/verify-account-migration.mjs +14 -4
- package/esm/pipes/verify-blocked.mjs +1 -1
- package/esm/pipes/verify-delegation.d.mts +22 -3
- package/esm/pipes/verify-delegation.mjs +259 -36
- package/esm/pipes/verify-list-size.mjs +1 -1
- package/esm/pipes/verify-multisig-v2.mjs +15 -7
- package/esm/pipes/verify-multisig.mjs +15 -7
- package/esm/pipes/verify-sender.mjs +1 -1
- package/esm/pipes/verify-signature.mjs +35 -6
- package/esm/pipes/verify-signer.mjs +2 -2
- package/esm/pipes/verify-state-diff.mjs +3 -3
- package/esm/pipes/verify-token-access.mjs +1 -1
- package/esm/pipes/verify-token-balance.mjs +13 -5
- package/esm/pipes/verify-transferrable.d.mts +8 -1
- package/esm/pipes/verify-transferrable.mjs +3 -3
- package/esm/pipes/verify-tx-input.mjs +2 -2
- package/esm/pipes/verify-tx-size.mjs +46 -2
- package/esm/pipes/verify-tx.mjs +5 -7
- package/esm/pipes/verify-updater.mjs +1 -1
- package/esm/social-economy-factories.d.mts +346 -0
- package/esm/social-economy-factories.mjs +845 -0
- package/esm/super-suites-foundation.d.mts +513 -0
- package/esm/super-suites-foundation.mjs +1241 -0
- package/esm/transaction-block.d.mts +471 -0
- package/esm/transaction-block.mjs +1906 -0
- package/esm/uniswap-erc7683-solver.d.mts +201 -0
- package/esm/uniswap-erc7683-solver.mjs +321 -0
- package/esm/uniswap-lp-copilot.d.mts +113 -0
- package/esm/uniswap-lp-copilot.mjs +320 -0
- package/esm/uniswap-router.d.mts +335 -0
- package/esm/uniswap-router.mjs +578 -0
- package/esm/uniswap-token-factory-graduation.d.mts +187 -0
- package/esm/uniswap-token-factory-graduation.mjs +426 -0
- package/esm/uniswap-v4-hook.d.mts +173 -0
- package/esm/uniswap-v4-hook.mjs +517 -0
- package/lib/appchain-sovereign-hub.cjs +352 -0
- package/lib/appchain-sovereign-hub.d.cts +160 -0
- package/lib/arcvault-external-adapter.cjs +383 -0
- package/lib/arcvault-external-adapter.d.cts +166 -0
- package/lib/encrypted-nft-envelope.cjs +477 -0
- package/lib/encrypted-nft-envelope.d.cts +172 -0
- package/lib/evm-simplified-bridge.cjs +3943 -0
- package/lib/evm-simplified-bridge.d.cts +1370 -0
- package/lib/give-to-mint-karma.cjs +1084 -0
- package/lib/give-to-mint-karma.d.cts +472 -0
- package/lib/helpers/replay-guard.cjs +27 -0
- package/lib/helpers/replay-guard.d.cts +15 -0
- package/lib/index.cjs +49 -16
- package/lib/index.d.cts +10 -5
- package/lib/legacy-protocol-sunset.cjs +1543 -0
- package/lib/legacy-protocol-sunset.d.cts +251 -0
- package/lib/library.cjs +303 -0
- package/lib/library.d.cts +16 -0
- package/lib/native-abt-exchange.cjs +7322 -0
- package/lib/native-abt-exchange.d.cts +2055 -0
- package/lib/ofac-screening.cjs +42 -0
- package/lib/ofac-screening.d.cts +17 -0
- package/lib/pipes/anti-land-attack.cjs +2 -2
- package/lib/pipes/decode-itx.cjs +43 -4
- package/lib/pipes/decode-itx.d.cts +1 -1
- package/lib/pipes/decode-tx.cjs +52 -116
- package/lib/pipes/decode-tx.d.cts +3 -4
- package/lib/pipes/extract-signer.cjs +2 -2
- package/lib/pipes/extract-state.cjs +14 -3
- package/lib/pipes/post-execution-invariant-gate.cjs +800 -0
- package/lib/pipes/post-execution-invariant-gate.d.cts +61 -0
- package/lib/pipes/pre-flight-waf.cjs +616 -0
- package/lib/pipes/pre-flight-waf.d.cts +34 -0
- package/lib/pipes/take-state-snapshot.cjs +3 -2
- package/lib/pipes/update-owner.cjs +40 -5
- package/lib/pipes/update-owner.d.cts +1 -1
- package/lib/pipes/verify-account-migration.cjs +14 -4
- package/lib/pipes/verify-blocked.cjs +1 -1
- package/lib/pipes/verify-delegation.cjs +259 -36
- package/lib/pipes/verify-delegation.d.cts +22 -3
- package/lib/pipes/verify-list-size.cjs +1 -1
- package/lib/pipes/verify-multisig-v2.cjs +15 -7
- package/lib/pipes/verify-multisig.cjs +15 -7
- package/lib/pipes/verify-sender.cjs +1 -1
- package/lib/pipes/verify-service-fee.d.cts +1 -1
- package/lib/pipes/verify-signature.cjs +35 -6
- package/lib/pipes/verify-signature.d.cts +1 -1
- package/lib/pipes/verify-signer.cjs +2 -2
- package/lib/pipes/verify-state-diff.cjs +4 -4
- package/lib/pipes/verify-token-access.cjs +2 -2
- package/lib/pipes/verify-token-balance.cjs +13 -5
- package/lib/pipes/verify-transferrable.cjs +3 -3
- package/lib/pipes/verify-transferrable.d.cts +8 -1
- package/lib/pipes/verify-tx-input.cjs +3 -3
- package/lib/pipes/verify-tx-size.cjs +46 -2
- package/lib/pipes/verify-tx-size.d.cts +1 -1
- package/lib/pipes/verify-tx.cjs +6 -8
- package/lib/pipes/verify-tx.d.cts +1 -1
- package/lib/pipes/verify-updater.cjs +1 -1
- package/lib/social-economy-factories.cjs +852 -0
- package/lib/social-economy-factories.d.cts +346 -0
- package/lib/super-suites-foundation.cjs +1257 -0
- package/lib/super-suites-foundation.d.cts +513 -0
- package/lib/transaction-block.cjs +1941 -0
- package/lib/transaction-block.d.cts +471 -0
- package/lib/uniswap-erc7683-solver.cjs +327 -0
- package/lib/uniswap-erc7683-solver.d.cts +201 -0
- package/lib/uniswap-lp-copilot.cjs +328 -0
- package/lib/uniswap-lp-copilot.d.cts +113 -0
- package/lib/uniswap-router.cjs +593 -0
- package/lib/uniswap-router.d.cts +335 -0
- package/lib/uniswap-token-factory-graduation.cjs +431 -0
- package/lib/uniswap-token-factory-graduation.d.cts +187 -0
- package/lib/uniswap-v4-hook.cjs +527 -0
- package/lib/uniswap-v4-hook.d.cts +173 -0
- package/package.json +11 -10
- package/esm/helpers/dedup-height.d.mts +0 -16
- package/esm/helpers/dedup-height.mjs +0 -61
- package/lib/helpers/dedup-height.cjs +0 -72
- package/lib/helpers/dedup-height.d.cts +0 -16
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
import { BN } from "@ocap/util";
|
|
2
|
+
import { CustomError } from "@ocap/util/lib/error";
|
|
3
|
+
|
|
4
|
+
//#region src/transaction-block.d.ts
|
|
5
|
+
declare const MAX_TX_BLOCK_BYTES = 16384;
|
|
6
|
+
declare const MAX_TX_BLOCK_TOP_LEVEL_STATEMENTS = 16;
|
|
7
|
+
declare const HARD_MAX_TX_BLOCK_STATEMENTS = 64;
|
|
8
|
+
declare const MAX_TX_BLOCK_TOTAL_EXPANDED_STATEMENTS = 32;
|
|
9
|
+
declare const MAX_TX_BLOCK_READ_KEYS = 64;
|
|
10
|
+
declare const MAX_TX_BLOCK_WRITE_KEYS = 32;
|
|
11
|
+
declare const MAX_TX_BLOCK_STATE_DIFF_ENTRIES = 48;
|
|
12
|
+
declare const MAX_EXECUTE_ASSET_DEPTH = 1;
|
|
13
|
+
declare const MAX_EXECUTE_ASSET_CALLS_PER_BLOCK = 4;
|
|
14
|
+
interface TransactionBlockResourceBudget {
|
|
15
|
+
maxBytes?: number;
|
|
16
|
+
maxTopLevelStatements?: number;
|
|
17
|
+
maxTotalExpandedStatements?: number;
|
|
18
|
+
maxReadKeys?: number;
|
|
19
|
+
maxWriteKeys?: number;
|
|
20
|
+
maxStateDiffEntries?: number;
|
|
21
|
+
maxExecuteAssetCallsPerBlock?: number;
|
|
22
|
+
}
|
|
23
|
+
interface TransactionBlockPostConditions {
|
|
24
|
+
/**
|
|
25
|
+
* Maximum allowed net token outflow per account DID and token address:
|
|
26
|
+
* `{ [accountDid]: { [tokenAddress]: "100" } }`
|
|
27
|
+
*/
|
|
28
|
+
maxTokenOutflow?: Record<string, Record<string, string>>;
|
|
29
|
+
/**
|
|
30
|
+
* Minimum required net token inflow per account DID and token address:
|
|
31
|
+
* `{ [accountDid]: { [tokenAddress]: "250" } }`
|
|
32
|
+
*/
|
|
33
|
+
minTokenInflow?: Record<string, Record<string, string>>;
|
|
34
|
+
/**
|
|
35
|
+
* Explicit allowlist of asset DIDs permitted to leave `accountDid`'s ownership
|
|
36
|
+
* (or be consumed/deleted) during this TransactionBlock.
|
|
37
|
+
*/
|
|
38
|
+
allowedOutgoingAssets?: Record<string, string[]>;
|
|
39
|
+
/**
|
|
40
|
+
* Asset DIDs that MUST be owned by `accountDid` (and unconsumed) when the TransactionBlock completes.
|
|
41
|
+
*/
|
|
42
|
+
mustOwnAssetsAfter?: Record<string, string[]>;
|
|
43
|
+
/**
|
|
44
|
+
* Defaults to `true` when `postConditions` is present:
|
|
45
|
+
* Any net token or asset outflow from `block.from` (or accounts listed in `maxTokenOutflow` / `allowedOutgoingAssets`)
|
|
46
|
+
* not explicitly authorized in `maxTokenOutflow` / `allowedOutgoingAssets` triggers `POST_CONDITION_VIOLATION`.
|
|
47
|
+
*/
|
|
48
|
+
strictZeroUnlistedOutflow?: boolean;
|
|
49
|
+
}
|
|
50
|
+
interface WalletClearSigningPreview {
|
|
51
|
+
signerDid: string;
|
|
52
|
+
blockId: string;
|
|
53
|
+
totalTopLevelStatements: number;
|
|
54
|
+
totalExpandedStatements: number;
|
|
55
|
+
byteSize: number;
|
|
56
|
+
footprint: StateFootprint;
|
|
57
|
+
signerTokenOutflows: Array<{
|
|
58
|
+
tokenAddress: string;
|
|
59
|
+
amount: string;
|
|
60
|
+
}>;
|
|
61
|
+
signerTokenInflows: Array<{
|
|
62
|
+
tokenAddress: string;
|
|
63
|
+
amount: string;
|
|
64
|
+
}>;
|
|
65
|
+
signerAssetsSent: string[];
|
|
66
|
+
signerAssetsReceived: string[];
|
|
67
|
+
invokedExecuteAssets: string[];
|
|
68
|
+
humanReadableLines: {
|
|
69
|
+
youPaySummary: string;
|
|
70
|
+
actionsSummary: string;
|
|
71
|
+
youReceiveSummary: string;
|
|
72
|
+
};
|
|
73
|
+
suggestedPostConditions: TransactionBlockPostConditions;
|
|
74
|
+
riskLevel: 'LOW' | 'MEDIUM' | 'HIGH';
|
|
75
|
+
riskReasons: string[];
|
|
76
|
+
}
|
|
77
|
+
interface StateFootprint {
|
|
78
|
+
readSet: string[];
|
|
79
|
+
writeSet: string[];
|
|
80
|
+
}
|
|
81
|
+
interface StateDiffEntry<T = Record<string, any>> {
|
|
82
|
+
table: string;
|
|
83
|
+
key: string;
|
|
84
|
+
op: 'create' | 'update' | 'delete';
|
|
85
|
+
before: T | null;
|
|
86
|
+
after: T | null;
|
|
87
|
+
}
|
|
88
|
+
interface TransactionStatement<TItx = Record<string, any>> {
|
|
89
|
+
id?: string;
|
|
90
|
+
type?: string;
|
|
91
|
+
typeUrl?: string;
|
|
92
|
+
from?: string;
|
|
93
|
+
delegator?: string;
|
|
94
|
+
itx: TItx;
|
|
95
|
+
readSet?: string[];
|
|
96
|
+
writeSet?: string[];
|
|
97
|
+
}
|
|
98
|
+
interface TransactionBlockInput {
|
|
99
|
+
id?: string;
|
|
100
|
+
from: string;
|
|
101
|
+
delegator?: string;
|
|
102
|
+
statements: TransactionStatement[];
|
|
103
|
+
readSet?: string[];
|
|
104
|
+
writeSet?: string[];
|
|
105
|
+
enforceZeroSum?: boolean;
|
|
106
|
+
postConditions?: TransactionBlockPostConditions;
|
|
107
|
+
resourceBudget?: TransactionBlockResourceBudget;
|
|
108
|
+
}
|
|
109
|
+
type StatementExecutor = (statement: TransactionStatement, statedb: OverlayStateDB, context: {
|
|
110
|
+
stepIndex: number;
|
|
111
|
+
stepOutputs: Record<string, any>[];
|
|
112
|
+
block: TransactionBlockInput;
|
|
113
|
+
}) => Promise<Record<string, any> | undefined>;
|
|
114
|
+
interface TransactionBlockResult {
|
|
115
|
+
ok: boolean;
|
|
116
|
+
blockId: string;
|
|
117
|
+
dryRun: boolean;
|
|
118
|
+
committed: boolean;
|
|
119
|
+
footprint: StateFootprint;
|
|
120
|
+
stateDiff: StateDiffEntry[];
|
|
121
|
+
tokenDeltas: Record<string, string>;
|
|
122
|
+
stepOutputs: Record<string, any>[];
|
|
123
|
+
totalExpandedStatements?: number;
|
|
124
|
+
invokedExecuteAssets?: string[];
|
|
125
|
+
degradedToDepositOnly?: boolean;
|
|
126
|
+
purchaseError?: string;
|
|
127
|
+
error?: CustomError;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* 1. Solana-Style Static & Explicit Read/Write State Footprint Extractor (`extractStateFootprint`)
|
|
131
|
+
* Derives `{ readSet, writeSet }` from any single OCAP transaction, statement, or multi-statement
|
|
132
|
+
* `TransactionBlock` without executing business logic.
|
|
133
|
+
*/
|
|
134
|
+
declare function extractStateFootprint(input: TransactionBlockInput | TransactionStatement | {
|
|
135
|
+
from?: string;
|
|
136
|
+
delegator?: string;
|
|
137
|
+
signatures?: Array<{
|
|
138
|
+
signer?: string;
|
|
139
|
+
delegator?: string;
|
|
140
|
+
}>;
|
|
141
|
+
signaturesList?: Array<{
|
|
142
|
+
signer?: string;
|
|
143
|
+
delegator?: string;
|
|
144
|
+
}>;
|
|
145
|
+
itx?: Record<string, any>;
|
|
146
|
+
statements?: TransactionStatement[];
|
|
147
|
+
readSet?: string[];
|
|
148
|
+
writeSet?: string[];
|
|
149
|
+
}): StateFootprint;
|
|
150
|
+
/**
|
|
151
|
+
* Determine whether two transactions or `TransactionBlock`s have a Read/Write or Write/Write conflict:
|
|
152
|
+
* $(W_A \cap (R_B \cup W_B)) \neq \emptyset \lor (W_B \cap (R_A \cup W_A)) \neq \emptyset$.
|
|
153
|
+
*/
|
|
154
|
+
declare function hasStateConflict(fpA: StateFootprint, fpB: StateFootprint): boolean;
|
|
155
|
+
declare const DEFAULT_MAX_STATEMENTS_PER_HOT_KEY_PER_BLOCK = 32;
|
|
156
|
+
/**
|
|
157
|
+
* Partition a batch of transactions or `TransactionBlock`s into deterministic, conflict-free
|
|
158
|
+
* parallel waves (Solana Sealevel / deterministic wave scheduler).
|
|
159
|
+
*
|
|
160
|
+
* When `options.maxStatementsPerHotKeyPerBlock` is provided, any item whose `writeSet` touches
|
|
161
|
+
* a hot state key that has already reached the per-block write quota is deferred into
|
|
162
|
+
* `deferredByHotKeyQuota`, preventing sniper storms on a single hot `TokenFactory` from
|
|
163
|
+
* creating hundreds of sequential waves and starving unrelated transactions.
|
|
164
|
+
*/
|
|
165
|
+
declare function scheduleParallelBatches<T>(items: T[], getFootprint?: (item: T) => StateFootprint, options?: {
|
|
166
|
+
maxStatementsPerHotKeyPerBlock?: number;
|
|
167
|
+
}): {
|
|
168
|
+
waves: T[][];
|
|
169
|
+
footprints: StateFootprint[];
|
|
170
|
+
deferredByHotKeyQuota: T[];
|
|
171
|
+
};
|
|
172
|
+
declare class OverlayStateDB {
|
|
173
|
+
private readonly base;
|
|
174
|
+
private writes;
|
|
175
|
+
private reads;
|
|
176
|
+
private runtimeIoBudget;
|
|
177
|
+
private savepoints;
|
|
178
|
+
[key: string]: any;
|
|
179
|
+
constructor(baseStateDB: Record<string, any>, tables?: readonly string[]);
|
|
180
|
+
setRuntimeIoBudget(budget: {
|
|
181
|
+
maxReadKeys: number;
|
|
182
|
+
maxWriteKeys: number;
|
|
183
|
+
staticReadSet?: readonly string[];
|
|
184
|
+
staticWriteSet?: readonly string[];
|
|
185
|
+
} | null): void;
|
|
186
|
+
private getTableWrites;
|
|
187
|
+
private getTableReads;
|
|
188
|
+
private assertLiveReadBudget;
|
|
189
|
+
private assertLiveWriteBudget;
|
|
190
|
+
private readBase;
|
|
191
|
+
getBaseSnapshot(table: string, rawKey: string, ctx?: unknown): Promise<any>;
|
|
192
|
+
hasTableWrite(table: string, rawKey: string): boolean;
|
|
193
|
+
private createTableProxy;
|
|
194
|
+
createSavepoint(): number;
|
|
195
|
+
rollbackToSavepoint(savepointId: number): void;
|
|
196
|
+
releaseSavepoint(savepointId: number): void;
|
|
197
|
+
discard(): void;
|
|
198
|
+
getTouchedTableReadKeys(): string[];
|
|
199
|
+
getTouchedTableWriteKeys(): string[];
|
|
200
|
+
getReadKeys(): string[];
|
|
201
|
+
getWriteKeys(): string[];
|
|
202
|
+
getStateDiff(): StateDiffEntry[];
|
|
203
|
+
/**
|
|
204
|
+
* Compute net token balance changes across all modified `account` and `stake` rows,
|
|
205
|
+
* subtracting authorized supply mints/burns in `token` / `tokenFactory`, to verify strict zero-sum conservation
|
|
206
|
+
* and guarantee no post-state balance or supply is negative or malformed.
|
|
207
|
+
*/
|
|
208
|
+
verifyZeroSumConservation(): {
|
|
209
|
+
valid: boolean;
|
|
210
|
+
netUnbackedDeltas: Record<string, string>;
|
|
211
|
+
};
|
|
212
|
+
/**
|
|
213
|
+
* Verify that the underlying `baseStateDB` has not changed since the overlay read snapshot was taken
|
|
214
|
+
* (Optimistic Concurrency Control check for 2PC Commit).
|
|
215
|
+
*/
|
|
216
|
+
verifyBaseUnchanged(ctx?: unknown): Promise<boolean>;
|
|
217
|
+
commit(ctx?: unknown): Promise<StateDiffEntry[]>;
|
|
218
|
+
}
|
|
219
|
+
declare function createOverlayStateDB(baseStateDB: Record<string, any>): OverlayStateDB;
|
|
220
|
+
/**
|
|
221
|
+
* Resolve `$steps[i].<path>` references inside a statement's `itx` so output values from
|
|
222
|
+
* earlier statements in a `TransactionBlock` can be piped into subsequent statements (Sui PTB style).
|
|
223
|
+
*/
|
|
224
|
+
declare function resolveStatementReferences<T>(value: T, stepOutputs: Record<string, any>[], currentStepIndex: number, depth?: number): T;
|
|
225
|
+
declare function isExecuteAssetStatement(stmt: TransactionStatement | Record<string, any>): boolean;
|
|
226
|
+
/**
|
|
227
|
+
* Enforces `MAX_EXECUTE_ASSET_DEPTH = 1`:
|
|
228
|
+
* Any statement inside `statementTemplates` (Depth 1) MUST be a leaf atomic primitive and CANNOT
|
|
229
|
+
* recursively invoke `execute_asset`, `contract_nft`, `transaction_block`, or carry nested `statementTemplates`.
|
|
230
|
+
*/
|
|
231
|
+
declare function assertLeafStatementTemplateOnly(templateStmt: TransactionStatement | Record<string, any>, label?: string): void;
|
|
232
|
+
interface ResolvedTransactionBlockBudget {
|
|
233
|
+
readonly maxBytes: number;
|
|
234
|
+
readonly maxTopLevelStatements: number;
|
|
235
|
+
readonly maxTotalExpandedStatements: number;
|
|
236
|
+
readonly maxReadKeys: number;
|
|
237
|
+
readonly maxWriteKeys: number;
|
|
238
|
+
readonly maxStateDiffEntries: number;
|
|
239
|
+
readonly maxExecuteAssetCallsPerBlock: number;
|
|
240
|
+
}
|
|
241
|
+
declare function resolveEffectiveResourceBudget(block: TransactionBlockInput, nodeBudget?: TransactionBlockResourceBudget): ResolvedTransactionBlockBudget;
|
|
242
|
+
/**
|
|
243
|
+
* Issue #1253 Guardrail #1 & #3:
|
|
244
|
+
* Statically validates the 4D resource budget (byte size, top-level & expanded statement counts,
|
|
245
|
+
* static read/write I/O footprint keys, and single-layer `execute_asset` depth/call limits)
|
|
246
|
+
* BEFORE touching `OverlayStateDB`.
|
|
247
|
+
*/
|
|
248
|
+
declare function assertTransactionBlockResourceBudget(block: TransactionBlockInput, nodeBudget?: TransactionBlockResourceBudget): {
|
|
249
|
+
budget: ResolvedTransactionBlockBudget;
|
|
250
|
+
byteSize: number;
|
|
251
|
+
staticExpandedStatements: number;
|
|
252
|
+
executeAssetTargets: string[];
|
|
253
|
+
staticFootprint: StateFootprint;
|
|
254
|
+
};
|
|
255
|
+
/**
|
|
256
|
+
* Computes net per-account liquid spendable token deltas and asset ownership changes from `StateDiffEntry[]`.
|
|
257
|
+
* - RT-1253-3: Strictly attributes account token deltas to `diff.key` on `diff.table === 'account'` (never `diff.after.owner` or `stake`).
|
|
258
|
+
* - RT-1253-4: Uses `min(liquidDelta, totalDelta)` so locking liquid tokens into `pendingTokens` is caught as outflow, while fake `pendingTokens` credits cannot spoof `minTokenInflow`.
|
|
259
|
+
* - RT-1253-5: Rejects malformed/negative token balances immediately with `ACCOUNTING_INVARIANT_VIOLATION`.
|
|
260
|
+
* - RT-1253-9: Checks `!diff.before?.consumedTime` symmetrically on `beforeOwner`.
|
|
261
|
+
*/
|
|
262
|
+
declare function computeAccountAndAssetNetEffects(stateDiff: StateDiffEntry[]): {
|
|
263
|
+
accountTokenNetDeltas: Map<string, Map<string, BN>>;
|
|
264
|
+
outgoingAssetsByOwner: Map<string, Set<string>>;
|
|
265
|
+
incomingAssetsByOwner: Map<string, Set<string>>;
|
|
266
|
+
};
|
|
267
|
+
/**
|
|
268
|
+
* Issue #1253 Guardrail #2:
|
|
269
|
+
* Enforces user-signed `TransactionBlockPostConditions` against the actual `OverlayStateDB` diff
|
|
270
|
+
* prior to committing. Any excess token outflow, missing minimum inflow, or unauthorized asset transfer
|
|
271
|
+
* triggers an immediate `POST_CONDITION_VIOLATION` rollback.
|
|
272
|
+
*/
|
|
273
|
+
declare function verifyTransactionBlockPostConditions(block: TransactionBlockInput, stateDiff: StateDiffEntry[], overlay: OverlayStateDB): Promise<void>;
|
|
274
|
+
/**
|
|
275
|
+
* 3. SQL-Style Multi-Statement `TransactionBlock` Execution + Zero-Side-Effect `Dry-Run`
|
|
276
|
+
* + Issue #1253 Hard Guardrails (4D Size/I/O Budget, Enforced PostConditions, Single-Layer execute_asset Sandbox)
|
|
277
|
+
*/
|
|
278
|
+
declare function executeTransactionBlock(block: TransactionBlockInput, options: {
|
|
279
|
+
statedb: Record<string, any>;
|
|
280
|
+
executeStatement: StatementExecutor;
|
|
281
|
+
dryRun?: boolean;
|
|
282
|
+
operationContext?: unknown;
|
|
283
|
+
resourceBudget?: TransactionBlockResourceBudget;
|
|
284
|
+
inlineExpandExecuteAsset?: boolean;
|
|
285
|
+
}): Promise<TransactionBlockResult>;
|
|
286
|
+
/**
|
|
287
|
+
* Issue #1253 Guardrail #2:
|
|
288
|
+
* Generates a human-comprehensible Wallet Clear-Signing Preview (`WalletClearSigningPreview`)
|
|
289
|
+
* by simulating the `TransactionBlock` in zero-side-effect `dryRun: true` mode on `OverlayStateDB`.
|
|
290
|
+
* Summarizes net token outflows, net token inflows, asset transfers, invoked `execute_asset` contracts,
|
|
291
|
+
* tight suggested `postConditions`, and deterministic `riskLevel` (`LOW` | `MEDIUM` | `HIGH`).
|
|
292
|
+
*/
|
|
293
|
+
declare function buildWalletClearSigningPreview(block: TransactionBlockInput, options: {
|
|
294
|
+
statedb: Record<string, any>;
|
|
295
|
+
executeStatement: StatementExecutor;
|
|
296
|
+
signerDid?: string;
|
|
297
|
+
resourceBudget?: TransactionBlockResourceBudget;
|
|
298
|
+
}): Promise<WalletClearSigningPreview>;
|
|
299
|
+
/**
|
|
300
|
+
* 4. Classic Two-Phase Commit (`2PC: PREPARE -> COMMIT / ABORT`) Coordinator +
|
|
301
|
+
* TigerBeetle-Style Two-Phase Pending Transfers (`PENDING -> POST / VOID`).
|
|
302
|
+
*/
|
|
303
|
+
interface PreparedTransactionBlock {
|
|
304
|
+
preparedId: string;
|
|
305
|
+
block: TransactionBlockInput;
|
|
306
|
+
footprint: StateFootprint;
|
|
307
|
+
stateDiff: StateDiffEntry[];
|
|
308
|
+
stepOutputs: Record<string, any>[];
|
|
309
|
+
timeoutHeight: number;
|
|
310
|
+
status: 'PREPARED' | 'COMMITTED' | 'ABORTED';
|
|
311
|
+
overlay: OverlayStateDB;
|
|
312
|
+
}
|
|
313
|
+
declare class TwoPhaseCommitCoordinator {
|
|
314
|
+
private readonly preparedBlocks;
|
|
315
|
+
private evictExpired;
|
|
316
|
+
prepare(block: TransactionBlockInput, options: {
|
|
317
|
+
statedb: Record<string, any>;
|
|
318
|
+
executeStatement: StatementExecutor;
|
|
319
|
+
currentHeight: number;
|
|
320
|
+
timeoutHeight: number;
|
|
321
|
+
}): Promise<PreparedTransactionBlock>;
|
|
322
|
+
commit(preparedId: string, options: {
|
|
323
|
+
currentHeight: number;
|
|
324
|
+
operationContext?: unknown;
|
|
325
|
+
}): Promise<StateDiffEntry[]>;
|
|
326
|
+
abort(preparedId: string): PreparedTransactionBlock;
|
|
327
|
+
getPrepared(preparedId: string): PreparedTransactionBlock | undefined;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* TigerBeetle-Style Two-Phase Pending Transfer Primitives (`PENDING -> POST / VOID`)
|
|
331
|
+
* Escrows funds inside `account.pendingTokens` during `PENDING`, then settles to `creditAddress`
|
|
332
|
+
* on `POST` or refunds to `debitAddress.tokens` on `VOID` (preserving strict zero-sum conservation at every step).
|
|
333
|
+
*/
|
|
334
|
+
interface PendingTransferRecord {
|
|
335
|
+
id: string;
|
|
336
|
+
debitAddress: string;
|
|
337
|
+
creditAddress: string;
|
|
338
|
+
tokenAddress: string;
|
|
339
|
+
amount: string;
|
|
340
|
+
timeoutHeight: number;
|
|
341
|
+
status: 'PENDING' | 'POSTED' | 'VOIDED';
|
|
342
|
+
}
|
|
343
|
+
declare class TwoPhaseTransferLedger {
|
|
344
|
+
private readonly transfers;
|
|
345
|
+
createPendingTransfer(params: {
|
|
346
|
+
id: string;
|
|
347
|
+
debitAddress: string;
|
|
348
|
+
creditAddress: string;
|
|
349
|
+
tokenAddress: string;
|
|
350
|
+
amount: string;
|
|
351
|
+
currentHeight: number;
|
|
352
|
+
timeoutHeight: number;
|
|
353
|
+
}, statedb: Record<string, any>): Promise<PendingTransferRecord>;
|
|
354
|
+
postPendingTransfer(params: {
|
|
355
|
+
id: string;
|
|
356
|
+
currentHeight: number;
|
|
357
|
+
}, statedb: Record<string, any>): Promise<PendingTransferRecord>;
|
|
358
|
+
voidPendingTransfer(params: {
|
|
359
|
+
id: string;
|
|
360
|
+
}, statedb: Record<string, any>): Promise<PendingTransferRecord>;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* 5. NFT-as-a-Smart-Contract (`ContractNFT`: `@ocap/contract` Declarative Guard + Parameterized `TransactionBlock` Stored Procedure)
|
|
364
|
+
*/
|
|
365
|
+
declare const CONTRACT_NFT_KIND: "ContractNFT";
|
|
366
|
+
declare const MAX_CONTRACT_NFT_STATEMENTS = 16;
|
|
367
|
+
declare const MAX_CONTRACT_ARGS_BYTES = 16384;
|
|
368
|
+
declare const MAX_CONTRACT_FOOTPRINT_KEYS = 64;
|
|
369
|
+
interface ContractGuardPredicate {
|
|
370
|
+
field: string;
|
|
371
|
+
op: 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'in';
|
|
372
|
+
value: any;
|
|
373
|
+
}
|
|
374
|
+
interface ContractNftPayload {
|
|
375
|
+
kind: typeof CONTRACT_NFT_KIND;
|
|
376
|
+
name: string;
|
|
377
|
+
version: string;
|
|
378
|
+
allowedCallers?: string[];
|
|
379
|
+
guards?: ContractGuardPredicate[];
|
|
380
|
+
statementTemplates: TransactionStatement[];
|
|
381
|
+
}
|
|
382
|
+
declare function executeContractNft(params: {
|
|
383
|
+
contractAsset: {
|
|
384
|
+
address: string;
|
|
385
|
+
owner: string;
|
|
386
|
+
consumedTime?: string;
|
|
387
|
+
data?: {
|
|
388
|
+
type?: string;
|
|
389
|
+
value?: ContractNftPayload;
|
|
390
|
+
} | null;
|
|
391
|
+
};
|
|
392
|
+
caller: string;
|
|
393
|
+
args: Record<string, any>;
|
|
394
|
+
statedb: Record<string, any>;
|
|
395
|
+
executeStatement: StatementExecutor;
|
|
396
|
+
dryRun?: boolean;
|
|
397
|
+
}): Promise<TransactionBlockResult>;
|
|
398
|
+
/**
|
|
399
|
+
* 6. Reth-Style Staged Sync & Unwindable Pipeline (`StagedSyncPipeline`)
|
|
400
|
+
* Decouples block/checkpoint synchronization into composable stages with independent
|
|
401
|
+
* progress checkpoints and reverse-order `unwindTo(targetHeight)`.
|
|
402
|
+
*/
|
|
403
|
+
interface SyncStage<TCtx = Record<string, any>> {
|
|
404
|
+
id: string;
|
|
405
|
+
execute: (range: {
|
|
406
|
+
fromHeight: number;
|
|
407
|
+
toHeight: number;
|
|
408
|
+
}, statedb: OverlayStateDB, ctx: TCtx) => Promise<void>;
|
|
409
|
+
unwind: (range: {
|
|
410
|
+
fromHeight: number;
|
|
411
|
+
toHeight: number;
|
|
412
|
+
}, statedb: OverlayStateDB, ctx: TCtx) => Promise<void>;
|
|
413
|
+
}
|
|
414
|
+
declare class StagedSyncPipeline<TCtx = Record<string, any>> {
|
|
415
|
+
private readonly stages;
|
|
416
|
+
private readonly checkpoints;
|
|
417
|
+
registerStage(stage: SyncStage<TCtx>): this;
|
|
418
|
+
getStageCheckpoint(stageId: string): number;
|
|
419
|
+
runTo(targetHeight: number, statedb: Record<string, any>, ctx: TCtx): Promise<{
|
|
420
|
+
checkpoints: Record<string, number>;
|
|
421
|
+
stateDiff: StateDiffEntry[];
|
|
422
|
+
}>;
|
|
423
|
+
unwindTo(targetHeight: number, statedb: Record<string, any>, ctx: TCtx): Promise<{
|
|
424
|
+
checkpoints: Record<string, number>;
|
|
425
|
+
stateDiff: StateDiffEntry[];
|
|
426
|
+
}>;
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* 7. 1-Click Relayer-Sponsored Cross-Chain Direct Purchase (`executeCrossChainPurchaseBlock`)
|
|
430
|
+
* Atomically chains a foreign-chain deposit (`DepositTokenV2Tx` submitted by `relayer`/`proposer`
|
|
431
|
+
* crediting `buyer`) with one or more purchase statements (`AcquireAssetV3Tx`, `MintTokenTx`,
|
|
432
|
+
* `TransferV3Tx`, or `ContractNFT`) inside a single zero-sum `TransactionBlock`.
|
|
433
|
+
* If any downstream purchase step fails, the entire block (including deposit and evidence) rolls back.
|
|
434
|
+
*/
|
|
435
|
+
interface CrossChainDepositSpec {
|
|
436
|
+
rollup: string;
|
|
437
|
+
token: {
|
|
438
|
+
address: string;
|
|
439
|
+
value: string;
|
|
440
|
+
};
|
|
441
|
+
actualFee: string;
|
|
442
|
+
proposer?: string;
|
|
443
|
+
evidence: {
|
|
444
|
+
hash: string;
|
|
445
|
+
targetType?: 'EVM' | 'SOLANA' | 'OCAP_ISOMORPHIC';
|
|
446
|
+
targetChainId?: string;
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
interface CrossChainPurchaseInput {
|
|
450
|
+
id?: string;
|
|
451
|
+
relayer: string;
|
|
452
|
+
buyer: string;
|
|
453
|
+
deposit: CrossChainDepositSpec;
|
|
454
|
+
purchaseStatements: TransactionStatement[];
|
|
455
|
+
minDepositValue?: string;
|
|
456
|
+
minRelayerFee?: string;
|
|
457
|
+
fallbackToDepositOnPurchaseFailure?: boolean;
|
|
458
|
+
ofacBlocklist?: string[];
|
|
459
|
+
enforceZeroSum?: boolean;
|
|
460
|
+
}
|
|
461
|
+
declare function executeCrossChainPurchaseBlock(input: CrossChainPurchaseInput, options: {
|
|
462
|
+
statedb: Record<string, any>;
|
|
463
|
+
executeStatement: StatementExecutor;
|
|
464
|
+
dryRun?: boolean;
|
|
465
|
+
minDepositValue?: string;
|
|
466
|
+
minRelayerFee?: string;
|
|
467
|
+
fallbackToDepositOnPurchaseFailure?: boolean;
|
|
468
|
+
ofacBlocklist?: Iterable<string>;
|
|
469
|
+
}): Promise<TransactionBlockResult>;
|
|
470
|
+
//#endregion
|
|
471
|
+
export { CONTRACT_NFT_KIND, ContractGuardPredicate, ContractNftPayload, CrossChainDepositSpec, CrossChainPurchaseInput, DEFAULT_MAX_STATEMENTS_PER_HOT_KEY_PER_BLOCK, HARD_MAX_TX_BLOCK_STATEMENTS, MAX_CONTRACT_ARGS_BYTES, MAX_CONTRACT_FOOTPRINT_KEYS, MAX_CONTRACT_NFT_STATEMENTS, MAX_EXECUTE_ASSET_CALLS_PER_BLOCK, MAX_EXECUTE_ASSET_DEPTH, MAX_TX_BLOCK_BYTES, MAX_TX_BLOCK_READ_KEYS, MAX_TX_BLOCK_STATE_DIFF_ENTRIES, MAX_TX_BLOCK_TOP_LEVEL_STATEMENTS, MAX_TX_BLOCK_TOTAL_EXPANDED_STATEMENTS, MAX_TX_BLOCK_WRITE_KEYS, OverlayStateDB, PendingTransferRecord, PreparedTransactionBlock, ResolvedTransactionBlockBudget, StagedSyncPipeline, StateDiffEntry, StateFootprint, StatementExecutor, SyncStage, TransactionBlockInput, TransactionBlockPostConditions, TransactionBlockResourceBudget, TransactionBlockResult, TransactionStatement, TwoPhaseCommitCoordinator, TwoPhaseTransferLedger, WalletClearSigningPreview, assertLeafStatementTemplateOnly, assertTransactionBlockResourceBudget, buildWalletClearSigningPreview, computeAccountAndAssetNetEffects, createOverlayStateDB, executeContractNft, executeCrossChainPurchaseBlock, executeTransactionBlock, extractStateFootprint, hasStateConflict, isExecuteAssetStatement, resolveEffectiveResourceBudget, resolveStatementReferences, scheduleParallelBatches, verifyTransactionBlockPostConditions };
|