@agoric/deploy-script-support 0.10.4-upgrade-21-dev-16519b2.0 → 0.10.4-upgrade-22-dev-2f770ff.0.2f770ff

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-upgrade-22-dev-2f770ff.0.2f770ff",
4
4
  "description": "Helpers and other support for writing deploy scripts",
5
5
  "type": "module",
6
6
  "main": "src/helpers.js",
@@ -34,25 +34,26 @@
34
34
  },
35
35
  "homepage": "https://github.com/Agoric/agoric-sdk#readme",
36
36
  "dependencies": {
37
- "@agoric/ertp": "workspace:*",
38
- "@agoric/import-manager": "workspace:*",
39
- "@agoric/internal": "workspace:*",
40
- "@agoric/notifier": "workspace:*",
41
- "@agoric/store": "workspace:*",
42
- "@agoric/time": "workspace:*",
43
- "@agoric/zoe": "workspace:*",
44
- "@endo/base64": "^1.0.9",
45
- "@endo/bundle-source": "^4.0.0",
46
- "@endo/errors": "^1.2.10",
47
- "@endo/far": "^1.1.11",
48
- "@endo/marshal": "^1.6.4",
49
- "@endo/nat": "^5.1.0",
50
- "@endo/promise-kit": "^1.1.10",
51
- "@endo/zip": "^1.0.9"
37
+ "@agoric/ertp": "0.16.3-upgrade-22-dev-2f770ff.0.2f770ff",
38
+ "@agoric/import-manager": "0.3.12-upgrade-22-dev-2f770ff.0.2f770ff",
39
+ "@agoric/internal": "0.3.3-upgrade-22-dev-2f770ff.0.2f770ff",
40
+ "@agoric/notifier": "0.6.3-upgrade-22-dev-2f770ff.0.2f770ff",
41
+ "@agoric/pola-io": "0.1.1-upgrade-22-dev-2f770ff.0.2f770ff",
42
+ "@agoric/store": "0.9.3-upgrade-22-dev-2f770ff.0.2f770ff",
43
+ "@agoric/time": "0.3.3-upgrade-22-dev-2f770ff.0.2f770ff",
44
+ "@agoric/zoe": "0.26.3-upgrade-22-dev-2f770ff.0.2f770ff",
45
+ "@endo/base64": "^1.0.12",
46
+ "@endo/bundle-source": "^4.1.2",
47
+ "@endo/errors": "^1.2.13",
48
+ "@endo/far": "^1.1.14",
49
+ "@endo/marshal": "^1.8.0",
50
+ "@endo/nat": "^5.1.3",
51
+ "@endo/promise-kit": "^1.1.13",
52
+ "@endo/zip": "^1.0.11"
52
53
  },
53
54
  "devDependencies": {
54
- "@agoric/vats": "workspace:*",
55
- "@endo/init": "^1.1.9",
55
+ "@agoric/vats": "0.15.2-upgrade-22-dev-2f770ff.0.2f770ff",
56
+ "@endo/init": "^1.1.12",
56
57
  "ava": "^5.3.0",
57
58
  "import-meta-resolve": "^4.1.0"
58
59
  },
@@ -72,7 +73,7 @@
72
73
  "access": "public"
73
74
  },
74
75
  "typeCoverage": {
75
- "atLeast": 83.92
76
+ "atLeast": 83.26
76
77
  },
77
- "gitHead": "16519b2de1eb2afda2b4ec866f55eadd4bb18223"
78
+ "gitHead": "2f770ff5e26c3aa93f6d3aee5dd2d191b11f8144"
78
79
  }
@@ -0,0 +1,168 @@
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 {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);
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 {number} n
86
+ */
87
+ export const waitForBlock = async (agd, n = 1) => {
88
+ const getHeight = async () => {
89
+ const { stdout } = await agd.exec(['status']);
90
+ const status = JSON.parse(stdout);
91
+ const { latest_block_height: height } = status.sync_info || status.SyncInfo;
92
+ return height;
93
+ };
94
+ const initialHeight = await getHeight();
95
+ const SEC = 1000;
96
+ let currentHeight;
97
+ do {
98
+ await new Promise(resolve => setTimeout(resolve, 1 * SEC)); // XXX ambient
99
+ currentHeight = await getHeight();
100
+ } while (currentHeight - initialHeight < n);
101
+ console.log('block height:', initialHeight, currentHeight);
102
+ };
103
+
104
+ /**
105
+ * @param {CmdRunner} agd - agd with --from etc.
106
+ * @param {string[]} txArgs
107
+ */
108
+ export const runTx = async (agd, txArgs) => {
109
+ const { stdout } = await agd.withFlags('-o', 'json').exec(['tx', ...txArgs]);
110
+ const result = JSON.parse(stdout);
111
+ if (result.code !== 0) {
112
+ throw Object.assign(Error(result.raw_log), result);
113
+ }
114
+ return result;
115
+ };
116
+
117
+ /**
118
+ * @param {CmdRunner} agd
119
+ * @param {FileRd} bundle
120
+ */
121
+ export const installBundle = async (agd, bundle) =>
122
+ runTx(agd, ['swingset', 'install-bundle', `@${bundle}`]);
123
+
124
+ export const txAbbr = tx => {
125
+ const { txhash, code, height, gas_used: g } = tx;
126
+
127
+ return { txhash, code, height, gas_used: g };
128
+ };
129
+
130
+ /**
131
+ * @param {CmdRunner} agd
132
+ * @param {Plan['bundles']} bundles
133
+ * @param {FileRd} files
134
+ */
135
+ export const installBundles = (agd, bundles, files) => {
136
+ const ps = bundles.map(b =>
137
+ installBundle(agd, files.join(files.relative(b.fileName))),
138
+ );
139
+ return Promise.all(ps);
140
+ };
141
+
142
+ /**
143
+ * @param {CmdRunner} agd
144
+ * @param {Pick<Plan, 'permit' | 'script'>[]} evals
145
+ * @param {object} [opts]
146
+ * @param {string} [opts.title]
147
+ * @param {string} [opts.description]
148
+ * @param {object} [opts.depositOpts]
149
+ * @param {string} [opts.depositOpts.denom]
150
+ * @param {number} [opts.depositOpts.unit]
151
+ * @param {number} [opts.depositOpts.qty]
152
+ * @param {string} [opts.deposit]
153
+ */
154
+ export const submitCoreEval = async (
155
+ agd,
156
+ evals,
157
+ {
158
+ title = evals[0].script,
159
+ description = title,
160
+ depositOpts: { denom = 'ubld', unit = 1_000_000, qty = 10 } = {},
161
+ deposit = `${qty * unit}${denom}`,
162
+ } = {},
163
+ ) =>
164
+ runTx(agd, [
165
+ ...'gov submit-proposal swingset-core-eval'.split(' '),
166
+ ...evals.map(e => [e.permit, e.script]).flat(),
167
+ ...toCLIOptions({ title, description, deposit }),
168
+ ]);