@keplr-wallet/background 0.12.313 → 0.13.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.
Files changed (83) hide show
  1. package/build/index.d.ts +1 -0
  2. package/build/index.js +7 -1
  3. package/build/index.js.map +1 -1
  4. package/build/keyring-cosmos/service.d.ts +10 -0
  5. package/build/keyring-cosmos/service.js +100 -0
  6. package/build/keyring-cosmos/service.js.map +1 -1
  7. package/build/keyring-ethereum/service.d.ts +5 -0
  8. package/build/keyring-ethereum/service.js +66 -0
  9. package/build/keyring-ethereum/service.js.map +1 -1
  10. package/build/recent-send-history/api.d.ts +31 -0
  11. package/build/recent-send-history/api.js +97 -0
  12. package/build/recent-send-history/api.js.map +1 -0
  13. package/build/recent-send-history/handler.js +36 -0
  14. package/build/recent-send-history/handler.js.map +1 -1
  15. package/build/recent-send-history/init.js +5 -0
  16. package/build/recent-send-history/init.js.map +1 -1
  17. package/build/recent-send-history/messages.d.ts +76 -1
  18. package/build/recent-send-history/messages.js +121 -1
  19. package/build/recent-send-history/messages.js.map +1 -1
  20. package/build/recent-send-history/service.d.ts +262 -9
  21. package/build/recent-send-history/service.js +2103 -812
  22. package/build/recent-send-history/service.js.map +1 -1
  23. package/build/recent-send-history/types.d.ts +214 -22
  24. package/build/recent-send-history/types.js +21 -0
  25. package/build/recent-send-history/types.js.map +1 -1
  26. package/build/tx/service.d.ts +2 -0
  27. package/build/tx/service.js +35 -0
  28. package/build/tx/service.js.map +1 -1
  29. package/build/tx-ethereum/service.d.ts +2 -0
  30. package/build/tx-ethereum/service.js +42 -0
  31. package/build/tx-ethereum/service.js.map +1 -1
  32. package/build/tx-executor/constants.d.ts +1 -0
  33. package/build/tx-executor/constants.js +5 -0
  34. package/build/tx-executor/constants.js.map +1 -0
  35. package/build/tx-executor/handler.d.ts +3 -0
  36. package/build/tx-executor/handler.js +45 -0
  37. package/build/tx-executor/handler.js.map +1 -0
  38. package/build/tx-executor/index.d.ts +3 -0
  39. package/build/tx-executor/index.js +20 -0
  40. package/build/tx-executor/index.js.map +1 -0
  41. package/build/tx-executor/init.d.ts +3 -0
  42. package/build/tx-executor/init.js +14 -0
  43. package/build/tx-executor/init.js.map +1 -0
  44. package/build/tx-executor/internal.d.ts +4 -0
  45. package/build/tx-executor/internal.js +24 -0
  46. package/build/tx-executor/internal.js.map +1 -0
  47. package/build/tx-executor/messages.d.ts +53 -0
  48. package/build/tx-executor/messages.js +116 -0
  49. package/build/tx-executor/messages.js.map +1 -0
  50. package/build/tx-executor/service.d.ts +67 -0
  51. package/build/tx-executor/service.js +715 -0
  52. package/build/tx-executor/service.js.map +1 -0
  53. package/build/tx-executor/types.d.ts +105 -0
  54. package/build/tx-executor/types.js +33 -0
  55. package/build/tx-executor/types.js.map +1 -0
  56. package/build/tx-executor/utils/cosmos.d.ts +59 -0
  57. package/build/tx-executor/utils/cosmos.js +526 -0
  58. package/build/tx-executor/utils/cosmos.js.map +1 -0
  59. package/build/tx-executor/utils/evm.d.ts +4 -0
  60. package/build/tx-executor/utils/evm.js +236 -0
  61. package/build/tx-executor/utils/evm.js.map +1 -0
  62. package/package.json +13 -13
  63. package/src/index.ts +24 -1
  64. package/src/keyring-cosmos/service.ts +151 -0
  65. package/src/keyring-ethereum/service.ts +103 -6
  66. package/src/recent-send-history/api.ts +119 -0
  67. package/src/recent-send-history/handler.ts +84 -0
  68. package/src/recent-send-history/init.ts +10 -0
  69. package/src/recent-send-history/messages.ts +163 -1
  70. package/src/recent-send-history/service.ts +3042 -1153
  71. package/src/recent-send-history/types.ts +268 -31
  72. package/src/tx/service.ts +41 -0
  73. package/src/tx-ethereum/service.ts +57 -0
  74. package/src/tx-executor/constants.ts +1 -0
  75. package/src/tx-executor/handler.ts +71 -0
  76. package/src/tx-executor/index.ts +3 -0
  77. package/src/tx-executor/init.ts +20 -0
  78. package/src/tx-executor/internal.ts +9 -0
  79. package/src/tx-executor/messages.ts +157 -0
  80. package/src/tx-executor/service.ts +1025 -0
  81. package/src/tx-executor/types.ts +161 -0
  82. package/src/tx-executor/utils/cosmos.ts +771 -0
  83. package/src/tx-executor/utils/evm.ts +310 -0
