@agoric/deploy-script-support 0.10.4-upgrade-21-dev-16519b2.0 → 0.10.4-ymax-v0.2-alpha-dev-a527ef4.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-upgrade-21-dev-16519b2.0+16519b2",
3
+ "version": "0.10.4-ymax-v0.2-alpha-dev-a527ef4.0+a527ef4",
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:*",
@@ -72,7 +73,7 @@
72
73
  "access": "public"
73
74
  },
74
75
  "typeCoverage": {
75
- "atLeast": 83.92
76
+ "atLeast": 83.27
76
77
  },
77
- "gitHead": "16519b2de1eb2afda2b4ec866f55eadd4bb18223"
78
+ "gitHead": "a527ef456b970107c2395833dce9abd87689959e"
78
79
  }
@@ -0,0 +1,169 @@
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 { toCLIOptions } from '@agoric/internal/src/cli-utils.js';
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(
56
+ ...(builderOpts ? toCLIOptions(builderOpts) : []),
57
+ );
58
+ const { stdout } = await cmd.exec(['run', String(builder)]);
59
+ const match = stdout?.match(/ (?<name>[-\w]+)-permit.json/);
60
+ if (!(match && match.groups)) {
61
+ throw Error('no permit found');
62
+ }
63
+ /** @type {Plan} */
64
+ const plan = await cwd.join(`${match.groups.name}-plan.json`).readJSON();
65
+ return plan;
66
+ };
67
+
68
+ export const txFlags = ({
69
+ node,
70
+ from,
71
+ chainId,
72
+ keyringBackend = 'test',
73
+ broadcastMode = 'block',
74
+ }) => ({
75
+ node,
76
+ from,
77
+ 'chain-id': chainId,
78
+ 'keyring-backend': keyringBackend,
79
+ 'broadcast-mode': broadcastMode,
80
+ // TODO: parameterize these?
81
+ gas: 'auto',
82
+ 'gas-adjustment': '1.4',
83
+ });
84
+
85
+ /**
86
+ * @param {CmdRunner} agd
87
+ * @param {number} n
88
+ */
89
+ export const waitForBlock = async (agd, n = 1) => {
90
+ const getHeight = async () => {
91
+ const { stdout } = await agd.exec(['status']);
92
+ const { latest_block_height: height } = JSON.parse(stdout).SyncInfo;
93
+ return height;
94
+ };
95
+ const initialHeight = await getHeight();
96
+ const SEC = 1000;
97
+ let currentHeight;
98
+ do {
99
+ await new Promise(resolve => setTimeout(resolve, 1 * SEC)); // XXX ambient
100
+ currentHeight = await getHeight();
101
+ } while (currentHeight - initialHeight < n);
102
+ console.log('block height:', initialHeight, currentHeight);
103
+ };
104
+
105
+ /**
106
+ * @param {CmdRunner} agd - agd with --from etc.
107
+ * @param {string[]} txArgs
108
+ */
109
+ export const runTx = async (agd, txArgs) => {
110
+ const { stdout } = await agd.withFlags('-o', 'json').exec(['tx', ...txArgs]);
111
+ const result = JSON.parse(stdout);
112
+ if (result.code !== 0) {
113
+ throw Object.assign(Error(result.raw_log), result);
114
+ }
115
+ return result;
116
+ };
117
+
118
+ /**
119
+ * @param {CmdRunner} agd
120
+ * @param {FileRd} bundle
121
+ */
122
+ export const installBundle = async (agd, bundle) =>
123
+ runTx(agd, ['swingset', 'install-bundle', `@${bundle}`]);
124
+
125
+ export const txAbbr = tx => {
126
+ const { txhash, code, height, gas_used: g } = tx;
127
+
128
+ return { txhash, code, height, gas_used: g };
129
+ };
130
+
131
+ /**
132
+ * @param {CmdRunner} agd
133
+ * @param {Plan['bundles']} bundles
134
+ * @param {FileRd} files
135
+ */
136
+ export const installBundles = (agd, bundles, files) => {
137
+ const ps = bundles.map(b =>
138
+ installBundle(agd, files.join(files.relative(b.fileName))),
139
+ );
140
+ return Promise.all(ps);
141
+ };
142
+
143
+ /**
144
+ * @param {CmdRunner} agd
145
+ * @param {Pick<Plan, 'permit' | 'script'>[]} evals
146
+ * @param {object} [opts]
147
+ * @param {string} [opts.title]
148
+ * @param {string} [opts.description]
149
+ * @param {object} [opts.depositOpts]
150
+ * @param {string} [opts.depositOpts.denom]
151
+ * @param {number} [opts.depositOpts.unit]
152
+ * @param {number} [opts.depositOpts.qty]
153
+ * @param {string} [opts.deposit]
154
+ */
155
+ export const submitCoreEval = async (
156
+ agd,
157
+ evals,
158
+ {
159
+ title = evals[0].script,
160
+ description = title,
161
+ depositOpts: { denom = 'ubld', unit = 1_000_000, qty = 10 } = {},
162
+ deposit = `${qty * unit}${denom}`,
163
+ } = {},
164
+ ) =>
165
+ runTx(agd, [
166
+ ...'gov submit-proposal swingset-core-eval'.split(' '),
167
+ ...evals.map(e => [e.permit, e.script]).flat(),
168
+ ...toCLIOptions({ title, description, deposit }),
169
+ ]);