@avalabs/evm-module 0.0.23 → 0.1.0

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 (87) hide show
  1. package/LICENSE +9 -0
  2. package/package.json +7 -2
  3. package/.turbo/turbo-build.log +0 -22
  4. package/.turbo/turbo-lint.log +0 -4
  5. package/.turbo/turbo-test.log +0 -119
  6. package/CHANGELOG.md +0 -174
  7. package/jest.config.js +0 -9
  8. package/src/constants.ts +0 -1
  9. package/src/contracts/openzeppelin/ERC1155.ts +0 -440
  10. package/src/contracts/openzeppelin/ERC20.ts +0 -330
  11. package/src/contracts/openzeppelin/ERC721.ts +0 -420
  12. package/src/contracts/openzeppelin/common.ts +0 -131
  13. package/src/contracts/openzeppelin/factories/ERC1155__factory.ts +0 -388
  14. package/src/contracts/openzeppelin/factories/ERC20__factory.ts +0 -353
  15. package/src/contracts/openzeppelin/factories/ERC721__factory.ts +0 -413
  16. package/src/contracts/openzeppelin/factories/index.ts +0 -6
  17. package/src/contracts/openzeppelin/index.ts +0 -10
  18. package/src/env.ts +0 -25
  19. package/src/handlers/eth-send-transaction/eth-send-transaction.test.ts +0 -572
  20. package/src/handlers/eth-send-transaction/eth-send-transaction.ts +0 -189
  21. package/src/handlers/eth-send-transaction/schema.test.ts +0 -240
  22. package/src/handlers/eth-send-transaction/schema.ts +0 -20
  23. package/src/handlers/eth-sign/eth-sign.test.ts +0 -359
  24. package/src/handlers/eth-sign/eth-sign.ts +0 -158
  25. package/src/handlers/eth-sign/schemas/eth-sign-typed-data.ts +0 -65
  26. package/src/handlers/eth-sign/schemas/eth-sign.ts +0 -9
  27. package/src/handlers/eth-sign/schemas/parse-request-params/fixture.ts +0 -47
  28. package/src/handlers/eth-sign/schemas/parse-request-params/parse-request-params.test.ts +0 -284
  29. package/src/handlers/eth-sign/schemas/parse-request-params/parse-request-params.ts +0 -94
  30. package/src/handlers/eth-sign/schemas/personal-sign.ts +0 -12
  31. package/src/handlers/eth-sign/schemas/shared.ts +0 -5
  32. package/src/handlers/eth-sign/utils/beautify-message/beautify-message.test.ts +0 -29
  33. package/src/handlers/eth-sign/utils/beautify-message/beautify-message.ts +0 -134
  34. package/src/handlers/eth-sign/utils/is-typed-data-valid.ts +0 -26
  35. package/src/handlers/eth-sign/utils/typeguards.ts +0 -10
  36. package/src/handlers/forward-to-rpc-node/forward-to-rpc-node.test.ts +0 -90
  37. package/src/handlers/forward-to-rpc-node/forward-to-rpc-node.ts +0 -23
  38. package/src/handlers/get-address/get-address.ts +0 -26
  39. package/src/handlers/get-balances/evm-balance-service/get-erc20-balances.test.ts +0 -77
  40. package/src/handlers/get-balances/evm-balance-service/get-erc20-balances.ts +0 -81
  41. package/src/handlers/get-balances/evm-balance-service/get-native-token-balances.test.ts +0 -96
  42. package/src/handlers/get-balances/evm-balance-service/get-native-token-balances.ts +0 -53
  43. package/src/handlers/get-balances/get-balances.test.ts +0 -248
  44. package/src/handlers/get-balances/get-balances.ts +0 -123
  45. package/src/handlers/get-balances/glacier-balance-service/get-erc20-balances.test.ts +0 -71
  46. package/src/handlers/get-balances/glacier-balance-service/get-erc20-balances.ts +0 -106
  47. package/src/handlers/get-balances/glacier-balance-service/get-native-token-balances.test.ts +0 -59
  48. package/src/handlers/get-balances/glacier-balance-service/get-native-token-balances.ts +0 -48
  49. package/src/handlers/get-network-fee/get-network-fee.test.ts +0 -43
  50. package/src/handlers/get-network-fee/get-network-fee.ts +0 -59
  51. package/src/handlers/get-tokens/get-tokens.test.ts +0 -100
  52. package/src/handlers/get-tokens/get-tokens.ts +0 -18
  53. package/src/handlers/get-transaction-history/converters/etherscan-transaction-converter/convert-transaction-erc20.test.ts +0 -53
  54. package/src/handlers/get-transaction-history/converters/etherscan-transaction-converter/convert-transaction-erc20.ts +0 -49
  55. package/src/handlers/get-transaction-history/converters/etherscan-transaction-converter/convert-transaction-normal.test.ts +0 -57
  56. package/src/handlers/get-transaction-history/converters/etherscan-transaction-converter/convert-transaction-normal.ts +0 -57
  57. package/src/handlers/get-transaction-history/converters/etherscan-transaction-converter/get-transaction-from-etherscan.test.ts +0 -116
  58. package/src/handlers/get-transaction-history/converters/etherscan-transaction-converter/get-transaction-from-etherscan.ts +0 -73
  59. package/src/handlers/get-transaction-history/converters/evm-transaction-converter/convert-transaction.ts +0 -47
  60. package/src/handlers/get-transaction-history/converters/evm-transaction-converter/get-nft-metadata.ts +0 -35
  61. package/src/handlers/get-transaction-history/converters/evm-transaction-converter/get-sender-info.ts +0 -38
  62. package/src/handlers/get-transaction-history/converters/evm-transaction-converter/get-tokens.ts +0 -106
  63. package/src/handlers/get-transaction-history/converters/evm-transaction-converter/get-transaction-from-glacier.test.ts +0 -222
  64. package/src/handlers/get-transaction-history/converters/evm-transaction-converter/get-transactions-from-glacier.ts +0 -62
  65. package/src/handlers/get-transaction-history/converters/evm-transaction-converter/get-tx-type.ts +0 -52
  66. package/src/handlers/get-transaction-history/get-transaction-history.test.ts +0 -57
  67. package/src/handlers/get-transaction-history/get-transaction-history.ts +0 -55
  68. package/src/handlers/get-transaction-history/utils/get-explorer-address-by-network.ts +0 -7
  69. package/src/handlers/get-transaction-history/utils/get-small-image-for-nft.ts +0 -16
  70. package/src/handlers/get-transaction-history/utils/ipfs-resolver-with-fallback.ts +0 -18
  71. package/src/handlers/get-transaction-history/utils/is-ethereum-chain-id.ts +0 -15
  72. package/src/handlers/get-transaction-history/utils/resolve.ts +0 -7
  73. package/src/index.ts +0 -3
  74. package/src/module.ts +0 -141
  75. package/src/services/glacier-service/glacier-service.ts +0 -238
  76. package/src/types.ts +0 -25
  77. package/src/utils/estimate-gas-limit.ts +0 -27
  78. package/src/utils/get-chain-id.ts +0 -12
  79. package/src/utils/get-nonce.ts +0 -11
  80. package/src/utils/get-provider.ts +0 -46
  81. package/src/utils/parse-erc20-transaction-type.ts +0 -35
  82. package/src/utils/process-transaction-simulation.test.ts +0 -105
  83. package/src/utils/process-transaction-simulation.ts +0 -293
  84. package/src/utils/scan-transaction.ts +0 -63
  85. package/tsconfig.jest.json +0 -7
  86. package/tsconfig.json +0 -14
  87. package/tsup.config.ts +0 -4
