@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
package/src/types.ts DELETED
@@ -1,25 +0,0 @@
1
- import { TransactionType } from '@avalabs/vm-module-types';
2
-
3
- export const NonContractCallTypes = [TransactionType.SEND, TransactionType.RECEIVE, TransactionType.TRANSFER];
4
-
5
- export type TransactionParams = {
6
- from: string;
7
- to: string;
8
- data?: string;
9
- value?: string;
10
- gas?: string;
11
- gasPrice?: string;
12
- maxFeePerGas?: string;
13
- maxPriorityFeePerGas?: string;
14
- nonce?: string;
15
- chainId?: string;
16
- };
17
-
18
- export enum ERC20TransactionType {
19
- TOTAL_SUPPLY = 'totalSupply',
20
- BALANCE_OF = 'balanceOf',
21
- TRANSFER = 'transfer',
22
- TRANSFER_FROM = 'transferFrom',
23
- APPROVE = 'approve',
24
- ALLOWANCE = 'allowance',
25
- }
@@ -1,27 +0,0 @@
1
- import { JsonRpcBatchInternal } from '@avalabs/wallets-sdk';
2
- import type { BigNumberish } from 'ethers';
3
-
4
- export const estimateGasLimit = async ({
5
- transactionParams: { from, to, data, value },
6
- provider,
7
- }: {
8
- transactionParams: {
9
- from: string;
10
- to: string;
11
- data?: string;
12
- value?: BigNumberish;
13
- };
14
- provider: JsonRpcBatchInternal;
15
- }): Promise<number> => {
16
- const nonce = await provider.getTransactionCount(from);
17
-
18
- return Number(
19
- await provider.estimateGas({
20
- from,
21
- to,
22
- nonce,
23
- data,
24
- value,
25
- }),
26
- );
27
- };
@@ -1,12 +0,0 @@
1
- import type { Caip2ChainId } from '@avalabs/vm-module-types';
2
- import { rpcErrors } from '@metamask/rpc-errors';
3
-
4
- export const getChainId = (caip2ChainId: Caip2ChainId): number => {
5
- const chainId = caip2ChainId.split(':')[1];
6
-
7
- if (!chainId || isNaN(Number(chainId))) {
8
- throw rpcErrors.invalidParams('Invalid chainId');
9
- }
10
-
11
- return Number(chainId);
12
- };
@@ -1,11 +0,0 @@
1
- import { JsonRpcBatchInternal } from '@avalabs/wallets-sdk';
2
-
3
- export const getNonce = async ({
4
- from,
5
- provider,
6
- }: {
7
- from: string;
8
- provider: JsonRpcBatchInternal;
9
- }): Promise<number> => {
10
- return provider.getTransactionCount(from);
11
- };
@@ -1,46 +0,0 @@
1
- import { JsonRpcBatchInternal } from '@avalabs/wallets-sdk';
2
- import { Network as EVMNetwork } from 'ethers';
3
-
4
- // this key is only needed in development to bypass rate limit
5
- // it should never be used in production
6
- const GLACIER_API_KEY = process.env.GLACIER_API_KEY;
7
-
8
- type ProviderParams = {
9
- chainId: number;
10
- chainName: string;
11
- rpcUrl: string;
12
- multiContractAddress?: string;
13
- pollingInterval?: number;
14
- };
15
-
16
- export const getProvider = (params: ProviderParams): JsonRpcBatchInternal => {
17
- const { chainId, chainName, rpcUrl, multiContractAddress, pollingInterval = 2000 } = params;
18
-
19
- const provider = new JsonRpcBatchInternal(
20
- { maxCalls: 40, multiContractAddress },
21
- addGlacierAPIKeyIfNeeded(rpcUrl, GLACIER_API_KEY),
22
- new EVMNetwork(chainName, chainId),
23
- );
24
-
25
- provider.pollingInterval = pollingInterval;
26
-
27
- return provider;
28
- };
29
-
30
- // RPC urls returned in the token list are always using the production URL
31
- const knownHosts = ['glacier-api.avax.network', 'proxy-api.avax.network'];
32
-
33
- /**
34
- * Glacier needs an API key for development, this adds the key if needed.
35
- */
36
- export function addGlacierAPIKeyIfNeeded(url: string, glacierApiKey?: string): string {
37
- const urlObj = new URL(url);
38
-
39
- if (glacierApiKey && knownHosts.includes(urlObj.hostname)) {
40
- const search_params = urlObj.searchParams; // copy, does not update the URL
41
- search_params.set('token', glacierApiKey);
42
- urlObj.search = search_params.toString();
43
- return urlObj.toString();
44
- }
45
- return url;
46
- }
@@ -1,35 +0,0 @@
1
- import { Interface } from 'ethers';
2
- import ERC20 from '@openzeppelin/contracts/build/contracts/ERC20.json';
3
- import { ERC20TransactionType } from '../types';
4
-
5
- export const parseERC20TransactionType = (transaction: {
6
- data?: string;
7
- value?: string;
8
- }): ERC20TransactionType | undefined => {
9
- if (!transaction.data) {
10
- return undefined;
11
- }
12
-
13
- try {
14
- const contractInterface = new Interface(ERC20.abi);
15
-
16
- const description = contractInterface.parseTransaction({
17
- data: transaction.data,
18
- value: transaction.value,
19
- });
20
-
21
- const functionName = description?.name ?? description?.fragment?.name;
22
-
23
- if (functionName && isERC20TransactionType(functionName)) {
24
- return functionName;
25
- }
26
-
27
- return undefined;
28
- } catch (e) {
29
- return undefined;
30
- }
31
- };
32
-
33
- function isERC20TransactionType(value: string): value is ERC20TransactionType {
34
- return Object.values(ERC20TransactionType).includes(value as ERC20TransactionType);
35
- }
@@ -1,105 +0,0 @@
1
- import Blockaid from '@blockaid/client';
2
- import { processBalanceChange } from './process-transaction-simulation';
3
-
4
- jest.mock('@blockaid/client', () => {
5
- return jest.fn().mockImplementation(() => {
6
- return {};
7
- });
8
- });
9
-
10
- describe('processBalanceChange', () => {
11
- it('should sort asset diffs correctly within ins and outs', () => {
12
- const assetDiffs: Blockaid.AssetDiff[] = [
13
- {
14
- asset: {
15
- type: 'ERC20',
16
- address: '0xTokenAddress1',
17
- name: 'TokenName1',
18
- symbol: 'TKN1',
19
- decimals: 18,
20
- logo_url: 'logo_url1',
21
- },
22
- in: [
23
- { value: '1', usd_price: '1', raw_value: '0x1' },
24
- { value: '2', usd_price: '2', raw_value: '0x2' },
25
- ],
26
- out: [
27
- { value: '3', usd_price: '3', raw_value: '0x3' },
28
- { value: '1', usd_price: '1', raw_value: '0x1' },
29
- ],
30
- },
31
- {
32
- asset: {
33
- type: 'ERC20',
34
- address: '0xTokenAddress2',
35
- name: 'TokenName2',
36
- symbol: 'TKN2',
37
- decimals: 18,
38
- logo_url: 'logo_url2',
39
- },
40
- in: [{ value: '4', usd_price: '4', raw_value: '0x4' }],
41
- out: [{ value: '5', usd_price: '5', raw_value: '0x5' }],
42
- },
43
- ];
44
-
45
- const result = processBalanceChange(assetDiffs);
46
-
47
- // Verify sorting logic for 'ins'
48
- expect(result?.ins).toEqual([
49
- {
50
- token: {
51
- type: 'ERC20',
52
- address: '0xTokenAddress2',
53
- name: 'TokenName2',
54
- symbol: 'TKN2',
55
- decimals: 18,
56
- logoUri: 'logo_url2',
57
- },
58
- items: [{ displayValue: '4', usdPrice: '4' }],
59
- },
60
- {
61
- token: {
62
- type: 'ERC20',
63
- address: '0xTokenAddress1',
64
- name: 'TokenName1',
65
- symbol: 'TKN1',
66
- decimals: 18,
67
- logoUri: 'logo_url1',
68
- },
69
- items: [
70
- { displayValue: '1', usdPrice: '1' },
71
- { displayValue: '2', usdPrice: '2' },
72
- ],
73
- },
74
- ]);
75
-
76
- // Verify sorting logic for 'outs'
77
- expect(result?.outs).toEqual([
78
- {
79
- token: {
80
- type: 'ERC20',
81
- address: '0xTokenAddress2',
82
- name: 'TokenName2',
83
- symbol: 'TKN2',
84
- decimals: 18,
85
- logoUri: 'logo_url2',
86
- },
87
- items: [{ displayValue: '5', usdPrice: '5' }],
88
- },
89
- {
90
- token: {
91
- type: 'ERC20',
92
- address: '0xTokenAddress1',
93
- name: 'TokenName1',
94
- symbol: 'TKN1',
95
- decimals: 18,
96
- logoUri: 'logo_url1',
97
- },
98
- items: [
99
- { displayValue: '3', usdPrice: '3' },
100
- { displayValue: '1', usdPrice: '1' },
101
- ],
102
- },
103
- ]);
104
- });
105
- });
@@ -1,293 +0,0 @@
1
- import Blockaid from '@blockaid/client';
2
- import type { TransactionParams } from '../types';
3
- import {
4
- type NetworkContractToken,
5
- type NetworkToken,
6
- TokenType,
7
- AlertType,
8
- type Alert,
9
- type BalanceChange,
10
- type TokenApproval,
11
- type TokenDiff,
12
- type TokenDiffItem,
13
- type TokenApprovals,
14
- type RpcRequest,
15
- RpcMethod,
16
- } from '@avalabs/vm-module-types';
17
- import { balanceToDisplayValue, numberToBN } from '@avalabs/utils-sdk';
18
- import { isHexString } from 'ethers';
19
- import { scanJsonRpc, scanTransaction } from './scan-transaction';
20
-
21
- export const processTransactionSimulation = async ({
22
- request,
23
- dAppUrl,
24
- params,
25
- chainId,
26
- proxyApiUrl,
27
- }: {
28
- request: RpcRequest;
29
- dAppUrl?: string;
30
- params: TransactionParams;
31
- chainId: number;
32
- proxyApiUrl: string;
33
- }) => {
34
- let alert: Alert | undefined;
35
- let balanceChange: BalanceChange | undefined;
36
- let tokenApprovals: TokenApprovals | undefined;
37
-
38
- try {
39
- const { validation, simulation } = await scanTransaction({
40
- proxyApiUrl,
41
- chainId,
42
- params,
43
- domain: dAppUrl,
44
- });
45
-
46
- if (!validation || validation.result_type === 'Error' || validation.result_type === 'Warning') {
47
- alert = transactionAlerts[AlertType.WARNING];
48
- } else if (validation.result_type === 'Malicious') {
49
- alert = transactionAlerts[AlertType.DANGER];
50
- }
51
-
52
- if (simulation?.status === 'Success') {
53
- tokenApprovals = processTokenApprovals(request, simulation.account_summary.exposures);
54
- balanceChange = processBalanceChange(simulation.account_summary.assets_diffs);
55
- }
56
- } catch (error) {
57
- console.error('processTransactionSimulation error', error);
58
- alert = transactionAlerts[AlertType.WARNING];
59
- }
60
-
61
- return { alert, balanceChange, tokenApprovals };
62
- };
63
-
64
- const processTokenApprovals = (
65
- request: RpcRequest,
66
- exposures: Blockaid.AddressAssetExposure[],
67
- ): TokenApprovals | undefined => {
68
- const approvals: TokenApproval[] = [];
69
-
70
- for (const exposurePerAsset of exposures) {
71
- const token = convertAssetToNetworkContractToken(exposurePerAsset.asset);
72
- if (!token) {
73
- continue;
74
- }
75
-
76
- for (const [spenderAddress, exposurePerSpender] of Object.entries(exposurePerAsset.spenders)) {
77
- if (exposurePerSpender.exposure.length === 0) {
78
- approvals.push({
79
- token,
80
- spenderAddress,
81
- logoUri: token.logoUri,
82
- });
83
- } else {
84
- for (const exposure of exposurePerSpender.exposure) {
85
- if ('raw_value' in exposure) {
86
- approvals.push({
87
- token,
88
- spenderAddress,
89
- value: exposure.raw_value,
90
- usdPrice: exposure.usd_price,
91
- logoUri: token.logoUri,
92
- });
93
- } else {
94
- approvals.push({
95
- token,
96
- spenderAddress,
97
- logoUri: exposure.logo_url,
98
- usdPrice: exposure.usd_price,
99
- });
100
- }
101
- }
102
- }
103
- }
104
- }
105
-
106
- if (approvals.length === 0) {
107
- return undefined;
108
- }
109
-
110
- const isEditable =
111
- approvals.length === 1 &&
112
- approvals[0]?.token.type === TokenType.ERC20 &&
113
- request.method === RpcMethod.ETH_SEND_TRANSACTION;
114
-
115
- return { isEditable, approvals };
116
- };
117
-
118
- export const processBalanceChange = (assetDiffs: Blockaid.AssetDiff[]): BalanceChange | undefined => {
119
- const ins = processAssetDiffs(assetDiffs, 'in');
120
- const outs = processAssetDiffs(assetDiffs, 'out');
121
-
122
- if (ins.length === 0 && outs.length === 0) {
123
- return undefined;
124
- }
125
-
126
- return { ins, outs };
127
- };
128
-
129
- const processAssetDiffs = (assetDiffs: Blockaid.AssetDiff[], type: 'in' | 'out'): TokenDiff[] => {
130
- return (
131
- assetDiffs
132
- .filter((assetDiff) => assetDiff[type].length > 0)
133
- // sort asset diffs by length of in/out array
134
- // this is done to ensure that the token with multiple in/out values are displayed last,
135
- // to put them in groups with appropriate UI(i.e. accordion), after single in/out tokens
136
- .sort((a, b) => a[type].length - b[type].length)
137
- .map((assetDiff) => {
138
- const asset = assetDiff.asset;
139
- // convert blockaid asset to network token
140
- const token: NetworkToken | NetworkContractToken | undefined =
141
- 'address' in asset ? convertAssetToNetworkContractToken(asset) : convertNativeAssetToToken(asset);
142
- if (!token) {
143
- return undefined;
144
- }
145
-
146
- const items = assetDiff[type]
147
- .map((diff) => {
148
- let displayValue;
149
- if ('value' in diff && diff.value) {
150
- if ('decimals' in token) {
151
- const valueBN = numberToBN(diff.value, token.decimals);
152
- displayValue = balanceToDisplayValue(valueBN, token.decimals);
153
- } else if (isHexString(diff.value)) {
154
- // for some token (like ERC1155) blockaid returns value in hex format
155
- displayValue = parseInt(diff.value, 16).toString();
156
- }
157
- } else if ('type' in token && token.type === TokenType.ERC721) {
158
- // for ERC721 type token, we just display 1 to indicate that a single NFT will be transferred
159
- displayValue = '1';
160
- }
161
-
162
- return displayValue ? { displayValue, usdPrice: diff.usd_price } : undefined;
163
- })
164
- .filter((x): x is TokenDiffItem => x !== undefined);
165
-
166
- return { token, items };
167
- })
168
- .filter((x): x is TokenDiff => x !== undefined)
169
- );
170
- };
171
-
172
- const convertAssetToNetworkContractToken = (
173
- asset:
174
- | Blockaid.Erc20TokenDetails
175
- | Blockaid.Erc1155TokenDetails
176
- | Blockaid.Erc721TokenDetails
177
- | Blockaid.NonercTokenDetails,
178
- ): NetworkContractToken | undefined => {
179
- let token: NetworkContractToken | undefined;
180
- if (asset.type === 'ERC20') {
181
- token = {
182
- type: TokenType.ERC20,
183
- address: asset.address,
184
- decimals: asset.decimals,
185
- name: asset.name ?? asset.symbol ?? '',
186
- symbol: asset.symbol ?? '',
187
- logoUri: asset.logo_url,
188
- };
189
- } else if (asset.type === 'ERC1155') {
190
- token = {
191
- type: TokenType.ERC1155,
192
- address: asset.address,
193
- logoUri: asset.logo_url,
194
- name: asset.name,
195
- symbol: asset.symbol,
196
- };
197
- } else if (asset.type === 'ERC721') {
198
- token = {
199
- type: TokenType.ERC721,
200
- address: asset.address,
201
- logoUri: asset.logo_url,
202
- name: asset.name,
203
- symbol: asset.symbol,
204
- };
205
- } else if (asset.type === 'NONERC') {
206
- token = {
207
- type: TokenType.NONERC,
208
- address: asset.address,
209
- logoUri: asset.logo_url,
210
- name: asset.name,
211
- symbol: asset.symbol,
212
- };
213
- }
214
-
215
- return token;
216
- };
217
-
218
- const convertNativeAssetToToken = (asset: Blockaid.NativeAssetDetails): NetworkToken => {
219
- return {
220
- name: asset.name ?? '',
221
- symbol: asset.symbol ?? '',
222
- decimals: asset.decimals,
223
- description: '',
224
- logoUri: asset.logo_url,
225
- };
226
- };
227
-
228
- export const processJsonRpcSimulation = async ({
229
- request,
230
- dAppUrl,
231
- accountAddress,
232
- chainId,
233
- data,
234
- proxyApiUrl,
235
- }: {
236
- request: RpcRequest;
237
- dAppUrl?: string;
238
- accountAddress: string;
239
- data: { method: string; params: unknown };
240
- chainId: number;
241
- proxyApiUrl: string;
242
- }) => {
243
- let alert: Alert | undefined;
244
- let balanceChange: BalanceChange | undefined;
245
- let tokenApprovals: TokenApprovals | undefined;
246
-
247
- try {
248
- const { validation, simulation } = await scanJsonRpc({
249
- proxyApiUrl,
250
- chainId,
251
- accountAddress,
252
- data: data as Blockaid.Evm.JsonRpcScanParams.Data,
253
- domain: dAppUrl,
254
- });
255
-
256
- if (!validation || validation.result_type === 'Error' || validation.result_type === 'Warning') {
257
- alert = transactionAlerts[AlertType.WARNING];
258
- } else if (validation.result_type === 'Malicious') {
259
- alert = transactionAlerts[AlertType.DANGER];
260
- }
261
-
262
- if (simulation?.status === 'Success') {
263
- tokenApprovals = processTokenApprovals(request, simulation.account_summary.exposures);
264
- balanceChange = processBalanceChange(simulation.account_summary.assets_diffs);
265
- }
266
- } catch (error) {
267
- console.error('processJsonRpcSimulation error', error);
268
- alert = transactionAlerts[AlertType.WARNING];
269
- }
270
-
271
- return { alert, balanceChange, tokenApprovals };
272
- };
273
-
274
- const transactionAlerts = {
275
- [AlertType.WARNING]: {
276
- type: AlertType.WARNING,
277
- details: {
278
- title: 'Suspicious Transaction',
279
- description: 'Use caution, this transaction may be malicious.',
280
- },
281
- },
282
- [AlertType.DANGER]: {
283
- type: AlertType.DANGER,
284
- details: {
285
- title: 'Scam Transaction',
286
- description: 'This transaction is malicious, do not proceed.',
287
- actionTitles: {
288
- reject: 'Reject Transaction',
289
- proceed: 'Proceed Anyway',
290
- },
291
- },
292
- },
293
- };
@@ -1,63 +0,0 @@
1
- import Blockaid from '@blockaid/client';
2
- import type { TransactionParams } from '../types';
3
-
4
- const DUMMY_API_KEY = 'DUMMY_API_KEY'; // since we're using our own proxy and api key is handled there, we can use a dummy key here
5
-
6
- export const scanTransaction = async ({
7
- proxyApiUrl,
8
- chainId,
9
- params,
10
- domain,
11
- }: {
12
- proxyApiUrl: string;
13
- chainId: number;
14
- params: TransactionParams;
15
- domain?: string;
16
- }): Promise<Blockaid.TransactionScanResponse> => {
17
- const blockaid = new Blockaid({
18
- baseURL: proxyApiUrl + '/proxy/blockaid/',
19
- apiKey: DUMMY_API_KEY,
20
- });
21
-
22
- return blockaid.evm.transaction.scan({
23
- account_address: params.from,
24
- chain: chainId.toString(),
25
- options: ['validation', 'simulation'],
26
- data: {
27
- from: params.from,
28
- to: params.to,
29
- data: params.data,
30
- value: params.value,
31
- gas: params.gas,
32
- gas_price: params.gasPrice,
33
- },
34
- metadata: (domain && domain.length > 0 ? { domain } : { non_dapp: true }) as Blockaid.Evm.Metadata,
35
- });
36
- };
37
-
38
- export const scanJsonRpc = async ({
39
- proxyApiUrl,
40
- chainId,
41
- accountAddress,
42
- data,
43
- domain,
44
- }: {
45
- proxyApiUrl: string;
46
- chainId: number;
47
- accountAddress: string;
48
- data: Blockaid.Evm.JsonRpcScanParams.Data;
49
- domain?: string;
50
- }): Promise<Blockaid.TransactionScanResponse> => {
51
- const blockaid = new Blockaid({
52
- baseURL: proxyApiUrl + '/proxy/blockaid/',
53
- apiKey: DUMMY_API_KEY,
54
- });
55
-
56
- return blockaid.evm.jsonRpc.scan({
57
- chain: chainId.toString(),
58
- options: ['validation', 'simulation'],
59
- account_address: accountAddress,
60
- data,
61
- metadata: (domain && domain.length > 0 ? { domain } : { non_dapp: true }) as Blockaid.Evm.Metadata,
62
- });
63
- };
@@ -1,7 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "verbatimModuleSyntax": false,
5
- "esModuleInterop": true
6
- }
7
- }
package/tsconfig.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "extends": "@internal/tsconfig/tsconfig.base.json",
3
- "compilerOptions": {
4
- "outDir": "./dist",
5
- "declaration": false,
6
- "incremental": false // Need to turn off because of tsup dts
7
- },
8
- "include": ["src"],
9
- "references": [
10
- {
11
- "path": "../../packages-internal/utils/tsconfig.json"
12
- }
13
- ]
14
- }
package/tsup.config.ts DELETED
@@ -1,4 +0,0 @@
1
- import { defineConfig } from 'tsup';
2
- import { baseConfig } from '@internal/tsup-config';
3
-
4
- export default defineConfig(baseConfig);