@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.
- package/LICENSE +9 -0
- package/README.md +1 -1
- package/dist/index.cjs +6 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/package.json +13 -8
- package/.turbo/turbo-build.log +0 -22
- package/.turbo/turbo-lint.log +0 -4
- package/.turbo/turbo-test.log +0 -119
- package/CHANGELOG.md +0 -174
- package/jest.config.js +0 -9
- package/src/constants.ts +0 -1
- package/src/contracts/openzeppelin/ERC1155.ts +0 -440
- package/src/contracts/openzeppelin/ERC20.ts +0 -330
- package/src/contracts/openzeppelin/ERC721.ts +0 -420
- package/src/contracts/openzeppelin/common.ts +0 -131
- package/src/contracts/openzeppelin/factories/ERC1155__factory.ts +0 -388
- package/src/contracts/openzeppelin/factories/ERC20__factory.ts +0 -353
- package/src/contracts/openzeppelin/factories/ERC721__factory.ts +0 -413
- package/src/contracts/openzeppelin/factories/index.ts +0 -6
- package/src/contracts/openzeppelin/index.ts +0 -10
- package/src/env.ts +0 -25
- package/src/handlers/eth-send-transaction/eth-send-transaction.test.ts +0 -572
- package/src/handlers/eth-send-transaction/eth-send-transaction.ts +0 -189
- package/src/handlers/eth-send-transaction/schema.test.ts +0 -240
- package/src/handlers/eth-send-transaction/schema.ts +0 -20
- package/src/handlers/eth-sign/eth-sign.test.ts +0 -359
- package/src/handlers/eth-sign/eth-sign.ts +0 -158
- package/src/handlers/eth-sign/schemas/eth-sign-typed-data.ts +0 -65
- package/src/handlers/eth-sign/schemas/eth-sign.ts +0 -9
- package/src/handlers/eth-sign/schemas/parse-request-params/fixture.ts +0 -47
- package/src/handlers/eth-sign/schemas/parse-request-params/parse-request-params.test.ts +0 -284
- package/src/handlers/eth-sign/schemas/parse-request-params/parse-request-params.ts +0 -94
- package/src/handlers/eth-sign/schemas/personal-sign.ts +0 -12
- package/src/handlers/eth-sign/schemas/shared.ts +0 -5
- package/src/handlers/eth-sign/utils/beautify-message/beautify-message.test.ts +0 -29
- package/src/handlers/eth-sign/utils/beautify-message/beautify-message.ts +0 -134
- package/src/handlers/eth-sign/utils/is-typed-data-valid.ts +0 -26
- package/src/handlers/eth-sign/utils/typeguards.ts +0 -10
- package/src/handlers/forward-to-rpc-node/forward-to-rpc-node.test.ts +0 -90
- package/src/handlers/forward-to-rpc-node/forward-to-rpc-node.ts +0 -23
- package/src/handlers/get-address/get-address.ts +0 -26
- package/src/handlers/get-balances/evm-balance-service/get-erc20-balances.test.ts +0 -77
- package/src/handlers/get-balances/evm-balance-service/get-erc20-balances.ts +0 -81
- package/src/handlers/get-balances/evm-balance-service/get-native-token-balances.test.ts +0 -96
- package/src/handlers/get-balances/evm-balance-service/get-native-token-balances.ts +0 -53
- package/src/handlers/get-balances/get-balances.test.ts +0 -248
- package/src/handlers/get-balances/get-balances.ts +0 -123
- package/src/handlers/get-balances/glacier-balance-service/get-erc20-balances.test.ts +0 -71
- package/src/handlers/get-balances/glacier-balance-service/get-erc20-balances.ts +0 -106
- package/src/handlers/get-balances/glacier-balance-service/get-native-token-balances.test.ts +0 -59
- package/src/handlers/get-balances/glacier-balance-service/get-native-token-balances.ts +0 -48
- package/src/handlers/get-network-fee/get-network-fee.test.ts +0 -43
- package/src/handlers/get-network-fee/get-network-fee.ts +0 -59
- package/src/handlers/get-tokens/get-tokens.test.ts +0 -100
- package/src/handlers/get-tokens/get-tokens.ts +0 -18
- package/src/handlers/get-transaction-history/converters/etherscan-transaction-converter/convert-transaction-erc20.test.ts +0 -53
- package/src/handlers/get-transaction-history/converters/etherscan-transaction-converter/convert-transaction-erc20.ts +0 -49
- package/src/handlers/get-transaction-history/converters/etherscan-transaction-converter/convert-transaction-normal.test.ts +0 -57
- package/src/handlers/get-transaction-history/converters/etherscan-transaction-converter/convert-transaction-normal.ts +0 -57
- package/src/handlers/get-transaction-history/converters/etherscan-transaction-converter/get-transaction-from-etherscan.test.ts +0 -116
- package/src/handlers/get-transaction-history/converters/etherscan-transaction-converter/get-transaction-from-etherscan.ts +0 -73
- package/src/handlers/get-transaction-history/converters/evm-transaction-converter/convert-transaction.ts +0 -47
- package/src/handlers/get-transaction-history/converters/evm-transaction-converter/get-nft-metadata.ts +0 -35
- package/src/handlers/get-transaction-history/converters/evm-transaction-converter/get-sender-info.ts +0 -38
- package/src/handlers/get-transaction-history/converters/evm-transaction-converter/get-tokens.ts +0 -106
- package/src/handlers/get-transaction-history/converters/evm-transaction-converter/get-transaction-from-glacier.test.ts +0 -222
- package/src/handlers/get-transaction-history/converters/evm-transaction-converter/get-transactions-from-glacier.ts +0 -62
- package/src/handlers/get-transaction-history/converters/evm-transaction-converter/get-tx-type.ts +0 -52
- package/src/handlers/get-transaction-history/get-transaction-history.test.ts +0 -57
- package/src/handlers/get-transaction-history/get-transaction-history.ts +0 -55
- package/src/handlers/get-transaction-history/utils/get-explorer-address-by-network.ts +0 -7
- package/src/handlers/get-transaction-history/utils/get-small-image-for-nft.ts +0 -16
- package/src/handlers/get-transaction-history/utils/ipfs-resolver-with-fallback.ts +0 -18
- package/src/handlers/get-transaction-history/utils/is-ethereum-chain-id.ts +0 -15
- package/src/handlers/get-transaction-history/utils/resolve.ts +0 -7
- package/src/index.ts +0 -3
- package/src/module.ts +0 -141
- package/src/services/glacier-service/glacier-service.ts +0 -238
- package/src/types.ts +0 -25
- package/src/utils/estimate-gas-limit.ts +0 -27
- package/src/utils/get-chain-id.ts +0 -12
- package/src/utils/get-nonce.ts +0 -11
- package/src/utils/get-provider.ts +0 -46
- package/src/utils/parse-erc20-transaction-type.ts +0 -35
- package/src/utils/process-transaction-simulation.test.ts +0 -105
- package/src/utils/process-transaction-simulation.ts +0 -293
- package/src/utils/scan-transaction.ts +0 -63
- package/tsconfig.jest.json +0 -7
- package/tsconfig.json +0 -14
- package/tsup.config.ts +0 -4
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type Network,
|
|
3
|
-
type Hex,
|
|
4
|
-
type RpcRequest,
|
|
5
|
-
type ApprovalController,
|
|
6
|
-
type DisplayData,
|
|
7
|
-
type SigningData,
|
|
8
|
-
RpcMethod,
|
|
9
|
-
} from '@avalabs/vm-module-types';
|
|
10
|
-
import { parseRequestParams } from './schema';
|
|
11
|
-
import { estimateGasLimit } from '../../utils/estimate-gas-limit';
|
|
12
|
-
import { getNonce } from '../../utils/get-nonce';
|
|
13
|
-
import { rpcErrors } from '@metamask/rpc-errors';
|
|
14
|
-
import { getProvider } from '../../utils/get-provider';
|
|
15
|
-
import type { JsonRpcBatchInternal } from '@avalabs/wallets-sdk';
|
|
16
|
-
import { processTransactionSimulation } from '../../utils/process-transaction-simulation';
|
|
17
|
-
import { parseERC20TransactionType } from '../../utils/parse-erc20-transaction-type';
|
|
18
|
-
import { ERC20TransactionType } from '../../types';
|
|
19
|
-
|
|
20
|
-
export const ethSendTransaction = async ({
|
|
21
|
-
request,
|
|
22
|
-
network,
|
|
23
|
-
approvalController,
|
|
24
|
-
proxyApiUrl,
|
|
25
|
-
}: {
|
|
26
|
-
request: RpcRequest;
|
|
27
|
-
network: Network;
|
|
28
|
-
approvalController: ApprovalController;
|
|
29
|
-
proxyApiUrl: string;
|
|
30
|
-
}) => {
|
|
31
|
-
const { dappInfo, params } = request;
|
|
32
|
-
|
|
33
|
-
// validate params
|
|
34
|
-
const result = parseRequestParams(params);
|
|
35
|
-
|
|
36
|
-
if (!result.success) {
|
|
37
|
-
console.error('invalid params', result.error);
|
|
38
|
-
return {
|
|
39
|
-
error: rpcErrors.invalidParams('Transaction params are invalid'),
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const transaction = result.data[0];
|
|
44
|
-
|
|
45
|
-
if (!transaction) {
|
|
46
|
-
return {
|
|
47
|
-
error: rpcErrors.invalidParams('Transaction params are invalid'),
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const provider = getProvider({
|
|
52
|
-
chainId: network.chainId,
|
|
53
|
-
chainName: network.chainName,
|
|
54
|
-
rpcUrl: network.rpcUrl,
|
|
55
|
-
multiContractAddress: network.utilityAddresses?.multicall,
|
|
56
|
-
pollingInterval: 1000,
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
// calculate gas limit if not provided/invalid
|
|
60
|
-
if (!transaction.gas || Number(transaction.gas) < 0) {
|
|
61
|
-
try {
|
|
62
|
-
const gasLimit = await estimateGasLimit({
|
|
63
|
-
transactionParams: {
|
|
64
|
-
from: transaction.from,
|
|
65
|
-
to: transaction.to,
|
|
66
|
-
data: transaction.data,
|
|
67
|
-
value: transaction.value,
|
|
68
|
-
},
|
|
69
|
-
provider,
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
transaction.gas = '0x' + gasLimit.toString(16);
|
|
73
|
-
} catch (error) {
|
|
74
|
-
return {
|
|
75
|
-
error: rpcErrors.internal('Unable to calculate gas limit'),
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// calculate nonce if not provided
|
|
81
|
-
if (!transaction.nonce) {
|
|
82
|
-
try {
|
|
83
|
-
const nonce = await getNonce({
|
|
84
|
-
from: transaction.from,
|
|
85
|
-
provider,
|
|
86
|
-
});
|
|
87
|
-
transaction.nonce = String(nonce);
|
|
88
|
-
} catch (error) {
|
|
89
|
-
return {
|
|
90
|
-
error: rpcErrors.internal('Unable to calculate nonce'),
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const transactionType = parseERC20TransactionType(transaction);
|
|
96
|
-
|
|
97
|
-
const { alert, balanceChange, tokenApprovals } = await processTransactionSimulation({
|
|
98
|
-
request,
|
|
99
|
-
proxyApiUrl,
|
|
100
|
-
chainId: network.chainId,
|
|
101
|
-
params: transaction,
|
|
102
|
-
dAppUrl: request.dappInfo.url,
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
// generate display and signing data
|
|
106
|
-
let title = 'Approve Transaction';
|
|
107
|
-
if (transactionType === ERC20TransactionType.APPROVE) {
|
|
108
|
-
title = 'Token Spend Approval';
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const displayData: DisplayData = {
|
|
112
|
-
title,
|
|
113
|
-
network: {
|
|
114
|
-
chainId: network.chainId,
|
|
115
|
-
name: network.chainName,
|
|
116
|
-
logoUri: network.logoUri,
|
|
117
|
-
},
|
|
118
|
-
transactionDetails: {
|
|
119
|
-
website: new URL(dappInfo.url).hostname,
|
|
120
|
-
from: transaction.from,
|
|
121
|
-
to: transaction.to,
|
|
122
|
-
data: transaction.data,
|
|
123
|
-
type: transactionType,
|
|
124
|
-
},
|
|
125
|
-
networkFeeSelector: true,
|
|
126
|
-
alert,
|
|
127
|
-
balanceChange,
|
|
128
|
-
tokenApprovals,
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
const signingData: SigningData = {
|
|
132
|
-
type: RpcMethod.ETH_SEND_TRANSACTION,
|
|
133
|
-
account: transaction.from,
|
|
134
|
-
chainId: network.chainId,
|
|
135
|
-
data: {
|
|
136
|
-
type: 2, // hardcoding to 2 for now as we only support EIP-1559
|
|
137
|
-
nonce: Number(transaction.nonce),
|
|
138
|
-
gasLimit: Number(transaction.gas),
|
|
139
|
-
to: transaction.to,
|
|
140
|
-
from: transaction.from,
|
|
141
|
-
data: transaction.data,
|
|
142
|
-
value: transaction.value,
|
|
143
|
-
chainId: transaction.chainId,
|
|
144
|
-
},
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
// prompt user for approval
|
|
148
|
-
const response = await approvalController.requestApproval({ request, displayData, signingData });
|
|
149
|
-
|
|
150
|
-
if ('error' in response) {
|
|
151
|
-
return {
|
|
152
|
-
error: response.error,
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// broadcast the signed transaction
|
|
157
|
-
const txHash = await provider.send('eth_sendRawTransaction', [response.result]);
|
|
158
|
-
|
|
159
|
-
waitForTransactionReceipt({
|
|
160
|
-
provider,
|
|
161
|
-
txHash,
|
|
162
|
-
onTransactionConfirmed: approvalController.onTransactionConfirmed,
|
|
163
|
-
onTransactionReverted: approvalController.onTransactionReverted,
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
return { result: txHash };
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
const waitForTransactionReceipt = async ({
|
|
170
|
-
provider,
|
|
171
|
-
txHash,
|
|
172
|
-
onTransactionConfirmed,
|
|
173
|
-
onTransactionReverted,
|
|
174
|
-
}: {
|
|
175
|
-
provider: JsonRpcBatchInternal;
|
|
176
|
-
txHash: Hex;
|
|
177
|
-
onTransactionConfirmed: (txHash: Hex) => void;
|
|
178
|
-
onTransactionReverted: (txHash: Hex) => void;
|
|
179
|
-
}) => {
|
|
180
|
-
const receipt = await provider.waitForTransaction(txHash);
|
|
181
|
-
|
|
182
|
-
const success = receipt?.status === 1; // 1 indicates success, 0 indicates revert
|
|
183
|
-
|
|
184
|
-
if (success) {
|
|
185
|
-
onTransactionConfirmed(txHash);
|
|
186
|
-
} else {
|
|
187
|
-
onTransactionReverted(txHash);
|
|
188
|
-
}
|
|
189
|
-
};
|
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
import { parseRequestParams } from './schema';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
|
|
4
|
-
it('should return success for valid params', () => {
|
|
5
|
-
const paramsList = [
|
|
6
|
-
[
|
|
7
|
-
{
|
|
8
|
-
from: '0x1234567890123456789012345678901234567890',
|
|
9
|
-
to: '0x1234567890123456789012345678901234567890',
|
|
10
|
-
data: '0xdata',
|
|
11
|
-
value: '0xvalue',
|
|
12
|
-
gas: '0x5208',
|
|
13
|
-
gasPrice: '0x5208',
|
|
14
|
-
maxFeePerGas: '0x5208',
|
|
15
|
-
maxPriorityFeePerGas: '0x5208',
|
|
16
|
-
nonce: '12',
|
|
17
|
-
chainId: '1',
|
|
18
|
-
},
|
|
19
|
-
],
|
|
20
|
-
[
|
|
21
|
-
{
|
|
22
|
-
from: '0x1234567890123456789012345678901234567890',
|
|
23
|
-
to: '0x1234567890123456789012345678901234567890',
|
|
24
|
-
value: '0xvalue',
|
|
25
|
-
gas: '0x5208',
|
|
26
|
-
gasPrice: '0x5208',
|
|
27
|
-
maxFeePerGas: '0x5208',
|
|
28
|
-
maxPriorityFeePerGas: '0x5208',
|
|
29
|
-
nonce: '12',
|
|
30
|
-
chainId: '1',
|
|
31
|
-
},
|
|
32
|
-
],
|
|
33
|
-
[
|
|
34
|
-
{
|
|
35
|
-
from: '0x1234567890123456789012345678901234567890',
|
|
36
|
-
to: '0x1234567890123456789012345678901234567890',
|
|
37
|
-
gas: '0x5208',
|
|
38
|
-
gasPrice: '0x5208',
|
|
39
|
-
maxFeePerGas: '0x5208',
|
|
40
|
-
maxPriorityFeePerGas: '0x5208',
|
|
41
|
-
nonce: '12',
|
|
42
|
-
chainId: '1',
|
|
43
|
-
},
|
|
44
|
-
],
|
|
45
|
-
[
|
|
46
|
-
{
|
|
47
|
-
from: '0x1234567890123456789012345678901234567890',
|
|
48
|
-
to: '0x1234567890123456789012345678901234567890',
|
|
49
|
-
gas: '0x5208',
|
|
50
|
-
gasPrice: '0x5208',
|
|
51
|
-
nonce: '12',
|
|
52
|
-
chainId: '1',
|
|
53
|
-
},
|
|
54
|
-
],
|
|
55
|
-
[
|
|
56
|
-
{
|
|
57
|
-
from: '0x1234567890123456789012345678901234567890',
|
|
58
|
-
to: '0x1234567890123456789012345678901234567890',
|
|
59
|
-
},
|
|
60
|
-
],
|
|
61
|
-
];
|
|
62
|
-
|
|
63
|
-
for (const params of paramsList) {
|
|
64
|
-
const result = parseRequestParams(params);
|
|
65
|
-
|
|
66
|
-
expect(result.success).toBe(true);
|
|
67
|
-
expect(result.data).toEqual(params);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('should return error for invalid params', () => {
|
|
72
|
-
const paramsList = [
|
|
73
|
-
// missing "from"
|
|
74
|
-
[
|
|
75
|
-
{
|
|
76
|
-
to: '0x1234567890123456789012345678901234567890',
|
|
77
|
-
data: '0xdata',
|
|
78
|
-
value: '0xvalue',
|
|
79
|
-
gas: '0x5208',
|
|
80
|
-
gasPrice: '0x5208',
|
|
81
|
-
maxFeePerGas: '0x5208',
|
|
82
|
-
maxPriorityFeePerGas: '0x5208',
|
|
83
|
-
nonce: '12',
|
|
84
|
-
chainId: '1',
|
|
85
|
-
},
|
|
86
|
-
],
|
|
87
|
-
// invalid "from"
|
|
88
|
-
[
|
|
89
|
-
{
|
|
90
|
-
from: '0x123',
|
|
91
|
-
to: '0x1234567890123456789012345678901234567890',
|
|
92
|
-
data: '0xdata',
|
|
93
|
-
value: '0xvalue',
|
|
94
|
-
gas: '0x5208',
|
|
95
|
-
gasPrice: '0x5208',
|
|
96
|
-
maxFeePerGas: '0x5208',
|
|
97
|
-
maxPriorityFeePerGas: '0x5208',
|
|
98
|
-
nonce: '12',
|
|
99
|
-
chainId: '1',
|
|
100
|
-
},
|
|
101
|
-
],
|
|
102
|
-
// missing "to"
|
|
103
|
-
[
|
|
104
|
-
{
|
|
105
|
-
from: '0x1234567890123456789012345678901234567890',
|
|
106
|
-
data: '0xdata',
|
|
107
|
-
value: '0xvalue',
|
|
108
|
-
gas: '0x5208',
|
|
109
|
-
gasPrice: '0x5208',
|
|
110
|
-
maxFeePerGas: '0x5208',
|
|
111
|
-
maxPriorityFeePerGas: '0x5208',
|
|
112
|
-
nonce: '12',
|
|
113
|
-
chainId: '1',
|
|
114
|
-
},
|
|
115
|
-
],
|
|
116
|
-
// invalid "to"
|
|
117
|
-
[
|
|
118
|
-
{
|
|
119
|
-
from: '0x1234567890123456789012345678901234567890',
|
|
120
|
-
to: '0x123',
|
|
121
|
-
data: '0xdata',
|
|
122
|
-
value: '0xvalue',
|
|
123
|
-
gas: '0x5208',
|
|
124
|
-
gasPrice: '0x5208',
|
|
125
|
-
maxFeePerGas: '0x5208',
|
|
126
|
-
maxPriorityFeePerGas: '0x5208',
|
|
127
|
-
nonce: '12',
|
|
128
|
-
chainId: '1',
|
|
129
|
-
},
|
|
130
|
-
],
|
|
131
|
-
// non-hex "value"
|
|
132
|
-
[
|
|
133
|
-
{
|
|
134
|
-
from: '0x1234567890123456789012345678901234567890',
|
|
135
|
-
to: '0x1234567890123456789012345678901234567890',
|
|
136
|
-
data: '0xdata',
|
|
137
|
-
value: 'value',
|
|
138
|
-
gas: '0x5208',
|
|
139
|
-
gasPrice: '0x5208',
|
|
140
|
-
maxFeePerGas: '0x5208',
|
|
141
|
-
maxPriorityFeePerGas: '0x5208',
|
|
142
|
-
nonce: '12',
|
|
143
|
-
chainId: '1',
|
|
144
|
-
},
|
|
145
|
-
],
|
|
146
|
-
// non-hex "gas"
|
|
147
|
-
[
|
|
148
|
-
{
|
|
149
|
-
from: '0x1234567890123456789012345678901234567890',
|
|
150
|
-
to: '0x1234567890123456789012345678901234567890',
|
|
151
|
-
data: '0xdata',
|
|
152
|
-
value: '0x5208',
|
|
153
|
-
gas: 'gas',
|
|
154
|
-
gasPrice: '0x5208',
|
|
155
|
-
maxFeePerGas: '0x5208',
|
|
156
|
-
maxPriorityFeePerGas: '0x5208',
|
|
157
|
-
nonce: '12',
|
|
158
|
-
chainId: '1',
|
|
159
|
-
},
|
|
160
|
-
],
|
|
161
|
-
// non-hex "gasPrice"
|
|
162
|
-
[
|
|
163
|
-
{
|
|
164
|
-
from: '0x1234567890123456789012345678901234567890',
|
|
165
|
-
to: '0x1234567890123456789012345678901234567890',
|
|
166
|
-
data: '0xdata',
|
|
167
|
-
value: '0x5208',
|
|
168
|
-
gas: '0x5208',
|
|
169
|
-
gasPrice: 'gasPrice',
|
|
170
|
-
maxFeePerGas: '0x5208',
|
|
171
|
-
maxPriorityFeePerGas: '0x5208',
|
|
172
|
-
nonce: '12',
|
|
173
|
-
chainId: '1',
|
|
174
|
-
},
|
|
175
|
-
],
|
|
176
|
-
// non-hex "maxFeePerGas"
|
|
177
|
-
[
|
|
178
|
-
{
|
|
179
|
-
from: '0x1234567890123456789012345678901234567890',
|
|
180
|
-
to: '0x1234567890123456789012345678901234567890',
|
|
181
|
-
data: '0xdata',
|
|
182
|
-
value: '0x5208',
|
|
183
|
-
gas: '0x5208',
|
|
184
|
-
gasPrice: '0x5208',
|
|
185
|
-
maxFeePerGas: 'maxFeePerGas',
|
|
186
|
-
maxPriorityFeePerGas: '0x5208',
|
|
187
|
-
nonce: '12',
|
|
188
|
-
chainId: '1',
|
|
189
|
-
},
|
|
190
|
-
],
|
|
191
|
-
// non-hex "maxPriorityFeePerGas"
|
|
192
|
-
[
|
|
193
|
-
{
|
|
194
|
-
from: '0x1234567890123456789012345678901234567890',
|
|
195
|
-
to: '0x1234567890123456789012345678901234567890',
|
|
196
|
-
data: '0xdata',
|
|
197
|
-
value: '0x5208',
|
|
198
|
-
gas: '0x5208',
|
|
199
|
-
gasPrice: '0x5208',
|
|
200
|
-
maxFeePerGas: '0x5208',
|
|
201
|
-
maxPriorityFeePerGas: 'maxPriorityFeePerGas',
|
|
202
|
-
nonce: '12',
|
|
203
|
-
chainId: '1',
|
|
204
|
-
},
|
|
205
|
-
],
|
|
206
|
-
// multiple transactions
|
|
207
|
-
[
|
|
208
|
-
{
|
|
209
|
-
from: '0x1234567890123456789012345678901234567890',
|
|
210
|
-
to: '0x1234567890123456789012345678901234567890',
|
|
211
|
-
data: '0xdata',
|
|
212
|
-
value: '0xvalue',
|
|
213
|
-
gas: '0x5208',
|
|
214
|
-
gasPrice: '0x5208',
|
|
215
|
-
maxFeePerGas: '0x5208',
|
|
216
|
-
maxPriorityFeePerGas: '0x5208',
|
|
217
|
-
nonce: '12',
|
|
218
|
-
chainId: '1',
|
|
219
|
-
},
|
|
220
|
-
{
|
|
221
|
-
from: '0x1234567890123456789012345678901234567890',
|
|
222
|
-
to: '0x1234567890123456789012345678901234567890',
|
|
223
|
-
data: '0xdata',
|
|
224
|
-
value: '0xvalue',
|
|
225
|
-
gas: '0x5208',
|
|
226
|
-
gasPrice: '0x5208',
|
|
227
|
-
maxFeePerGas: '0x5208',
|
|
228
|
-
maxPriorityFeePerGas: '0x5208',
|
|
229
|
-
nonce: '12',
|
|
230
|
-
chainId: '1',
|
|
231
|
-
},
|
|
232
|
-
],
|
|
233
|
-
];
|
|
234
|
-
|
|
235
|
-
for (const params of paramsList) {
|
|
236
|
-
const result = parseRequestParams([params]);
|
|
237
|
-
expect(result.success).toBe(false);
|
|
238
|
-
expect(result.error).toBeInstanceOf(z.ZodError);
|
|
239
|
-
}
|
|
240
|
-
});
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
|
|
3
|
-
const transactionSchema = z.object({
|
|
4
|
-
from: z.string().length(42),
|
|
5
|
-
to: z.string().length(42),
|
|
6
|
-
data: z.string().optional(),
|
|
7
|
-
value: z.string().startsWith('0x').optional(),
|
|
8
|
-
gas: z.string().startsWith('0x').optional(),
|
|
9
|
-
gasPrice: z.string().startsWith('0x').optional(),
|
|
10
|
-
maxFeePerGas: z.string().startsWith('0x').optional(),
|
|
11
|
-
maxPriorityFeePerGas: z.string().startsWith('0x').optional(),
|
|
12
|
-
nonce: z.string().optional(),
|
|
13
|
-
chainId: z.string().optional(),
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
const paramsSchema = z.array(transactionSchema).length(1);
|
|
17
|
-
|
|
18
|
-
export const parseRequestParams = (params: unknown) => {
|
|
19
|
-
return paramsSchema.safeParse(params);
|
|
20
|
-
};
|