Skip to content

Commit

Permalink
chore(start-contract-proposal): swap bootstrap types
Browse files Browse the repository at this point in the history
 - prune dead code
 - add static types
  • Loading branch information
dckc committed Mar 1, 2024
1 parent 352109f commit 7e5d975
Showing 1 changed file with 15 additions and 38 deletions.
53 changes: 15 additions & 38 deletions contract/src/start-contract-proposal.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,39 @@
// @ts-check
import { E } from '@endo/far';
import { makeMarshal } from '@endo/marshal';
import { AmountMath } from '@agoric/ertp/src/amountMath.js';

console.warn('start-contract-proposal.js module evaluating');

const { Fail } = assert;

// vstorage paths under published.*
const BOARD_AUX = 'boardAux';

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

const IST_UNIT = 1_000_000n;
const CENT = IST_UNIT / 100n;
const contractName = 'swaparoo';

/**
* Make a storage node for auxilliary data for a value on the board.
*
* @param {ERef<StorageNode>} chainStorage
* @param {string} boardId
* @typedef {{
* installation: PromiseSpaceOf<{ swaparoo: Installation }>;
* instance: PromiseSpaceOf<{ swaparoo: Instance }>;
* }} SwaparooSpace
*/
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));
};

const contractName = 'swaparoo';

/**
* Core eval script to install contract
*
* @param {BootstrapPowers} powers
* @param {*} config
*/
export const installContract = async (powers, config) => {
console.log('installContract() ...', contractName);
/** @type { BootstrapPowers & SwaparooSpace} */
// @ts-expect-error cast
const swapPowers = powers;
const { bundleID = Fail`missing bundleID` } =
config.options?.[contractName] || {};
const {
consume: { zoe },
installation: {
produce: { [contractName]: produceInstallation },
},
} = powers;
} = swapPowers;

const installation = await E(zoe).installBundleID(bundleID);
produceInstallation.reset();
Expand All @@ -67,29 +48,25 @@ export const installContract = async (powers, config) => {
*/
export const startContract = async permittedPowers => {
console.error('startContract()...');
/** @type { BootstrapPowers & SwaparooSpace} */
// @ts-expect-error bootstrap powers evolve with BLD staker governance
const swapPowers = permittedPowers;
const {
consume: { startUpgradable, namesByAddressAdmin: namesByAddressAdminP },
brand: {
consume: { IST: istBrandP },
},
// issuer: {
// // @ts-expect-error dynamic extension to promise space
// produce: { Place: producePlaceIssuer },
// },
installation: {
consume: { [contractName]: installationP },
},
instance: {
produce: { [contractName]: produceInstance },
},
} = permittedPowers;
} = swapPowers;

const istBrand = await istBrandP;
const ist = {
brand: istBrand,
};
// NOTE: TODO all terms for the contract go here
let oneIST = AmountMath.make(istBrand, 1n);
const oneIST = AmountMath.make(istBrand, 1n);
const namesByAddressAdmin = await namesByAddressAdminP;
const terms = { feeAmount: oneIST, namesByAddressAdmin };

Expand Down

0 comments on commit 7e5d975

Please sign in to comment.