@@ -0,0 +1,119 @@
1
+ import { simpleFetch } from "@keplr-wallet/simple-fetch";
2
+ import {
3
+ SwapProvider,
4
+ SwapV2TxStatusResponse,
5
+ TxStatusResponse,
6
+ SwapV2TxStatusRequest,
7
+ } from "./types";
8
+ import { EthTxReceipt, JsonRpcResponse } from "@keplr-wallet/types";
9
+
10
+ export async function requestSkipTxTrack(params: {
11
+ endpoint: string;
12
+ chainId: string;
13
+ txHash: string;
14
+ }) {
15
+ const { endpoint, chainId, txHash } = params;
16
+ return simpleFetch<any>(endpoint, "/v1/swap/tx", {
17
+ method: "POST",
18
+ headers: {
19
+ "content-type": "application/json",
20
+ },
21
+ body: JSON.stringify({
22
+ tx_hash: txHash,
23
+ chain_id: chainId,
24
+ }),
25
+ });
26
+ }
27
+
28
+ export async function requestSkipTxStatus(params: {
29
+ endpoint: string;
30
+ chainId: string;
31
+ txHash: string;
32
+ }) {
33
+ const { endpoint, chainId, txHash } = params;
34
+
35
+ const requestParams = new URLSearchParams({
36
+ chain_id: chainId,
37
+ tx_hash: txHash,
38
+ }).toString();
39
+
40
+ return simpleFetch<TxStatusResponse>(
41
+ endpoint,
42
+ `/v1/swap/tx?${requestParams}`,
43
+ {
44
+ method: "GET",
45
+ headers: {
46
+ "content-type": "application/json",
47
+ },
48
+ }
49
+ );
50
+ }
51
+
52
+ export async function requestSwapV2TxStatus(params: {
53
+ endpoint: string;
54
+ fromChainId: string;
55
+ toChainId: string;
56
+ provider: SwapProvider;
57
+ txHash: string;
58
+ }) {
59
+ const { endpoint, fromChainId, toChainId, provider, txHash } = params;
60
+
61
+ const request: SwapV2TxStatusRequest = {
62
+ provider,
63
+ from_chain: fromChainId,
64
+ to_chain: toChainId,
65
+ tx_hash: txHash,
66
+ };
67
+
68
+ return simpleFetch<SwapV2TxStatusResponse>(endpoint, "v2/swap/tx_status", {
69
+ method: "POST",
70
+ headers: {
71
+ "content-type": "application/json",
72
+ },
73
+ body: JSON.stringify(request),
74
+ });
75
+ }
76
+
77
+ export async function requestEthTxReceipt(params: {
78
+ rpc: string;
79
+ txHash: string;
80
+ origin?: string;
81
+ id?: number;
82
+ }) {
83
+ const { rpc, txHash, origin, id = 1 } = params;
84
+ return simpleFetch<JsonRpcResponse<EthTxReceipt>>(rpc, {
85
+ method: "POST",
86
+ headers: {
87
+ "content-type": "application/json",
88
+ ...(origin ? { "request-source": origin } : {}),
89
+ },
90
+ body: JSON.stringify({
91
+ jsonrpc: "2.0",
92
+ method: "eth_getTransactionReceipt",
93
+ params: [txHash],
94
+ id,
95
+ }),
96
+ });
97
+ }
98
+
99
+ export async function requestEthTxTrace(params: {
100
+ rpc: string;
101
+ txHash: string;
102
+ origin?: string;
103
+ id?: number;
104
+ }) {
105
+ const { rpc, txHash, origin, id = 1 } = params;
106
+ return simpleFetch<JsonRpcResponse<any>>(rpc, {
107
+ method: "POST",
108
+ headers: {
109
+ "content-type": "application/json",
110
+ ...(origin ? { "request-source": origin } : {}),
111
+ },
112
+ body: JSON.stringify({
113
+ jsonrpc: "2.0",
114
+ method: "debug_traceTransaction",
115
+ params: [txHash, { tracer: "callTracer" }],
116
+ id,
117
+ }),
118
+ });
119
+ }
@@ -18,6 +18,11 @@ import {
18
18
  RemoveSkipHistoryMsg,
19
19
  ClearAllSkipHistoryMsg,
20
20
  RecordTxWithSkipSwapMsg,
21
+ RecordTxWithSwapV2Msg,
22
+ GetSwapV2HistoriesMsg,
23
+ RemoveSwapV2HistoryMsg,
24
+ ClearAllSwapV2HistoryMsg,
25
+ HideSwapV2HistoryMsg,
21
26
  } from "./messages";
