@0xbow/privacy-pools-core-sdk 0.1.11 → 0.1.12

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.
Files changed (43) hide show
  1. package/dist/esm/{fetchArtifacts.esm-B8U6icK3.js → fetchArtifacts.esm-Cykfrm5S.js} +2 -3
  2. package/dist/esm/fetchArtifacts.esm-Cykfrm5S.js.map +1 -0
  3. package/dist/esm/{fetchArtifacts.node-D8glxBXj.js → fetchArtifacts.node-D5S1JvH1.js} +2 -3
  4. package/dist/esm/fetchArtifacts.node-D5S1JvH1.js.map +1 -0
  5. package/dist/esm/{index-BLHTvD4r.js → index-CWlKxlGD.js} +164 -278
  6. package/dist/esm/{index-BLHTvD4r.js.map → index-CWlKxlGD.js.map} +1 -1
  7. package/dist/esm/index.mjs +1 -2
  8. package/dist/esm/index.mjs.map +1 -1
  9. package/dist/index.d.mts +29 -63
  10. package/dist/node/artifacts/commitment.vkey +101 -101
  11. package/dist/node/artifacts/commitment.zkey +0 -0
  12. package/dist/node/artifacts/withdraw.vkey +121 -121
  13. package/dist/node/artifacts/withdraw.zkey +0 -0
  14. package/dist/node/{fetchArtifacts.esm-DhvocQ3l.js → fetchArtifacts.esm-CntDMl3d.js} +2 -3
  15. package/dist/node/fetchArtifacts.esm-CntDMl3d.js.map +1 -0
  16. package/dist/node/{fetchArtifacts.node-NZQXuUgf.js → fetchArtifacts.node-Ch7znfg5.js} +2 -3
  17. package/dist/node/fetchArtifacts.node-Ch7znfg5.js.map +1 -0
  18. package/dist/node/{index-krXk1X_i.js → index-CHw5QPh5.js} +164 -278
  19. package/dist/node/{index-krXk1X_i.js.map → index-CHw5QPh5.js.map} +1 -1
  20. package/dist/node/index.mjs +1 -2
  21. package/dist/node/index.mjs.map +1 -1
  22. package/dist/types/core/account.service.d.ts +4 -10
  23. package/dist/types/core/data.service.d.ts +17 -45
  24. package/dist/types/{fetchArtifacts.esm-BdNIlBG_.js → fetchArtifacts.esm-C3O9_Qn4.js} +1 -2
  25. package/dist/types/{fetchArtifacts.node-BpkM2ojo.js → fetchArtifacts.node-D58W80lP.js} +1 -2
  26. package/dist/types/{index-CIOALVDs.js → index-BE_t-oBr.js} +163 -277
  27. package/dist/types/index.js +1 -2
  28. package/dist/types/types/account.d.ts +5 -5
  29. package/dist/types/types/events.d.ts +6 -6
  30. package/package.json +1 -2
  31. package/src/core/account.service.ts +56 -59
  32. package/src/core/data.service.ts +170 -315
  33. package/src/types/account.ts +5 -5
  34. package/src/types/events.ts +6 -6
  35. package/dist/esm/fetchArtifacts.esm-B8U6icK3.js.map +0 -1
  36. package/dist/esm/fetchArtifacts.node-D8glxBXj.js.map +0 -1
  37. package/dist/node/artifacts/merkleTree.vkey +0 -269
  38. package/dist/node/artifacts/merkleTree.wasm +0 -0
  39. package/dist/node/artifacts/merkleTree.zkey +0 -0
  40. package/dist/node/fetchArtifacts.esm-DhvocQ3l.js.map +0 -1
  41. package/dist/node/fetchArtifacts.node-NZQXuUgf.js.map +0 -1
  42. package/dist/types/integration-tests/envio.test.d.ts +0 -1
  43. package/src/integration-tests/envio.test.ts +0 -110
@@ -1,10 +1,9 @@
1
- import { F as FetchArtifact } from './index-BLHTvD4r.js';
1
+ import { F as FetchArtifact } from './index-CWlKxlGD.js';
2
2
  import 'viem/accounts';
3
3
  import 'buffer';
4
4
  import 'assert';
5
5
  import 'viem';
6
6
  import 'viem/chains';
7
- import '@envio-dev/hypersync-client';
8
7
 
