@yodlpay/payment-decoder 1.1.0 → 1.2.1
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 +18 -10
- package/dist/index.js +41 -39
- package/package.json +1 -1
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;
|
|
@@ -26,8 +27,8 @@ interface SwapInfo {
|
|
|
26
27
|
service: ServiceProvider;
|
|
27
28
|
}
|
|
28
29
|
interface BridgeInfo extends SwapInfo {
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
sourceChainId: number;
|
|
31
|
+
sourceTxHash: Hex;
|
|
31
32
|
destinationChainId: number;
|
|
32
33
|
destinationTxHash: Hex;
|
|
33
34
|
tokenOutAmountGross: bigint;
|
|
@@ -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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
originTxHash: Hex;
|
|
60
|
+
tokenIn: TokenInInfo;
|
|
61
|
+
tokenOut: TokenOutInfo;
|
|
62
|
+
sourceChainId: number;
|
|
63
|
+
sourceTxHash: 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
|
@@ -374,8 +374,8 @@ function parseRelayResponse(request) {
|
|
|
374
374
|
throw new NoBridgeFoundError();
|
|
375
375
|
}
|
|
376
376
|
return {
|
|
377
|
-
|
|
378
|
-
|
|
377
|
+
sourceChainId: inTx.chainId,
|
|
378
|
+
sourceTxHash: inTx.hash,
|
|
379
379
|
destinationChainId: outTx.chainId,
|
|
380
380
|
destinationTxHash: outTx.hash,
|
|
381
381
|
inputAmountGross: BigInt(data?.metadata?.currencyIn?.amount ?? 0)
|
|
@@ -384,18 +384,18 @@ function parseRelayResponse(request) {
|
|
|
384
384
|
async function decodeBridgePayment(hash, clients) {
|
|
385
385
|
const request = await fetchRelayRequest(hash);
|
|
386
386
|
const {
|
|
387
|
-
|
|
388
|
-
|
|
387
|
+
sourceChainId,
|
|
388
|
+
sourceTxHash,
|
|
389
389
|
destinationChainId,
|
|
390
390
|
destinationTxHash,
|
|
391
391
|
inputAmountGross
|
|
392
392
|
} = parseRelayResponse(request);
|
|
393
393
|
const destProvider = getClient(clients, destinationChainId);
|
|
394
|
-
const sourceProvider = getClient(clients,
|
|
394
|
+
const sourceProvider = getClient(clients, sourceChainId);
|
|
395
395
|
const { address: routerAddress } = getRouter(destinationChainId);
|
|
396
396
|
const [destReceipt, sourceReceipt] = await Promise.all([
|
|
397
397
|
destProvider.getTransactionReceipt({ hash: destinationTxHash }),
|
|
398
|
-
sourceProvider.getTransactionReceipt({ hash:
|
|
398
|
+
sourceProvider.getTransactionReceipt({ hash: sourceTxHash })
|
|
399
399
|
]);
|
|
400
400
|
const yodlEvent = decodeYodlFromLogs(destReceipt.logs, routerAddress);
|
|
401
401
|
if (!yodlEvent) {
|
|
@@ -406,7 +406,7 @@ async function decodeBridgePayment(hash, clients) {
|
|
|
406
406
|
const [destBlock, destTx, sender] = await Promise.all([
|
|
407
407
|
destProvider.getBlock({ blockNumber: destReceipt.blockNumber }),
|
|
408
408
|
destProvider.getTransaction({ hash: destinationTxHash }),
|
|
409
|
-
extractSenderFromSource(sourceReceipt, sourceProvider,
|
|
409
|
+
extractSenderFromSource(sourceReceipt, sourceProvider, sourceTxHash)
|
|
410
410
|
]);
|
|
411
411
|
const tokens = resolveBridgeTokens(
|
|
412
412
|
sourceReceipt,
|
|
@@ -414,12 +414,12 @@ async function decodeBridgePayment(hash, clients) {
|
|
|
414
414
|
yodlEvent,
|
|
415
415
|
sender,
|
|
416
416
|
inputAmountGross,
|
|
417
|
-
|
|
417
|
+
sourceChainId,
|
|
418
418
|
destinationChainId
|
|
419
419
|
);
|
|
420
420
|
const bridge = {
|
|
421
|
-
|
|
422
|
-
|
|
421
|
+
sourceChainId,
|
|
422
|
+
sourceTxHash,
|
|
423
423
|
destinationChainId,
|
|
424
424
|
destinationTxHash,
|
|
425
425
|
...tokens,
|
|
@@ -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
|
|
480
|
-
const
|
|
481
|
-
|
|
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
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
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
|
-
...
|
|
507
|
+
...buildTokenInfo({
|
|
506
508
|
tokenIn: paymentInfo.token,
|
|
507
509
|
tokenInAmount: paymentInfo.amount,
|
|
508
510
|
tokenOut: paymentInfo.token,
|
|
@@ -511,8 +513,8 @@ function extractTokenInfo(paymentInfo, chainId, txHash) {
|
|
|
511
513
|
inChainId: chainId,
|
|
512
514
|
outChainId: chainId
|
|
513
515
|
}),
|
|
514
|
-
|
|
515
|
-
|
|
516
|
+
sourceChainId: chainId,
|
|
517
|
+
sourceTxHash: txHash,
|
|
516
518
|
destinationChainId: chainId,
|
|
517
519
|
destinationTxHash: txHash,
|
|
518
520
|
solver: null
|
|
@@ -520,7 +522,7 @@ function extractTokenInfo(paymentInfo, chainId, txHash) {
|
|
|
520
522
|
}
|
|
521
523
|
case "swap": {
|
|
522
524
|
return {
|
|
523
|
-
...
|
|
525
|
+
...buildTokenInfo({
|
|
524
526
|
tokenIn: paymentInfo.tokenIn,
|
|
525
527
|
tokenInAmount: paymentInfo.tokenInAmount,
|
|
526
528
|
tokenOut: paymentInfo.token,
|
|
@@ -529,8 +531,8 @@ function extractTokenInfo(paymentInfo, chainId, txHash) {
|
|
|
529
531
|
inChainId: chainId,
|
|
530
532
|
outChainId: chainId
|
|
531
533
|
}),
|
|
532
|
-
|
|
533
|
-
|
|
534
|
+
sourceChainId: chainId,
|
|
535
|
+
sourceTxHash: txHash,
|
|
534
536
|
destinationChainId: chainId,
|
|
535
537
|
destinationTxHash: txHash,
|
|
536
538
|
solver: paymentInfo.service ?? null
|
|
@@ -538,17 +540,17 @@ function extractTokenInfo(paymentInfo, chainId, txHash) {
|
|
|
538
540
|
}
|
|
539
541
|
case "bridge": {
|
|
540
542
|
return {
|
|
541
|
-
...
|
|
543
|
+
...buildTokenInfo({
|
|
542
544
|
tokenIn: paymentInfo.tokenIn,
|
|
543
545
|
tokenInAmount: paymentInfo.tokenInAmount,
|
|
544
546
|
tokenOut: paymentInfo.tokenOut,
|
|
545
547
|
tokenOutAmountGross: paymentInfo.tokenOutAmountGross,
|
|
546
548
|
tokenOutAmountNet: paymentInfo.amount,
|
|
547
|
-
inChainId: paymentInfo.
|
|
549
|
+
inChainId: paymentInfo.sourceChainId,
|
|
548
550
|
outChainId: paymentInfo.destinationChainId
|
|
549
551
|
}),
|
|
550
|
-
|
|
551
|
-
|
|
552
|
+
sourceChainId: paymentInfo.sourceChainId,
|
|
553
|
+
sourceTxHash: paymentInfo.sourceTxHash,
|
|
552
554
|
destinationChainId: paymentInfo.destinationChainId,
|
|
553
555
|
destinationTxHash: paymentInfo.destinationTxHash,
|
|
554
556
|
solver: paymentInfo.service ?? null
|