Skip to content

Commit f37adcf

Browse files
committed
feat(agoric): set-defaults --bootstrap-address and friends
1 parent f5926a3 commit f37adcf

File tree

5 files changed

+66
-23
lines changed

5 files changed

+66
-23
lines changed

packages/agoric-cli/lib/chain-config.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ export const MINT_DENOM = 'ubld';
55
export const STAKING_DENOM = 'ubld';
66
export const STAKING_MAX_VALIDATORS = 150;
77

8+
export const DEFAULT_BOOTSTRAP_VALUE = 50000n * 10n ** 6n;
9+
export const DEFAULT_DONATION_VALUE = 5n * 10n ** 6n;
10+
811
export const GOV_DEPOSIT_COINS = [{ amount: '1000000', denom: MINT_DENOM }];
912

1013
// Can't beat the speed of light, we need 600ms round trip time for the other
@@ -93,7 +96,13 @@ export function finishTendermintConfig({
9396
}
9497

9598
// Rewrite/import the genesis.json.
96-
export function finishCosmosGenesis({ genesisJson, exportedGenesisJson }) {
99+
export function finishCosmosGenesis({
100+
genesisJson,
101+
exportedGenesisJson,
102+
bootstrapAddress,
103+
bootstrapValue,
104+
donationValue,
105+
}) {
97106
const genesis = JSON.parse(genesisJson);
98107
const exported = exportedGenesisJson ? JSON.parse(exportedGenesisJson) : {};
99108

@@ -124,20 +133,11 @@ export function finishCosmosGenesis({ genesisJson, exportedGenesisJson }) {
124133
genesis.app_state.mint.params.inflation_rate_change = '0.0';
125134
genesis.app_state.mint.params.inflation_min = '0.0';
126135

127-
/*
128-
FIXME: Allow these to be configurable.
129-
- name: faucet
130-
type: local
131-
address: agoric1hr29lkgsdzdr0jdpa0tfzjgrm0vnd339qde52l
132-
pubkey: agoricpub1addwnpepqw0aeejelzrmy9wn0tp9zcs70jf2d0jw0ycyt6pc4a92fmss9uv4g5e0n9y
133-
mnemonic: ""
134-
threshold: 0
135-
pubkeys: []
136-
*/
137-
genesis.app_state.vpurse.bootstrap_address =
138-
'agoric1hr29lkgsdzdr0jdpa0tfzjgrm0vnd339qde52l';
139-
genesis.app_state.vpurse.bootstrap_value = `${50000n * 10n ** 6n}`;
140-
genesis.app_state.vpurse.donation_value = `${5n * 10n ** 6n}`;
136+
genesis.app_state.vpurse.bootstrap_address = bootstrapAddress;
137+
genesis.app_state.vpurse.bootstrap_value = `${bootstrapValue ||
138+
DEFAULT_BOOTSTRAP_VALUE}`;
139+
genesis.app_state.vpurse.donation_value = `${donationValue ||
140+
DEFAULT_DONATION_VALUE}`;
141141

142142
// Set the denomination for different modules.
143143
genesis.app_state.mint.params.mint_denom = MINT_DENOM;

packages/agoric-cli/lib/main.js

+33-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/* global __dirname process */
22
import { Command } from 'commander';
33

4-
import { assert, details as X } from '@agoric/assert';
4+
import { assert, details as X, quote as q } from '@agoric/assert';
5+
import { Nat } from '@agoric/nat';
56
import cosmosMain from './cosmos';
67
import deployMain from './deploy';
78
import initMain from './init';
@@ -32,6 +33,15 @@ const main = async (progname, rawArgs, powers) => {
3233
return true;
3334
}
3435

36+
const makeParseNatValue = flag => value => {
37+
try {
38+
const bi = BigInt(value);
39+
return Nat(bi);
40+
} catch (e) {
41+
assert.fail(X`${q(flag)} must be a natural number, not ${value}; ${e}`);
42+
}
43+
};
44+
3545
function subMain(fn, args, options) {
3646
return fn(progname, args, powers, options).then(
3747
// This seems to be the only way to propagate the exit code.
@@ -111,6 +121,28 @@ const main = async (progname, rawArgs, powers) => {
111121
program
112122
.command('set-defaults <program> <config-dir>')
113123
.description('update the configuration files for <program> in <config-dir>')
124+
.option(
125+
'--bootstrap-address <bech32>',
126+
'the chain address which should receive urun',
127+
'',
128+
)
129+
.option(
130+
'--bootstrap-value <number>',
131+
'the amount of urun to give to bootstrap-address',
132+
makeParseNatValue('bootstrap-value'),
133+
0n,
134+
)
135+
.option(
136+
'--donation-value <number>',
137+
'the amount of urun to transfer from bootsrtap-address to each client',
138+
makeParseNatValue('donation-value'),
139+
0n,
140+
)
141+
.option(
142+
'--export-metrics',
143+
'open ports to export Prometheus metrics',
144+
false,
145+
)
114146
.option(
115147
'--import-from <dir>',
116148
'import the exported configuration from <dir>',
@@ -126,11 +158,6 @@ const main = async (progname, rawArgs, powers) => {
126158
'set the config.toml p2p.unconditional_peer_ids value',
127159
'',
128160
)
129-
.option(
130-
'--export-metrics',
131-
'open ports to export Prometheus metrics',
132-
false,
133-
)
134161
.action(async (prog, configDir, cmd) => {
135162
const opts = { ...program.opts(), ...cmd.opts() };
136163
return subMain(setDefaultsMain, ['set-defaults', prog, configDir], opts);

packages/agoric-cli/lib/set-defaults.js

+15
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ export default async function setDefaultsMain(progname, rawArgs, powers, opts) {
1717
X`<prog> must currently be 'ag-chain-cosmos'`,
1818
);
1919

20+
const { bootstrapAddress, bootstrapValue, donationValue } = opts;
21+
22+
console.log(bootstrapAddress, bootstrapValue, donationValue);
23+
assert(
24+
bootstrapAddress || !bootstrapValue,
25+
X`must set bootstrap-address if bootstrap-value is set`,
26+
);
27+
assert(
28+
bootstrapAddress || !donationValue,
29+
X`must set bootstrap-address if donation-value is set`,
30+
);
31+
2032
const { exportMetrics } = opts;
2133

2234
let appFile;
@@ -82,6 +94,9 @@ export default async function setDefaultsMain(progname, rawArgs, powers, opts) {
8294
const newGenesisJson = finishCosmosGenesis({
8395
genesisJson,
8496
exportedGenesisJson,
97+
bootstrapAddress,
98+
bootstrapValue,
99+
donationValue,
85100
});
86101

87102
await create(genesisFile, newGenesisJson);

packages/agoric-cli/lib/start.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ import { createHash } from 'crypto';
55

66
import {
77
STAKING_DENOM,
8-
MINT_DENOM,
98
finishTendermintConfig,
109
finishCosmosGenesis,
1110
finishCosmosApp,
1211
} from './chain-config';
1312

1413
import { makePspawn } from './helpers';
1514

16-
const PROVISION_COINS = `100000000${STAKING_DENOM},100000000${MINT_DENOM},100provisionpass,100sendpacketpass`;
15+
const PROVISION_COINS = `100000000${STAKING_DENOM},100provisionpass,100sendpacketpass`;
1716
const DELEGATE0_COINS = `50000000${STAKING_DENOM}`;
1817
const CHAIN_ID = 'agoric';
1918

@@ -312,6 +311,7 @@ export default async function startMain(progname, rawArgs, powers, opts) {
312311
]);
313312
const newGenesisJson = finishCosmosGenesis({
314313
genesisJson,
314+
bootstrapAddress: addrs.provision,
315315
});
316316
const newConfigToml = finishTendermintConfig({
317317
configToml,

packages/agoric-cli/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"@agoric/bundle-source": "^1.3.4",
3131
"@agoric/captp": "^1.7.10",
3232
"@agoric/install-ses": "^0.5.10",
33+
"@agoric/nat": "^4.0.0",
3334
"@agoric/promise-kit": "^0.2.10",
3435
"@agoric/swing-store-simple": "^0.3.6",
3536
"@iarna/toml": "^2.2.3",

0 commit comments

Comments
 (0)