@agoric/builders 0.2.0-u19.3 → 0.2.0-u21.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.
@@ -1,65 +0,0 @@
1
- import { parseArgs } from 'node:util';
2
- import { getManifestForUpdateFastUsdcPolicy } from '@agoric/fast-usdc/src/fast-usdc-policy.core.js';
3
- import { toExternalConfig } from '@agoric/fast-usdc/src/utils/config-marshal.js';
4
- import { FeedPolicyShape } from '@agoric/fast-usdc/src/type-guards.js';
5
- import { makeHelpers } from '@agoric/deploy-script-support';
6
-
7
- /**
8
- * @import {CoreEvalBuilder, DeployScriptFunction} from '@agoric/deploy-script-support/src/externalTypes.js'
9
- * @import {ParseArgsConfig} from 'node:util'
10
- * @import {FastUSDCConfig} from '@agoric/fast-usdc';
11
- */
12
-
13
- /** @type {ParseArgsConfig['options']} */
14
- const options = {
15
- feedPolicy: { type: 'string' },
16
- };
17
- const feedPolicyUsage = 'use --feedPolicy <policy> ...';
18
-
19
- /**
20
- * @typedef {{
21
- * feedPolicy?: string;
22
- * }} FastUSDCUpdateOpts
23
- */
24
-
25
- /**
26
- * @param {Parameters<CoreEvalBuilder>[0]} powers
27
- * @param {FastUSDCConfig} config
28
- * @satisfies {CoreEvalBuilder}
29
- */
30
- export const updateProposalBuilder = async (
31
- powers,
32
- /** @type {Pick<FastUSDCConfig, 'feedPolicy'>} */ config,
33
- ) => {
34
- return harden({
35
- sourceSpec: '@agoric/fast-usdc/src/fast-usdc-policy.core.js',
36
- /** @type {[string, Parameters<typeof getManifestForUpdateFastUsdcPolicy>[1]]} */
37
- getManifestCall: [
38
- getManifestForUpdateFastUsdcPolicy.name,
39
- {
40
- options: toExternalConfig(
41
- config,
42
- {},
43
- harden({ feedPolicy: FeedPolicyShape }),
44
- ),
45
- },
46
- ],
47
- });
48
- };
49
-
50
- /** @type {DeployScriptFunction} */
51
- export default async (homeP, endowments) => {
52
- const { writeCoreEval } = await makeHelpers(homeP, endowments);
53
- const {
54
- values: { feedPolicy },
55
- } = parseArgs({ args: endowments.scriptArgs, options });
56
-
57
- const parseFeedPolicy = () => {
58
- if (typeof feedPolicy !== 'string') throw Error(feedPolicyUsage);
59
- return JSON.parse(feedPolicy);
60
- };
61
- const config = harden({ feedPolicy: parseFeedPolicy() });
62
- await writeCoreEval('eval-fast-usdc-policy-update', utils =>
63
- updateProposalBuilder(utils, config),
64
- );
65
- };
@@ -1,207 +0,0 @@
1
- // @ts-check
2
- import { makeHelpers } from '@agoric/deploy-script-support';
3
- import { AmountMath } from '@agoric/ertp';
4
- import { getManifestForFastUSDC } from '@agoric/fast-usdc/src/start-fast-usdc.core.js';
5
- import { FastUSDCConfigShape } from '@agoric/fast-usdc/src/type-guards.js';
6
- import { toExternalConfig } from '@agoric/fast-usdc/src/utils/config-marshal.js';
7
- import { configurations } from '@agoric/fast-usdc/src/utils/deploy-config.js';
8
- import {
9
- multiplyBy,
10
- parseRatio,
11
- } from '@agoric/zoe/src/contractSupport/ratio.js';
12
- import { Far } from '@endo/far';
13
- import { parseArgs } from 'node:util';
14
-
15
- /**
16
- * @import {CoreEvalBuilder, DeployScriptFunction} from '@agoric/deploy-script-support/src/externalTypes.js'
17
- * @import {ParseArgsConfig} from 'node:util'
18
- * @import {FastUSDCConfig, FeedPolicy} from '@agoric/fast-usdc';
19
- */
20
-
21
- const { keys } = Object;
22
-
23
- /** @type {ParseArgsConfig['options']} */
24
- const options = {
25
- flatFee: { type: 'string', default: '0.01' },
26
- variableRate: { type: 'string', default: '0.01' },
27
- contractRate: { type: 'string', default: '0.2' },
28
- net: { type: 'string' },
29
- oracle: { type: 'string', multiple: true },
30
- feedPolicy: { type: 'string' },
31
- usdcDenom: {
32
- type: 'string',
33
- default:
34
- 'ibc/FE98AAD68F02F03565E9FA39A5E627946699B2B07115889ED812D8BA639576A9',
35
- },
36
- chainInfo: { type: 'string' },
37
- assetInfo: { type: 'string' },
38
- noNoble: { type: 'boolean', default: false },
39
- };
40
- const oraclesUsage = 'use --oracle name:address ...';
41
-
42
- const feedPolicyUsage = 'use --feedPolicy <policy> ...';
43
-
44
- const chainInfoUsage = 'use --chainInfo {chainName:CosmosChainInfo, ...}';
45
- const assetInfoUsage =
46
- 'use --assetInfo { denom:DenomInfo & {brandKey?: string} ... }';
47
-
48
- /**
49
- * @typedef {{
50
- * flatFee: string;
51
- * variableRate: string;
52
- * contractRate: string;
53
- * net?: string;
54
- * oracle?: string[];
55
- * usdcDenom: string;
56
- * feedPolicy?: string;
57
- * chainInfo?: string;
58
- * assetInfo?: string;
59
- * noNoble: boolean;
60
- * }} FastUSDCOpts
61
- */
62
-
63
- const crossVatContext = /** @type {const} */ ({
64
- /** @type {Brand<'nat'>} */
65
- USDC: Far('USDC Brand'),
66
- });
67
- const { USDC } = crossVatContext;
68
- const USDC_DECIMALS = 6;
69
- const unit = AmountMath.make(USDC, 10n ** BigInt(USDC_DECIMALS));
70
-
71
- /**
72
- * @param {Parameters<CoreEvalBuilder>[0]} powers
73
- * @param {FastUSDCConfig} config
74
- * @satisfies {CoreEvalBuilder}
75
- */
76
- export const defaultProposalBuilder = async (
77
- { publishRef, install },
78
- config,
79
- ) => {
80
- return harden({
81
- sourceSpec: '@agoric/fast-usdc/src/start-fast-usdc.core.js',
82
- /** @type {[string, Parameters<typeof getManifestForFastUSDC>[1]]} */
83
- getManifestCall: [
84
- getManifestForFastUSDC.name,
85
- {
86
- options: toExternalConfig(config, crossVatContext, FastUSDCConfigShape),
87
- installKeys: {
88
- fastUsdc: publishRef(
89
- install('@agoric/fast-usdc/src/fast-usdc.contract.js'),
90
- ),
91
- },
92
- },
93
- ],
94
- });
95
- };
96
-
97
- /** @type {DeployScriptFunction} */
98
- export default async (homeP, endowments) => {
99
- const { writeCoreEval } = await makeHelpers(homeP, endowments);
100
- const { scriptArgs } = endowments;
101
-
102
- /** @type {{ values: FastUSDCOpts }} */
103
- // @ts-expect-error ensured by options
104
- const {
105
- values: {
106
- oracle: oracleArgs,
107
- net,
108
- usdcDenom,
109
- feedPolicy,
110
- chainInfo,
111
- assetInfo,
112
- noNoble,
113
- ...fees
114
- },
115
- } = parseArgs({ args: scriptArgs, options });
116
-
117
- /** @returns {FeedPolicy} */
118
- const parseFeedPolicy = () => {
119
- if (net) {
120
- if (!(net in configurations)) {
121
- throw Error(`${net} not in ${keys(configurations)}`);
122
- }
123
- return configurations[net].feedPolicy;
124
- }
125
- if (!feedPolicy) throw Error(feedPolicyUsage);
126
- const parsed = JSON.parse(feedPolicy);
127
- if (!parsed.chainPolicies) {
128
- return {
129
- ...configurations.MAINNET.feedPolicy,
130
- ...parsed,
131
- };
132
- } else {
133
- // consider having callers use `toExternalConfig` to pass in bigints and
134
- // use `fromExternalConfig` here to parse
135
- throw Error('TODO: support unmarshalling feedPolicy');
136
- }
137
- };
138
-
139
- const parseOracleArgs = () => {
140
- if (net) {
141
- if (!(net in configurations)) {
142
- throw Error(`${net} not in ${keys(configurations)}`);
143
- }
144
- return configurations[net].oracles;
145
- }
146
- if (!oracleArgs) throw Error(oraclesUsage);
147
- return Object.fromEntries(
148
- oracleArgs.map(arg => {
149
- const result = arg.match(/(?<name>[^:]+):(?<address>.+)/);
150
- if (!(result && result.groups)) throw Error(oraclesUsage);
151
- const { name, address } = result.groups;
152
- return [name, address];
153
- }),
154
- );
155
- };
156
-
157
- /** @param {string} numeral */
158
- const toAmount = numeral => multiplyBy(unit, parseRatio(numeral, USDC));
159
- /** @param {string} numeral */
160
- const toRatio = numeral => parseRatio(numeral, USDC);
161
- const parseFeeConfigArgs = () => {
162
- const { flatFee, variableRate, contractRate } = fees;
163
- return {
164
- flat: toAmount(flatFee),
165
- variableRate: toRatio(variableRate),
166
- contractRate: toRatio(contractRate),
167
- };
168
- };
169
-
170
- const parseChainInfo = () => {
171
- if (net) {
172
- if (!(net in configurations)) {
173
- throw Error(`${net} not in ${keys(configurations)}`);
174
- }
175
- return configurations[net].chainInfo;
176
- }
177
- if (!chainInfo) throw Error(chainInfoUsage);
178
- return JSON.parse(chainInfo);
179
- };
180
- const parseAssetInfo = () => {
181
- if (net) {
182
- if (!(net in configurations)) {
183
- throw Error(`${net} not in ${keys(configurations)}`);
184
- }
185
- return configurations[net].assetInfo;
186
- }
187
- if (!assetInfo) throw Error(assetInfoUsage);
188
- return JSON.parse(assetInfo);
189
- };
190
-
191
- /** @type {FastUSDCConfig} */
192
- const config = harden({
193
- oracles: parseOracleArgs(),
194
- terms: {
195
- usdcDenom,
196
- },
197
- feeConfig: parseFeeConfigArgs(),
198
- feedPolicy: parseFeedPolicy(),
199
- chainInfo: parseChainInfo(),
200
- assetInfo: parseAssetInfo(),
201
- noNoble,
202
- });
203
-
204
- await writeCoreEval('start-fast-usdc', utils =>
205
- defaultProposalBuilder(utils, config),
206
- );
207
- };
@@ -1,134 +0,0 @@
1
- /**
2
- * @file Terminate price-feed governor instances such as mainnet v110.
3
- * Functions as both an off-chain builder and an on-chain core-eval.
4
- */
5
-
6
- /// <reference types="@agoric/vats/src/core/types-ambient"/>
7
-
8
- import { E } from '@endo/far';
9
-
10
- const SELF = '@agoric/builders/scripts/vats/terminate-governor-instance.js';
11
- const USAGE = `Usage: agoric run /path/to/terminate-governor-instance.js \\
12
- <$governorInstanceHandleBoardID:$instanceKitLabel>...`;
13
-
14
- const repr = val =>
15
- typeof val === 'string' || (typeof val === 'object' && val !== null)
16
- ? JSON.stringify(val)
17
- : String(val);
18
- const defaultMakeError = (strings, ...subs) =>
19
- Error(
20
- strings.map((s, i) => `${i === 0 ? '' : repr(subs[i - 1])}${s}`).join(''),
21
- );
22
- const makeUsageError = (strings, ...subs) => {
23
- const err = defaultMakeError(strings, ...subs);
24
- console.error(err.message);
25
- console.error(USAGE);
26
- return err;
27
- };
28
-
29
- const rtarget = /^(?<boardID>board[0-9]+):(?<instanceKitLabel>.+)$/;
30
- /**
31
- * @param {string[]} args
32
- * @param {(strings: TemplateStringsArray | string[], ...subs: unknown[]) => Error} [makeError]
33
- * @returns {Array<{boardID: string, instanceKitLabel: string}>}
34
- */
35
- const parseTargets = (args = [], makeError = defaultMakeError) => {
36
- if (!Array.isArray(args)) throw makeError`invalid targets: ${args}`;
37
- /** @type {Array<{boardID: string, instanceKitLabel: string}>} */
38
- const targets = [];
39
- const badTargets = [];
40
- for (const arg of args) {
41
- const m = typeof arg === 'string' && arg.match(rtarget);
42
- if (!m) {
43
- badTargets.push(arg);
44
- } else {
45
- // @ts-expect-error cast
46
- targets.push(m.groups);
47
- }
48
- }
49
- if (badTargets.length !== 0) {
50
- throw makeError`malformed target(s): ${badTargets}`;
51
- } else if (targets.length === 0) {
52
- throw makeError`no target(s)`;
53
- }
54
- return targets;
55
- };
56
-
57
- /**
58
- * @param {BootstrapPowers} powers
59
- * @param {{ options: { targetSpecifiers: string[] } }} config
60
- */
61
- export const terminateGovernors = async (
62
- { consume: { board, governedContractKits } },
63
- { options: { targetSpecifiers } },
64
- ) => {
65
- const { Fail, quote: q } = assert;
66
- const targets = parseTargets(targetSpecifiers, Fail);
67
- const doneP = Promise.allSettled(
68
- targets.map(async ({ boardID, instanceKitLabel }) => {
69
- const logLabel = [boardID, instanceKitLabel];
70
- const contractInstanceHandle = await E(board).getValue(boardID);
71
- const instanceKit = await E(governedContractKits).get(
72
- // @ts-expect-error TS2345 Property '[tag]' is missing
73
- contractInstanceHandle,
74
- );
75
- console.log(
76
- `${q(logLabel)} alleged governor contract instance kit`,
77
- instanceKit,
78
- );
79
- const { label, governorAdminFacet, adminFacet } = instanceKit;
80
- label === instanceKitLabel ||
81
- Fail`${q(logLabel)} unexpected instanceKit label, got ${label} but wanted ${q(instanceKitLabel)}`;
82
- (adminFacet && adminFacet !== governorAdminFacet) ||
83
- Fail`${q(logLabel)} instanceKit adminFacet should have been present and different from governorAdminFacet but was ${adminFacet}`;
84
- const reason = harden(Error(`core-eval terminating ${label} governor`));
85
- await E(governorAdminFacet).terminateContract(reason);
86
- console.log(`${q(logLabel)} terminated governor`);
87
- }),
88
- );
89
- const results = await doneP;
90
- const problems = targets.flatMap(({ boardID, instanceKitLabel }, i) => {
91
- if (results[i].status === 'fulfilled') return [];
92
- return [[boardID, instanceKitLabel, results[i].reason]];
93
- });
94
- if (problems.length !== 0) {
95
- console.error('governor termination(s) failed', problems);
96
- Fail`governor termination(s) failed: ${problems}`;
97
- }
98
- };
99
- harden(terminateGovernors);
100
-
101
- export const getManifest = (_powers, targetSpecifiers) => {
102
- parseTargets(targetSpecifiers);
103
- return {
104
- manifest: {
105
- [terminateGovernors.name]: {
106
- consume: { board: true, governedContractKits: true },
107
- },
108
- },
109
- // Provide `terminateGovernors` a second argument like
110
- // `{ options: { targetSpecifiers } }`.
111
- options: { targetSpecifiers },
112
- };
113
- };
114
-
115
- /** @type {import('@agoric/deploy-script-support/src/externalTypes.js').CoreEvalBuilder} */
116
- export const defaultProposalBuilder = async (_utils, targetSpecifiers) => {
117
- parseTargets(targetSpecifiers);
118
- return harden({
119
- sourceSpec: SELF,
120
- getManifestCall: ['getManifest', targetSpecifiers],
121
- });
122
- };
123
-
124
- /** @type {import('@agoric/deploy-script-support/src/externalTypes.js').DeployScriptFunction} */
125
- export default async (homeP, endowments) => {
126
- const { scriptArgs } = endowments;
127
- parseTargets(scriptArgs, makeUsageError);
128
- const dspModule = await import('@agoric/deploy-script-support');
129
- const { makeHelpers } = dspModule;
130
- const { writeCoreEval } = await makeHelpers(homeP, endowments);
131
- await writeCoreEval(terminateGovernors.name, utils =>
132
- defaultProposalBuilder(utils, scriptArgs),
133
- );
134
- };