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

Markm make exo not far #29

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"build": "yarn build:deployer",
"build:deployer": "rollup -c rollup.config.mjs",
"test": "ava --verbose",
"format": "yarn prettier --write .github golang packages",
erights marked this conversation as resolved.
Show resolved Hide resolved
"lint": "eslint '**/*.js'",
"lint:types": "tsc -p jsconfig.json",
"lint:fix": "eslint --fix '**/*.js'"
Expand Down Expand Up @@ -56,6 +57,7 @@
"@agoric/vats": "0.15.2-u14.0",
"@agoric/zoe": "^0.26.3-u14.0",
"@endo/bundle-source": "^2.8.0",
"@endo/exo": "^1.3.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dapp uses packages from agoric-upgrade-14. The version there seems to be "@endo/[email protected]".

https://github.com/Agoric/agoric-sdk/blob/d69c011001d300735546dcb74a9ae21e306e4789/yarn.lock#L1395

I don't know what happens if you mix in this version of exo.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I need to wait until I can depend on a more recent endo before proceeding farther. I need at least support for M.raw() in order to sidestep some of the exceptional cases.

I am surprised to see lots of async generator definitions in this repo. Looks like twelve! This is the cause of some of the special cases I need to sidestep. Where did these come from?

Copy link
Member

@dckc dckc Mar 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did these [async generator definitions] come from?

Async iterators seemed like the natural API for query subscriptions, and async generators seemed like a convenient way to produce them for mocking purposes, as well as consuming them.

for example:

  const { stringify: lit } = JSON;
...
  const cosmosBalanceUpdates = () =>
    dedup(poll(getCosmosBalances, { delay }), (a, b) => lit(a) === lit(b));

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case M.raw() is blocking progress here, it became available in Agoric SDK on March 20. Please let me know if there’s further Endo work in flight to unblock this draft.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dapp uses packages from agoric-upgrade-14. The version there seems to be "@endo/[email protected]".

In case M.raw() is blocking progress here,

It is.

it became available in Agoric SDK on March 20. Please let me know if there’s further Endo work in flight to unblock this draft.

What is needed so M.raw() is available here?

"@endo/far": "^0.2.22",
"@endo/init": "^0.5.60",
"@endo/marshal": "^0.8.9",
Expand Down
6 changes: 4 additions & 2 deletions contract/src/fixHub.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// @ts-check
import { E, Far } from '@endo/far';
import { E } from '@endo/far';
import { M } from '@endo/patterns';
import { makeExo } from '@endo/exo';

const { Fail } = assert;

