@avalabs/evm-module 0.0.22 → 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 (90) hide show
  1. package/LICENSE +9 -0
  2. package/dist/index.cjs +18 -20
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +2 -2
  5. package/dist/index.d.ts +2 -2
  6. package/dist/index.js +16 -17
  7. package/dist/index.js.map +1 -1
  8. package/package.json +14 -8
  9. package/.turbo/turbo-build.log +0 -22
  10. package/.turbo/turbo-lint.log +0 -4
  11. package/.turbo/turbo-test.log +0 -117
  12. package/CHANGELOG.md +0 -166
  13. package/jest.config.js +0 -9
  14. package/src/constants.ts +0 -1
  15. package/src/contracts/openzeppelin/ERC1155.ts +0 -440
  16. package/src/contracts/openzeppelin/ERC20.ts +0 -330
  17. package/src/contracts/openzeppelin/ERC721.ts +0 -420
  18. package/src/contracts/openzeppelin/common.ts +0 -131
  19. package/src/contracts/openzeppelin/factories/ERC1155__factory.ts +0 -388
  20. package/src/contracts/openzeppelin/factories/ERC20__factory.ts +0 -353
  21. package/src/contracts/openzeppelin/factories/ERC721__factory.ts +0 -413
  22. package/src/contracts/openzeppelin/factories/index.ts +0 -6
  23. package/src/contracts/openzeppelin/index.ts +0 -10
  24. package/src/env.ts +0 -25
  25. package/src/handlers/eth-send-transaction/eth-send-transaction.test.ts +0 -572
  26. package/src/handlers/eth-send-transaction/eth-send-transaction.ts +0 -189
  27. package/src/handlers/eth-send-transaction/schema.test.ts +0 -240
  28. package/src/handlers/eth-send-transaction/schema.ts +0 -20
  29. package/src/handlers/eth-sign/eth-sign.test.ts +0 -359
  30. package/src/handlers/eth-sign/eth-sign.ts +0 -158
  31. package/src/handlers/eth-sign/schemas/eth-sign-typed-data.ts +0 -65
  32. package/src/handlers/eth-sign/schemas/eth-sign.ts +0 -9
  33. package/src/handlers/eth-sign/schemas/parse-request-params/fixture.ts +0 -47
  34. package/src/handlers/eth-sign/schemas/parse-request-params/parse-request-params.test.ts +0 -284
  35. package/src/handlers/eth-sign/schemas/parse-request-params/parse-request-params.ts +0 -94
  36. package/src/handlers/eth-sign/schemas/personal-sign.ts +0 -12
  37. package/src/handlers/eth-sign/schemas/shared.ts +0 -5
  38. package/src/handlers/eth-sign/utils/beautify-message/beautify-message.test.ts +0 -29
  39. package/src/handlers/eth-sign/utils/beautify-message/beautify-message.ts +0 -134
  40. package/src/handlers/eth-sign/utils/is-typed-data-valid.ts +0 -26
  41. package/src/handlers/eth-sign/utils/typeguards.ts +0 -10
  42. package/src/handlers/forward-to-rpc-node/forward-to-rpc-node.test.ts +0 -90
  43. package/src/handlers/forward-to-rpc-node/forward-to-rpc-node.ts +0 -23
  44. package/src/handlers/get-balances/evm-balance-service/get-erc20-balances.test.ts +0 -78
  45. package/src/handlers/get-balances/evm-balance-service/get-erc20-balances.ts +0 -85
  46. package/src/handlers/get-balances/evm-balance-service/get-native-token-balances.test.ts +0 -97
  47. package/src/handlers/get-balances/evm-balance-service/get-native-token-balances.ts +0 -56
  48. package/src/handlers/get-balances/get-balances.test.ts +0 -249
  49. package/src/handlers/get-balances/get-balances.ts +0 -121
  50. package/src/handlers/get-balances/glacier-balance-service/get-erc20-balances.test.ts +0 -72
  51. package/src/handlers/get-balances/glacier-balance-service/get-erc20-balances.ts +0 -109
  52. package/src/handlers/get-balances/glacier-balance-service/get-native-token-balances.test.ts +0 -60
  53. package/src/handlers/get-balances/glacier-balance-service/get-native-token-balances.ts +0 -47
  54. package/src/handlers/get-network-fee/get-network-fee.test.ts +0 -43
  55. package/src/handlers/get-network-fee/get-network-fee.ts +0 -59
  56. package/src/handlers/get-tokens/get-tokens.test.ts +0 -100
  57. package/src/handlers/get-tokens/get-tokens.ts +0 -18
  58. package/src/handlers/get-transaction-history/converters/etherscan-transaction-converter/convert-transaction-erc20.ts +0 -51
  59. package/src/handlers/get-transaction-history/converters/etherscan-transaction-converter/convert-transaction-normal.ts +0 -58
  60. package/src/handlers/get-transaction-history/converters/etherscan-transaction-converter/get-transaction-from-etherscan.test.ts +0 -116
  61. package/src/handlers/get-transaction-history/converters/etherscan-transaction-converter/get-transaction-from-etherscan.ts +0 -73
  62. package/src/handlers/get-transaction-history/converters/evm-transaction-converter/convert-transaction.ts +0 -47
  63. package/src/handlers/get-transaction-history/converters/evm-transaction-converter/get-nft-metadata.ts +0 -35
  64. package/src/handlers/get-transaction-history/converters/evm-transaction-converter/get-sender-info.ts +0 -38
  65. package/src/handlers/get-transaction-history/converters/evm-transaction-converter/get-tokens.ts +0 -107
  66. package/src/handlers/get-transaction-history/converters/evm-transaction-converter/get-transaction-from-glacier.test.ts +0 -222
  67. package/src/handlers/get-transaction-history/converters/evm-transaction-converter/get-transactions-from-glacier.ts +0 -62
  68. package/src/handlers/get-transaction-history/converters/evm-transaction-converter/get-tx-type.ts +0 -52
  69. package/src/handlers/get-transaction-history/get-transaction-history.test.ts +0 -57
  70. package/src/handlers/get-transaction-history/get-transaction-history.ts +0 -55
  71. package/src/handlers/get-transaction-history/utils/get-explorer-address-by-network.ts +0 -7
  72. package/src/handlers/get-transaction-history/utils/get-small-image-for-nft.ts +0 -16
  73. package/src/handlers/get-transaction-history/utils/ipfs-resolver-with-fallback.ts +0 -18
  74. package/src/handlers/get-transaction-history/utils/is-ethereum-chain-id.ts +0 -15
  75. package/src/handlers/get-transaction-history/utils/resolve.ts +0 -7
  76. package/src/index.ts +0 -3
  77. package/src/module.ts +0 -138
  78. package/src/services/glacier-service/glacier-service.ts +0 -238
  79. package/src/types.ts +0 -25
  80. package/src/utils/estimate-gas-limit.ts +0 -27
  81. package/src/utils/get-chain-id.ts +0 -12
  82. package/src/utils/get-nonce.ts +0 -11
  83. package/src/utils/get-provider.ts +0 -46
  84. package/src/utils/parse-erc20-transaction-type.ts +0 -35
  85. package/src/utils/process-transaction-simulation.test.ts +0 -105
  86. package/src/utils/process-transaction-simulation.ts +0 -293
  87. package/src/utils/scan-transaction.ts +0 -63
  88. package/tsconfig.jest.json +0 -7
  89. package/tsconfig.json +0 -14
  90. package/tsup.config.ts +0 -4