22
27
  import { RecentSendHistoryService } from "./service";
23
28
 
@@ -86,6 +91,31 @@ export const getHandler: (service: RecentSendHistoryService) => Handler = (
86
91
  env,
87
92
  msg as ClearAllSkipHistoryMsg
88
93
  );
94
+ case RecordTxWithSwapV2Msg:
95
+ return handleRecordTxWithSwapV2Msg(service)(
96
+ env,
97
+ msg as RecordTxWithSwapV2Msg
98
+ );
99
+ case GetSwapV2HistoriesMsg:
100
+ return handleGetSwapV2HistoriesMsg(service)(
101
+ env,
102
+ msg as GetSwapV2HistoriesMsg
103
+ );
104
+ case RemoveSwapV2HistoryMsg:
105
+ return handleRemoveSwapV2HistoryMsg(service)(
106
+ env,
107
+ msg as RemoveSwapV2HistoryMsg
108
+ );
109
+ case ClearAllSwapV2HistoryMsg:
110
+ return handleClearAllSwapV2HistoryMsg(service)(
111
+ env,
112
+ msg as ClearAllSwapV2HistoryMsg
113
+ );
114
+ case HideSwapV2HistoryMsg:
115
+ return handleHideSwapV2HistoryMsg(service)(
116
+ env,
117
+ msg as HideSwapV2HistoryMsg
118
+ );
89
119
  default:
90
120
  throw new KeplrError("tx", 110, "Unknown msg type");
91
121
  }
@@ -253,3 +283,57 @@ const handleClearAllSkipHistoryMsg: (
253
283
  service.clearAllRecentSkipHistory();
254
284
  };
255
285
  };
