@avalabs/vm-module-types 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.
- package/.turbo/turbo-build.log +32 -0
- package/.turbo/turbo-lint.log +1 -1
- package/CHANGELOG.md +15 -0
- package/dist/chunk-4RO2H63T.js +7 -0
- package/dist/chunk-4RO2H63T.js.map +1 -0
- package/dist/chunk-L7UO6W6T.cjs +16 -0
- package/dist/chunk-L7UO6W6T.cjs.map +1 -0
- package/dist/index.cjs +40 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/types.cjs +40 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +516 -0
- package/dist/types.d.ts +516 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +15 -4
- package/src/types.ts +146 -23
- package/tsconfig.json +1 -1
- package/tsup.config.ts +4 -0
package/src/types.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { object, string, boolean, z } from 'zod';
|
|
2
|
+
import type { TransactionRequest } from 'ethers';
|
|
3
|
+
import type { JsonRpcError, EthereumProviderError, OptionalDataWithOptionalCause } from '@metamask/rpc-errors';
|
|
2
4
|
|
|
3
5
|
export enum TransactionType {
|
|
4
6
|
BRIDGE = 'Bridge',
|
|
@@ -16,6 +18,34 @@ export enum TransactionType {
|
|
|
16
18
|
UNKNOWN = 'UNKNOWN',
|
|
17
19
|
}
|
|
18
20
|
|
|
21
|
+
export enum PChainTransactionType {
|
|
22
|
+
ADD_VALIDATOR_TX = 'AddValidatorTx',
|
|
23
|
+
ADD_SUBNET_VALIDATOR_TX = 'AddSubnetValidatorTx',
|
|
24
|
+
ADD_DELEGATOR_TX = 'AddDelegatorTx',
|
|
25
|
+
CREATE_CHAIN_TX = 'CreateChainTx',
|
|
26
|
+
CREATE_SUBNET_TX = 'CreateSubnetTx',
|
|
27
|
+
IMPORT_TX = 'ImportTx',
|
|
28
|
+
EXPORT_TX = 'ExportTx',
|
|
29
|
+
ADVANCE_TIME_TX = 'AdvanceTimeTx',
|
|
30
|
+
REWARD_VALIDATOR_TX = 'RewardValidatorTx',
|
|
31
|
+
REMOVE_SUBNET_VALIDATOR_TX = 'RemoveSubnetValidatorTx',
|
|
32
|
+
TRANSFORM_SUBNET_TX = 'TransformSubnetTx',
|
|
33
|
+
ADD_PERMISSIONLESS_VALIDATOR_TX = 'AddPermissionlessValidatorTx',
|
|
34
|
+
ADD_PERMISSIONLESS_DELEGATOR_TX = 'AddPermissionlessDelegatorTx',
|
|
35
|
+
BASE_TX = 'BaseTx',
|
|
36
|
+
TRANSFER_SUBNET_OWNERSHIP_TX = 'TransferSubnetOwnershipTx',
|
|
37
|
+
UNKNOWN = 'UNKNOWN',
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export enum XChainTransactionType {
|
|
41
|
+
BASE_TX = 'BaseTx',
|
|
42
|
+
CREATE_ASSET_TX = 'CreateAssetTx',
|
|
43
|
+
OPERATION_TX = 'OperationTx',
|
|
44
|
+
IMPORT_TX = 'ImportTx',
|
|
45
|
+
EXPORT_TX = 'ExportTx',
|
|
46
|
+
UNKNOWN = 'UNKNOWN',
|
|
47
|
+
}
|
|
48
|
+
|
|
19
49
|
export enum TokenType {
|
|
20
50
|
NATIVE = 'NATIVE',
|
|
21
51
|
ERC20 = 'ERC20',
|
|
@@ -24,10 +54,11 @@ export enum TokenType {
|
|
|
24
54
|
}
|
|
25
55
|
|
|
26
56
|
export type NetworkFees = {
|
|
27
|
-
low: {
|
|
28
|
-
medium: {
|
|
29
|
-
high: {
|
|
57
|
+
low: { maxFeePerGas: bigint; maxPriorityFeePerGas?: bigint };
|
|
58
|
+
medium: { maxFeePerGas: bigint; maxPriorityFeePerGas?: bigint };
|
|
59
|
+
high: { maxFeePerGas: bigint; maxPriorityFeePerGas?: bigint };
|
|
30
60
|
baseFee: bigint;
|
|
61
|
+
isFixedFee: boolean;
|
|
31
62
|
};
|
|
32
63
|
|
|
33
64
|
export enum RpcMethod {
|
|
@@ -39,17 +70,29 @@ export enum RpcMethod {
|
|
|
39
70
|
SIGN_TYPED_DATA = 'eth_signTypedData',
|
|
40
71
|
PERSONAL_SIGN = 'personal_sign',
|
|
41
72
|
ETH_SIGN = 'eth_sign',
|
|
42
|
-
WALLET_ADD_ETHEREUM_CHAIN = 'wallet_addEthereumChain',
|
|
43
|
-
WALLET_SWITCH_ETHEREUM_CHAIN = 'wallet_switchEthereumChain',
|
|
44
|
-
WALLET_GET_ETHEREUM_CHAIN = 'wallet_getEthereumChain',
|
|
45
73
|
}
|
|
46
74
|
|
|
75
|
+
export type DappInfo = {
|
|
76
|
+
name: string;
|
|
77
|
+
url: string;
|
|
78
|
+
icon: string;
|
|
79
|
+
};
|
|
80
|
+
|
|
47
81
|
export type RpcRequest = {
|
|
82
|
+
requestId: string;
|
|
83
|
+
sessionId: string;
|
|
48
84
|
method: RpcMethod;
|
|
85
|
+
chainId: Caip2ChainId;
|
|
49
86
|
params: unknown;
|
|
87
|
+
dappInfo: DappInfo;
|
|
88
|
+
context?: Record<string, unknown>; // for storing additional context information that's only relevant to the consumer
|
|
50
89
|
};
|
|
51
90
|
|
|
52
|
-
export type
|
|
91
|
+
export type RpcError =
|
|
92
|
+
| JsonRpcError<OptionalDataWithOptionalCause>
|
|
93
|
+
| EthereumProviderError<OptionalDataWithOptionalCause>;
|
|
94
|
+
|
|
95
|
+
export type RpcResponse<R = unknown, E extends RpcError = JsonRpcError<OptionalDataWithOptionalCause>> =
|
|
53
96
|
| {
|
|
54
97
|
result: R;
|
|
55
98
|
}
|
|
@@ -57,35 +100,34 @@ export type RpcResponse<R = unknown, E extends Error = Error> =
|
|
|
57
100
|
error: E;
|
|
58
101
|
};
|
|
59
102
|
|
|
60
|
-
export type
|
|
103
|
+
export type Network = {
|
|
104
|
+
chainId: number;
|
|
105
|
+
chainName: string;
|
|
106
|
+
rpcUrl: string;
|
|
107
|
+
networkToken: NetworkToken;
|
|
108
|
+
utilityAddresses?: {
|
|
109
|
+
multicall: string;
|
|
110
|
+
};
|
|
111
|
+
logoUrl?: string;
|
|
61
112
|
isTestnet?: boolean;
|
|
62
|
-
|
|
63
|
-
chainName?: string;
|
|
64
|
-
rpcUrl?: string;
|
|
65
|
-
multiContractAddress?: string;
|
|
113
|
+
explorerUrl?: string;
|
|
66
114
|
};
|
|
67
115
|
|
|
68
|
-
export type GetNetworkFeeParams = Chain;
|
|
69
|
-
|
|
70
116
|
export interface Module {
|
|
71
117
|
getManifest: () => Manifest | undefined;
|
|
72
118
|
getBalances: () => Promise<string>;
|
|
73
119
|
getTransactionHistory: (params: GetTransactionHistory) => Promise<TransactionHistoryResponse>;
|
|
74
|
-
getNetworkFee: (
|
|
120
|
+
getNetworkFee: (network: Network) => Promise<NetworkFees>;
|
|
75
121
|
getAddress: () => Promise<string>;
|
|
76
|
-
getTokens: (
|
|
77
|
-
onRpcRequest: (request: RpcRequest) => Promise<RpcResponse>;
|
|
122
|
+
getTokens: (network: Network) => Promise<NetworkContractToken[]>;
|
|
123
|
+
onRpcRequest: (request: RpcRequest, network: Network) => Promise<RpcResponse>;
|
|
78
124
|
}
|
|
79
125
|
|
|
80
126
|
export type GetTransactionHistory = {
|
|
81
|
-
|
|
82
|
-
isTestnet: boolean;
|
|
83
|
-
networkToken: NetworkToken;
|
|
84
|
-
explorerUrl: string;
|
|
127
|
+
network: Network;
|
|
85
128
|
address: string;
|
|
86
129
|
nextPageToken?: string;
|
|
87
130
|
offset?: number;
|
|
88
|
-
glacierApiUrl?: string;
|
|
89
131
|
};
|
|
90
132
|
|
|
91
133
|
export type TransactionHistoryResponse = {
|
|
@@ -105,7 +147,7 @@ export type Transaction = {
|
|
|
105
147
|
tokens: TxToken[];
|
|
106
148
|
gasPrice?: string;
|
|
107
149
|
gasUsed: string;
|
|
108
|
-
txType?: TransactionType;
|
|
150
|
+
txType?: TransactionType | PChainTransactionType | XChainTransactionType;
|
|
109
151
|
chainId: string; // chainId from ActiveNetwork used to fetch tx
|
|
110
152
|
method?: string;
|
|
111
153
|
explorerLink: string;
|
|
@@ -203,3 +245,84 @@ export type Manifest = z.infer<typeof manifestSchema>;
|
|
|
203
245
|
export const parseManifest = (params: unknown): z.SafeParseReturnType<unknown, Manifest> => {
|
|
204
246
|
return manifestSchema.safeParse(params);
|
|
205
247
|
};
|
|
248
|
+
|
|
249
|
+
export type Caip2ChainId = string;
|
|
250
|
+
|
|
251
|
+
export type Hex = `0x${string}`;
|
|
252
|
+
|
|
253
|
+
export enum Environment {
|
|
254
|
+
PRODUCTION = 'production',
|
|
255
|
+
DEV = 'dev',
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export type DisplayData = {
|
|
259
|
+
title: string;
|
|
260
|
+
network: {
|
|
261
|
+
chainId: number;
|
|
262
|
+
name: string;
|
|
263
|
+
logoUrl?: string;
|
|
264
|
+
};
|
|
265
|
+
messageDetails?: string;
|
|
266
|
+
transactionDetails?: {
|
|
267
|
+
website: string;
|
|
268
|
+
from: string;
|
|
269
|
+
to: string;
|
|
270
|
+
data?: string;
|
|
271
|
+
};
|
|
272
|
+
networkFeeSelector?: boolean;
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Enum for different types of signing data.
|
|
277
|
+
*/
|
|
278
|
+
export enum SigningDataType {
|
|
279
|
+
// EVM signing data types
|
|
280
|
+
EVM_TRANSACTION = 'evm_transaction',
|
|
281
|
+
EVM_MESSAGE_ETH_SIGN = 'evm_message_eth_sign',
|
|
282
|
+
EVM_MESSAGE_PERSONAL_SIGN = 'evm_message_personal_sign',
|
|
283
|
+
EVM_MESSAGE_ETH_SIGN_TYPED_DATA = 'evm_message_eth_sign_typed_data',
|
|
284
|
+
EVM_MESSAGE_ETH_SIGN_TYPED_DATA_V1 = 'evm_message_eth_sign_typed_data_v1',
|
|
285
|
+
EVM_MESSAGE_ETH_SIGN_TYPED_DATA_V3 = 'evm_message_eth_sign_typed_data_v3',
|
|
286
|
+
EVM_MESSAGE_ETH_SIGN_TYPED_DATA_V4 = 'evm_message_eth_sign_typed_data_v4',
|
|
287
|
+
|
|
288
|
+
// Avalanche signing data types
|
|
289
|
+
AVALANCHE_TRANSACTION = 'avalanche_transaction',
|
|
290
|
+
AVALANCHE_MESSAGE = 'avalanche_message',
|
|
291
|
+
|
|
292
|
+
// Bitcoin signing data types
|
|
293
|
+
BTC_TRANSACTION = 'btc_transaction',
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export type SigningData =
|
|
297
|
+
| {
|
|
298
|
+
type: SigningDataType.EVM_TRANSACTION;
|
|
299
|
+
account: string;
|
|
300
|
+
chainId: number;
|
|
301
|
+
data: TransactionRequest;
|
|
302
|
+
}
|
|
303
|
+
| {
|
|
304
|
+
type: SigningDataType.EVM_MESSAGE_ETH_SIGN;
|
|
305
|
+
account: string;
|
|
306
|
+
chainId: number;
|
|
307
|
+
data: string;
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
export type ApprovalParams = {
|
|
311
|
+
request: RpcRequest;
|
|
312
|
+
displayData: DisplayData;
|
|
313
|
+
signingData: SigningData;
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
export type ApprovalResponse =
|
|
317
|
+
| {
|
|
318
|
+
result: Hex;
|
|
319
|
+
}
|
|
320
|
+
| {
|
|
321
|
+
error: RpcError;
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
export interface ApprovalController {
|
|
325
|
+
requestApproval: (params: ApprovalParams) => Promise<ApprovalResponse>;
|
|
326
|
+
onTransactionConfirmed: (txHash: Hex) => void;
|
|
327
|
+
onTransactionReverted: (txHash: Hex) => void;
|
|
328
|
+
}
|
package/tsconfig.json
CHANGED
package/tsup.config.ts
ADDED