Skip to content

Commit

Permalink
chore: split game1 proposal from walletFactory upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc committed Aug 23, 2023
1 parent f2fc314 commit e86d606
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 187 deletions.
34 changes: 34 additions & 0 deletions packages/builders/scripts/smart-wallet/build-game1-start.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @file Proposal Builder: Upgrade walletFactory
*
* Usage:
* agoric run build-game1-start.js
*/

import { makeHelpers } from '@agoric/deploy-script-support';
import { getManifestForGame1 } from '@agoric/smart-wallet/test/start-game1-proposal.js';

/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').ProposalBuilder} */
export const game1ProposalBuilder = async ({ publishRef, install }) => {
return harden({
sourceSpec: '@agoric/smart-wallet/test/start-game1-proposal.js',
getManifestCall: [
getManifestForGame1.name,
{
game1Ref: publishRef(
install(
'@agoric/smart-wallet/test/gameAssetContract.js',
'../bundles/bundle-game1.js',
{ persist: true },
),
),
},
],
});
};

/** @type {DeployScriptFunction} */
export default async (homeP, endowments) => {
const { writeCoreProposal } = await makeHelpers(homeP, endowments);
await writeCoreProposal('start-game1', game1ProposalBuilder);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @file Proposal Builder: Upgrade walletFactory
*
* Usage:
* agoric run build-walletFactory-upgrade.js
*/

import { makeHelpers } from '@agoric/deploy-script-support';
import { getManifestForUpgrade } from '@agoric/smart-wallet/src/proposals/upgrade-walletFactory-proposal.js';

/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').ProposalBuilder} */
export const defaultProposalBuilder = async ({ publishRef, install }) => {
return harden({
sourceSpec:
'@agoric/smart-wallet/src/proposals/upgrade-walletFactory-proposal.js',
getManifestCall: [
getManifestForUpgrade.name,
{
walletFactoryRef: publishRef(
install(
'@agoric/smart-wallet/src/walletFactory.js',
'../bundles/bundle-walletFactory.js',
{ persist: true },
),
),
},
],
});
};

/** @type {DeployScriptFunction} */
export default async (homeP, endowments) => {
const { writeCoreProposal } = await makeHelpers(homeP, endowments);
await writeCoreProposal('upgrade-walletFactory', defaultProposalBuilder);
};
Empty file.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# Propose and carry out Wallet Factory upgrade
# Propose and carry out starting game contract

SDK=${SDK:-/usr/src/agoric-sdk}
UP11=${UP11:-$SDK/upgrade-test-scripts/agoric-upgrade-11}
Expand All @@ -15,6 +15,7 @@ TITLE="Start Game1 Contract"

DESC="Start Game1 and register well-known Place issuer"

# TODO: fix error recovery (or don't bother with it at all)
[ -f ./start-game1-permit.json ] || (echo run wf-install-bundle.sh first ; exit 1)

agd tx gov submit-proposal \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ UP11=${UP11:-$SDK/upgrade-test-scripts/agoric-upgrade-11}

cd $UP11/wallet-all-ertp

echo +++ run walletFactory upgrade proposal builder +++
agoric run $SDK/packages/smart-wallet/scripts/wfup.js >/tmp/,run.log
echo +++ run walletFactory, game upgrade proposal builders +++
(agoric run $SDK/packages/builders/scripts/smart-wallet/build-walletFactory-upgrade.js; \
agoric run $SDK/packages/builders/scripts/smart-wallet/build-game1-start.js
)>/tmp/,run.log
bundles=$($UP11/tools/parseProposals.mjs </tmp/,run.log | jq -r '.bundles[]' | sort -u )

echo +++ proposal evals for later +++
Expand All @@ -19,6 +21,7 @@ ls ./upgrade-walletFactory* ./start-game1*

echo +++++ install bundles +++++

# TODO: try `agoric publish` to better track outcome
install_bundle() {
agd tx swingset install-bundle "@$1" \
--from gov1 --keyring-backend=test --gas=auto \
Expand Down
57 changes: 0 additions & 57 deletions packages/smart-wallet/scripts/wfup.js

This file was deleted.

129 changes: 2 additions & 127 deletions packages/smart-wallet/src/proposals/upgrade-walletFactory-proposal.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// @ts-check
import { E } from '@endo/far';
import { makeMarshal } from '@endo/marshal';
import { allValues } from '@agoric/internal';

console.warn('@@@ upgrade-walletFactory-proposal.js module evaluating');
console.warn('upgrade-walletFactory-proposal.js module evaluating');

const { fromEntries, keys, values } = Object;
const { Fail } = assert;

// vstorage paths under published.*
Expand All @@ -13,18 +13,6 @@ const BOARD_AUX = 'boardAux';

const marshalData = makeMarshal(_val => Fail`data only`);

// borrow zip, allValues from @agoric/interal
// but don't bring in all of @endo/marshal etc.
/** @type { <X, Y>(xs: X[], ys: Y[]) => [X, Y][]} */
const zip = (xs, ys) => harden(xs.map((x, i) => [x, ys[+i]]));

/** @type { <T extends Record<string, ERef<any>>>(obj: T) => Promise<{ [K in keyof T]: Awaited<T[K]>}> } */
const allValues = async obj => {
const resolved = await Promise.all(values(obj));
// @ts-expect-error cast
return harden(fromEntries(zip(keys(obj), resolved)));
};

/**
* @param { BootstrapPowers } powers
*
Expand Down Expand Up @@ -137,116 +125,3 @@ export const getManifestForUpgrade = (_powers, { walletFactoryRef }) => {
options: { walletFactoryRef },
});
};

// avoid importing all of ERTP
const makeAmount = (brand, value) => harden({ brand, value });

const IST_UNIT = 1_000_000n;
const CENT = IST_UNIT / 100n;

/**
* Make a storage node for auxilliary data for a value on the board.
*
* @param {ERef<StorageNode>} chainStorage
* @param {string} boardId
*/
const makeBoardAuxNode = async (chainStorage, boardId) => {
const boardAux = E(chainStorage).makeChildNode(BOARD_AUX);
return E(boardAux).makeChildNode(boardId);
};

const publishBrandInfo = async (chainStorage, board, brand) => {
const [id, displayInfo] = await Promise.all([
E(board).getId(brand),
E(brand).getDisplayInfo(),
]);
const node = makeBoardAuxNode(chainStorage, id);
const aux = marshalData.toCapData(harden({ displayInfo }));
await E(node).setValue(JSON.stringify(aux));
};

/**
* Core eval script to start contract
*
* @param {BootstrapPowers} permittedPowers
*/
export const startGameContract = async permittedPowers => {
console.error('@@@startGameContract()...');
const {
consume: { agoricNames, board, chainStorage, startUpgradable, zoe },
brand: {
// @ts-expect-error dynamic extension to promise space
produce: { Place: producePlaceBrand },
},
issuer: {
// @ts-expect-error dynamic extension to promise space
produce: { Place: producePlaceIssuer },
},
instance: {
// @ts-expect-error dynamic extension to promise space
produce: { game1: produceInstance },
},
} = permittedPowers;

const istBrand = await E(agoricNames).lookup('brand', 'IST');
const ist = {
brand: istBrand,
};
// NOTE: joinPrice could be configurable
const terms = { joinPrice: makeAmount(ist.brand, 25n * CENT) };

// agoricNames gets updated each time; the promise space only once XXXXXXX
const installation = await E(agoricNames).lookup('installation', 'game1');

const { instance } = await E(startUpgradable)({
installation,
label: 'game1',
terms,
});
console.log('CoreEval script: started game contract', instance);
const {
brands: { Place: brand },
issuers: { Place: issuer },
} = await E(zoe).getTerms(instance);

console.log('CoreEval script: share via agoricNames:', brand);

produceInstance.reset();
produceInstance.resolve(instance);

producePlaceBrand.reset();
producePlaceIssuer.reset();
producePlaceBrand.resolve(brand);
producePlaceIssuer.resolve(issuer);

await publishBrandInfo(chainStorage, board, brand);
console.log('game1 (re)installed');
};

/** @type { import("@agoric/vats/src/core/lib-boot").BootstrapManifest } */
const gameManifest = {
[startGameContract.name]: {
// include rationale for closely-held, high authority capabilities
consume: {
agoricNames: true,
board: 'to publish boardAux info for game NFT',
chainStorage: 'to publish boardAux info for game NFT',
startUpgradable: 'to start contract and save adminFacet',
zoe: 'to get contract terms, including issuer/brand',
},
installation: { consume: { game1: true } },
issuer: { produce: { Place: true } },
brand: { produce: { Place: true } },
instance: { produce: { game1: true } },
},
};
harden(manifest);

export const getManifestForGame1 = ({ restoreRef }, { game1Ref }) => {
return harden({
manifest: gameManifest,
installations: {
game1: restoreRef(game1Ref),
},
});
};
Loading

0 comments on commit e86d606

Please sign in to comment.