Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Inter Protocol Liquidation Bidding Test Tool #7295

Merged
merged 12 commits into from
Apr 24, 2023
4 changes: 3 additions & 1 deletion packages/agoric-cli/src/commands/ec.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ export const makeEconomicCommiteeCommand = (_logger, io = {}) => {

const info = await readLatestHead(
'published.committees.Economic_Committee.latestQuestion',
);
).catch(err => {
throw new CommanderError(1, 'VSTORAGE_FAILURE', err.message);
});
// XXX runtime shape-check
const questionDesc = /** @type {any} */ (info);

Expand Down
9 changes: 6 additions & 3 deletions packages/agoric-cli/src/commands/inter.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ const bidInvitationShape = harden({
* @param {AssetDescriptor[]} assets
*/
const makeFormatters = assets => {
const r4 = x => Math.round(x * 10_000) / 10_000;

const br = asBoardRemote;
const fmtAmtTuple = makeAmountFormatter(assets);

Expand All @@ -56,11 +58,11 @@ const makeFormatters = assets => {
const price = r => {
const [nl, nm] = fmtAmtTuple(br(r.numerator));
const [dl, dm] = fmtAmtTuple(br(r.denominator));
return `${Number(nm) / Number(dm)} ${nl}/${dl}`;
return `${r4(Number(nm) / Number(dm))} ${nl}/${dl}`;
};
/** @param {Ratio} r */
const discount = r =>
100 - (Number(r.numerator.value) / Number(r.denominator.value)) * 100;
r4(100 - (Number(r.numerator.value) / Number(r.denominator.value)) * 100);

/** @param {import('@agoric/time/src/types.js').TimestampRecord} tr */
const absTime = tr => new Date(Number(tr.absValue) * 1000).toISOString();
Expand Down Expand Up @@ -146,7 +148,7 @@ export const fmtBid = (bid, assets) => {

const {
id,
proposal: { give },
proposal: { give, want },
offerArgs: { maxBuy },
payouts,
result,
Expand All @@ -156,6 +158,7 @@ export const fmtBid = (bid, assets) => {
!error && result && result !== 'UNPUBLISHED' ? { result } : {};
const props = {
...(give ? { give: fmt.record(give) } : {}),
...(want ? { give: fmt.record(want) } : {}),
...(maxBuy ? { maxBuy: fmt.amount(maxBuy) } : {}),
...(payouts ? { payouts: fmt.record(payouts) } : resultProp),
...(error ? { error } : {}),
Expand Down
8 changes: 7 additions & 1 deletion packages/agoric-cli/src/lib/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,18 @@ export const asPercent = ratio => {
return (100 * Number(numerator.value)) / Number(denominator.value);
};

const { Fail, quote: q } = assert;

const isObject = x => typeof x === 'object' && x !== null;

/**
* @param {Amount} x
* @returns {Amount & { brand: BoardRemote }}
*/
export const asBoardRemote = x => {
assert('getBoardId' in x.brand);
isObject(x) || Fail`not object: ${q(x)}`;
isObject(x.brand) || Fail`not object: ${q(x.brand)}`;
'getBoardId' in x.brand || Fail`missing getBoardId: ${q(x.brand)}`;
// @ts-expect-error dynamic check
return x;
};
Expand Down
18 changes: 15 additions & 3 deletions packages/agoric-cli/src/lib/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,21 @@ export const makeVStorage = (powers, config = networkConfig) => {
`/abci_query?path=%22/custom/vstorage/${kind}/${path}%22&height=${height}`;

const readStorage = (path = 'published', { kind = 'children', height = 0 }) =>
getJSON(url(path, { kind, height })).catch(err => {
throw Error(`cannot read ${kind} of ${path}: ${err.message}`);
});
getJSON(url(path, { kind, height }))
.catch(err => {
throw Error(`cannot read ${kind} of ${path}: ${err.message}`);
})
.then(data => {
const {
result: { response },
} = data;
if (response?.code !== 0) {
throw Error(
`error code ${response?.code} reading ${kind} of ${path}: ${response.log}`,
);
}
return data;
});

return {
url,
Expand Down
4 changes: 2 additions & 2 deletions packages/agoric-cli/test/snapshots/test-inter-cli.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Generated by [AVA](https://avajs.dev).
--maxBuy <amount> max Collateral wanted (default: "1_000_000IbcATOM")␊
--wantMinimum <amount> only transact a bid that supplies this much␊
collateral␊
--offer-id <string> Offer id (default: "bid-978307200000")␊
--offer-id <string> Offer id (default: "bid-1680241587424")␊
--generate-only print wallet action only␊
--price <number> bid price (IST/Collateral)␊
-h, --help display help for command`
Expand All @@ -92,7 +92,7 @@ Generated by [AVA](https://avajs.dev).
--maxBuy <amount> max Collateral wanted (default: "1_000_000IbcATOM")␊
--wantMinimum <amount> only transact a bid that supplies this much␊
collateral␊
--offer-id <string> Offer id (default: "bid-978307200000")␊
--offer-id <string> Offer id (default: "bid-1680241587424")␊
--generate-only print wallet action only␊
--discount <percent> bid discount (0 to 100) or markup (0 to -100) %␊
-h, --help display help for command`
Expand Down
Binary file modified packages/agoric-cli/test/snapshots/test-inter-cli.js.snap
Binary file not shown.
Loading