@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,23 +0,0 @@
1
- import type { Network, RpcRequest } from '@avalabs/vm-module-types';
2
- import { rpcErrors } from '@metamask/rpc-errors';
3
- import { getProvider } from '../../utils/get-provider';
4
-
5
- export const forwardToRpcNode = async (request: RpcRequest, network: Network) => {
6
- try {
7
- const provider = getProvider({
8
- chainId: network.chainId,
9
- chainName: network.chainName,
10
- rpcUrl: network.rpcUrl,
11
- multiContractAddress: network.utilityAddresses?.multicall,
12
- pollingInterval: 1000,
13
- });
14
-
15
- const response = await provider.send(request.method, request.params as unknown[]);
16
- return { result: response };
17
- } catch (error) {
18
- // extracting the error message based on the error object structure from ethers lib
19
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
- const message = (error as any).info?.error?.message || (error as any).error?.message || (error as Error).message;
21
- return { error: rpcErrors.internal(message) };
22
- }
23
- };
@@ -1,78 +0,0 @@
1
- import { BN } from 'bn.js';
2
- import { getErc20Balances } from './get-erc20-balances';
3
- import { ethers } from 'ethers';
4
- import { TokenType } from '@avalabs/vm-module-types';
5
-
6
- describe('get-erc20-balances', () => {
7
- it('should return erc20 token balances', async () => {
8
- jest.spyOn(ethers, 'Contract').mockImplementation(() => {
9
- return {
10
- balanceOf: jest.fn().mockResolvedValue(new BN('1000000000000000000')),
11
- } as never;
12
- });
13
-
14
- const balance = getErc20Balances({
15
- tokens: [
16
- {
17
- address: '0x123',
18
- name: 'Ethereum',
19
- symbol: 'ETH',
20
- decimals: 18,
21
- logoUri: 'https://example.com/logo.png',
22
- type: TokenType.ERC20,
23
- },
24
- ],
25
- provider: {
26
- getBalance: jest.fn().mockResolvedValue(new BN('1000000000000000000')),
27
- } as never,
28
- tokenService: {
29
- getPricesByAddresses: jest.fn().mockResolvedValue({
30
- '123': {
31
- USD: {
32
- price: 1000,
33
- marketCap: 0,
34
- vol24: 0,
35
- change24: 0,
36
- },
37
- },
38
- }),
39
- } as never,
40
- address: '0x123',
41
- currency: 'USD',
42
- network: {
43
- pricingProviders: {
44
- coingecko: {
45
- nativeTokenId: '123',
46
- assetPlatformId: '123',
47
- },
48
- },
49
- networkToken: {
50
- address: '0x123',
51
- name: 'Ethereum',
52
- symbol: 'ETH',
53
- decimals: 18,
54
- logoUri: 'https://example.com/logo.png',
55
- },
56
- } as never,
57
- });
58
-
59
- expect(balance).resolves.toEqual({
60
- '0x123': {
61
- address: '0x123',
62
- name: 'Ethereum',
63
- symbol: 'ETH',
64
- decimals: 18,
65
- logoUri: 'https://example.com/logo.png',
66
- balance: new BN('1000000000000000000'),
67
- balanceCurrencyDisplayValue: '1000.00',
68
- balanceDisplayValue: '1',
69
- balanceInCurrency: 1000,
70
- priceInCurrency: 1000,
71
- type: 'ERC20',
72
- change24: 0,
73
- marketCap: 0,
74
- vol24: 0,
75
- },
76
- });
77
- });
78
- });
@@ -1,85 +0,0 @@
1
- import { numberToBN, bnToBig, balanceToDisplayValue } from '@avalabs/utils-sdk';
2
- import { TokenType, type ERC20Token, type Network, 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
- export const getErc20Balances = async ({
10
- provider,
11
- tokenService,
12
- address: userAddress,
13
- currency,
14
- tokens,
15
- network,
16
- }: {
17
- provider: Provider;
18
- tokenService: TokenService;
19
- address: string;
20
- currency: string;
21
- tokens: ERC20Token[];
22
- network: Network;
23
- }): Promise<Record<string, TokenWithBalance>> => {
24
- const coingeckoPlatformId = network.pricingProviders?.coingecko.assetPlatformId;
25
- const coingeckoTokenId = network.pricingProviders?.coingecko.nativeTokenId;
26
- const tokenAddresses = tokens.map((token) => token.address);
27
-
28
- const tokensBalances = await Promise.allSettled(
29
- tokens.map(async (token) => {
30
- const contract = new ethers.Contract(token.address, ERC20.abi, provider);
31
- const balanceBig = await contract.balanceOf?.(userAddress);
32
- const balance = new BN(balanceBig) || numberToBN(0, token.decimals);
33
-
34
- const tokenWithBalance = {
35
- ...token,
36
- balance,
37
- };
38
-
39
- return tokenWithBalance;
40
- }),
41
- ).then((res) => {
42
- return res.reduce<(ERC20Token & { balance: BN })[]>((acc, result) => {
43
- return result.status === 'fulfilled' && !result.value.balance.isZero() ? [...acc, result.value] : acc;
44
- }, []);
45
- });
46
-
47
- if (!tokensBalances.length) return {};
48
-
49
- const simplePriceResponse =
50
- (coingeckoPlatformId &&
51
- (await tokenService.getPricesByAddresses(tokenAddresses, coingeckoPlatformId, currency as VsCurrencyType))) ||
52
- {};
53
-
54
- return tokensBalances.reduce(
55
- (acc, token) => {
56
- const priceInCurrency = simplePriceResponse?.[coingeckoTokenId ?? '']?.[currency]?.price ?? undefined;
57
- const marketCap = simplePriceResponse?.[coingeckoTokenId ?? '']?.[currency]?.marketCap ?? undefined;
58
- const vol24 = simplePriceResponse?.[coingeckoTokenId ?? '']?.[currency]?.vol24 ?? undefined;
59
- const change24 = simplePriceResponse?.[coingeckoTokenId ?? '']?.[currency]?.change24 ?? undefined;
60
-
61
- const balanceInCurrency = priceInCurrency
62
- ? bnToBig(token.balance, token.decimals).mul(priceInCurrency).toNumber()
63
- : undefined;
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
- };
@@ -1,97 +0,0 @@
1
- import { BN } from 'bn.js';
2
- import { getNativeTokenBalances } from './get-native-token-balances';
3
-
4
- describe('get-native-token-balances', () => {
5
- it('should return native token balances', async () => {
6
- const balance = getNativeTokenBalances({
7
- provider: {
8
- getBalance: jest.fn().mockResolvedValue(new BN('1000000000000000000')),
9
- } as never,
10
- tokenService: {
11
- getSimplePrice: jest.fn().mockResolvedValue({
12
- '123': {
13
- USD: {
14
- price: 1000,
15
- marketCap: 0,
16
- vol24: 0,
17
- change24: 0,
18
- },
19
- },
20
- }),
21
- } as never,
22
- address: '0x123',
23
- currency: 'USD',
24
- network: {
25
- pricingProviders: {
26
- coingecko: {
27
- nativeTokenId: '123',
28
- },
29
- },
30
- networkToken: {
31
- address: '0x123',
32
- name: 'Ethereum',
33
- symbol: 'ETH',
34
- decimals: 18,
35
- logoUri: 'https://example.com/logo.png',
36
- },
37
- } as never,
38
- });
39
-
40
- expect(balance).resolves.toEqual({
41
- address: '0x123',
42
- name: 'Ethereum',
43
- symbol: 'ETH',
44
- decimals: 18,
45
- logoUri: 'https://example.com/logo.png',
46
- balance: new BN('1000000000000000000'),
47
- balanceCurrencyDisplayValue: '1000.00',
48
- balanceDisplayValue: '1',
49
- balanceInCurrency: 1000,
50
- priceInCurrency: 1000,
51
- coingeckoId: '123',
52
- type: 'NATIVE',
53
- marketCap: 0,
54
- vol24: 0,
55
- change24: 0,
56
- });
57
- });
58
-
59
- it('should return native token object without balance data', async () => {
60
- const balance = getNativeTokenBalances({
61
- provider: {
62
- getBalance: jest.fn().mockResolvedValue(new BN('0')),
63
- } as never,
64
- tokenService: {
65
- getSimplePrice: jest.fn().mockResolvedValue({}),
66
- } as never,
67
- address: '0x123',
68
- currency: 'USD',
69
- network: {
70
- pricingProviders: {
71
- coingecko: {
72
- nativeTokenId: '123',
73
- },
74
- },
75
- networkToken: {
76
- address: '0x123',
77
- name: 'Ethereum',
78
- symbol: 'ETH',
79
- decimals: 18,
80
- logoUri: 'https://example.com/logo.png',
81
- },
82
- } as never,
83
- });
84
- expect(balance).resolves.toEqual({
85
- address: '0x123',
86
- name: 'Ethereum',
87
- symbol: 'ETH',
88
- decimals: 18,
89
- logoUri: 'https://example.com/logo.png',
90
- balance: new BN('0'),
91
- balanceCurrencyDisplayValue: undefined,
92
- balanceDisplayValue: '0',
93
- coingeckoId: '123',
94
- type: 'NATIVE',
95
- });
96
- });
97
- });
@@ -1,56 +0,0 @@
1
- import { balanceToDisplayValue, bigToBN, bigintToBig, bnToBig } from '@avalabs/utils-sdk';
2
- import { TokenType, type Network, type NetworkTokenWithBalance } from '@avalabs/vm-module-types';
3
- import type { VsCurrencyType } from '@avalabs/coingecko-sdk';
4
- import { TokenService } from '@internal/utils';
5
- import type { Provider } from 'ethers';
6
-
7
- export const getNativeTokenBalances = async ({
8
- provider,
9
- tokenService,
10
- address,
11
- currency,
12
- network,
13
- }: {
14
- provider: Provider;
15
- tokenService: TokenService;
16
- address: string;
17
- currency: string;
18
- network: Network;
19
- }): Promise<NetworkTokenWithBalance> => {
20
- const coingeckoTokenId = network.pricingProviders?.coingecko.nativeTokenId;
21
- const networkToken = network.networkToken;
22
- const simplePriceResponse = coingeckoTokenId
23
- ? await tokenService.getSimplePrice({
24
- coinIds: [coingeckoTokenId],
25
- currencies: [currency] as VsCurrencyType[],
26
- })
27
- : {};
28
-
29
- const priceInCurrency = simplePriceResponse?.[coingeckoTokenId ?? '']?.[currency]?.price ?? undefined;
30
- const marketCap = simplePriceResponse?.[coingeckoTokenId ?? '']?.[currency]?.marketCap ?? undefined;
31
- const vol24 = simplePriceResponse?.[coingeckoTokenId ?? '']?.[currency]?.vol24 ?? undefined;
32
- const change24 = simplePriceResponse?.[coingeckoTokenId ?? '']?.[currency]?.change24 ?? undefined;
33
-
34
- const balanceBigint = await provider.getBalance(address);
35
- const balaceBig = bigintToBig(balanceBigint, networkToken.decimals);
36
- const balance = bigToBN(balaceBig, networkToken.decimals);
37
- const balanceDisplayValue = balanceToDisplayValue(balance, networkToken.decimals);
38
- const balanceInCurrency = priceInCurrency
39
- ? bnToBig(balance, networkToken.decimals).mul(priceInCurrency).toNumber()
40
- : undefined;
41
- const balanceCurrencyDisplayValue = balanceInCurrency?.toFixed(2);
42
-
43
- return {
44
- ...networkToken,
45
- coingeckoId: coingeckoTokenId ?? '',
46
- type: TokenType.NATIVE,
47
- balance,
48
- balanceDisplayValue,
49
- balanceInCurrency,
50
- balanceCurrencyDisplayValue,
51
- priceInCurrency,
52
- marketCap,
53
- vol24,
54
- change24,
55
- };
56
- };
@@ -1,249 +0,0 @@
1
- import { NetworkVMType, TokenType } from '@avalabs/vm-module-types';
2
- import { getBalances } from './get-balances';
3
- import * as GlacierNativeToken from './glacier-balance-service/get-native-token-balances';
4
- import { BN } from 'bn.js';
5
- import * as GlacierERC20Token from './glacier-balance-service/get-erc20-balances';
6
- import * as EvmNativeToken from './evm-balance-service/get-native-token-balances';
7
- import * as EvmERC20Token from './evm-balance-service/get-erc20-balances';
8
- import type { EvmGlacierService } from '../../services/glacier-service/glacier-service';
9
-
10
- describe('get-balances', () => {
11
- it('should get balances from glacier', async () => {
12
- const mockGlacierService: EvmGlacierService = {
13
- ...expect.any(Object),
14
- isNetworkSupported: () => true,
15
- isHealthy: () => true,
16
- };
17
- jest.spyOn(GlacierNativeToken, 'getNativeTokenBalances').mockImplementationOnce(async () => {
18
- return {
19
- name: 'Ether',
20
- symbol: 'ETH',
21
- decimals: 18,
22
- type: TokenType.NATIVE,
23
- logoUri:
24
- 'https://images.ctfassets.net/gcj8jwzm6086/6l56QLVZmvacuBfjHBTThP/791d743dd2c526692562780c2325fedf/eth-circle__1_.svg',
25
- balance: new BN(1),
26
- balanceDisplayValue: '1',
27
- balanceInCurrency: 1,
28
- balanceCurrencyDisplayValue: '1',
29
- priceInCurrency: 1,
30
- marketCap: 0,
31
- vol24: 0,
32
- change24: 0,
33
- coingeckoId: '',
34
- };
35
- });
36
-
37
- jest.spyOn(GlacierERC20Token, 'getErc20Balances').mockImplementationOnce(async () => {
38
- return {
39
- '0x123': {
40
- chainId: 1,
41
- address: '0x123',
42
- name: 'DAI',
43
- symbol: 'DAI',
44
- decimals: 18,
45
- logoUri: 'https://s3.us-east-2.amazonaws.com/nomics-api/static/images/currencies/dai.svg',
46
- balance: new BN(1),
47
- balanceCurrencyDisplayValue: '1',
48
- balanceDisplayValue: '1',
49
- balanceInCurrency: 1,
50
- priceInCurrency: 1,
51
- type: TokenType.ERC20,
52
- change24: 0,
53
- marketCap: 0,
54
- vol24: 0,
55
- },
56
- };
57
- });
58
- const balances = await getBalances({
59
- addresses: ['0x123'],
60
- currency: 'USD',
61
- network: {
62
- chainId: 1,
63
- chainName: 'Ethereum',
64
- isTestnet: false,
65
- networkToken: {
66
- name: 'Ether',
67
- decimals: 18,
68
- symbol: 'ETH',
69
- description:
70
- 'Ether is used to pay for transaction fees and computational services on Etherum. Users can send Ether to other users, and developers can write smart contracts that receive, hold, and send Ether.',
71
- logoUri:
72
- 'https://images.ctfassets.net/gcj8jwzm6086/6l56QLVZmvacuBfjHBTThP/791d743dd2c526692562780c2325fedf/eth-circle__1_.svg',
73
- },
74
- pricingProviders: { coingecko: { nativeTokenId: 'ethereum', assetPlatformId: 'ethereum' } },
75
- rpcUrl: 'https://proxy-api.avax.network/proxy/infura/mainnet',
76
- utilityAddresses: { multicall: '0x5ba1e12693dc8f9c48aad8770482f4739beed696' },
77
- vmName: NetworkVMType.EVM,
78
- },
79
- proxyApiUrl: 'proxyApiUrl',
80
- glacierService: mockGlacierService,
81
- });
82
- expect(balances).toEqual({
83
- '0x123': {
84
- '0x123': {
85
- address: '0x123',
86
- balance: new BN(1),
87
- balanceCurrencyDisplayValue: '1',
88
- balanceDisplayValue: '1',
89
- balanceInCurrency: 1,
90
- chainId: 1,
91
- change24: 0,
92
- decimals: 18,
93
- logoUri: 'https://s3.us-east-2.amazonaws.com/nomics-api/static/images/currencies/dai.svg',
94
- marketCap: 0,
95
- name: 'DAI',
96
- priceInCurrency: 1,
97
- symbol: 'DAI',
98
- type: 'ERC20',
99
- vol24: 0,
100
- },
101
- ETH: {
102
- balance: new BN(1),
103
- balanceCurrencyDisplayValue: '1',
104
- balanceDisplayValue: '1',
105
- balanceInCurrency: 1,
106
- change24: 0,
107
- coingeckoId: '',
108
- decimals: 18,
109
- logoUri:
110
- 'https://images.ctfassets.net/gcj8jwzm6086/6l56QLVZmvacuBfjHBTThP/791d743dd2c526692562780c2325fedf/eth-circle__1_.svg',
111
- marketCap: 0,
112
- name: 'Ether',
113
- priceInCurrency: 1,
114
- symbol: 'ETH',
115
- type: 'NATIVE',
116
- vol24: 0,
117
- },
118
- },
119
- });
120
- });
121
-
122
- it('should get balances from evm', async () => {
123
- const mockGlacierService: EvmGlacierService = {
124
- ...expect.any(Object),
125
- isNetworkSupported: () => false,
126
- isHealthy: () => false,
127
- };
128
- global.fetch = jest.fn(() =>
129
- Promise.resolve({
130
- ok: true,
131
- json: () =>
132
- Promise.resolve([
133
- {
134
- chainId: 2,
135
- address: '0x456',
136
- name: 'DAI2',
137
- symbol: 'DAI2',
138
- decimals: 18,
139
- logoUri: 'https://s3.us-east-2.amazonaws.com/nomics-api/static/images/currencies/dai.svg',
140
- type: TokenType.ERC20,
141
- },
142
- ]),
143
- }),
144
- ) as jest.Mock;
145
- jest.spyOn(EvmNativeToken, 'getNativeTokenBalances').mockImplementationOnce(async () => {
146
- return {
147
- name: 'Ether2',
148
- symbol: 'ETH2',
149
- decimals: 18,
150
- type: TokenType.NATIVE,
151
- logoUri:
152
- 'https://images.ctfassets.net/gcj8jwzm6086/6l56QLVZmvacuBfjHBTThP/791d743dd2c526692562780c2325fedf/eth-circle__1_.svg',
153
- balance: new BN(1),
154
- balanceDisplayValue: '1',
155
- balanceInCurrency: 1,
156
- balanceCurrencyDisplayValue: '1',
157
- priceInCurrency: 1,
158
- marketCap: 0,
159
- vol24: 0,
160
- change24: 0,
161
- coingeckoId: '',
162
- };
163
- });
164
-
165
- jest.spyOn(EvmERC20Token, 'getErc20Balances').mockImplementationOnce(async () => {
166
- return {
167
- '0x456': {
168
- chainId: 2,
169
- address: '0x456',
170
- name: 'DAI2',
171
- symbol: 'DAI2',
172
- decimals: 18,
173
- logoUri: 'https://s3.us-east-2.amazonaws.com/nomics-api/static/images/currencies/dai.svg',
174
- balance: new BN(1),
175
- balanceCurrencyDisplayValue: '1',
176
- balanceDisplayValue: '1',
177
- balanceInCurrency: 1,
178
- priceInCurrency: 1,
179
- type: TokenType.ERC20,
180
- change24: 0,
181
- marketCap: 0,
182
- vol24: 0,
183
- },
184
- };
185
- });
186
- const balances = await getBalances({
187
- addresses: ['0x456'],
188
- currency: 'USD',
189
- network: {
190
- chainId: 2,
191
- chainName: '2',
192
- isTestnet: false,
193
- networkToken: {
194
- name: 'Ether2',
195
- decimals: 18,
196
- symbol: 'ETH2',
197
- description:
198
- 'Ether is used to pay for transaction fees and computational services on Etherum. Users can send Ether to other users, and developers can write smart contracts that receive, hold, and send Ether.',
199
- logoUri:
200
- 'https://images.ctfassets.net/gcj8jwzm6086/6l56QLVZmvacuBfjHBTThP/791d743dd2c526692562780c2325fedf/eth-circle__1_.svg',
201
- },
202
- pricingProviders: { coingecko: { nativeTokenId: 'ethereum', assetPlatformId: 'ethereum' } },
203
- rpcUrl: 'https://proxy-api.avax.network/proxy/infura/mainnet',
204
- utilityAddresses: { multicall: '0x5ba1e12693dc8f9c48aad8770482f4739beed696' },
205
- vmName: NetworkVMType.EVM,
206
- },
207
- proxyApiUrl: 'proxyApiUrl',
208
- glacierService: mockGlacierService,
209
- });
210
- expect(balances).toEqual({
211
- '0x456': {
212
- '0x456': {
213
- address: '0x456',
214
- balance: new BN(1),
215
- balanceCurrencyDisplayValue: '1',
216
- balanceDisplayValue: '1',
217
- balanceInCurrency: 1,
218
- chainId: 2,
219
- change24: 0,
220
- decimals: 18,
221
- logoUri: 'https://s3.us-east-2.amazonaws.com/nomics-api/static/images/currencies/dai.svg',
222
- marketCap: 0,
223
- name: 'DAI2',
224
- priceInCurrency: 1,
225
- symbol: 'DAI2',
226
- type: 'ERC20',
227
- vol24: 0,
228
- },
229
- ETH2: {
230
- balance: new BN(1),
231
- balanceCurrencyDisplayValue: '1',
232
- balanceDisplayValue: '1',
233
- balanceInCurrency: 1,
234
- change24: 0,
235
- coingeckoId: '',
236
- decimals: 18,
237
- logoUri:
238
- 'https://images.ctfassets.net/gcj8jwzm6086/6l56QLVZmvacuBfjHBTThP/791d743dd2c526692562780c2325fedf/eth-circle__1_.svg',
239
- marketCap: 0,
240
- name: 'Ether2',
241
- priceInCurrency: 1,
242
- symbol: 'ETH2',
243
- type: 'NATIVE',
244
- vol24: 0,
245
- },
246
- },
247
- });
248
- });
249
- });