@agoric/deploy-script-support 0.10.4-dev-f04cf72.0 → 0.10.4-dev-fab25c1.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/deploy-script-support",
3
- "version": "0.10.4-dev-f04cf72.0+f04cf72",
3
+ "version": "0.10.4-dev-fab25c1.0+fab25c1",
4
4
  "description": "Helpers and other support for writing deploy scripts",
5
5
  "type": "module",
6
6
  "main": "src/helpers.js",
@@ -38,6 +38,7 @@
38
38
  "@agoric/import-manager": "workspace:*",
39
39
  "@agoric/internal": "workspace:*",
40
40
  "@agoric/notifier": "workspace:*",
41
+ "@agoric/pola-io": "workspace:*",
41
42
  "@agoric/store": "workspace:*",
42
43
  "@agoric/time": "workspace:*",
43
44
  "@agoric/zoe": "workspace:*",
@@ -74,5 +75,5 @@
74
75
  "typeCoverage": {
75
76
  "atLeast": 83.92
76
77
  },
77
- "gitHead": "f04cf725b3b98261b2fdcd978d44c584930c9c2f"
78
+ "gitHead": "fab25c1d7df5590379b9d71d12d4b72500652932"
78
79
  }
@@ -0,0 +1,147 @@
1
+ /**
2
+ * @file support for Contract Deployment Process
3
+ *
4
+ * 1. `agoric run XYZ.build.js` produces:
5
+ * - `b1-123.json` bundle x 2: contract, aux
6
+ * - `XYZ-permit.json`, `XYZ.js` script
7
+ * 2. Install bundles
8
+ * - permissionless with per-byte fee in IST
9
+ * 3. Submit CoreEval proposal to BLD stakers
10
+ * - `XYZ-permit.json`, `XYZ.js`
11
+ *
12
+ * @see {runBuilder}
13
+ * @see {installBundles}
14
+ * @see {submitCoreEval}
15
+ */
16
+ import { flags } from '@agoric/pola-io';
17
+
18
+ /**
19
+ * @import {CmdRunner} from '@agoric/pola-io';
20
+ * @import {FileRd} from '@agoric/pola-io';
21
+ */
22
+
23
+ /**
24
+ *
25
+ * TODO: builder should be a FileRd
26
+ * TODO: parameterize dest dir
27
+ *
28
+ * @example
29
+ * to use npx to find `agoric` in node_modules/.bin:
30
+ * const execP = promisify(childProcess.execFile)
31
+ * const agoric = makeCmdRunner('npx', { execFile: execP }).subCommand('agoric');
32
+ *
33
+ * XXX use a different name from execFile since the meaning is different
34
+ *
35
+ * @param {CmdRunner} agoric
36
+ * @param {FileRd} builder
37
+ * @param {Record<string, string | string[]>} [builderOpts]
38
+ * @param {{cwd?: FileRd}} [io]
39
+ *
40
+ * @returns {Promise<Plan>}
41
+ *
42
+ * @typedef {{
43
+ * name: string,
44
+ * script: string,
45
+ * permit: string,
46
+ * bundles: { entrypoint:string, bundleID:string, fileName:string}[];
47
+ * }} Plan
48
+ */
49
+ export const runBuilder = async (
50
+ agoric,
51
+ builder,
52
+ builderOpts = {},
53
+ { cwd = builder.join('../../') } = {},
54
+ ) => {
55
+ const cmd = agoric.withFlags(...(builderOpts ? flags(builderOpts) : []));
56
+ const { stdout } = await cmd.exec(['run', String(builder)]);
57
+ const match = stdout?.match(/ (?<name>[-\w]+)-permit.json/);
58
+ if (!(match && match.groups)) {
59
+ throw Error('no permit found');
60
+ }
61
+ /** @type {Plan} */
62
+ const plan = await cwd.join(`${match.groups.name}-plan.json`).readJSON();
63
+ return plan;
64
+ };
65
+
66
+ export const txFlags = ({
67
+ node,
68
+ from,
69
+ chainId,
70
+ keyringBackend = 'test',
71
+ broadcastMode = 'block',
72
+ }) => ({
73
+ node,
74
+ from,
75
+ 'chain-id': chainId,
76
+ 'keyring-backend': keyringBackend,
77
+ 'broadcast-mode': broadcastMode,
78
+ // TODO: parameterize these?
79
+ gas: 'auto',
80
+ 'gas-adjustment': '1.4',
81
+ });
82
+
83
+ /**
84
+ * @param {CmdRunner} agd
85
+ * @param {string[]} txArgs
86
+ */
87
+ export const runTx = (agd, txArgs) => {
88
+ const { stdout } = agd.withFlags('-o', 'json').exec(['tx', ...txArgs]);
89
+ const result = JSON.parse(stdout);
90
+ if (result.code !== 0) {
91
+ throw Object.assign(Error(result.raw_log), result);
92
+ }
93
+ return result;
94
+ };
95
+
96
+ /**
97
+ * @param {CmdRunner} agd
98
+ * @param {FileRd} bundle
99
+ */
100
+ export const installBundle = async (agd, bundle) =>
101
+ runTx(agd, ['swingset', 'install-bundle', `@${bundle}`]);
102
+
103
+ export const txAbbr = tx => {
104
+ const { txhash, code, height, gas_used: g } = tx;
105
+
106
+ return { txhash, code, height, gas_used: g };
107
+ };
108
+
109
+ /**
110
+ * @param {CmdRunner} agd
111
+ * @param {Plan['bundles']} bundles
112
+ * @param {FileRd} files
113
+ */
114
+ export const installBundles = (agd, bundles, files) => {
115
+ const ps = bundles.map(b =>
116
+ installBundle(agd, files.join(files.relative(b.fileName))),
117
+ );
118
+ return Promise.all(ps);
119
+ };
120
+
121
+ /**
122
+ * @param {CmdRunner} agd
123
+ * @param {Pick<Plan, 'permit' | 'script'>[]} evals
124
+ * @param {object} [opts]
125
+ * @param {string} [opts.title]
126
+ * @param {string} [opts.description]
127
+ * @param {object} [opts.depositOpts]
128
+ * @param {string} [opts.depositOpts.denom]
129
+ * @param {number} [opts.depositOpts.unit]
130
+ * @param {number} [opts.depositOpts.qty]
131
+ * @param {string} [opts.deposit]
132
+ */
133
+ export const submitCoreEval = async (
134
+ agd,
135
+ evals,
136
+ {
137
+ title = evals[0].script,
138
+ description = title,
139
+ depositOpts: { denom = 'ubld', unit = 1_000_000, qty = 1 } = {},
140
+ deposit = `${qty * unit}${denom}`,
141
+ } = {},
142
+ ) =>
143
+ runTx(agd, [
144
+ ...'gov submit-proposal swingset-core-eval'.split(' '),
145
+ ...evals.map(e => [e.permit, e.script]).flat(),
146
+ ...flags({ title, description, deposit }),
147
+ ]);