@kohaku-eth/tornado-cash 0.0.2-alpha.11 → 0.0.2-alpha.13

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/dist/index.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import { Broadcaster } from '@kohaku-eth/plugins/broadcaster';
2
- import { Host, ChainId, Storage, PrivateOperation, PublicOperation, AssetAmount, ERC20AssetId, PluginInstance, AccountId } from '@kohaku-eth/plugins';
2
+ import { Host, ExternalRawEvent, ChainId, Storage, PrivateOperation, PublicOperation, AccountId, AssetAmount, ERC20AssetId, PluginInstance, UnshieldOptions } from '@kohaku-eth/plugins';
3
+ import { TxData } from '@kohaku-eth/provider';
3
4
  import { combineReducers } from '@reduxjs/toolkit';
4
5
  import { ParseAbiItem, SignedAuthorization, Hash, Address as Address$2 } from 'viem';
5
- import { TxData } from '@kohaku-eth/provider';
6
6
  import { Address as Address$1 } from 'ox/Address';
7
+ import { Hex } from 'ox/Hex';
7
8
 
8
9
  type Nullifier$1 = bigint & {};
9
10
  type NullifierHash = bigint & {};
@@ -39,41 +40,6 @@ interface SecretManagerParams {
39
40
  }
40
41
  declare function SecretManager({ host: { keystore }, accountIndex }: SecretManagerParams): Promise<ISecretManager>;
41
42
 
