@daimo/pay-common 0.0.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/src/chain.ts ADDED
@@ -0,0 +1,151 @@
1
+ export type Chain = {
2
+ chainId: number;
3
+ name: string;
4
+ cctpDomain: number | null;
5
+ };
6
+
7
+ export const arbitrum: Chain = {
8
+ chainId: 42161,
9
+ name: "Arbitrum",
10
+ cctpDomain: 3,
11
+ };
12
+
13
+ export const base: Chain = {
14
+ chainId: 8453,
15
+ name: "Base",
16
+ cctpDomain: 6,
17
+ };
18
+
19
+ export const blast: Chain = {
20
+ chainId: 81457,
21
+ name: "Blast",
22
+ cctpDomain: null,
23
+ };
24
+
25
+ export const bsc: Chain = {
26
+ chainId: 56,
27
+ name: "BNB Smart Chain",
28
+ cctpDomain: null,
29
+ };
30
+
31
+ export const ethereum: Chain = {
32
+ chainId: 1,
33
+ name: "Ethereum",
34
+ cctpDomain: 0,
35
+ };
36
+
37
+ export const linea: Chain = {
38
+ chainId: 59144,
39
+ name: "Linea",
40
+ cctpDomain: null,
41
+ };
42
+
43
+ export const mantle: Chain = {
44
+ chainId: 5000,
45
+ name: "Mantle",
46
+ cctpDomain: null,
47
+ };
48
+
49
+ export const optimism: Chain = {
50
+ chainId: 10,
51
+ name: "Optimism",
52
+ cctpDomain: 2,
53
+ };
54
+
55
+ export const polygon: Chain = {
56
+ chainId: 137,
57
+ name: "Polygon",
58
+ cctpDomain: 7,
59
+ };
60
+
61
+ export const solana: Chain = {
62
+ chainId: 101,
63
+ name: "Solana",
64
+ cctpDomain: 5,
65
+ };
66
+
67
+ export const worldchain: Chain = {
68
+ chainId: 480,
69
+ name: "Worldchain",
70
+ cctpDomain: null,
71
+ };
72
+
73
+ export const chainConfigs: Chain[] = [
74
+ arbitrum,
75
+ base,
76
+ blast,
77
+ bsc,
78
+ ethereum,
79
+ linea,
80
+ mantle,
81
+ optimism,
82
+ polygon,
83
+ solana,
84
+ worldchain,
85
+ ];
86
+
87
+ /** Given a chainId, return the chain. */
88
+ export function getChainById(chainId: number): Chain {
89
+ const ret = chainConfigs.find((c) => c.chainId === chainId);
90
+ if (ret == null) throw new Error(`Unknown chainId ${chainId}`);
91
+ return ret;
92
+ }
93
+
94
+ /** Returns the chain name for the given chainId. */
95
+ export function getChainName(chainId: number): string {
96
+ return getChainById(chainId).name;
97
+ }
98
+
99
+ /**
100
+ * Get block explorer URL for chain ID
101
+ */
102
+ export function getChainExplorerByChainId(chainId: number): string | undefined {
103
+ switch (chainId) {
104
+ case arbitrum.chainId:
105
+ return "https://arbiscan.io";
106
+ case base.chainId:
107
+ return "https://basescan.org";
108
+ case blast.chainId:
109
+ return "https://blastscan.io";
110
+ case bsc.chainId:
111
+ return "https://bscscan.com";
112
+ case ethereum.chainId:
113
+ return "https://etherscan.io";
114
+ case linea.chainId:
115
+ return "https://lineascan.build";
116
+ case mantle.chainId:
117
+ return "https://mantlescan.xyz";
118
+ case optimism.chainId:
119
+ return "https://optimistic.etherscan.io";
120
+ case polygon.chainId:
121
+ return "https://polygonscan.com";
122
+ case solana.chainId:
123
+ return "https://solscan.io";
124
+ case worldchain.chainId:
125
+ return "https://worldscan.org";
126
+ default:
127
+ return undefined;
128
+ }
129
+ }
130
+
131
+ /**
132
+ * Get block explorer address URL for chain ID and address.
133
+ */
134
+ export function getChainExplorerAddressUrl(chainId: number, address: string) {
135
+ const explorer = getChainExplorerByChainId(chainId);
136
+ if (!explorer) {
137
+ return undefined;
138
+ }
139
+ return `${explorer}/address/${address}`;
140
+ }
141
+
142
+ /**
143
+ * Get block explorer transaction URL for chain ID and transaction hash.
144
+ */
145
+ export function getChainExplorerTxUrl(chainId: number, txHash: string) {
146
+ const explorer = getChainExplorerByChainId(chainId);
147
+ if (!explorer) {
148
+ return undefined;
149
+ }
150
+ return `${explorer}/tx/${txHash}`;
151
+ }
package/src/debug.ts ADDED
@@ -0,0 +1,11 @@
1
+ // Return compact JSON, 1000 chars max. Never throws.
2
+ export function debugJson(obj: any) {
3
+ try {
4
+ const serialized = JSON.stringify(obj, (_, value) =>
5
+ typeof value === "bigint" ? value.toString() : value,
6
+ );
7
+ return serialized.slice(0, 10000);
8
+ } catch (e: any) {
9
+ return `<JSON error: ${e.message}>`;
10
+ }
11
+ }
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./assert";
2
+ export * from "./chain";
3
+ export * from "./debug";
4
+ export * from "./token";