@@ -1,58 +0,0 @@
1
- import type { NormalTx } from '@avalabs/etherscan-sdk';
2
- import { TokenType, TransactionType, type NetworkToken, type Transaction } from '@avalabs/vm-module-types';
3
- import { balanceToDisplayValue } from '@avalabs/utils-sdk';
4
- import { BN } from 'bn.js';
5
- import { getExplorerAddressByNetwork } from '../../utils/get-explorer-address-by-network';
6
-
7
- export const convertTransactionNormal = ({
8
- tx,
9
- networkToken,
10
- chainId,
11
- explorerUrl,
12
- address,
13
- }: {
14
- tx: NormalTx;
15
- networkToken: NetworkToken;
16
- chainId: number;
17
- explorerUrl: string;
18
- address: string;
19
- }): Transaction => {
20
- const isSender = tx.from.toLowerCase() === address.toLowerCase();
21
- const timestamp = parseInt(tx.timeStamp) * 1000;
22
- const decimals = networkToken.decimals;
23
- const amountBN = new BN(tx.value);
24
- const amountDisplayValue = balanceToDisplayValue(amountBN, decimals);
25
- const txType = isSender ? TransactionType.SEND : TransactionType.RECEIVE;
26
-
27
- const { from, to, gasPrice, gasUsed, hash } = tx;
28
- const explorerLink = getExplorerAddressByNetwork(explorerUrl, hash);
29
-
30
- return {
31
- isIncoming: !isSender,
32
- isOutgoing: isSender,
33
- isContractCall: isContractCall(tx),
34
- timestamp,
35
- hash,
36
- isSender,
37
- from,
38
- to,
39
- tokens: [
40
- {
41
- decimal: decimals.toString(),
42
- name: networkToken.name,
43
- symbol: networkToken.symbol,
44
- amount: amountDisplayValue,
45
- type: TokenType.NATIVE,
46
- },
47
- ],
48
- gasUsed,
49
- gasPrice,
50
- chainId: chainId.toString(),
51
- txType,
52
- explorerLink,
53
- };
54
- };
55
-
56
- function isContractCall(tx: NormalTx): boolean {
57
- return tx.input !== '0x';
58
- }
@@ -1,116 +0,0 @@
1
- import { TokenType } from '@avalabs/vm-module-types';
2
- import { getTransactionFromEtherscan } from './get-transaction-from-etherscan';
3
- import type { Erc20Tx, NormalTx } from '@avalabs/etherscan-sdk';
4
-
5
- const mockNormalTxs: NormalTx[] = [
6
- {
7
- blockNumber: 'blockNumber',
8
- timeStamp: 'timeStamp',
9
- hash: 'normalTxHash',
10
- nonce: 'nonce',
11
- blockHash: 'blockHash',
12
- transactionIndex: 'transactionIndex',
13
- from: 'from',
14
- to: 'to',
15
- value: '1',
16
- gas: '1',
17
- gasPrice: '1',
18
- isError: 'isError',
19
- txreceipt_status: 'txreceipt_status',
20
- input: 'input',
21
- contractAddress: 'contractAddress',
22
- cumulativeGasUsed: '1',
23
- gasUsed: '1',
24
- confirmations: 'confirmations',
25
- },
26
- ];
27
-
28
- const mockErc20Txs: Erc20Tx[] = [
29
- {
30
- blockNumber: 'blockNumber',
31
- timeStamp: 'timeStamp',
32
- hash: 'erc20Hash',
33
- nonce: 'nonce',
34
- blockHash: 'blockHash',
35
- from: 'from',
36
- contractAddress: 'contractAddress',
37
- to: 'to',
38
- value: '1',
39
- tokenName: 'tokenName',
40
- tokenSymbol: 'tokenSymbol',
41
- tokenDecimal: '1',
42
- transactionIndex: 'transactionIndex',
43
- gas: '1',
44
- gasPrice: '1',
45
- input: 'input',
46
- cumulativeGasUsed: '1',
47
- gasUsed: '1',
48
- confirmations: 'confirmations',
49
- },
50
- ];
51
- // const mockTransactions = jest.fn();
52
- jest.mock('@avalabs/etherscan-sdk', () => ({
53
- getNormalTxs: () => mockNormalTxs,
54
- getErc20Txs: () => mockErc20Txs,
55
- }));
56
-
57
- describe('get-transaction-from-etherscan', () => {
58
- it('should have returned 1 normal transaction and 1 erc20 transaction', async () => {
59
- const result = await getTransactionFromEtherscan({
60
- isTestnet: false,
61
- chainId: 1,
62
- networkToken: {
63
- name: 'networkToken',
64
- symbol: 'networkToken',
65
- decimals: 1,
66
- description: 'description',
67
- logoUri: 'logoUri',
68
- },
69
- explorerUrl: 'explorerUrl',
70
- address: 'address',
71
- nextPageToken: '',
72
- offset: 1,
73
- });
74
- expect(result.transactions.length).toEqual(2);
75
- });
76
-
77
- it('should have returned 1 normal if nextPageToken contains only normal', async () => {
78
- const result = await getTransactionFromEtherscan({
79
- isTestnet: false,
80
- chainId: 1,
81
- networkToken: {
82
- name: 'networkToken',
83
- symbol: 'networkToken',
84
- decimals: 1,
85
- description: 'description',
86
- logoUri: 'logoUri',
87
- },
88
- explorerUrl: 'explorerUrl',
89
- address: 'address',
90
- nextPageToken: JSON.stringify({ page: 1, queries: ['normal'] }),
91
- offset: 1,
92
- });
93
- expect(result.transactions.length).toEqual(1);
94
- expect(result.transactions[0]?.tokens[0]?.type).toEqual(TokenType.NATIVE);
95
- });
96
-
97
- it('should have returned 1 erc20 if nextPageToken contains only erc20', async () => {
98
- const result = await getTransactionFromEtherscan({
99
- isTestnet: false,
100
- chainId: 1,
101
- networkToken: {
102
- name: 'networkToken',
103
- symbol: 'networkToken',
104
- decimals: 1,
105
- description: 'description',
106
- logoUri: 'logoUri',
107
- },
108
- explorerUrl: 'explorerUrl',
109
- address: 'address',
110
- nextPageToken: JSON.stringify({ page: 1, queries: ['erc20'] }),
111
- offset: 1,
112
- });
113
- expect(result.transactions.length).toEqual(1);
114
- expect(result.transactions[0]?.tokens[0]?.type).toEqual(TokenType.ERC20);
115
- });
116
- });
@@ -1,73 +0,0 @@
1
- import { convertTransactionNormal } from './convert-transaction-normal';
2
- import { convertTransactionERC20 } from './convert-transaction-erc20';
3
- import type { NetworkToken, TransactionHistoryResponse } from '@avalabs/vm-module-types';
4
- import { getErc20Txs, getNormalTxs } from '@avalabs/etherscan-sdk';
5
-
6
- interface EtherscanPagination {
7
- queries: ('normal' | 'erc20')[];
8
- page?: number;
9
- }
10
-
11
- export const getTransactionFromEtherscan = async ({
12
- isTestnet,
13
- networkToken,
14
- explorerUrl,
15
- chainId,
16
- address,
17
- nextPageToken,
18
- offset,
19
- }: {
20
- isTestnet?: boolean;
21
- networkToken: NetworkToken;
22
- explorerUrl: string;
23
- chainId: number;
24
- address: string;
25
- nextPageToken?: string;
26
- offset?: number;
27
- }): Promise<TransactionHistoryResponse> => {
28
- /*
29
- Using JSON for nextPageToken because this function is managing both the Normal
30
- and ERC20 queries. It encodes the current page and the queries that should be
31
- run. For example, if 'normal' has no more records to fetch then it will be
32
- excluded from the list and the JSON will be something like:
33
- { page: 3, queries: ['erc20'] }
34
- */
35
- const parsedPageToken = nextPageToken ? (JSON.parse(nextPageToken) as EtherscanPagination) : undefined;
36
- const page = parsedPageToken?.page || 1;
37
- const queries = parsedPageToken?.queries || ['normal', 'erc20'];
38
-
39
- const normalHist = (queries.includes('normal') ? await getNormalTxs(address, !isTestnet, { page, offset }) : []).map(
40
- (tx) => convertTransactionNormal({ tx, chainId, networkToken, explorerUrl, address }),
41
- );
42
-
43
- const erc20Hist = (
44
- queries.includes('erc20')
45
- ? await getErc20Txs(address, !isTestnet, undefined, {
46
- page,
47
- offset,
48
- })
49
- : []
50
- ).map((tx) =>
51
- convertTransactionERC20({
52
- tx,
53
- address,
54
- explorerUrl,
55
- chainId,
56
- }),
57
- );
58
-
59
- // Filter erc20 transactions from normal tx list
60
- const erc20TxHashes = erc20Hist.map((tx) => tx.hash);
61
- const filteredNormalTxs = normalHist.filter((tx) => {
62
- return !erc20TxHashes.includes(tx.hash);
63
- });
64
-
65
- const next: EtherscanPagination = { queries: [], page: page + 1 };
66
- if (normalHist.length) next.queries.push('normal');
67
- if (erc20Hist.length) next.queries.push('erc20');
68
-
69
- return {
70
- transactions: [...filteredNormalTxs, ...erc20Hist],
71
- nextPageToken: next.queries.length ? JSON.stringify(next) : '', // stop pagination
72
- };
73
- };
@@ -1,47 +0,0 @@
1
- import type { Transaction, NetworkToken } from '@avalabs/vm-module-types';
2
- import { getTxType } from './get-tx-type';
3
- import { getSenderInfo } from './get-sender-info';
4
- import { getTokens } from './get-tokens';
5
- import { getExplorerAddressByNetwork } from '../../utils/get-explorer-address-by-network';
6
- import type { TransactionDetails } from '@avalabs/glacier-sdk';
7
- import { NonContractCallTypes } from '../../../../types';
8
-
9
- type ConvertTransactionParams = {
10
- transactions: TransactionDetails;
11
- explorerUrl: string;
12
- networkToken: NetworkToken;
13
- chainId: number;
14
- address: string;
15
- };
16
-
17
- export const convertTransaction = async ({
18
- transactions,
19
- explorerUrl,
20
- networkToken,
21
- chainId,
22
- address,
23
- }: ConvertTransactionParams): Promise<Transaction> => {
24
- const tokens = await getTokens(transactions, networkToken);
25
- const txType = getTxType(transactions, address, tokens);
26
- const { isOutgoing, isIncoming, isSender, from, to } = getSenderInfo(txType, transactions, address);
27
- const { blockTimestamp, txHash: hash, gasPrice, gasUsed } = transactions.nativeTransaction;
28
- const explorerLink = getExplorerAddressByNetwork(explorerUrl, hash);
29
- const isContractCall = !NonContractCallTypes.includes(txType);
30
-
31
- return {
32
- isContractCall,
33
- isIncoming,
34
- isOutgoing,
35
- isSender,
36
- timestamp: blockTimestamp * 1000, // s to ms
37
- hash,
38
- from,
39
- to,
40
- tokens,
41
- gasPrice,
42
- gasUsed,
43
- chainId: chainId.toString(),
44
- txType,
45
- explorerLink,
46
- };
47
- };
@@ -1,35 +0,0 @@
1
- import { ipfsResolverWithFallback } from '../../utils/ipfs-resolver-with-fallback';
2
-
3
- interface NftMetadata {
4
- attributes?: string;
5
- name?: string;
6
- image?: string;
7
- description?: string;
8
- }
9
-
10
- async function fetchWithTimeout(uri: string, timeout = 5000) {
11
- const controller = new AbortController();
12
- setTimeout(() => controller.abort(), timeout);
13
-
14
- return fetch(uri, { signal: controller.signal });
15
- }
16
-
17
- export async function getNftMetadata(tokenUri: string) {
18
- let data: NftMetadata = {};
19
- if (!tokenUri) {
20
- return {};
21
- } else if (tokenUri.startsWith('data:application/json;base64,')) {
22
- const value = tokenUri.substring(29);
23
- try {
24
- const json = Buffer.from(value, 'base64').toString();
25
- data = JSON.parse(json);
26
- } catch {
27
- data = {};
28
- }
29
- } else {
30
- data = await fetchWithTimeout(ipfsResolverWithFallback(tokenUri))
31
- .then((r) => r.json())
32
- .catch(() => ({}));
33
- }
34
- return data;
35
- }
@@ -1,38 +0,0 @@
1
- import type { TransactionDetails } from '@avalabs/glacier-sdk';
2
- import { TransactionType } from '@avalabs/vm-module-types';
3
-
4
- export const getSenderInfo = (
5
- txType: TransactionType,
6
- { nativeTransaction, erc20Transfers, erc721Transfers }: TransactionDetails,
7
- address: string,
8
- ): { isOutgoing: boolean; isIncoming: boolean; isSender: boolean; from: string; to: string } => {
9
- const isTransfer = txType === TransactionType.TRANSFER;
10
- const isNativeSend = txType === TransactionType.SEND;
11
- const isNativeReceive = txType === TransactionType.RECEIVE;
12
- let from = nativeTransaction?.from?.address;
13
- let to = nativeTransaction?.to?.address;
14
-
15
- // Until multi tokens transaction is supported in UI, using from and to of the only token is helpful for UI
16
- if (isTransfer && erc20Transfers && erc20Transfers[0]) {
17
- from = erc20Transfers[0].from.address;
18
- to = erc20Transfers[0].to.address;
19
- }
20
-
21
- if (isTransfer && erc721Transfers && erc721Transfers[0]) {
22
- from = erc721Transfers[0].from.address;
23
- to = erc721Transfers[0].to.address;
24
- }
25
-
26
- const isOutgoing = isNativeSend || (isTransfer && from.toLowerCase() === address.toLowerCase());
27
- const isIncoming = isNativeReceive || (isTransfer && to.toLowerCase() === address.toLowerCase());
28
-
29
- const isSender = from === address;
30
-
31
- return {
32
- isOutgoing,
33
- isIncoming,
34
- isSender,
35
- from,
36
- to,
37
- };
38
- };
@@ -1,107 +0,0 @@
1
- import type { TransactionDetails } from '@avalabs/glacier-sdk';
2
- import { balanceToDisplayValue } from '@avalabs/utils-sdk';
3
- import { BN } from 'bn.js';
4
- import type { TxToken, NetworkToken } from '@avalabs/vm-module-types';
5
- import { TokenType } from '@avalabs/vm-module-types';
6
- import { resolve } from '../../utils/resolve';
7
- import { getNftMetadata } from './get-nft-metadata';
8
- import { getSmallImageForNFT } from '../../utils/get-small-image-for-nft';
9
- import { ipfsResolverWithFallback } from '../../utils/ipfs-resolver-with-fallback';
10
-
11
- export const getTokens = async (
12
- { nativeTransaction, erc20Transfers, erc721Transfers, erc1155Transfers }: TransactionDetails,
13
- networkToken: NetworkToken,
14
- ): Promise<TxToken[]> => {
15
- const result: TxToken[] = [];
16
-
17
- if (nativeTransaction.value !== '0') {
18
- const decimal = networkToken.decimals;
19
- const amountBN = new BN(nativeTransaction.value);
20
- const amountDisplayValue = balanceToDisplayValue(amountBN, decimal);
21
- result.push({
22
- decimal: decimal.toString(),
23
- name: networkToken.name,
24
- symbol: networkToken.symbol,
25
- amount: amountDisplayValue,
26
- from: nativeTransaction.from,
27
- to: nativeTransaction.to,
28
- type: TokenType.NATIVE,
29
- });
30
- }
31
-
32
- erc20Transfers?.forEach((erc20Transfer) => {
33
- const decimals = erc20Transfer.erc20Token.decimals;
34
- const amountBN = new BN(erc20Transfer.value);
35
- const amountDisplayValue = balanceToDisplayValue(amountBN, decimals);
36
-
37
- result.push({
38
- decimal: decimals.toString(),
39
- name: erc20Transfer.erc20Token.name,
40
- symbol: erc20Transfer.erc20Token.symbol,
41
- amount: amountDisplayValue,
42
- from: erc20Transfer.from,
43
- to: erc20Transfer.to,
44
- imageUri: erc20Transfer.erc20Token.logoUri,
45
- type: TokenType.ERC20,
46
- });
47
- });
48
-
49
- if (erc721Transfers) {
50
- await Promise.allSettled(
51
- erc721Transfers.map(async (erc721Transfer) => {
52
- const token = erc721Transfer.erc721Token;
53
- const imageUri = await getImageUri(token.tokenUri, token.metadata.imageUri);
54
-
55
- result.push({
56
- name: erc721Transfer.erc721Token.name,
57
- symbol: erc721Transfer.erc721Token.symbol,
58
- amount: '1',
59
- imageUri,
60
- from: erc721Transfer.from,
61
- to: erc721Transfer.to,
62
- collectableTokenId: erc721Transfer.erc721Token.tokenId,
63
- type: TokenType.ERC721,
64
- });
65
- }),
66
- );
67
- }
68
-
69
- if (erc1155Transfers) {
70
- await Promise.allSettled(
71
- erc1155Transfers.map(async (erc1155Transfer) => {
72
- const token = erc1155Transfer.erc1155Token;
73
- const imageUri = await getImageUri(token.tokenUri, token.metadata.imageUri);
74
-
75
- result.push({
76
- name: erc1155Transfer.erc1155Token.metadata.name ?? '',
77
- symbol: erc1155Transfer.erc1155Token.metadata.symbol ?? '',
78
- amount: erc1155Transfer.value,
79
- imageUri,
80
- from: erc1155Transfer.from,
81
- to: erc1155Transfer.to,
82
- collectableTokenId: erc1155Transfer.erc1155Token.tokenId,
83
- type: TokenType.ERC1155,
84
- });
85
- }),
86
- );
87
- }
88
-
89
- return result;
90
- };
91
-
92
- const getImageUri = async (tokenUri: string, imageUri?: string): Promise<string> => {
93
- if (imageUri) {
94
- if (imageUri.startsWith('ipfs://')) {
95
- return ipfsResolverWithFallback(imageUri);
96
- } else {
97
- return imageUri;
98
- }
99
- } else {
100
- const [metadata, error] = await resolve(getNftMetadata(tokenUri));
101
- if (error) {
102
- return '';
103
- } else {
104
- return metadata.image ? getSmallImageForNFT(metadata.image) : '';
105
- }
106
- }
107
- };
@@ -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
- });