@yodlpay/payment-decoder 1.1.0 → 1.2.0

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,4 +1,5 @@
1
1
  import { PublicClient, Address, Hex, Log } from 'viem';
2
+ import { TokenInfo } from '@yodlpay/tokenlists';
2
3
 
3
4
  type ChainClients = Record<number, PublicClient>;
4
5
  declare function createClients(): ChainClients;
@@ -39,6 +40,16 @@ type PaymentInfo = (PaymentEvent & {
39
40
  }) | (PaymentEvent & BridgeInfo & {
40
41
  type: "bridge";
41
42
  });
43
+ interface TokenInInfo extends TokenInfo {
44
+ amount: bigint;
45
+ amountFormatted: string;
46
+ }
47
+ interface TokenOutInfo extends TokenInfo {
48
+ amountGross: bigint;
49
+ amountGrossFormatted: string;
50
+ amountNet: bigint;
51
+ amountNetFormatted: string;
52
+ }
42
53
  interface YodlPayment {
43
54
  senderAddress: Address;
44
55
  receiverAddress: Address;
@@ -46,16 +57,13 @@ interface YodlPayment {
46
57
  processorMemo: string;
47
58
  processorAddress: Address;
48
59
  data: Record<string, unknown>;
49
- tokenInAddress: Address;
50
- tokenInAmount: string;
51
- tokenOutAddress: Address;
60
+ tokenIn: TokenInInfo;
61
+ tokenOut: TokenOutInfo;
52
62
  originChainId: number;
53
63
  originTxHash: Hex;
54
64
  destinationChainId: number;
55
65
  destinationTxHash: Hex;
56
66
  solver: string | null;
57
- tokenOutAmountGross: string;
58
- tokenOutAmountNet: string;
59
67
  blockTimestamp: Date;
60
68
  }
61
69
 
@@ -99,4 +107,4 @@ declare function decodeBridgePayment(hash: Hex, clients: ChainClients): Promise<
99
107
 
100
108
  declare function decodeYodlPayment(txHash: Hex, chainId: number, clients: ChainClients): Promise<YodlPayment>;
101
109
 
102
- export { type BridgeInfo, type ChainClients, type DecodedYodlEvent, NoBridgeFoundError, NoYodlEventError, type PaymentEvent, type PaymentInfo, type ServiceProvider, type SwapInfo, type Webhook, type YodlPayment, createClients, decodeBridgePayment, decodePayment, decodeYodlFromLogs, decodeYodlPayment };
110
+ export { type BridgeInfo, type ChainClients, type DecodedYodlEvent, NoBridgeFoundError, NoYodlEventError, type PaymentEvent, type PaymentInfo, type ServiceProvider, type SwapInfo, type TokenInInfo, type TokenOutInfo, type Webhook, type YodlPayment, createClients, decodeBridgePayment, decodePayment, decodeYodlFromLogs, decodeYodlPayment };
package/dist/index.js CHANGED
@@ -476,33 +476,35 @@ async function decodePayment(hash, chainId, clients) {
476
476
  // src/yodl-payment.ts
477
477
  import { getTokenByAddress as getTokenByAddress2 } from "@yodlpay/tokenlists";
478
478
  import { formatUnits, zeroAddress } from "viem";
479
- function formatTokenAmounts(params) {
480
- const { decimals: inDecimals } = getTokenByAddress2(
481
- params.tokenIn,
482
- params.inChainId
483
- );
484
- const { decimals: outDecimals } = getTokenByAddress2(
485
- params.tokenOut,
486
- params.outChainId
487
- );
488
- const tokenOutAmountGross = formatUnits(
489
- params.tokenOutAmountGross,
490
- outDecimals
491
- );
492
- const tokenOutAmountNet = formatUnits(params.tokenOutAmountNet, outDecimals);
479
+ function buildTokenInfo(params) {
480
+ const inToken = getTokenByAddress2(params.tokenIn, params.inChainId);
481
+ const outToken = getTokenByAddress2(params.tokenOut, params.outChainId);
493
482
  return {
494
- tokenInAddress: params.tokenIn,
495
- tokenInAmount: formatUnits(params.tokenInAmount, inDecimals),
496
- tokenOutAddress: params.tokenOut,
497
- tokenOutAmountGross,
498
- tokenOutAmountNet
483
+ tokenIn: {
484
+ ...inToken,
485
+ amount: params.tokenInAmount,
486
+ amountFormatted: formatUnits(params.tokenInAmount, inToken.decimals)
487
+ },
488
+ tokenOut: {
489
+ ...outToken,
490
+ amountGross: params.tokenOutAmountGross,
491
+ amountGrossFormatted: formatUnits(
492
+ params.tokenOutAmountGross,
493
+ outToken.decimals
494
+ ),
495
+ amountNet: params.tokenOutAmountNet,
496
+ amountNetFormatted: formatUnits(
497
+ params.tokenOutAmountNet,
498
+ outToken.decimals
499
+ )
500
+ }
499
501
  };
500
502
  }
501
503
  function extractTokenInfo(paymentInfo, chainId, txHash) {
502
504
  switch (paymentInfo.type) {
503
505
  case "direct": {
504
506
  return {
505
- ...formatTokenAmounts({
507
+ ...buildTokenInfo({
506
508
  tokenIn: paymentInfo.token,
507
509
  tokenInAmount: paymentInfo.amount,
508
510
  tokenOut: paymentInfo.token,
@@ -520,7 +522,7 @@ function extractTokenInfo(paymentInfo, chainId, txHash) {
520
522
  }
521
523
  case "swap": {
522
524
  return {
523
- ...formatTokenAmounts({
525
+ ...buildTokenInfo({
524
526
  tokenIn: paymentInfo.tokenIn,
525
527
  tokenInAmount: paymentInfo.tokenInAmount,
526
528
  tokenOut: paymentInfo.token,
@@ -538,7 +540,7 @@ function extractTokenInfo(paymentInfo, chainId, txHash) {
538
540
  }
539
541
  case "bridge": {
540
542
  return {
541
- ...formatTokenAmounts({
543
+ ...buildTokenInfo({
542
544
  tokenIn: paymentInfo.tokenIn,
543
545
  tokenInAmount: paymentInfo.tokenInAmount,
544
546
  tokenOut: paymentInfo.tokenOut,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yodlpay/payment-decoder",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Decode Yodl payment hashes into structured payment data",
5
5
  "keywords": [
6
6
  "yodl",