@@ -1,222 +0,0 @@
1
- import type { ListTransactionDetailsResponse } from '@avalabs/glacier-sdk';
2
- import { getTransactionsFromGlacier } from './get-transactions-from-glacier';
3
- import { EvmGlacierService } from '../../../../services/glacier-service/glacier-service';
4
-
5
- const mockListTransactionDetailsResponse: ListTransactionDetailsResponse = {
6
- nextPageToken: 'nextPageToken',
7
- transactions: [
8
- {
9
- nativeTransaction: {
10
- from: {
11
- address: 'address',
12
- },
13
- to: {
14
- address: 'address',
15
- },
16
- value: '1',
17
- gasLimit: '1',
18
- nonce: '1',
19
- txStatus: '1',
20
- txType: 1,
21
- blockHash: 'blockHash',
22
- blockIndex: 1,
23
- blockNumber: '1',
24
- blockTimestamp: 1,
25
- txHash: 'txHash',
26
- gasPrice: '1',
27
- gasUsed: '1',
28
- },
29
- },
30
- ],
31
- };
32
-
33
- describe('get-transactions-from-glacier', () => {
34
- beforeEach(() => {
35
- jest.clearAllMocks();
36
- });
37
- it('should have returned empty response when listTransaction failed', async () => {
38
- const mockGlacierService: EvmGlacierService = {
39
- ...expect.any(Object),
40
- listTransactions: jest.fn().mockRejectedValue(new Error('failed to list transactions')),
41
- isHealthy: jest.fn().mockReturnValue(true),
42
- };
43
- const result = await getTransactionsFromGlacier({
44
- networkToken: {
45
- name: 'networkToken',
46
- symbol: 'networkToken',
47
- decimals: 1,
48
- description: 'description',
49
- logoUri: 'logoUri',
50
- },
51
- explorerUrl: 'explorerUrl',
52
- chainId: 1,
53
- address: 'address',
54
- nextPageToken: 'nextPageToken',
55
- offset: 1,
56
- glacierService: mockGlacierService,
57
- });
58
- expect(result).toEqual({
59
- transactions: [],
60
- nextPageToken: '',
61
- });
62
- });
63
- it('should have returned filtered response with no transaction status of 0', async () => {
64
- const mockGlacierService: EvmGlacierService = {
65
- ...expect.any(Object),
66
- listTransactions: jest.fn().mockResolvedValue({
67
- ...mockListTransactionDetailsResponse,
68
- transactions: [
69
- {
70
- ...mockListTransactionDetailsResponse.transactions[0],
71
- nativeTransaction: {
72
- ...mockListTransactionDetailsResponse.transactions[0]?.nativeTransaction,
73
- txStatus: '0',
74
- },
75
- },
76
- ],
77
- }),
78
- isHealthy: jest.fn().mockReturnValue(true),
79
- };
80
- const result = await getTransactionsFromGlacier({
81
- networkToken: {
82
- name: 'networkToken',
83
- symbol: 'networkToken',
84
- decimals: 1,
85
- description: 'description',
86
- logoUri: 'logoUri',
87
- },
88
- explorerUrl: 'explorerUrl',
89
- chainId: 1,
90
- address: 'address',
91
- nextPageToken: 'nextPageToken',
92
- offset: 1,
93
- glacierService: mockGlacierService,
94
- });
95
- expect(result).toEqual({
96
- transactions: [],
97
- nextPageToken: 'nextPageToken',
98
- });
99
- });
100
- it('should have returned filtered response without transaction with amount 0', async () => {
101
- const mockGlacierService: EvmGlacierService = {
102
- ...expect.any(Object),
103
- listTransactions: jest.fn().mockResolvedValue({
104
- ...mockListTransactionDetailsResponse,
105
- transactions: [
106
- {
107
- ...mockListTransactionDetailsResponse.transactions[0],
108
- nativeTransaction: {
109
- ...mockListTransactionDetailsResponse.transactions[0]?.nativeTransaction,
110
- txStatus: '0',
111
- },
112
- },
113
- ],
114
- }),
115
- isHealthy: jest.fn().mockReturnValue(true),
116
- };
117
- const result = await getTransactionsFromGlacier({
118
- networkToken: {
119
- name: 'networkToken',
120
- symbol: 'networkToken',
121
- decimals: 1,
122
- description: 'description',
123
- logoUri: 'logoUri',
124
- },
125
- explorerUrl: 'explorerUrl',
126
- chainId: 1,
127
- address: 'address',
128
- nextPageToken: 'nextPageToken',
129
- offset: 1,
130
- glacierService: mockGlacierService,
131
- });
132
- expect(result).toEqual({
133
- transactions: [],
134
- nextPageToken: 'nextPageToken',
135
- });
136
- });
137
-
138
- it('should have returned response', async () => {
139
- const mockGlacierService: EvmGlacierService = {
140
- ...expect.any(Object),
141
- listTransactions: jest.fn().mockResolvedValue(mockListTransactionDetailsResponse),
142
- isHealthy: jest.fn().mockReturnValue(true),
143
- };
144
- const result = await getTransactionsFromGlacier({
145
- networkToken: {
146
- name: 'networkToken',
147
- symbol: 'networkToken',
148
- decimals: 1,
149
- description: 'description',
150
- logoUri: 'logoUri',
151
- },
152
- explorerUrl: 'explorerUrl',
153
- chainId: 1,
154
- address: 'address',
155
- nextPageToken: 'nextPageToken',
156
- offset: 1,
157
- glacierService: mockGlacierService,
158
- });
159
- expect(result).toEqual({
160
- transactions: [
161
- {
162
- isContractCall: false,
163
- isIncoming: false,
164
- isOutgoing: true,
165
- isSender: true,
166
- timestamp: 1000,
167
- hash: 'txHash',
168
- from: 'address',
169
- to: 'address',
170
- tokens: [
171
- {
172
- amount: '0.1',
173
- symbol: 'networkToken',
174
- decimal: '1',
175
- name: 'networkToken',
176
- type: 'NATIVE',
177
- from: {
178
- address: 'address',
179
- },
180
- to: {
181
- address: 'address',
182
- },
183
- },
184
- ],
185
- gasPrice: '1',
186
- gasUsed: '1',
187
- chainId: '1',
188
- txType: 'Send',
189
- explorerLink: 'explorerUrl/tx/txHash',
190
- },
191
- ],
192
- nextPageToken: 'nextPageToken',
193
- });
194
- });
195
-
196
- it('should have returned empty response', async () => {
197
- const mockGlacierService: EvmGlacierService = {
198
- ...expect.any(Object),
199
- listTransactions: jest.fn(),
200
- isHealthy: jest.fn().mockReturnValue(false),
201
- };
202
- const result = await getTransactionsFromGlacier({
203
- networkToken: {
204
- name: 'networkToken',
205
- symbol: 'networkToken',
206
- decimals: 1,
207
- description: 'description',
208
- logoUri: 'logoUri',
209
- },
210
- explorerUrl: 'explorerUrl',
211
- chainId: 1,
212
- address: 'address',
213
- nextPageToken: 'nextPageToken',
214
- offset: 1,
215
- glacierService: mockGlacierService,
216
- });
217
- expect(result).toEqual({
218
- transactions: [],
219
- nextPageToken: '',
220
- });
221
- });
222
- });
@@ -1,62 +0,0 @@
1
- import type { NetworkToken, TransactionHistoryResponse } from '@avalabs/vm-module-types';
2
- import { convertTransaction } from './convert-transaction';
3
- import type { EvmGlacierService } from '../../../../services/glacier-service/glacier-service';
4
-
5
- export const getTransactionsFromGlacier = async ({
6
- chainId,
7
- explorerUrl,
8
- networkToken,
9
- address,
10
- nextPageToken,
11
- offset,
12
- glacierService,
13
- }: {
14
- chainId: number;
15
- explorerUrl: string;
16
- networkToken: NetworkToken;
17
- address: string;
18
- nextPageToken?: string;
19
- offset?: number;
20
- glacierService: EvmGlacierService;
21
- }): Promise<TransactionHistoryResponse> => {
22
- try {
23
- const response = await glacierService.listTransactions({
24
- chainId: chainId.toString(),
25
- address,
26
- pageToken: nextPageToken,
27
- pageSize: offset,
28
- });
29
-
30
- const convertedTxs = await Promise.all(
31
- response.transactions
32
- .filter(
33
- // Currently not showing failed tx
34
- (tranasaction) => tranasaction.nativeTransaction.txStatus === '1',
35
- )
36
- .map((transactions) =>
37
- convertTransaction({
38
- transactions,
39
- explorerUrl,
40
- networkToken,
41
- chainId,
42
- address,
43
- }).then((tx) => tx),
44
- ),
45
- );
46
-
47
- const transactions = convertedTxs.filter(
48
- // Filtering txs with 0 value since there is no change in balance
49
- (transaction) => transaction.tokens.find((token) => Number(token.amount) !== 0),
50
- );
51
-
52
- return {
53
- transactions,
54
- nextPageToken: response.nextPageToken,
55
- };
56
- } catch {
57
- return {
58
- transactions: [],
59
- nextPageToken: '',
60
- };
61
- }
62
- };
@@ -1,52 +0,0 @@
1
- import type { TransactionDetails } from '@avalabs/glacier-sdk';
2
- import { TokenType, TransactionType, type TxToken } from '@avalabs/vm-module-types';
3
- import startCase from 'lodash.startcase';
4
-
5
- export const getTxType = (
6
- { nativeTransaction, erc20Transfers, erc721Transfers }: TransactionDetails,
7
- userAddress: string,
8
- tokens: TxToken[],
9
- ): TransactionType => {
10
- const nativeOnly = !erc20Transfers && !erc721Transfers;
11
- const method = parseRawMethod(nativeTransaction.method?.methodName);
12
-
13
- const address = userAddress.toLowerCase();
14
-
15
- const isSwap = method.toLowerCase().includes('swap');
16
- const isNativeSend = nativeOnly && nativeTransaction.from.address.toLowerCase() === address;
17
- const isNativeReceive = nativeOnly && nativeTransaction.to.address.toLowerCase() === address;
18
- const isNFTPurchase = method === 'Market Buy Orders With Eth' || method === 'Buy NFT';
19
- const isApprove = method === 'Approve';
20
- const isTransfer = method.toLowerCase().includes('transfer');
21
- const isAirdrop = method.toLowerCase().includes('airdrop');
22
- const isUnwrap = method.toLowerCase().includes('unwrap');
23
- const isFillOrder = method === 'Fill Order';
24
- const isNFTSend =
25
- isTransfer && !!tokens[0] && isNFT(tokens[0].type) && tokens[0].from?.address.toLowerCase() === address;
26
- const isNFTReceive =
27
- isTransfer && !!tokens[0] && isNFT(tokens[0].type) && tokens[0].to?.address.toLowerCase() === address;
28
-
29
- if (isSwap) return TransactionType.SWAP;
30
- if (isNativeSend) return TransactionType.SEND;
31
- if (isNativeReceive) return TransactionType.RECEIVE;
32
- if (isNFTPurchase) return TransactionType.NFT_BUY;
33
- if (isApprove) return TransactionType.APPROVE;
34
- if (isNFTSend) return TransactionType.NFT_SEND;
35
- if (isNFTReceive) return TransactionType.NFT_RECEIVE;
36
- if (isTransfer) return TransactionType.TRANSFER;
37
- if (isAirdrop) return TransactionType.AIRDROP;
38
- if (isUnwrap) return TransactionType.UNWRAP;
39
- if (isFillOrder) return TransactionType.FILL_ORDER;
40
- return TransactionType.UNKNOWN;
41
- };
42
-
43
- function isNFT(tokenType: TokenType) {
44
- return tokenType === TokenType.ERC721 || tokenType === TokenType.ERC1155;
45
- }
46
-
47
- const parseRawMethod = (method = ''): string => {
48
- if (method.includes('(')) {
49
- return startCase(method.split('(', 1)[0]);
50
- }
51
- return method;
52
- };
@@ -1,57 +0,0 @@
1
- import { getTransactionHistory } from './get-transaction-history';
2
- import { getTransactionFromEtherscan } from './converters/etherscan-transaction-converter/get-transaction-from-etherscan';
3
- import { getTransactionsFromGlacier } from './converters/evm-transaction-converter/get-transactions-from-glacier';
4
- import type { EvmGlacierService } from '../../services/glacier-service/glacier-service';
5
-
6
- jest.mock('./converters/evm-transaction-converter/get-transactions-from-glacier', () => ({
7
- getTransactionsFromGlacier: jest.fn(),
8
- }));
9
-
10
- jest.mock('./converters/etherscan-transaction-converter/get-transaction-from-etherscan', () => ({
11
- getTransactionFromEtherscan: jest.fn(),
12
- }));
13
-
14
- describe('get-transaction-history', () => {
15
- it('should have called getTransactionFromEtherscan', async () => {
16
- await getTransactionHistory({
17
- glacierService: {} as EvmGlacierService,
18
- chainId: 1,
19
- isTestnet: false,
20
- networkToken: {
21
- name: 'networkToken',
22
- symbol: 'networkToken',
23
- decimals: 1,
24
- description: 'description',
25
- logoUri: 'logoUri',
26
- },
27
- explorerUrl: 'explorerUrl',
28
- address: 'address',
29
- nextPageToken: 'nextPageToken',
30
- offset: 1,
31
- });
32
- expect(getTransactionFromEtherscan).toHaveBeenCalled();
33
- });
34
- it('should have called getTransactionsFromGlacier', async () => {
35
- const mockGlacierService: EvmGlacierService = {
36
- ...expect.any(Object),
37
- isHealthy: jest.fn().mockReturnValue(true),
38
- };
39
- await getTransactionHistory({
40
- glacierService: mockGlacierService,
41
- chainId: 41334,
42
- isTestnet: false,
43
- networkToken: {
44
- name: 'networkToken',
45
- symbol: 'networkToken',
46
- decimals: 1,
47
- description: 'description',
48
- logoUri: 'logoUri',
49
- },
50
- explorerUrl: 'explorerUrl',
51
- address: 'address',
52
- nextPageToken: 'nextPageToken',
53
- offset: 1,
54
- });
55
- expect(getTransactionsFromGlacier).toHaveBeenCalled();
56
- });
57
- });
@@ -1,55 +0,0 @@
1
- import { getTransactionFromEtherscan } from './converters/etherscan-transaction-converter/get-transaction-from-etherscan';
2
- import { isEthereumChainId } from './utils/is-ethereum-chain-id';
3
- import type { NetworkToken, TransactionHistoryResponse } from '@avalabs/vm-module-types';
4
- import { getTransactionsFromGlacier } from './converters/evm-transaction-converter/get-transactions-from-glacier';
5
- import type { EvmGlacierService } from '../../services/glacier-service/glacier-service';
6
-
7
- export const getTransactionHistory = async ({
8
- chainId,
9
- isTestnet,
10
- networkToken,
11
- explorerUrl,
12
- address,
13
- nextPageToken,
14
- offset,
15
- glacierService,
16
- }: {
17
- chainId: number;
18
- isTestnet?: boolean;
19
- networkToken: NetworkToken;
20
- explorerUrl: string;
21
- address: string;
22
- nextPageToken?: string;
23
- offset?: number;
24
- glacierService: EvmGlacierService;
25
- }): Promise<TransactionHistoryResponse> => {
26
- if (isEthereumChainId(chainId)) {
27
- return getTransactionFromEtherscan({
28
- isTestnet,
29
- networkToken,
30
- explorerUrl,
31
- chainId,
32
- address,
33
- nextPageToken,
34
- offset,
35
- });
36
- }
37
-
38
- const isHealthy = glacierService.isHealthy();
39
- if (!isHealthy) {
40
- return {
41
- transactions: [],
42
- nextPageToken: '',
43
- };
44
- }
45
-
46
- return getTransactionsFromGlacier({
47
- networkToken,
48
- explorerUrl,
49
- chainId,
50
- address,
51
- nextPageToken,
52
- offset,
53
- glacierService,
54
- });
55
- };
@@ -1,7 +0,0 @@
1
- export function getExplorerAddressByNetwork(
2
- explorerUrl: string,
3
- hash: string,
4
- hashType: 'address' | 'tx' = 'tx',
5
- ): string {
6
- return `${explorerUrl}/${hashType}/${hash}`;
7
- }
@@ -1,16 +0,0 @@
1
- import { ipfsResolverWithFallback } from './ipfs-resolver-with-fallback';
2
-
3
- const COVALENT_IMG_SIZER = 'https://image-proxy.svc.prod.covalenthq.com/cdn-cgi/image';
4
-
5
- /**
6
- * Covalent has an on the fly image resizer, it resolves image urls then resizes the image.
7
- *
8
- * This allows us to request smaller images depending on the UI needs
9
- *
10
- * @param imgUrl the url of the image to convert to size
11
- * @returns The url to the image which is sized at the time of request
12
- */
13
- export function getSmallImageForNFT(imgUrl: string, imageSize: '256' | '512' | '1024' = '256') {
14
- const url = ipfsResolverWithFallback(imgUrl);
15
- return `${COVALENT_IMG_SIZER}/width=${imageSize},fit/${url}`;
16
- }
@@ -1,18 +0,0 @@
1
- import { ipfsResolver } from '@avalabs/utils-sdk';
2
-
3
- export const CLOUDFLARE_IPFS_URL = 'https://cloudflare-ipfs.com';
4
-
5
- export function ipfsResolverWithFallback(
6
- sourceUrl: string | undefined,
7
- desiredGatewayPrefix: string = CLOUDFLARE_IPFS_URL,
8
- ) {
9
- if (!sourceUrl) {
10
- return '';
11
- }
12
-
13
- try {
14
- return ipfsResolver(sourceUrl, desiredGatewayPrefix);
15
- } catch {
16
- return sourceUrl;
17
- }
18
- }
@@ -1,15 +0,0 @@
1
- enum ChainId {
2
- ETHEREUM_HOMESTEAD = 1,
3
- ETHEREUM_TEST_RINKEBY = 4,
4
- ETHEREUM_TEST_GOERLY = 5,
5
- ETHEREUM_TEST_SEPOLIA = 11155111,
6
- }
7
-
8
- export const isEthereumChainId = (chainId: number): boolean => {
9
- return (
10
- ChainId.ETHEREUM_HOMESTEAD === chainId ||
11
- ChainId.ETHEREUM_TEST_GOERLY === chainId ||
12
- ChainId.ETHEREUM_TEST_RINKEBY === chainId ||
13
- ChainId.ETHEREUM_TEST_SEPOLIA === chainId
14
- );
15
- };
@@ -1,7 +0,0 @@
1
- export async function resolve<T = unknown>(promise: Promise<T>) {
2
- try {
3
- return promise.then((res) => [res, null]).catch((err) => [null, err]);
4
- } catch (err) {
5
- return Promise.resolve([null, err]);
6
- }
7
- }
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from './module';
2
- export * from './types';
3
- export * from './handlers/eth-sign/utils/typeguards';
package/src/module.ts DELETED
@@ -1,141 +0,0 @@
1
- import type {
2
- Module,
3
- Manifest,
4
- NetworkFees,
5
- GetTransactionHistory,
6
- RpcRequest,
7
- Environment,
8
- Network,
9
- ApprovalController,
10
- GetBalancesParams,
11
- GetBalancesResponse,
12
- GetAddressParams,
13
- GetAddressResponse,
14
- } from '@avalabs/vm-module-types';
15
- import { rpcErrors } from '@metamask/rpc-errors';
16
- import { RpcMethod, parseManifest } from '@avalabs/vm-module-types';
17
- import { getTokens } from './handlers/get-tokens/get-tokens';
18
- import { getNetworkFee } from './handlers/get-network-fee/get-network-fee';
19
- import { getTransactionHistory } from './handlers/get-transaction-history/get-transaction-history';
20
- import ManifestJson from '../manifest.json';
21
- import { ethSendTransaction } from './handlers/eth-send-transaction/eth-send-transaction';
22
- import { getBalances } from './handlers/get-balances/get-balances';
23
- import { getEnv } from './env';
24
- import { EvmGlacierService } from './services/glacier-service/glacier-service';
25
- import { ethSign } from './handlers/eth-sign/eth-sign';
26
- import { forwardToRpcNode } from './handlers/forward-to-rpc-node/forward-to-rpc-node';
27
- import { getAddress } from './handlers/get-address/get-address';
28
-
29
- export class EvmModule implements Module {
30
- #glacierService: EvmGlacierService;
31
- #proxyApiUrl: string;
32
- #approvalController: ApprovalController;
33
-
34
- constructor({
35
- approvalController,
36
- environment,
37
- }: {
38
- approvalController: ApprovalController;
39
- environment: Environment;
40
- }) {
41
- const { glacierApiUrl, proxyApiUrl } = getEnv(environment);
42
- this.#glacierService = new EvmGlacierService({ glacierApiUrl });
43
- this.#proxyApiUrl = proxyApiUrl;
44
- this.#approvalController = approvalController;
45
- }
46
-
47
- getAddress({ accountIndex, xpub, walletType }: GetAddressParams): Promise<GetAddressResponse> {
48
- return getAddress({ accountIndex, xpub, walletType });
49
- }
50
-
51
- getBalances({
52
- addresses,
53
- network,
54
- currency,
55
- customTokens,
56
- storage,
57
- }: GetBalancesParams): Promise<GetBalancesResponse> {
58
- return getBalances({
59
- addresses,
60
- currency,
61
- network,
62
- proxyApiUrl: this.#proxyApiUrl,
63
- customTokens,
64
- glacierService: this.#glacierService,
65
- storage,
66
- });
67
- }
68
-
69
- getManifest(): Manifest | undefined {
70
- const result = parseManifest(ManifestJson);
71
- return result.success ? result.data : undefined;
72
- }
73
-
74
- getNetworkFee(network: Network): Promise<NetworkFees> {
75
- const { chainId, chainName, rpcUrl, utilityAddresses } = network;
76
- return getNetworkFee({
77
- chainId,
78
- chainName,
79
- rpcUrl,
80
- multiContractAddress: utilityAddresses?.multicall,
81
- });
82
- }
83
-
84
- getTransactionHistory(params: GetTransactionHistory) {
85
- const { network, address, nextPageToken, offset } = params;
86
- const { chainId, isTestnet, networkToken, explorerUrl = '' } = network;
87
-
88
- return getTransactionHistory({
89
- chainId,
90
- isTestnet,
91
- networkToken,
92
- explorerUrl,
93
- address,
94
- nextPageToken,
95
- offset,
96
- glacierService: this.#glacierService,
97
- });
98
- }
99
-
100
- getTokens(network: Network) {
101
- const { chainId } = network;
102
- return getTokens({ chainId, proxyApiUrl: this.#proxyApiUrl });
103
- }
104
-
105
- async onRpcRequest(request: RpcRequest, network: Network) {
106
- switch (request.method) {
107
- case RpcMethod.ETH_SEND_TRANSACTION:
108
- return ethSendTransaction({
109
- request,
110
- network,
111
- approvalController: this.#approvalController,
112
- proxyApiUrl: this.#proxyApiUrl,
113
- });
114
- case RpcMethod.PERSONAL_SIGN:
115
- case RpcMethod.ETH_SIGN:
116
- case RpcMethod.SIGN_TYPED_DATA:
117
- case RpcMethod.SIGN_TYPED_DATA_V1:
118
- case RpcMethod.SIGN_TYPED_DATA_V3:
119
- case RpcMethod.SIGN_TYPED_DATA_V4:
120
- return ethSign({
121
- request,
122
- network,
123
- approvalController: this.#approvalController,
124
- proxyApiUrl: this.#proxyApiUrl,
125
- });
126
- default:
127
- if (shouldForwardToRpcNode(request.method)) {
128
- return forwardToRpcNode(request, network);
129
- }
130
-
131
- return { error: rpcErrors.methodNotSupported(`Method ${request.method} not supported`) };
132
- }
133
- }
134
- }
135
-
136
- const shouldForwardToRpcNode = (method: RpcMethod) => {
137
- return (
138
- method.startsWith('eth_') ||
139
- ['web3_clientVersion', 'web3_sha3', 'net_version', 'net_peerCount', 'net_listening'].includes(method)
140
- );
141
- };