@avalabs/evm-module 0.0.23 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/LICENSE +9 -0
  2. package/README.md +1 -1
  3. package/dist/index.cjs +6 -6
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.js +5 -5
  6. package/dist/index.js.map +1 -1
  7. package/package.json +13 -8
  8. package/.turbo/turbo-build.log +0 -22
  9. package/.turbo/turbo-lint.log +0 -4
  10. package/.turbo/turbo-test.log +0 -119
  11. package/CHANGELOG.md +0 -174
  12. package/jest.config.js +0 -9
  13. package/src/constants.ts +0 -1
  14. package/src/contracts/openzeppelin/ERC1155.ts +0 -440
  15. package/src/contracts/openzeppelin/ERC20.ts +0 -330
  16. package/src/contracts/openzeppelin/ERC721.ts +0 -420
  17. package/src/contracts/openzeppelin/common.ts +0 -131
  18. package/src/contracts/openzeppelin/factories/ERC1155__factory.ts +0 -388
  19. package/src/contracts/openzeppelin/factories/ERC20__factory.ts +0 -353
  20. package/src/contracts/openzeppelin/factories/ERC721__factory.ts +0 -413
  21. package/src/contracts/openzeppelin/factories/index.ts +0 -6
  22. package/src/contracts/openzeppelin/index.ts +0 -10
  23. package/src/env.ts +0 -25
  24. package/src/handlers/eth-send-transaction/eth-send-transaction.test.ts +0 -572
  25. package/src/handlers/eth-send-transaction/eth-send-transaction.ts +0 -189
  26. package/src/handlers/eth-send-transaction/schema.test.ts +0 -240
  27. package/src/handlers/eth-send-transaction/schema.ts +0 -20
  28. package/src/handlers/eth-sign/eth-sign.test.ts +0 -359
  29. package/src/handlers/eth-sign/eth-sign.ts +0 -158
  30. package/src/handlers/eth-sign/schemas/eth-sign-typed-data.ts +0 -65
  31. package/src/handlers/eth-sign/schemas/eth-sign.ts +0 -9
  32. package/src/handlers/eth-sign/schemas/parse-request-params/fixture.ts +0 -47
  33. package/src/handlers/eth-sign/schemas/parse-request-params/parse-request-params.test.ts +0 -284
  34. package/src/handlers/eth-sign/schemas/parse-request-params/parse-request-params.ts +0 -94
  35. package/src/handlers/eth-sign/schemas/personal-sign.ts +0 -12
  36. package/src/handlers/eth-sign/schemas/shared.ts +0 -5
  37. package/src/handlers/eth-sign/utils/beautify-message/beautify-message.test.ts +0 -29
  38. package/src/handlers/eth-sign/utils/beautify-message/beautify-message.ts +0 -134
  39. package/src/handlers/eth-sign/utils/is-typed-data-valid.ts +0 -26
  40. package/src/handlers/eth-sign/utils/typeguards.ts +0 -10
  41. package/src/handlers/forward-to-rpc-node/forward-to-rpc-node.test.ts +0 -90
  42. package/src/handlers/forward-to-rpc-node/forward-to-rpc-node.ts +0 -23
  43. package/src/handlers/get-address/get-address.ts +0 -26
  44. package/src/handlers/get-balances/evm-balance-service/get-erc20-balances.test.ts +0 -77
  45. package/src/handlers/get-balances/evm-balance-service/get-erc20-balances.ts +0 -81
  46. package/src/handlers/get-balances/evm-balance-service/get-native-token-balances.test.ts +0 -96
  47. package/src/handlers/get-balances/evm-balance-service/get-native-token-balances.ts +0 -53
  48. package/src/handlers/get-balances/get-balances.test.ts +0 -248
  49. package/src/handlers/get-balances/get-balances.ts +0 -123
  50. package/src/handlers/get-balances/glacier-balance-service/get-erc20-balances.test.ts +0 -71
  51. package/src/handlers/get-balances/glacier-balance-service/get-erc20-balances.ts +0 -106
  52. package/src/handlers/get-balances/glacier-balance-service/get-native-token-balances.test.ts +0 -59
  53. package/src/handlers/get-balances/glacier-balance-service/get-native-token-balances.ts +0 -48
  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.test.ts +0 -53
  59. package/src/handlers/get-transaction-history/converters/etherscan-transaction-converter/convert-transaction-erc20.ts +0 -49
  60. package/src/handlers/get-transaction-history/converters/etherscan-transaction-converter/convert-transaction-normal.test.ts +0 -57
  61. package/src/handlers/get-transaction-history/converters/etherscan-transaction-converter/convert-transaction-normal.ts +0 -57
  62. package/src/handlers/get-transaction-history/converters/etherscan-transaction-converter/get-transaction-from-etherscan.test.ts +0 -116
  63. package/src/handlers/get-transaction-history/converters/etherscan-transaction-converter/get-transaction-from-etherscan.ts +0 -73
  64. package/src/handlers/get-transaction-history/converters/evm-transaction-converter/convert-transaction.ts +0 -47
  65. package/src/handlers/get-transaction-history/converters/evm-transaction-converter/get-nft-metadata.ts +0 -35
  66. package/src/handlers/get-transaction-history/converters/evm-transaction-converter/get-sender-info.ts +0 -38
  67. package/src/handlers/get-transaction-history/converters/evm-transaction-converter/get-tokens.ts +0 -106
  68. package/src/handlers/get-transaction-history/converters/evm-transaction-converter/get-transaction-from-glacier.test.ts +0 -222
  69. package/src/handlers/get-transaction-history/converters/evm-transaction-converter/get-transactions-from-glacier.ts +0 -62
  70. package/src/handlers/get-transaction-history/converters/evm-transaction-converter/get-tx-type.ts +0 -52
  71. package/src/handlers/get-transaction-history/get-transaction-history.test.ts +0 -57
  72. package/src/handlers/get-transaction-history/get-transaction-history.ts +0 -55
  73. package/src/handlers/get-transaction-history/utils/get-explorer-address-by-network.ts +0 -7
  74. package/src/handlers/get-transaction-history/utils/get-small-image-for-nft.ts +0 -16
  75. package/src/handlers/get-transaction-history/utils/ipfs-resolver-with-fallback.ts +0 -18
  76. package/src/handlers/get-transaction-history/utils/is-ethereum-chain-id.ts +0 -15
  77. package/src/handlers/get-transaction-history/utils/resolve.ts +0 -7
  78. package/src/index.ts +0 -3
  79. package/src/module.ts +0 -141
  80. package/src/services/glacier-service/glacier-service.ts +0 -238
  81. package/src/types.ts +0 -25
  82. package/src/utils/estimate-gas-limit.ts +0 -27
  83. package/src/utils/get-chain-id.ts +0 -12
  84. package/src/utils/get-nonce.ts +0 -11
  85. package/src/utils/get-provider.ts +0 -46
  86. package/src/utils/parse-erc20-transaction-type.ts +0 -35
  87. package/src/utils/process-transaction-simulation.test.ts +0 -105
  88. package/src/utils/process-transaction-simulation.ts +0 -293
  89. package/src/utils/scan-transaction.ts +0 -63
  90. package/tsconfig.jest.json +0 -7
  91. package/tsconfig.json +0 -14
  92. package/tsup.config.ts +0 -4