286
+
287
+ const handleRecordTxWithSwapV2Msg: (
288
+ service: RecentSendHistoryService
289
+ ) => InternalHandler<RecordTxWithSwapV2Msg> = (service) => {
290
+ return async (_env, msg) => {
291
+ return service.recordTxWithSwapV2(
292
+ msg.fromChainId,
293
+ msg.toChainId,
294
+ msg.provider,
295
+ msg.destinationAsset,
296
+ msg.simpleRoute,
297
+ msg.sender,
298
+ msg.recipient,
299
+ msg.amount,
300
+ msg.notificationInfo,
301
+ msg.routeDurationSeconds,
302
+ msg.txHash,
303
+ msg.isOnlyUseBridge
304
+ );
305
+ };
306
+ };
307
+
308
+ const handleGetSwapV2HistoriesMsg: (
309
+ service: RecentSendHistoryService
310
+ ) => InternalHandler<GetSwapV2HistoriesMsg> = (service) => {
311
+ return (_env, _msg) => {
312
+ return service.getRecentSwapV2Histories();
313
+ };
314
+ };
315
+
316
+ const handleRemoveSwapV2HistoryMsg: (
317
+ service: RecentSendHistoryService
318
+ ) => InternalHandler<RemoveSwapV2HistoryMsg> = (service) => {
319
+ return (_env, msg) => {
320
+ service.removeRecentSwapV2History(msg.id);
321
+ return service.getRecentSwapV2Histories();
322
+ };
323
+ };
324
+
325
+ const handleClearAllSwapV2HistoryMsg: (
326
+ service: RecentSendHistoryService
327
+ ) => InternalHandler<ClearAllSwapV2HistoryMsg> = (service) => {
328
+ return (_env, _msg) => {
329
+ service.clearAllRecentSwapV2History();
330
+ };
331
+ };
332
+
333
+ const handleHideSwapV2HistoryMsg: (
334
+ service: RecentSendHistoryService
335
+ ) => InternalHandler<HideSwapV2HistoryMsg> = (service) => {
336
+ return (_env, msg) => {
337
+ service.hideSwapV2History(msg.id);
338
+ };
339
+ };
@@ -12,6 +12,11 @@ import {
12
12
  RecordTxWithSkipSwapMsg,
13
13
  GetSkipHistoriesMsg,
14
14
  RemoveSkipHistoryMsg,
15
+ RecordTxWithSwapV2Msg,
16
+ GetSwapV2HistoriesMsg,
17
+ RemoveSwapV2HistoryMsg,
18
+ ClearAllSwapV2HistoryMsg,
19
+ HideSwapV2HistoryMsg,
15
20
  } from "./messages";
16
21
  import { ROUTE } from "./constants";
17
22
  import { getHandler } from "./handler";
@@ -30,6 +35,11 @@ export function init(router: Router, service: RecentSendHistoryService): void {
30
35
  router.registerMessage(GetSkipHistoriesMsg);
31
36
  router.registerMessage(RemoveSkipHistoryMsg);
32
37
  router.registerMessage(ClearAllSkipHistoryMsg);
38
+ router.registerMessage(RecordTxWithSwapV2Msg);
39
+ router.registerMessage(GetSwapV2HistoriesMsg);
40
+ router.registerMessage(RemoveSwapV2HistoryMsg);
41
+ router.registerMessage(ClearAllSwapV2HistoryMsg);
42
+ router.registerMessage(HideSwapV2HistoryMsg);
33
43
 
34
44
  router.addHandler(ROUTE, getHandler(service));
35
45
  }
@@ -1,6 +1,12 @@
1
1
  import { Message } from "@keplr-wallet/router";
2
2
  import { ROUTE } from "./constants";
3
- import { IBCHistory, RecentSendHistory, SkipHistory } from "./types";
3
+ import {
4
+ IBCHistory,
5
+ RecentSendHistory,
6
+ SkipHistory,
7
+ SwapProvider,
8
+ SwapV2History,
9
+ } from "./types";
4
10
  import { AppCurrency } from "@keplr-wallet/types";
5
11
 
6
12
  export class GetRecentSendHistoriesMsg extends Message<RecentSendHistory[]> {
@@ -539,3 +545,159 @@ export class ClearAllSkipHistoryMsg extends Message<void> {
539
545
  return ClearAllSkipHistoryMsg.type();
540
546
  }
541
547
  }
