@rocketh/export 0.10.12 → 0.10.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/package.json +4 -1
- package/.prettierignore +0 -3
- package/.prettierrc +0 -7
- package/CHANGELOG.md +0 -84
- package/src/cli.ts +0 -40
- package/src/index.ts +0 -271
- package/tsconfig.json +0 -18
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rocketh/export",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.13",
|
|
4
4
|
"description": "export deployments",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -17,6 +17,9 @@
|
|
|
17
17
|
"bin": {
|
|
18
18
|
"rocketh-export": "dist/esm/cli.js"
|
|
19
19
|
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
20
23
|
"devDependencies": {
|
|
21
24
|
"@types/node": "^20.14.8",
|
|
22
25
|
"abitype": "^1.0.4",
|
package/.prettierignore
DELETED
package/.prettierrc
DELETED
package/CHANGELOG.md
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
# @rocketh/export
|
|
2
|
-
|
|
3
|
-
## 0.10.12
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- use tsx
|
|
8
|
-
- Updated dependencies
|
|
9
|
-
- rocketh@0.10.16
|
|
10
|
-
|
|
11
|
-
## 0.10.11
|
|
12
|
-
|
|
13
|
-
### Patch Changes
|
|
14
|
-
|
|
15
|
-
- Updated dependencies
|
|
16
|
-
- rocketh@0.10.15
|
|
17
|
-
|
|
18
|
-
## 0.10.10
|
|
19
|
-
|
|
20
|
-
### Patch Changes
|
|
21
|
-
|
|
22
|
-
- allow to export each contract as individual exported field
|
|
23
|
-
|
|
24
|
-
## 0.10.9
|
|
25
|
-
|
|
26
|
-
### Patch Changes
|
|
27
|
-
|
|
28
|
-
- export argsData when exporting bytecode
|
|
29
|
-
|
|
30
|
-
## 0.10.8
|
|
31
|
-
|
|
32
|
-
### Patch Changes
|
|
33
|
-
|
|
34
|
-
- latest dependencies
|
|
35
|
-
- Updated dependencies
|
|
36
|
-
- rocketh@0.10.14
|
|
37
|
-
|
|
38
|
-
## 0.10.7
|
|
39
|
-
|
|
40
|
-
### Patch Changes
|
|
41
|
-
|
|
42
|
-
- Updated dependencies
|
|
43
|
-
- rocketh@0.10.13
|
|
44
|
-
|
|
45
|
-
## 0.10.6
|
|
46
|
-
|
|
47
|
-
### Patch Changes
|
|
48
|
-
|
|
49
|
-
- Updated dependencies
|
|
50
|
-
- rocketh@0.10.12
|
|
51
|
-
|
|
52
|
-
## 0.10.5
|
|
53
|
-
|
|
54
|
-
### Patch Changes
|
|
55
|
-
|
|
56
|
-
- forgot to build
|
|
57
|
-
|
|
58
|
-
## 0.10.4
|
|
59
|
-
|
|
60
|
-
### Patch Changes
|
|
61
|
-
|
|
62
|
-
- chalk do not support cjs
|
|
63
|
-
|
|
64
|
-
## 0.10.3
|
|
65
|
-
|
|
66
|
-
### Patch Changes
|
|
67
|
-
|
|
68
|
-
- Updated dependencies
|
|
69
|
-
- rocketh@0.10.11
|
|
70
|
-
|
|
71
|
-
## 0.10.2
|
|
72
|
-
|
|
73
|
-
### Patch Changes
|
|
74
|
-
|
|
75
|
-
- Updated dependencies
|
|
76
|
-
- rocketh@0.10.10
|
|
77
|
-
|
|
78
|
-
## 0.10.1
|
|
79
|
-
|
|
80
|
-
### Patch Changes
|
|
81
|
-
|
|
82
|
-
- use pkgroll and @rocketh namespace
|
|
83
|
-
- Updated dependencies
|
|
84
|
-
- rocketh@0.10.9
|
package/src/cli.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
import {readAndResolveConfig} from 'rocketh';
|
|
3
|
-
import {run} from './index.js';
|
|
4
|
-
import {Command} from 'commander';
|
|
5
|
-
import pkg from '../package.json' with {type: 'json'};
|
|
6
|
-
import {ConfigOptions} from 'rocketh';
|
|
7
|
-
|
|
8
|
-
const commandName = pkg.name;
|
|
9
|
-
|
|
10
|
-
const program = new Command();
|
|
11
|
-
program
|
|
12
|
-
.name(commandName)
|
|
13
|
-
.description('export deployments to consume elswhere')
|
|
14
|
-
.version(pkg.version)
|
|
15
|
-
.option('-d, --deployments <value>', 'folder where deployments are saved')
|
|
16
|
-
.option('--ts <value>', 'list of filepath where the typescript export will be written, separated by commas')
|
|
17
|
-
.option('--js <value>', 'list of filepath where the javascript export will be written, separated by commas')
|
|
18
|
-
.option('--json <value>', 'list of filepath where the json export will be written, separated by commas')
|
|
19
|
-
.option(
|
|
20
|
-
'--tsm <value>',
|
|
21
|
-
'list of filepath where the typescript export with individual export will be written, separated by commas'
|
|
22
|
-
)
|
|
23
|
-
.option(
|
|
24
|
-
'--jsm <value>',
|
|
25
|
-
'list of filepath where the javascript export with individual exportwill be written, separated by commas'
|
|
26
|
-
)
|
|
27
|
-
.option('-b, --bytecode', 'if set, the bytecode will also be part of the output')
|
|
28
|
-
.requiredOption('-n, --network <value>', 'network context to use')
|
|
29
|
-
.parse(process.argv);
|
|
30
|
-
|
|
31
|
-
const options = program.opts();
|
|
32
|
-
const resolvedConfig = readAndResolveConfig({...(options as ConfigOptions), ignoreMissingRPC: true});
|
|
33
|
-
run(resolvedConfig, {
|
|
34
|
-
tots: options.ts ? options.ts.split(',') : undefined,
|
|
35
|
-
tojson: options.json ? options.json.split(',') : undefined,
|
|
36
|
-
tojs: options.js ? options.js.split(',') : undefined,
|
|
37
|
-
totsm: options.tsm ? options.tsm.split(',') : undefined,
|
|
38
|
-
tojsm: options.jsm ? options.jsm.split(',') : undefined,
|
|
39
|
-
includeBytecode: options.bytecode,
|
|
40
|
-
});
|
package/src/index.ts
DELETED
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
import {Abi, Address} from 'abitype';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
|
|
5
|
-
import {Deployment, ResolvedConfig, chainTypes, getChain, loadDeployments} from 'rocketh';
|
|
6
|
-
|
|
7
|
-
export interface ContractExport {
|
|
8
|
-
address: `0x${string}`;
|
|
9
|
-
abi: Abi;
|
|
10
|
-
argsData?: string;
|
|
11
|
-
bytecode?: `0x${string}`;
|
|
12
|
-
// linkedData?: any; TODO
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
type ChainBlockExplorer = {
|
|
16
|
-
name: string;
|
|
17
|
-
url: string;
|
|
18
|
-
apiUrl?: string | undefined;
|
|
19
|
-
};
|
|
20
|
-
type ChainContract = {
|
|
21
|
-
address: Address;
|
|
22
|
-
blockCreated?: number | undefined;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
type ChainNativeCurrency = {
|
|
26
|
-
name: string;
|
|
27
|
-
/** 2-6 characters long */
|
|
28
|
-
symbol: string;
|
|
29
|
-
decimals: number;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
type ChainRpcUrls = {
|
|
33
|
-
http: readonly string[];
|
|
34
|
-
webSocket?: readonly string[] | undefined;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @description Combines members of an intersection into a readable type.
|
|
39
|
-
*
|
|
40
|
-
* @see {@link https://twitter.com/mattpocockuk/status/1622730173446557697?s=20&t=NdpAcmEFXY01xkqU3KO0Mg}
|
|
41
|
-
* @example
|
|
42
|
-
* Prettify<{ a: string } & { b: string } & { c: number, d: bigint }>
|
|
43
|
-
* => { a: string, b: string, c: number, d: bigint }
|
|
44
|
-
*/
|
|
45
|
-
type Prettify<T> = {
|
|
46
|
-
[K in keyof T]: T[K];
|
|
47
|
-
} & {};
|
|
48
|
-
|
|
49
|
-
export type ChainInfo = {
|
|
50
|
-
/** ID in number form */
|
|
51
|
-
id: number;
|
|
52
|
-
/** Human-readable name */
|
|
53
|
-
name: string;
|
|
54
|
-
/** Collection of block explorers */
|
|
55
|
-
blockExplorers?:
|
|
56
|
-
| {
|
|
57
|
-
[key: string]: ChainBlockExplorer;
|
|
58
|
-
default: ChainBlockExplorer;
|
|
59
|
-
}
|
|
60
|
-
| undefined;
|
|
61
|
-
/** Collection of contracts */
|
|
62
|
-
contracts?:
|
|
63
|
-
| Prettify<
|
|
64
|
-
{
|
|
65
|
-
[key: string]: ChainContract | {[sourceId: number]: ChainContract | undefined} | undefined;
|
|
66
|
-
} & {
|
|
67
|
-
ensRegistry?: ChainContract | undefined;
|
|
68
|
-
ensUniversalResolver?: ChainContract | undefined;
|
|
69
|
-
multicall3?: ChainContract | undefined;
|
|
70
|
-
}
|
|
71
|
-
>
|
|
72
|
-
| undefined;
|
|
73
|
-
/** Currency used by chain */
|
|
74
|
-
nativeCurrency: ChainNativeCurrency;
|
|
75
|
-
/** Collection of RPC endpoints */
|
|
76
|
-
rpcUrls: {
|
|
77
|
-
[key: string]: ChainRpcUrls;
|
|
78
|
-
default: ChainRpcUrls;
|
|
79
|
-
};
|
|
80
|
-
/** Source Chain ID (ie. the L1 chain) */
|
|
81
|
-
sourceId?: number | undefined;
|
|
82
|
-
/** Flag for test networks */
|
|
83
|
-
testnet?: boolean | undefined;
|
|
84
|
-
|
|
85
|
-
chainType: 'zksync' | 'op-stack' | 'celo' | 'default';
|
|
86
|
-
|
|
87
|
-
// this will bring in the following when reconstructed from the data above
|
|
88
|
-
|
|
89
|
-
// /** Custom chain data. */
|
|
90
|
-
// custom?: any;
|
|
91
|
-
|
|
92
|
-
// /**
|
|
93
|
-
// * Modifies how chain data structures (ie. Blocks, Transactions, etc)
|
|
94
|
-
// * are formatted & typed.
|
|
95
|
-
// */
|
|
96
|
-
// formatters?: any | undefined;
|
|
97
|
-
// /** Modifies how data (ie. Transactions) is serialized. */
|
|
98
|
-
// serializers?: any | undefined;
|
|
99
|
-
// /** Modifies how fees are derived. */
|
|
100
|
-
// fees?: any | undefined;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
export type ExportedDeployments = {
|
|
104
|
-
chainId: string;
|
|
105
|
-
genesisHash?: string;
|
|
106
|
-
chainInfo: ChainInfo;
|
|
107
|
-
name: string;
|
|
108
|
-
contracts: {[name: string]: ContractExport};
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
type Trandformed<O, Value> = {
|
|
112
|
-
[Property in keyof O]: Value;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
function objectMap<V, N, O extends Trandformed<{}, V> = Trandformed<{}, V>>(
|
|
116
|
-
object: O,
|
|
117
|
-
mapFn: (v: V) => N
|
|
118
|
-
): Trandformed<O, N> {
|
|
119
|
-
return Object.keys(object).reduce((result, key) => {
|
|
120
|
-
(result as any)[key] = mapFn((object as any)[key]);
|
|
121
|
-
return result;
|
|
122
|
-
}, {} as Trandformed<O, N>);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export async function run(
|
|
126
|
-
config: ResolvedConfig,
|
|
127
|
-
options: {
|
|
128
|
-
tojs?: string[];
|
|
129
|
-
tots?: string[];
|
|
130
|
-
tojson?: string[];
|
|
131
|
-
totsm?: string[];
|
|
132
|
-
tojsm?: string[];
|
|
133
|
-
includeBytecode?: boolean;
|
|
134
|
-
}
|
|
135
|
-
) {
|
|
136
|
-
if (!options.tots && !options.tojs && !options.tojson && !options.tojsm && !options.totsm) {
|
|
137
|
-
console.log(`no filepath to export to are specified`);
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const {deployments, chainId, genesisHash} = loadDeployments(config.deployments, config.network.name);
|
|
142
|
-
|
|
143
|
-
if (!deployments || Object.keys(deployments).length === 0) {
|
|
144
|
-
console.log(`no deployments to export`);
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (!chainId) {
|
|
149
|
-
throw new Error(`no chainId found for ${config.network.name}`);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const chain = getChain(chainId);
|
|
153
|
-
|
|
154
|
-
const chainInfo: ChainInfo = {
|
|
155
|
-
id: chain.id,
|
|
156
|
-
name: chain.name,
|
|
157
|
-
nativeCurrency: chain.nativeCurrency,
|
|
158
|
-
rpcUrls: chain.rpcUrls,
|
|
159
|
-
blockExplorers: chain.blockExplorers,
|
|
160
|
-
chainType: chainTypes[chainId] || 'default',
|
|
161
|
-
contracts: chain.contracts,
|
|
162
|
-
sourceId: chain.sourceId,
|
|
163
|
-
testnet: chain.testnet,
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
const exportData: ExportedDeployments = {
|
|
167
|
-
chainId,
|
|
168
|
-
genesisHash,
|
|
169
|
-
chainInfo,
|
|
170
|
-
contracts: objectMap<Deployment<Abi>, ContractExport>(deployments, (d) => ({
|
|
171
|
-
abi: d.abi,
|
|
172
|
-
address: d.address,
|
|
173
|
-
linkedData: d.linkedData,
|
|
174
|
-
bytecode: options.includeBytecode ? d.bytecode : undefined,
|
|
175
|
-
argsData: options.includeBytecode ? d.argsData : undefined,
|
|
176
|
-
startBlock: d.receipt?.blockNumber ? parseInt(d.receipt.blockNumber.slice(2), 16) : undefined,
|
|
177
|
-
})),
|
|
178
|
-
name: config.network.name,
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
const js = typeof options.tojs === 'string' ? [options.tojs] : options.tojs || [];
|
|
182
|
-
const ts = typeof options.tots === 'string' ? [options.tots] : options.tots || [];
|
|
183
|
-
const json = typeof options.tojson === 'string' ? [options.tojson] : options.tojson || [];
|
|
184
|
-
|
|
185
|
-
const tsmodule = typeof options.totsm === 'string' ? [options.totsm] : options.totsm || [];
|
|
186
|
-
const jsmodule = typeof options.tojsm === 'string' ? [options.tojsm] : options.tojsm || [];
|
|
187
|
-
|
|
188
|
-
if (ts.length > 0) {
|
|
189
|
-
const newContent = `export default ${JSON.stringify(exportData, null, 2)} as const;`;
|
|
190
|
-
for (const tsFile of ts) {
|
|
191
|
-
const folderPath = path.dirname(tsFile);
|
|
192
|
-
fs.mkdirSync(folderPath, {recursive: true});
|
|
193
|
-
fs.writeFileSync(tsFile, newContent);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
if (js.length > 0) {
|
|
198
|
-
const newContent = `export default /** @type {const} **/ (${JSON.stringify(exportData, null, 2)});`;
|
|
199
|
-
const dtsContent = `export = ${JSON.stringify(exportData, null, 2)} as const;`;
|
|
200
|
-
for (const jsFile of js) {
|
|
201
|
-
const folderPath = path.dirname(jsFile);
|
|
202
|
-
fs.mkdirSync(folderPath, {recursive: true});
|
|
203
|
-
fs.writeFileSync(jsFile, newContent);
|
|
204
|
-
fs.writeFileSync(jsFile.replace('.js', '.d.ts'), dtsContent);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
if (json.length > 0) {
|
|
209
|
-
const newContent = JSON.stringify(exportData, null, 2);
|
|
210
|
-
for (const jsonFile of json) {
|
|
211
|
-
const folderPath = path.dirname(jsonFile);
|
|
212
|
-
fs.mkdirSync(folderPath, {recursive: true});
|
|
213
|
-
fs.writeFileSync(jsonFile, newContent);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
if (tsmodule.length > 0) {
|
|
218
|
-
let newContent = `export const chain = ${JSON.stringify(
|
|
219
|
-
{
|
|
220
|
-
chainId: exportData.chainId,
|
|
221
|
-
genesisHash: exportData.genesisHash,
|
|
222
|
-
chainInfo: exportData.chainInfo,
|
|
223
|
-
name: exportData.name,
|
|
224
|
-
},
|
|
225
|
-
null,
|
|
226
|
-
2
|
|
227
|
-
)} as const;\n`;
|
|
228
|
-
|
|
229
|
-
for (const contractName of Object.keys(exportData.contracts)) {
|
|
230
|
-
newContent += `export const ${contractName} = ${JSON.stringify(
|
|
231
|
-
(exportData.contracts as any)[contractName],
|
|
232
|
-
null,
|
|
233
|
-
2
|
|
234
|
-
)} as const;`;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
for (const tsFile of tsmodule) {
|
|
238
|
-
const folderPath = path.dirname(tsFile);
|
|
239
|
-
fs.mkdirSync(folderPath, {recursive: true});
|
|
240
|
-
fs.writeFileSync(tsFile, newContent);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
if (jsmodule.length > 0) {
|
|
245
|
-
// TODO test
|
|
246
|
-
let newContent = `export const chain = /** @type {const} **/ (${JSON.stringify(
|
|
247
|
-
{
|
|
248
|
-
chainId: exportData.chainId,
|
|
249
|
-
genesisHash: exportData.genesisHash,
|
|
250
|
-
chainInfo: exportData.chainInfo,
|
|
251
|
-
name: exportData.name,
|
|
252
|
-
},
|
|
253
|
-
null,
|
|
254
|
-
2
|
|
255
|
-
)});\n`;
|
|
256
|
-
|
|
257
|
-
for (const contractName of Object.keys(exportData.contracts)) {
|
|
258
|
-
newContent += `export const ${contractName} = /** @type {const} **/ (${JSON.stringify(
|
|
259
|
-
(exportData.contracts as any)[contractName],
|
|
260
|
-
null,
|
|
261
|
-
2
|
|
262
|
-
)});`;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
for (const jsFile of jsmodule) {
|
|
266
|
-
const folderPath = path.dirname(jsFile);
|
|
267
|
-
fs.mkdirSync(folderPath, {recursive: true});
|
|
268
|
-
fs.writeFileSync(jsFile, newContent);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"strict": true,
|
|
4
|
-
"strictNullChecks": true,
|
|
5
|
-
"target": "ESNext",
|
|
6
|
-
"module": "NodeNext",
|
|
7
|
-
"lib": ["ESNext", "dom"],
|
|
8
|
-
"moduleResolution": "NodeNext",
|
|
9
|
-
"resolveJsonModule": true,
|
|
10
|
-
"skipLibCheck": true,
|
|
11
|
-
"sourceMap": true,
|
|
12
|
-
"declaration": true,
|
|
13
|
-
"declarationMap": true,
|
|
14
|
-
"rootDir": "./src",
|
|
15
|
-
"outDir": "./dist/esm"
|
|
16
|
-
},
|
|
17
|
-
"include": ["src/**/*.ts"]
|
|
18
|
-
}
|