@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,413 @@
1
+ /* Autogenerated file. Do not edit manually. */
2
+ /* tslint:disable */
3
+ /* eslint-disable */
4
+ import {
5
+ Contract,
6
+ ContractFactory,
7
+ ContractTransactionResponse,
8
+ Interface,
9
+ } from "ethers";
10
+ import type { Signer, ContractDeployTransaction, ContractRunner } from "ethers";
11
+ import type { NonPayableOverrides } from "../common";
12
+ import type { ERC721, ERC721Interface } from "../ERC721";
13
+
14
+ const _abi = [
15
+ {
16
+ inputs: [
17
+ {
18
+ internalType: "string",
19
+ name: "name_",
20
+ type: "string",
21
+ },
22
+ {
23
+ internalType: "string",
24
+ name: "symbol_",
25
+ type: "string",
26
+ },
27
+ ],
28
+ stateMutability: "nonpayable",
29
+ type: "constructor",
30
+ },
31
+ {
32
+ anonymous: false,
33
+ inputs: [
34
+ {
35
+ indexed: true,
36
+ internalType: "address",
37
+ name: "owner",
38
+ type: "address",
39
+ },
40
+ {
41
+ indexed: true,
42
+ internalType: "address",
43
+ name: "approved",
44
+ type: "address",
45
+ },
46
+ {
47
+ indexed: true,
48
+ internalType: "uint256",
49
+ name: "tokenId",
50
+ type: "uint256",
51
+ },
52
+ ],
53
+ name: "Approval",
54
+ type: "event",
55
+ },
56
+ {
57
+ anonymous: false,
58
+ inputs: [
59
+ {
60
+ indexed: true,
61
+ internalType: "address",
62
+ name: "owner",
63
+ type: "address",
64
+ },
65
+ {
66
+ indexed: true,
67
+ internalType: "address",
68
+ name: "operator",
69
+ type: "address",
70
+ },
71
+ {
72
+ indexed: false,
73
+ internalType: "bool",
74
+ name: "approved",
75
+ type: "bool",
76
+ },
77
+ ],
78
+ name: "ApprovalForAll",
79
+ type: "event",
80
+ },
81
+ {
82
+ anonymous: false,
83
+ inputs: [
84
+ {
85
+ indexed: true,
86
+ internalType: "address",
87
+ name: "from",
88
+ type: "address",
89
+ },
90
+ {
91
+ indexed: true,
92
+ internalType: "address",
93
+ name: "to",
94
+ type: "address",
95
+ },
96
+ {
97
+ indexed: true,
98
+ internalType: "uint256",
99
+ name: "tokenId",
100
+ type: "uint256",
101
+ },
102
+ ],
103
+ name: "Transfer",
104
+ type: "event",
105
+ },
106
+ {
107
+ inputs: [
108
+ {
109
+ internalType: "address",
110
+ name: "to",
111
+ type: "address",
112
+ },
113
+ {
114
+ internalType: "uint256",
115
+ name: "tokenId",
116
+ type: "uint256",
117
+ },
118
+ ],
119
+ name: "approve",
120
+ outputs: [],
121
+ stateMutability: "nonpayable",
122
+ type: "function",
123
+ },
124
+ {
125
+ inputs: [
126
+ {
127
+ internalType: "address",
128
+ name: "owner",
129
+ type: "address",
130
+ },
131
+ ],
132
+ name: "balanceOf",
133
+ outputs: [
134
+ {
135
+ internalType: "uint256",
136
+ name: "",
137
+ type: "uint256",
138
+ },
139
+ ],
140
+ stateMutability: "view",
141
+ type: "function",
142
+ },
143
+ {
144
+ inputs: [
145
+ {
146
+ internalType: "uint256",
147
+ name: "tokenId",
148
+ type: "uint256",
149
+ },
150
+ ],
151
+ name: "getApproved",
152
+ outputs: [
153
+ {
154
+ internalType: "address",
155
+ name: "",
156
+ type: "address",
157
+ },
158
+ ],
159
+ stateMutability: "view",
160
+ type: "function",
161
+ },
162
+ {
163
+ inputs: [
164
+ {
165
+ internalType: "address",
166
+ name: "owner",
167
+ type: "address",
168
+ },
169
+ {
170
+ internalType: "address",
171
+ name: "operator",
172
+ type: "address",
173
+ },
174
+ ],
175
+ name: "isApprovedForAll",
176
+ outputs: [
177
+ {
178
+ internalType: "bool",
179
+ name: "",
180
+ type: "bool",
181
+ },
182
+ ],
183
+ stateMutability: "view",
184
+ type: "function",
185
+ },
186
+ {
187
+ inputs: [],
188
+ name: "name",
189
+ outputs: [
190
+ {
191
+ internalType: "string",
192
+ name: "",
193
+ type: "string",
194
+ },
195
+ ],
196
+ stateMutability: "view",
197
+ type: "function",
198
+ },
199
+ {
200
+ inputs: [
201
+ {
202
+ internalType: "uint256",
203
+ name: "tokenId",
204
+ type: "uint256",
205
+ },
206
+ ],
207
+ name: "ownerOf",
208
+ outputs: [
209
+ {
210
+ internalType: "address",
211
+ name: "",
212
+ type: "address",
213
+ },
214
+ ],
215
+ stateMutability: "view",
216
+ type: "function",
217
+ },
218
+ {
219
+ inputs: [
220
+ {
221
+ internalType: "address",
222
+ name: "from",
223
+ type: "address",
224
+ },
225
+ {
226
+ internalType: "address",
227
+ name: "to",
228
+ type: "address",
229
+ },
230
+ {
231
+ internalType: "uint256",
232
+ name: "tokenId",
233
+ type: "uint256",
234
+ },
235
+ ],
236
+ name: "safeTransferFrom",
237
+ outputs: [],
238
+ stateMutability: "nonpayable",
239
+ type: "function",
240
+ },
241
+ {
242
+ inputs: [
243
+ {
244
+ internalType: "address",
245
+ name: "from",
246
+ type: "address",
247
+ },
248
+ {
249
+ internalType: "address",
250
+ name: "to",
251
+ type: "address",
252
+ },
253
+ {
254
+ internalType: "uint256",
255
+ name: "tokenId",
256
+ type: "uint256",
257
+ },
258
+ {
259
+ internalType: "bytes",
260
+ name: "data",
261
+ type: "bytes",
262
+ },
263
+ ],
264
+ name: "safeTransferFrom",
265
+ outputs: [],
266
+ stateMutability: "nonpayable",
267
+ type: "function",
268
+ },
269
+ {
270
+ inputs: [
271
+ {
272
+ internalType: "address",
273
+ name: "operator",
274
+ type: "address",
275
+ },
276
+ {
277
+ internalType: "bool",
278
+ name: "approved",
279
+ type: "bool",
280
+ },
281
+ ],
282
+ name: "setApprovalForAll",
283
+ outputs: [],
284
+ stateMutability: "nonpayable",
285
+ type: "function",
286
+ },
287
+ {
288
+ inputs: [
289
+ {
290
+ internalType: "bytes4",
291
+ name: "interfaceId",
292
+ type: "bytes4",
293
+ },
294
+ ],
295
+ name: "supportsInterface",
296
+ outputs: [
297
+ {
298
+ internalType: "bool",
299
+ name: "",
300
+ type: "bool",
301
+ },
302
+ ],
303
+ stateMutability: "view",
304
+ type: "function",
305
+ },
306
+ {
307
+ inputs: [],
308
+ name: "symbol",
309
+ outputs: [
310
+ {
311
+ internalType: "string",
312
+ name: "",
313
+ type: "string",
314
+ },
315
+ ],
316
+ stateMutability: "view",
317
+ type: "function",
318
+ },
319
+ {
320
+ inputs: [
321
+ {
322
+ internalType: "uint256",
323
+ name: "tokenId",
324
+ type: "uint256",
325
+ },
326
+ ],
327
+ name: "tokenURI",
328
+ outputs: [
329
+ {
330
+ internalType: "string",
331
+ name: "",
332
+ type: "string",
333
+ },
334
+ ],
335
+ stateMutability: "view",
336
+ type: "function",
337
+ },
338
+ {
339
+ inputs: [
340
+ {
341
+ internalType: "address",
342
+ name: "from",
343
+ type: "address",
344
+ },
345
+ {
346
+ internalType: "address",
347
+ name: "to",
348
+ type: "address",
349
+ },
350
+ {
351
+ internalType: "uint256",
352
+ name: "tokenId",
353
+ type: "uint256",
354
+ },
355
+ ],
356
+ name: "transferFrom",
357
+ outputs: [],
358
+ stateMutability: "nonpayable",
359
+ type: "function",
360
+ },
361
+ ] as const;
362
+
363
+ const _bytecode =
364
+ "0x60806040523480156200001157600080fd5b506040516200138c3803806200138c8339810160408190526200003491620001db565b81516200004990600090602085019062000068565b5080516200005f90600190602084019062000068565b50505062000281565b828054620000769062000245565b90600052602060002090601f0160209004810192826200009a5760008555620000e5565b82601f10620000b557805160ff1916838001178555620000e5565b82800160010185558215620000e5579182015b82811115620000e5578251825591602001919060010190620000c8565b50620000f3929150620000f7565b5090565b5b80821115620000f35760008155600101620000f8565b634e487b7160e01b600052604160045260246000fd5b600082601f8301126200013657600080fd5b81516001600160401b03808211156200015357620001536200010e565b604051601f8301601f19908116603f011681019082821181831017156200017e576200017e6200010e565b816040528381526020925086838588010111156200019b57600080fd5b600091505b83821015620001bf5785820183015181830184015290820190620001a0565b83821115620001d15760008385830101525b9695505050505050565b60008060408385031215620001ef57600080fd5b82516001600160401b03808211156200020757600080fd5b620002158683870162000124565b935060208501519150808211156200022c57600080fd5b506200023b8582860162000124565b9150509250929050565b600181811c908216806200025a57607f821691505b6020821081036200027b57634e487b7160e01b600052602260045260246000fd5b50919050565b6110fb80620002916000396000f3fe608060405234801561001057600080fd5b50600436106100cf5760003560e01c80636352211e1161008c578063a22cb46511610066578063a22cb465146101b3578063b88d4fde146101c6578063c87b56dd146101d9578063e985e9c5146101ec57600080fd5b80636352211e1461017757806370a082311461018a57806395d89b41146101ab57600080fd5b806301ffc9a7146100d457806306fdde03146100fc578063081812fc14610111578063095ea7b31461013c57806323b872dd1461015157806342842e0e14610164575b600080fd5b6100e76100e2366004610c7f565b610228565b60405190151581526020015b60405180910390f35b61010461027a565b6040516100f39190610cf4565b61012461011f366004610d07565b61030c565b6040516001600160a01b0390911681526020016100f3565b61014f61014a366004610d3c565b610333565b005b61014f61015f366004610d66565b61044d565b61014f610172366004610d66565b61047e565b610124610185366004610d07565b610499565b61019d610198366004610da2565b6104f9565b6040519081526020016100f3565b61010461057f565b61014f6101c1366004610dbd565b61058e565b61014f6101d4366004610e0f565b61059d565b6101046101e7366004610d07565b6105d5565b6100e76101fa366004610eeb565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b60006001600160e01b031982166380ac58cd60e01b148061025957506001600160e01b03198216635b5e139f60e01b145b8061027457506301ffc9a760e01b6001600160e01b03198316145b92915050565b60606000805461028990610f1e565b80601f01602080910402602001604051908101604052809291908181526020018280546102b590610f1e565b80156103025780601f106102d757610100808354040283529160200191610302565b820191906000526020600020905b8154815290600101906020018083116102e557829003601f168201915b5050505050905090565b600061031782610649565b506000908152600460205260409020546001600160a01b031690565b600061033e82610499565b9050806001600160a01b0316836001600160a01b0316036103b05760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b60648201526084015b60405180910390fd5b336001600160a01b03821614806103cc57506103cc81336101fa565b61043e5760405162461bcd60e51b815260206004820152603d60248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f7420746f60448201527f6b656e206f776e6572206f7220617070726f76656420666f7220616c6c00000060648201526084016103a7565b61044883836106ab565b505050565b6104573382610719565b6104735760405162461bcd60e51b81526004016103a790610f58565b610448838383610798565b6104488383836040518060200160405280600081525061059d565b6000818152600260205260408120546001600160a01b0316806102745760405162461bcd60e51b8152602060048201526018602482015277115490cdcc8c4e881a5b9d985b1a59081d1bdad95b88125160421b60448201526064016103a7565b60006001600160a01b0382166105635760405162461bcd60e51b815260206004820152602960248201527f4552433732313a2061646472657373207a65726f206973206e6f7420612076616044820152683634b21037bbb732b960b91b60648201526084016103a7565b506001600160a01b031660009081526003602052604090205490565b60606001805461028990610f1e565b6105993383836108fc565b5050565b6105a73383610719565b6105c35760405162461bcd60e51b81526004016103a790610f58565b6105cf848484846109ca565b50505050565b60606105e082610649565b60006105f760408051602081019091526000815290565b905060008151116106175760405180602001604052806000815250610642565b80610621846109fd565b604051602001610632929190610fa5565b6040516020818303038152906040525b9392505050565b6000818152600260205260409020546001600160a01b03166106a85760405162461bcd60e51b8152602060048201526018602482015277115490cdcc8c4e881a5b9d985b1a59081d1bdad95b88125160421b60448201526064016103a7565b50565b600081815260046020526040902080546001600160a01b0319166001600160a01b03841690811790915581906106e082610499565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b60008061072583610499565b9050806001600160a01b0316846001600160a01b0316148061076c57506001600160a01b0380821660009081526005602090815260408083209388168352929052205460ff165b806107905750836001600160a01b03166107858461030c565b6001600160a01b0316145b949350505050565b826001600160a01b03166107ab82610499565b6001600160a01b0316146107d15760405162461bcd60e51b81526004016103a790610fd4565b6001600160a01b0382166108335760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b60648201526084016103a7565b826001600160a01b031661084682610499565b6001600160a01b03161461086c5760405162461bcd60e51b81526004016103a790610fd4565b600081815260046020908152604080832080546001600160a01b03199081169091556001600160a01b0387811680865260038552838620805460001901905590871680865283862080546001019055868652600290945282852080549092168417909155905184937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b816001600160a01b0316836001600160a01b03160361095d5760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c65720000000000000060448201526064016103a7565b6001600160a01b03838116600081815260056020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b6109d5848484610798565b6109e184848484610a90565b6105cf5760405162461bcd60e51b81526004016103a790611019565b60606000610a0a83610b91565b600101905060008167ffffffffffffffff811115610a2a57610a2a610df9565b6040519080825280601f01601f191660200182016040528015610a54576020820181803683370190505b5090508181016020015b600019016f181899199a1a9b1b9c1cb0b131b232b360811b600a86061a8153600a8504945084610a5e57509392505050565b60006001600160a01b0384163b15610b8657604051630a85bd0160e11b81526001600160a01b0385169063150b7a0290610ad490339089908890889060040161106b565b6020604051808303816000875af1925050508015610b0f575060408051601f3d908101601f19168201909252610b0c918101906110a8565b60015b610b6c573d808015610b3d576040519150601f19603f3d011682016040523d82523d6000602084013e610b42565b606091505b508051600003610b645760405162461bcd60e51b81526004016103a790611019565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050610790565b506001949350505050565b60008072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b8310610bd05772184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b830492506040015b6d04ee2d6d415b85acef81000000008310610bfc576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc100008310610c1a57662386f26fc10000830492506010015b6305f5e1008310610c32576305f5e100830492506008015b6127108310610c4657612710830492506004015b60648310610c58576064830492506002015b600a83106102745760010192915050565b6001600160e01b0319811681146106a857600080fd5b600060208284031215610c9157600080fd5b813561064281610c69565b60005b83811015610cb7578181015183820152602001610c9f565b838111156105cf5750506000910152565b60008151808452610ce0816020860160208601610c9c565b601f01601f19169290920160200192915050565b6020815260006106426020830184610cc8565b600060208284031215610d1957600080fd5b5035919050565b80356001600160a01b0381168114610d3757600080fd5b919050565b60008060408385031215610d4f57600080fd5b610d5883610d20565b946020939093013593505050565b600080600060608486031215610d7b57600080fd5b610d8484610d20565b9250610d9260208501610d20565b9150604084013590509250925092565b600060208284031215610db457600080fd5b61064282610d20565b60008060408385031215610dd057600080fd5b610dd983610d20565b915060208301358015158114610dee57600080fd5b809150509250929050565b634e487b7160e01b600052604160045260246000fd5b60008060008060808587031215610e2557600080fd5b610e2e85610d20565b9350610e3c60208601610d20565b925060408501359150606085013567ffffffffffffffff80821115610e6057600080fd5b818701915087601f830112610e7457600080fd5b813581811115610e8657610e86610df9565b604051601f8201601f19908116603f01168101908382118183101715610eae57610eae610df9565b816040528281528a6020848701011115610ec757600080fd5b82602086016020830137600060208483010152809550505050505092959194509250565b60008060408385031215610efe57600080fd5b610f0783610d20565b9150610f1560208401610d20565b90509250929050565b600181811c90821680610f3257607f821691505b602082108103610f5257634e487b7160e01b600052602260045260246000fd5b50919050565b6020808252602d908201527f4552433732313a2063616c6c6572206973206e6f7420746f6b656e206f776e6560408201526c1c881bdc88185c1c1c9bdd9959609a1b606082015260800190565b60008351610fb7818460208801610c9c565b835190830190610fcb818360208801610c9c565b01949350505050565b60208082526025908201527f4552433732313a207472616e736665722066726f6d20696e636f72726563742060408201526437bbb732b960d91b606082015260800190565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b6001600160a01b038581168252841660208201526040810183905260806060820181905260009061109e90830184610cc8565b9695505050505050565b6000602082840312156110ba57600080fd5b815161064281610c6956fea2646970667358221220656215cd1c770b1c0ef26b32de6dec1d6fd90e95d8c1190aff80f7b572dca52664736f6c634300080d0033";
365
+
366
+ type ERC721ConstructorParams =
367
+ | [signer?: Signer]
368
+ | ConstructorParameters<typeof ContractFactory>;
369
+
370
+ const isSuperArgs = (
371
+ xs: ERC721ConstructorParams
372
+ ): xs is ConstructorParameters<typeof ContractFactory> => xs.length > 1;
373
+
374
+ export class ERC721__factory extends ContractFactory {
375
+ constructor(...args: ERC721ConstructorParams) {
376
+ if (isSuperArgs(args)) {
377
+ super(...args);
378
+ } else {
379
+ super(_abi, _bytecode, args[0]);
380
+ }
381
+ }
382
+
383
+ override getDeployTransaction(
384
+ name_: string,
385
+ symbol_: string,
386
+ overrides?: NonPayableOverrides & { from?: string }
387
+ ): Promise<ContractDeployTransaction> {
388
+ return super.getDeployTransaction(name_, symbol_, overrides || {});
389
+ }
390
+ override deploy(
391
+ name_: string,
392
+ symbol_: string,
393
+ overrides?: NonPayableOverrides & { from?: string }
394
+ ) {
395
+ return super.deploy(name_, symbol_, overrides || {}) as Promise<
396
+ ERC721 & {
397
+ deploymentTransaction(): ContractTransactionResponse;
398
+ }
399
+ >;
400
+ }
401
+ override connect(runner: ContractRunner | null): ERC721__factory {
402
+ return super.connect(runner) as ERC721__factory;
403
+ }
404
+
405
+ static readonly bytecode = _bytecode;
406
+ static readonly abi = _abi;
407
+ static createInterface(): ERC721Interface {
408
+ return new Interface(_abi) as ERC721Interface;
409
+ }
410
+ static connect(address: string, runner?: ContractRunner | null): ERC721 {
411
+ return new Contract(address, _abi, runner) as unknown as ERC721;
412
+ }
413
+ }
@@ -0,0 +1,6 @@
1
+ /* Autogenerated file. Do not edit manually. */
2
+ /* tslint:disable */
3
+ /* eslint-disable */
4
+ export { ERC1155__factory } from "./ERC1155__factory";
5
+ export { ERC20__factory } from "./ERC20__factory";
6
+ export { ERC721__factory } from "./ERC721__factory";
@@ -0,0 +1,10 @@
1
+ /* Autogenerated file. Do not edit manually. */
2
+ /* tslint:disable */
3
+ /* eslint-disable */
4
+ export type { ERC1155 } from "./ERC1155";
5
+ export type { ERC20 } from "./ERC20";
6
+ export type { ERC721 } from "./ERC721";
7
+ export * as factories from "./factories";
8
+ export { ERC20__factory } from "./factories/ERC20__factory";
9
+ export { ERC721__factory } from "./factories/ERC721__factory";
10
+ export { ERC1155__factory } from "./factories/ERC1155__factory";
@@ -40,7 +40,7 @@ const testNetwork: Network = {
40
40
  chainId: 1,
41
41
  chainName: 'chainName',
42
42
  rpcUrl: 'rpcUrl',
43
- logoUrl: 'logoUrl',
43
+ logoUri: 'logoUri',
44
44
  utilityAddresses: { multicall: 'multiContractAddress' },
45
45
  networkToken: {
46
46
  name: 'Ethereum',
@@ -71,7 +71,7 @@ const displayData = {
71
71
  network: {
72
72
  chainId: testNetwork.chainId,
73
73
  name: testNetwork.chainName,
74
- logoUrl: testNetwork.logoUrl,
74
+ logoUri: testNetwork.logoUri,
75
75
  },
76
76
  transactionDetails: {
77
77
  website: 'example.com',
@@ -98,7 +98,7 @@ export const ethSendTransaction = async ({
98
98
  network: {
99
99
  chainId: network.chainId,
100
100
  name: network.chainName,
101
- logoUrl: network.logoUrl,
101
+ logoUri: network.logoUri,
102
102
  },
103
103
  transactionDetails: {
104
104
  website: new URL(dappInfo.url).hostname,
@@ -0,0 +1,78 @@
1
+ import { BN } from 'bn.js';
2
+ import { getErc20Balances } from './get-erc20-balances';
3
+ import { ethers } from 'ethers';
4
+
5
+ describe('get-erc20-balances', () => {
6
+ it('should return erc20 token balances', async () => {
7
+ jest.spyOn(ethers, 'Contract').mockImplementation(() => {
8
+ return {
9
+ balanceOf: jest.fn().mockResolvedValue(new BN('1000000000000000000')),
10
+ } as never;
11
+ });
12
+
13
+ const balance = getErc20Balances({
14
+ tokens: [
15
+ {
16
+ address: '0x123',
17
+ name: 'Ethereum',
18
+ symbol: 'ETH',
19
+ decimals: 18,
20
+ logoUri: 'https://example.com/logo.png',
21
+ contractType: 'ERC-20',
22
+ },
23
+ ],
24
+ provider: {
25
+ getBalance: jest.fn().mockResolvedValue(new BN('1000000000000000000')),
26
+ } as never,
27
+ tokenService: {
28
+ getPricesByAddresses: jest.fn().mockResolvedValue({
29
+ '123': {
30
+ USD: {
31
+ price: 1000,
32
+ marketCap: 0,
33
+ vol24: 0,
34
+ change24: 0,
35
+ },
36
+ },
37
+ }),
38
+ } as never,
39
+ address: '0x123',
40
+ currency: 'USD',
41
+ network: {
42
+ pricingProviders: {
43
+ coingecko: {
44
+ nativeTokenId: '123',
45
+ assetPlatformId: '123',
46
+ },
47
+ },
48
+ networkToken: {
49
+ address: '0x123',
50
+ name: 'Ethereum',
51
+ symbol: 'ETH',
52
+ decimals: 18,
53
+ logoUri: 'https://example.com/logo.png',
54
+ },
55
+ } as never,
56
+ });
57
+
58
+ expect(balance).resolves.toEqual({
59
+ '0x123': {
60
+ address: '0x123',
61
+ name: 'Ethereum',
62
+ symbol: 'ETH',
63
+ decimals: 18,
64
+ logoUri: 'https://example.com/logo.png',
65
+ balance: new BN('1000000000000000000'),
66
+ balanceCurrencyDisplayValue: '1000.00',
67
+ balanceDisplayValue: '1',
68
+ balanceInCurrency: 1000,
69
+ priceInCurrency: 1000,
70
+ contractType: 'ERC-20',
71
+ type: 'ERC20',
72
+ change24: 0,
73
+ marketCap: 0,
74
+ vol24: 0,
75
+ },
76
+ });
77
+ });
78
+ });
@@ -0,0 +1,85 @@
1
+ import { numberToBN, bnToBig, balanceToDisplayValue } from '@avalabs/utils-sdk';
2
+ import { TokenType, type Network, type NetworkContractToken, type TokenWithBalance } from '@avalabs/vm-module-types';
3
+ import { ethers, type Provider } from 'ethers';
4
+ import ERC20 from '@openzeppelin/contracts/build/contracts/ERC20.json';
5
+ import type { TokenService } from '@internal/utils';
6
+ import { VsCurrencyType } from '@avalabs/coingecko-sdk';
7
+ import BN from 'bn.js';
8
+
9
+ const DEFAULT_DECIMALS = 18;
10
+
11
+ export const getErc20Balances = async ({
12
+ provider,
13
+ tokenService,
14
+ address: userAddress,
15
+ currency,
16
+ tokens,
17
+ network,
18
+ }: {
19
+ provider: Provider;
20
+ tokenService: TokenService;
21
+ address: string;
22
+ currency: string;
23
+ tokens: NetworkContractToken[];
24
+ network: Network;
25
+ }): Promise<Record<string, TokenWithBalance>> => {
26
+ const coingeckoPlatformId = network.pricingProviders?.coingecko.assetPlatformId;
27
+ const coingeckoTokenId = network.pricingProviders?.coingecko.nativeTokenId;
28
+ const tokenAddresses = tokens.map((token) => token.address);
29
+
30
+ const tokensBalances = await Promise.allSettled(
31
+ tokens.map(async (token) => {
32
+ const contract = new ethers.Contract(token.address, ERC20.abi, provider);
33
+ const balanceBig = await contract.balanceOf?.(userAddress);
34
+ const balance = new BN(balanceBig) || numberToBN(0, token.decimals || DEFAULT_DECIMALS);
35
+
36
+ const tokenWithBalance = {
37
+ ...token,
38
+ balance,
39
+ };
40
+
41
+ return tokenWithBalance;
42
+ }),
43
+ ).then((res) => {
44
+ return res.reduce<(NetworkContractToken & { balance: BN })[]>((acc, result) => {
45
+ return result.status === 'fulfilled' && !result.value.balance.isZero() ? [...acc, result.value] : acc;
46
+ }, []);
47
+ });
48
+
49
+ if (!tokensBalances.length) return {};
50
+
51
+ const simplePriceResponse =
52
+ (coingeckoPlatformId &&
53
+ (await tokenService.getPricesByAddresses(tokenAddresses, coingeckoPlatformId, currency as VsCurrencyType))) ||
54
+ {};
55
+
56
+ return tokensBalances.reduce(
57
+ (acc, token) => {
58
+ const priceInCurrency = simplePriceResponse?.[coingeckoTokenId ?? '']?.[currency]?.price ?? 0;
59
+ const marketCap = simplePriceResponse?.[coingeckoTokenId ?? '']?.[currency]?.marketCap ?? 0;
60
+ const vol24 = simplePriceResponse?.[coingeckoTokenId ?? '']?.[currency]?.vol24 ?? 0;
61
+ const change24 = simplePriceResponse?.[coingeckoTokenId ?? '']?.[currency]?.change24 ?? 0;
62
+
63
+ const balanceInCurrency = bnToBig(token.balance, token.decimals).mul(priceInCurrency).toNumber();
64
+ const balanceDisplayValue = balanceToDisplayValue(token.balance, token.decimals);
65
+ const balanceCurrencyDisplayValue = balanceInCurrency.toFixed(2);
66
+
67
+ return {
68
+ ...acc,
69
+ [token.address.toLowerCase()]: {
70
+ ...token,
71
+ type: TokenType.ERC20,
72
+ balance: token.balance,
73
+ balanceDisplayValue,
74
+ balanceInCurrency,
75
+ balanceCurrencyDisplayValue,
76
+ priceInCurrency,
77
+ marketCap,
78
+ change24,
79
+ vol24,
80
+ },
81
+ };
82
+ },
83
+ {} as Record<string, TokenWithBalance>,
84
+ );
85
+ };