@zkp2p/cash 0.1.4 → 0.1.5

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.js CHANGED
@@ -607,10 +607,18 @@ function collectRelayTransactions(steps, sourceChainId) {
607
607
  for (const step of steps) {
608
608
  for (const item of step.items) {
609
609
  for (const tx of item.internalTxHashes ?? []) {
610
- record({ hash: tx.txHash, chainId: tx.chainId });
610
+ record({
611
+ hash: tx.txHash,
612
+ chainId: tx.chainId,
613
+ ...tx.isBatchTx ? { isBatchTx: true } : {}
614
+ });
611
615
  }
612
616
  for (const tx of item.txHashes ?? []) {
613
- record({ hash: tx.txHash, chainId: tx.chainId });
617
+ record({
618
+ hash: tx.txHash,
619
+ chainId: tx.chainId,
620
+ ...tx.isBatchTx ? { isBatchTx: true } : {}
621
+ });
614
622
  }
615
623
  }
616
624
  }
@@ -1330,6 +1338,78 @@ function createCashClient(options) {
1330
1338
  }
1331
1339
  throw errors.allowanceNotVisible(amount, lastReadError);
1332
1340
  }
1341
+ async function waitForBaseSignerAfterRelay(client, cashoutSigner, sourceSigner, owner, sourceChainId, executed) {
1342
+ if (sourceChainId !== BASE_CHAIN_ID) return;
1343
+ const baseTransactions = (executed.transactions?.origin ?? []).filter(
1344
+ (transaction) => transaction.chainId === BASE_CHAIN_ID
1345
+ );
1346
+ const batchIds = baseTransactions.filter((transaction) => transaction.isBatchTx === true).map((transaction) => transaction.hash);
1347
+ let batchTransactionHashes = [];
1348
+ if (batchIds.length > 0) {
1349
+ let batchError;
1350
+ let batchesComplete = false;
1351
+ for (let attempt = 0; attempt < 20; attempt++) {
1352
+ try {
1353
+ const statuses = await Promise.all(
1354
+ batchIds.map((id) => sourceSigner.getCallsStatus({ id }))
1355
+ );
1356
+ if (statuses.some((status) => status.status === "failure")) {
1357
+ throw new Error("Relay wallet call bundle failed");
1358
+ }
1359
+ if (statuses.every((status) => status.status === "success")) {
1360
+ batchTransactionHashes = statuses.flatMap(
1361
+ (status) => (status.receipts ?? []).map((receipt) => receipt.transactionHash)
1362
+ );
1363
+ batchesComplete = true;
1364
+ break;
1365
+ }
1366
+ } catch (err) {
1367
+ batchError = err;
1368
+ }
1369
+ await sleep(250);
1370
+ }
1371
+ if (!batchesComplete) {
1372
+ throw batchError ?? new Error("Relay wallet call bundle did not complete");
1373
+ }
1374
+ }
1375
+ const hashes = [
1376
+ ...baseTransactions.filter((transaction) => transaction.isBatchTx !== true).map((transaction) => transaction.hash),
1377
+ ...batchTransactionHashes
1378
+ ];
1379
+ if (hashes.length === 0) return;
1380
+ let transactions;
1381
+ let lastLookupError;
1382
+ for (let attempt = 0; attempt < 20; attempt++) {
1383
+ try {
1384
+ transactions = await Promise.all(
1385
+ hashes.map((hash) => client.publicClient.getTransaction({ hash }))
1386
+ );
1387
+ break;
1388
+ } catch (err) {
1389
+ lastLookupError = err;
1390
+ await sleep(250);
1391
+ }
1392
+ }
1393
+ if (!transactions) throw lastLookupError;
1394
+ const ownerNonces = transactions.filter((transaction) => transaction.from.toLowerCase() === owner.toLowerCase()).map((transaction) => transaction.nonce);
1395
+ if (ownerNonces.length === 0) return;
1396
+ const afterRelay = Math.max(...ownerNonces) + 1;
1397
+ let lastNonceError;
1398
+ for (let attempt = 0; attempt < 20; attempt++) {
1399
+ try {
1400
+ const pendingHex = await cashoutSigner.transport.request({
1401
+ method: "eth_getTransactionCount",
1402
+ params: [owner, "pending"]
1403
+ });
1404
+ if (Number(BigInt(pendingHex)) >= afterRelay) return;
1405
+ } catch (err) {
1406
+ lastNonceError = err;
1407
+ }
1408
+ await sleep(250);
1409
+ }
1410
+ if (lastNonceError) throw lastNonceError;
1411
+ throw new Error(`Signer provider did not observe Relay nonce ${afterRelay - 1}`);
1412
+ }
1333
1413
  return {
1334
1414
  capabilities,
1335
1415
  async sourceCapabilities() {
@@ -1401,6 +1481,21 @@ function createCashClient(options) {
1401
1481
  ...executed.transactions ? { transactions: executed.transactions } : {}
1402
1482
  };
1403
1483
  sourceResult = routedSource;
1484
+ try {
1485
+ await waitForBaseSignerAfterRelay(
1486
+ client,
1487
+ opts.signer,
1488
+ sourceSigner,
1489
+ owner,
1490
+ input.source.chainId,
1491
+ executed
1492
+ );
1493
+ } catch (err) {
1494
+ throw errors.sourceRouteCompletedCashoutFailed(
1495
+ routedSource,
1496
+ mapChainError("resolve same-chain Relay nonce", err)
1497
+ );
1498
+ }
1404
1499
  const attributedParams2 = { ...params2, txOverrides: attribution };
1405
1500
  const send2 = async () => {
1406
1501
  try {
@@ -1773,7 +1868,8 @@ var bigintString = z.string().regex(/^-?\d+$/, "expected a decimal bigint string
1773
1868
  var nonNegativeBigintString = z.string().regex(/^\d+$/, "expected a non-negative decimal bigint string");
1774
1869
  var relayTransactionJsonSchema = z.object({
1775
1870
  hash: z.string(),
1776
- chainId: z.number()
1871
+ chainId: z.number(),
1872
+ isBatchTx: z.boolean().optional()
1777
1873
  });
1778
1874
  var relayTransactionsJsonSchema = z.object({
1779
1875
  origin: z.array(relayTransactionJsonSchema),
package/dist/react.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { CurrencyType } from '@zkp2p/sdk';
2
- import { q as CashClient, E as EstimateInput, i as CashEstimate, B as CashoutOptions, h as CashoutResult, A as CashoutInput, T as TopUpResult, W as WithdrawResult, e as CashOrder } from './createCashClient-BbkfxILl.cjs';
2
+ import { q as CashClient, E as EstimateInput, i as CashEstimate, B as CashoutOptions, h as CashoutResult, A as CashoutInput, T as TopUpResult, W as WithdrawResult, e as CashOrder } from './createCashClient-jUA_GNdh.cjs';
3
3
  import { WalletClient } from 'viem';
4
4
  import '@relayprotocol/relay-sdk';
5
5
 
package/dist/react.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { CurrencyType } from '@zkp2p/sdk';
2
- import { q as CashClient, E as EstimateInput, i as CashEstimate, B as CashoutOptions, h as CashoutResult, A as CashoutInput, T as TopUpResult, W as WithdrawResult, e as CashOrder } from './createCashClient-BbkfxILl.js';
2
+ import { q as CashClient, E as EstimateInput, i as CashEstimate, B as CashoutOptions, h as CashoutResult, A as CashoutInput, T as TopUpResult, W as WithdrawResult, e as CashOrder } from './createCashClient-jUA_GNdh.js';
3
3
  import { WalletClient } from 'viem';
4
4
  import '@relayprotocol/relay-sdk';
5
5
 
package/dist/tools.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  // package.json
4
4
  var package_default = {
5
- version: "0.1.4"};
5
+ version: "0.1.5"};
6
6
 
7
7
  // src/tools/index.ts
8
8
  var bigintString = {
package/dist/tools.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // package.json
2
2
  var package_default = {
3
- version: "0.1.4"};
3
+ version: "0.1.5"};
4
4
 
5
5
  // src/tools/index.ts
6
6
  var bigintString = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zkp2p/cash",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Peer Cash - offramp-only SDK for routing crypto to Base USDC, then cashing out to fiat at the live oracle market rate.",
5
5
  "license": "MIT",
6
6
  "author": "Peer (https://peer.xyz)",