@yodlpay/payment-decoder 1.3.5 → 1.3.6

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 (2) hide show
  1. package/dist/index.js +56 -33
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,3 +1,6 @@
1
+ // src/bridges/bridge-payment.ts
2
+ import { parseDepositLogs as parseDepositLogs2, parseFillLogs as parseFillLogs2 } from "@across-protocol/app-sdk";
3
+
1
4
  // src/errors.ts
2
5
  var ExpectedDecodeError = class extends Error {
3
6
  constructor(message = "Expected decode error") {
@@ -495,7 +498,7 @@ async function calculateOutputAmountGross(inputAmount, inputToken, inputChainId,
495
498
  if (decimalDiff > 0) return inputAmount / 10n ** BigInt(decimalDiff);
496
499
  return inputAmount * 10n ** BigInt(-decimalDiff);
497
500
  }
498
- async function extractSenderFromSource(sourceReceipt, sourceProvider, sourceHash) {
501
+ function extractSenderFromSource(sourceReceipt) {
499
502
  const userOps = parseEventLogs2({
500
503
  abi: entryPoint08Abi,
501
504
  logs: sourceReceipt.logs.filter(
@@ -506,8 +509,7 @@ async function extractSenderFromSource(sourceReceipt, sourceProvider, sourceHash
506
509
  if (userOps[0]) {
507
510
  return userOps[0].args.sender;
508
511
  }
509
- const sourceTx = await sourceProvider.getTransaction({ hash: sourceHash });
510
- return sourceTx.from;
512
+ return sourceReceipt.from;
511
513
  }
512
514
  async function resolveBridgeTokens(sourceReceipt, destReceipt, yodlEvent, sender, inputAmountGross, inputChainId, outputChainId, clients) {
513
515
  const sourceTransfers = extractTokenTransfers(sourceReceipt.logs);
@@ -586,10 +588,10 @@ async function decodeRelayBridgePayment(hash, clients, options = {}) {
586
588
  "No Yodl event found in destination transaction"
587
589
  );
588
590
  }
589
- const [destBlock, destTx, sender] = await Promise.all([
591
+ const sender = extractSenderFromSource(sourceReceipt);
592
+ const [destBlock, destTx] = await Promise.all([
590
593
  destProvider.getBlock({ blockNumber: destReceipt.blockNumber }),
591
- destProvider.getTransaction({ hash: destinationTxHash }),
592
- extractSenderFromSource(sourceReceipt, sourceProvider, sourceTxHash)
594
+ destProvider.getTransaction({ hash: destinationTxHash })
593
595
  ]);
594
596
  const tokens = await resolveBridgeTokens(
595
597
  sourceReceipt,
@@ -619,29 +621,26 @@ async function decodeRelayBridgePayment(hash, clients, options = {}) {
619
621
  }
620
622
 
621
623
  // src/bridges/across-bridge.ts
622
- async function resolveAcrossStatus(hash, fillReceipt) {
623
- try {
624
- return await fetchAcrossDepositByTx(hash);
625
- } catch (error) {
626
- if (!(error instanceof NoBridgeFoundError) || !fillReceipt) {
627
- throw error;
624
+ async function resolveAcrossStatus(hash, fillReceipt, cachedFillLog) {
625
+ const fillLog = cachedFillLog !== void 0 ? cachedFillLog : fillReceipt ? parseFillLogs(fillReceipt.logs) : null;
626
+ if (fillLog) {
627
+ const status = await fetchAcrossDepositByDepositId(
628
+ Number(fillLog.originChainId),
629
+ String(fillLog.depositId)
630
+ );
631
+ if (status.fillTxnRef?.toLowerCase() === hash.toLowerCase()) {
632
+ return status;
628
633
  }
634
+ return await fetchAcrossDepositByTx(hash);
629
635
  }
630
- const fillLog = parseFillLogs(fillReceipt.logs);
631
- if (!fillLog) {
632
- throw new NoBridgeFoundError();
633
- }
634
- const status = await fetchAcrossDepositByDepositId(
635
- Number(fillLog.originChainId),
636
- String(fillLog.depositId)
637
- );
638
- if (!status.fillTxnRef || status.fillTxnRef.toLowerCase() !== hash.toLowerCase()) {
639
- throw new NoBridgeFoundError();
640
- }
641
- return status;
636
+ return await fetchAcrossDepositByTx(hash);
642
637
  }
643
638
  async function decodeAcrossBridgePayment(hash, clients, options = {}) {
644
- const status = await resolveAcrossStatus(hash, options.fillReceipt);
639
+ const status = await resolveAcrossStatus(
640
+ hash,
641
+ options.fillReceipt,
642
+ options.parsedFillLog
643
+ );
645
644
  if (status.status !== "filled" || !status.fillTxnRef) {
646
645
  throw new NoBridgeFoundError();
647
646
  }
@@ -669,10 +668,10 @@ async function decodeAcrossBridgePayment(hash, clients, options = {}) {
669
668
  if (!yodlEvent) {
670
669
  throw new NoBridgeFoundError();
671
670
  }
672
- const [destBlock, destTx, sender] = await Promise.all([
671
+ const sender = extractSenderFromSource(sourceReceipt);
672
+ const [destBlock, destTx] = await Promise.all([
673
673
  destProvider.getBlock({ blockNumber: destReceipt.blockNumber }),
674
- destProvider.getTransaction({ hash: destinationTxHash }),
675
- extractSenderFromSource(sourceReceipt, sourceProvider, sourceTxHash)
674
+ destProvider.getTransaction({ hash: destinationTxHash })
676
675
  ]);
677
676
  const depositLog = parseDepositLogs(sourceReceipt.logs);
678
677
  const depositData = depositLog && depositLog.depositId === BigInt(status.depositId) ? {
@@ -733,6 +732,16 @@ async function decodeAcrossBridgePayment(hash, clients, options = {}) {
733
732
  // src/bridges/bridge-payment.ts
734
733
  async function decodeBridgePayment(hash, clients, options = {}) {
735
734
  const includeAcross = options.includeAcross ?? true;
735
+ const parsedFillLog = options.fillReceipt ? parseFillLogs2(options.fillReceipt.logs) : null;
736
+ const parsedDepositLog = options.sourceReceipt ? parseDepositLogs2(options.sourceReceipt.logs) : null;
737
+ const hasAcrossEvents = !!(parsedFillLog || parsedDepositLog);
738
+ if (includeAcross && hasAcrossEvents) {
739
+ return await decodeAcrossBridgePayment(hash, clients, {
740
+ fillReceipt: options.fillReceipt,
741
+ sourceReceipt: options.sourceReceipt,
742
+ parsedFillLog
743
+ });
744
+ }
736
745
  let relayError;
737
746
  try {
738
747
  return await decodeRelayBridgePayment(hash, clients, {
@@ -768,6 +777,7 @@ async function decodeBridgePayment(hash, clients, options = {}) {
768
777
 
769
778
  // src/core/payment-decoder.ts
770
779
  import { getRouter as getRouter3 } from "@yodlpay/tokenlists";
780
+ import { isAddressEqual as isAddressEqual3 } from "viem";
771
781
  async function tryDecodeBridge(hash, clients, options = {}) {
772
782
  try {
773
783
  return await decodeBridgePayment(hash, clients, options);
@@ -798,10 +808,17 @@ async function decodePayment(hash, chainId2, clients, cachedReceipt) {
798
808
  );
799
809
  return { type: "swap", ...paymentEvent2, ...swapEvent };
800
810
  }
801
- const bridgeResult2 = await tryDecodeBridge(hash, clients, {
802
- fillReceipt: receipt
803
- });
804
- if (bridgeResult2) return bridgeResult2;
811
+ const effectiveSender = extractSenderFromSource(receipt);
812
+ const isSameChainPayment = isAddressEqual3(
813
+ effectiveSender,
814
+ yodlEvent.sender
815
+ );
816
+ if (!isSameChainPayment) {
817
+ const bridgeResult2 = await tryDecodeBridge(hash, clients, {
818
+ fillReceipt: receipt
819
+ });
820
+ if (bridgeResult2) return bridgeResult2;
821
+ }
805
822
  const [block, tx] = await Promise.all([
806
823
  provider.getBlock({ blockNumber: receipt.blockNumber }),
807
824
  provider.getTransaction({ hash })
@@ -831,10 +848,16 @@ async function decodePayment(hash, chainId2, clients, cachedReceipt) {
831
848
  // src/core/yodl-payment.ts
832
849
  import {
833
850
  formatUnits,
851
+ isAddressEqual as isAddressEqual4,
834
852
  zeroAddress
835
853
  } from "viem";
836
854
  async function buildTokenInfo(params, clients) {
837
- const [inToken, outToken] = await Promise.all([
855
+ const sameToken = isAddressEqual4(params.tokenIn, params.tokenOut) && params.inChainId === params.outChainId;
856
+ const [inToken, outToken] = sameToken ? await resolveToken(
857
+ params.tokenIn,
858
+ params.inChainId,
859
+ getClient(clients, params.inChainId)
860
+ ).then((t) => [t, t]) : await Promise.all([
838
861
  resolveToken(
839
862
  params.tokenIn,
840
863
  params.inChainId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yodlpay/payment-decoder",
3
- "version": "1.3.5",
3
+ "version": "1.3.6",
4
4
  "description": "Decode Yodl payment hashes into structured payment data",
5
5
  "keywords": [
6
6
  "yodl",