@avalabs/evm-module 0.0.12 → 0.0.15

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 (42) hide show
  1. package/.turbo/turbo-build.log +10 -10
  2. package/.turbo/turbo-lint.log +1 -1
  3. package/.turbo/turbo-test.log +11 -6
  4. package/CHANGELOG.md +27 -0
  5. package/dist/index.cjs +10 -7
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.cts +6 -5
  8. package/dist/index.d.ts +6 -5
  9. package/dist/index.js +10 -8
  10. package/dist/index.js.map +1 -1
  11. package/package.json +17 -10
  12. package/src/contracts/openzeppelin/ERC1155.ts +440 -0
  13. package/src/contracts/openzeppelin/ERC20.ts +330 -0
  14. package/src/contracts/openzeppelin/ERC721.ts +420 -0
  15. package/src/contracts/openzeppelin/common.ts +131 -0
  16. package/src/contracts/openzeppelin/factories/ERC1155__factory.ts +388 -0
  17. package/src/contracts/openzeppelin/factories/ERC20__factory.ts +353 -0
  18. package/src/contracts/openzeppelin/factories/ERC721__factory.ts +413 -0
  19. package/src/contracts/openzeppelin/factories/index.ts +6 -0
  20. package/src/contracts/openzeppelin/index.ts +10 -0
  21. package/src/handlers/eth-send-transaction/eth-send-transaction.test.ts +2 -2
  22. package/src/handlers/eth-send-transaction/eth-send-transaction.ts +1 -1
  23. package/src/handlers/get-balances/evm-balance-service/get-erc20-balances.test.ts +78 -0
  24. package/src/handlers/get-balances/evm-balance-service/get-erc20-balances.ts +85 -0
  25. package/src/handlers/get-balances/evm-balance-service/get-native-token-balances.test.ts +102 -0
  26. package/src/handlers/get-balances/evm-balance-service/get-native-token-balances.ts +54 -0
  27. package/src/handlers/get-balances/get-balances.test.ts +252 -0
  28. package/src/handlers/get-balances/get-balances.ts +109 -0
  29. package/src/handlers/get-balances/glacier-balance-service/get-erc20-balances.test.ts +76 -0
  30. package/src/handlers/get-balances/glacier-balance-service/get-erc20-balances.ts +107 -0
  31. package/src/handlers/get-balances/glacier-balance-service/get-native-token-balances.test.ts +61 -0
  32. package/src/handlers/get-balances/glacier-balance-service/get-native-token-balances.ts +46 -0
  33. package/src/handlers/get-network-fee/get-network-fee.test.ts +1 -1
  34. package/src/handlers/get-network-fee/get-network-fee.ts +1 -1
  35. package/src/handlers/get-transaction-history/converters/evm-transaction-converter/get-transaction-from-glacier.test.ts +72 -59
  36. package/src/handlers/get-transaction-history/converters/evm-transaction-converter/get-transactions-from-glacier.ts +4 -11
  37. package/src/handlers/get-transaction-history/get-transaction-history.test.ts +7 -2
  38. package/src/handlers/get-transaction-history/get-transaction-history.ts +13 -3
  39. package/src/module.ts +18 -8
  40. package/src/services/glacier-service/glacier-service.ts +259 -0
  41. package/tsconfig.json +1 -0
  42. /package/{src/manifest.json → manifest.json} +0 -0