@@ -1,49 +0,0 @@
1
- import type { Erc20Tx } from '@avalabs/etherscan-sdk';
2
- import { TokenType, TransactionType, type Transaction } from '@avalabs/vm-module-types';
3
- import { TokenUnit } from '@avalabs/utils-sdk';
4
- import { getExplorerAddressByNetwork } from '../../utils/get-explorer-address-by-network';
5
-
6
- export function convertTransactionERC20({
7
- tx,
8
- address,
9
- explorerUrl,
10
- chainId,
11
- }: {
12
- tx: Erc20Tx;
13
- address: string;
14
- chainId: number;
15
- explorerUrl: string;
16
- }): Transaction {
17
- const isSender = tx.from.toLowerCase() === address.toLowerCase();
18
- const timestamp = parseInt(tx.timeStamp) * 1000;
19
- const amount = new TokenUnit(tx.value, Number(tx.tokenDecimal), tx.tokenSymbol);
20
- const amountDisplayValue = amount.toDisplay();
21
- const { from, to, gasPrice, gasUsed, hash, tokenDecimal, tokenName, tokenSymbol } = tx;
22
- const txType = isSender ? TransactionType.SEND : TransactionType.RECEIVE;
23
- const explorerLink = getExplorerAddressByNetwork(explorerUrl, hash);
24
-
25
- return {
26
- isIncoming: !isSender,
27
- isOutgoing: isSender,
28
- isContractCall: false,
29
- timestamp,
30
- hash,
31
- isSender,
32
- from,
33
- to,
34
- tokens: [
35
- {
36
- decimal: tokenDecimal,
37
- name: tokenName,
38
- symbol: tokenSymbol,
39
- type: TokenType.ERC20,
40
- amount: amountDisplayValue,
41
- },
42
- ],
43
- gasUsed,
44
- gasPrice,
45
- chainId: chainId.toString(),
46
- txType,
47
- explorerLink,
48
- };
49
- }
@@ -1,57 +0,0 @@
1
- import { TokenType, TransactionType } from '@avalabs/vm-module-types';
2
- import { convertTransactionNormal } from './convert-transaction-normal';
3
- import type { NormalTx } from '@avalabs/etherscan-sdk';
4
-
5
- describe('convertTransactionNormal ', () => {
6
- it('correctly converts normal transaction data', () => {
7
- const tx = {
8
- from: '0xSenderAddress',
9
- to: '0xReceiverAddress',
10
- timeStamp: '1625794800', // Unix timestamp in seconds
11
- value: '1000000000000000000', // 1 token in wei
12
- gasPrice: '20000000000', // in wei
13
- gasUsed: '21000',
14
- hash: '0xTransactionHash',
15
- input: '0x', // Empty input for a non-contract call
16
- } as NormalTx;
17
-
18
- const networkToken = {
19
- name: 'Ethereum',
20
- symbol: 'ETH',
21
- decimals: 18,
22
- };
23
-
24
- const address = '0xSenderAddress';
25
- const explorerUrl = 'https://explorer.example.com';
26
- const chainId = 1;
27
-
28
- const expected = {
29
- isIncoming: false,
30
- isOutgoing: true,
31
- isContractCall: false,
32
- timestamp: 1625794800000, // Converted timestamp in milliseconds
33
- hash: '0xTransactionHash',
34
- isSender: true,
35
- from: '0xSenderAddress',
36
- to: '0xReceiverAddress',
37
- tokens: [
38
- {
39
- decimal: '18',
40
- name: 'Ethereum',
41
- symbol: 'ETH',
42
- amount: '1',
43
- type: TokenType.NATIVE,
44
- },
45
- ],
46
- gasUsed: '21000',
47
- gasPrice: '20000000000',
48
- chainId: '1',
49
- txType: TransactionType.SEND,
50
- explorerLink: 'https://explorer.example.com/tx/0xTransactionHash', // Assuming this is how the explorer link is formatted
51
- };
52
-
53
- const result = convertTransactionNormal({ tx, networkToken, chainId, explorerUrl, address });
54
-
55
- expect(result).toEqual(expected);
56
- });
57
- });
@@ -1,57 +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 { TokenUnit } from '@avalabs/utils-sdk';
4
- import { getExplorerAddressByNetwork } from '../../utils/get-explorer-address-by-network';
5
-
6
- export const convertTransactionNormal = ({
7
- tx,
8
- networkToken,
9
- chainId,
10
- explorerUrl,
11
- address,
12
- }: {
13
- tx: NormalTx;
14
- networkToken: NetworkToken;
15
- chainId: number;
16
- explorerUrl: string;
17
- address: string;
18
- }): Transaction => {
19
- const isSender = tx.from.toLowerCase() === address.toLowerCase();
20
- const timestamp = parseInt(tx.timeStamp) * 1000;
21
- const decimals = networkToken.decimals;
22
- const amount = new TokenUnit(tx.value, networkToken.decimals, networkToken.symbol);
23
- const amountDisplayValue = amount.toDisplay();
24
- const txType = isSender ? TransactionType.SEND : TransactionType.RECEIVE;
25
-
26
- const { from, to, gasPrice, gasUsed, hash } = tx;
27
- const explorerLink = getExplorerAddressByNetwork(explorerUrl, hash);
28
-
29
- return {
30
- isIncoming: !isSender,
31
- isOutgoing: isSender,
32
- isContractCall: isContractCall(tx),
33
- timestamp,
34
- hash,
35
- isSender,
36
- from,
37
- to,
38
- tokens: [
39
- {
40
- decimal: decimals.toString(),
41
- name: networkToken.name,
42
- symbol: networkToken.symbol,
43
- amount: amountDisplayValue,
44
- type: TokenType.NATIVE,
45
- },
46
- ],
47
- gasUsed,
48
- gasPrice,
49
- chainId: chainId.toString(),
50
- txType,
51
- explorerLink,
52
- };
53
- };
54
-
55
- function isContractCall(tx: NormalTx): boolean {
56
- return tx.input !== '0x';
57
- }
@@ -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,106 +0,0 @@
1
- import type { TransactionDetails } from '@avalabs/glacier-sdk';
2
- import { TokenUnit } from '@avalabs/utils-sdk';
3
- import type { TxToken, NetworkToken } from '@avalabs/vm-module-types';
4
- import { TokenType } from '@avalabs/vm-module-types';
5
- import { resolve } from '../../utils/resolve';
6
- import { getNftMetadata } from './get-nft-metadata';
7
- import { getSmallImageForNFT } from '../../utils/get-small-image-for-nft';
8
- import { ipfsResolverWithFallback } from '../../utils/ipfs-resolver-with-fallback';
9
-
10
- export const getTokens = async (
11
- { nativeTransaction, erc20Transfers, erc721Transfers, erc1155Transfers }: TransactionDetails,
12
- networkToken: NetworkToken,
13
- ): Promise<TxToken[]> => {
14
- const result: TxToken[] = [];
15
-
16
- if (nativeTransaction.value !== '0') {
17
- const decimal = networkToken.decimals;
18
- const amount = new TokenUnit(nativeTransaction.value, networkToken.decimals, networkToken.symbol);
19
- const amountDisplayValue = amount.toDisplay();
20
- result.push({
21
- decimal: decimal.toString(),
22
- name: networkToken.name,
23
- symbol: networkToken.symbol,
24
- amount: amountDisplayValue,
25
- from: nativeTransaction.from,
26
- to: nativeTransaction.to,
27
- type: TokenType.NATIVE,
28
- });
29
- }
30
-
31
- erc20Transfers?.forEach((erc20Transfer) => {
32
- const decimals = erc20Transfer.erc20Token.decimals;
33
- const amount = new TokenUnit(erc20Transfer.value, decimals, erc20Transfer.erc20Token.symbol);
34
- const amountDisplayValue = amount.toDisplay();
35
-
36
- result.push({
37
- decimal: decimals.toString(),
38
- name: erc20Transfer.erc20Token.name,
39
- symbol: erc20Transfer.erc20Token.symbol,
40
- amount: amountDisplayValue,
41
- from: erc20Transfer.from,
42
- to: erc20Transfer.to,
43
- imageUri: erc20Transfer.erc20Token.logoUri,
44
- type: TokenType.ERC20,
45
- });
46
- });
47
-
48
- if (erc721Transfers) {
49
- await Promise.allSettled(
50
- erc721Transfers.map(async (erc721Transfer) => {
51
- const token = erc721Transfer.erc721Token;
52
- const imageUri = await getImageUri(token.tokenUri, token.metadata.imageUri);
53
-
54
- result.push({
55
- name: erc721Transfer.erc721Token.name,
56
- symbol: erc721Transfer.erc721Token.symbol,
57
- amount: '1',
58
- imageUri,
59
- from: erc721Transfer.from,
60
- to: erc721Transfer.to,
61
- collectableTokenId: erc721Transfer.erc721Token.tokenId,
62
- type: TokenType.ERC721,
63
- });
64
- }),
65
- );
66
- }
67
-
68
- if (erc1155Transfers) {
69
- await Promise.allSettled(
70
- erc1155Transfers.map(async (erc1155Transfer) => {
71
- const token = erc1155Transfer.erc1155Token;
72
- const imageUri = await getImageUri(token.tokenUri, token.metadata.imageUri);
73
-
74
- result.push({
75
- name: erc1155Transfer.erc1155Token.metadata.name ?? '',
76
- symbol: erc1155Transfer.erc1155Token.metadata.symbol ?? '',
77
- amount: erc1155Transfer.value,
78
- imageUri,
79
- from: erc1155Transfer.from,
80
- to: erc1155Transfer.to,
81
- collectableTokenId: erc1155Transfer.erc1155Token.tokenId,
82
- type: TokenType.ERC1155,
83
- });
84
- }),
85
- );
86
- }
87
-
88
- return result;
89
- };
90
-
91
- const getImageUri = async (tokenUri: string, imageUri?: string): Promise<string> => {
92
- if (imageUri) {
93
- if (imageUri.startsWith('ipfs://')) {
94
- return ipfsResolverWithFallback(imageUri);
95
- } else {
96
- return imageUri;
97
- }
98
- } else {
99
- const [metadata, error] = await resolve(getNftMetadata(tokenUri));
100
- if (error) {
101
- return '';
102
- } else {
103
- return metadata.image ? getSmallImageForNFT(metadata.image) : '';
104
- }
105
- }
106
- };