agoric 0.21.2-dev-c236c55.0 → 0.21.2-dev-d19b293.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 +20 -20
- package/src/commands/wallet.js +49 -8
- package/src/helpers.js +2 -0
- package/src/lib/chain.js +34 -1
- package/src/lib/format.js +12 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agoric",
|
|
3
|
-
"version": "0.21.2-dev-
|
|
3
|
+
"version": "0.21.2-dev-d19b293.0+d19b293",
|
|
4
4
|
"description": "Manage the Agoric Javascript smart contract platform",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/main.js",
|
|
@@ -29,29 +29,29 @@
|
|
|
29
29
|
"lint:eslint": "eslint ."
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@agoric/cosmic-swingset": "0.41.4-dev-
|
|
33
|
-
"@agoric/deploy-script-support": "0.10.4-dev-
|
|
32
|
+
"@agoric/cosmic-swingset": "0.41.4-dev-d19b293.0+d19b293",
|
|
33
|
+
"@agoric/deploy-script-support": "0.10.4-dev-d19b293.0+d19b293",
|
|
34
34
|
"ava": "^5.3.0",
|
|
35
35
|
"c8": "^9.1.0",
|
|
36
36
|
"dd-trace": "^4.11.1"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@agoric/access-token": "0.4.22-dev-
|
|
40
|
-
"@agoric/cache": "0.3.3-dev-
|
|
41
|
-
"@agoric/casting": "0.4.3-dev-
|
|
42
|
-
"@agoric/client-utils": "0.1.1-dev-
|
|
43
|
-
"@agoric/cosmic-proto": "0.4.1-dev-
|
|
44
|
-
"@agoric/ertp": "0.16.3-dev-
|
|
45
|
-
"@agoric/governance": "0.10.4-dev-
|
|
46
|
-
"@agoric/inter-protocol": "0.16.2-dev-
|
|
47
|
-
"@agoric/internal": "0.3.3-dev-
|
|
48
|
-
"@agoric/network": "0.1.1-dev-
|
|
49
|
-
"@agoric/smart-wallet": "0.5.4-dev-
|
|
50
|
-
"@agoric/store": "0.9.3-dev-
|
|
51
|
-
"@agoric/swingset-vat": "0.32.3-dev-
|
|
52
|
-
"@agoric/vats": "0.15.2-dev-
|
|
53
|
-
"@agoric/zoe": "0.26.3-dev-
|
|
54
|
-
"@agoric/zone": "0.2.3-dev-
|
|
39
|
+
"@agoric/access-token": "0.4.22-dev-d19b293.0+d19b293",
|
|
40
|
+
"@agoric/cache": "0.3.3-dev-d19b293.0+d19b293",
|
|
41
|
+
"@agoric/casting": "0.4.3-dev-d19b293.0+d19b293",
|
|
42
|
+
"@agoric/client-utils": "0.1.1-dev-d19b293.0+d19b293",
|
|
43
|
+
"@agoric/cosmic-proto": "0.4.1-dev-d19b293.0+d19b293",
|
|
44
|
+
"@agoric/ertp": "0.16.3-dev-d19b293.0+d19b293",
|
|
45
|
+
"@agoric/governance": "0.10.4-dev-d19b293.0+d19b293",
|
|
46
|
+
"@agoric/inter-protocol": "0.16.2-dev-d19b293.0+d19b293",
|
|
47
|
+
"@agoric/internal": "0.3.3-dev-d19b293.0+d19b293",
|
|
48
|
+
"@agoric/network": "0.1.1-dev-d19b293.0+d19b293",
|
|
49
|
+
"@agoric/smart-wallet": "0.5.4-dev-d19b293.0+d19b293",
|
|
50
|
+
"@agoric/store": "0.9.3-dev-d19b293.0+d19b293",
|
|
51
|
+
"@agoric/swingset-vat": "0.32.3-dev-d19b293.0+d19b293",
|
|
52
|
+
"@agoric/vats": "0.15.2-dev-d19b293.0+d19b293",
|
|
53
|
+
"@agoric/zoe": "0.26.3-dev-d19b293.0+d19b293",
|
|
54
|
+
"@agoric/zone": "0.2.3-dev-d19b293.0+d19b293",
|
|
55
55
|
"@confio/relayer": "^0.11.3",
|
|
56
56
|
"@cosmjs/crypto": "^0.32.3",
|
|
57
57
|
"@cosmjs/encoding": "^0.32.3",
|
|
@@ -102,5 +102,5 @@
|
|
|
102
102
|
"typeCoverage": {
|
|
103
103
|
"atLeast": 77.54
|
|
104
104
|
},
|
|
105
|
-
"gitHead": "
|
|
105
|
+
"gitHead": "d19b293d5b28a2d78754eb7912771bdb66d5fb37"
|
|
106
106
|
}
|
package/src/commands/wallet.js
CHANGED
|
@@ -21,7 +21,11 @@ import {
|
|
|
21
21
|
} from '../lib/chain.js';
|
|
22
22
|
import { getNetworkConfig } from '../lib/network-config.js';
|
|
23
23
|
import { coalesceWalletState, getCurrent } from '../lib/wallet.js';
|
|
24
|
-
import {
|
|
24
|
+
import {
|
|
25
|
+
summarize,
|
|
26
|
+
fmtRecordOfLines,
|
|
27
|
+
parseFiniteNumber,
|
|
28
|
+
} from '../lib/format.js';
|
|
25
29
|
|
|
26
30
|
const networkConfig = await getNetworkConfig({ env: process.env, fetch });
|
|
27
31
|
|
|
@@ -135,23 +139,60 @@ export const makeWalletCommand = async command => {
|
|
|
135
139
|
)
|
|
136
140
|
.requiredOption('--offer [filename]', 'path to file with prepared offer')
|
|
137
141
|
.option('--dry-run', 'spit out the command instead of running it')
|
|
142
|
+
.option('--gas', 'gas limit; "auto" [default] to calculate automatically')
|
|
143
|
+
.option(
|
|
144
|
+
'--gas-adjustment',
|
|
145
|
+
'factor by which to multiply the --gas=auto calculation result [default 1.2]',
|
|
146
|
+
)
|
|
147
|
+
.option('--verbose', 'print command output')
|
|
138
148
|
.action(function (opts) {
|
|
139
|
-
/**
|
|
149
|
+
/**
|
|
150
|
+
* @typedef {{
|
|
151
|
+
* from: string,
|
|
152
|
+
* offer: string,
|
|
153
|
+
* dryRun: boolean,
|
|
154
|
+
* gas: string,
|
|
155
|
+
* gasAdjustment: string,
|
|
156
|
+
* verbose: boolean,
|
|
157
|
+
* }} Opts
|
|
158
|
+
*/
|
|
140
159
|
const {
|
|
141
160
|
dryRun,
|
|
142
161
|
from,
|
|
162
|
+
gas = 'auto',
|
|
163
|
+
gasAdjustment = '1.2',
|
|
143
164
|
offer,
|
|
144
165
|
home,
|
|
166
|
+
verbose,
|
|
145
167
|
keyringBackend: backend,
|
|
146
168
|
} = /** @type {SharedTxOptions & Opts} */ ({ ...wallet.opts(), ...opts });
|
|
147
169
|
|
|
148
170
|
const offerBody = fs.readFileSync(offer).toString();
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
171
|
+
const out = execSwingsetTransaction(
|
|
172
|
+
['wallet-action', '--allow-spend', offerBody, '-ojson', '-bblock'],
|
|
173
|
+
{
|
|
174
|
+
...networkConfig,
|
|
175
|
+
keyring: { home, backend },
|
|
176
|
+
from,
|
|
177
|
+
gas:
|
|
178
|
+
gas === 'auto' ? ['auto', parseFiniteNumber(gasAdjustment)] : gas,
|
|
179
|
+
dryRun,
|
|
180
|
+
verbose,
|
|
181
|
+
},
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
// see sendAction in {@link ../lib/wallet.js}
|
|
185
|
+
if (dryRun || !verbose) return;
|
|
186
|
+
try {
|
|
187
|
+
const tx = JSON.parse(/** @type {string} */ (out));
|
|
188
|
+
if (tx.code !== 0) {
|
|
189
|
+
console.error('failed to send tx', tx);
|
|
190
|
+
}
|
|
191
|
+
console.log(tx);
|
|
192
|
+
} catch (err) {
|
|
193
|
+
console.error('unexpected output', JSON.stringify(out));
|
|
194
|
+
throw err;
|
|
195
|
+
}
|
|
155
196
|
});
|
|
156
197
|
|
|
157
198
|
wallet
|
package/src/helpers.js
CHANGED
package/src/lib/chain.js
CHANGED
|
@@ -38,11 +38,42 @@ export const normalizeAddressWithOptions = (
|
|
|
38
38
|
};
|
|
39
39
|
harden(normalizeAddressWithOptions);
|
|
40
40
|
|
|
41
|
+
/** @typedef {number | 'auto' | ['auto', adjustment?: number | undefined]} GasLimit */
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @param {GasLimit} limit
|
|
45
|
+
* @returns {string[]}
|
|
46
|
+
*/
|
|
47
|
+
const makeGasOpts = limit => {
|
|
48
|
+
if (Number.isFinite(limit) || limit === 'auto') {
|
|
49
|
+
return [`--gas=${limit}`];
|
|
50
|
+
}
|
|
51
|
+
if (Array.isArray(limit) && limit.length >= 1 && limit[0] === 'auto') {
|
|
52
|
+
const gasOpts = ['--gas=auto'];
|
|
53
|
+
if (limit.length > 1) {
|
|
54
|
+
const [adjustment, ...rest] = limit.slice(1);
|
|
55
|
+
const adjustmentIsValid =
|
|
56
|
+
adjustment === undefined ||
|
|
57
|
+
(Number.isFinite(adjustment) && Number(adjustment) > 0);
|
|
58
|
+
if (rest.length !== 0 || !adjustmentIsValid) {
|
|
59
|
+
throw Error('invalid gas input');
|
|
60
|
+
}
|
|
61
|
+
if (adjustment !== undefined) {
|
|
62
|
+
gasOpts.push(`--gas-adjustment=${adjustment}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return gasOpts;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
throw Error('invalid gas input');
|
|
69
|
+
};
|
|
70
|
+
|
|
41
71
|
/**
|
|
42
72
|
* @param {ReadonlyArray<string>} swingsetArgs
|
|
43
73
|
* @param {MinimalNetworkConfig & {
|
|
44
74
|
* from: string,
|
|
45
75
|
* fees?: string,
|
|
76
|
+
* gas?: GasLimit,
|
|
46
77
|
* dryRun?: boolean,
|
|
47
78
|
* verbose?: boolean,
|
|
48
79
|
* keyring?: {home?: string, backend: string}
|
|
@@ -54,6 +85,7 @@ export const execSwingsetTransaction = (swingsetArgs, opts) => {
|
|
|
54
85
|
const {
|
|
55
86
|
from,
|
|
56
87
|
fees,
|
|
88
|
+
gas = ['auto', 1.2],
|
|
57
89
|
dryRun = false,
|
|
58
90
|
verbose = true,
|
|
59
91
|
keyring = undefined,
|
|
@@ -71,6 +103,7 @@ export const execSwingsetTransaction = (swingsetArgs, opts) => {
|
|
|
71
103
|
homeOpt,
|
|
72
104
|
backendOpt,
|
|
73
105
|
feeOpt,
|
|
106
|
+
makeGasOpts(gas),
|
|
74
107
|
[`--from=${from}`, 'tx', 'swingset'],
|
|
75
108
|
swingsetArgs,
|
|
76
109
|
);
|
|
@@ -82,7 +115,7 @@ export const execSwingsetTransaction = (swingsetArgs, opts) => {
|
|
|
82
115
|
stdout.write('\n');
|
|
83
116
|
} else {
|
|
84
117
|
const yesCmd = cmd.concat(['--yes']);
|
|
85
|
-
if (verbose) console.log('Executing ', yesCmd);
|
|
118
|
+
if (verbose) console.log('Executing ', agdBinary, yesCmd);
|
|
86
119
|
const out = execFileSync(agdBinary, yesCmd, { encoding: 'utf-8' });
|
|
87
120
|
|
|
88
121
|
// agd puts this diagnostic on stdout rather than stderr :-/
|
package/src/lib/format.js
CHANGED
|
@@ -6,6 +6,18 @@ import { makeBoardRemote } from '@agoric/vats/tools/board-utils.js';
|
|
|
6
6
|
* @import {AgoricNamesRemotes, BoardRemote, VBankAssetDetail} from '@agoric/vats/tools/board-utils.js';
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
// TODO Move to packages/internal.
|
|
10
|
+
/**
|
|
11
|
+
* Parses the input and returns either a finite number or NaN.
|
|
12
|
+
*
|
|
13
|
+
* @param {string} input
|
|
14
|
+
* @returns {number}
|
|
15
|
+
*/
|
|
16
|
+
export const parseFiniteNumber = input => {
|
|
17
|
+
const result = /[0-9]/.test(input || '') ? Number(input) : NaN;
|
|
18
|
+
return Number.isFinite(result) ? result : NaN;
|
|
19
|
+
};
|
|
20
|
+
|
|
9
21
|
/**
|
|
10
22
|
* JSON.stringify replacer to handle bigint
|
|
11
23
|
*
|