@avalabs/vm-module-types 0.0.0-CP-8800-20240626134307

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.
@@ -0,0 +1,4 @@
1
+
2
+ > @avalabs/vm-module-types@0.0.9 lint /home/runner/work/vm-modules/vm-modules/packages/types
3
+ > eslint "src/**/*.ts"
4
+
package/CHANGELOG.md ADDED
@@ -0,0 +1,43 @@
1
+ # @avalabs/vm-module-types
2
+
3
+ ## 0.0.0-CP-8800-20240626134307
4
+
5
+ ### Patch Changes
6
+
7
+ - 985ab0d: add getTokens function
8
+
9
+ ## 0.0.9
10
+
11
+ ### Patch Changes
12
+
13
+ - 6ffa356: add module functions to evm-module
14
+
15
+ ## 0.0.8
16
+
17
+ ### Patch Changes
18
+
19
+ - d1d080f: test release
20
+
21
+ ## 0.0.7
22
+
23
+ ### Patch Changes
24
+
25
+ - bb98621: Move types to @avalabs/vm-module-types
26
+
27
+ ## 0.0.6
28
+
29
+ ### Patch Changes
30
+
31
+ - 1122704: test release
32
+
33
+ ## 0.0.3
34
+
35
+ ### Patch Changes
36
+
37
+ - 0b0c52e: Move types to @avalabs/vm-module-types
38
+
39
+ ## 0.0.2
40
+
41
+ ### Patch Changes
42
+
43
+ - 4b7d5e9: Move types from packages-internal/types to packages/types
package/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # VM Module Types
2
+
3
+ ## Overview
4
+
5
+ This package exposes the types for the VM modules
6
+
7
+ ## Installation
8
+
9
+ The module is privately available on NPM as `@avalabs/vm-module-types`
package/package.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "@avalabs/vm-module-types",
3
+ "version": "0.0.0-CP-8800-20240626134307",
4
+ "main": "src/index.ts",
5
+ "dependencies": {
6
+ "zod": "3.23.8"
7
+ },
8
+ "devDependencies": {
9
+ "eslint-config-custom": "0.0.1"
10
+ },
11
+ "scripts": {
12
+ "lint": "eslint \"src/**/*.ts\""
13
+ }
14
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './types';
package/src/types.ts ADDED
@@ -0,0 +1,205 @@
1
+ import { object, string, boolean, z } from 'zod';
2
+
3
+ export enum TransactionType {
4
+ BRIDGE = 'Bridge',
5
+ SWAP = 'Swap',
6
+ SEND = 'Send',
7
+ RECEIVE = 'Receive',
8
+ NFT_BUY = 'NFTBuy',
9
+ APPROVE = 'Approve',
10
+ TRANSFER = 'Transfer',
11
+ NFT_SEND = 'NFTSend',
12
+ NFT_RECEIVE = 'NFTReceive',
13
+ AIRDROP = 'Airdrop',
14
+ FILL_ORDER = 'FillOrder',
15
+ UNWRAP = 'Unwrap',
16
+ UNKNOWN = 'UNKNOWN',
17
+ }
18
+
19
+ export enum TokenType {
20
+ NATIVE = 'NATIVE',
21
+ ERC20 = 'ERC20',
22
+ ERC721 = 'ERC721',
23
+ ERC1155 = 'ERC1155',
24
+ }
25
+
26
+ export type NetworkFees = {
27
+ low: { maxPriorityFeePerGas: bigint; maxFeePerGas: bigint };
28
+ medium: { maxPriorityFeePerGas: bigint; maxFeePerGas: bigint };
29
+ high: { maxPriorityFeePerGas: bigint; maxFeePerGas: bigint };
30
+ baseFee: bigint;
31
+ };
32
+
33
+ export enum RpcMethod {
34
+ /* EVM */
35
+ ETH_SEND_TRANSACTION = 'eth_sendTransaction',
36
+ SIGN_TYPED_DATA_V3 = 'eth_signTypedData_v3',
37
+ SIGN_TYPED_DATA_V4 = 'eth_signTypedData_v4',
38
+ SIGN_TYPED_DATA_V1 = 'eth_signTypedData_v1',
39
+ SIGN_TYPED_DATA = 'eth_signTypedData',
40
+ PERSONAL_SIGN = 'personal_sign',
41
+ 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
+ }
46
+
47
+ export type RpcRequest = {
48
+ method: RpcMethod;
49
+ params: unknown;
50
+ };
51
+
52
+ export type RpcResponse<R = unknown, E extends Error = Error> =
53
+ | {
54
+ result: R;
55
+ }
56
+ | {
57
+ error: E;
58
+ };
59
+
60
+ export type Chain = {
61
+ isTestnet?: boolean;
62
+ chainId?: string;
63
+ chainName?: string;
64
+ rpcUrl?: string;
65
+ multiContractAddress?: string;
66
+ };
67
+
68
+ export type GetNetworkFeeParams = Chain;
69
+
70
+ export interface Module {
71
+ getManifest: () => Manifest | undefined;
72
+ getBalances: () => Promise<string>;
73
+ getTransactionHistory: (params: GetTransactionHistory) => Promise<TransactionHistoryResponse>;
74
+ getNetworkFee: (params: GetNetworkFeeParams) => Promise<NetworkFees>;
75
+ getAddress: () => Promise<string>;
76
+ getTokens: (chainId: number) => Promise<NetworkContractToken[]>;
77
+ onRpcRequest: (request: RpcRequest) => Promise<RpcResponse>;
78
+ }
79
+
80
+ export type GetTransactionHistory = {
81
+ chainId: number;
82
+ isTestnet: boolean;
83
+ networkToken: NetworkToken;
84
+ explorerUrl: string;
85
+ address: string;
86
+ nextPageToken?: string;
87
+ offset?: number;
88
+ glacierApiUrl?: string;
89
+ };
90
+
91
+ export type TransactionHistoryResponse = {
92
+ transactions: Transaction[];
93
+ nextPageToken?: string;
94
+ };
95
+
96
+ export type Transaction = {
97
+ isContractCall: boolean;
98
+ isIncoming: boolean;
99
+ isOutgoing: boolean;
100
+ isSender: boolean;
101
+ timestamp: number;
102
+ hash: string;
103
+ from: string;
104
+ to: string;
105
+ tokens: TxToken[];
106
+ gasPrice?: string;
107
+ gasUsed: string;
108
+ txType?: TransactionType;
109
+ chainId: string; // chainId from ActiveNetwork used to fetch tx
110
+ method?: string;
111
+ explorerLink: string;
112
+ };
113
+
114
+ export interface TxToken {
115
+ decimal?: string;
116
+ name: string;
117
+ symbol: string;
118
+ amount: string;
119
+ imageUri?: string;
120
+ from?: RichAddress;
121
+ to?: RichAddress;
122
+ collectableTokenId?: string;
123
+ type: TokenType;
124
+ }
125
+
126
+ type RichAddress = {
127
+ /**
128
+ * The contract name.
129
+ */
130
+ name?: string;
131
+ /**
132
+ * The contract symbol.
133
+ */
134
+ symbol?: string;
135
+ /**
136
+ * The number of decimals the token uses. For example `6`, means to divide the token amount by `1000000` to get its user representation.
137
+ */
138
+ decimals?: number;
139
+ /**
140
+ * The logo uri for the address.
141
+ */
142
+ logoUri?: string;
143
+ /**
144
+ * A wallet or contract address in mixed-case checksum encoding.
145
+ */
146
+ address: string;
147
+ };
148
+
149
+ export interface NetworkToken {
150
+ name: string;
151
+ symbol: string;
152
+ description: string;
153
+ decimals: number;
154
+ logoUri: string;
155
+ }
156
+
157
+ export interface NetworkContractToken {
158
+ address: string;
159
+ chainId?: number;
160
+ color?: string;
161
+ contractType: string;
162
+ decimals: number;
163
+ logoUri?: string;
164
+ name: string;
165
+ symbol: string;
166
+ }
167
+
168
+ const sourceSchema = object({
169
+ checksum: string(),
170
+ location: object({
171
+ npm: object({
172
+ filePath: string(),
173
+ packageName: string(),
174
+ registry: string(),
175
+ }),
176
+ }),
177
+ });
178
+
179
+ const manifestSchema = object({
180
+ name: string(),
181
+ version: string(),
182
+ description: string(),
183
+ sources: object({
184
+ module: sourceSchema,
185
+ provider: sourceSchema.optional(),
186
+ }),
187
+ network: object({
188
+ chainIds: string().array(),
189
+ namespaces: string().array(),
190
+ }),
191
+ cointype: string(),
192
+ permissions: object({
193
+ rpc: object({
194
+ dapps: boolean(),
195
+ methods: string().array(),
196
+ }),
197
+ }),
198
+ manifestVersion: string(),
199
+ });
200
+
201
+ export type Manifest = z.infer<typeof manifestSchema>;
202
+
203
+ export const parseManifest = (params: unknown): z.SafeParseReturnType<unknown, Manifest> => {
204
+ return manifestSchema.safeParse(params);
205
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "@internal/tsconfig/tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "composite": true
6
+ },
7
+ "include": ["src"]
8
+ }