42
- interface IRelayerStatusResponse {
43
- currentQueue: number;
44
- netId: number;
45
- rewardAccount: string;
46
- version: string;
47
- tornadoServiceFee: number;
48
- ethPrices: Record<string, string>;
49
- }
50
- interface ITornadoWithdrawRequest {
51
- proof: `0x${string}`;
52
- args: [`0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`];
53
- contract: `0x${string}`;
54
- }
55
- interface ITornadoWithdrawResponse {
56
- id: string;
57
- }
58
- interface IRelayerClient {
59
- getStatus(hostname: string): Promise<IRelayerStatusResponse>;
60
- withdraw(relayerUrl: string, body: ITornadoWithdrawRequest): Promise<ITornadoWithdrawResponse>;
61
- }
62
-
63
- interface InstanceRegistryConfig extends IScrapeableContract {
64
- lastDeployedOnBlock?: bigint;
65
- }
66
- interface ProtocolConfigState {
67
- chainId: bigint;
68
- ensSubdomainKey: string;
69
- instanceRegistry: InstanceRegistryConfig;
70
- relayerRegistry: IScrapeableContract;
71
- aggregator: IContract;
72
- }
73
-
74
- type RootState = ReturnType<ReturnType<typeof combineReducers<typeof reducers>>>;
75
- type PublicRootState = Omit<RootState, 'userSecrets'>;
76
-
77
43
  interface IBaseEvent {
78
44
  blockNumber: bigint;
79
45
  transactionHash: bigint;
@@ -86,6 +52,15 @@ interface IDepositEvent extends IPoolEvent {
86
52
  leafIndex: number;
87
53
  timestamp: bigint;
88
54
  }
55
+ interface IIndexedDepositEvent extends IDepositEvent {
56
+ index: number;
57
+ }
58
+ interface IDepositWithAsset extends IIndexedDepositEvent {
59
+ assetAddress: Address;
60
+ }
61
+ interface IDepositWithBalance extends IDepositWithAsset {
62
+ balance: bigint;
63
+ }
89
64
  interface IWithdrawalEvent extends IPoolEvent {
90
65
  to: Address;
91
66
  nullifierHash: NullifierHash;
@@ -111,6 +86,41 @@ interface IAsset {
111
86
  symbol: string;
112
87
  }
113
88
 
89
+ interface IRelayerStatusResponse {
90
+ currentQueue: number;
91
+ netId: number;
92
+ rewardAccount: string;
93
+ version: string;
94
+ tornadoServiceFee: number;
95
+ ethPrices: Record<string, string>;
96
+ }
97
+ interface ITornadoWithdrawRequest {
98
+ proof: `0x${string}`;
99
+ args: [`0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`];
100
+ contract: `0x${string}`;
101
+ }
102
+ interface ITornadoWithdrawResponse {
103
+ id: string;
104
+ }
105
+ interface IRelayerClient {
106
+ getStatus(hostname: string): Promise<IRelayerStatusResponse>;
107
+ withdraw(relayerUrl: string, body: ITornadoWithdrawRequest): Promise<ITornadoWithdrawResponse>;
108
+ }
109
+
110
+ interface InstanceRegistryConfig extends IScrapeableContract {
111
+ lastDeployedOnBlock?: bigint;
112
+ }
113
+ interface ProtocolConfigState {
114
+ chainId: bigint;
115
+ ensSubdomainKey: string;
116
+ instanceRegistry: InstanceRegistryConfig;
117
+ relayerRegistry: IScrapeableContract;
118
+ aggregator: IContract;
119
+ }
120
+
121
+ type RootState = ReturnType<ReturnType<typeof combineReducers<typeof reducers>>>;
122
+ type PublicRootState = Omit<RootState, 'userSecrets'>;
123
+
114
124
  declare const POOL_EVENTS_SIGNATURES: {
115
125
  readonly Deposited: {
116
126
  readonly name: "Deposit";
@@ -181,7 +191,7 @@ declare const INSTANCE_REGISTRY_EVENT_SIGNATURES: {
181
191
  };
182
192
 
183
193
  type IEventsMap = Record<string, ParseAbiItem<string>>;
184
- interface IGetEventsParams<T> {
194
+ interface IGetEventsParams$1<T> {
185
195
  events: T | T[];
186
196
  fromBlock: bigint;
187
197
  toBlock?: bigint;
@@ -202,7 +212,7 @@ type IGroupedEvents<NamesTable extends Record<string, unknown>> = {
202
212
  };
203
213
  type GetEventsFn<EventsMap extends IEventsMap, ParsedEvents extends {
204
214
  [key in keyof EventsMap]: unknown;
205
- }> = <const T extends keyof ParsedEvents = never>(params: IGetEventsParams<T>) => Promise<Pick<IGroupedEvents<ParsedEvents>, T> & {
215
+ }> = <const T extends keyof ParsedEvents = never>(params: IGetEventsParams$1<T>) => Promise<Pick<IGroupedEvents<ParsedEvents>, T> & {
206
216
  fromBlock: bigint;
207
217
  toBlock: bigint;
208
218
  }>;
@@ -211,7 +221,6 @@ interface IPoolConfig {
211
221
  isERC20: boolean;
212
222
  token: Address;
213
223
  state: 0 | 1;
214
- uniswapPoolSwappingFee: number;
215
224
  protocolFeePercentage: number;
216
225
  denomination: bigint;
217
226
  rootHistorySize: number;
@@ -224,6 +233,14 @@ interface IRelayerAggregatorData {
224
233
  }
225
234
  interface IDataService {
226
235
  getPoolEvents: GetEventsFn<typeof POOL_EVENTS_SIGNATURES, IPoolEvents>;
236
+ getBlockNumber(): Promise<bigint>;
237
+ parsePoolEvents(events: ExternalRawEvent[]): {
238
+ Deposited: IRawDepositEvent[];
239
+ Withdrawn: IRawWithdrawalEvent[];
240
+ };
241
+ parseRelayerRegistryEvents(events: ExternalRawEvent[]): {
242
+ RelayerRegistered: IRelayerRegisteredEvent[];
243
+ };
227
244
  getRelayerRegistryEvents: GetEventsFn<typeof RELAYER_REGISTRY_EVENTS_SIGNATURES, IRelayerRegistryEvents>;
228
245
  getInstanceRegistryEvents: GetEventsFn<typeof INSTANCE_REGISTRY_EVENT_SIGNATURES, IInstanceRegistryEvents>;
229
246
  getAsset(assetAddress: Address): Promise<IAsset>;
@@ -240,7 +257,38 @@ interface IDataService {
240
257
  getLatestBlockTimestamp(): Promise<bigint>;
241
258
  getRelayerData(aggregatorAddress: Address, relayerNameHashes: bigint[], subdomains: string[]): Promise<IRelayerAggregatorData[]>;
242
259
  getAccountNonce(accountAddress: Address): Promise<number>;
243
- quoteEthToToken(amountInWei: bigint, tokenAddress: Address, poolFee: number): Promise<bigint>;
260
+ quoteWeiInToken(paymasterAddress: Address, feeToken: Address, weiAmount: bigint): Promise<bigint>;
261
+ }
262
+
263
+ /** Identifies one contract to sync from a given block. */
264
+ interface IGetEventsParams {
265
+ chainId: bigint;
266
+ address: Address;
267
+ fromBlock: bigint;
268
+ }
269
+ interface IGetPoolEventsResult {
270
+ Deposited: IRawDepositEvent[];
271
+ Withdrawn: IRawWithdrawalEvent[];
272
+ /** Highest block the returned events are synced up to. */
273
+ toBlock: bigint;
274
+ }
275
+ interface IGetRelayerRegistryEventsResult {
276
+ RelayerRegistered: IRelayerRegisteredEvent[];
277
+ /** Highest block the returned events are synced up to. */
278
+ toBlock: bigint;
279
+ }
280
+ interface ISyncService {
281
+ /**
282
+ * Fetches a single pool's `Deposited`/`Withdrawn` events from `fromBlock`.
283
+ * Uses the external sync provider for the bulk of a large range and the chain
284
+ * for the remaining tail; falls back to a chain-only fetch otherwise.
285
+ */
286
+ getPoolEvents(params: IGetEventsParams): Promise<IGetPoolEventsResult>;
287
+ /**
288
+ * Fetches the relayer registry's `RelayerRegistered` events from `fromBlock`,
289
+ * with the same external-then-chain strategy as {@link getPoolEvents}.
290
+ */
291
+ getRelayerRegistryEvents(params: IGetEventsParams): Promise<IGetRelayerRegistryEventsResult>;
244
292
  }
245
293
 
246
294
  type SpecificAssetBalanceFn<isAsync extends boolean = false> = <const Adresses extends Address | Address[] = Address[], ReturnType = Adresses extends unknown[] ? Map<Address, bigint> : bigint>(assetAddress?: Adresses) => isAsync extends true ? Promise<ReturnType> : ReturnType;
@@ -280,6 +328,7 @@ interface IRelayerFeeConfig {
280
328
  interface StoreFactoryParams {
281
329
  secretManagerFactory: () => Promise<ISecretManager>;
282
330
  dataService: IDataService;
331
+ syncService: ISyncService;
283
332
  relayerClient: IRelayerClient;
284
333
  paymasterConfig: IChainsPaymastersConfig;
285
334
  storageToSyncTo?: Storage;
@@ -294,6 +343,36 @@ declare enum DepositStrategy {
294
343
  MinFee = 1
295
344
  }
296
345
 
346
+ interface SerializedAuth {
347
+ address: Address$1;
348
+ chainId: Hex;
349
+ nonce: Hex;
350
+ r: Hex;
351
+ s: Hex;
352
+ yParity: Hex;
353
+ }
354
+ /**
355
+ * A userOp serialized to the hex shape expected by `eth_sendUserOperation`, so
356
+ * it can be carried as plain (JSON-serializable) data from the prepare phase
357
+ * (thunk) to the broadcast phase.
358
+ */
359
+ interface SerializedUserOperation {
360
+ sender: `0x${string}`;
361
+ nonce: `0x${string}`;
362
+ callData: `0x${string}`;
363
+ callGasLimit: `0x${string}`;
364
+ verificationGasLimit: `0x${string}`;
365
+ preVerificationGas: `0x${string}`;
366
+ maxFeePerGas: `0x${string}`;
367
+ maxPriorityFeePerGas: `0x${string}`;
368
+ paymaster?: `0x${string}`;
369
+ paymasterVerificationGasLimit?: `0x${string}`;
370
+ paymasterPostOpGasLimit?: `0x${string}`;
371
+ paymasterData?: `0x${string}`;
372
+ signature: `0x${string}`;
373
+ eip7702Auth?: SerializedAuth;
374
+ }
375
+
297
376
  interface SignedDelegation {
298
377
  senderAddress: `0x${string}`;
299
378
  authorization: SignedAuthorization;
@@ -313,8 +392,7 @@ interface IGenericPaymasterWithdrawalPayload {
313
392
  paymasterAddress: `0x${string}`;
314
393
  entryPointAddress: `0x${string}`;
315
394
  bundlerUrl: string;
316
- accountAddress: `0x${string}`;
317
- delegation?: SignedDelegation;
395
+ userOperation: SerializedUserOperation;
318
396
  }
319
397
  interface PaymasterBroadcastResult {
320
398
  userOpHash: Hash;
@@ -323,16 +401,6 @@ interface IPaymasterBroadcasterClient {
323
401
  broadcast(withdrawals: IPaymasterWithdrawalPayload[]): Promise<PaymasterBroadcastResult[]>;
324
402
  }
325
403
 
326
- declare function makeLazyProverFactory(artifactsLoader: () => Promise<ITornadoArtifacts>, version?: 'legacy' | 'js'): () => Promise<ITornadoProver>;
327
-
328
- interface WorkerInitOptions {
329
- protocolConfig: TCProtocolConfig;
330
- relayerConfig?: IRelayerFeeConfig;
331
- accountIndex: number;
332
- paymasterConfig: IChainsPaymastersConfig;
333
- proverVersion?: Parameters<typeof makeLazyProverFactory>[1];
334
- }
335
-
336
404
  type DelegationConfig = {
337
405
  mode: 'deterministic';
338
406
  path?: string;
@@ -367,7 +435,7 @@ interface ITornadoArtifacts {
367
435
  provingKey: ArrayBuffer;
368
436
  }
369
437
  type TCProtocolConfig = Omit<ProtocolConfigState, 'chainId'>;
370
- interface TCProtocolParams extends Pick<WorkerInitOptions, 'proverVersion'> {
438
+ interface TCProtocolParams {
371
439
  accountIndex?: number;
372
440
  paymasterConfig: IChainsPaymastersConfig;
373
441
  secretManagerFactory: (params: SecretManagerParams) => Promise<ISecretManager>;
@@ -378,6 +446,12 @@ interface TCProtocolParams extends Pick<WorkerInitOptions, 'proverVersion'> {
378
446
  artifactsLoader?: () => Promise<ITornadoArtifacts>;
379
447
  initialState?: () => Promise<Record<string, PublicRootState>>;
380
448
  stateManagerWorkerUrl?: string;
449
+ /**
450
+ * When a pool is at least this many blocks behind, use the host's
451
+ * `externalSyncProvider` (if any) for the bulk of the sync instead of the
452
+ * chain. Omit to always sync from the chain.
453
+ */
454
+ minExternalSyncBlocksAmount?: number;
381
455
  }
382
456
  interface IBaseOperationParams {
383
457
  }
@@ -397,8 +471,18 @@ interface IRelayerWithdrawParams extends IWithdrawBaseParams {
397
471
  interface IPaymasterWithdrawParams extends IWithdrawBaseParams {
398
472
  mode: 'paymaster';
399
473
  delegation?: DelegationConfig;
474
+ tailCalls?: (address: AccountId) => Promise<TxData[]>;
400
475
  }
401
476
  type IWithdrawapOperationParams = IRelayerWithdrawParams | IPaymasterWithdrawParams;
477
+ interface IGetNotesParams extends IBaseOperationParams {
478
+ includeSpent?: boolean;
479
+ assets?: Address[];
480
+ }
481
+ type TCNote = Pick<IDepositWithBalance, 'commitment' | 'balance' | 'assetAddress' | 'timestamp' | 'leafIndex' | 'pool'> & {
482
+ /** Fixed pool denomination for this note. */
483
+ amount: bigint;
484
+ depositIndex: number;
485
+ };
402
486
  type StoreKey = `${string}-${string}`;
403
487
  type StoreStorageKey = `tornado-cash-state-${StoreKey}`;
404
488
  interface IStateManager {
@@ -419,6 +503,12 @@ interface IStateManager {
419
503
  * All assets if not specified.
420
504
  */
421
505
  getBalances: SpecificAssetBalanceFn<true>;
506
+ /**
507
+ * Gets all notes for the account.
508
+ * @param includeSpent - If true, include notes with zero balance
509
+ * @param assets - Optional filter by specific assets
510
+ */
511
+ getNotes: (params: IGetNotesParams) => Promise<TCNote[]>;
422
512
  dumpState: () => Record<StoreStorageKey, PublicRootState>;
423
513
  }
424
514
 
@@ -431,7 +521,7 @@ type TCBroadcaster = Broadcaster<TCPrivateOperation, ITornadoWithdrawResponse[]>
431
521
  interface TCBaseCredential {
432
522
  accountIndex: number;
433
523
  }
434
- interface TCPluginParameters extends TCBroadcasterParameters, TCBaseCredential, Pick<TCProtocolParams, 'proverVersion' | 'initialState'> {
524
+ interface TCPluginParameters extends TCBroadcasterParameters, TCBaseCredential, Pick<TCProtocolParams, 'initialState' | 'minExternalSyncBlocksAmount'> {
435
525
  protocolConfig: TCProtocolConfig;
436
526
  relayerConfig?: IRelayerFeeConfig;
437
527
  stateManagerWorkerUrl?: string;
@@ -440,11 +530,11 @@ interface TCPluginParameters extends TCBroadcasterParameters, TCBaseCredential,
440
530
  type TCAddress = Address$1;
441
531
  type TCAssetAmount<Tag extends string | undefined = undefined> = AssetAmount<ERC20AssetId, bigint, Tag>;
442
532
  type TCAssetBalance = TCAssetAmount;
443
- interface TCRelayerUnshieldOptions {
533
+ interface TCRelayerUnshieldOptions extends UnshieldOptions {
444
534
  mode: 'relayer';
445
535
  preferredRelayersEns?: string[];
446
536
  }
447
- interface TCPaymasterUnshieldOptions {
537
+ interface TCPaymasterUnshieldOptions extends UnshieldOptions {
448
538
  mode: 'paymaster';
449
539
  delegation?: DelegationConfig;
450
540
  }
@@ -463,6 +553,7 @@ type TCInstance = PluginInstance<TCAddress, {
463
553
  output: TCAssetAmount;
464
554
  read: TCAssetBalance;
465
555
  };
556
+ note: TCNote;
466
557
  extras: {
467
558
  sync(): Promise<void>;
468
559
  prepareShield(asset: TCAssetAmount, options: TCPrepareShieldOptions): Promise<TCPublicOperation>;
@@ -480,7 +571,7 @@ type RequireOnly<T, Keys extends keyof T> = Partial<T> & Pick<T, Keys>;
480
571
  declare class TornadoCashProtocol implements TCInstance {
481
572
  readonly host: Host;
482
573
  private stateManager;
483
- constructor(host: Host, { accountIndex, initialState, protocolConfig, artifactsLoader, stateManagerWorkerUrl, relayerConfig, paymasterConfig, relayerClientFactory, proverVersion }: RequireOnly<TCProtocolParams, 'protocolConfig'>);
574
+ constructor(host: Host, { accountIndex, initialState, protocolConfig, artifactsLoader, stateManagerWorkerUrl, relayerConfig, paymasterConfig, relayerClientFactory, minExternalSyncBlocksAmount, }: RequireOnly<TCProtocolParams, 'protocolConfig'>);
484
575
  instanceId: () => Promise<"0x1">;
485
576
  /**
486
577
  * Only process supported assets or error out?
@@ -488,7 +579,14 @@ declare class TornadoCashProtocol implements TCInstance {
488
579
  * The assets retain the provided order. If an asset is not supported its balance will be 0
489
580
  */
490
581
  balance(assets?: ERC20AssetId[]): Promise<TCAssetBalance[]>;
582
+ /**
583
+ * Returns all notes for the account.
584
+ * @param assets - Filter by specific assets (optional, if empty returns all)
585
+ * @param includeSpent - Include notes with zero balance (default: false)
586
+ */
587
+ notes(assets?: ERC20AssetId[], includeSpent?: boolean): Promise<TCNote[]>;
491
588
  prepareShield(assets: TCAssetAmount, options?: TCPrepareShieldOptions | `0x${string}`): Promise<TCPublicOperation>;
589
+ prepareUnshield(assets: AssetAmount, to: AccountId): Promise<TCPrivateOperation<'relayer'>>;
492
590
  prepareUnshield(assets: AssetAmount, to: AccountId, options?: TCRelayerUnshieldOptions): Promise<TCPrivateOperation<'relayer'>>;
493
591
  prepareUnshield(assets: AssetAmount, to: AccountId, options?: TCPaymasterUnshieldOptions): Promise<TCPrivateOperation<'paymaster'>>;
494
592
  sync(): Promise<void>;
@@ -513,11 +611,11 @@ declare const TornadoPaymasterConfigs: {
513
611
  readonly 11155111: {
514
612
  readonly bundlerUrl: "https://public.pimlico.io/v2/11155111/rpc";
515
613
  readonly entryPointAddress: "0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108";
516
- readonly paymasterAddress: "0xA0e2667AcdECb9bCDa6Fcf87638a962e2E9dB20D";
614
+ readonly paymasterAddress: "0x1c5aCCb9c09D72945b79EC986776136bE01d7B2F";
517
615
  readonly poolsAccountsMap: {
518
- readonly '0x8c4a04d872a6c1be37964a21ba3a138525dff50b': "0x8A70E3dE493B8599447013f08d8b35719C8ED0ec";
519
- readonly '0x8cc930096b4df705a007c4a039bdfa1320ed2508': "0x191e3De3cF7f61de7EbEf4Bf45cfBA4f652d1C6e";
520
- readonly '0x6921fd1a97441dd603a997ed6ddf388658daf754': "0x060d053A6595630851ab873d6C95401b0C964d26";
616
+ readonly '0x8c4a04d872a6c1be37964a21ba3a138525dff50b': "0xa616aAE443FCCABfc2F1EA2Afe001E5046FFDCe0";
617
+ readonly '0x8cc930096b4df705a007c4a039bdfa1320ed2508': "0x67a898343F32641206d0f30CB3367944a8919A3A";
618
+ readonly '0x6921fd1a97441dd603a997ed6ddf388658daf754': "0xbF0a7969dacF8337716d0F283df0574dF56b0479";
521
619
  };
522
620
  };
523
621
  readonly 1: never;
@@ -537,7 +635,6 @@ declare const TornadoCashConfigs: {
537
635
  readonly address: 1329937909414098670091808248270266272594403334985n;
538
636
  };
539
637
  readonly weth: 1097077688018008265106216665536940668749033598146n;
540
- readonly uniswapQuoterV2: 559478315000592720989748010348495519536007655966n;
541
638
  };
542
639
  readonly 11155111: {
543
640
  readonly ensSubdomainKey: "sepolia-tornado";
@@ -553,8 +650,7 @@ declare const TornadoCashConfigs: {
553
650
  readonly address: 368418168928372787409224158240737522620871644738n;
554
651
  };
555
652
  readonly weth: 1461358721292675304620367034492138750323989506836n;
556
- readonly uniswapQuoterV2: 1353730886217084326490181093487957540173111046067n;
557
653
  };
558
654
  };
559
655
 
560
- export { type Commitment, DepositStrategy, E_ADDRESS, type ISecretManager, type Nullifier, SecretManager, type SecretManagerParams, type TCAddress, type TCAssetAmount, type TCAssetBalance, type TCBroadcaster, type TCBroadcasterParameters, type TCInstance, type TCPaymasterUnshieldOptions, type TCPluginParameters, type TCPrepareShieldOptions, type TCPrepareUnshieldOptions, type TCRelayerUnshieldOptions, TornadoCashConfigs, TornadoCashProtocol, TornadoPaymasterConfigs, createTCBroadcaster, createTCPlugin };
656
+ export { type Commitment, DepositStrategy, E_ADDRESS, type ISecretManager, type Nullifier, SecretManager, type SecretManagerParams, type TCAddress, type TCAssetAmount, type TCAssetBalance, type TCBroadcaster, type TCBroadcasterParameters, type TCInstance, type TCNote, type TCPaymasterUnshieldOptions, type TCPluginParameters, type TCPrepareShieldOptions, type TCPrepareUnshieldOptions, type TCRelayerUnshieldOptions, TornadoCashConfigs, TornadoCashProtocol, TornadoPaymasterConfigs, createTCBroadcaster, createTCPlugin };