@avalabs/evm-module 0.0.11 → 0.0.13

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 (33) hide show
  1. package/.turbo/turbo-build.log +10 -10
  2. package/.turbo/turbo-lint.log +1 -1
  3. package/.turbo/turbo-test.log +36 -5
  4. package/CHANGELOG.md +21 -0
  5. package/dist/index.cjs +7 -4
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.cts +30 -12
  8. package/dist/index.d.ts +30 -12
  9. package/dist/index.js +6 -4
  10. package/dist/index.js.map +1 -1
  11. package/package.json +5 -3
  12. package/src/env.ts +25 -0
  13. package/src/handlers/eth-send-transaction/eth-send-transaction.test.ts +333 -0
  14. package/src/handlers/eth-send-transaction/eth-send-transaction.ts +170 -0
  15. package/src/handlers/eth-send-transaction/schema.test.ts +240 -0
  16. package/src/handlers/eth-send-transaction/schema.ts +20 -0
  17. package/src/handlers/get-network-fee/get-network-fee.test.ts +2 -1
  18. package/src/handlers/get-network-fee/get-network-fee.ts +10 -11
  19. package/src/handlers/get-tokens/get-tokens.ts +2 -1
  20. package/src/handlers/get-transaction-history/converters/etherscan-transaction-converter/get-transaction-from-etherscan.ts +11 -3
  21. package/src/handlers/get-transaction-history/converters/evm-transaction-converter/get-transaction-from-glacier.test.ts +1 -5
  22. package/src/handlers/get-transaction-history/converters/evm-transaction-converter/get-transactions-from-glacier.ts +12 -3
  23. package/src/handlers/get-transaction-history/get-transaction-history.test.ts +2 -0
  24. package/src/handlers/get-transaction-history/get-transaction-history.ts +11 -3
  25. package/src/index.ts +2 -72
  26. package/src/module.ts +95 -0
  27. package/src/types.ts +13 -0
  28. package/src/utils/estimate-gas-limit.ts +27 -0
  29. package/src/utils/get-chain-id.ts +12 -0
  30. package/src/utils/get-nonce.ts +11 -0
  31. package/src/utils/get-provider.ts +18 -23
  32. package/tsconfig.json +1 -5
  33. /package/{src/manifest.json → manifest.json} +0 -0
@@ -0,0 +1,27 @@
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
+ };
@@ -0,0 +1,12 @@
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
+ };
@@ -0,0 +1,11 @@
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,33 +1,28 @@
1
- import type { GetNetworkFeeParams } from '@avalabs/vm-module-types';
2
1
  import { JsonRpcBatchInternal } from '@avalabs/wallets-sdk';
3
- import { Network } from 'ethers';
4
-
5
- export const getProvider = ({
6
- glacierApiKey,
7
- chainId: caip2ChainId,
8
- chainName,
9
- rpcUrl,
10
- multiContractAddress,
11
- }: GetNetworkFeeParams & {
12
- glacierApiUrl: string;
13
- glacierApiKey?: string;
14
- }): JsonRpcBatchInternal => {
15
- if (!caip2ChainId || !chainName || !rpcUrl) {
16
- throw new Error('Missing required parameters');
17
- }
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
+ };
18
15
 
19
- const chainId = caip2ChainId.split(':')[1];
20
- if (!chainId || isNaN(Number(chainId))) {
21
- throw new Error('Invalid chainId');
22
- }
16
+ export const getProvider = (params: ProviderParams): JsonRpcBatchInternal => {
17
+ const { chainId, chainName, rpcUrl, multiContractAddress, pollingInterval = 2000 } = params;
23
18
 
24
19
  const provider = new JsonRpcBatchInternal(
25
20
  { maxCalls: 40, multiContractAddress },
26
- addGlacierAPIKeyIfNeeded(rpcUrl, glacierApiKey),
27
- new Network(chainName, Number(chainId)),
21
+ addGlacierAPIKeyIfNeeded(rpcUrl, GLACIER_API_KEY),
22
+ new EVMNetwork(chainName, chainId),
28
23
  );
29
24
 
30
- provider.pollingInterval = 2000;
25
+ provider.pollingInterval = pollingInterval;
31
26
 
32
27
  return provider;
33
28
  };
package/tsconfig.json CHANGED
@@ -4,9 +4,5 @@
4
4
  "outDir": "./dist",
5
5
  "incremental": false // Need to turn off because of tsup dts
6
6
  },
7
- "include": ["src"],
8
- "references": [
9
- { "path": "../../packages/vm-module-types/tsconfig.json" },
10
- { "path": "../../packages-internal/types/tsconfig.json" }
11
- ]
7
+ "include": ["src"]
12
8
  }
File without changes