548
+
549
+ export class RecordTxWithSwapV2Msg extends Message<string> {
550
+ public static type() {
551
+ return "record-tx-with-swap-v2";
552
+ }
553
+
554
+ constructor(
555
+ public readonly fromChainId: string,
556
+ public readonly toChainId: string,
557
+ public readonly provider: SwapProvider,
558
+ public readonly destinationAsset: {
559
+ chainId: string;
560
+ denom: string;
561
+ expectedAmount: string;
562
+ },
563
+ public readonly simpleRoute: {
564
+ isOnlyEvm: boolean;
565
+ chainId: string;
566
+ receiver: string;
567
+ }[],
568
+ public readonly sender: string,
569
+ public readonly recipient: string,
570
+ public readonly amount: {
571
+ readonly amount: string;
572
+ readonly denom: string;
573
+ }[],
574
+ public readonly notificationInfo: {
575
+ currencies: AppCurrency[];
576
+ },
577
+ public readonly routeDurationSeconds: number,
578
+ public readonly txHash: string,
579
+ public readonly isOnlyUseBridge?: boolean
580
+ ) {
581
+ super();
582
+ }
583
+
584
+ validateBasic(): void {
585
+ if (!this.fromChainId) {
586
+ throw new Error("chain id is empty");
587
+ }
588
+
589
+ if (!this.toChainId) {
590
+ throw new Error("chain id is empty");
591
+ }
592
+
593
+ if (!this.simpleRoute) {
594
+ throw new Error("simple route is empty");
595
+ }
596
+
597
+ if (!this.sender) {
598
+ throw new Error("sender is empty");
599
+ }
600
+
601
+ if (!this.recipient) {
602
+ throw new Error("recipient is empty");
603
+ }
604
+ }
605
+
606
+ route(): string {
607
+ return ROUTE;
608
+ }
609
+
610
+ type(): string {
611
+ return RecordTxWithSwapV2Msg.type();
612
+ }
613
+ }
614
+
615
+ export class GetSwapV2HistoriesMsg extends Message<SwapV2History[]> {
616
+ public static type() {
617
+ return "get-swap-v2-histories";
618
+ }
619
+
620
+ constructor() {
621
+ super();
622
+ }
623
+
624
+ validateBasic(): void {
625
+ // noop
626
+ }
627
+
628
+ route(): string {
629
+ return ROUTE;
630
+ }
631
+
632
+ type(): string {
633
+ return GetSwapV2HistoriesMsg.type();
634
+ }
635
+ }
636
+
637
+ export class RemoveSwapV2HistoryMsg extends Message<SwapV2History[]> {
638
+ public static type() {
639
+ return "remove-swap-v2-histories";
640
+ }
641
+
642
+ constructor(public readonly id: string) {
643
+ super();
644
+ }
645
+
646
+ validateBasic(): void {
647
+ if (!this.id) {
648
+ throw new Error("id is empty");
649
+ }
650
+ }
651
+
652
+ route(): string {
653
+ return ROUTE;
654
+ }
655
+
656
+ type(): string {
657
+ return RemoveSwapV2HistoryMsg.type();
658
+ }
659
+ }
660
+
661
+ export class ClearAllSwapV2HistoryMsg extends Message<void> {
662
+ public static type() {
663
+ return "clear-all-swap-v2-histories";
664
+ }
665
+
666
+ constructor() {
667
+ super();
668
+ }
669
+
670
+ validateBasic(): void {
671
+ // noop
672
+ }
673
+
674
+ route(): string {
675
+ return ROUTE;
676
+ }
677
+
678
+ type(): string {
679
+ return ClearAllSwapV2HistoryMsg.type();
680
+ }
681
+ }
682
+
683
+ export class HideSwapV2HistoryMsg extends Message<void> {
684
+ public static type() {
685
+ return "hide-swap-v2-history";
686
+ }
687
+
688
+ constructor(public readonly id: string) {
689
+ super();
690
+ }
691
+
692
+ validateBasic(): void {
693
+ // noop
694
+ }
695
+
696
+ route(): string {
697
+ return ROUTE;
698
+ }
699
+
700
+ type(): string {
701
+ return HideSwapV2HistoryMsg.type();
702
+ }
703
+ }