Expand All @@ -11,7 +13,7 @@ const { Fail } = assert;
export const fixHub = async namesByAddressAdmin => {
assert(namesByAddressAdmin, 'no namesByAddressAdmin???');
/** @type {import('@agoric/vats').NameHub} */
const hub = Far('Hub work-around', {
const hub = makeExo('Hub work-around', M.interface('Hub work-around', {}, { defaultGuards: 'passable' }), {
lookup: async (addr, ...rest) => {
await E(namesByAddressAdmin).reserve(addr);
const addressAdmin = await E(namesByAddressAdmin).lookupAdmin(addr);
Expand Down
10 changes: 6 additions & 4 deletions contract/src/platform-goals/board-aux.core.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// @ts-check
import { E, Far } from '@endo/far';
import { E } from '@endo/far';
import { M } from '@endo/patterns';
import { makeExo } from '@endo/exo';

const { Fail } = assert;

Expand Down Expand Up @@ -59,9 +61,9 @@ export const makeBoardAuxManager = (zone, marshalData, powers) => {
);

return harden({
brandAuxPublisher: Far('BrandAuxPublisher', { publishBrandInfo }),
boardAuxTOFU: Far('BoardAuxTOFU', { publishBrandInfo, init }),
boardAuxAdmin: Far('BoardAuxAdmin', { publishBrandInfo, init, update }),
brandAuxPublisher: makeExo('BrandAuxPublisher', M.interface('BrandAuxPublisher', {}, { defaultGuards: 'passable' }), { publishBrandInfo }),
boardAuxTOFU: makeExo('BoardAuxTOFU', M.interface('BoardAuxTOFU', {}, { defaultGuards: 'passable' }), { publishBrandInfo, init }),
boardAuxAdmin: makeExo('BoardAuxAdmin', M.interface('BoardAuxAdmin', {}, { defaultGuards: 'passable' }), { publishBrandInfo, init, update }),
});
};
/** @typedef {ReturnType<typeof makeBoardAuxManager>} BoardAuxManager */
Expand Down
5 changes: 3 additions & 2 deletions contract/src/postal-service.contract.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @ts-check
import { E, Far } from '@endo/far';
import { E } from '@endo/far';
import { M, mustMatch } from '@endo/patterns';
import { makeExo } from '@endo/exo';
import { withdrawFromSeat } from '@agoric/zoe/src/contractSupport/zoeHelpers.js';

const { keys, values } = Object;
Expand Down Expand Up @@ -61,7 +62,7 @@ export const start = zcf => {
return zcf.makeInvitation(handleSend, 'send');
};

const publicFacet = Far('postalSvc', {
const publicFacet = makeExo('postalSvc', M.interface('postalSvc', {}, { defaultGuards: 'passable' }), {
lookup: (...path) => E(namesByAddress).lookup(...path),
getDepositFacet,
sendTo,
Expand Down
4 changes: 2 additions & 2 deletions contract/src/sell-concert-tickets.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
*/
// @ts-check

import { Far } from '@endo/far';
import { M, getCopyBagEntries, makeCopyBag } from '@endo/patterns';
import { makeExo } from '@endo/exo';
import { AssetKind } from '@agoric/ertp/src/amountMath.js';
import { atomicRearrange } from '@agoric/zoe/src/contractSupport/atomicTransfer.js';
import '@agoric/zoe/exported.js';
Expand Down Expand Up @@ -209,7 +209,7 @@ export const start = async zcf => {
zcf.makeInvitation(tradeHandler, 'buy tickets', undefined, proposalShape);

// Mark the publicFacet Far, i.e. reachable from outside the contract
const publicFacet = Far('Tickets Public Facet', {
const publicFacet = makeExo('Tickets Public Facet', M.interface('Tickets Public Facet', {}, { defaultGuards: 'passable' }), {
makeTradeInvitation,
});
return harden({ publicFacet });
Expand Down
7 changes: 4 additions & 3 deletions contract/src/swaparoo.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// @ts-check

import { M, matches, mustMatch } from '@endo/patterns';
import { E, Far } from '@endo/far';
import { E } from '@endo/far';
import { makeExo } from '@endo/exo';
import '@agoric/zoe/exported.js';
import { atomicRearrange } from '@agoric/zoe/src/contractSupport/atomicTransfer.js';
import '@agoric/zoe/src/contracts/exported.js';
Expand Down Expand Up @@ -198,11 +199,11 @@ export const start = async (zcf, privateArgs, baggage) => {
return firstInvitation;
};

const publicFacet = Far('Public', {
const publicFacet = makeExo('Public', M.interface('Public', {}, { defaultGuards: 'passable' }), {
makeFirstInvitation,
...publicMixin,
});
const limitedCreatorFacet = Far('Creator', {
const limitedCreatorFacet = makeExo('Creator', M.interface('Creator', {}, { defaultGuards: 'passable' }), {
makeCollectFeesInvitation() {
return makeCollectFeesInvitation(zcf, feeSeat, feeBrand, 'Fee');
},
Expand Down
8 changes: 5 additions & 3 deletions contract/test/boot-tools.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// @ts-check
import { E, Far } from '@endo/far';
import { E } from '@endo/far';
import { M } from '@endo/patterns';
import { makeExo } from '@endo/exo';
import { makeNameHubKit, makePromiseSpace } from '@agoric/vats';
import { makeFakeBoard } from '@agoric/vats/tools/board-utils.js';
import { makeWellKnownSpaces } from '@agoric/vats/src/core/utils.js';
Expand Down Expand Up @@ -95,7 +97,7 @@ export const mockBootstrapPowers = async (
spaces.issuer.produce.BLD.resolve(bldIssuerKit.issuer);
spaces.issuer.produce.IST.resolve(feeIssuer);
spaces.issuer.produce.Invitation.resolve(invitationIssuer);
produce.priceAuthority.resolve(Far('NullPriceAuthority', {}));
produce.priceAuthority.resolve(makeExo('NullPriceAuthority', M.interface('NullPriceAuthority', {}, { defaultGuards: 'passable' }), {}));

/**
* @type {BootstrapPowers & import('../src/types').NonNullChainStorage}
Expand Down Expand Up @@ -212,7 +214,7 @@ export const makeMockTools = async (t, bundleCache) => {

// XXX marshal context is not fresh. hm.
const makeQueryTool = () => {
return Far('QT', {
return makeExo('QT', M.interface('QT', {}, { defaultGuards: 'passable' }), {
toCapData: x => boardMarshaller.toCapData(x), // XXX remote???
fromCapData: d => boardMarshaller.fromCapData(d),
queryData: async path => {
Expand Down
6 changes: 4 additions & 2 deletions contract/test/lib-gov-test/puppet-gov.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// @ts-check
// borrowed from https://github.com/Agoric/agoric-sdk/blob/master/packages/inter-protocol/test/supports.js
import { E, Far } from '@endo/far';
import { E } from '@endo/far';
import { M } from '@endo/patterns';
import { makeExo } from '@endo/exo';
import { createRequire } from 'node:module';

const nodeRequire = createRequire(import.meta.url);
Expand Down Expand Up @@ -54,7 +56,7 @@ export const mockElectorate = async (zoe, bundleCache) => {
await bundleCache.load(assets.invitationMakerContract),
);
const arbInstance = await E(zoe).startInstance(installation);
const committeeCreatorFacet = Far('Electorate CF', {
const committeeCreatorFacet = makeExo('Electorate CF', M.interface('Electorate CF', {}, { defaultGuards: 'passable' }), {
getPoserInvitation: async () => E(arbInstance.publicFacet).makeInvitation(),
});
return { creatorFacet: committeeCreatorFacet };
Expand Down
10 changes: 6 additions & 4 deletions contract/test/wallet-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
* @see {mockWalletFactory}
*/
// @ts-check
import { E, Far } from '@endo/far';
import { E } from '@endo/far';
import { M } from '@endo/patterns';
import { makeExo } from '@endo/exo';
import { makePromiseKit } from '@endo/promise-kit';

// eslint-disable-next-line import/no-extraneous-dependencies
Expand Down Expand Up @@ -58,7 +60,7 @@ export const mockWalletFactory = (
const invitationPurse = purseByBrand.get(invitationBrand);
assert(invitationPurse);

const depositFacet = Far('DepositFacet', {
const depositFacet = makeExo('DepositFacet', M.interface('DepositFacet', {}, { defaultGuards: 'passable' }), {
/** @param {Payment} pmt */
receive: async pmt => {
const pBrand = await E(pmt).getAllegedBrand();
Expand Down Expand Up @@ -191,8 +193,8 @@ export const mockWalletFactory = (

return {
deposit: depositFacet,
offers: Far('Offers', { executeOffer, tryExit }),
peek: Far('Wallet Peek', { purseUpdates }),
offers: makeExo('Offers', M.interface('Offers', {}, { defaultGuards: 'passable' }), { executeOffer, tryExit }),
peek: makeExo('Wallet Peek', M.interface('Wallet Peek', {}, { defaultGuards: 'passable' }), { purseUpdates }),
};
};

Expand Down
10 changes: 6 additions & 4 deletions contract/tools/e2e-tools.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// @ts-check

import { E, Far } from '@endo/far';
import { E } from '@endo/far';
import { M } from '@endo/patterns';
import { makeExo } from '@endo/exo';
// eslint-disable-next-line import/no-extraneous-dependencies
import { Nat } from '@endo/nat';
import { flags, makeAgd } from './agd-lib.js';
Expand Down Expand Up @@ -228,14 +230,14 @@ export const provisionSmartWallet = async (
}

/** @type {import('../test/wallet-tools.js').MockWallet['offers']} */
const offers = Far('Offers', {
const offers = makeExo('Offers', M.interface('Offers', {}, { defaultGuards: 'passable' }), {
executeOffer,
/** @param {string|number} offerId */
tryExit: offerId => sendAction({ method: 'tryExitOffer', offerId }),
});

/** @type {import('../test/wallet-tools.js').MockWallet['deposit']} */
const deposit = Far('DepositFacet', {
const deposit = makeExo('DepositFacet', M.interface('DepositFacet', {}, { defaultGuards: 'passable' }), {
receive: async payment => {
const brand = await E(payment).getAllegedBrand();
const asset = vbankEntries.find(([_denom, a]) => a.brand === brand);
Expand Down Expand Up @@ -296,7 +298,7 @@ export const provisionSmartWallet = async (
}

/** @type {import('../test/wallet-tools.js').MockWallet['peek']} */
const peek = Far('Peek', { purseUpdates });
const peek = makeExo('Peek', M.interface('Peek', {}, { defaultGuards: 'passable' }), { purseUpdates });

return { offers, deposit, peek };
};
Expand Down
5 changes: 3 additions & 2 deletions contract/tools/ui-kit-goals/makeHttpClient.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-check
import { Far } from '@endo/far';
import { M } from '@endo/patterns';
import { makeExo } from '@endo/exo';

const { freeze } = Object;

Expand Down Expand Up @@ -92,7 +93,7 @@ export const makeAPI = (apiAddress, { fetch }) => {
});
};

return Far('LCD', {
return makeExo('LCD', M.interface('LCD', {}, { defaultGuards: 'passable' }), {
getJSON,
latestBlock: () => getJSON(`/cosmos/base/tendermint/v1beta1/blocks/latest`),
});
Expand Down
8 changes: 5 additions & 3 deletions contract/tools/ui-kit-goals/name-service-client.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// @ts-check
import { E, Far } from '@endo/far';
import { E } from '@endo/far';
import { M } from '@endo/patterns';
import { makeExo } from '@endo/exo';

/** @param {{ queryData: (path: string) => any }} qt */
export const makeAgoricNames = async qt => {
Expand All @@ -14,7 +16,7 @@ export const makeAgoricNames = async qt => {
}
const entries = await qt.queryData(`published.agoricNames.${kind}`);
const record = Object.fromEntries(entries);
const hub = Far('NameHub', {
const hub = makeExo('NameHub', M.interface('NameHub', {}, { defaultGuards: 'passable' }), {
lookup: name => record[name],
keys: () => entries.map(e => e[0]),
entries: () => entries,
Expand All @@ -27,7 +29,7 @@ export const makeAgoricNames = async qt => {
nameHubCache.clear();
};

const hub0 = Far('Hub', {
const hub0 = makeExo('Hub', M.interface('Hub', {}, { defaultGuards: 'passable' }), {
lookup: async (kind, ...more) => {
const hub2 = lookupKind(kind);
if (more.length > 0) {
Expand Down
8 changes: 5 additions & 3 deletions contract/tools/ui-kit-goals/queryKit.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// @ts-check

import { E, Far } from '@endo/far';
import { E } from '@endo/far';
import { M } from '@endo/patterns';
import { makeExo } from '@endo/exo';
import { batchVstorageQuery } from './batchQuery.js';
import { makeClientMarshaller } from './marshalTables.js';

Expand Down Expand Up @@ -79,7 +81,7 @@ export async function* eachVstorageUpdate(key, { vstorage, delay }) {
* @param {import('./batchQuery.js').VStorage} powers.vstorage
*/
export const makeWalletView = (addr, { query, vstorage }) => {
return Far('WalletQuery', {
return makeExo('WalletQuery', M.interface('WalletQuery', {}, { defaultGuards: 'passable' }), {
current: () => query.queryData(`published.wallet.${addr}.current`),
/**
* TODO: visit in chunks by block
Expand Down Expand Up @@ -132,7 +134,7 @@ export const makeQueryKit = (vstorage, m = makeClientMarshaller()) => {
}
}

const query = Far('QueryTool', {
const query = makeExo('QueryTool', M.interface('QueryTool', {}, { defaultGuards: 'passable' }), {
batchQuery,
queryData,
follow,
Expand Down
5 changes: 3 additions & 2 deletions contract/tools/ui-kit-goals/test-nameProxy.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import '@endo/init/debug.js';
import test from 'ava';

import { Far } from '@endo/far';
import { M } from '@endo/patterns';
import { makeExo } from '@endo/exo';
import { makeNameHubKit } from '@agoric/vats';
import { makeNameProxy } from './name-service-client.js';

test('makeNameProxy makes NameHub lookup convenient', async t => {
const k0 = makeNameHubKit();
const kb = makeNameHubKit();
k0.nameAdmin.update('brand', kb.nameHub, kb.nameAdmin);
const atomBrand = Far('Atom Brand', {});
const atomBrand = makeExo('Atom Brand', M.interface('Atom Brand', {}, { defaultGuards: 'passable' }), {});
kb.nameAdmin.update('Atom', atomBrand);

const agoricNames = k0.nameHub;
Expand Down
Loading