@@ -0,0 +1,259 @@
1
+ import {
2
+ BlockchainId,
3
+ CurrencyCode,
4
+ Erc1155Token,
5
+ Erc721Token,
6
+ type GetNativeBalanceResponse,
7
+ Glacier,
8
+ type ListCChainAtomicBalancesResponse,
9
+ type ListErc1155BalancesResponse,
10
+ type ListErc20BalancesResponse,
11
+ type ListErc721BalancesResponse,
12
+ type ListPChainBalancesResponse,
13
+ type ListXChainBalancesResponse,
14
+ Network,
15
+ } from '@avalabs/glacier-sdk';
16
+
17
+ class GlacierUnhealthyError extends Error {
18
+ override message = 'Glacier is unhealthy. Try again later.';
19
+ }
20
+
21
+ export class EvmGlacierService {
22
+ glacierSdk: Glacier;
23
+ isGlacierHealthy = true;
24
+ supportedChainIds: string[] = [];
25
+
26
+ constructor({ glacierApiUrl }: { glacierApiUrl: string }) {
27
+ this.glacierSdk = new Glacier({ BASE: glacierApiUrl });
28
+ /**
29
+ * This is for performance, basically we just cache the health of glacier every 5 seconds and
30
+ * go off of that instead of every request
31
+ */
32
+ this.getSupportedChainIds().catch(() => {
33
+ // Noop. It will be retried by .isSupportedNetwork calls upon unlocking if necessary.
34
+ });
35
+ }
36
+
37
+ isHealthy = (): boolean => this.isGlacierHealthy;
38
+
39
+ setGlacierToUnhealthy(): void {
40
+ this.isGlacierHealthy = false;
41
+ setTimeout(
42
+ () => {
43
+ this.isGlacierHealthy = true;
44
+ },
45
+ 5 * 60 * 1000,
46
+ ); // 5 minutes
47
+ }
48
+
49
+ async isNetworkSupported(chainId: number): Promise<boolean> {
50
+ const chainIds = await this.getSupportedChainIds();
51
+ return chainIds.some((id) => id === chainId.toString());
52
+ }
53
+
54
+ async getSupportedChainIds(): Promise<string[]> {
55
+ if (this.supportedChainIds.length) {
56
+ return this.supportedChainIds;
57
+ }
58
+
59
+ try {
60
+ const supportedChains = await this.glacierSdk.evmChains.supportedChains({});
61
+ this.supportedChainIds = supportedChains.chains.map((chain) => chain.chainId);
62
+ return this.supportedChainIds;
63
+ } catch {
64
+ return [];
65
+ }
66
+ }
67
+
68
+ async reindexNft({
69
+ address,
70
+ chainId,
71
+ tokenId,
72
+ }: {
73
+ address: string;
74
+ chainId: string;
75
+ tokenId: string;
76
+ }): Promise<void> {
77
+ try {
78
+ await this.glacierSdk.nfTs.reindexNft({
79
+ address,
80
+ chainId,
81
+ tokenId,
82
+ });
83
+ } catch (error) {
84
+ if (error instanceof GlacierUnhealthyError) {
85
+ this.setGlacierToUnhealthy();
86
+ }
87
+ throw error;
88
+ }
89
+ }
90
+
91
+ async getTokenDetails({
92
+ address,
93
+ chainId,
94
+ tokenId,
95
+ }: {
96
+ address: string;
97
+ chainId: string;
98
+ tokenId: string;
99
+ }): Promise<Erc721Token | Erc1155Token> {
100
+ try {
101
+ return this.glacierSdk.nfTs.getTokenDetails({
102
+ address,
103
+ chainId,
104
+ tokenId,
105
+ });
106
+ } catch (error) {
107
+ if (error instanceof GlacierUnhealthyError) {
108
+ this.setGlacierToUnhealthy();
109
+ }
110
+ throw error;
111
+ }
112
+ }
113
+
114
+ async getChainBalance(params: {
115
+ blockchainId: BlockchainId;
116
+ network: Network;
117
+ blockTimestamp?: number;
118
+ addresses?: string;
119
+ }): Promise<ListPChainBalancesResponse | ListXChainBalancesResponse | ListCChainAtomicBalancesResponse> {
120
+ try {
121
+ return this.glacierSdk.primaryNetworkBalances.getBalancesByAddresses(params);
122
+ } catch (error) {
123
+ if (error instanceof GlacierUnhealthyError) {
124
+ this.setGlacierToUnhealthy();
125
+ }
126
+ throw error;
127
+ }
128
+ }
129
+
130
+ async getNativeBalance({
131
+ chainId,
132
+ address,
133
+ currency,
134
+ }: {
135
+ chainId: string;
136
+ address: string;
137
+ currency: CurrencyCode;
138
+ }): Promise<GetNativeBalanceResponse> {
139
+ try {
140
+ return this.glacierSdk.evmBalances.getNativeBalance({
141
+ chainId,
142
+ address,
143
+ currency: currency.toLocaleLowerCase() as CurrencyCode,
144
+ });
145
+ } catch (error) {
146
+ if (error instanceof GlacierUnhealthyError) {
147
+ this.setGlacierToUnhealthy();
148
+ }
149
+ throw error;
150
+ }
151
+ }
152
+
153
+ async listErc721Balances({
154
+ chainId,
155
+ address,
156
+ pageSize,
157
+ pageToken,
158
+ }: {
159
+ chainId: string;
160
+ address: string;
161
+ pageSize: number;
162
+ pageToken?: string;
163
+ }): Promise<ListErc721BalancesResponse> {
164
+ try {
165
+ return this.glacierSdk.evmBalances.listErc721Balances({
166
+ chainId,
167
+ address,
168
+ pageSize,
169
+ pageToken,
170
+ });
171
+ } catch (error) {
172
+ if (error instanceof GlacierUnhealthyError) {
173
+ this.setGlacierToUnhealthy();
174
+ }
175
+ throw error;
176
+ }
177
+ }
178
+
179
+ async listErc1155Balances({
180
+ chainId,
181
+ address,
182
+ pageSize,
183
+ pageToken,
184
+ }: {
185
+ chainId: string;
186
+ address: string;
187
+ pageSize: number;
188
+ pageToken?: string;
189
+ }): Promise<ListErc1155BalancesResponse> {
190
+ try {
191
+ return this.glacierSdk.evmBalances.listErc1155Balances({
192
+ chainId,
193
+ address,
194
+ pageSize,
195
+ pageToken,
196
+ });
197
+ } catch (error) {
198
+ if (error instanceof GlacierUnhealthyError) {
199
+ this.setGlacierToUnhealthy();
200
+ }
201
+ throw error;
202
+ }
203
+ }
204
+
205
+ async listErc20Balances({
206
+ chainId,
207
+ address,
208
+ currency,
209
+ pageSize,
210
+ pageToken,
211
+ }: {
212
+ chainId: string;
213
+ address: string;
214
+ currency: CurrencyCode;
215
+ pageSize: number;
216
+ pageToken?: string;
217
+ }): Promise<ListErc20BalancesResponse> {
218
+ try {
219
+ return this.glacierSdk.evmBalances.listErc20Balances({
220
+ chainId,
221
+ address,
222
+ currency: currency.toLocaleLowerCase() as CurrencyCode,
223
+ pageSize,
224
+ pageToken,
225
+ });
226
+ } catch (error) {
227
+ if (error instanceof GlacierUnhealthyError) {
228
+ this.setGlacierToUnhealthy();
229
+ }
230
+ throw error;
231
+ }
232
+ }
233
+
234
+ async listTransactions({
235
+ chainId,
236
+ address,
237
+ pageToken,
238
+ pageSize,
239
+ }: {
240
+ chainId: string;
241
+ address: string;
242
+ pageToken?: string;
243
+ pageSize?: number;
244
+ }) {
245
+ try {
246
+ return this.glacierSdk.evmTransactions.listTransactions({
247
+ chainId,
248
+ address,
249
+ pageToken,
250
+ pageSize,
251
+ });
252
+ } catch (error) {
253
+ if (error instanceof GlacierUnhealthyError) {
254
+ this.setGlacierToUnhealthy();
255
+ }
256
+ throw error;
257
+ }
258
+ }
259
+ }
package/tsconfig.json CHANGED
@@ -2,6 +2,7 @@
2
2
  "extends": "@internal/tsconfig/tsconfig.base.json",
3
3
  "compilerOptions": {
4
4
  "outDir": "./dist",
5
+ "declaration": false,
5
6
  "incremental": false // Need to turn off because of tsup dts
6
7
  },
7
8
  "include": ["src"]
File without changes