9
8
  async function fetchVersionedArtifact(artifactUrl) {
10
9
  const res = await fetch(artifactUrl);
@@ -16,4 +15,4 @@ async function fetchVersionedArtifact(artifactUrl) {
16
15
  }
17
16
 
18
17
  export { fetchVersionedArtifact };
19
- //# sourceMappingURL=fetchArtifacts.esm-B8U6icK3.js.map
18
+ //# sourceMappingURL=fetchArtifacts.esm-Cykfrm5S.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetchArtifacts.esm-Cykfrm5S.js","sources":["../../src/circuits/fetchArtifacts.esm.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;AAEO,eAAe,sBAAsB,CAC1C,WAAgB,EAAA;AAEhB,IAAA,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,WAAW,CAAC;AACpC,IAAA,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,EAAE;AACtB,QAAA,MAAM,IAAI,aAAa,CAAC,WAAW,CAAC;;AAEtC,IAAA,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,WAAW,EAAE;AACpC,IAAA,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC;AAC7B;;;;"}
@@ -1,10 +1,9 @@
1
- import { F as FetchArtifact } from './index-BLHTvD4r.js';
1
+ import { F as FetchArtifact } from './index-CWlKxlGD.js';
2
2
  import 'viem/accounts';
3
3
  import 'buffer';
4
4
  import 'assert';
5
5
  import 'viem';
6
6
  import 'viem/chains';
7
- import '@envio-dev/hypersync-client';
8
7
 
9
8
  async function fetchVersionedArtifact(artifactUrl) {
10
9
  try {
@@ -29,4 +28,4 @@ async function fetchVersionedArtifact(artifactUrl) {
29
28
  }
30
29
 
31
30
  export { fetchVersionedArtifact };
32
- //# sourceMappingURL=fetchArtifacts.node-D8glxBXj.js.map
31
+ //# sourceMappingURL=fetchArtifacts.node-D5S1JvH1.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetchArtifacts.node-D5S1JvH1.js","sources":["../../src/circuits/fetchArtifacts.node.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;AAEO,eAAe,sBAAsB,CAC1C,WAAgB,EAAA;AAEhB,IAAA,IAAI;QACF,MAAM,EAAE,GAAG,CAAC,MAAM,OAAO,IAAI,CAAC,EAAE,OAAO;QACvC,MAAM,WAAW,GAAoB,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAI;AACnE,YAAA,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,IAAI,KAAI;gBAC9C,IAAI,GAAG,EAAE;oBACP,MAAM,CAAC,GAAG,CAAC;;qBACN;oBACL,OAAO,CAAC,IAAI,CAAC;;AAEjB,aAAC,CAAC;AACJ,SAAC,CAAC;AACF,QAAA,MAAM,GAAG,GAAG,MAAM,WAAW;AAC7B,QAAA,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC;;IAC1B,OAAO,KAAK,EAAE;AACd,QAAA,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC;AACpB,QAAA,MAAM,IAAI,aAAa,CAAC,WAAW,CAAC;;AAExC;;;;"}
@@ -1,9 +1,8 @@
1
1
  import { mnemonicToAccount, privateKeyToAccount } from 'viem/accounts';
2
2
  import require$$0 from 'buffer';
3
3
  import require$$2 from 'assert';
4
- import { keccak256, encodeAbiParameters, numberToHex, createPublicClient, http, createWalletClient, getAddress, bytesToNumber as bytesToNumber$1 } from 'viem';
4
+ import { keccak256, encodeAbiParameters, numberToHex, createPublicClient, http, createWalletClient, getAddress, bytesToNumber as bytesToNumber$1, parseAbiItem } from 'viem';
5
5
  import { mainnet } from 'viem/chains';
6
- import { HypersyncClient, presetQueryLogsOfEvent } from '@envio-dev/hypersync-client';
7
6
 
8
7
  const version = '2.22.14';
9
8
 
@@ -45816,10 +45815,10 @@ const circuitToAsset = {
45816
45815
 
45817
45816
  async function importFetchVersionedArtifact(isBrowser) {
45818
45817
  if (isBrowser) {
45819
- return import('./fetchArtifacts.esm-B8U6icK3.js');
45818
+ return import('./fetchArtifacts.esm-Cykfrm5S.js');
45820
45819
  }
45821
45820
  else {
45822
- return import('./fetchArtifacts.node-D8glxBXj.js');
45821
+ return import('./fetchArtifacts.node-D5S1JvH1.js');
45823
45822
  }
45824
45823
  }
45825
45824
 
@@ -68678,12 +68677,12 @@ class AccountService {
68678
68677
  _initializeAccount(mnemonic) {
68679
68678
  try {
68680
68679
  this.logger.debug("Initializing account with mnemonic");
68681
- let key1 = bytesToNumber$1(mnemonicToAccount(mnemonic, { accountIndex: 0 }).getHdKey().privateKey);
68682
- let key2 = bytesToNumber$1(mnemonicToAccount(mnemonic, { accountIndex: 1 }).getHdKey().privateKey);
68683
- let masterKey1 = hashingExports.poseidon([BigInt(key1)]);
68684
- let masterKey2 = hashingExports.poseidon([BigInt(key2)]);
68680
+ let masterNullifierSeed = bytesToNumber$1(mnemonicToAccount(mnemonic, { accountIndex: 0 }).getHdKey().privateKey);
68681
+ let masterSecretSeed = bytesToNumber$1(mnemonicToAccount(mnemonic, { accountIndex: 1 }).getHdKey().privateKey);
68682
+ let masterNullifier = hashingExports.poseidon([BigInt(masterNullifierSeed)]);
68683
+ let masterSecret = hashingExports.poseidon([BigInt(masterSecretSeed)]);
68685
68684
  return {
68686
- masterKeys: [masterKey1, masterKey2],
68685
+ masterKeys: [masterNullifier, masterSecret],
68687
68686
  poolAccounts: new Map(),
68688
68687
  creationTimestamp: 0n,
68689
68688
  lastUpdateTimestamp: 0n
@@ -68694,16 +68693,20 @@ class AccountService {
68694
68693
  }
68695
68694
  }
68696
68695
  _genDepositNullifier(scope, index) {
68697
- return hashingExports.poseidon([this.account.masterKeys[0], scope, index]);
68696
+ const [masterNullifier] = this.account.masterKeys;
68697
+ return hashingExports.poseidon([masterNullifier, scope, index]);
68698
68698
  }
68699
68699
  _genDepositSecret(scope, index) {
68700
- return hashingExports.poseidon([this.account.masterKeys[1], scope, index]);
68700
+ const [, masterSecret] = this.account.masterKeys;
68701
+ return hashingExports.poseidon([masterSecret, scope, index]);
68701
68702
  }
68702
68703
  _genWithdrawalNullifier(label, index) {
68703
- return hashingExports.poseidon([this.account.masterKeys[0], label, index]);
68704
+ const [masterNullifier] = this.account.masterKeys;
68705
+ return hashingExports.poseidon([masterNullifier, label, index]);
68704
68706
  }
68705
68707
  _genWithdrawalSecret(label, index) {
68706
- return hashingExports.poseidon([this.account.masterKeys[1], label, index]);
68708
+ const [, masterSecret] = this.account.masterKeys;
68709
+ return hashingExports.poseidon([masterSecret, label, index]);
68707
68710
  }
68708
68711
  _hashCommitment(value, label, precommitment) {
68709
68712
  return hashingExports.poseidon([value, label, precommitment]);
@@ -68865,35 +68868,6 @@ class AccountService {
68865
68868
  this.logger.info(`Added new commitment with value ${value} to account with label ${parentCommitment.label}`);
68866
68869
  return newCommitment;
68867
68870
  }
68868
- /**
68869
- * Process withdrawals for a given chain and block range
68870
- *
68871
- * @param chainId - The chain ID to process withdrawals for
68872
- * @param fromBlock - The starting block number
68873
- * @param foundAccounts - Map of accounts indexed by label
68874
- */
68875
- async _processWithdrawals(chainId, fromBlock, foundAccounts) {
68876
- const withdrawals = await this.dataService.getWithdrawals(chainId, {
68877
- fromBlock,
68878
- });
68879
- for (const withdrawal of withdrawals) {
68880
- for (const account of foundAccounts.values()) {
68881
- const isParentCommitment = BigInt(account.deposit.nullifier) === BigInt(withdrawal.spentNullifier) ||
68882
- account.children.some(child => BigInt(child.nullifier) === BigInt(withdrawal.spentNullifier));
68883
- if (isParentCommitment) {
68884
- const parentCommitment = account.children.length > 0
68885
- ? account.children[account.children.length - 1]
68886
- : account.deposit;
68887
- if (!parentCommitment) {
68888
- this.logger.warn(`No parent commitment found for withdrawal ${withdrawal.spentNullifier.toString()}`);
68889
- continue;
68890
- }
68891
- this.addWithdrawalCommitment(parentCommitment, withdrawal.withdrawn, withdrawal.spentNullifier, parentCommitment.secret, withdrawal.blockNumber, withdrawal.timestamp, withdrawal.transactionHash);
68892
- break;
68893
- }
68894
- }
68895
- }
68896
- }
68897
68871
  /**
68898
68872
  * Retrieves the history of deposits and withdrawals for the given pools.
68899
68873
  *
@@ -68959,6 +68933,28 @@ class AccountService {
68959
68933
  await this._processWithdrawals(pool.chainId, firstDepositBlock, accountMap);
68960
68934
  }));
68961
68935
  }
68936
+ async _processWithdrawals(chainId, fromBlock, foundAccounts) {
68937
+ const withdrawals = await this.dataService.getWithdrawals(chainId, {
68938
+ fromBlock,
68939
+ });
68940
+ for (const withdrawal of withdrawals) {
68941
+ for (const account of foundAccounts.values()) {
68942
+ const isParentCommitment = BigInt(account.deposit.nullifier) === BigInt(withdrawal.spentNullifier) ||
68943
+ account.children.some(child => BigInt(child.nullifier) === BigInt(withdrawal.spentNullifier));
68944
+ if (isParentCommitment) {
68945
+ const parentCommitment = account.children.length > 0
68946
+ ? account.children[account.children.length - 1]
68947
+ : account.deposit;
68948
+ if (!parentCommitment) {
68949
+ this.logger.warn(`No parent commitment found for withdrawal ${withdrawal.spentNullifier.toString()}`);
68950
+ continue;
68951
+ }
68952
+ this.addWithdrawalCommitment(parentCommitment, withdrawal.withdrawn, withdrawal.spentNullifier, parentCommitment.secret, withdrawal.blockNumber, withdrawal.timestamp, withdrawal.transactionHash);
68953
+ break;
68954
+ }
68955
+ }
68956
+ }
68957
+ }
68962
68958
  }
68963
68959
 
68964
68960
  class DataError extends SDKError {
@@ -68977,13 +68973,18 @@ class DataError extends SDKError {
68977
68973
  }
68978
68974
  }
68979
68975
 
68976
+ // Event signatures from the contract
68977
+ const DEPOSIT_EVENT = parseAbiItem('event Deposited(address indexed _depositor, uint256 _commitment, uint256 _label, uint256 _value, uint256 _merkleRoot)');
68978
+ const WITHDRAWAL_EVENT = parseAbiItem('event Withdrawn(address indexed _processooor, uint256 _value, uint256 _spentNullifier, uint256 _newCommitment)');
68979
+ const RAGEQUIT_EVENT = parseAbiItem('event Ragequit(address indexed _ragequitter, uint256 _commitment, uint256 _label, uint256 _value)');
68980
68980
  /**
68981
68981
  * Service responsible for fetching and managing privacy pool events across multiple chains.
68982
68982
  * Handles event retrieval, parsing, and validation for deposits, withdrawals, and ragequits.
68983
68983
  *
68984
68984
  * @remarks
68985
- * This service uses HypersyncClient to efficiently fetch and process blockchain events.
68985
+ * This service uses viem's PublicClient to efficiently fetch and process blockchain events.
68986
68986
  * It supports multiple chains and provides robust error handling and validation.
68987
+ * All uint256 values from events are handled as bigints, with Hash type assertions for commitment-related fields.
68987
68988
  */
68988
68989
  class DataService {
68989
68990
  chainConfigs;
@@ -68992,7 +68993,7 @@ class DataService {
68992
68993
  /**
68993
68994
  * Initialize the data service with chain configurations
68994
68995
  *
68995
- * @param chainConfigs - Array of chain configurations
68996
+ * @param chainConfigs - Array of chain configurations containing chainId, RPC URL, and API key
68996
68997
  * @throws {DataError} If client initialization fails for any chain
68997
68998
  */
68998
68999
  constructor(chainConfigs) {
@@ -69000,96 +69001,67 @@ class DataService {
69000
69001
  this.logger = new Logger({ prefix: "Data" });
69001
69002
  try {
69002
69003
  for (const config of chainConfigs) {
69003
- const client = HypersyncClient.new({
69004
- url: this.getHypersyncUrlForChain(config.chainId),
69004
+ if (!config.rpcUrl || !config.apiKey) {
69005
+ throw new Error(`Missing RPC URL or API key for chain ${config.chainId}`);
69006
+ }
69007
+ const client = createPublicClient({
69008
+ transport: http(config.rpcUrl),
69009
+ key: config.apiKey,
69005
69010
  });
69006
69011
  this.clients.set(config.chainId, client);
69007
69012
  }
69008
69013
  }
69009
69014
  catch (error) {
69010
- throw new DataError("Failed to initialize HypersyncClient", ErrorCode.NETWORK_ERROR, { error: error instanceof Error ? error.message : "Unknown error" });
69015
+ throw new DataError("Failed to initialize PublicClient", ErrorCode.NETWORK_ERROR, { error: error instanceof Error ? error.message : "Unknown error" });
69011
69016
  }
69012
69017
  }
69013
69018
  /**
69014
- * Get deposits for a specific chain
69019
+ * Get deposit events for a specific chain
69015
69020
  *
69016
- * @param chainId - Chain ID to fetch deposits from
69017
- * @param options - Event filter options
69018
- * @returns Array of deposit events
69019
- * @throws {DataError} If client is not configured or network error occurs
69021
+ * @param chainId - Chain ID to fetch events from
69022
+ * @param options - Event filter options including fromBlock, toBlock, and other filters
69023
+ * @returns Array of deposit events with properly typed fields (bigint for numbers, Hash for commitments)
69024
+ * @throws {DataError} If client is not configured, network error occurs, or event data is invalid
69020
69025
  */
69021
69026
  async getDeposits(chainId, options = {}) {
69022
69027
  try {
69023
69028
  const client = this.getClientForChain(chainId);
69024
69029
  const config = this.getConfigForChain(chainId);
69025
- const fromBlock = options.fromBlock ?? config.startBlock;
69026
- const toBlock = options.toBlock ?? undefined;
69027
- this.logger.debug(`Fetching deposits for chain ${chainId} from block ${fromBlock}${toBlock ? ` to ${toBlock}` : ""}`);
69028
- const query = presetQueryLogsOfEvent(config.privacyPoolAddress,
69029
- // topic0 is keccak256("Deposited(address,uint256,uint256,uint256,uint256)")
69030
- "0xe3b53cd1a44fbf11535e145d80b8ef1ed6d57a73bf5daa7e939b6b01657d6549", Number(fromBlock), toBlock ? Number(toBlock) : undefined);
69031
- if (options.depositor) {
69032
- const queryWithTopics = query;
69033
- const topic0 = queryWithTopics.topics[0];
69034
- if (!topic0) {
69035
- throw DataError.invalidLog("deposit", "missing topic0");
69036
- }
69037
- queryWithTopics.topics = [
69038
- topic0,
69039
- `0x000000000000000000000000${options.depositor.slice(2)}`,
69040
- ];
69041
- }
69042
- const res = await client.get(query);
69043
- // Create a map of block numbers to timestamps
69044
- const blockTimestamps = new Map(res.data.blocks.map(block => [
69045
- block.number,
69046
- block.timestamp ? BigInt(block.timestamp) : 0n
69047
- ]));
69048
- return res.data.logs.map((log) => {
69049
- let a = log;
69050
- if (!log.topics || log.topics.length < 2) {
69051
- throw DataError.invalidLog("deposit", "missing topics");
69052
- }
69053
- const depositorTopic = log.topics[1];
69054
- if (!depositorTopic) {
69055
- throw DataError.invalidLog("deposit", "missing depositor topic");
69056
- }
69057
- const depositor = BigInt(depositorTopic);
69058
- if (!log.data) {
69059
- throw DataError.invalidLog("deposit", "missing data");
69060
- }
69061
- const data = log.data.slice(2).match(/.{64}/g);
69062
- if (!data || data.length < 4) {
69063
- throw DataError.invalidLog("deposit", "insufficient data");
69064
- }
69065
- const commitment = BigInt("0x" + data[0]);
69066
- const label = BigInt("0x" + data[1]);
69067
- const value = BigInt("0x" + data[2]);
69068
- const precommitment = BigInt("0x" + data[3]);
69069
- if (!depositor ||
69070
- !commitment ||
69071
- !label ||
69072
- !value ||
69073
- !log.blockNumber ||
69074
- !log.transactionHash) {
69075
- throw DataError.invalidLog("deposit", "missing required fields");
69030
+ const logs = await client.getLogs({
69031
+ address: config.privacyPoolAddress,
69032
+ event: DEPOSIT_EVENT,
69033
+ fromBlock: options.fromBlock ?? config.startBlock,
69034
+ toBlock: options.toBlock,
69035
+ }).catch(error => {
69036
+ throw new DataError("Failed to fetch deposit logs", ErrorCode.NETWORK_ERROR, { error: error instanceof Error ? error.message : "Unknown error" });
69037
+ });
69038
+ return await Promise.all(logs.map(async (log) => {
69039
+ try {
69040
+ const block = await client.getBlock({ blockNumber: log.blockNumber });
69041
+ if (!log.args) {
69042
+ throw DataError.invalidLog("deposit", "missing args");
69043
+ }
69044
+ const { _depositor: depositor, _commitment: commitment, _label: label, _value: value, _merkleRoot: precommitment, } = log.args;
69045
+ if (!depositor || !commitment || !label || !value || !precommitment || !log.blockNumber || !log.transactionHash) {
69046
+ throw DataError.invalidLog("deposit", "missing required fields");
69047
+ }
69048
+ return {
69049
+ depositor: depositor.toLowerCase(),
69050
+ commitment: commitment,
69051
+ label: label,
69052
+ value,
69053
+ precommitment: precommitment,
69054
+ blockNumber: BigInt(log.blockNumber),
69055
+ timestamp: BigInt(block.timestamp),
69056
+ transactionHash: log.transactionHash,
69057
+ };
69076
69058
  }
69077
- const blockNumber = BigInt(log.blockNumber);
69078
- const timestamp = blockTimestamps.get(Number(blockNumber));
69079
- if (!timestamp) {
69080
- throw DataError.invalidLog("deposit", "missing block timestamp");
69059
+ catch (error) {
69060
+ if (error instanceof DataError)
69061
+ throw error;
69062
+ throw DataError.invalidLog("deposit", error instanceof Error ? error.message : "Unknown error");
69081
69063
  }
69082
- return {
69083
- depositor: `0x${depositor.toString(16).padStart(40, "0")}`,
69084
- commitment: bigintToHash(commitment),
69085
- label: bigintToHash(label),
69086
- value,
69087
- precommitment: bigintToHash(precommitment),
69088
- blockNumber,
69089
- timestamp,
69090
- transactionHash: log.transactionHash,
69091
- };
69092
- });
69064
+ }));
69093
69065
  }
69094
69066
  catch (error) {
69095
69067
  if (error instanceof DataError)
@@ -69098,69 +69070,50 @@ class DataService {
69098
69070
  }
69099
69071
  }
69100
69072
  /**
69101
- * Get withdrawals for a specific chain
69073
+ * Get withdrawal events for a specific chain
69102
69074
  *
69103
- * @param chainId - Chain ID to fetch withdrawals from
69104
- * @param options - Event filter options
69105
- * @returns Array of withdrawal events
69106
- * @throws {DataError} If client is not configured or network error occurs
69075
+ * @param chainId - Chain ID to fetch events from
69076
+ * @param options - Event filter options including fromBlock, toBlock, and other filters
69077
+ * @returns Array of withdrawal events with properly typed fields (bigint for numbers, Hash for commitments)
69078
+ * @throws {DataError} If client is not configured, network error occurs, or event data is invalid
69107
69079
  */
69108
69080
  async getWithdrawals(chainId, options = {}) {
69109
69081
  try {
69110
69082
  const client = this.getClientForChain(chainId);
69111
69083
  const config = this.getConfigForChain(chainId);
69112
- const fromBlock = options.fromBlock ?? config.startBlock;
69113
- const toBlock = options.toBlock ?? undefined;
69114
- this.logger.debug(`Fetching withdrawals for chain ${chainId} from block ${fromBlock}${toBlock ? ` to ${toBlock}` : ""}`);
69115
- const query = presetQueryLogsOfEvent(config.privacyPoolAddress,
69116
- // topic0 is keccak256("Withdrawn(address,uint256,uint256,uint256)")
69117
- "0x75e161b3e824b114fc1a33274bd7091918dd4e639cede50b78b15a4eea956a21", Number(fromBlock), toBlock ? Number(toBlock) : undefined);
69118
- const res = await client.get(query);
69119
- // Create a map of block numbers to timestamps
69120
- const blockTimestamps = new Map(res.data.blocks.map(block => [
69121
- block.number,
69122
- block.timestamp ? BigInt(block.timestamp) : 0n
69123
- ]));
69124
- return res.data.logs.map((log) => {
69125
- if (!log.topics || log.topics.length < 2) {
69126
- throw DataError.invalidLog("withdrawal", "missing topics");
69127
- }
69128
- const processorTopic = log.topics[1];
69129
- if (!processorTopic) {
69130
- throw DataError.invalidLog("withdrawal", "missing processor topic");
69131
- }
69132
- const processor = BigInt(processorTopic);
69133
- if (!log.data) {
69134
- throw DataError.invalidLog("withdrawal", "missing data");
69135
- }
69136
- const data = log.data.slice(2).match(/.{64}/g);
69137
- if (!data || data.length < 3) {
69138
- throw DataError.invalidLog("withdrawal", "insufficient data");
69139
- }
69140
- const value = BigInt("0x" + data[0]);
69141
- const spentNullifier = BigInt("0x" + data[1]);
69142
- const newCommitment = BigInt("0x" + data[2]);
69143
- if (!value ||
69144
- !spentNullifier ||
69145
- !newCommitment ||
69146
- !log.blockNumber ||
69147
- !log.transactionHash) {
69148
- throw DataError.invalidLog("withdrawal", "missing required fields");
69084
+ const logs = await client.getLogs({
69085
+ address: config.privacyPoolAddress,
69086
+ event: WITHDRAWAL_EVENT,
69087
+ fromBlock: options.fromBlock ?? config.startBlock,
69088
+ toBlock: options.toBlock,
69089
+ }).catch(error => {
69090
+ throw new DataError("Failed to fetch withdrawal logs", ErrorCode.NETWORK_ERROR, { error: error instanceof Error ? error.message : "Unknown error" });
69091
+ });
69092
+ return await Promise.all(logs.map(async (log) => {
69093
+ try {
69094
+ const block = await client.getBlock({ blockNumber: log.blockNumber });
69095
+ if (!log.args) {
69096
+ throw DataError.invalidLog("withdrawal", "missing args");
69097
+ }
69098
+ const { _value: value, _spentNullifier: spentNullifier, _newCommitment: newCommitment, } = log.args;
69099
+ if (!value || !spentNullifier || !newCommitment || !log.blockNumber || !log.transactionHash) {
69100
+ throw DataError.invalidLog("withdrawal", "missing required fields");
69101
+ }
69102
+ return {
69103
+ withdrawn: value,
69104
+ spentNullifier: spentNullifier,
69105
+ newCommitment: newCommitment,
69106
+ blockNumber: BigInt(log.blockNumber),
69107
+ timestamp: BigInt(block.timestamp),
69108
+ transactionHash: log.transactionHash,
69109
+ };
69149
69110
  }
69150
- const blockNumber = BigInt(log.blockNumber);
69151
- const timestamp = blockTimestamps.get(Number(blockNumber));
69152
- if (!timestamp) {
69153
- throw DataError.invalidLog("withdrawal", "missing block timestamp");
69111
+ catch (error) {
69112
+ if (error instanceof DataError)
69113
+ throw error;
69114
+ throw DataError.invalidLog("withdrawal", error instanceof Error ? error.message : "Unknown error");
69154
69115
  }
69155
- return {
69156
- withdrawn: value,
69157
- spentNullifier: bigintToHash(spentNullifier),
69158
- newCommitment: bigintToHash(newCommitment),
69159
- blockNumber,
69160
- timestamp,
69161
- transactionHash: log.transactionHash,
69162
- };
69163
- });
69116
+ }));
69164
69117
  }
69165
69118
  catch (error) {
69166
69119
  if (error instanceof DataError)
@@ -69171,100 +69124,49 @@ class DataService {
69171
69124
  /**
69172
69125
  * Get ragequit events for a specific chain
69173
69126
  *
69174
- * @param chainId - Chain ID to fetch ragequits from
69175
- * @param options - Event filter options
69176
- * @returns Array of ragequit events
69177
- * @throws {DataError} If client is not configured or network error occurs
69127
+ * @param chainId - Chain ID to fetch events from
69128
+ * @param options - Event filter options including fromBlock, toBlock, and other filters
69129
+ * @returns Array of ragequit events with properly typed fields (bigint for numbers, Hash for commitments)
69130
+ * @throws {DataError} If client is not configured, network error occurs, or event data is invalid
69178
69131
  */
69179
69132
  async getRagequits(chainId, options = {}) {
69180
69133
  try {
69181
69134
  const client = this.getClientForChain(chainId);
69182
69135
  const config = this.getConfigForChain(chainId);
69183
- const fromBlock = options.fromBlock ?? config.startBlock;
69184
- const toBlock = options.toBlock ?? undefined;
69185
- this.logger.debug(`Fetching ragequits for chain ${chainId} from block ${fromBlock}${toBlock ? ` to ${toBlock}` : ""}`);
69186
- const query = presetQueryLogsOfEvent(config.privacyPoolAddress,
69187
- // topic0 is keccak256("Ragequit(address,uint256,uint256,uint256)")
69188
- "0xd2b3e868ae101106371f2bd93abc8d5a4de488b9fe47ed122c23625aa7172f13", Number(fromBlock), toBlock ? Number(toBlock) : undefined);
69189
- const res = await client.get(query);
69190
- // Create a map of block numbers to timestamps
69191
- const blockTimestamps = new Map(res.data.blocks.map(block => [
69192
- block.number,
69193
- block.timestamp ? BigInt(block.timestamp) : 0n
69194
- ]));
69195
- return res.data.logs.map((log) => {
69196
- if (!log.topics || log.topics.length < 2) {
69197
- throw DataError.invalidLog("ragequit", "missing topics");
69198
- }
69199
- const ragequitterTopic = log.topics[1];
69200
- if (!ragequitterTopic) {
69201
- throw DataError.invalidLog("ragequit", "missing ragequitter topic");
69202
- }
69203
- const ragequitter = BigInt(ragequitterTopic);
69204
- if (!log.data) {
69205
- throw DataError.invalidLog("ragequit", "missing data");
69206
- }
69207
- const data = log.data.slice(2).match(/.{64}/g);
69208
- if (!data || data.length < 3) {
69209
- throw DataError.invalidLog("ragequit", "insufficient data");
69210
- }
69211
- const commitment = BigInt("0x" + data[0]);
69212
- const label = BigInt("0x" + data[1]);
69213
- const value = BigInt("0x" + data[2]);
69214
- if (!ragequitter ||
69215
- !commitment ||
69216
- !label ||
69217
- !value ||
69218
- !log.blockNumber ||
69219
- !log.transactionHash) {
69220
- throw DataError.invalidLog("ragequit", "missing required fields");
69221
- }
69222
- const blockNumber = BigInt(log.blockNumber);
69223
- const timestamp = blockTimestamps.get(Number(blockNumber));
69224
- if (!timestamp) {
69225
- throw DataError.invalidLog("ragequit", "missing block timestamp");
69226
- }
69227
- return {
69228
- ragequitter: `0x${ragequitter.toString(16).padStart(40, "0")}`,
69229
- commitment: bigintToHash(commitment),
69230
- label: bigintToHash(label),
69231
- value,
69232
- blockNumber,
69233
- timestamp,
69234
- transactionHash: log.transactionHash,
69235
- };
69136
+ const logs = await client.getLogs({
69137
+ address: config.privacyPoolAddress,
69138
+ event: RAGEQUIT_EVENT,
69139
+ fromBlock: options.fromBlock ?? config.startBlock,
69140
+ toBlock: options.toBlock,
69141
+ }).catch(error => {
69142
+ throw new DataError("Failed to fetch ragequit logs", ErrorCode.NETWORK_ERROR, { error: error instanceof Error ? error.message : "Unknown error" });
69236
69143
  });
69237
- }
69238
- catch (error) {
69239
- if (error instanceof DataError)
69240
- throw error;
69241
- throw DataError.networkError(chainId, error instanceof Error ? error : new Error(String(error)));
69242
- }
69243
- }
69244
- /**
69245
- * Get all events (deposits and withdrawals) for a specific chain in chronological order
69246
- *
69247
- * @param chainId - Chain ID to fetch events from
69248
- * @param options - Event filter options
69249
- * @returns Array of events sorted by block number
69250
- * @throws {DataError} If client is not configured or network error occurs
69251
- */
69252
- async getAllEvents(chainId, options = {}) {
69253
- try {
69254
- const [deposits, withdrawals] = await Promise.all([
69255
- this.getDeposits(chainId, options),
69256
- this.getWithdrawals(chainId, options),
69257
- ]);
69258
- return [
69259
- ...deposits.map((d) => ({ type: "deposit", ...d })),
69260
- ...withdrawals.map((w) => ({ type: "withdrawal", ...w })),
69261
- ].sort((a, b) => {
69262
- const blockDiff = a.blockNumber - b.blockNumber;
69263
- if (blockDiff === 0n) {
69264
- return a.type === "deposit" ? -1 : 1;
69144
+ return await Promise.all(logs.map(async (log) => {
69145
+ try {
69146
+ const block = await client.getBlock({ blockNumber: log.blockNumber });
69147
+ if (!log.args) {
69148
+ throw DataError.invalidLog("ragequit", "missing args");
69149
+ }
69150
+ const { _ragequitter: ragequitter, _commitment: commitment, _label: label, _value: value, } = log.args;
69151
+ if (!ragequitter || !commitment || !label || !value || !log.blockNumber || !log.transactionHash) {
69152
+ throw DataError.invalidLog("ragequit", "missing required fields");
69153
+ }
69154
+ return {
69155
+ ragequitter: ragequitter.toLowerCase(),
69156
+ commitment: commitment,
69157
+ label: label,
69158
+ value,
69159
+ blockNumber: BigInt(log.blockNumber),
69160
+ timestamp: BigInt(block.timestamp),
69161
+ transactionHash: log.transactionHash,
69162
+ };
69265
69163
  }
69266
- return Number(blockDiff);
69267
- });
69164
+ catch (error) {
69165
+ if (error instanceof DataError)
69166
+ throw error;
69167
+ throw DataError.invalidLog("ragequit", error instanceof Error ? error.message : "Unknown error");
69168
+ }
69169
+ }));
69268
69170
  }
69269
69171
  catch (error) {
69270
69172
  if (error instanceof DataError)
@@ -69280,29 +69182,13 @@ class DataService {
69280
69182
  return client;
69281
69183
  }
69282
69184
  getConfigForChain(chainId) {
69283
- const config = this.chainConfigs.find((c) => c.chainId === chainId);
69185
+ const config = this.chainConfigs.find(c => c.chainId === chainId);
69284
69186
  if (!config) {
69285
69187
  throw DataError.chainNotConfigured(chainId);
69286
69188
  }
69287
69189
  return config;
69288
69190
  }
69289
- getHypersyncUrlForChain(chainId) {
69290
- switch (chainId) {
69291
- case 1: // Ethereum Mainnet
69292
- return "https://eth.hypersync.xyz";
69293
- case 137: // Polygon
69294
- return "https://polygon.hypersync.xyz";
69295
- case 42161: // Arbitrum
69296
- return "https://arbitrum.hypersync.xyz";
69297
- case 10: // Optimism
69298
- return "https://optimism.hypersync.xyz";
69299
- case 11155111: // Sepolia
69300
- return "https://sepolia.hypersync.xyz";
69301
- default:
69302
- throw DataError.chainNotConfigured(chainId);
69303
- }
69304
- }
69305
69191
  }
69306
69192
 
69307
69193
  export { AccountService as A, BlockchainProvider as B, CommitmentService as C, DataService as D, ErrorCode as E, FetchArtifact as F, InvalidRpcUrl as I, PrivacyPoolSDK as P, SDKError as S, WithdrawalService as W, generateDepositSecrets as a, generateWithdrawalSecrets as b, getCommitment as c, generateMerkleProof as d, bigintToHash as e, bigintToHex as f, generateMasterKeys as g, hashPrecommitment as h, calculateContext as i, Circuits as j, ContractInteractionsService as k, ProofError as l, ContractError as m, AccountError as n, CircuitName as o };
69308
- //# sourceMappingURL=index-BLHTvD4r.js.map
69194
+ //# sourceMappingURL=index-CWlKxlGD.js.map