@continuumdao/ctm-mpc-defi 0.2.59 → 0.2.61

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.
@@ -1,5 +1,5 @@
1
1
  import { Address } from 'viem';
2
- import { TXIDVersion, NetworkName, TransactionGasDetails } from '@railgun-community/shared-models';
2
+ import { TXIDVersion, NetworkName, TransactionGasDetails, RailgunBalancesEvent } from '@railgun-community/shared-models';
3
3
 
4
4
  /** Aligns with app NonEvmChainType + 'evm'. Extend as mpc-auth adds chains. */
5
5
  type ChainCategory = 'evm' | 'solana' | 'near' | 'sui' | 'ton' | 'stellar';
@@ -226,6 +226,8 @@ type AllowanceReader = (args: {
226
226
  }) => Promise<bigint>;
227
227
  declare function setRailgunPopulateShieldForTests(fn: PopulateShield | null): void;
228
228
  declare function setRailgunAllowanceReaderForTests(fn: AllowanceReader | null): void;
229
+ /** Railgun hashes the 65-byte personal_sign. The node often returns r||s without the recovery byte. */
230
+ declare function shieldPrivateKeyFromSignature(signature: string, executorAddress?: string): Promise<`0x${string}`>;
229
231
  declare function buildEvmMultisignBodyWethUnwrap(args: {
230
232
  keyGen: KeyGenSubset;
231
233
  executorAddress: Address | string;
@@ -247,8 +249,65 @@ type RailgunPrivateActionArgs = {
247
249
  amountWei: string;
248
250
  recipientAddress: string;
249
251
  memoText?: string;
252
+ onBroadcasterSearch?: () => void;
253
+ onBroadcasterNote?: (note: string) => void;
250
254
  onProofProgress?: (progress: number) => void;
255
+ onProofStatusRefresh?: () => void;
256
+ broadcasterFeesId?: string;
251
257
  };
258
+ /** Railgun replaces the note-check text with a short sentence. Keep the required amount and balance when they are still attached. */
259
+ declare function railgunDetailedError(err: unknown): string;
260
+ /** The broadcaster accepted the proof request and asked for a fresh proof-of-innocence status. */
261
+ declare function broadcasterAskedToRefreshProofStatus(err: unknown): boolean;
262
+ declare function broadcasterRefusedForGas(err: unknown): boolean;
263
+ /** A fee message can take about a minute to arrive after the spending-wallet sync. */
264
+ declare const BROADCASTER_PROOF_WAIT_MS: number;
265
+ /** Same margin the Waku client uses before it treats a fee as expired. */
266
+ declare const BROADCASTER_FEE_MIN_REMAINING_MS = 40000;
267
+ declare function broadcasterFeeStillValid(expiration: number, now?: number): boolean;
268
+ type RailgunBroadcasterChoice = {
269
+ feesId: string;
270
+ railgunAddress: string;
271
+ feeWei: string;
272
+ ratio: string | null;
273
+ coversGas: boolean;
274
+ reliability: number;
275
+ expiration: number;
276
+ tokenDecimals: number;
277
+ };
278
+ declare function listRailgunBroadcasters(args: {
279
+ chainId: number;
280
+ rpcUrl: string;
281
+ chainDetail: EvmChainDetail;
282
+ tokenAddress: string;
283
+ kind: string;
284
+ }): Promise<RailgunBroadcasterChoice[]>;
285
+ declare function quoteRailgunBroadcasterFee(args: {
286
+ kind: 'transfer' | 'unshield';
287
+ chainId: number;
288
+ rpcUrl: string;
289
+ chainDetail: EvmChainDetail;
290
+ tokenAddress: string;
291
+ amountWei: string;
292
+ recipientAddress: string;
293
+ memoText?: string;
294
+ walletId: string;
295
+ encryptionKey: string;
296
+ }): Promise<{
297
+ feeWei: string;
298
+ tokenAddress: string;
299
+ }>;
300
+ /** Broadcaster fee from the live fee rate and chain gas. A view-only wallet cannot run the proof estimate. */
301
+ declare function quoteRailgunBroadcasterFeeRate(args: {
302
+ kind: 'transfer' | 'unshield';
303
+ chainId: number;
304
+ rpcUrl: string;
305
+ chainDetail: EvmChainDetail;
306
+ tokenAddress: string;
307
+ }): Promise<{
308
+ feeWei: string;
309
+ tokenAddress: string;
310
+ }>;
252
311
  declare function railgunPrivateTransfer(args: RailgunPrivateActionArgs): Promise<{
253
312
  txHash: string;
254
313
  }>;
@@ -256,6 +315,36 @@ declare function railgunUnshield(args: RailgunPrivateActionArgs): Promise<{
256
315
  txHash: string;
257
316
  }>;
258
317
 
318
+ type RailgunFeeKind = 'shield' | 'transfer' | 'unshield';
319
+ type RailgunFeeQuote = {
320
+ kind: RailgunFeeKind;
321
+ amountWei: string;
322
+ protocolFeeBasisPoints: string;
323
+ protocolFeeWei: string;
324
+ receivedWei: string;
325
+ broadcasterFeeWei: string;
326
+ broadcasterTokenAddress: string;
327
+ totalDebitWei: string;
328
+ broadcasterError?: string;
329
+ };
330
+ declare function railgunProtocolFee(amount: bigint, basisPoints: bigint): {
331
+ fee: bigint;
332
+ received: bigint;
333
+ };
334
+ declare function clearRailgunFeeCache(): void;
335
+ declare function quoteRailgunFee(args: {
336
+ kind: RailgunFeeKind;
337
+ chainId: number;
338
+ rpcUrl: string;
339
+ chainDetail?: EvmChainDetail;
340
+ tokenAddress: string;
341
+ amountWei: string;
342
+ recipientAddress?: string;
343
+ memoText?: string;
344
+ walletId?: string;
345
+ encryptionKey?: string;
346
+ }): Promise<RailgunFeeQuote>;
347
+
259
348
  declare function createRailgunBrowserWallet(args: {
260
349
  encryptionKey: string;
261
350
  mnemonic: string;
@@ -270,25 +359,72 @@ declare function openRailgunViewOnlyWallet(args: {
270
359
  encryptionKey: string;
271
360
  shareableViewingKey: string;
272
361
  chainId: number;
362
+ keyGenId?: string;
273
363
  }): Promise<{
274
364
  walletId: string;
275
365
  railgunAddress: string;
276
366
  }>;
277
367
  declare function discardRailgunWallet(walletId: string): Promise<void>;
278
368
  declare function railgunAddressIsValid(address: string): Promise<boolean>;
369
+ declare function recordRailgunWalletBalance(event: RailgunBalancesEvent): void;
370
+ declare function railgunWalletBalanceSnapshot(walletId: string, chainId: number): RailgunPrivateBalanceRow[];
371
+ declare function clearRailgunWalletBalances(): void;
279
372
  /** History sync emits Complete on the merkletree callback. It does not emit the wallet event awaitWalletScan waits for. */
280
373
  declare function utxoScanTerminalStatus(scanStatus: string): 'done' | 'failed' | 'pending';
374
+ /** After the note scan reports 100%, wait this long for the spendable-note check, then save the balances already decrypted. */
375
+ declare const RAILGUN_TXID_WAIT_AFTER_NOTES_MS = 45000;
376
+ /** After the history walk, sync blocks that were mined while it was running. A shield in that gap is otherwise left out. */
377
+ declare const RAILGUN_CATCH_UP_MS = 120000;
378
+ /** The first merkletree walk can take much longer than the catch-up window. Give up only when progress itself stops. */
379
+ declare const RAILGUN_MERKLETREE_STALL_MS: number;
380
+ declare const RAILGUN_SCAN_BEHIND_NOTE = "The shielded balance is saved. The newest blocks did not finish syncing, so a shield that just landed may be missing until the next scan.";
381
+ declare const RAILGUN_SCAN_STOPPED_NOTE = "The note scan stopped before it reached the latest block. The shielded balance is unchanged until a scan finishes.";
382
+ /** A catch-up timer that expires while leaves are still arriving has not finished the tree. */
383
+ declare function merkletreeScanStillRunning(args: {
384
+ sawProgress: boolean;
385
+ notesFinished: boolean;
386
+ terminal: 'done' | 'failed' | 'pending';
387
+ }): boolean;
388
+ declare function railgunScanRecord(merkletree: 'done' | 'failed', balanceCount: number, caughtUp: boolean): {
389
+ scanStatus: RailgunScanStatus;
390
+ notes: string;
391
+ };
392
+ declare function balancesToKeepAfterNoteScan(decrypted: RailgunPrivateBalanceRow[], afterRefresh: RailgunPrivateBalanceRow[], previous: RailgunPrivateBalanceRow[]): RailgunPrivateBalanceRow[];
393
+ declare const RAILGUN_SPEND_SCAN_STOPPED = "The spending wallet did not finish scanning private notes.";
394
+ /**
395
+ * History complete is emitted at 100% after this wallet's notes are decrypted.
396
+ * The decrypt-complete wallet event is deferred until after that, so 100% is the
397
+ * signal to build the proof. Give up only when leaves stop arriving before then.
398
+ */
399
+ declare function spendingScanReadyAfterHistory(progress: number, scanStatus: string): boolean;
400
+ declare function spendingNoteScanGaveUp(args: {
401
+ walletReady: boolean;
402
+ sawProgress: boolean;
403
+ notesFinished: boolean;
404
+ msSinceProgress: number;
405
+ msWaitingForDecrypt: number | null;
406
+ }): boolean;
407
+ /** Decrypt this spending wallet's notes before a proof. A view-only scan does not fill this wallet. */
408
+ declare function scanSpendingWalletNotes(args: {
409
+ chainId: number;
410
+ rpcUrl: string;
411
+ walletId: string;
412
+ onProgress?: (progress: number) => void;
413
+ }): Promise<void>;
281
414
  declare function scanRailgunPrivateBalances(args: {
282
415
  chainId: number;
283
416
  rpcUrl: string;
284
417
  walletId: string;
285
418
  onProgress?: (progress: number) => void;
419
+ onBalances?: (balances: RailgunPrivateBalanceRow[]) => void;
286
420
  }): Promise<{
287
421
  scanStatus: RailgunScanStatus;
288
422
  balances: RailgunPrivateBalanceRow[];
423
+ settled: boolean;
424
+ notes: string;
289
425
  }>;
290
426
 
291
427
  declare const RAILGUN_PROTOCOL_ID = "railgun";
292
428
  declare const railgunProtocolModule: ProtocolModule;
293
429
 
294
- export { RAILGUN_CTM_DISABLED_MESSAGE, RAILGUN_CTM_ENABLED, RAILGUN_POPULAR_ASSET_LIMIT, RAILGUN_PROTOCOL_ID, RAILGUN_WALLET_LOCKED_MESSAGE, type RailgunNetworkRow, type RailgunNetworkSource, type RailgunPrivateActionArgs, type RailgunPrivateBalanceRow, type RailgunPrivateBalanceSnapshot, type RailgunScanStatus, type RailgunShieldArgs, type RailgunWalletSession, type ShieldCommitmentLike, assertRailgunCtmAllowed, buildEvmMultisignBodyRailgunShield, buildEvmMultisignBodyWethUnwrap, clearRailgunNetworkCache, clearRailgunPopularAssetCache, clearRailgunPrivateBalanceSnapshots, commitmentsFromShieldIndex, createRailgunBrowserWallet, discardRailgunWallet, getRailgunWalletSession, loadRailgunNetworks, loadRailgunPopularAssets, loadRailgunSupportedChainIds, openRailgunViewOnlyWallet, publishRailgunPrivateBalanceSnapshot, railgunAddressIsValid, railgunFetchPopularAssets, railgunFetchPrivateBalances, railgunFetchPrivateBalancesSummary, railgunNetworkByChainId, railgunPrivateTransfer, railgunProtocolModule, railgunShareableViewingKey, railgunUnshield, rankPopularShieldTokens, readRailgunPrivateBalanceSnapshot, requireRailgunWalletSession, scanRailgunPrivateBalances, selectRailgunNetworks, setRailgunAllowanceReaderForTests, setRailgunPopulateShieldForTests, setRailgunShieldLogReaderForTests, setRailgunWalletSession, shieldIndexEndpoint, unlockRailgunBrowserWallet, utxoScanTerminalStatus };
430
+ export { BROADCASTER_FEE_MIN_REMAINING_MS, BROADCASTER_PROOF_WAIT_MS, RAILGUN_CATCH_UP_MS, RAILGUN_CTM_DISABLED_MESSAGE, RAILGUN_CTM_ENABLED, RAILGUN_MERKLETREE_STALL_MS, RAILGUN_POPULAR_ASSET_LIMIT, RAILGUN_PROTOCOL_ID, RAILGUN_SCAN_BEHIND_NOTE, RAILGUN_SCAN_STOPPED_NOTE, RAILGUN_SPEND_SCAN_STOPPED, RAILGUN_TXID_WAIT_AFTER_NOTES_MS, RAILGUN_WALLET_LOCKED_MESSAGE, type RailgunBroadcasterChoice, type RailgunFeeKind, type RailgunFeeQuote, type RailgunNetworkRow, type RailgunNetworkSource, type RailgunPrivateActionArgs, type RailgunPrivateBalanceRow, type RailgunPrivateBalanceSnapshot, type RailgunScanStatus, type RailgunShieldArgs, type RailgunWalletSession, type ShieldCommitmentLike, assertRailgunCtmAllowed, balancesToKeepAfterNoteScan, broadcasterAskedToRefreshProofStatus, broadcasterFeeStillValid, broadcasterRefusedForGas, buildEvmMultisignBodyRailgunShield, buildEvmMultisignBodyWethUnwrap, clearRailgunFeeCache, clearRailgunNetworkCache, clearRailgunPopularAssetCache, clearRailgunPrivateBalanceSnapshots, clearRailgunWalletBalances, commitmentsFromShieldIndex, createRailgunBrowserWallet, discardRailgunWallet, getRailgunWalletSession, listRailgunBroadcasters, loadRailgunNetworks, loadRailgunPopularAssets, loadRailgunSupportedChainIds, merkletreeScanStillRunning, openRailgunViewOnlyWallet, publishRailgunPrivateBalanceSnapshot, quoteRailgunBroadcasterFee, quoteRailgunBroadcasterFeeRate, quoteRailgunFee, railgunAddressIsValid, railgunDetailedError, railgunFetchPopularAssets, railgunFetchPrivateBalances, railgunFetchPrivateBalancesSummary, railgunNetworkByChainId, railgunPrivateTransfer, railgunProtocolFee, railgunProtocolModule, railgunScanRecord, railgunShareableViewingKey, railgunUnshield, railgunWalletBalanceSnapshot, rankPopularShieldTokens, readRailgunPrivateBalanceSnapshot, recordRailgunWalletBalance, requireRailgunWalletSession, scanRailgunPrivateBalances, scanSpendingWalletNotes, selectRailgunNetworks, setRailgunAllowanceReaderForTests, setRailgunPopulateShieldForTests, setRailgunShieldLogReaderForTests, setRailgunWalletSession, shieldIndexEndpoint, shieldPrivateKeyFromSignature, spendingNoteScanGaveUp, spendingScanReadyAfterHistory, unlockRailgunBrowserWallet, utxoScanTerminalStatus };