diff --git a/packages/dapp-svelte-wallet/api/src/lib-wallet.js b/packages/dapp-svelte-wallet/api/src/lib-wallet.js index 7e40719216a..cc0682f15d7 100644 --- a/packages/dapp-svelte-wallet/api/src/lib-wallet.js +++ b/packages/dapp-svelte-wallet/api/src/lib-wallet.js @@ -55,7 +55,7 @@ const cmp = (a, b) => { /** * @typedef {Object} MakeWalletParams - * @property {ZoeService} zoe + * @property {ERef} zoe * @property {Board} board * @property {NameHub} [agoricNames] * @property {NameHub} [namesByAddress] diff --git a/packages/dapp-svelte-wallet/api/test/test-getPursesNotifier.js b/packages/dapp-svelte-wallet/api/test/test-getPursesNotifier.js index 8194e81ad66..b55eba6f9f9 100644 --- a/packages/dapp-svelte-wallet/api/test/test-getPursesNotifier.js +++ b/packages/dapp-svelte-wallet/api/test/test-getPursesNotifier.js @@ -2,12 +2,13 @@ import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js'; import { makeIssuerKit } from '@agoric/ertp'; -import { makeZoe } from '@agoric/zoe'; +import { makeZoeKit } from '@agoric/zoe'; import fakeVatAdmin from '@agoric/zoe/tools/fakeVatAdmin.js'; // eslint-disable-next-line import/no-extraneous-dependencies import { makeBoard } from '@agoric/vats/src/lib-board.js'; // eslint-disable-next-line import/no-extraneous-dependencies import { makeNameHubKit } from '@agoric/vats/src/nameHub.js'; +import { E } from '@agoric/eventual-send'; import { Far } from '@agoric/marshal'; import { makeWallet } from '../src/lib-wallet.js'; @@ -24,7 +25,9 @@ function makeFakeMyAddressNameAdmin() { } const setup = async () => { - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const board = makeBoard(); const pursesStateChangeHandler = _data => {}; diff --git a/packages/dapp-svelte-wallet/api/test/test-lib-wallet.js b/packages/dapp-svelte-wallet/api/test/test-lib-wallet.js index 175b873f718..be2768c867c 100644 --- a/packages/dapp-svelte-wallet/api/test/test-lib-wallet.js +++ b/packages/dapp-svelte-wallet/api/test/test-lib-wallet.js @@ -5,11 +5,11 @@ import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js'; import bundleSource from '@agoric/bundle-source'; import { makeIssuerKit, AmountMath, AssetKind } from '@agoric/ertp'; -import { makeZoe } from '@agoric/zoe'; +import { makeZoeKit } from '@agoric/zoe'; import fakeVatAdmin from '@agoric/zoe/tools/fakeVatAdmin.js'; +import { E } from '@agoric/eventual-send'; import { assert } from '@agoric/assert'; -import { E } from '@agoric/eventual-send'; // eslint-disable-next-line import/no-extraneous-dependencies import { makeBoard } from '@agoric/vats/src/lib-board.js'; // eslint-disable-next-line import/no-extraneous-dependencies @@ -45,7 +45,9 @@ async function setupTest() { const moolaBundle = makeIssuerKit('moola'); const simoleanBundle = makeIssuerKit('simolean'); const rpgBundle = makeIssuerKit('rpg', AssetKind.SET); - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const board = makeBoard(); // Create AutomaticRefund instance @@ -56,9 +58,9 @@ async function setupTest() { const automaticRefundContractRoot = new URL(automaticRefundContractUrl) .pathname; const automaticRefundBundle = await bundleSource(automaticRefundContractRoot); - const installation = await zoe.install(automaticRefundBundle); + const installation = await E(zoe).install(automaticRefundBundle); const issuerKeywordRecord = harden({ Contribution: moolaBundle.issuer }); - const { creatorInvitation: invite, instance } = await zoe.startInstance( + const { creatorInvitation: invite, instance } = await E(zoe).startInstance( installation, issuerKeywordRecord, ); @@ -71,7 +73,7 @@ async function setupTest() { ); const autoswapContractRoot = new URL(autoswapContractUrl).pathname; const autoswapBundle = await bundleSource(autoswapContractRoot); - const autoswapInstallationHandle = await zoe.install(autoswapBundle); + const autoswapInstallationHandle = await E(zoe).install(autoswapBundle); const autoswapIssuerKeywordRecord = harden({ Central: moolaBundle.issuer, Secondary: simoleanBundle.issuer, @@ -79,7 +81,7 @@ async function setupTest() { const { publicFacet: autoswapPublicFacet, instance: autoswapInstanceHandle, - } = await zoe.startInstance( + } = await E(zoe).startInstance( autoswapInstallationHandle, autoswapIssuerKeywordRecord, ); @@ -1193,7 +1195,9 @@ test('addOffer offer.invitation', async t => { }); test('addOffer makeContinuingInvitation', async t => { - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const board = makeBoard(); // Create ContinuingInvitationExample instance @@ -1203,8 +1207,10 @@ test('addOffer makeContinuingInvitation', async t => { ); const path = new URL(url).pathname; const bundle = await bundleSource(path); - const installation = await zoe.install(bundle); - const { creatorInvitation, instance } = await zoe.startInstance(installation); + const installation = await E(zoe).install(bundle); + const { creatorInvitation, instance } = await E(zoe).startInstance( + installation, + ); assert(creatorInvitation); const pursesStateChangeLog = []; @@ -1275,7 +1281,9 @@ test('addOffer makeContinuingInvitation', async t => { }); test('getZoe, getBoard', async t => { - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const board = makeBoard(); const pursesStateChangeHandler = _data => {}; @@ -1290,6 +1298,6 @@ test('getZoe, getBoard', async t => { }); await initialized; - t.is(await E(wallet).getZoe(), zoe); + t.is(await E(wallet).getZoe(), await zoe); t.is(await E(wallet).getBoard(), board); }); diff --git a/packages/deploy-script-support/test/unitTests/test-install.js b/packages/deploy-script-support/test/unitTests/test-install.js index 4e31be9bb54..86c84a7954c 100644 --- a/packages/deploy-script-support/test/unitTests/test-install.js +++ b/packages/deploy-script-support/test/unitTests/test-install.js @@ -1,18 +1,21 @@ // @ts-check import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js'; -import { makeZoe } from '@agoric/zoe'; +import { makeZoeKit } from '@agoric/zoe'; import fakeVatAdmin from '@agoric/zoe/tools/fakeVatAdmin.js'; import { makeBoard } from '@agoric/vats/src/lib-board.js'; import bundleSource from '@agoric/bundle-source'; import { resolve as importMetaResolve } from 'import-meta-resolve'; +import { E } from '@agoric/eventual-send'; import '../../exported.js'; import { makeInstall } from '../../src/install.js'; test('install', async t => { - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); let addedInstallation; diff --git a/packages/deploy-script-support/test/unitTests/test-offer.js b/packages/deploy-script-support/test/unitTests/test-offer.js index a3a8ea34dc0..60bf2ca7163 100644 --- a/packages/deploy-script-support/test/unitTests/test-offer.js +++ b/packages/deploy-script-support/test/unitTests/test-offer.js @@ -1,15 +1,15 @@ // @ts-check import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js'; -import { makeZoe } from '@agoric/zoe'; +import { makeZoeKit } from '@agoric/zoe'; import fakeVatAdmin from '@agoric/zoe/tools/fakeVatAdmin.js'; import bundleSource from '@agoric/bundle-source'; import { makeIssuerKit, AmountMath } from '@agoric/ertp'; import { resolve as importMetaResolve } from 'import-meta-resolve'; +import { E } from '@agoric/eventual-send'; import '../../exported.js'; -import { E } from '@agoric/eventual-send'; import { makeOfferAndFindInvitationAmount } from '../../src/offer.js'; test('offer', async t => { @@ -37,7 +37,9 @@ test('offer', async t => { }, saveOfferResult: () => {}, }; - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const bundleUrl = await importMetaResolve( '@agoric/zoe/src/contracts/automaticRefund.js', diff --git a/packages/deploy-script-support/test/unitTests/test-startInstance.js b/packages/deploy-script-support/test/unitTests/test-startInstance.js index ce8da8bd90c..c713282466c 100644 --- a/packages/deploy-script-support/test/unitTests/test-startInstance.js +++ b/packages/deploy-script-support/test/unitTests/test-startInstance.js @@ -1,15 +1,15 @@ // @ts-check import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js'; -import { makeZoe } from '@agoric/zoe'; +import { makeZoeKit } from '@agoric/zoe'; import fakeVatAdmin from '@agoric/zoe/tools/fakeVatAdmin.js'; import bundleSource from '@agoric/bundle-source'; import { makeIssuerKit } from '@agoric/ertp'; import { resolve as importMetaResolve } from 'import-meta-resolve'; +import { E } from '@agoric/eventual-send'; import '../../exported.js'; -import { E } from '@agoric/eventual-send'; import { makeStartInstance } from '../../src/startInstance.js'; test('startInstance', async t => { @@ -19,7 +19,9 @@ test('startInstance', async t => { const moolaKit = makeIssuerKit('moola'); const usdKit = makeIssuerKit('usd'); - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const bundleUrl = new URL( await importMetaResolve( diff --git a/packages/governance/test/swingsetTests/committeeBinary/vat-zoe.js b/packages/governance/test/swingsetTests/committeeBinary/vat-zoe.js index d546b3ad2c4..7544a16749c 100644 --- a/packages/governance/test/swingsetTests/committeeBinary/vat-zoe.js +++ b/packages/governance/test/swingsetTests/committeeBinary/vat-zoe.js @@ -2,10 +2,17 @@ import { Far } from '@agoric/marshal'; -import { makeZoe } from '@agoric/zoe'; +import { makeZoeKit } from '@agoric/zoe'; +import { E } from '@agoric/eventual-send'; -export function buildRootObject(_vatPowers) { +export function buildRootObject(vatPowers) { return Far('root', { - buildZoe: vatAdminSvc => makeZoe(vatAdminSvc), + buildZoe: vatAdminSvc => { + const shutdownZoeVat = vatPowers.exitVatWithFailure; + const { zoeService } = makeZoeKit(vatAdminSvc, shutdownZoeVat); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); + return zoe; + }, }); } diff --git a/packages/governance/test/unitTests/test-committee.js b/packages/governance/test/unitTests/test-committee.js index 7cabbc714ea..e39d97898a3 100644 --- a/packages/governance/test/unitTests/test-committee.js +++ b/packages/governance/test/unitTests/test-committee.js @@ -6,7 +6,7 @@ import '@agoric/zoe/exported.js'; import path from 'path'; import { E } from '@agoric/eventual-send'; -import { makeZoe } from '@agoric/zoe'; +import { makeZoeKit } from '@agoric/zoe'; import fakeVatAdmin from '@agoric/zoe/tools/fakeVatAdmin.js'; import bundleSource from '@agoric/bundle-source'; import buildManualTimer from '@agoric/zoe/tools/manualTimer.js'; @@ -20,7 +20,9 @@ const registrarRoot = `${dirname}/../../src/committeeRegistrar.js`; const counterRoot = `${dirname}/../../src/binaryBallotCounter.js`; async function setupContract() { - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // pack the contract const [registrarBundle, counterBundle] = await Promise.all([ @@ -29,8 +31,8 @@ async function setupContract() { ]); // install the contract const [registrarInstallation, counterInstallation] = await Promise.all([ - zoe.install(registrarBundle), - zoe.install(counterBundle), + E(zoe).install(registrarBundle), + E(zoe).install(counterBundle), ]); const terms = { committeeName: 'illuminati', committeeSize: 13 }; const registrarStartResult = await E(zoe).startInstance( diff --git a/packages/pegasus/bundles/install-on-chain.js b/packages/pegasus/bundles/install-on-chain.js index f28bb61a87a..cfd7db09430 100644 --- a/packages/pegasus/bundles/install-on-chain.js +++ b/packages/pegasus/bundles/install-on-chain.js @@ -11,7 +11,13 @@ import pegasusBundle from './bundle-pegasus.js'; * @param {NameHub} param0.namesByAddress * @param {ERef} param0.zoe */ -export async function installOnChain({ agoricNames, board, nameAdmins, namesByAddress, zoe }) { +export async function installOnChain({ + agoricNames, + board, + nameAdmins, + namesByAddress, + zoe, +}) { // Fetch the nameAdmins we need. const [installAdmin, instanceAdmin, uiConfigAdmin] = await Promise.all( ['installation', 'instance', 'uiConfig'].map(async edge => { @@ -38,8 +44,12 @@ export async function installOnChain({ agoricNames, board, nameAdmins, namesByAd namesByAddress, }); - const { instance, creatorFacet } = await E(zoe).startInstance(pegasusInstall, undefined, terms); - + const { instance, creatorFacet } = await E(zoe).startInstance( + pegasusInstall, + undefined, + terms, + ); + const pegasusUiDefaults = { CONTRACT_NAME: 'Pegasus', BRIDGE_URL: 'http://127.0.0.1:8000', @@ -49,14 +59,14 @@ export async function installOnChain({ agoricNames, board, nameAdmins, namesByAd }; // Look up all the board IDs. - const boardIdValue = [ - ['INSTANCE_BOARD_ID', instance], - ]; - await Promise.all(boardIdValue.map(async ([key, valP]) => { - const val = await valP; - const boardId = await E(board).getId(val); - pegasusUiDefaults[key] = boardId; - })); + const boardIdValue = [['INSTANCE_BOARD_ID', instance]]; + await Promise.all( + boardIdValue.map(async ([key, valP]) => { + const val = await valP; + const boardId = await E(board).getId(val); + pegasusUiDefaults[key] = boardId; + }), + ); // Stash the defaults where the UI can find them. harden(pegasusUiDefaults); @@ -69,7 +79,9 @@ export async function installOnChain({ agoricNames, board, nameAdmins, namesByAd [instanceAdmin, pegasusUiDefaults.CONTRACT_NAME, instance], ]; await Promise.all( - nameAdminUpdates.map(([nameAdmin, name, value]) => E(nameAdmin).update(name, value)), + nameAdminUpdates.map(([nameAdmin, name, value]) => + E(nameAdmin).update(name, value), + ), ); return creatorFacet; diff --git a/packages/pegasus/test/test-peg.js b/packages/pegasus/test/test-peg.js index e03241cbdc2..fab5886e99b 100644 --- a/packages/pegasus/test/test-peg.js +++ b/packages/pegasus/test/test-peg.js @@ -9,7 +9,7 @@ import { import bundleSource from '@agoric/bundle-source'; import { AmountMath } from '@agoric/ertp'; -import { makeZoe } from '@agoric/zoe'; +import { makeZoeKit } from '@agoric/zoe'; import fakeVatAdmin from '@agoric/zoe/tools/fakeVatAdmin.js'; import { Far } from '@agoric/marshal'; @@ -47,7 +47,9 @@ async function testRemotePeg(t) { }, }); - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Pack the contract. const contractBundle = await bundleSource(contractPath); diff --git a/packages/swingset-runner/demo/exchangeBenchmark/vat-zoe.js b/packages/swingset-runner/demo/exchangeBenchmark/vat-zoe.js index 150a446539c..e61b43d8197 100644 --- a/packages/swingset-runner/demo/exchangeBenchmark/vat-zoe.js +++ b/packages/swingset-runner/demo/exchangeBenchmark/vat-zoe.js @@ -1,8 +1,22 @@ -import { makeZoe } from '@agoric/zoe'; +// @ts-check + import { Far } from '@agoric/marshal'; -export function buildRootObject(_vatPowers, vatParameters) { +import { makeZoeKit } from '@agoric/zoe'; +import { E } from '@agoric/eventual-send'; + +export function buildRootObject(vatPowers, vatParameters) { return Far('root', { - buildZoe: vatAdminSvc => makeZoe(vatAdminSvc, vatParameters.zcfBundleName), + buildZoe: vatAdminSvc => { + const shutdownZoeVat = vatPowers.exitVatWithFailure; + const { zoeService } = makeZoeKit( + vatAdminSvc, + shutdownZoeVat, + vatParameters.zcfBundleName, + ); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); + return zoe; + }, }); } diff --git a/packages/swingset-runner/demo/swapBenchmark/vat-zoe.js b/packages/swingset-runner/demo/swapBenchmark/vat-zoe.js index 150a446539c..e61b43d8197 100644 --- a/packages/swingset-runner/demo/swapBenchmark/vat-zoe.js +++ b/packages/swingset-runner/demo/swapBenchmark/vat-zoe.js @@ -1,8 +1,22 @@ -import { makeZoe } from '@agoric/zoe'; +// @ts-check + import { Far } from '@agoric/marshal'; -export function buildRootObject(_vatPowers, vatParameters) { +import { makeZoeKit } from '@agoric/zoe'; +import { E } from '@agoric/eventual-send'; + +export function buildRootObject(vatPowers, vatParameters) { return Far('root', { - buildZoe: vatAdminSvc => makeZoe(vatAdminSvc, vatParameters.zcfBundleName), + buildZoe: vatAdminSvc => { + const shutdownZoeVat = vatPowers.exitVatWithFailure; + const { zoeService } = makeZoeKit( + vatAdminSvc, + shutdownZoeVat, + vatParameters.zcfBundleName, + ); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); + return zoe; + }, }); } diff --git a/packages/swingset-runner/demo/zoeTests/vat-zoe.js b/packages/swingset-runner/demo/zoeTests/vat-zoe.js index e7f14bfdde1..e61b43d8197 100644 --- a/packages/swingset-runner/demo/zoeTests/vat-zoe.js +++ b/packages/swingset-runner/demo/zoeTests/vat-zoe.js @@ -1,9 +1,22 @@ -// noinspection ES6PreferShortImport -import { makeZoe } from '@agoric/zoe'; +// @ts-check + import { Far } from '@agoric/marshal'; -export function buildRootObject(_vatPowers, vatParameters) { +import { makeZoeKit } from '@agoric/zoe'; +import { E } from '@agoric/eventual-send'; + +export function buildRootObject(vatPowers, vatParameters) { return Far('root', { - buildZoe: vatAdminSvc => makeZoe(vatAdminSvc, vatParameters.zcfBundleName), + buildZoe: vatAdminSvc => { + const shutdownZoeVat = vatPowers.exitVatWithFailure; + const { zoeService } = makeZoeKit( + vatAdminSvc, + shutdownZoeVat, + vatParameters.zcfBundleName, + ); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); + return zoe; + }, }); } diff --git a/packages/treasury/bundles/install-on-chain.js b/packages/treasury/bundles/install-on-chain.js index b3665cccf30..b7b25561eb8 100644 --- a/packages/treasury/bundles/install-on-chain.js +++ b/packages/treasury/bundles/install-on-chain.js @@ -1,5 +1,4 @@ // @ts-check -import { assert, details as X } from '@agoric/assert'; import { E } from '@agoric/eventual-send'; import liquidateBundle from './bundle-liquidateMinimum.js'; @@ -20,22 +19,51 @@ const DEFAULT_PROTOCOL_FEE = 6n; * @param {Store} param0.nameAdmins * @param {ERef} param0.priceAuthority * @param {ERef} param0.zoe + * @param {Handle<'feeMintAccess'>} param0.feeMintAccess * @param {NatValue} param0.bootstrapPaymentValue * @param {NatValue} [param0.poolFee] * @param {NatValue} [param0.protocolFee] */ -export async function installOnChain({ agoricNames, board, centralName, chainTimerService, nameAdmins, priceAuthority, zoe, bootstrapPaymentValue, poolFee = DEFAULT_POOL_FEE, protocolFee = DEFAULT_PROTOCOL_FEE }) { +export async function installOnChain({ + agoricNames, + board, + centralName, + chainTimerService, + nameAdmins, + priceAuthority, + zoe, + feeMintAccess, + bootstrapPaymentValue, + poolFee = DEFAULT_POOL_FEE, + protocolFee = DEFAULT_PROTOCOL_FEE, +}) { // Fetch the nameAdmins we need. - const [brandAdmin, installAdmin, instanceAdmin, issuerAdmin, uiConfigAdmin] = await Promise.all( - ['brand', 'installation', 'instance', 'issuer', 'uiConfig'].map(async edge => { - const hub = /** @type {NameHub} */ (await E(agoricNames).lookup(edge)); - return nameAdmins.get(hub); - }), + const [ + brandAdmin, + installAdmin, + instanceAdmin, + issuerAdmin, + uiConfigAdmin, + ] = await Promise.all( + ['brand', 'installation', 'instance', 'issuer', 'uiConfig'].map( + async edge => { + const hub = /** @type {NameHub} */ (await E(agoricNames).lookup(edge)); + return nameAdmins.get(hub); + }, + ), ); /** @type {Array<[string, SourceBundle]>} */ - const nameBundles = [['liquidate', liquidateBundle], ['autoswap', autoswapBundle], ['stablecoin', stablecoinBundle]]; - const [liquidationInstall, autoswapInstall, stablecoinMachineInstall] = await Promise.all( + const nameBundles = [ + ['liquidate', liquidateBundle], + ['autoswap', autoswapBundle], + ['stablecoin', stablecoinBundle], + ]; + const [ + liquidationInstall, + autoswapInstall, + stablecoinMachineInstall, + ] = await Promise.all( nameBundles.map(async ([name, bundle]) => { // Install the bundle in Zoe. const install = await E(zoe).install(bundle); @@ -62,8 +90,15 @@ export async function installOnChain({ agoricNames, board, centralName, chainTim bootstrapPaymentValue, }); - const { instance, creatorFacet } = await E(zoe).startInstance(stablecoinMachineInstall, undefined, terms); - + const privateArgs = harden({ feeMintAccess }); + + const { instance, creatorFacet } = await E(zoe).startInstance( + stablecoinMachineInstall, + undefined, + terms, + privateArgs, + ); + const [ ammInstance, invitationIssuer, @@ -71,7 +106,11 @@ export async function installOnChain({ agoricNames, board, centralName, chainTim issuers: { Governance: govIssuer, RUN: centralIssuer }, brands: { Governance: govBrand, RUN: centralBrand }, }, - ] = await Promise.all([E(creatorFacet).getAMM(), E(zoe).getInvitationIssuer(), E(zoe).getTerms(instance)]); + ] = await Promise.all([ + E(creatorFacet).getAMM(), + E(zoe).getInvitationIssuer(), + E(zoe).getTerms(instance), + ]); const treasuryUiDefaults = { CONTRACT_NAME: 'Treasury', @@ -93,11 +132,13 @@ export async function installOnChain({ agoricNames, board, centralName, chainTim ['AMM_INSTANCE_BOARD_ID', ammInstance], ['INVITE_BRAND_BOARD_ID', E(invitationIssuer).getBrand()], ]; - await Promise.all(boardIdValue.map(async ([key, valP]) => { - const val = await valP; - const boardId = await E(board).getId(val); - treasuryUiDefaults[key] = boardId; - })); + await Promise.all( + boardIdValue.map(async ([key, valP]) => { + const val = await valP; + const boardId = await E(board).getId(val); + treasuryUiDefaults[key] = boardId; + }), + ); // Stash the defaults where the UI can find them. harden(treasuryUiDefaults); @@ -113,7 +154,9 @@ export async function installOnChain({ agoricNames, board, centralName, chainTim [issuerAdmin, centralName, centralIssuer], ]; await Promise.all( - nameAdminUpdates.map(([nameAdmin, name, value]) => E(nameAdmin).update(name, value)), + nameAdminUpdates.map(([nameAdmin, name, value]) => + E(nameAdmin).update(name, value), + ), ); return creatorFacet; diff --git a/packages/treasury/src/stablecoinMachine.js b/packages/treasury/src/stablecoinMachine.js index 52539a27a37..9627d24d336 100644 --- a/packages/treasury/src/stablecoinMachine.js +++ b/packages/treasury/src/stablecoinMachine.js @@ -41,7 +41,7 @@ import { makeMakeCollectFeesInvitation } from './collectRewardFees.js'; const trace = makeTracer('ST'); /** @type {ContractStartFn} */ -export async function start(zcf) { +export async function start(zcf, privateArgs) { // loanParams has time limits for charging interest const { autoswapInstall, @@ -52,6 +52,8 @@ export async function start(zcf) { bootstrapPaymentValue = 0n, } = zcf.getTerms(); + const { feeMintAccess } = privateArgs; + assert.typeof( loanParams.chargingPeriod, 'bigint', @@ -66,7 +68,7 @@ export async function start(zcf) { ); const [runMint, govMint] = await Promise.all([ - zcf.makeZCFMint('RUN', undefined, harden({ decimalPlaces: 6 })), + zcf.registerFeeMint('RUN', feeMintAccess), zcf.makeZCFMint('Governance', undefined, harden({ decimalPlaces: 6 })), ]); const { issuer: runIssuer, brand: runBrand } = runMint.getIssuerRecord(); diff --git a/packages/treasury/test/swingsetTests/bootstrap.js b/packages/treasury/test/swingsetTests/bootstrap.js index 4ec9f97c3b5..1dcf68c00d7 100644 --- a/packages/treasury/test/swingsetTests/bootstrap.js +++ b/packages/treasury/test/swingsetTests/bootstrap.js @@ -20,7 +20,14 @@ const setupBasicMints = () => { }); }; -const makeVats = (log, vats, zoe, installations, startingValues) => { +const makeVats = ( + log, + vats, + zoe, + installations, + startingValues, + feeMintAccess, +) => { const timer = buildManualTimer(console.log, 0n, ONE_DAY); const { mints, issuers, brands } = setupBasicMints(); const makePayments = values => @@ -46,6 +53,7 @@ const makeVats = (log, vats, zoe, installations, startingValues) => { installations, timer, vats.priceAuthority, + feeMintAccess, ); const result = { aliceP, treasuryPublicFacet }; @@ -59,7 +67,11 @@ function makeBootstrap(argv, cb, vatPowers) { const vatAdminSvc = await E(vats.vatAdmin).createVatAdminService( devices.vatAdmin, ); - const zoe = E(vats.zoe).buildZoe(vatAdminSvc); + const { zoeService, feeMintAccess } = await E(vats.zoe).buildZoe( + vatAdminSvc, + ); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const [liquidateMinimum, autoswap, treasury] = await Promise.all([ E(zoe).install(cb.liquidateMinimum), E(zoe).install(cb.autoswap), @@ -75,6 +87,7 @@ function makeBootstrap(argv, cb, vatPowers) { zoe, installations, startingValues, + feeMintAccess, ); await E(aliceP).startTest(testName, treasuryPublicFacet); diff --git a/packages/treasury/test/swingsetTests/vat-owner.js b/packages/treasury/test/swingsetTests/vat-owner.js index fc798bb9162..5c601fb81cd 100644 --- a/packages/treasury/test/swingsetTests/vat-owner.js +++ b/packages/treasury/test/swingsetTests/vat-owner.js @@ -20,6 +20,7 @@ const build = async ( installations, timer, priceAuthorityVat, + feeMintAccess, ) => { const [moolaBrand] = brands; const [moolaPayment] = payments; @@ -45,6 +46,7 @@ const build = async ( installations.treasury, undefined, terms, + harden({ feeMintAccess }), ); const { diff --git a/packages/treasury/test/swingsetTests/vat-zoe.js b/packages/treasury/test/swingsetTests/vat-zoe.js index d546b3ad2c4..934583f2c0f 100644 --- a/packages/treasury/test/swingsetTests/vat-zoe.js +++ b/packages/treasury/test/swingsetTests/vat-zoe.js @@ -1,11 +1,13 @@ // @ts-check import { Far } from '@agoric/marshal'; +import { makeZoeKit } from '@agoric/zoe'; -import { makeZoe } from '@agoric/zoe'; - -export function buildRootObject(_vatPowers) { +export function buildRootObject(vatPowers) { return Far('root', { - buildZoe: vatAdminSvc => makeZoe(vatAdminSvc), + buildZoe: vatAdminSvc => { + const shutdownZoeVat = vatPowers.exitVatWithFailure; + return makeZoeKit(vatAdminSvc, shutdownZoeVat); + }, }); } diff --git a/packages/treasury/test/test-bootstrapPayment.js b/packages/treasury/test/test-bootstrapPayment.js index ac227302fae..93c9d0d0402 100644 --- a/packages/treasury/test/test-bootstrapPayment.js +++ b/packages/treasury/test/test-bootstrapPayment.js @@ -9,7 +9,7 @@ import path from 'path'; import { E } from '@agoric/eventual-send'; import bundleSource from '@agoric/bundle-source'; import fakeVatAdmin from '@agoric/zoe/tools/fakeVatAdmin.js'; -import { makeZoe } from '@agoric/zoe'; +import { makeZoeKit } from '@agoric/zoe'; import buildManualTimer from '@agoric/zoe/tools/manualTimer.js'; import { AmountMath } from '@agoric/ertp'; import { resolve as importMetaResolve } from 'import-meta-resolve'; @@ -33,7 +33,9 @@ const makeInstall = async (root, zoe) => { }; test('bootstrap payment', async t => { - const zoe = makeZoe(fakeVatAdmin); + const { zoeService, feeMintAccess } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const autoswapRoot = await autoswapRootP; const autoswapInstall = await makeInstall(autoswapRoot, zoe); const stablecoinInstall = await makeInstall(stablecoinRoot, zoe); @@ -61,6 +63,7 @@ test('bootstrap payment', async t => { bootstrapPaymentValue, }, + harden({ feeMintAccess }), ); const issuers = await E(zoe).getIssuers(instance); @@ -80,7 +83,9 @@ test('bootstrap payment', async t => { }); test('bootstrap payment - only minted once', async t => { - const zoe = makeZoe(fakeVatAdmin); + const { zoeService, feeMintAccess } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const autoswapRoot = await autoswapRootP; const autoswapInstall = await makeInstall(autoswapRoot, zoe); const stablecoinInstall = await makeInstall(stablecoinRoot, zoe); @@ -108,6 +113,7 @@ test('bootstrap payment - only minted once', async t => { bootstrapPaymentValue, }, + harden({ feeMintAccess }), ); const issuers = await E(zoe).getIssuers(instance); @@ -136,7 +142,9 @@ test('bootstrap payment - only minted once', async t => { }); test('bootstrap payment - default value is 0n', async t => { - const zoe = makeZoe(fakeVatAdmin); + const { zoeService, feeMintAccess } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const autoswapRoot = await autoswapRootP; const autoswapInstall = await makeInstall(autoswapRoot, zoe); const stablecoinInstall = await makeInstall(stablecoinRoot, zoe); @@ -159,6 +167,7 @@ test('bootstrap payment - default value is 0n', async t => { timerService: manualTimer, liquidationInstall, }, + harden({ feeMintAccess }), ); const issuers = await E(zoe).getIssuers(instance); diff --git a/packages/treasury/test/test-stablecoin.js b/packages/treasury/test/test-stablecoin.js index e382680e182..6c2aee59605 100644 --- a/packages/treasury/test/test-stablecoin.js +++ b/packages/treasury/test/test-stablecoin.js @@ -12,7 +12,7 @@ import { resolve as importMetaResolve } from 'import-meta-resolve'; import { makeFakeVatAdmin } from '@agoric/zoe/tools/fakeVatAdmin.js'; import { makeLoopback } from '@agoric/captp'; -import { makeZoe } from '@agoric/zoe'; +import { makeZoeKit } from '@agoric/zoe'; import { makeIssuerKit, AssetKind, AmountMath } from '@agoric/ertp'; import buildManualTimer from '@agoric/zoe/tools/manualTimer.js'; @@ -35,7 +35,7 @@ const trace = makeTracer('TestST'); const BASIS_POINTS = 10000n; const PERCENT = 100n; -function setUpZoeForTest(setJig) { +const setUpZoeForTest = async setJig => { const { makeFar, makeNear } = makeLoopback('zoeTest'); let isFirst = true; function makeRemote(arg) { @@ -46,7 +46,7 @@ function setUpZoeForTest(setJig) { } /** - * These properties will be asssigned by `setJig` in the contract. + * These properties will be assigned by `setJig` in the contract. * * @typedef {Object} TestContext * @property {ContractFacet} zcf @@ -55,11 +55,21 @@ function setUpZoeForTest(setJig) { * @property {ERef} autoswap */ + const { + zoeService: nonFarZoeService, + feeMintAccess: nonFarFeeMintAccess, + } = makeZoeKit(makeFakeVatAdmin(setJig, makeRemote).admin); + const feePurse = E(nonFarZoeService).makeFeePurse(); + const zoeService = await E(nonFarZoeService).bindDefaultFeePurse(feePurse); /** @type {ERef} */ - const zoe = makeFar(makeZoe(makeFakeVatAdmin(setJig, makeRemote).admin)); + const zoe = makeFar(zoeService); trace('makeZoe'); - return zoe; -} + const feeMintAccess = await makeFar(nonFarFeeMintAccess); + return { + zoe, + feeMintAccess, + }; +}; async function makeInstall(sourceRoot, zoe) { const url = await importMetaResolve(sourceRoot, import.meta.url); @@ -133,7 +143,7 @@ test('first', async t => { const setJig = jig => { testJig = jig; }; - const zoe = setUpZoeForTest(setJig); + const { zoe, feeMintAccess } = await setUpZoeForTest(setJig); const autoswapInstall = await makeInstall(autoswapRoot, zoe); const stablecoinInstall = await makeInstall(stablecoinRoot, zoe); @@ -164,6 +174,7 @@ test('first', async t => { timerService: manualTimer, liquidationInstall, }, + harden({ feeMintAccess }), ); const { runIssuerRecord, govIssuerRecord, autoswap: _autoswapAPI } = testJig; @@ -294,7 +305,7 @@ test('price drop', async t => { const setJig = jig => { testJig = jig; }; - const zoe = setUpZoeForTest(setJig); + const { zoe, feeMintAccess } = await setUpZoeForTest(setJig); const autoswapInstall = await makeInstall(autoswapRoot, zoe); const stablecoinInstall = await makeInstall(stablecoinRoot, zoe); @@ -329,6 +340,7 @@ test('price drop', async t => { timerService: manualTimer, liquidationInstall, }, + harden({ feeMintAccess }), ); const { runIssuerRecord, govIssuerRecord } = testJig; @@ -447,7 +459,7 @@ test('price falls precipitously', async t => { const setJig = jig => { testJig = jig; }; - const zoe = setUpZoeForTest(setJig); + const { zoe, feeMintAccess } = await setUpZoeForTest(setJig); const autoswapInstall = await makeInstall(autoswapRoot, zoe); const stablecoinInstall = await makeInstall(stablecoinRoot, zoe); @@ -487,6 +499,7 @@ test('price falls precipitously', async t => { timerService: manualTimer, liquidationInstall, }, + harden({ feeMintAccess }), ); const { runIssuerRecord, govIssuerRecord, autoswap: autoswapAPI } = testJig; @@ -603,7 +616,7 @@ test('stablecoin display collateral', async t => { const setJig = jig => { testJig = jig; }; - const zoe = setUpZoeForTest(setJig); + const { zoe, feeMintAccess } = await setUpZoeForTest(setJig); const autoswapInstall = await makeInstall(autoswapRoot, zoe); const stablecoinInstall = await makeInstall(stablecoinRoot, zoe); @@ -632,6 +645,7 @@ test('stablecoin display collateral', async t => { timerService: manualTimer, liquidationInstall, }, + harden({ feeMintAccess }), ); const { runIssuerRecord, govIssuerRecord, autoswap: _autoswapAPI } = testJig; @@ -691,7 +705,7 @@ test('interest on multiple vaults', async t => { const setJig = jig => { testJig = jig; }; - const zoe = setUpZoeForTest(setJig); + const { zoe, feeMintAccess } = await setUpZoeForTest(setJig); const autoswapInstall = await makeInstall(autoswapRoot, zoe); const stablecoinInstall = await makeInstall(stablecoinRoot, zoe); @@ -724,6 +738,7 @@ test('interest on multiple vaults', async t => { timerService: manualTimer, liquidationInstall, }, + harden({ feeMintAccess }), ); const { runIssuerRecord, govIssuerRecord, autoswap: _autoswapAPI } = testJig; @@ -898,7 +913,7 @@ test('adjust balances', async t => { const setJig = jig => { testJig = jig; }; - const zoe = setUpZoeForTest(setJig); + const { zoe, feeMintAccess } = await setUpZoeForTest(setJig); const autoswapInstall = await makeInstall(autoswapRoot, zoe); const stablecoinInstall = await makeInstall(stablecoinRoot, zoe); @@ -929,6 +944,7 @@ test('adjust balances', async t => { timerService: manualTimer, liquidationInstall, }, + harden({ feeMintAccess }), ); const { runIssuerRecord, govIssuerRecord } = testJig; @@ -1200,7 +1216,7 @@ test('overdeposit', async t => { const setJig = jig => { testJig = jig; }; - const zoe = setUpZoeForTest(setJig); + const { zoe, feeMintAccess } = await setUpZoeForTest(setJig); const autoswapInstall = await makeInstall(autoswapRoot, zoe); const stablecoinInstall = await makeInstall(stablecoinRoot, zoe); @@ -1231,6 +1247,7 @@ test('overdeposit', async t => { timerService: manualTimer, liquidationInstall, }, + harden({ feeMintAccess }), ); const { runIssuerRecord, govIssuerRecord } = testJig; @@ -1393,7 +1410,7 @@ test('mutable liquidity triggers and interest', async t => { const setJig = jig => { testJig = jig; }; - const zoe = setUpZoeForTest(setJig); + const { zoe, feeMintAccess } = await setUpZoeForTest(setJig); const autoswapInstall = await makeInstall(autoswapRoot, zoe); const stablecoinInstall = await makeInstall(stablecoinRoot, zoe); @@ -1427,6 +1444,7 @@ test('mutable liquidity triggers and interest', async t => { timerService: manualTimer, liquidationInstall, }, + harden({ feeMintAccess }), ); const { runIssuerRecord, govIssuerRecord } = testJig; @@ -1620,7 +1638,7 @@ test('mutable liquidity triggers and interest', async t => { test('bad chargingPeriod', async t => { /* @type {TestContext} */ const setJig = () => {}; - const zoe = setUpZoeForTest(setJig); + const { zoe, feeMintAccess } = await setUpZoeForTest(setJig); const autoswapInstall = await makeInstall(autoswapRoot, zoe); const stablecoinInstall = await makeInstall(stablecoinRoot, zoe); @@ -1648,6 +1666,7 @@ test('bad chargingPeriod', async t => { timerService: manualTimer, liquidationInstall, }, + harden({ feeMintAccess }), ), { message: 'chargingPeriod (2) must be a BigInt' }, ); @@ -1659,7 +1678,7 @@ test('coll fees from loan and AMM', async t => { const setJig = jig => { testJig = jig; }; - const zoe = setUpZoeForTest(setJig); + const { zoe, feeMintAccess } = await setUpZoeForTest(setJig); const autoswapInstall = await makeInstall(autoswapRoot, zoe); const stablecoinInstall = await makeInstall(stablecoinRoot, zoe); @@ -1690,6 +1709,7 @@ test('coll fees from loan and AMM', async t => { timerService: manualTimer, liquidationInstall, }, + harden({ feeMintAccess }), ); const { runIssuerRecord, govIssuerRecord, autoswap: _autoswapAPI } = testJig; @@ -1796,7 +1816,7 @@ test('close loan', async t => { const setJig = jig => { testJig = jig; }; - const zoe = setUpZoeForTest(setJig); + const { zoe, feeMintAccess } = await setUpZoeForTest(setJig); const autoswapInstall = await makeInstall(autoswapRoot, zoe); const stablecoinInstall = await makeInstall(stablecoinRoot, zoe); @@ -1827,6 +1847,7 @@ test('close loan', async t => { timerService: manualTimer, liquidationInstall, }, + harden({ feeMintAccess }), ); const { runIssuerRecord, govIssuerRecord } = testJig; const { issuer: runIssuer, brand: runBrand } = runIssuerRecord; diff --git a/packages/treasury/test/test-vault-interest.js b/packages/treasury/test/test-vault-interest.js index 146d5d27c11..196b1ba2e4c 100644 --- a/packages/treasury/test/test-vault-interest.js +++ b/packages/treasury/test/test-vault-interest.js @@ -5,7 +5,7 @@ import '@agoric/zoe/exported.js'; import { E } from '@agoric/eventual-send'; import { makeFakeVatAdmin } from '@agoric/zoe/tools/fakeVatAdmin.js'; import { makeLoopback } from '@agoric/captp'; -import { makeZoe } from '@agoric/zoe'; +import { makeZoeKit } from '@agoric/zoe'; import bundleSource from '@agoric/bundle-source'; import { resolve as importMetaResolve } from 'import-meta-resolve'; @@ -39,9 +39,16 @@ const setJig = jig => { const { makeFar, makeNear: makeRemote } = makeLoopback('zoeTest'); +const { + zoeService: nonFarZoeService, + feeMintAccess: nonFarFeeMintAccess, +} = makeZoeKit(makeFakeVatAdmin(setJig, makeRemote).admin); +const feePurse = E(nonFarZoeService).makeFeePurse(); +const zoeService = await E(nonFarZoeService).bindDefaultFeePurse(feePurse); /** @type {ERef} */ -const zoe = makeFar(makeZoe(makeFakeVatAdmin(setJig, makeRemote).admin)); +const zoe = makeFar(zoeService); trace('makeZoe'); +const feeMintAccessP = makeFar(nonFarFeeMintAccess); /** * @param {ERef} zoeP @@ -52,9 +59,15 @@ async function launch(zoeP, sourceRoot) { const contractPath = new URL(contractUrl).pathname; const contractBundle = await bundleSource(contractPath); const installation = await E(zoeP).install(contractBundle); + const feeMintAccess = await feeMintAccessP; const { creatorInvitation, creatorFacet, instance } = await E( zoeP, - ).startInstance(installation); + ).startInstance( + installation, + undefined, + undefined, + harden({ feeMintAccess }), + ); const { runMint, collateralKit: { mint: collateralMint, brand: collaterlBrand }, diff --git a/packages/treasury/test/test-vault.js b/packages/treasury/test/test-vault.js index 2930c1146cd..b6d8faed469 100644 --- a/packages/treasury/test/test-vault.js +++ b/packages/treasury/test/test-vault.js @@ -6,7 +6,7 @@ import '@agoric/zoe/exported.js'; import { E } from '@agoric/eventual-send'; import { makeFakeVatAdmin } from '@agoric/zoe/tools/fakeVatAdmin.js'; import { makeLoopback } from '@agoric/captp'; -import { makeZoe } from '@agoric/zoe'; +import { makeZoeKit } from '@agoric/zoe'; import bundleSource from '@agoric/bundle-source'; import { resolve as importMetaResolve } from 'import-meta-resolve'; @@ -37,9 +37,16 @@ const setJig = jig => { const { makeFar, makeNear: makeRemote } = makeLoopback('zoeTest'); +const { + zoeService: nonFarZoeService, + feeMintAccess: nonFarFeeMintAccess, +} = makeZoeKit(makeFakeVatAdmin(setJig, makeRemote).admin); +const feePurse = E(nonFarZoeService).makeFeePurse(); +const zoeService = await E(nonFarZoeService).bindDefaultFeePurse(feePurse); /** @type {ERef} */ -const zoe = makeFar(makeZoe(makeFakeVatAdmin(setJig, makeRemote).admin)); +const zoe = makeFar(zoeService); trace('makeZoe'); +const feeMintAccessP = makeFar(nonFarFeeMintAccess); /** * @param {ERef} zoeP @@ -50,9 +57,15 @@ async function launch(zoeP, sourceRoot) { const contractPath = new URL(contractUrl).pathname; const contractBundle = await bundleSource(contractPath); const installation = await E(zoeP).install(contractBundle); + const feeMintAccess = await feeMintAccessP; const { creatorInvitation, creatorFacet, instance } = await E( zoeP, - ).startInstance(installation); + ).startInstance( + installation, + undefined, + undefined, + harden({ feeMintAccess }), + ); const { runMint, collateralKit: { mint: collateralMint, brand: collaterlBrand }, diff --git a/packages/treasury/test/vault-contract-wrapper.js b/packages/treasury/test/vault-contract-wrapper.js index 13002206a44..80f267611c3 100644 --- a/packages/treasury/test/vault-contract-wrapper.js +++ b/packages/treasury/test/vault-contract-wrapper.js @@ -17,15 +17,16 @@ import { SECONDS_PER_YEAR } from '../src/interest.js'; const BASIS_POINTS = 10000n; -/** @param {ContractFacet} zcf */ -export async function start(zcf) { +/** @type {ContractStartFn} */ +export async function start(zcf, privateArgs) { console.log(`contract started`); + assert.typeof(privateArgs.feeMintAccess, 'object'); const collateralKit = makeIssuerKit('Collateral'); const { brand: collateralBrand } = collateralKit; await zcf.saveIssuer(collateralKit.issuer, 'Collateral'); // todo: CollateralETH, etc - const runMint = await zcf.makeZCFMint('RUN'); + const runMint = await zcf.registerFeeMint('RUN', privateArgs.feeMintAccess); const { brand: runBrand } = runMint.getIssuerRecord(); const { zcfSeat: _collateralSt, userSeat: liqSeat } = zcf.makeEmptySeatKit(); diff --git a/packages/vats/src/bootstrap.js b/packages/vats/src/bootstrap.js index 99690258caa..200f7c5f36a 100644 --- a/packages/vats/src/bootstrap.js +++ b/packages/vats/src/bootstrap.js @@ -75,14 +75,16 @@ export function buildRootObject(vatPowers, vatParameters) { sharingService, board, chainTimerService, - zoe, + { zoeService: zoe, feeMintAccess }, { priceAuthority, adminFacet: priceAuthorityAdmin }, ] = await Promise.all([ E(bankVat).makeBankManager(bankBridgeManager), E(vats.sharing).getSharingService(), E(vats.board).getBoard(), E(vats.timer).createTimerService(timerDevice), - /** @type {ERef} */ (E(vats.zoe).buildZoe(vatAdminSvc)), + /** @type {Promise<{ zoeService: ZoeService, feeMintAccess: FeeMintAccess }>} */ (E( + vats.zoe, + ).buildZoe(vatAdminSvc)), E(vats.priceAuthority).makePriceAuthority(), ]); @@ -129,6 +131,7 @@ export function buildRootObject(vatPowers, vatParameters) { priceAuthority, zoe, bootstrapPaymentValue, + feeMintAccess, }), installPegasusOnChain({ agoricNames, diff --git a/packages/vats/src/vat-zoe.js b/packages/vats/src/vat-zoe.js index c2564f40335..c5e2f482da4 100644 --- a/packages/vats/src/vat-zoe.js +++ b/packages/vats/src/vat-zoe.js @@ -1,8 +1,11 @@ import { Far } from '@agoric/marshal'; -import { makeZoe } from '@agoric/zoe'; +import { makeZoeKit } from '@agoric/zoe'; -export function buildRootObject(_vatPowers, vatParameters) { +export function buildRootObject(vatPowers, vatParameters) { return Far('root', { - buildZoe: adminVat => makeZoe(adminVat, vatParameters.zcfBundleName), + buildZoe: adminVat => { + const shutdownZoeVat = vatPowers.exitVatWithFailure; + makeZoeKit(adminVat, shutdownZoeVat, vatParameters.zcfBundleName); + }, }); } diff --git a/packages/zoe/src/contractFacet/internal-types.js b/packages/zoe/src/contractFacet/internal-types.js index 88367d9659e..70e1875b0ba 100644 --- a/packages/zoe/src/contractFacet/internal-types.js +++ b/packages/zoe/src/contractFacet/internal-types.js @@ -20,6 +20,7 @@ * @param {ERef} zoeService * @param {Issuer} invitationIssuer * @param {Function | undefined} testJigSetter + * @param {ERef} feePurse * @returns {ZCFZygote} */ diff --git a/packages/zoe/src/contractFacet/types.js b/packages/zoe/src/contractFacet/types.js index f17993d8fd4..c6af1523fd5 100644 --- a/packages/zoe/src/contractFacet/types.js +++ b/packages/zoe/src/contractFacet/types.js @@ -39,9 +39,11 @@ * @property {(brand: Brand) => Issuer} getIssuerForBrand * @property {GetAssetKindByBrand} getAssetKind * @property {MakeZCFMint} makeZCFMint + * @property {ZCFRegisterFeeMint} registerFeeMint * @property {ZCFMakeEmptySeatKit} makeEmptySeatKit * @property {SetTestJig} setTestJig * @property {() => void} stopAcceptingOffers + * @property {() => Instance} getInstance */ /** @@ -107,6 +109,14 @@ * @returns {Promise} */ +/** + * @callback ZCFRegisterFeeMint + * @param {Keyword} keyword + * @param {FeeMintAccess} allegedFeeMintAccess - an object that + * purports to be the object that grants access to the fee mint + * @returns {Promise + */ + /** * Provide a jig object for testing purposes only. * diff --git a/packages/zoe/src/contractFacet/vatRoot.js b/packages/zoe/src/contractFacet/vatRoot.js index 2ff6bf8c546..7a045e01950 100644 --- a/packages/zoe/src/contractFacet/vatRoot.js +++ b/packages/zoe/src/contractFacet/vatRoot.js @@ -36,6 +36,7 @@ export function buildRootObject(powers, _params, testJigSetter = undefined) { instanceRecordFromZoe, issuerStorageFromZoe, privateArgs = undefined, + feePurse, ) => { /** @type {ZCFZygote} */ const zcfZygote = makeZCFZygote( @@ -43,6 +44,7 @@ export function buildRootObject(powers, _params, testJigSetter = undefined) { zoeService, invitationIssuer, testJigSetter, + feePurse, ); zcfZygote.evaluateContract(bundle); return zcfZygote.startContract( diff --git a/packages/zoe/src/contractFacet/zcfZygote.js b/packages/zoe/src/contractFacet/zcfZygote.js index 9710e5659d3..ccd2efb4dbc 100644 --- a/packages/zoe/src/contractFacet/zcfZygote.js +++ b/packages/zoe/src/contractFacet/zcfZygote.js @@ -29,6 +29,7 @@ export const makeZCFZygote = ( zoeService, invitationIssuer, testJigSetter, + feePurse, ) => { /** @type {PromiseRecord} */ const zoeInstanceAdminPromiseKit = makePromiseKit(); @@ -120,19 +121,8 @@ export const makeZCFZygote = ( assert(amountKeywordRecord !== null, X`${name} cannot be null`); }; - /** @type {MakeZCFMint} */ - const makeZCFMint = async ( - keyword, - assetKind = AssetKind.NAT, - displayInfo, - ) => { - assertUniqueKeyword(keyword); - - const zoeMintP = E(zoeInstanceAdmin).makeZoeMint( - keyword, - assetKind, - displayInfo, - ); + // A helper for the code shared between MakeZCFMint and RegisterZCFMint + const doMakeZCFMint = async (keyword, zoeMintP) => { const { brand: mintyBrand, issuer: mintyIssuer, @@ -146,7 +136,7 @@ export const makeZCFZygote = ( ); recordIssuer(keyword, mintyIssuerRecord); - const empty = AmountMath.makeEmpty(mintyBrand, assetKind); + const empty = AmountMath.makeEmpty(mintyBrand, mintyDisplayInfo.assetKind); const add = (total, amountToAdd) => { return AmountMath.add(total, amountToAdd, mintyBrand); }; @@ -193,6 +183,34 @@ export const makeZCFZygote = ( return zcfMint; }; + /** @type {MakeZCFMint} */ + const makeZCFMint = async ( + keyword, + assetKind = AssetKind.NAT, + displayInfo, + ) => { + assertUniqueKeyword(keyword); + + const zoeMintP = E(zoeInstanceAdmin).makeZoeMint( + keyword, + assetKind, + displayInfo, + ); + + return doMakeZCFMint(keyword, zoeMintP); + }; + + /** @type {ZCFRegisterFeeMint} */ + const registerFeeMint = async (keyword, feeMintAccess) => { + assertUniqueKeyword(keyword); + + const zoeMintP = E(zoeInstanceAdmin).registerFeeMint( + keyword, + feeMintAccess, + ); + return doMakeZCFMint(keyword, zoeMintP); + }; + /** @type {ContractFacet} */ const zcf = Far('zcf', { reallocate, @@ -238,10 +256,11 @@ export const makeZCFZygote = ( assert: makeAssert(shutdownWithFailure), stopAcceptingOffers: () => E(zoeInstanceAdmin).stopAcceptingOffers(), makeZCFMint, + registerFeeMint, makeEmptySeatKit, // The methods below are pure and have no side-effects // - getZoeService: () => zoeService, + getZoeService: () => E(zoeService).bindDefaultFeePurse(feePurse), getInvitationIssuer: () => invitationIssuer, getTerms, getBrandForIssuer, diff --git a/packages/zoe/src/internal-types.js b/packages/zoe/src/internal-types.js index 640fe5530cd..51f63cbd640 100644 --- a/packages/zoe/src/internal-types.js +++ b/packages/zoe/src/internal-types.js @@ -118,6 +118,7 @@ * keyword: Keyword * ) => Promise} saveIssuer * @property {MakeZoeMint} makeZoeMint + * @property {RegisterFeeMint} registerFeeMint * @property {MakeNoEscrowSeat} makeNoEscrowSeat * @property {ReplaceAllocations} replaceAllocations * @property {(completion: Completion) => void} exitAllSeats @@ -125,6 +126,21 @@ * @property {() => void} stopAcceptingOffers */ +/** + * @callback RegisterFeeMint + * @param {Keyword} keyword - the keyword to use for the issuer + * @param {FeeMintAccess} allegedFeeMintAccess - an object that + * purports to be the object that allows access to the feeMint + * @returns {ZoeMint} + */ + +/** + * @callback WrapIssuerKitWithZoeMint + * @param {Keyword} keyword - the keyword to use for the issuer + * @param {IssuerKit} localIssuerKit - an issuer kit that originates + * within Zoe + */ + /** * @callback MakeZoeMint * @param {Keyword} keyword @@ -183,6 +199,7 @@ * @param {InstanceRecord} instanceRecord * @param {IssuerRecords} issuerStorageFromZoe * @param {Object=} privateArgs + * @param {ERef} feePurse * @returns {Promise} * */ @@ -209,6 +226,13 @@ * @property {AdminNode} adminNode */ +/** + * @typedef RootAndAdminNodeAndMeter + * @property {Object} root + * @property {AdminNode} adminNode + * @property {Meter} meter + */ + /** * @typedef {Object} AdminNode * A powerful object that can be used to terminate the vat in which a contract diff --git a/packages/zoe/src/issuerStorage.js b/packages/zoe/src/issuerStorage.js index d5f05a7d514..31ed742c2b5 100644 --- a/packages/zoe/src/issuerStorage.js +++ b/packages/zoe/src/issuerStorage.js @@ -127,7 +127,7 @@ export const makeIssuerStorage = () => { /** * - * @param {IssuerPKeywordRecord} uncleanIssuerKeywordRecord + * @param {IssuerKeywordRecord} uncleanIssuerKeywordRecord * @returns {Promise<{ issuers: IssuerKeywordRecord, * brands: BrandKeywordRecord }>} */ diff --git a/packages/zoe/src/zoeService/createZCFVat.js b/packages/zoe/src/zoeService/createZCFVat.js index d45ce2f8786..cca4b215412 100644 --- a/packages/zoe/src/zoeService/createZCFVat.js +++ b/packages/zoe/src/zoeService/createZCFVat.js @@ -13,10 +13,17 @@ import zcfContractBundle from '../../bundles/bundle-contractFacet.js'; export const setupCreateZCFVat = (vatAdminSvc, zcfBundleName = undefined) => { /** @type {CreateZCFVat} */ const createZCFVat = async () => { - const meter = await E(vatAdminSvc).createUnlimitedMeter(); - return typeof zcfBundleName === 'string' - ? E(vatAdminSvc).createVatByName(zcfBundleName, { meter }) - : E(vatAdminSvc).createVat(zcfContractBundle, { meter }); + // const remaining = 100_000_000n; // 100M computrons + // const threshold = 20_000_000n; // notify below 20M + const remaining = 100_000_000n; // 100M computrons + const threshold = 10n; // notify below 20M + const meter = await E(vatAdminSvc).createMeter(remaining, threshold); + const rootAndAdminNodeP = + typeof zcfBundleName === 'string' + ? E(vatAdminSvc).createVatByName(zcfBundleName, { meter }) + : E(vatAdminSvc).createVat(zcfContractBundle, { meter }); + const rootAndAdminNode = await rootAndAdminNodeP; + return harden({ meter, ...rootAndAdminNode }); }; return createZCFVat; }; diff --git a/packages/zoe/src/zoeService/feeMint.js b/packages/zoe/src/zoeService/feeMint.js new file mode 100644 index 00000000000..20bf971443b --- /dev/null +++ b/packages/zoe/src/zoeService/feeMint.js @@ -0,0 +1,53 @@ +// @ts-check + +import { makeIssuerKit, AmountMath } from '@agoric/ertp'; + +import { makeHandle } from '../makeHandle.js'; + +const { details: X } = assert; +/** + * @param {FeeIssuerConfig} feeIssuerConfig + * @param {ShutdownWithFailure} shutdownZoeVat + * @returns {{ + * feeMintAccess: FeeMintAccess, + * getFeeIssuerKit: GetFeeIssuerKit, + * feeIssuer: Issuer, + * feeBrand: Brand, + * initialFeeFunds: Payment, + * }} + */ +const createFeeMint = (feeIssuerConfig, shutdownZoeVat) => { + /** @type {IssuerKit} */ + const feeIssuerKit = makeIssuerKit( + feeIssuerConfig.name, + feeIssuerConfig.assetKind, + feeIssuerConfig.displayInfo, + shutdownZoeVat, + ); + + /** @type {FeeMintAccess} */ + const feeMintAccess = makeHandle('feeMintAccess'); + + /** @type {GetFeeIssuerKit} */ + const getFeeIssuerKit = allegedFeeMintAccess => { + assert( + feeMintAccess === allegedFeeMintAccess, + X`The object representing access to the fee brand mint was not provided`, + ); + return feeIssuerKit; + }; + + const initialFeeFunds = feeIssuerKit.mint.mintPayment( + AmountMath.make(feeIssuerKit.brand, feeIssuerConfig.initialFunds), + ); + + return harden({ + feeMintAccess, + getFeeIssuerKit, + feeIssuer: feeIssuerKit.issuer, + feeBrand: feeIssuerKit.brand, + initialFeeFunds, + }); +}; + +export { createFeeMint }; diff --git a/packages/zoe/src/zoeService/feePurse.js b/packages/zoe/src/zoeService/feePurse.js new file mode 100644 index 00000000000..cac5586a43e --- /dev/null +++ b/packages/zoe/src/zoeService/feePurse.js @@ -0,0 +1,95 @@ +// @ts-check + +import { Far } from '@agoric/marshal'; +import { E } from '@agoric/eventual-send'; + +const { details: X } = assert; + +/** + * + * @param {Issuer} feeIssuer + * @returns {{ + * makeFeePurse: MakeFeePurse + * chargeZoeFee: ChargeZoeFee, + * getFeeCollectionPurse: GetFeeCollectionPurse, + * }} + */ +const setupMakeFeePurse = feeIssuer => { + const feePurses = new WeakSet(); + + const collectionPurse = feeIssuer.makeEmptyPurse(); + + /** @type {MakeFeePurse} */ + const makeFeePurse = async () => { + const purse = feeIssuer.makeEmptyPurse(); + /** @type {FeePurse} */ + const feePurse = Far('feePurse', { + ...purse, + }); + feePurses.add(feePurse); + + // After keeping the purse methods, we throw away the purse + return feePurse; + }; + + /** @type {ChargeZoeFee} */ + const chargeZoeFee = (feePurse, feeAmount) => { + return E.when(feePurse, fp => { + assert(feePurses.has(fp), X`A feePurse must be provided, not ${fp}`); + collectionPurse.deposit(fp.withdraw(feeAmount)); + }); + }; + + /** @type {GetFeeCollectionPurse} */ + const getFeeCollectionPurse = () => collectionPurse; + + return { + makeFeePurse, + chargeZoeFee, + getFeeCollectionPurse, + }; +}; + +const bindDefaultFeePurse = (zoeService, defaultFeePurse) => + Far('bound zoeService', { + // The functions from zoe not overridden below have no impact on + // state within Zoe + ...zoeService, + + install: (bundle, feePurse = defaultFeePurse) => + zoeService.install(bundle, feePurse), + startInstance: ( + installation, + issuerKeywordRecord, + terms, + privateArgs, + feePurse = defaultFeePurse, + ) => + zoeService.startInstance( + installation, + issuerKeywordRecord, + terms, + privateArgs, + feePurse, + ), + offer: ( + invitation, + proposal, + paymentKeywordRecord, + offerArgs, + feePurse = defaultFeePurse, + ) => + zoeService.offer( + invitation, + proposal, + paymentKeywordRecord, + offerArgs, + feePurse, + ), + getPublicFacet: (instance, feePurse = defaultFeePurse) => + zoeService.getPublicFacet(instance, feePurse), + }); + +harden(setupMakeFeePurse); +harden(bindDefaultFeePurse); +export { setupMakeFeePurse, bindDefaultFeePurse }; diff --git a/packages/zoe/src/zoeService/installationStorage.js b/packages/zoe/src/zoeService/installationStorage.js index 55fc6c27b63..4330c157347 100644 --- a/packages/zoe/src/zoeService/installationStorage.js +++ b/packages/zoe/src/zoeService/installationStorage.js @@ -4,7 +4,11 @@ import { assert, details as X } from '@agoric/assert'; import { Far } from '@agoric/marshal'; import { E } from '@agoric/eventual-send'; -export const makeInstallationStorage = () => { +/** + * @param {ChargeZoeFee} chargeZoeFee + * @param {Amount} installFeeAmount + */ +export const makeInstallationStorage = (chargeZoeFee, installFeeAmount) => { /** @type {WeakSet} */ const installations = new WeakSet(); @@ -12,9 +16,10 @@ export const makeInstallationStorage = () => { * Create an installation by permanently storing the bundle. It will be * evaluated each time it is used to make a new instance of a contract. */ - /** @type {Install} */ - const install = bundle => { + /** @type {InstallFeePurseRequired} */ + const install = async (bundle, feePurse) => { assert.typeof(bundle, 'object', X`a bundle must be provided`); + await chargeZoeFee(feePurse, installFeeAmount); /** @type {Installation} */ const installation = Far('Installation', { getBundle: () => bundle, diff --git a/packages/zoe/src/zoeService/instanceAdminStorage.js b/packages/zoe/src/zoeService/instanceAdminStorage.js index 0cf647aa3d9..ff837028cbd 100644 --- a/packages/zoe/src/zoeService/instanceAdminStorage.js +++ b/packages/zoe/src/zoeService/instanceAdminStorage.js @@ -2,27 +2,36 @@ import { makeWeakStore } from '@agoric/store'; -export const makeInstanceAdminStorage = () => { +/** + * @param {ChargeZoeFee} chargeZoeFee + * @param {Amount} getPublicFacetFeeAmount + */ +export const makeInstanceAdminStorage = ( + chargeZoeFee, + getPublicFacetFeeAmount, +) => { /** @type {WeakStore} */ const instanceToInstanceAdmin = makeWeakStore('instance'); - /** @type {GetPublicFacet} */ - const getPublicFacet = instance => - instanceToInstanceAdmin.get(instance).getPublicFacet(); + /** @type {GetPublicFacetFeePurseRequired} */ + const getPublicFacet = async (instance, feePurse) => { + await chargeZoeFee(feePurse, getPublicFacetFeeAmount); + return instanceToInstanceAdmin.get(instance).getPublicFacet(); + }; /** @type {GetBrands} */ - const getBrands = instance => + const getBrands = async instance => instanceToInstanceAdmin.get(instance).getBrands(); /** @type {GetIssuers} */ - const getIssuers = instance => + const getIssuers = async instance => instanceToInstanceAdmin.get(instance).getIssuers(); /** @type {GetTerms} */ const getTerms = instance => instanceToInstanceAdmin.get(instance).getTerms(); /** @type {GetInstallationForInstance} */ - const getInstallationForInstance = instance => + const getInstallationForInstance = async instance => instanceToInstanceAdmin.get(instance).getInstallationForInstance(); return harden({ diff --git a/packages/zoe/src/zoeService/internal-types.js b/packages/zoe/src/zoeService/internal-types.js index 6bf53dc97c4..2def06da4a1 100644 --- a/packages/zoe/src/zoeService/internal-types.js +++ b/packages/zoe/src/zoeService/internal-types.js @@ -75,6 +75,7 @@ * @property {InstanceRecordGetBrands} getBrands * @property {SaveIssuer} saveIssuer * @property {MakeZoeMint} makeZoeMint + * @property {RegisterFeeMint} registerFeeMint * @property {GetInstanceRecord} getInstanceRecord * @property {GetIssuerRecords} getIssuerRecords * @property {WithdrawPayments} withdrawPayments @@ -97,6 +98,7 @@ * @param {Object} customTerms * @param {IssuerKeywordRecord} uncleanIssuerKeywordRecord * @param {Instance} instance + * @param {ERef} feePurse * @returns {ZoeInstanceStorageManager} */ @@ -121,5 +123,30 @@ * ZCF bundle * * @callback CreateZCFVat - * @returns {Promise} + * @returns {Promise} + */ + +/** + * @typedef {Handle<'feeMintAccess'>} FeeMintAccess + */ + +/** + * @callback GetFeeIssuerKit + * @param {FeeMintAccess} feeMintAccess + * @returns {IssuerKit} + */ + +/** + * @callback ChargeZoeFee + * @param {ERef} feePurse + * @param {Amount} feeAmount + * @returns {Promise} + */ + +/** + * @typedef {Object} Meter + * @property {(delta: bigint) => void} addRemaining + * @property {(newThreshold: bigint) => void} setThreshold + * @property {() => bigint} get + * @property {() => Notifier} getNotifier */ diff --git a/packages/zoe/src/zoeService/makeInvitation.js b/packages/zoe/src/zoeService/makeInvitation.js index e8762e7c345..14134576192 100644 --- a/packages/zoe/src/zoeService/makeInvitation.js +++ b/packages/zoe/src/zoeService/makeInvitation.js @@ -2,8 +2,13 @@ import { assert, details as X } from '@agoric/assert'; import { AmountMath, makeIssuerKit, AssetKind } from '@agoric/ertp'; -export const createInvitationKit = () => { - const invitationKit = makeIssuerKit('Zoe Invitation', AssetKind.SET); +export const createInvitationKit = shutdownZoeVat => { + const invitationKit = makeIssuerKit( + 'Zoe Invitation', + AssetKind.SET, + undefined, + shutdownZoeVat, + ); /** * @param {Instance} instance diff --git a/packages/zoe/src/zoeService/offer/offer.js b/packages/zoe/src/zoeService/offer/offer.js index 998cb728628..d1b47bf1bdf 100644 --- a/packages/zoe/src/zoeService/offer/offer.js +++ b/packages/zoe/src/zoeService/offer/offer.js @@ -16,6 +16,8 @@ const { details: X, quote: q } = assert; * @param {GetInstanceAdmin} getInstanceAdmin * @param {DepositPayments} depositPayments * @param {GetAssetKindByBrand} getAssetKindByBrand + * @param {ChargeZoeFee} chargeZoeFee + * @param {Amount} offerFeeAmount * @returns {Offer} */ export const makeOffer = ( @@ -23,13 +25,16 @@ export const makeOffer = ( getInstanceAdmin, depositPayments, getAssetKindByBrand, + chargeZoeFee, + offerFeeAmount, ) => { - /** @type {Offer} */ + /** @type {OfferFeePurseRequired} */ const offer = async ( invitation, uncleanProposal = harden({}), paymentKeywordRecord = harden({}), offerArgs = undefined, + feePurse, ) => { const { instanceHandle, invitationHandle } = await burnInvitation( invitationIssuer, @@ -37,6 +42,8 @@ export const makeOffer = ( ); // AWAIT /// + await chargeZoeFee(feePurse, offerFeeAmount); + const instanceAdmin = getInstanceAdmin(instanceHandle); instanceAdmin.assertAcceptingOffers(); diff --git a/packages/zoe/src/zoeService/refillMeter.js b/packages/zoe/src/zoeService/refillMeter.js new file mode 100644 index 00000000000..5bec54f238d --- /dev/null +++ b/packages/zoe/src/zoeService/refillMeter.js @@ -0,0 +1,41 @@ +// @ts-check + +import { E } from '@agoric/eventual-send'; +import { makeAsyncIterableFromNotifier as iterateNotifier } from '@agoric/notifier'; +import { AmountMath } from '@agoric/ertp'; +import { multiplyBy } from '../contractSupport/index.js'; + +/** + * @param {Meter} meter + * @param {ChargeZoeFee} chargeZoeFee + * @param {ERef} feePurse + * @param {bigint} incrementBy + * @param {Ratio} computronPrice + */ +const refillMeter = async ( + meter, + chargeZoeFee, + feePurse, + incrementBy, + computronPrice, +) => { + // computronPrice is a ratio of fee brand to computrons (fake computron + // brand) + + const computronBrand = computronPrice.denominator.brand; + + const feeToCharge = multiplyBy( + AmountMath.make(computronBrand, incrementBy), + computronPrice, + ); + + const meterNotifier = E(meter).getNotifier(); + + for await (const value of iterateNotifier(meterNotifier)) { + console.log('NOTIFIED', value); + await chargeZoeFee(feePurse, feeToCharge); + await E(meter).addRemaining(incrementBy); // will notify at the same threshold as before + } +}; +harden(refillMeter); +export { refillMeter }; diff --git a/packages/zoe/src/zoeService/startInstance.js b/packages/zoe/src/zoeService/startInstance.js index 946fa4b4ce2..7317d961324 100644 --- a/packages/zoe/src/zoeService/startInstance.js +++ b/packages/zoe/src/zoeService/startInstance.js @@ -14,20 +14,26 @@ import { handlePKitWarning } from '../handleWarning.js'; * @param {Promise} zoeServicePromise * @param {MakeZoeInstanceStorageManager} makeZoeInstanceStorageManager * @param {UnwrapInstallation} unwrapInstallation + * @param {ChargeZoeFee} chargeZoeFee + * @param {Amount} startInstanceFeeAmount * @returns {StartInstance} */ export const makeStartInstance = ( zoeServicePromise, makeZoeInstanceStorageManager, unwrapInstallation, + chargeZoeFee, + startInstanceFeeAmount, ) => { - /** @type {StartInstance} */ + /** @type {StartInstanceFeePurseRequired} */ const startInstance = async ( installationP, uncleanIssuerKeywordRecord = harden({}), customTerms = harden({}), privateArgs = undefined, + feePurse, ) => { + await chargeZoeFee(feePurse, startInstanceFeeAmount); /** @type {WeakStore} */ const seatHandleToZoeSeatAdmin = makeWeakStore('seatHandle'); @@ -180,6 +186,7 @@ export const makeStartInstance = ( exitAllSeats: completion => instanceAdmin.exitAllSeats(completion), failAllSeats: reason => instanceAdmin.failAllSeats(reason), makeZoeMint: zoeInstanceStorageManager.makeZoeMint, + registerFeeMint: zoeInstanceStorageManager.registerFeeMint, replaceAllocations: seatHandleAllocations => { try { seatHandleAllocations.forEach(({ seatHandle, allocation }) => { @@ -210,6 +217,7 @@ export const makeStartInstance = ( zoeInstanceStorageManager.getInstanceRecord(), zoeInstanceStorageManager.getIssuerRecords(), privateArgs, + feePurse, ); handleOfferObjPromiseKit.resolve(handleOfferObj); diff --git a/packages/zoe/src/zoeService/types.js b/packages/zoe/src/zoeService/types.js index a3691af804c..3ee53d5008a 100644 --- a/packages/zoe/src/zoeService/types.js +++ b/packages/zoe/src/zoeService/types.js @@ -16,7 +16,7 @@ * within its vat. The contract and ZCF never have direct access to * the users' payments or the Zoe purses. * - * @property {() => Issuer} getInvitationIssuer + * @property {GetInvitationIssuer} getInvitationIssuer * * Zoe has a single `invitationIssuer` for the entirety of its * lifetime. By having a reference to Zoe, a user can get the @@ -38,36 +38,82 @@ * @property {GetInvitationDetails} getInvitationDetails - return an * object with the instance, installation, description, invitation * handle, and any custom properties specific to the contract. + * @property {GetFeeIssuer} getFeeIssuer + * @property {MakeFeePurse} makeFeePurse + * @property {BindDefaultFeePurse} bindDefaultFeePurse + */ + +/** + * @callback GetInvitationIssuer + * @returns {Promise} + */ + +/** + * @callback GetFeeIssuer + * @returns {Promise} + */ + +/** + * @typedef {Purse} FeePurse + */ + +/** + * @callback MakeFeePurse + * @returns {Promise} + */ + +/** + * @callback GetFeeCollectionPurse + * + * Allows the caller of `makeZoeKit` to get the purse in which fees + * are collected. Note that these fees are for using Zoe, not for + * paying for execution in a ZCFVat. + * + * @returns {Purse} + */ + +/** + * @callback BindDefaultFeePurse + * @param {ERef} defaultFeePurse + * @returns {ZoeService} */ /** * @callback GetPublicFacet * @param {Instance} instance - * @returns {Object} + * @param {ERef=} feePurse + * @returns {Promise} + */ + +/** + * @callback GetPublicFacetFeePurseRequired + * @param {Instance} instance + * @param {ERef} feePurse + * @returns {Promise} */ /** * @callback GetIssuers * @param {Instance} instance - * @returns {IssuerKeywordRecord} + * @returns {Promise} */ /** * @callback GetBrands * @param {Instance} instance - * @returns {BrandKeywordRecord} + * @returns {Promise} */ /** * @callback GetTerms * @param {Instance} instance - * @returns {Terms} + * @returns {Promise} */ /** * @callback GetInstallationForInstance * @param {Instance} instance - * @returns {Installation} + * @returns {Promise} */ /** @@ -95,11 +141,23 @@ * registering it with Zoe. Returns an installation. * * @param {SourceBundle} bundle - * @returns {Installation} + * @param {ERef=} feePurse + * @returns {Promise} + */ + +/** + * @callback InstallFeePurseRequired + * + * See Install for comments. + * + * @param {SourceBundle} bundle + * @param {ERef} feePurse + * @returns {Promise} */ /** * @callback StartInstance + * * Zoe is long-lived. We can use Zoe to create smart contract * instances by specifying a particular contract installation to use, * as well as the `terms` of the contract. The `terms.issuers` is a @@ -121,6 +179,20 @@ * @param {Object=} privateArgs - an optional configuration object * that can be used to pass in arguments that should not be in the * public terms + * @param {ERef=} feePurse + * @returns {Promise} + */ + +/** + * @callback StartInstanceFeePurseRequired + * + * See StartInstance for comments. + * + * @param {ERef} installation + * @param {IssuerKeywordRecord=} issuerKeywordRecord + * @param {Object=} terms + * @param {Object=} privateArgs + * @param {ERef} feePurse * @returns {Promise} */ @@ -144,6 +216,21 @@ * @param {ERef} invitation * @param {Proposal=} proposal * @param {PaymentPKeywordRecord=} paymentKeywordRecord + * @param {Object=} offerArgs + * @param {ERef=} feePurse + * @returns {Promise} seat + */ + +/** + * @callback OfferFeePurseRequired + * + * See Offer for comments. + * + * @param {ERef} invitation + * @param {Proposal=} proposal + * @param {PaymentPKeywordRecord=} paymentKeywordRecord + * @param {Object=} offerArgs + * @param {ERef} feePurse * @returns {Promise} seat */ @@ -269,3 +356,41 @@ * @typedef {Object} Installation * @property {() => SourceBundle} getBundle */ + +/** + * @typedef {Object} FeeIssuerConfig + * @property {string} name + * @property {AssetKind} assetKind + * @property {DisplayInfo} displayInfo + * @property {Value} initialFunds + */ + +/** + * @typedef {Object} ZoeServiceFeePurseRequired + * + * See ZoeService for further comments and explanation (not copied here). + * + * @property {GetInvitationIssuer} getInvitationIssuer + * @property {InstallFeePurseRequired} install + * @property {StartInstanceFeePurseRequired} startInstance + * @property {OfferFeePurseRequired} offer + * @property {GetPublicFacetFeePurseRequired} getPublicFacet + * @property {GetIssuers} getIssuers + * @property {GetBrands} getBrands + * @property {GetTerms} getTerms + * @property {GetInstallationForInstance} getInstallationForInstance + * @property {GetInstance} getInstance + * @property {GetInstallation} getInstallation + * @property {GetInvitationDetails} getInvitationDetails + * @property {GetFeeIssuer} getFeeIssuer + * @property {MakeFeePurse} makeFeePurse + * @property {BindDefaultFeePurse} bindDefaultFeePurse + */ + +/** + * @typedef {Object} ZoeFeesConfig + * @property {NatValue} getPublicFacetFee + * @property {NatValue} installFee + * @property {NatValue} startInstanceFee + * @property {NatValue} offerFee + */ diff --git a/packages/zoe/src/zoeService/zoe.js b/packages/zoe/src/zoeService/zoe.js index 261e417e229..344c794bc9a 100644 --- a/packages/zoe/src/zoeService/zoe.js +++ b/packages/zoe/src/zoeService/zoe.js @@ -15,6 +15,7 @@ import '@agoric/store/exported.js'; import '../../exported.js'; import '../internal-types.js'; +import { AmountMath, AssetKind } from '@agoric/ertp'; import { Far } from '@agoric/marshal'; import { makePromiseKit } from '@agoric/promise-kit'; @@ -23,21 +24,86 @@ import { makeStartInstance } from './startInstance.js'; import { makeOffer } from './offer/offer.js'; import { makeInvitationQueryFns } from './invitationQueries.js'; import { setupCreateZCFVat } from './createZCFVat.js'; +import { createFeeMint } from './feeMint.js'; +import { bindDefaultFeePurse, setupMakeFeePurse } from './feePurse.js'; /** * Create an instance of Zoe. * * @param {VatAdminSvc} vatAdminSvc - The vatAdmin Service, which carries the power * to create a new vat. + * @param {ShutdownWithFailure} shutdownZoeVat - a function to + * shutdown the Zoe Vat. This function needs to use the vatPowers + * available to a vat. + * @param {FeeIssuerConfig} feeIssuerConfig + * @param {ZoeFeesConfig} zoeFees * @param {string} [zcfBundleName] - The name of the contract facet bundle. - * @returns {ZoeService} The created Zoe service. + * @returns {{ + * zoeService: ZoeService, + * feeMintAccess: FeeMintAccess, + * initialFeeFunds: Payment, + * getFeeCollectionPurse: GetFeeCollectionPurse, + * }} */ -const makeZoe = (vatAdminSvc, zcfBundleName = undefined) => { +const makeZoeKit = ( + vatAdminSvc, + shutdownZoeVat = () => {}, + feeIssuerConfig = { + name: 'RUN', + assetKind: AssetKind.NAT, + displayInfo: { decimalPlaces: 6, assetKind: AssetKind.NAT }, + initialFunds: 0n, + }, + zoeFees = { + getPublicFacetFee: 0n, + installFee: 0n, + startInstanceFee: 0n, + offerFee: 0n, + }, + zcfBundleName = undefined, +) => { // We must pass the ZoeService to `makeStartInstance` before it is // defined. See below where the promise is resolved. /** @type {PromiseRecord} */ const zoeServicePromiseKit = makePromiseKit(); + const { + feeMintAccess, + getFeeIssuerKit, + feeIssuer, + feeBrand, + initialFeeFunds, + } = createFeeMint(feeIssuerConfig, shutdownZoeVat); + + // The initial funds should be enough to pay for launching the + // Agoric economy. + assert( + AmountMath.isGTE( + AmountMath.make(feeBrand, feeIssuerConfig.initialFunds), + AmountMath.add( + AmountMath.make(feeBrand, zoeFees.installFee), + AmountMath.make(feeBrand, zoeFees.startInstanceFee), + ), + ), + ); + + const getPublicFacetFeeAmount = AmountMath.make( + feeBrand, + zoeFees.getPublicFacetFee, + ); + const installFeeAmount = AmountMath.make(feeBrand, zoeFees.installFee); + const startInstanceFeeAmount = AmountMath.make( + feeBrand, + zoeFees.startInstanceFee, + ); + const offerFeeAmount = AmountMath.make(feeBrand, zoeFees.offerFee); + + const { + makeFeePurse, + chargeZoeFee, + getFeeCollectionPurse, + } = setupMakeFeePurse(feeIssuer); + // This method contains the power to create a new ZCF Vat, and must // be closely held. vatAdminSvc is even more powerful - any vat can // be created. We severely restrict access to vatAdminSvc for this reason. @@ -58,21 +124,34 @@ const makeZoe = (vatAdminSvc, zcfBundleName = undefined) => { getInstallationForInstance, getInstanceAdmin, invitationIssuer, - } = makeZoeStorageManager(createZCFVat); + } = makeZoeStorageManager( + createZCFVat, + getFeeIssuerKit, + shutdownZoeVat, + chargeZoeFee, + getPublicFacetFeeAmount, + installFeeAmount, + incrementBy, + computronPrice, + ); - // Pass the capabilities necessary to create zoe.startInstance + // Pass the capabilities necessary to create E(zoe).startInstance const startInstance = makeStartInstance( zoeServicePromiseKit.promise, makeZoeInstanceStorageManager, unwrapInstallation, + chargeZoeFee, + startInstanceFeeAmount, ); - // Pass the capabilities necessary to create zoe.offer + // Pass the capabilities necessary to create E(zoe).offer const offer = makeOffer( invitationIssuer, getInstanceAdmin, depositPayments, getAssetKindByBrand, + chargeZoeFee, + offerFeeAmount, ); // Make the methods that allow users to easily and credibly get @@ -83,16 +162,20 @@ const makeZoe = (vatAdminSvc, zcfBundleName = undefined) => { getInvitationDetails, } = makeInvitationQueryFns(invitationIssuer); - /** @type {ZoeService} */ - const zoeService = Far('zoeService', { + /** @type {ZoeServiceFeePurseRequired} */ + const zoeService = Far('zoeServiceFeePurseRequired', { install, startInstance, offer, + makeFeePurse, + bindDefaultFeePurse: defaultFeePurse => + bindDefaultFeePurse(zoeService, defaultFeePurse), + getPublicFacet, // The functions below are getters only and have no impact on // state within Zoe - getInvitationIssuer: () => invitationIssuer, - getPublicFacet, + getInvitationIssuer: async () => invitationIssuer, + getFeeIssuer: async () => feeIssuer, getBrands, getIssuers, getTerms, @@ -107,7 +190,12 @@ const makeZoe = (vatAdminSvc, zcfBundleName = undefined) => { // defined. So, we pass a promise and then resolve the promise here. zoeServicePromiseKit.resolve(zoeService); - return zoeService; + return harden({ + zoeService, + feeMintAccess, + initialFeeFunds, + getFeeCollectionPurse, + }); }; -export { makeZoe }; +export { makeZoeKit }; diff --git a/packages/zoe/src/zoeService/zoeStorageManager.js b/packages/zoe/src/zoeService/zoeStorageManager.js index b7007ee124a..574ac7c5332 100644 --- a/packages/zoe/src/zoeService/zoeStorageManager.js +++ b/packages/zoe/src/zoeService/zoeStorageManager.js @@ -13,6 +13,7 @@ import { makeEscrowStorage } from './escrowStorage.js'; import { createInvitationKit } from './makeInvitation.js'; import { makeInstanceAdminStorage } from './instanceAdminStorage.js'; import { makeInstallationStorage } from './installationStorage.js'; +import { refillMeter } from './refillMeter.js'; /** * The Zoe Storage Manager encapsulates and composes important @@ -26,9 +27,25 @@ import { makeInstallationStorage } from './installationStorage.js'; * * @param {CreateZCFVat} createZCFVat - the ability to create a new * ZCF Vat + * @param {GetFeeIssuerKit} getFeeIssuerKit + * @param {ShutdownWithFailure} shutdownZoeVat + * @param {ChargeZoeFee} chargeZoeFee + * @param {Amount} getPublicFacetFeeAmount + * @param {Amount} installFeeAmount + * @param {bigint} incrementBy + * @param {Ratio} computronPrice * @returns {ZoeStorageManager} */ -export const makeZoeStorageManager = createZCFVat => { +export const makeZoeStorageManager = ( + createZCFVat, + getFeeIssuerKit, + shutdownZoeVat, + chargeZoeFee, + getPublicFacetFeeAmount, + installFeeAmount, + incrementBy, + computronPrice, +) => { // issuerStorage contains the issuers that the ZoeService knows // about, as well as information about them such as their brand, // assetKind, and displayInfo @@ -43,7 +60,9 @@ export const makeZoeStorageManager = createZCFVat => { // In order to participate in a contract, users must have // invitations, which are ERTP payments made by Zoe. This code // contains the mint capability for invitations. - const { setupMakeInvitation, invitationIssuer } = createInvitationKit(); + const { setupMakeInvitation, invitationIssuer } = createInvitationKit( + shutdownZoeVat, + ); // Every new instance of a contract creates a corresponding // "zoeInstanceAdmin" - an admin facet within the Zoe Service for @@ -58,12 +77,15 @@ export const makeZoeStorageManager = createZCFVat => { getInstanceAdmin, initInstanceAdmin, deleteInstanceAdmin, - } = makeInstanceAdminStorage(); + } = makeInstanceAdminStorage(chargeZoeFee, getPublicFacetFeeAmount); // Zoe stores "installations" - identifiable bundles of contract // code that can be reused again and again to create new contract // instances - const { install, unwrapInstallation } = makeInstallationStorage(); + const { install, unwrapInstallation } = makeInstallationStorage( + chargeZoeFee, + installFeeAmount, + ); /** @type {MakeZoeInstanceStorageManager} */ const makeZoeInstanceStorageManager = async ( @@ -71,6 +93,7 @@ export const makeZoeStorageManager = createZCFVat => { customTerms, uncleanIssuerKeywordRecord, instance, + feePurse, ) => { // Clean the issuerKeywordRecord we receive in `startInstance` // from the user, and save the issuers in Zoe if they are not @@ -106,22 +129,15 @@ export const makeZoeStorageManager = createZCFVat => { return issuerRecord; }; - /** @type {MakeZoeMint} */ - const makeZoeMint = (keyword, assetKind = AssetKind.NAT, displayInfo) => { - // Local indicates one that zoe itself makes from vetted code, - // and so can be assumed correct and fresh by zoe. + /** @type {WrapIssuerKitWithZoeMint} */ + const wrapIssuerKitWithZoeMint = (keyword, localIssuerKit) => { const { mint: localMint, issuer: localIssuer, brand: localBrand, displayInfo: localDisplayInfo, - } = makeIssuerKit( - keyword, - assetKind, - displayInfo, - // eslint-disable-next-line no-use-before-define - adminNode.terminateWithFailure, - ); + } = localIssuerKit; + const localIssuerRecord = makeIssuerRecord( localBrand, localIssuer, @@ -163,6 +179,26 @@ export const makeZoeStorageManager = createZCFVat => { return zoeMint; }; + /** @type {MakeZoeMint} */ + const makeZoeMint = (keyword, assetKind = AssetKind.NAT, displayInfo) => { + // Local indicates one that zoe itself makes from vetted code, + // and so can be assumed correct and fresh by zoe. + const localIssuerKit = makeIssuerKit( + keyword, + assetKind, + displayInfo, + // eslint-disable-next-line no-use-before-define + adminNode.terminateWithFailure, + ); + return wrapIssuerKitWithZoeMint(keyword, localIssuerKit); + }; + + /** @type {RegisterFeeMint} */ + const registerFeeMint = (keyword, allegedFeeMintAccess) => { + const feeIssuerKit = getFeeIssuerKit(allegedFeeMintAccess); + return wrapIssuerKitWithZoeMint(keyword, feeIssuerKit); + }; + /** @type {GetIssuerRecords} */ const getIssuerRecords = () => issuerStorage.getIssuerRecords( @@ -175,7 +211,17 @@ export const makeZoeStorageManager = createZCFVat => { const makeInvitation = setupMakeInvitation(instance, installation); - const { root, adminNode } = await createZCFVat(); + const { root, adminNode, meter } = await createZCFVat(); + + console.log('METER', meter); + + await refillMeter( + meter, + chargeZoeFee, + feePurse, + incrementBy, + computronPrice, + ); return harden({ getTerms: instanceRecordManager.getTerms, @@ -185,6 +231,7 @@ export const makeZoeStorageManager = createZCFVat => { instanceRecordManager.getInstallationForInstance, saveIssuer, makeZoeMint, + registerFeeMint, getInstanceRecord: instanceRecordManager.getInstanceRecord, getIssuerRecords, withdrawPayments: escrowStorage.withdrawPayments, diff --git a/packages/zoe/test/autoswapJig.js b/packages/zoe/test/autoswapJig.js index 80e13b21fad..79324117a7e 100644 --- a/packages/zoe/test/autoswapJig.js +++ b/packages/zoe/test/autoswapJig.js @@ -134,7 +134,7 @@ export const makeTrader = async (purses, zoe, publicFacet, centralIssuer) => { const invitation = swapIn ? E(publicFacet).makeSwapInInvitation() : E(publicFacet).makeSwapOutInvitation(); - const seat = await zoe.offer(invitation, proposal, payment); + const seat = await E(zoe).offer(invitation, proposal, payment); return seat; }, @@ -248,7 +248,7 @@ export const makeTrader = async (purses, zoe, publicFacet, centralIssuer) => { Secondary: withdrawPayment(sAmount), }); - const seat = await zoe.offer( + const seat = await E(zoe).offer( E(publicFacet).makeAddLiquidityInvitation(), proposal, payment, @@ -330,7 +330,7 @@ export const makeTrader = async (purses, zoe, publicFacet, centralIssuer) => { Liquidity: withdrawPayment(lAmount), }); - const seat = await zoe.offer( + const seat = await E(zoe).offer( E(publicFacet).makeRemoveLiquidityInvitation(), proposal, payment, @@ -396,7 +396,7 @@ export const makeTrader = async (purses, zoe, publicFacet, centralIssuer) => { Secondary: withdrawPayment(sAmount), }); - const seat = await zoe.offer( + const seat = await E(zoe).offer( await E(publicFacet).makeAddLiquidityInvitation(), proposal, payment, diff --git a/packages/zoe/test/swingsetTests/brokenContracts/vat-zoe.js b/packages/zoe/test/swingsetTests/brokenContracts/vat-zoe.js index d6b8436bed9..a78d5f8fb20 100644 --- a/packages/zoe/test/swingsetTests/brokenContracts/vat-zoe.js +++ b/packages/zoe/test/swingsetTests/brokenContracts/vat-zoe.js @@ -1,12 +1,19 @@ // @ts-check import { Far } from '@agoric/marshal'; +import { E } from '@agoric/eventual-send'; // noinspection ES6PreferShortImport -import { makeZoe } from '../../../src/zoeService/zoe.js'; +import { makeZoeKit } from '../../../src/zoeService/zoe.js'; -export function buildRootObject(_vatPowers) { +export function buildRootObject(vatPowers) { return Far('root', { - buildZoe: vatAdminSvc => makeZoe(vatAdminSvc), + buildZoe: vatAdminSvc => { + const shutdownZoeVat = vatPowers.exitVatWithFailure; + const { zoeService } = makeZoeKit(vatAdminSvc, shutdownZoeVat); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); + return zoe; + }, }); } diff --git a/packages/zoe/test/swingsetTests/makeKind/vat-zoe.js b/packages/zoe/test/swingsetTests/makeKind/vat-zoe.js index 463e1cff30a..a78d5f8fb20 100644 --- a/packages/zoe/test/swingsetTests/makeKind/vat-zoe.js +++ b/packages/zoe/test/swingsetTests/makeKind/vat-zoe.js @@ -1,10 +1,19 @@ +// @ts-check + import { Far } from '@agoric/marshal'; +import { E } from '@agoric/eventual-send'; // noinspection ES6PreferShortImport -import { makeZoe } from '../../../src/zoeService/zoe.js'; +import { makeZoeKit } from '../../../src/zoeService/zoe.js'; -export function buildRootObject(_vatPowers) { +export function buildRootObject(vatPowers) { return Far('root', { - buildZoe: vatAdminSvc => makeZoe(vatAdminSvc), + buildZoe: vatAdminSvc => { + const shutdownZoeVat = vatPowers.exitVatWithFailure; + const { zoeService } = makeZoeKit(vatAdminSvc, shutdownZoeVat); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); + return zoe; + }, }); } diff --git a/packages/zoe/test/swingsetTests/offerArgs/vat-zoe.js b/packages/zoe/test/swingsetTests/offerArgs/vat-zoe.js index 463e1cff30a..416de8633d5 100644 --- a/packages/zoe/test/swingsetTests/offerArgs/vat-zoe.js +++ b/packages/zoe/test/swingsetTests/offerArgs/vat-zoe.js @@ -1,10 +1,19 @@ +// @ts-check + import { Far } from '@agoric/marshal'; // noinspection ES6PreferShortImport -import { makeZoe } from '../../../src/zoeService/zoe.js'; +import { E } from '@agoric/eventual-send'; +import { makeZoeKit } from '../../../src/zoeService/zoe.js'; -export function buildRootObject(_vatPowers) { +export function buildRootObject(vatPowers) { return Far('root', { - buildZoe: vatAdminSvc => makeZoe(vatAdminSvc), + buildZoe: vatAdminSvc => { + const shutdownZoeVat = vatPowers.exitVatWithFailure; + const { zoeService } = makeZoeKit(vatAdminSvc, shutdownZoeVat); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); + return zoe; + }, }); } diff --git a/packages/zoe/test/swingsetTests/privateArgs/vat-zoe.js b/packages/zoe/test/swingsetTests/privateArgs/vat-zoe.js index 463e1cff30a..416de8633d5 100644 --- a/packages/zoe/test/swingsetTests/privateArgs/vat-zoe.js +++ b/packages/zoe/test/swingsetTests/privateArgs/vat-zoe.js @@ -1,10 +1,19 @@ +// @ts-check + import { Far } from '@agoric/marshal'; // noinspection ES6PreferShortImport -import { makeZoe } from '../../../src/zoeService/zoe.js'; +import { E } from '@agoric/eventual-send'; +import { makeZoeKit } from '../../../src/zoeService/zoe.js'; -export function buildRootObject(_vatPowers) { +export function buildRootObject(vatPowers) { return Far('root', { - buildZoe: vatAdminSvc => makeZoe(vatAdminSvc), + buildZoe: vatAdminSvc => { + const shutdownZoeVat = vatPowers.exitVatWithFailure; + const { zoeService } = makeZoeKit(vatAdminSvc, shutdownZoeVat); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); + return zoe; + }, }); } diff --git a/packages/zoe/test/swingsetTests/zoe-metering/vat-zoe.js b/packages/zoe/test/swingsetTests/zoe-metering/vat-zoe.js index 463e1cff30a..416de8633d5 100644 --- a/packages/zoe/test/swingsetTests/zoe-metering/vat-zoe.js +++ b/packages/zoe/test/swingsetTests/zoe-metering/vat-zoe.js @@ -1,10 +1,19 @@ +// @ts-check + import { Far } from '@agoric/marshal'; // noinspection ES6PreferShortImport -import { makeZoe } from '../../../src/zoeService/zoe.js'; +import { E } from '@agoric/eventual-send'; +import { makeZoeKit } from '../../../src/zoeService/zoe.js'; -export function buildRootObject(_vatPowers) { +export function buildRootObject(vatPowers) { return Far('root', { - buildZoe: vatAdminSvc => makeZoe(vatAdminSvc), + buildZoe: vatAdminSvc => { + const shutdownZoeVat = vatPowers.exitVatWithFailure; + const { zoeService } = makeZoeKit(vatAdminSvc, shutdownZoeVat); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); + return zoe; + }, }); } diff --git a/packages/zoe/test/swingsetTests/zoe/vat-zoe.js b/packages/zoe/test/swingsetTests/zoe/vat-zoe.js index d6b8436bed9..416de8633d5 100644 --- a/packages/zoe/test/swingsetTests/zoe/vat-zoe.js +++ b/packages/zoe/test/swingsetTests/zoe/vat-zoe.js @@ -3,10 +3,17 @@ import { Far } from '@agoric/marshal'; // noinspection ES6PreferShortImport -import { makeZoe } from '../../../src/zoeService/zoe.js'; +import { E } from '@agoric/eventual-send'; +import { makeZoeKit } from '../../../src/zoeService/zoe.js'; -export function buildRootObject(_vatPowers) { +export function buildRootObject(vatPowers) { return Far('root', { - buildZoe: vatAdminSvc => makeZoe(vatAdminSvc), + buildZoe: vatAdminSvc => { + const shutdownZoeVat = vatPowers.exitVatWithFailure; + const { zoeService } = makeZoeKit(vatAdminSvc, shutdownZoeVat); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); + return zoe; + }, }); } diff --git a/packages/zoe/test/unitTests/contractSupport/test-depositTo.js b/packages/zoe/test/unitTests/contractSupport/test-depositTo.js index 1207769b0c2..952197a2bdb 100644 --- a/packages/zoe/test/unitTests/contractSupport/test-depositTo.js +++ b/packages/zoe/test/unitTests/contractSupport/test-depositTo.js @@ -8,7 +8,7 @@ import { E } from '@agoric/eventual-send'; import bundleSource from '@agoric/bundle-source'; import { setup } from '../setupBasicMints.js'; -import { makeZoe } from '../../../src/zoeService/zoe.js'; +import { makeZoeKit } from '../../../src/zoeService/zoe.js'; import { makeFakeVatAdmin } from '../../../tools/fakeVatAdmin.js'; import { depositToSeat } from '../../../src/contractSupport/zoeHelpers.js'; import { makeOffer } from '../makeOffer.js'; @@ -23,12 +23,14 @@ async function setupContract(moolaIssuer, bucksIssuer) { const setJig = jig => { testJig = jig; }; - const zoe = makeZoe(makeFakeVatAdmin(setJig).admin); + const { zoeService } = makeZoeKit(makeFakeVatAdmin(setJig).admin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // pack the contract const bundle = await bundleSource(contractRoot); // install the contract - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Alice creates an instance const issuerKeywordRecord = harden({ diff --git a/packages/zoe/test/unitTests/contractSupport/test-offerTo.js b/packages/zoe/test/unitTests/contractSupport/test-offerTo.js index 3709c3b7933..fbdef48a265 100644 --- a/packages/zoe/test/unitTests/contractSupport/test-offerTo.js +++ b/packages/zoe/test/unitTests/contractSupport/test-offerTo.js @@ -8,7 +8,7 @@ import { E } from '@agoric/eventual-send'; import bundleSource from '@agoric/bundle-source'; import { setup } from '../setupBasicMints.js'; -import { makeZoe } from '../../../src/zoeService/zoe.js'; +import { makeZoeKit } from '../../../src/zoeService/zoe.js'; import { makeFakeVatAdmin } from '../../../tools/fakeVatAdmin.js'; import { offerTo, @@ -27,12 +27,14 @@ const setupContract = async (moolaIssuer, bucksIssuer) => { const setJig = jig => { instanceToZCF.set(jig.instance, jig.zcf); }; - const zoe = makeZoe(makeFakeVatAdmin(setJig).admin); + const { zoeService } = makeZoeKit(makeFakeVatAdmin(setJig).admin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // pack the contract const bundle = await bundleSource(contractRoot); // install the contract - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Create TWO instances of the zcfTesterContract which have // different keywords diff --git a/packages/zoe/test/unitTests/contractSupport/test-withdrawFrom.js b/packages/zoe/test/unitTests/contractSupport/test-withdrawFrom.js index d6a8dcbdde5..15ee170ed73 100644 --- a/packages/zoe/test/unitTests/contractSupport/test-withdrawFrom.js +++ b/packages/zoe/test/unitTests/contractSupport/test-withdrawFrom.js @@ -8,7 +8,7 @@ import { E } from '@agoric/eventual-send'; import bundleSource from '@agoric/bundle-source'; import { setup } from '../setupBasicMints.js'; -import { makeZoe } from '../../../src/zoeService/zoe.js'; +import { makeZoeKit } from '../../../src/zoeService/zoe.js'; import { makeFakeVatAdmin } from '../../../tools/fakeVatAdmin.js'; import { depositToSeat, @@ -27,12 +27,14 @@ async function setupContract(moolaIssuer, bucksIssuer) { const setJig = jig => { testJig = jig; }; - const zoe = makeZoe(makeFakeVatAdmin(setJig).admin); + const { zoeService } = makeZoeKit(makeFakeVatAdmin(setJig).admin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // pack the contract const bundle = await bundleSource(contractRoot); // install the contract - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Alice creates an instance const issuerKeywordRecord = harden({ diff --git a/packages/zoe/test/unitTests/contracts/attestation/test-attestation.js b/packages/zoe/test/unitTests/contracts/attestation/test-attestation.js index a41843ad30a..080e06cdf2f 100644 --- a/packages/zoe/test/unitTests/contracts/attestation/test-attestation.js +++ b/packages/zoe/test/unitTests/contracts/attestation/test-attestation.js @@ -11,7 +11,7 @@ import { Far } from '@agoric/marshal'; import bundleSource from '@agoric/bundle-source'; import { E } from '@agoric/eventual-send'; -import { makeZoe } from '../../../../src/zoeService/zoe.js'; +import { makeZoeKit } from '../../../../src/zoeService/zoe.js'; import fakeVatAdmin from '../../../../tools/fakeVatAdmin.js'; const filename = new URL(import.meta.url).pathname; @@ -22,7 +22,9 @@ const attestationRoot = `${dirname}/../../../../src/contracts/attestation/attest test('attestation contract basic tests', async t => { const bundle = await bundleSource(attestationRoot); - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const installation = await E(zoe).install(bundle); const bldIssuerKit = makeIssuerKit('BLD', AssetKind.NAT, { diff --git a/packages/zoe/test/unitTests/contracts/attestation/test-exampleVotingUsage.js b/packages/zoe/test/unitTests/contracts/attestation/test-exampleVotingUsage.js index ed9e0b02f7f..f17c75b3549 100644 --- a/packages/zoe/test/unitTests/contracts/attestation/test-exampleVotingUsage.js +++ b/packages/zoe/test/unitTests/contracts/attestation/test-exampleVotingUsage.js @@ -10,7 +10,7 @@ import { makeIssuerKit, AssetKind, AmountMath } from '@agoric/ertp'; import bundleSource from '@agoric/bundle-source'; import { E } from '@agoric/eventual-send'; -import { makeZoe } from '../../../../src/zoeService/zoe.js'; +import { makeZoeKit } from '../../../../src/zoeService/zoe.js'; import fakeVatAdmin from '../../../../tools/fakeVatAdmin.js'; import { makeAttestationElem } from '../../../../src/contracts/attestation/expiring/expiringHelpers.js'; import { makeHandle } from '../../../../src/makeHandle.js'; @@ -23,7 +23,9 @@ const exampleVotingUsageRoot = `${dirname}/exampleVotingUsage.js`; test('exampleVotingUsage', async t => { const bundle = await bundleSource(exampleVotingUsageRoot); - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const installation = await E(zoe).install(bundle); const bldIssuerKit = makeIssuerKit('BLD', AssetKind.NAT, { diff --git a/packages/zoe/test/unitTests/contracts/loan/helpers.js b/packages/zoe/test/unitTests/contracts/loan/helpers.js index 72c77d8c3af..8374c3a45aa 100644 --- a/packages/zoe/test/unitTests/contracts/loan/helpers.js +++ b/packages/zoe/test/unitTests/contracts/loan/helpers.js @@ -225,7 +225,7 @@ export const makeAutoswapInstance = async ( ), }); - const seat = await zoe.offer( + const seat = await E(zoe).offer( E(publicFacet).makeAddLiquidityInvitation(), proposal, payment, diff --git a/packages/zoe/test/unitTests/contracts/multipoolAutoswap/test-multipoolAutoswap.js b/packages/zoe/test/unitTests/contracts/multipoolAutoswap/test-multipoolAutoswap.js index a570e25bfee..98c5e78192e 100644 --- a/packages/zoe/test/unitTests/contracts/multipoolAutoswap/test-multipoolAutoswap.js +++ b/packages/zoe/test/unitTests/contracts/multipoolAutoswap/test-multipoolAutoswap.js @@ -10,7 +10,7 @@ import { E } from '@agoric/eventual-send'; import fakeVatAdmin from '../../../../tools/fakeVatAdmin.js'; // noinspection ES6PreferShortImport -import { makeZoe } from '../../../../src/zoeService/zoe.js'; +import { makeZoeKit } from '../../../../src/zoeService/zoe.js'; import { setup } from '../../setupBasicMints.js'; import { makeTrader, @@ -33,8 +33,10 @@ const multipoolAutoswapRoot = `${dirname}/../../../../src/contracts/multipoolAut test('multipoolAutoSwap with valid offers', async t => { const { moolaR, simoleanR, moola, simoleans } = setup(); - const zoe = makeZoe(fakeVatAdmin); - const invitationIssuer = zoe.getInvitationIssuer(); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); + const invitationIssuer = await E(zoe).getInvitationIssuer(); const invitationBrand = await E(invitationIssuer).getBrand(); // Set up central token @@ -56,10 +58,10 @@ test('multipoolAutoSwap with valid offers', async t => { // Pack the contract. const bundle = await bundleSource(multipoolAutoswapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // This timer is only used to build quotes. Let's make it non-zero const fakeTimer = buildManualTimer(console.log, 30); - const { instance, publicFacet } = await zoe.startInstance( + const { instance, publicFacet } = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), { timer: fakeTimer }, @@ -68,7 +70,7 @@ test('multipoolAutoSwap with valid offers', async t => { publicFacet, ).makeAddLiquidityInvitation(); - const aliceInvitationAmount = await invitationIssuer.getAmountOf( + const aliceInvitationAmount = await E(invitationIssuer).getAmountOf( aliceAddLiquidityInvitation, ); t.deepEqual( @@ -108,7 +110,7 @@ test('multipoolAutoSwap with valid offers', async t => { publicFacet, ).getPriceAuthorities(moolaR.brand); - const issuerKeywordRecord = zoe.getIssuers(instance); + const issuerKeywordRecord = await E(zoe).getIssuers(instance); t.deepEqual( issuerKeywordRecord, harden({ @@ -143,7 +145,7 @@ test('multipoolAutoSwap with valid offers', async t => { Central: aliceCentralPayment, }; - const addLiquiditySeat = await zoe.offer( + const addLiquiditySeat = await E(zoe).offer( aliceAddLiquidityInvitation, aliceProposal, alicePayments, @@ -193,8 +195,10 @@ test('multipoolAutoSwap with valid offers', async t => { const { value: [bobInvitationValue], - } = await invitationIssuer.getAmountOf(bobSwapInvitation1); - const bobPublicFacet = await zoe.getPublicFacet(bobInvitationValue.instance); + } = await E(invitationIssuer).getAmountOf(bobSwapInvitation1); + const bobPublicFacet = await E(zoe).getPublicFacet( + bobInvitationValue.instance, + ); t.is( bobInvitationValue.installation, @@ -220,7 +224,7 @@ test('multipoolAutoSwap with valid offers', async t => { const bobMoolaForCentralPayments = harden({ In: bobMoolaPayment }); // Bob swaps - const bobSeat = await zoe.offer( + const bobSeat = await E(zoe).offer( bobSwapInvitation1, bobMoolaForCentralProposal, bobMoolaForCentralPayments, @@ -285,7 +289,7 @@ test('multipoolAutoSwap with valid offers', async t => { In: await E(bobCentralPurse).withdraw(centralTokens(7)), }); - const bobSeat2 = await zoe.offer( + const bobSeat2 = await E(zoe).offer( bobSwapInvitation2, bobCentralForMoolaProposal, centralForMoolaPayments, @@ -350,7 +354,7 @@ test('multipoolAutoSwap with valid offers', async t => { Central: aliceCentralPayment2, }; - const aliceSeat2 = await zoe.offer( + const aliceSeat2 = await E(zoe).offer( aliceSimCentralLiquidityInvitation, aliceSimCentralProposal, aliceSimCentralPayments, @@ -437,7 +441,7 @@ test('multipoolAutoSwap with valid offers', async t => { In: bobSimoleanPayment, }); - const bobSeat3 = await zoe.offer( + const bobSeat3 = await E(zoe).offer( bobThirdInvitation, bobSimsForMoolaProposal, simsForMoolaPayments, @@ -501,7 +505,7 @@ test('multipoolAutoSwap with valid offers', async t => { want: { Secondary: moola(91), Central: centralTokens(56) }, }); - const aliceSeat3 = await zoe.offer( + const aliceSeat3 = await E(zoe).offer( aliceRemoveLiquidityInvitation, aliceRemoveLiquidityProposal, harden({ Liquidity: liquidityPayout }), @@ -546,8 +550,10 @@ test('multipoolAutoSwap with valid offers', async t => { test('multipoolAutoSwap get detailed prices', async t => { const { moolaR, simoleanR, moola, simoleans } = setup(); - const zoe = makeZoe(fakeVatAdmin); - const invitationIssuer = zoe.getInvitationIssuer(); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); + const invitationIssuer = await E(zoe).getInvitationIssuer(); const invitationBrand = await E(invitationIssuer).getBrand(); // Set up central token @@ -565,8 +571,8 @@ test('multipoolAutoSwap get detailed prices', async t => { // Pack the contract. const bundle = await bundleSource(multipoolAutoswapRoot); - const installation = await zoe.install(bundle); - const { instance, publicFacet } = await zoe.startInstance( + const installation = await E(zoe).install(bundle); + const { instance, publicFacet } = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), ); @@ -574,7 +580,7 @@ test('multipoolAutoSwap get detailed prices', async t => { publicFacet, ).makeAddLiquidityInvitation(); - const aliceInvitationAmount = await invitationIssuer.getAmountOf( + const aliceInvitationAmount = await E(invitationIssuer).getAmountOf( aliceAddLiquidityInvitation, ); t.deepEqual( @@ -621,7 +627,7 @@ test('multipoolAutoSwap get detailed prices', async t => { Central: aliceCentralPayment, }; - const addLiquiditySeat = await zoe.offer( + const addLiquiditySeat = await E(zoe).offer( aliceAddLiquidityInvitation, aliceProposal, alicePayments, @@ -667,7 +673,7 @@ test('multipoolAutoSwap get detailed prices', async t => { Central: aliceCentralPayment2, }; - const aliceSeat2 = await zoe.offer( + const aliceSeat2 = await E(zoe).offer( aliceSimCentralLiquidityInvitation, aliceSimCentralProposal, aliceSimCentralPayments, @@ -728,8 +734,10 @@ test('multipoolAutoSwap get detailed prices', async t => { test('multipoolAutoSwap with some invalid offers', async t => { const { moolaR, moola } = setup(); - const zoe = makeZoe(fakeVatAdmin); - const invitationIssuer = zoe.getInvitationIssuer(); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); + const invitationIssuer = await E(zoe).getInvitationIssuer(); // Set up central token const centralR = makeIssuerKit('central'); @@ -743,8 +751,8 @@ test('multipoolAutoSwap with some invalid offers', async t => { // Pack the contract. const bundle = await bundleSource(multipoolAutoswapRoot); - const installation = await zoe.install(bundle); - const { publicFacet } = await zoe.startInstance( + const installation = await E(zoe).install(bundle); + const { publicFacet } = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), ); @@ -755,8 +763,8 @@ test('multipoolAutoSwap with some invalid offers', async t => { const { value: [bobInvitationValue], - } = await invitationIssuer.getAmountOf(bobSwapInvitation1); - const bobPublicFacet = zoe.getPublicFacet(bobInvitationValue.instance); + } = await E(invitationIssuer).getAmountOf(bobSwapInvitation1); + const bobPublicFacet = E(zoe).getPublicFacet(bobInvitationValue.instance); // Bob tries to look up prices, but the pool isn't initiailzed await t.throwsAsync( @@ -773,7 +781,7 @@ test('multipoolAutoSwap with some invalid offers', async t => { const bobMoolaForCentralPayments = harden({ In: bobMoolaPayment }); // Bob swaps - const failedSeat = await zoe.offer( + const failedSeat = await E(zoe).offer( bobSwapInvitation1, bobMoolaForCentralProposal, bobMoolaForCentralPayments, @@ -789,11 +797,13 @@ test('multipoolAutoSwap with some invalid offers', async t => { test('multipoolAutoSwap jig - addLiquidity', async t => { const { moolaR, moola } = setup(); - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Pack the contract. const bundle = await bundleSource(multipoolAutoswapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Set up central token const centralR = makeIssuerKit('central'); @@ -806,7 +816,7 @@ test('multipoolAutoSwap jig - addLiquidity', async t => { const moolaPurse = moolaR.issuer.makeEmptyPurse(); moolaPurse.deposit(moolaR.mint.mintPayment(moola(20000))); - const startRecord = await zoe.startInstance( + const startRecord = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), ); @@ -911,7 +921,7 @@ test('multipoolAutoSwap jig - addLiquidity', async t => { }); const invite = E(publicFacet).makeAddLiquidityInvitation(); - const seat = zoe.offer(invite, proposal, payment); + const seat = E(zoe).offer(invite, proposal, payment); await t.throwsAsync( () => E(seat).getOfferResult(), { message: 'insufficient Secondary deposited' }, @@ -923,11 +933,13 @@ test('multipoolAutoSwap jig - addLiquidity', async t => { test('multipoolAutoSwap jig - check liquidity', async t => { const { moolaR, moola } = setup(); - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Pack the contract. const bundle = await bundleSource(multipoolAutoswapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Set up central token const centralR = makeIssuerKit('central'); @@ -940,7 +952,7 @@ test('multipoolAutoSwap jig - check liquidity', async t => { const moolaPurse = moolaR.issuer.makeEmptyPurse(); moolaPurse.deposit(moolaR.mint.mintPayment(moola(20000))); - const startRecord = await zoe.startInstance( + const startRecord = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), ); @@ -1058,11 +1070,13 @@ test('multipoolAutoSwap jig - check liquidity', async t => { test('multipoolAutoSwap jig - swapOut', async t => { const { moolaR, moola, simoleanR, simoleans } = setup(); - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Pack the contract. const bundle = await bundleSource(multipoolAutoswapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Set up central token const centralR = makeIssuerKit('central'); @@ -1077,7 +1091,7 @@ test('multipoolAutoSwap jig - swapOut', async t => { const simoleanPurse = simoleanR.issuer.makeEmptyPurse(); simoleanPurse.deposit(simoleanR.mint.mintPayment(simoleans(20000))); - const startRecord = await zoe.startInstance( + const startRecord = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), ); @@ -1270,11 +1284,13 @@ test('multipoolAutoSwap jig - swapOut', async t => { test('multipoolAutoSwap jig - swapOut uneven', async t => { const { moolaR, moola, simoleanR, simoleans } = setup(); - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Pack the contract. const bundle = await bundleSource(multipoolAutoswapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Set up central token const centralR = makeIssuerKit('central'); @@ -1289,7 +1305,7 @@ test('multipoolAutoSwap jig - swapOut uneven', async t => { const simoleanPurse = simoleanR.issuer.makeEmptyPurse(); simoleanPurse.deposit(simoleanR.mint.mintPayment(simoleans(20000))); - const startRecord = await zoe.startInstance( + const startRecord = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), ); @@ -1452,11 +1468,13 @@ test('multipoolAutoSwap jig - swapOut uneven', async t => { test('multipoolAutoSwap jig - removeLiquidity', async t => { const { moolaR, moola } = setup(); - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Pack the contract. const bundle = await bundleSource(multipoolAutoswapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Set up central token const centralR = makeIssuerKit('central'); @@ -1469,7 +1487,7 @@ test('multipoolAutoSwap jig - removeLiquidity', async t => { const moolaPurse = moolaR.issuer.makeEmptyPurse(); moolaPurse.deposit(moolaR.mint.mintPayment(moola(20000))); - const startRecord = await zoe.startInstance( + const startRecord = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), ); @@ -1564,11 +1582,13 @@ test('multipoolAutoSwap jig - removeLiquidity', async t => { test('multipoolAutoSwap jig - removeLiquidity ask for too much', async t => { const { moolaR, moola } = setup(); - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Pack the contract. const bundle = await bundleSource(multipoolAutoswapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Set up central token const centralR = makeIssuerKit('central'); @@ -1581,7 +1601,7 @@ test('multipoolAutoSwap jig - removeLiquidity ask for too much', async t => { const moolaPurse = moolaR.issuer.makeEmptyPurse(); moolaPurse.deposit(moolaR.mint.mintPayment(moola(20000))); - const startRecord = await zoe.startInstance( + const startRecord = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), ); @@ -1660,11 +1680,13 @@ test('multipoolAutoSwap jig - removeLiquidity ask for too much', async t => { test('multipoolAutoSwap jig - remove all liquidity', async t => { const { moolaR, moola } = setup(); - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Pack the contract. const bundle = await bundleSource(multipoolAutoswapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Set up central token const centralR = makeIssuerKit('central'); @@ -1677,7 +1699,7 @@ test('multipoolAutoSwap jig - remove all liquidity', async t => { const moolaPurse = moolaR.issuer.makeEmptyPurse(); moolaPurse.deposit(moolaR.mint.mintPayment(moola(20000))); - const startRecord = await zoe.startInstance( + const startRecord = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), ); @@ -1755,11 +1777,13 @@ test('multipoolAutoSwap jig - remove all liquidity', async t => { test('multipoolAutoSwap jig - insufficient', async t => { const { moolaR, moola } = setup(); - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Pack the contract. const bundle = await bundleSource(multipoolAutoswapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Set up central token const centralR = makeIssuerKit('central'); @@ -1772,7 +1796,7 @@ test('multipoolAutoSwap jig - insufficient', async t => { const moolaPurse = moolaR.issuer.makeEmptyPurse(); moolaPurse.deposit(moolaR.mint.mintPayment(moola(20000))); - const startRecord = await zoe.startInstance( + const startRecord = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), ); @@ -1849,15 +1873,17 @@ test('multipoolAutoSwap jig - insufficient', async t => { }); test('multipoolAutoSwap collect empty fees', async t => { - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const centralR = makeIssuerKit('central'); const centralTokens = value => AmountMath.make(value, centralR.brand); const bundle = await bundleSource(multipoolAutoswapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // This timer is only used to build quotes. Let's make it non-zero const fakeTimer = buildManualTimer(console.log, 30); - const { publicFacet, creatorFacet } = await zoe.startInstance( + const { publicFacet, creatorFacet } = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), { timer: fakeTimer }, @@ -1866,7 +1892,7 @@ test('multipoolAutoSwap collect empty fees', async t => { creatorFacet, ).makeCollectFeesInvitation(); - const feeSeat = await zoe.offer(aliceCollectFeesInvitation); + const feeSeat = await E(zoe).offer(aliceCollectFeesInvitation); t.deepEqual(await E(feeSeat).getCurrentAllocation(), {}); await assertAmountsEqual( @@ -1881,8 +1907,10 @@ test('multipoolAutoSwap collect empty fees', async t => { test('multipoolAutoSwap swapout secondary to secondary', async t => { const { moolaR, simoleanR, moola, simoleans } = setup(); - const zoe = makeZoe(fakeVatAdmin); - const invitationIssuer = zoe.getInvitationIssuer(); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); + const invitationIssuer = await E(zoe).getInvitationIssuer(); const invitationBrand = await E(invitationIssuer).getBrand(); // Set up central token @@ -1900,10 +1928,10 @@ test('multipoolAutoSwap swapout secondary to secondary', async t => { // Alice creates an autoswap instance const bundle = await bundleSource(multipoolAutoswapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // This timer is only used to build quotes. Let's make it non-zero const fakeTimer = buildManualTimer(console.log, 30); - const { instance, publicFacet } = await zoe.startInstance( + const { instance, publicFacet } = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), { timer: fakeTimer }, @@ -1912,7 +1940,7 @@ test('multipoolAutoSwap swapout secondary to secondary', async t => { publicFacet, ).makeAddLiquidityInvitation(); - const aliceInvitationAmount = await invitationIssuer.getAmountOf( + const aliceInvitationAmount = await E(invitationIssuer).getAmountOf( aliceAddLiquidityInvitation, ); t.deepEqual( @@ -1951,7 +1979,7 @@ test('multipoolAutoSwap swapout secondary to secondary', async t => { publicFacet, ).getPriceAuthorities(moolaR.brand); - const issuerKeywordRecord = zoe.getIssuers(instance); + const issuerKeywordRecord = await E(zoe).getIssuers(instance); t.deepEqual( issuerKeywordRecord, harden({ @@ -1976,7 +2004,7 @@ test('multipoolAutoSwap swapout secondary to secondary', async t => { Central: aliceCentralPayment, }; - const addLiquiditySeat = await zoe.offer( + const addLiquiditySeat = await E(zoe).offer( aliceAddLiquidityInvitation, aliceProposal, alicePayments, @@ -2017,7 +2045,7 @@ test('multipoolAutoSwap swapout secondary to secondary', async t => { Central: aliceCentralPayment2, }; - const aliceAddLiquiditySeat2 = await zoe.offer( + const aliceAddLiquiditySeat2 = await E(zoe).offer( aliceSimCentralLiquidityInvitation, aliceSimCentralProposal, aliceSimCentralPayments, @@ -2057,7 +2085,7 @@ test('multipoolAutoSwap swapout secondary to secondary', async t => { In: bobSimoleanPayment, }); - const bobSeat = await zoe.offer( + const bobSeat = await E(zoe).offer( bobInvitation, bobSimsForMoolaProposal, simsForMoolaPayments, diff --git a/packages/zoe/test/unitTests/contracts/newSwap/test-newSwap-swap.js b/packages/zoe/test/unitTests/contracts/newSwap/test-newSwap-swap.js index 61515e60cba..71226196560 100644 --- a/packages/zoe/test/unitTests/contracts/newSwap/test-newSwap-swap.js +++ b/packages/zoe/test/unitTests/contracts/newSwap/test-newSwap-swap.js @@ -11,7 +11,7 @@ import { assert, q } from '@agoric/assert'; import fakeVatAdmin from '../../../../tools/fakeVatAdmin.js'; // noinspection ES6PreferShortImport -import { makeZoe } from '../../../../src/zoeService/zoe.js'; +import { makeZoeKit } from '../../../../src/zoeService/zoe.js'; import { setup } from '../../setupBasicMints.js'; import { makeTrader, @@ -37,8 +37,10 @@ const newSwapRoot = `${dirname}/../../../../src/contracts/newSwap/multipoolAutos test('newSwap with valid offers', async t => { const { moolaR, simoleanR, moola, simoleans } = setup(); - const zoe = makeZoe(fakeVatAdmin); - const invitationIssuer = zoe.getInvitationIssuer(); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); + const invitationIssuer = await E(zoe).getInvitationIssuer(); const invitationBrand = await E(invitationIssuer).getBrand(); // Set up central token @@ -59,10 +61,10 @@ test('newSwap with valid offers', async t => { // Pack the contract. const bundle = await bundleSource(newSwapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // This timer is only used to build quotes. Let's make it non-zero const fakeTimer = buildManualTimer(console.log, 30n); - const { instance, publicFacet } = await zoe.startInstance( + const { instance, publicFacet } = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), { timer: fakeTimer, poolFee: 24n, protocolFee: 6n }, @@ -71,7 +73,7 @@ test('newSwap with valid offers', async t => { publicFacet, ).makeAddLiquidityInvitation(); - const aliceInvitationAmount = await invitationIssuer.getAmountOf( + const aliceInvitationAmount = await E(invitationIssuer).getAmountOf( aliceAddLiquidityInvitation, ); t.deepEqual( @@ -110,7 +112,7 @@ test('newSwap with valid offers', async t => { publicFacet, ).getPriceAuthorities(moolaR.brand); - const issuerKeywordRecord = zoe.getIssuers(instance); + const issuerKeywordRecord = await E(zoe).getIssuers(instance); t.deepEqual( issuerKeywordRecord, harden({ @@ -145,7 +147,7 @@ test('newSwap with valid offers', async t => { Central: aliceCentralPayment, }; - const addLiquiditySeat = await zoe.offer( + const addLiquiditySeat = await E(zoe).offer( aliceAddLiquidityInvitation, aliceProposal, alicePayments, @@ -176,10 +178,12 @@ test('newSwap with valid offers', async t => { // Bob creates a swap invitation for himself const bobSwapInvitation1 = await E(publicFacet).makeSwapInInvitation(); - const { value } = await invitationIssuer.getAmountOf(bobSwapInvitation1); + const { value } = await E(invitationIssuer).getAmountOf(bobSwapInvitation1); assert(Array.isArray(value)); const [bobInvitationValue] = value; - const bobPublicFacet = await zoe.getPublicFacet(bobInvitationValue.instance); + const bobPublicFacet = await E(zoe).getPublicFacet( + bobInvitationValue.instance, + ); t.is( bobInvitationValue.installation, @@ -201,7 +205,7 @@ test('newSwap with valid offers', async t => { const bobMoolaForCentralPayments = harden({ In: bobMoolaPayment }); // Bob swaps - const bobSeat = await zoe.offer( + const bobSeat = await E(zoe).offer( bobSwapInvitation1, bobMoolaForCentralProposal, bobMoolaForCentralPayments, @@ -276,7 +280,7 @@ test('newSwap with valid offers', async t => { In: await E(bobCentralPurse).withdraw(centralTokens(700)), }); - const bobSeat2 = await zoe.offer( + const bobSeat2 = await E(zoe).offer( bobSwapInvitation2, bobCentralForMoolaProposal, centralForMoolaPayments, @@ -348,7 +352,7 @@ test('newSwap with valid offers', async t => { Central: aliceCentralPayment2, }; - const aliceSeat2 = await zoe.offer( + const aliceSeat2 = await E(zoe).offer( aliceSimCentralLiquidityInvitation, aliceSimCentralProposal, aliceSimCentralPayments, @@ -390,7 +394,9 @@ test('newSwap with valid offers', async t => { test('newSwap doubleSwap', async t => { const { moolaR, simoleanR, moola, simoleans } = setup(); - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Set up central token const centralR = makeIssuerKit('central'); @@ -409,17 +415,17 @@ test('newSwap doubleSwap', async t => { // Alice creates an autoswap instance const bundle = await bundleSource(newSwapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // This timer is only used to build quotes. Let's make it non-zero const fakeTimer = buildManualTimer(console.log, 30n); - const { - instance, - publicFacet, - creatorFacet, - } = await zoe.startInstance( + const { instance, publicFacet, creatorFacet } = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), - { timer: fakeTimer, poolFee: 24n, protocolFee: 6n }, + { + timer: fakeTimer, + poolFee: 24n, + protocolFee: 6n, + }, ); const aliceAddLiquidityInvitation = E( publicFacet, @@ -441,7 +447,7 @@ test('newSwap doubleSwap', async t => { const simoleanLiquidity = value => AmountMath.make(value, simoleanLiquidityBrand); - const issuerKeywordRecord = zoe.getIssuers(instance); + const issuerKeywordRecord = await E(zoe).getIssuers(instance); t.deepEqual( issuerKeywordRecord, harden({ @@ -476,7 +482,7 @@ test('newSwap doubleSwap', async t => { Central: aliceCentralPayment, }; - const addLiquiditySeat = await zoe.offer( + const addLiquiditySeat = await E(zoe).offer( aliceAddLiquidityInvitation, aliceProposal, alicePayments, @@ -508,7 +514,7 @@ test('newSwap doubleSwap', async t => { Central: aliceCentralPayment2, }; - const aliceSeat2 = await zoe.offer( + const aliceSeat2 = await E(zoe).offer( aliceSimLiquidityInvitation, aliceSimCentralProposal, aliceSimCentralPayments, @@ -538,7 +544,7 @@ test('newSwap doubleSwap', async t => { t.deepEqual(await E(publicFacet).getProtocolPoolBalance(), {}); - const bobSeat1 = await zoe.offer( + const bobSeat1 = await E(zoe).offer( bobInvitation, bobSimsForMoolaProposal, simsForMoolaPayments, @@ -572,7 +578,7 @@ test('newSwap doubleSwap', async t => { In: bobMoolaPayment, }); - const bobSeat2 = await zoe.offer( + const bobSeat2 = await E(zoe).offer( bobInvitation2, bobMoolaForSimsProposal, moolaForSimsPayments, @@ -594,7 +600,7 @@ test('newSwap doubleSwap', async t => { }); const collectFeesInvitation = E(creatorFacet).makeCollectFeesInvitation(); - const collectFeesSeat = await zoe.offer( + const collectFeesSeat = await E(zoe).offer( collectFeesInvitation, undefined, undefined, @@ -611,8 +617,10 @@ test('newSwap doubleSwap', async t => { test('newSwap with some invalid offers', async t => { const { moolaR, moola } = setup(); - const zoe = makeZoe(fakeVatAdmin); - const invitationIssuer = zoe.getInvitationIssuer(); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); + const invitationIssuer = await E(zoe).getInvitationIssuer(); // Set up central token const centralR = makeIssuerKit('central'); @@ -627,8 +635,8 @@ test('newSwap with some invalid offers', async t => { const bundle = await bundleSource(newSwapRoot); const fakeTimer = buildManualTimer(console.log); - const installation = await zoe.install(bundle); - const { publicFacet } = await zoe.startInstance( + const installation = await E(zoe).install(bundle); + const { publicFacet } = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), { timer: fakeTimer, poolFee: 24n, protocolFee: 6n }, @@ -638,10 +646,10 @@ test('newSwap with some invalid offers', async t => { // Bob creates a swap invitation for himself const bobSwapInvitation1 = await E(publicFacet).makeSwapInInvitation(); - const { value } = await invitationIssuer.getAmountOf(bobSwapInvitation1); + const { value } = await E(invitationIssuer).getAmountOf(bobSwapInvitation1); assert(Array.isArray(value)); const [bobInvitationValue] = value; - const bobPublicFacet = zoe.getPublicFacet(bobInvitationValue.instance); + const bobPublicFacet = E(zoe).getPublicFacet(bobInvitationValue.instance); // Bob tries to look up prices, but the pool isn't initiailzed await t.throwsAsync( @@ -658,7 +666,7 @@ test('newSwap with some invalid offers', async t => { const bobMoolaForCentralPayments = harden({ In: bobMoolaPayment }); // Bob swaps - const failedSeat = await zoe.offer( + const failedSeat = await E(zoe).offer( bobSwapInvitation1, bobMoolaForCentralProposal, bobMoolaForCentralPayments, @@ -674,11 +682,13 @@ test('newSwap with some invalid offers', async t => { test('newSwap jig - swapOut uneven', async t => { const { moolaR, moola, simoleanR, simoleans } = setup(); - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Pack the contract. const bundle = await bundleSource(newSwapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Set up central token const centralR = makeIssuerKit('central'); @@ -694,7 +704,7 @@ test('newSwap jig - swapOut uneven', async t => { simoleanPurse.deposit(simoleanR.mint.mintPayment(simoleans(20000000))); const fakeTimer = buildManualTimer(console.log); - const startRecord = await zoe.startInstance( + const startRecord = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), { timer: fakeTimer, poolFee: 24n, protocolFee: 6n }, @@ -889,7 +899,7 @@ test('newSwap jig - swapOut uneven', async t => { mPoolState = updatePoolState(mPoolState, expectedC); const collectFeesInvitation = E(creatorFacet).makeCollectFeesInvitation(); - const collectFeesSeat = await zoe.offer( + const collectFeesSeat = await E(zoe).offer( collectFeesInvitation, undefined, undefined, @@ -911,11 +921,13 @@ test('newSwap jig - swapOut uneven', async t => { test('newSwap jig - breaking scenario', async t => { const { moolaR, moola, simoleanR } = setup(); - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Pack the contract. const bundle = await bundleSource(newSwapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Set up central token const centralR = makeIssuerKit('central'); @@ -931,7 +943,7 @@ test('newSwap jig - breaking scenario', async t => { moolaPurse.deposit(moolaR.mint.mintPayment(moola(2396247730468n + 4145005n))); const fakeTimer = buildManualTimer(console.log); - const startRecord = await zoe.startInstance( + const startRecord = await E(zoe).startInstance( installation, harden({ Central: centralR.issuer }), { timer: fakeTimer, poolFee: 24n, protocolFee: 6n }, @@ -1028,7 +1040,9 @@ test('newSwap jig - breaking scenario', async t => { // This demonstrates that Zoe can reallocate empty amounts. i.e. that // https://github.com/Agoric/agoric-sdk/issues/3033 stays fixed test('zoe allow empty reallocations', async t => { - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Set up central token const { issuer, brand } = makeIssuerKit('central'); @@ -1036,17 +1050,17 @@ test('zoe allow empty reallocations', async t => { // Alice creates an autoswap instance const bundle = await bundleSource(newSwapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // This timer is only used to build quotes. Let's make it non-zero const fakeTimer = buildManualTimer(console.log, 30n); - const { creatorFacet } = await zoe.startInstance( + const { creatorFacet } = await E(zoe).startInstance( installation, harden({ Central: issuer }), { timer: fakeTimer, poolFee: 24n, protocolFee: 6n }, ); const collectFeesInvitation2 = E(creatorFacet).makeCollectFeesInvitation(); - const collectFeesSeat2 = await zoe.offer( + const collectFeesSeat2 = await E(zoe).offer( collectFeesInvitation2, undefined, undefined, diff --git a/packages/zoe/test/unitTests/contracts/newSwap/test-newswap-bug.js b/packages/zoe/test/unitTests/contracts/newSwap/test-newswap-bug.js index 4801fec6934..71f98e147d0 100644 --- a/packages/zoe/test/unitTests/contracts/newSwap/test-newswap-bug.js +++ b/packages/zoe/test/unitTests/contracts/newSwap/test-newswap-bug.js @@ -9,7 +9,7 @@ import { makeIssuerKit, AmountMath, AssetKind } from '@agoric/ertp'; import { E } from '@agoric/eventual-send'; import fakeVatAdmin from '../../../../tools/fakeVatAdmin.js'; -import { makeZoe } from '../../../../src/zoeService/zoe.js'; +import { makeZoeKit } from '../../../../src/zoeService/zoe.js'; import buildManualTimer from '../../../../tools/manualTimer.js'; import { makeRatio, @@ -36,14 +36,16 @@ test('test bug scenario', async t => { AssetKind.NAT, harden({ decimalPlaces: 6 }), ); - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Pack the contract. const bundle = await bundleSource(multipoolAutoswapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); const fakeTimer = buildManualTimer(console.log, 30n); - const { publicFacet } = await zoe.startInstance( + const { publicFacet } = await E(zoe).startInstance( installation, harden({ Central: runKit.issuer }), { @@ -75,7 +77,7 @@ test('test bug scenario', async t => { Central: runKit.mint.mintPayment(runPoolAllocation), }; - const addLiquiditySeat = await zoe.offer( + const addLiquiditySeat = await E(zoe).offer( aliceAddLiquidityInvitation, aliceProposal, alicePayments, @@ -123,14 +125,16 @@ const conductTrade = async (t, reduceWantOutBP = 30n) => { AssetKind.NAT, harden({ decimalPlaces: 6 }), ); - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Pack the contract. const bundle = await bundleSource(multipoolAutoswapRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); const fakeTimer = buildManualTimer(console.log, 30n); - const { publicFacet } = await zoe.startInstance( + const { publicFacet } = await E(zoe).startInstance( installation, harden({ Central: runKit.issuer }), { @@ -162,7 +166,7 @@ const conductTrade = async (t, reduceWantOutBP = 30n) => { Central: runKit.mint.mintPayment(runPoolAllocation), }; - const addLiquiditySeat = await zoe.offer( + const addLiquiditySeat = await E(zoe).offer( aliceAddLiquidityInvitation, aliceProposal, alicePayments, diff --git a/packages/zoe/test/unitTests/contracts/test-atomicSwap.js b/packages/zoe/test/unitTests/contracts/test-atomicSwap.js index 76ab96be9d1..712c6e69217 100644 --- a/packages/zoe/test/unitTests/contracts/test-atomicSwap.js +++ b/packages/zoe/test/unitTests/contracts/test-atomicSwap.js @@ -37,7 +37,7 @@ test('zoe - atomicSwap', async t => { Asset: moolaKit.issuer, Price: simoleanKit.issuer, }); - const adminP = zoe.startInstance(installation, issuerKeywordRecord); + const adminP = E(zoe).startInstance(installation, issuerKeywordRecord); return adminP; }, offer: async firstInvitation => { @@ -91,7 +91,7 @@ test('zoe - atomicSwap', async t => { // Bob is able to use the trusted invitationIssuer from Zoe to // transform an untrusted invitation that Alice also has access to, to // an - const invitation = await invitationIssuer.claim(untrustedInvitation); + const invitation = await E(invitationIssuer).claim(untrustedInvitation); const invitationValue = await E(zoe).getInvitationDetails(invitation); t.is( invitationValue.installation, @@ -116,7 +116,7 @@ test('zoe - atomicSwap', async t => { }); const payments = { Price: simoleanPayment }; - const seat = await zoe.offer(invitation, proposal, payments); + const seat = await E(zoe).offer(invitation, proposal, payments); t.is( await E(seat).getOfferResult(), @@ -199,7 +199,7 @@ test('zoe - non-fungible atomicSwap', async t => { Asset: ccIssuer, Price: rpgIssuer, }); - const adminP = zoe.startInstance(installation, issuerKeywordRecord); + const adminP = E(zoe).startInstance(installation, issuerKeywordRecord); return adminP; }, offer: async (firstInvitation, calico37Amount, vorpalAmount) => { @@ -210,7 +210,7 @@ test('zoe - non-fungible atomicSwap', async t => { }); const payments = { Asset: aliceCcPayment }; - const seat = await zoe.offer(firstInvitation, proposal, payments); + const seat = await E(zoe).offer(firstInvitation, proposal, payments); seat .getPayout('Asset') @@ -253,7 +253,7 @@ test('zoe - non-fungible atomicSwap', async t => { // Bob is able to use the trusted invitationIssuer from Zoe to // transform an untrusted invitation that Alice also has access to, to // an - const invitation = await invitationIssuer.claim(untrustedInvitation); + const invitation = await E(invitationIssuer).claim(untrustedInvitation); const invitationValue = await E(zoe).getInvitationDetails(invitation); t.is( @@ -279,7 +279,7 @@ test('zoe - non-fungible atomicSwap', async t => { }); const payments = { Price: rpgPayment }; - const seat = await zoe.offer(invitation, proposal, payments); + const seat = await E(zoe).offer(invitation, proposal, payments); t.is( await E(seat).getOfferResult(), @@ -340,12 +340,12 @@ test('zoe - non-fungible atomicSwap', async t => { test('zoe - atomicSwap like-for-like', async t => { t.plan(13); const { moolaIssuer, moolaMint, moola, zoe } = setup(); - const invitationIssuer = zoe.getInvitationIssuer(); + const invitationIssuer = await E(zoe).getInvitationIssuer(); // pack the contract const bundle = await bundleSource(atomicSwapRoot); // install the contract - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Setup Alice const aliceMoolaPayment = moolaMint.mintPayment(moola(3)); @@ -360,7 +360,7 @@ test('zoe - atomicSwap like-for-like', async t => { Asset: moolaIssuer, Price: moolaIssuer, }); - const { creatorInvitation: aliceInvitation } = await zoe.startInstance( + const { creatorInvitation: aliceInvitation } = await E(zoe).startInstance( installation, issuerKeywordRecord, ); @@ -374,7 +374,7 @@ test('zoe - atomicSwap like-for-like', async t => { const alicePayments = { Asset: aliceMoolaPayment }; // 3: Alice makes the first offer in the swap. - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( aliceInvitation, aliceProposal, alicePayments, @@ -385,12 +385,14 @@ test('zoe - atomicSwap like-for-like', async t => { // counter-party. const bobInvitationP = E(aliceSeat).getOfferResult(); - const bobExclusiveInvitation = await invitationIssuer.claim(bobInvitationP); + const bobExclusiveInvitation = await E(invitationIssuer).claim( + bobInvitationP, + ); const bobInvitationValue = await E(zoe).getInvitationDetails( bobExclusiveInvitation, ); - const bobIssuers = zoe.getIssuers(bobInvitationValue.instance); + const bobIssuers = await E(zoe).getIssuers(bobInvitationValue.instance); t.is(bobInvitationValue.installation, installation, 'bobInstallationId'); t.deepEqual(bobIssuers, { Asset: moolaIssuer, Price: moolaIssuer }); @@ -405,7 +407,7 @@ test('zoe - atomicSwap like-for-like', async t => { const bobPayments = { Price: bobMoolaPayment }; // 5: Bob makes an offer - const bobSeat = await zoe.offer( + const bobSeat = await E(zoe).offer( bobExclusiveInvitation, bobProposal, bobPayments, diff --git a/packages/zoe/test/unitTests/contracts/test-automaticRefund.js b/packages/zoe/test/unitTests/contracts/test-automaticRefund.js index 0ebee954e27..5b0ff10e19a 100644 --- a/packages/zoe/test/unitTests/contracts/test-automaticRefund.js +++ b/packages/zoe/test/unitTests/contracts/test-automaticRefund.js @@ -20,14 +20,14 @@ test('zoe - simplest automaticRefund', async t => { const { moolaR, moola, zoe } = setup(); // Pack the contract. const bundle = await bundleSource(automaticRefundRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Setup Alice const aliceMoolaPayment = moolaR.mint.mintPayment(moola(3)); // 1: Alice creates an automatic refund instance const issuerKeywordRecord = harden({ Contribution: moolaR.issuer }); - const { creatorInvitation } = await zoe.startInstance( + const { creatorInvitation } = await E(zoe).startInstance( installation, issuerKeywordRecord, ); @@ -38,7 +38,11 @@ test('zoe - simplest automaticRefund', async t => { }); const alicePayments = { Contribution: aliceMoolaPayment }; - const seat = await zoe.offer(creatorInvitation, aliceProposal, alicePayments); + const seat = await E(zoe).offer( + creatorInvitation, + aliceProposal, + alicePayments, + ); const aliceMoolaPayout = await seat.getPayout('Contribution'); @@ -95,7 +99,7 @@ test('zoe with automaticRefund', async t => { t.plan(11); // Setup zoe and mints const { moolaR, simoleanR, moola, simoleans, zoe } = setup(); - const invitationIssuer = zoe.getInvitationIssuer(); + const invitationIssuer = await E(zoe).getInvitationIssuer(); // Setup Alice const aliceMoolaPayment = moolaR.mint.mintPayment(moola(3)); @@ -111,15 +115,14 @@ test('zoe with automaticRefund', async t => { const bundle = await bundleSource(automaticRefundRoot); // 1: Alice creates an automatic refund instance - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); const issuerKeywordRecord = harden({ Contribution1: moolaR.issuer, Contribution2: simoleanR.issuer, }); - const { - creatorInvitation: aliceInvitation, - publicFacet, - } = await zoe.startInstance(installation, issuerKeywordRecord); + const { creatorInvitation: aliceInvitation, publicFacet } = await E( + zoe, + ).startInstance(installation, issuerKeywordRecord); // 2: Alice escrows with zoe const aliceProposal = harden({ @@ -134,7 +137,7 @@ test('zoe with automaticRefund', async t => { // In the 'automaticRefund' trivial contract, you just get your // payments back when you make an offer. The offerResult is simply // the string 'The offer was accepted' - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( aliceInvitation, aliceProposal, alicePayments, @@ -148,7 +151,7 @@ test('zoe with automaticRefund', async t => { // will do a claim on the invitation with the Zoe invitation issuer and // will check that the installation and terms match what he // expects - const exclusBobInvitation = await invitationIssuer.claim(bobInvitation); + const exclusBobInvitation = await E(invitationIssuer).claim(bobInvitation); const { value: [bobInvitationValue], @@ -173,7 +176,7 @@ test('zoe with automaticRefund', async t => { const bobPayments = { Contribution2: bobSimoleanPayment }; // Bob also gets a seat back - const bobSeat = await zoe.offer( + const bobSeat = await E(zoe).offer( exclusBobInvitation, bobProposal, bobPayments, @@ -241,7 +244,7 @@ test('multiple instances of automaticRefund for the same Zoe', async t => { // Pack the contract. const bundle = await bundleSource(automaticRefundRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); const issuerKeywordRecord = harden({ ContributionA: moolaR.issuer, ContributionB: simoleanR.issuer, @@ -249,36 +252,36 @@ test('multiple instances of automaticRefund for the same Zoe', async t => { const { creatorInvitation: aliceInvitation1, publicFacet: publicFacet1, - } = await zoe.startInstance(installation, issuerKeywordRecord); + } = await E(zoe).startInstance(installation, issuerKeywordRecord); const { creatorInvitation: aliceInvitation2, publicFacet: publicFacet2, - } = await zoe.startInstance(installation, issuerKeywordRecord); + } = await E(zoe).startInstance(installation, issuerKeywordRecord); const { creatorInvitation: aliceInvitation3, publicFacet: publicFacet3, - } = await zoe.startInstance(installation, issuerKeywordRecord); + } = await E(zoe).startInstance(installation, issuerKeywordRecord); const aliceProposal = harden({ give: { ContributionA: moola(10) }, want: { ContributionB: simoleans(7) }, }); - const seat1 = await zoe.offer( + const seat1 = await E(zoe).offer( aliceInvitation1, aliceProposal, harden({ ContributionA: aliceMoolaPayments[0] }), ); - const seat2 = await zoe.offer( + const seat2 = await E(zoe).offer( aliceInvitation2, aliceProposal, harden({ ContributionA: aliceMoolaPayments[1] }), ); - const seat3 = await zoe.offer( + const seat3 = await E(zoe).offer( aliceInvitation3, aliceProposal, harden({ ContributionA: aliceMoolaPayments[2] }), @@ -320,12 +323,12 @@ test('zoe - alice tries to complete after completion has already occurred', asyn // Pack the contract. const bundle = await bundleSource(automaticRefundRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); const issuerKeywordRecord = harden({ ContributionA: moolaR.issuer, ContributionB: simoleanR.issuer, }); - const { creatorInvitation } = await zoe.startInstance( + const { creatorInvitation } = await E(zoe).startInstance( installation, issuerKeywordRecord, ); @@ -336,7 +339,7 @@ test('zoe - alice tries to complete after completion has already occurred', asyn }); const alicePayments = { ContributionA: aliceMoolaPayment }; - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( creatorInvitation, aliceProposal, alicePayments, @@ -377,14 +380,14 @@ test('zoe - automaticRefund non-fungible', async t => { // Pack the contract. const bundle = await bundleSource(automaticRefundRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Setup Alice const aliceCcPayment = ccMint.mintPayment(cryptoCats(harden(['tigger']))); // 1: Alice creates an automatic refund instance const issuerKeywordRecord = harden({ Contribution: ccIssuer }); - const { creatorInvitation } = await zoe.startInstance( + const { creatorInvitation } = await E(zoe).startInstance( installation, issuerKeywordRecord, ); @@ -395,7 +398,11 @@ test('zoe - automaticRefund non-fungible', async t => { }); const alicePayments = { Contribution: aliceCcPayment }; - const seat = await zoe.offer(creatorInvitation, aliceProposal, alicePayments); + const seat = await E(zoe).offer( + creatorInvitation, + aliceProposal, + alicePayments, + ); const aliceCcPayout = await seat.getPayout('Contribution'); diff --git a/packages/zoe/test/unitTests/contracts/test-autoswap.js b/packages/zoe/test/unitTests/contracts/test-autoswap.js index c7f74aa3852..39345c04688 100644 --- a/packages/zoe/test/unitTests/contracts/test-autoswap.js +++ b/packages/zoe/test/unitTests/contracts/test-autoswap.js @@ -35,7 +35,7 @@ test('autoSwap API interactions, no jig', async t => { simoleans, zoe, } = setup(); - const invitationIssuer = zoe.getInvitationIssuer(); + const invitationIssuer = await E(zoe).getInvitationIssuer(); const installation = await installationPFromSource(zoe, autoswap); // Setup Alice @@ -52,7 +52,7 @@ test('autoSwap API interactions, no jig', async t => { Central: moolaIssuer, Secondary: simoleanIssuer, }); - const startRecord = await zoe.startInstance( + const startRecord = await E(zoe).startInstance( installation, issuerKeywordRecord, ); @@ -74,7 +74,7 @@ test('autoSwap API interactions, no jig', async t => { Secondary: aliceSimoleanPayment, }; const aliceInvitation = await publicFacet.makeAddLiquidityInvitation(); - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( aliceInvitation, aliceProposal, alicePayments, @@ -97,7 +97,7 @@ test('autoSwap API interactions, no jig', async t => { const bobInvitation = await E(publicFacet).makeSwapInvitation(); // Bob claims it - const bobExclInvitation = await invitationIssuer.claim(bobInvitation); + const bobExclInvitation = await E(invitationIssuer).claim(bobInvitation); const bobInstance = await E(zoe).getInstance(bobExclInvitation); const bobInstallation = await E(zoe).getInstallation(bobExclInvitation); t.is(bobInstallation, installation, `installation`); @@ -117,7 +117,7 @@ test('autoSwap API interactions, no jig', async t => { }); const bobMoolaForSimPayments = harden({ In: bobMoolaPayment }); - const bobSeat = await zoe.offer( + const bobSeat = await E(zoe).offer( bobExclInvitation, bobMoolaForSimProposal, bobMoolaForSimPayments, @@ -160,7 +160,7 @@ test('autoSwap API interactions, no jig', async t => { }); const simsForMoolaPayments = harden({ In: bobSimoleanPayment }); - const bobSecondSeat = await zoe.offer( + const bobSecondSeat = await E(zoe).offer( bobSecondInvitation, bobSimsForMoolaProposal, simsForMoolaPayments, @@ -195,7 +195,7 @@ test('autoSwap API interactions, no jig', async t => { want: { Central: moola(0n), Secondary: simoleans(0) }, }); - const aliceRmLiqSeat = await zoe.offer( + const aliceRmLiqSeat = await E(zoe).offer( aliceSecondInvitation, aliceRemoveLiquidityProposal, harden({ Liquidity: liquidityPayout }), @@ -235,7 +235,7 @@ test('autoSwap - thorough jig test init, add, swap', async t => { Central: moolaIssuer, Secondary: simoleanIssuer, }); - const startRecord = await zoe.startInstance( + const startRecord = await E(zoe).startInstance( installation, issuerKeywordRecord, ); @@ -353,7 +353,7 @@ test('autoSwap jig - add liquidity in exact ratio', async t => { Central: moolaIssuer, Secondary: simoleanIssuer, }); - const startRecord = await zoe.startInstance( + const startRecord = await E(zoe).startInstance( installation, issuerKeywordRecord, ); @@ -446,7 +446,7 @@ test('autoSwap - trade attempt before init, no jig', async t => { Central: moolaIssuer, Secondary: simoleanIssuer, }); - const startRecord = await zoe.startInstance( + const startRecord = await E(zoe).startInstance( installation, issuerKeywordRecord, ); @@ -463,7 +463,7 @@ test('autoSwap - trade attempt before init, no jig', async t => { }); const payment = harden({ In: moolaPurse.withdraw(inAmount) }); - const seat = await zoe.offer( + const seat = await E(zoe).offer( E(publicFacet).makeSwapInInvitation(), proposal, payment, @@ -501,7 +501,7 @@ test('autoSwap jig - swap varying amounts', async t => { Central: moolaIssuer, Secondary: simoleanIssuer, }); - const startRecord = await zoe.startInstance( + const startRecord = await E(zoe).startInstance( installation, issuerKeywordRecord, ); @@ -649,7 +649,7 @@ test('autoSwap price quote for zero', async t => { Central: moolaIssuer, Secondary: simoleanIssuer, }); - const startRecord = await zoe.startInstance( + const startRecord = await E(zoe).startInstance( installation, issuerKeywordRecord, ); @@ -671,7 +671,7 @@ test('autoSwap price quote for zero', async t => { Secondary: aliceSimoleanPayment, }; const aliceInvitation = await publicFacet.makeAddLiquidityInvitation(); - await zoe.offer(aliceInvitation, aliceProposal, alicePayments); + await E(zoe).offer(aliceInvitation, aliceProposal, alicePayments); const simoleanAmounts = await E(publicFacet).getInputPrice( moola(0), diff --git a/packages/zoe/test/unitTests/contracts/test-barter.js b/packages/zoe/test/unitTests/contracts/test-barter.js index 99b97384133..0a71aba480c 100644 --- a/packages/zoe/test/unitTests/contracts/test-barter.js +++ b/packages/zoe/test/unitTests/contracts/test-barter.js @@ -27,7 +27,7 @@ test('barter with valid offers', async t => { simoleans, zoe, } = setup(); - const invitationIssuer = zoe.getInvitationIssuer(); + const invitationIssuer = await E(zoe).getInvitationIssuer(); const installation = await installationPFromSource(zoe, barter); // Setup Alice @@ -38,7 +38,7 @@ test('barter with valid offers', async t => { // 1: Simon creates a barter instance and spreads the instance far and // wide with instructions on how to use it. - const { instance } = await zoe.startInstance(installation, { + const { instance } = await E(zoe).startInstance(installation, { Asset: moolaIssuer, Price: simoleanIssuer, }); @@ -57,7 +57,7 @@ test('barter with valid offers', async t => { }); const alicePayments = { In: aliceMoolaPayment }; // 3: Alice adds her sell order to the exchange - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( aliceInvitation, aliceSellOrderProposal, alicePayments, @@ -72,7 +72,7 @@ test('barter with valid offers', async t => { const bobInstallation = await E(zoe).getInstallation(bobInvitation); // 4: Bob decides to join. - const bobExclusiveInvitation = await invitationIssuer.claim(bobInvitation); + const bobExclusiveInvitation = await E(invitationIssuer).claim(bobInvitation); t.is(bobInstallation, installation); t.is(bobInstance, instance); @@ -87,7 +87,7 @@ test('barter with valid offers', async t => { const bobPayments = { In: bobSimoleanPayment }; // 5: Bob escrows with zoe - const bobSeat = await zoe.offer( + const bobSeat = await E(zoe).offer( bobExclusiveInvitation, bobBuyOrderProposal, bobPayments, diff --git a/packages/zoe/test/unitTests/contracts/test-brokenContract.js b/packages/zoe/test/unitTests/contracts/test-brokenContract.js index 13976daf5b7..21859726b6a 100644 --- a/packages/zoe/test/unitTests/contracts/test-brokenContract.js +++ b/packages/zoe/test/unitTests/contracts/test-brokenContract.js @@ -6,9 +6,10 @@ import path from 'path'; // eslint-disable-next-line import/no-extraneous-dependencies import bundleSource from '@agoric/bundle-source'; +import { E } from '@agoric/eventual-send'; // noinspection ES6PreferShortImport -import { makeZoe } from '../../../src/zoeService/zoe.js'; +import { makeZoeKit } from '../../../src/zoeService/zoe.js'; import { setup } from '../setupBasicMints.js'; import fakeVatAdmin from '../../../tools/fakeVatAdmin.js'; @@ -21,17 +22,19 @@ test('zoe - brokenAutomaticRefund', async t => { t.plan(1); // Setup zoe and mints const { moolaR } = setup(); - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Pack the contract. const bundle = await bundleSource(automaticRefundRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); const issuerKeywordRecord = harden({ Contribution: moolaR.issuer }); // Alice tries to create an instance, but the contract is badly // written. await t.throwsAsync( - () => zoe.startInstance(installation, issuerKeywordRecord), + () => E(zoe).startInstance(installation, issuerKeywordRecord), { message: 'The contract did not correctly return a creatorInvitation' }, 'startInstance should have thrown', ); diff --git a/packages/zoe/test/unitTests/contracts/test-callSpread.js b/packages/zoe/test/unitTests/contracts/test-callSpread.js index f3958985d56..93f43b913fd 100644 --- a/packages/zoe/test/unitTests/contracts/test-callSpread.js +++ b/packages/zoe/test/unitTests/contracts/test-callSpread.js @@ -86,7 +86,7 @@ test('fundedCallSpread below Strike1', async t => { brands.get('moola'), ), }); - const { creatorInvitation } = await zoe.startInstance( + const { creatorInvitation } = await E(zoe).startInstance( installation, issuerKeywordRecord, terms, @@ -101,7 +101,7 @@ test('fundedCallSpread below Strike1', async t => { give: { Collateral: bucks(300) }, }); const alicePayments = { Collateral: aliceBucksPayment }; - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( creatorInvitation, aliceProposal, alicePayments, @@ -111,11 +111,11 @@ test('fundedCallSpread below Strike1', async t => { ShortOption: carolShortOption, } = await aliceSeat.getPayouts(); - const bobOptionSeat = await zoe.offer(bobLongOption); + const bobOptionSeat = await E(zoe).offer(bobLongOption); const bobPayout = bobOptionSeat.getPayout('Collateral'); const bobDeposit = assertPayoutDeposit(t, bobPayout, bobBucksPurse, bucks(0)); - const carolOptionSeat = await zoe.offer(carolShortOption); + const carolOptionSeat = await E(zoe).offer(carolShortOption); const carolPayout = carolOptionSeat.getPayout('Collateral'); const carolDeposit = assertPayoutDeposit( t, @@ -177,7 +177,7 @@ test('fundedCallSpread above Strike2', async t => { Strike: moolaIssuer, }); - const { creatorInvitation } = await zoe.startInstance( + const { creatorInvitation } = await E(zoe).startInstance( installation, issuerKeywordRecord, terms, @@ -192,7 +192,7 @@ test('fundedCallSpread above Strike2', async t => { give: { Collateral: bucks(300) }, }); const alicePayments = { Collateral: aliceBucksPayment }; - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( creatorInvitation, aliceProposal, alicePayments, @@ -202,7 +202,7 @@ test('fundedCallSpread above Strike2', async t => { ShortOption: carolShortOption, } = await aliceSeat.getPayouts(); - const bobOptionSeat = await zoe.offer(bobLongOption); + const bobOptionSeat = await E(zoe).offer(bobLongOption); const bobPayout = bobOptionSeat.getPayout('Collateral'); const bobDeposit = assertPayoutDeposit( t, @@ -211,7 +211,7 @@ test('fundedCallSpread above Strike2', async t => { bucks(300), ); - const carolOptionSeat = await zoe.offer(carolShortOption); + const carolOptionSeat = await E(zoe).offer(carolShortOption); const carolPayout = carolOptionSeat.getPayout('Collateral'); const carolDeposit = assertPayoutDeposit( t, @@ -272,7 +272,7 @@ test('fundedCallSpread, mid-strike', async t => { Strike: moolaIssuer, }); - const { creatorInvitation } = await zoe.startInstance( + const { creatorInvitation } = await E(zoe).startInstance( installation, issuerKeywordRecord, terms, @@ -287,7 +287,7 @@ test('fundedCallSpread, mid-strike', async t => { give: { Collateral: bucks(300) }, }); const alicePayments = { Collateral: aliceBucksPayment }; - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( creatorInvitation, aliceProposal, alicePayments, @@ -297,7 +297,7 @@ test('fundedCallSpread, mid-strike', async t => { ShortOption: carolShortOption, } = await aliceSeat.getPayouts(); - const bobOptionSeat = await zoe.offer(bobLongOption); + const bobOptionSeat = await E(zoe).offer(bobLongOption); const bobPayout = bobOptionSeat.getPayout('Collateral'); const bobDeposit = assertPayoutDeposit( t, @@ -306,7 +306,7 @@ test('fundedCallSpread, mid-strike', async t => { bucks(225), ); - const carolOptionSeat = await zoe.offer(carolShortOption); + const carolOptionSeat = await E(zoe).offer(carolShortOption); const carolPayout = carolOptionSeat.getPayout('Collateral'); const carolDeposit = assertPayoutDeposit( t, @@ -367,7 +367,7 @@ test('fundedCallSpread, late exercise', async t => { Collateral: bucksIssuer, Strike: moolaIssuer, }); - const { creatorInvitation } = await zoe.startInstance( + const { creatorInvitation } = await E(zoe).startInstance( installation, issuerKeywordRecord, terms, @@ -384,7 +384,7 @@ test('fundedCallSpread, late exercise', async t => { give: { Collateral: bucks(300) }, }); const alicePayments = { Collateral: aliceBucksPayment }; - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( creatorInvitation, aliceProposal, alicePayments, @@ -394,7 +394,7 @@ test('fundedCallSpread, late exercise', async t => { ShortOption: carolShortOption, } = await aliceSeat.getPayouts(); - const bobOptionSeat = await zoe.offer(bobLongOption); + const bobOptionSeat = await E(zoe).offer(bobLongOption); const bobPayout = bobOptionSeat.getPayout('Collateral'); const bobDeposit = assertPayoutDeposit( t, @@ -407,7 +407,7 @@ test('fundedCallSpread, late exercise', async t => { await E(manualTimer).tick(); await E(manualTimer).tick(); - const carolOptionSeat = await zoe.offer(carolShortOption); + const carolOptionSeat = await E(zoe).offer(carolShortOption); const carolPayout = await carolOptionSeat.getPayout('Collateral'); const carolDepositAmount = await E(carolBucksPurse).deposit(carolPayout); await t.deepEqual( @@ -466,7 +466,7 @@ test('fundedCallSpread, sell options', async t => { Collateral: bucksIssuer, Strike: moolaIssuer, }); - const { creatorInvitation } = await zoe.startInstance( + const { creatorInvitation } = await E(zoe).startInstance( installation, issuerKeywordRecord, terms, @@ -481,7 +481,7 @@ test('fundedCallSpread, sell options', async t => { give: { Collateral: bucks(300) }, }); const alicePayments = { Collateral: aliceBucksPayment }; - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( creatorInvitation, aliceProposal, alicePayments, @@ -495,7 +495,7 @@ test('fundedCallSpread, sell options', async t => { zoe, simpleExchange, ); - const { publicFacet: exchangePublic } = await zoe.startInstance( + const { publicFacet: exchangePublic } = await E(zoe).startInstance( exchangeInstallation, { Asset: invitationIssuer, @@ -509,9 +509,13 @@ test('fundedCallSpread, sell options', async t => { give: { Asset: longOptionAmount }, want: { Price: bucks(200) }, }); - const aliceSellLongSeat = await zoe.offer(aliceLongInvitation, proposalLong, { - Asset: longOption, - }); + const aliceSellLongSeat = await E(zoe).offer( + aliceLongInvitation, + proposalLong, + { + Asset: longOption, + }, + ); const aliceLong = assertPayoutDeposit( t, aliceSellLongSeat.getPayout('Price'), @@ -525,7 +529,7 @@ test('fundedCallSpread, sell options', async t => { give: { Asset: shortOptionAmount }, want: { Price: bucks(100) }, }); - const aliceSellShortSeat = await zoe.offer( + const aliceSellShortSeat = await E(zoe).offer( aliceShortInvitation, proposalShort, { Asset: shortOption }, @@ -543,7 +547,7 @@ test('fundedCallSpread, sell options', async t => { give: { Price: bucks(200) }, want: { Asset: longOptionAmount }, }); - const bobBuySeat = await zoe.offer(bobLongInvitation, bobProposal, { + const bobBuySeat = await E(zoe).offer(bobLongInvitation, bobProposal, { Price: bobBucksPayment, }); const longInvitationPayout = await bobBuySeat.getPayout('Asset'); @@ -553,7 +557,7 @@ test('fundedCallSpread, sell options', async t => { longInvitationPayout, longOptionAmount, ); - const bobOptionSeat = await zoe.offer(longInvitationPayout); + const bobOptionSeat = await E(zoe).offer(longInvitationPayout); const bobPayout = bobOptionSeat.getPayout('Collateral'); const bobDeposit = assertPayoutDeposit( t, @@ -568,7 +572,7 @@ test('fundedCallSpread, sell options', async t => { give: { Price: bucks(100) }, want: { Asset: shortOptionAmount }, }); - const carolBuySeat = await zoe.offer(carolShortInvitation, carolProposal, { + const carolBuySeat = await E(zoe).offer(carolShortInvitation, carolProposal, { Price: carolBucksPayment, }); const ShortInvitationPayout = await carolBuySeat.getPayout('Asset'); @@ -578,7 +582,7 @@ test('fundedCallSpread, sell options', async t => { ShortInvitationPayout, shortOptionAmount, ); - const carolOptionSeat = await zoe.offer(ShortInvitationPayout); + const carolOptionSeat = await E(zoe).offer(ShortInvitationPayout); const carolPayout = carolOptionSeat.getPayout('Collateral'); const carolDeposit = assertPayoutDeposit( t, @@ -641,7 +645,7 @@ test('pricedCallSpread, mid-strike', async t => { Collateral: bucksIssuer, Strike: moolaIssuer, }); - const { creatorFacet } = await zoe.startInstance( + const { creatorFacet } = await E(zoe).startInstance( installation, issuerKeywordRecord, terms, @@ -662,12 +666,12 @@ test('pricedCallSpread, mid-strike', async t => { want: { Option: longOption }, give: { Collateral: bucks(longOptionValue.collateral) }, }); - const bobFundingSeat = await zoe.offer(await longInvitation, bobProposal, { + const bobFundingSeat = await E(zoe).offer(await longInvitation, bobProposal, { Collateral: bobBucksPayment, }); // bob gets an option, and exercises it for the payout const bobOption = await bobFundingSeat.getPayout('Option'); - const bobOptionSeat = await zoe.offer(bobOption); + const bobOptionSeat = await E(zoe).offer(bobOption); const bobPayout = bobOptionSeat.getPayout('Collateral'); const bobDeposit = assertPayoutDeposit( @@ -686,7 +690,7 @@ test('pricedCallSpread, mid-strike', async t => { want: { Option: shortOption }, give: { Collateral: bucks(shortOptionValue.collateral) }, }); - const carolFundingSeat = await zoe.offer( + const carolFundingSeat = await E(zoe).offer( await shortInvitation, carolProposal, { @@ -695,7 +699,7 @@ test('pricedCallSpread, mid-strike', async t => { ); // carol gets an option, and exercises it for the payout const carolOption = await carolFundingSeat.getPayout('Option'); - const carolOptionSeat = await zoe.offer(carolOption); + const carolOptionSeat = await E(zoe).offer(carolOption); const carolPayout = carolOptionSeat.getPayout('Collateral'); const carolDeposit = assertPayoutDeposit( diff --git a/packages/zoe/test/unitTests/contracts/test-coveredCall.js b/packages/zoe/test/unitTests/contracts/test-coveredCall.js index 9d902f63bb2..e8596b302ac 100644 --- a/packages/zoe/test/unitTests/contracts/test-coveredCall.js +++ b/packages/zoe/test/unitTests/contracts/test-coveredCall.js @@ -51,7 +51,7 @@ test('zoe - coveredCall', async t => { Simoleans: simoleanKit.issuer, Bucks: bucksKit.issuer, }); - const adminP = zoe.startInstance(installation, issuerKeywordRecord); + const adminP = E(zoe).startInstance(installation, issuerKeywordRecord); return adminP; }, offer: async createCallOptionInvitation => { @@ -228,7 +228,7 @@ test(`zoe - coveredCall - alice's deadline expires, cancelling alice and bob`, a const { moolaR, simoleanR, moola, simoleans, zoe } = setup(); // Pack the contract. const bundle = await bundleSource(coveredCallRoot); - const coveredCallInstallation = await zoe.install(bundle); + const coveredCallInstallation = await E(zoe).install(bundle); const timer = buildManualTimer(console.log); // Setup Alice @@ -246,7 +246,7 @@ test(`zoe - coveredCall - alice's deadline expires, cancelling alice and bob`, a UnderlyingAsset: moolaR.issuer, StrikePrice: simoleanR.issuer, }); - const { creatorInvitation: aliceInvitation } = await zoe.startInstance( + const { creatorInvitation: aliceInvitation } = await E(zoe).startInstance( coveredCallInstallation, issuerKeywordRecord, ); @@ -264,7 +264,7 @@ test(`zoe - coveredCall - alice's deadline expires, cancelling alice and bob`, a }); const alicePayments = { UnderlyingAsset: aliceMoolaPayment }; // Alice makes an option - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( aliceInvitation, aliceProposal, alicePayments, @@ -280,8 +280,8 @@ test(`zoe - coveredCall - alice's deadline expires, cancelling alice and bob`, a // contract instance that he expects as well as that Alice has // already escrowed. - const invitationIssuer = zoe.getInvitationIssuer(); - const bobExclOption = await invitationIssuer.claim(optionP); + const invitationIssuer = await E(zoe).getInvitationIssuer(); + const bobExclOption = await E(invitationIssuer).claim(optionP); const optionValue = await E(zoe).getInvitationDetails(bobExclOption); t.is(optionValue.installation, coveredCallInstallation); t.is(optionValue.description, 'exerciseOption'); @@ -298,7 +298,7 @@ test(`zoe - coveredCall - alice's deadline expires, cancelling alice and bob`, a }); // Bob escrows - const bobSeat = await zoe.offer(bobExclOption, bobProposal, bobPayments); + const bobSeat = await E(zoe).offer(bobExclOption, bobProposal, bobPayments); // TODO is this await safe? await t.throwsAsync( @@ -350,10 +350,10 @@ test('zoe - coveredCall with swap for invitation', async t => { // Pack the contract. const coveredCallBundle = await bundleSource(coveredCallRoot); - const coveredCallInstallation = await zoe.install(coveredCallBundle); + const coveredCallInstallation = await E(zoe).install(coveredCallBundle); const atomicSwapBundle = await bundleSource(atomicSwapRoot); - const swapInstallationId = await zoe.install(atomicSwapBundle); + const swapInstallationId = await E(zoe).install(atomicSwapBundle); // Setup Alice // Alice starts with 3 moola @@ -380,7 +380,7 @@ test('zoe - coveredCall with swap for invitation', async t => { UnderlyingAsset: moolaR.issuer, StrikePrice: simoleanR.issuer, }); - const { creatorInvitation: aliceInvitation } = await zoe.startInstance( + const { creatorInvitation: aliceInvitation } = await E(zoe).startInstance( coveredCallInstallation, issuerKeywordRecord, ); @@ -404,7 +404,7 @@ test('zoe - coveredCall with swap for invitation', async t => { }); const alicePayments = { UnderlyingAsset: aliceMoolaPayment }; // Alice makes an option. - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( aliceInvitation, aliceProposal, alicePayments, @@ -420,10 +420,10 @@ test('zoe - coveredCall with swap for invitation', async t => { // party in the covered call: Did the covered call use the // expected covered call installation (code)? Does it use the issuers // that he expects (moola and simoleans)? - const invitationIssuer = zoe.getInvitationIssuer(); + const invitationIssuer = await E(zoe).getInvitationIssuer(); const invitationBrand = await E(invitationIssuer).getBrand(); - const bobExclOption = await invitationIssuer.claim(optionP); - const optionAmount = await invitationIssuer.getAmountOf(bobExclOption); + const bobExclOption = await E(invitationIssuer).claim(optionP); + const optionAmount = await E(invitationIssuer).getAmountOf(bobExclOption); const optionDesc = optionAmount.value[0]; t.is(optionDesc.installation, coveredCallInstallation); t.is(optionDesc.description, 'exerciseOption'); @@ -438,7 +438,7 @@ test('zoe - coveredCall with swap for invitation', async t => { Asset: invitationIssuer, Price: bucksR.issuer, }); - const { creatorInvitation: bobSwapInvitation } = await zoe.startInstance( + const { creatorInvitation: bobSwapInvitation } = await E(zoe).startInstance( swapInstallationId, swapIssuerKeywordRecord, ); @@ -446,7 +446,7 @@ test('zoe - coveredCall with swap for invitation', async t => { // Bob wants to swap an invitation with the same amount as his // current invitation from Alice. He wants 1 buck in return. const bobProposalSwap = harden({ - give: { Asset: await invitationIssuer.getAmountOf(bobExclOption) }, + give: { Asset: await E(invitationIssuer).getAmountOf(bobExclOption) }, want: { Price: bucks(1) }, }); @@ -454,7 +454,7 @@ test('zoe - coveredCall with swap for invitation', async t => { // Bob escrows his option in the swap // Bob makes an offer to the swap with his "higher order" invitation - const bobSwapSeat = await zoe.offer( + const bobSwapSeat = await E(zoe).offer( bobSwapInvitation, bobProposalSwap, bobPayments, @@ -467,9 +467,9 @@ test('zoe - coveredCall with swap for invitation', async t => { const { value: [{ instance: swapInstance, installation: daveSwapInstallId }], - } = await invitationIssuer.getAmountOf(daveSwapInvitationP); + } = await E(invitationIssuer).getAmountOf(daveSwapInvitationP); - const daveSwapIssuers = zoe.getIssuers(swapInstance); + const daveSwapIssuers = await E(zoe).getIssuers(swapInstance); // Dave is looking to buy the option to trade his 7 simoleans for // 3 moola, and is willing to pay 1 buck for the option. He @@ -502,7 +502,7 @@ test('zoe - coveredCall with swap for invitation', async t => { }); const daveSwapPayments = harden({ Price: daveBucksPayment }); - const daveSwapSeat = await zoe.offer( + const daveSwapSeat = await E(zoe).offer( daveSwapInvitationP, daveSwapProposal, daveSwapPayments, @@ -526,7 +526,7 @@ test('zoe - coveredCall with swap for invitation', async t => { const daveCoveredCallPayments = harden({ StrikePrice: daveSimoleanPayment, }); - const daveCoveredCallSeat = await zoe.offer( + const daveCoveredCallSeat = await E(zoe).offer( daveOption, daveCoveredCallProposal, daveCoveredCallPayments, @@ -561,7 +561,7 @@ test('zoe - coveredCall with swap for invitation', async t => { ); t.deepEqual( - await invitationIssuer.getAmountOf(bobInvitationPayout), + await E(invitationIssuer).getAmountOf(bobInvitationPayout), AmountMath.makeEmpty(invitationBrand, AssetKind.SET), ); t.deepEqual(await bucksR.issuer.getAmountOf(bobBucksPayout), bucks(1)); @@ -603,7 +603,7 @@ test('zoe - coveredCall with coveredCall for invitation', async t => { // Pack the contract. const bundle = await bundleSource(coveredCallRoot); - const coveredCallInstallation = await zoe.install(bundle); + const coveredCallInstallation = await E(zoe).install(bundle); // Setup Alice // Alice starts with 3 moola @@ -630,9 +630,9 @@ test('zoe - coveredCall with coveredCall for invitation', async t => { UnderlyingAsset: moolaR.issuer, StrikePrice: simoleanR.issuer, }); - const { - creatorInvitation: aliceCoveredCallInvitation, - } = await zoe.startInstance(coveredCallInstallation, issuerKeywordRecord); + const { creatorInvitation: aliceCoveredCallInvitation } = await E( + zoe, + ).startInstance(coveredCallInstallation, issuerKeywordRecord); // Alice escrows with Zoe. She specifies her proposal, // which include what she wants and gives as well as the exit @@ -654,7 +654,7 @@ test('zoe - coveredCall with coveredCall for invitation', async t => { const alicePayments = { UnderlyingAsset: aliceMoolaPayment }; // Alice makes a call option, which is an invitation to join the // covered call contract - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( aliceCoveredCallInvitation, aliceProposal, alicePayments, @@ -670,8 +670,8 @@ test('zoe - coveredCall with coveredCall for invitation', async t => { // party in the covered call: Did the covered call use the // expected covered call installation (code)? Does it use the issuers // that he expects (moola and simoleans)? - const invitationIssuer = zoe.getInvitationIssuer(); - const bobExclOption = await invitationIssuer.claim(optionP); + const invitationIssuer = await E(zoe).getInvitationIssuer(); + const bobExclOption = await E(invitationIssuer).claim(optionP); const optionValue = await E(zoe).getInvitationDetails(bobExclOption); t.is(optionValue.installation, coveredCallInstallation); t.is(optionValue.description, 'exerciseOption'); @@ -686,15 +686,15 @@ test('zoe - coveredCall with coveredCall for invitation', async t => { UnderlyingAsset: invitationIssuer, StrikePrice: bucksR.issuer, }); - const { - creatorInvitation: bobInvitationForSecondCoveredCall, - } = await zoe.startInstance(coveredCallInstallation, issuerKeywordRecord2); + const { creatorInvitation: bobInvitationForSecondCoveredCall } = await E( + zoe, + ).startInstance(coveredCallInstallation, issuerKeywordRecord2); // Bob wants to swap an invitation with the same amount as his // current invitation from Alice. He wants 1 buck in return. const bobProposalSecondCoveredCall = harden({ give: { - UnderlyingAsset: await invitationIssuer.getAmountOf(bobExclOption), + UnderlyingAsset: await E(invitationIssuer).getAmountOf(bobExclOption), }, want: { StrikePrice: bucks(1) }, exit: { @@ -709,7 +709,7 @@ test('zoe - coveredCall with coveredCall for invitation', async t => { // Bob escrows his invitation // Bob makes an offer to the swap with his "higher order" option - const bobSeat = await zoe.offer( + const bobSeat = await E(zoe).offer( bobInvitationForSecondCoveredCall, bobProposalSecondCoveredCall, bobPayments, @@ -722,7 +722,7 @@ test('zoe - coveredCall with coveredCall for invitation', async t => { // Dave is looking to buy the option to trade his 7 simoleans for // 3 moola, and is willing to pay 1 buck for the option. He // checks that this invitation matches what he wants - const daveExclOption = await invitationIssuer.claim(invitationForDaveP); + const daveExclOption = await E(invitationIssuer).claim(invitationForDaveP); const daveOptionValue = await E(zoe).getInvitationDetails(daveExclOption); t.is(daveOptionValue.installation, coveredCallInstallation); t.is(daveOptionValue.description, 'exerciseOption'); @@ -759,7 +759,7 @@ test('zoe - coveredCall with coveredCall for invitation', async t => { // Dave escrows his 1 buck with Zoe and forms his proposal const daveSecondCoveredCallPayments = { StrikePrice: daveBucksPayment }; - const daveSecondCoveredCallSeat = await zoe.offer( + const daveSecondCoveredCallSeat = await E(zoe).offer( daveExclOption, daveProposalCoveredCall, daveSecondCoveredCallPayments, @@ -787,7 +787,7 @@ test('zoe - coveredCall with coveredCall for invitation', async t => { const daveFirstCoveredCallPayments = harden({ StrikePrice: daveSimoleanPayment, }); - const daveFirstCoveredCallSeat = await zoe.offer( + const daveFirstCoveredCallSeat = await E(zoe).offer( firstCoveredCallInvitation, daveFirstCoveredCallProposal, daveFirstCoveredCallPayments, @@ -829,7 +829,7 @@ test('zoe - coveredCall with coveredCall for invitation', async t => { const invitationBrand = await E(invitationIssuer).getBrand(); t.deepEqual( - await invitationIssuer.getAmountOf(bobInvitationPayout), + await E(invitationIssuer).getAmountOf(bobInvitationPayout), AmountMath.makeEmpty(invitationBrand, AssetKind.SET), ); t.deepEqual(await bucksR.issuer.getAmountOf(bobBucksPayout), bucks(1)); @@ -875,7 +875,7 @@ test('zoe - coveredCall non-fungible', async t => { // install the contract. const bundle = await bundleSource(coveredCallRoot); - const coveredCallInstallation = await zoe.install(bundle); + const coveredCallInstallation = await E(zoe).install(bundle); const timer = buildManualTimer(console.log); // Setup Alice @@ -902,7 +902,7 @@ test('zoe - coveredCall non-fungible', async t => { StrikePrice: rpgIssuer, }); // separate issuerKeywordRecord from contract-specific terms - const { creatorInvitation: aliceInvitation } = await zoe.startInstance( + const { creatorInvitation: aliceInvitation } = await E(zoe).startInstance( coveredCallInstallation, issuerKeywordRecord, ); @@ -915,7 +915,7 @@ test('zoe - coveredCall non-fungible', async t => { }); const alicePayments = { UnderlyingAsset: aliceCcPayment }; // Alice creates a call option - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( aliceInvitation, aliceProposal, alicePayments, @@ -929,8 +929,8 @@ test('zoe - coveredCall non-fungible', async t => { // contract instance that he expects as well as that Alice has // already escrowed. - const invitationIssuer = zoe.getInvitationIssuer(); - const bobExclOption = await invitationIssuer.claim(optionP); + const invitationIssuer = await E(zoe).getInvitationIssuer(); + const bobExclOption = await E(invitationIssuer).claim(optionP); const optionValue = await E(zoe).getInvitationDetails(bobExclOption); t.is(optionValue.installation, coveredCallInstallation); t.is(optionValue.description, 'exerciseOption'); @@ -957,7 +957,7 @@ test('zoe - coveredCall non-fungible', async t => { // Bob redeems his invitation and escrows with Zoe // Bob exercises the option - const bobSeat = await zoe.offer(bobExclOption, bobProposal, bobPayments); + const bobSeat = await E(zoe).offer(bobExclOption, bobProposal, bobPayments); t.is( await E(bobSeat).getOfferResult(), diff --git a/packages/zoe/test/unitTests/contracts/test-escrowToVote.js b/packages/zoe/test/unitTests/contracts/test-escrowToVote.js index 0ae311e8db2..f3cd4f5bd64 100644 --- a/packages/zoe/test/unitTests/contracts/test-escrowToVote.js +++ b/packages/zoe/test/unitTests/contracts/test-escrowToVote.js @@ -8,7 +8,7 @@ import path from 'path'; import bundleSource from '@agoric/bundle-source'; import { E } from '@agoric/eventual-send'; -import { makeZoe } from '../../../src/zoeService/zoe.js'; +import { makeZoeKit } from '../../../src/zoeService/zoe.js'; import { setup } from '../setupBasicMints.js'; import fakeVatAdmin from '../../../tools/fakeVatAdmin.js'; @@ -20,12 +20,14 @@ const contractRoot = `${dirname}/escrowToVote.js`; test('zoe - escrowToVote', async t => { t.plan(14); const { moolaIssuer, moolaMint, moola } = setup(); - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // pack the contract const bundle = await bundleSource(contractRoot); // install the contract - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Alice creates an instance and acts as the Secretary const issuerKeywordRecord = harden({ diff --git a/packages/zoe/test/unitTests/contracts/test-mintPayments.js b/packages/zoe/test/unitTests/contracts/test-mintPayments.js index 7af5644f341..c6ec8d7dcde 100644 --- a/packages/zoe/test/unitTests/contracts/test-mintPayments.js +++ b/packages/zoe/test/unitTests/contracts/test-mintPayments.js @@ -10,7 +10,7 @@ import { makeIssuerKit, AmountMath } from '@agoric/ertp'; import fakeVatAdmin from '../../../tools/fakeVatAdmin.js'; // noinspection ES6PreferShortImport -import { makeZoe } from '../../../src/zoeService/zoe.js'; +import { makeZoeKit } from '../../../src/zoeService/zoe.js'; const filename = new URL(import.meta.url).pathname; const dirname = path.dirname(filename); @@ -19,7 +19,9 @@ const mintPaymentsRoot = `${dirname}/../../../src/contracts/mintPayments.js`; test('zoe - mint payments', async t => { t.plan(2); - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const makeAlice = () => { return { @@ -31,7 +33,7 @@ test('zoe - mint payments', async t => { return installationP; }, startInstance: async installation => { - const adminP = zoe.startInstance(installation); + const adminP = E(zoe).startInstance(installation); return adminP; }, }; @@ -87,7 +89,9 @@ test('zoe - mint payments', async t => { test('zoe - mint payments with unrelated give and want', async t => { t.plan(3); - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const moolaKit = makeIssuerKit('moola'); const simoleanKit = makeIssuerKit('simolean'); diff --git a/packages/zoe/test/unitTests/contracts/test-oracle.js b/packages/zoe/test/unitTests/contracts/test-oracle.js index d5bea8267f0..6ed753da7d7 100644 --- a/packages/zoe/test/unitTests/contracts/test-oracle.js +++ b/packages/zoe/test/unitTests/contracts/test-oracle.js @@ -12,7 +12,7 @@ import { assert, details as X } from '@agoric/assert'; import { E } from '@agoric/eventual-send'; import { makeFakeVatAdmin } from '../../../tools/fakeVatAdmin.js'; -import { makeZoe } from '../../../src/zoeService/zoe.js'; +import { makeZoeKit } from '../../../src/zoeService/zoe.js'; import '../../../exported.js'; import '../../../src/contracts/exported.js'; @@ -37,7 +37,9 @@ test.before( /** @param {ExecutionContext} ot */ async ot => { // Outside of tests, we should use the long-lived Zoe on the // testnet. In this test, we must create a new Zoe. - const zoe = makeZoe(makeFakeVatAdmin().admin); + const { zoeService } = makeZoeKit(makeFakeVatAdmin().admin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Pack the contract. const contractBundle = await bundleSource(contractPath); diff --git a/packages/zoe/test/unitTests/contracts/test-otcDesk.js b/packages/zoe/test/unitTests/contracts/test-otcDesk.js index 74737c3cc0a..67fa5e4c1d8 100644 --- a/packages/zoe/test/unitTests/contracts/test-otcDesk.js +++ b/packages/zoe/test/unitTests/contracts/test-otcDesk.js @@ -133,7 +133,7 @@ const makeBob = ( return Far('Bob', { offerOk: async untrustedInvitation => { const invitationIssuer = await E(zoe).getInvitationIssuer(); - const invitation = await invitationIssuer.claim(untrustedInvitation); + const invitation = await E(invitationIssuer).claim(untrustedInvitation); const invitationValue = await E(zoe).getInvitationDetails(invitation); t.is( invitationValue.installation, @@ -160,7 +160,7 @@ const makeBob = ( const simoleanPayment1 = simoleanPurse.withdraw(simoleans(4)); const payments = { Whatever1: simoleanPayment1 }; - const seat = await zoe.offer(invitation, proposal, payments); + const seat = await E(zoe).offer(invitation, proposal, payments); t.is( await E(seat).getOfferResult(), @@ -184,7 +184,7 @@ const makeBob = ( }, offerExpired: async untrustedInvitation => { const invitationIssuer = await E(zoe).getInvitationIssuer(); - const invitation = await invitationIssuer.claim(untrustedInvitation); + const invitation = await E(invitationIssuer).claim(untrustedInvitation); const invitationValue = await E(zoe).getInvitationDetails(invitation); t.is( invitationValue.installation, @@ -211,7 +211,11 @@ const makeBob = ( const simoleanPayment1 = simoleanPurse.withdraw(simoleans(4)); const payments = { Whatever1: simoleanPayment1 }; - const offerExpiredSeat = await zoe.offer(invitation, proposal, payments); + const offerExpiredSeat = await E(zoe).offer( + invitation, + proposal, + payments, + ); await t.throwsAsync(() => E(offerExpiredSeat).getOfferResult(), { message: 'The covered call option is expired.', @@ -234,7 +238,7 @@ const makeBob = ( }, offerWantTooMuch: async untrustedInvitation => { const invitationIssuer = await E(zoe).getInvitationIssuer(); - const invitation = await invitationIssuer.claim(untrustedInvitation); + const invitation = await E(invitationIssuer).claim(untrustedInvitation); const invitationValue = await E(zoe).getInvitationDetails(invitation); t.is( invitationValue.installation, @@ -265,7 +269,7 @@ const makeBob = ( Whatever2: moola35Payment, }; - const seat = await zoe.offer(invitation, proposal, payments); + const seat = await E(zoe).offer(invitation, proposal, payments); await t.throwsAsync(() => E(seat).getOfferResult(), { message: @@ -296,7 +300,7 @@ const makeBob = ( }, offerNotCovered: async untrustedInvitation => { const invitationIssuer = await E(zoe).getInvitationIssuer(); - const invitation = await invitationIssuer.claim(untrustedInvitation); + const invitation = await E(invitationIssuer).claim(untrustedInvitation); const invitationValue = await E(zoe).getInvitationDetails(invitation); t.is( invitationValue.installation, @@ -331,7 +335,7 @@ const makeBob = ( Whatever2: moola35Payment, }; - const seat = await zoe.offer(invitation, proposal, payments); + const seat = await E(zoe).offer(invitation, proposal, payments); await t.throwsAsync(() => E(seat).getOfferResult(), { message: diff --git a/packages/zoe/test/unitTests/contracts/test-priceAggregator.js b/packages/zoe/test/unitTests/contracts/test-priceAggregator.js index ef75a69ef3b..7eeef2e2ae6 100644 --- a/packages/zoe/test/unitTests/contracts/test-priceAggregator.js +++ b/packages/zoe/test/unitTests/contracts/test-priceAggregator.js @@ -13,7 +13,7 @@ import { makePromiseKit } from '@agoric/promise-kit'; import { assert } from '@agoric/assert'; import { makeFakeVatAdmin } from '../../../tools/fakeVatAdmin.js'; -import { makeZoe } from '../../../src/zoeService/zoe.js'; +import { makeZoeKit } from '../../../src/zoeService/zoe.js'; import buildManualTimer from '../../../tools/manualTimer.js'; import '../../../exported.js'; @@ -48,7 +48,9 @@ test.before( /** @param {ExecutionContext} ot */ async ot => { // Outside of tests, we should use the long-lived Zoe on the // testnet. In this test, we must create a new Zoe. - const zoe = makeZoe(makeFakeVatAdmin().admin); + const { zoeService } = makeZoeKit(makeFakeVatAdmin().admin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Pack the contracts. const oracleBundle = await bundleSource(oraclePath); diff --git a/packages/zoe/test/unitTests/contracts/test-secondPriceAuction.js b/packages/zoe/test/unitTests/contracts/test-secondPriceAuction.js index 3d7da0ccac7..5fa63986f0b 100644 --- a/packages/zoe/test/unitTests/contracts/test-secondPriceAuction.js +++ b/packages/zoe/test/unitTests/contracts/test-secondPriceAuction.js @@ -9,7 +9,7 @@ import { E } from '@agoric/eventual-send'; import { Far } from '@agoric/marshal'; // noinspection ES6PreferShortImport -import { makeZoe } from '../../../src/zoeService/zoe.js'; +import { makeZoeKit } from '../../../src/zoeService/zoe.js'; import buildManualTimer from '../../../tools/manualTimer.js'; import { setup } from '../setupBasicMints.js'; import { setupMixed } from '../setupMixedMints.js'; @@ -41,7 +41,7 @@ test('zoe - secondPriceAuction w/ 3 bids', async t => { Ask: simoleanKit.issuer, }); const terms = { timeAuthority: timer, closesAfter: 1n }; - const adminP = zoe.startInstance( + const adminP = E(zoe).startInstance( installation, issuerKeywordRecord, terms, @@ -98,7 +98,7 @@ test('zoe - secondPriceAuction w/ 3 bids', async t => { // Bob is able to use the trusted invitationIssuer from Zoe to // transform an untrusted invitation that Alice also has access to, to // an - const invitation = await invitationIssuer.claim(untrustedInvitation); + const invitation = await E(invitationIssuer).claim(untrustedInvitation); const invitationValue = await E(zoe).getInvitationDetails(invitation); @@ -130,7 +130,7 @@ test('zoe - secondPriceAuction w/ 3 bids', async t => { }); const payments = { Bid: simoleanPayment }; - const seat = await zoe.offer(invitation, proposal, payments); + const seat = await E(zoe).offer(invitation, proposal, payments); t.is( await E(seat).getOfferResult(), @@ -166,7 +166,7 @@ test('zoe - secondPriceAuction w/ 3 bids', async t => { return Far('losing bidder', { offer: async untrustedInvitation => { const invitationIssuer = await E(zoe).getInvitationIssuer(); - const invitation = await invitationIssuer.claim(untrustedInvitation); + const invitation = await E(invitationIssuer).claim(untrustedInvitation); const proposal = harden({ give: { Bid: bidAmount }, @@ -174,7 +174,7 @@ test('zoe - secondPriceAuction w/ 3 bids', async t => { }); const payments = { Bid: simoleanPayment }; - const seat = await zoe.offer(invitation, proposal, payments); + const seat = await E(zoe).offer(invitation, proposal, payments); t.is( await E(seat).getOfferResult(), @@ -245,7 +245,9 @@ test('zoe - secondPriceAuction w/ 3 bids', async t => { test('zoe - secondPriceAuction - alice tries to exit', async t => { t.plan(12); const { moolaR, simoleanR, moola, simoleans } = setup(); - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // Setup Alice const aliceMoolaPayment = moolaR.mint.mintPayment(moola(1)); @@ -265,14 +267,14 @@ test('zoe - secondPriceAuction - alice tries to exit', async t => { // Pack the contract. const bundle = await bundleSource(secondPriceAuctionRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); const issuerKeywordRecord = harden({ Asset: moolaR.issuer, Ask: simoleanR.issuer, }); const timer = buildManualTimer(console.log); const terms = harden({ timeAuthority: timer, closesAfter: 1n }); - const { creatorInvitation: aliceInvitation } = await zoe.startInstance( + const { creatorInvitation: aliceInvitation } = await E(zoe).startInstance( installation, issuerKeywordRecord, terms, @@ -286,7 +288,7 @@ test('zoe - secondPriceAuction - alice tries to exit', async t => { }); const alicePayments = harden({ Asset: aliceMoolaPayment }); // Alice initializes the auction - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( aliceInvitation, aliceProposal, alicePayments, @@ -312,7 +314,7 @@ test('zoe - secondPriceAuction - alice tries to exit', async t => { // Bob escrows with zoe // Bob bids - const bobSeat = await zoe.offer(bobInvitation, bobProposal, bobPayments); + const bobSeat = await E(zoe).offer(bobInvitation, bobProposal, bobPayments); t.is( await E(bobSeat).getOfferResult(), @@ -333,7 +335,7 @@ test('zoe - secondPriceAuction - alice tries to exit', async t => { const carolPayments = harden({ Bid: carolSimoleanPayment }); // Carol bids - const carolSeat = await zoe.offer( + const carolSeat = await E(zoe).offer( carolInvitation, carolProposal, carolPayments, @@ -403,7 +405,7 @@ test('zoe - secondPriceAuction non-fungible asset', async t => { moola, zoe, } = setupMixed(); - const invitationIssuer = zoe.getInvitationIssuer(); + const invitationIssuer = await E(zoe).getInvitationIssuer(); // Setup Alice const aliceCcPayment = ccMint.mintPayment(cryptoCats(harden(['Felix']))); @@ -430,14 +432,14 @@ test('zoe - secondPriceAuction non-fungible asset', async t => { // Pack the contract. const bundle = await bundleSource(secondPriceAuctionRoot); - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); const issuerKeywordRecord = harden({ Asset: ccIssuer, Ask: moolaIssuer, }); const timer = buildManualTimer(console.log); const terms = harden({ timeAuthority: timer, closesAfter: 1n }); - const { creatorInvitation: aliceInvitation } = await zoe.startInstance( + const { creatorInvitation: aliceInvitation } = await E(zoe).startInstance( installation, issuerKeywordRecord, terms, @@ -451,7 +453,7 @@ test('zoe - secondPriceAuction non-fungible asset', async t => { }); const alicePayments = { Asset: aliceCcPayment }; // Alice initializes the auction - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( aliceInvitation, aliceProposal, alicePayments, @@ -463,12 +465,12 @@ test('zoe - secondPriceAuction non-fungible asset', async t => { // Alice spreads the invitations far and wide and Bob decides he // wants to participate in the auction. - const bobExclusiveInvitation = await invitationIssuer.claim(bobInvitation); + const bobExclusiveInvitation = await E(invitationIssuer).claim(bobInvitation); const bobInvitationValue = await E(zoe).getInvitationDetails( bobExclusiveInvitation, ); - const bobIssuers = zoe.getIssuers(bobInvitationValue.instance); + const bobIssuers = await E(zoe).getIssuers(bobInvitationValue.instance); t.is(bobInvitationValue.installation, installation, 'bobInstallationId'); t.deepEqual(bobIssuers, { Asset: ccIssuer, Ask: moolaIssuer }, 'bobIssuers'); @@ -487,7 +489,7 @@ test('zoe - secondPriceAuction non-fungible asset', async t => { // Bob escrows with zoe // Bob bids - const bobSeat = await zoe.offer( + const bobSeat = await E(zoe).offer( bobExclusiveInvitation, bobProposal, bobPayments, @@ -501,14 +503,14 @@ test('zoe - secondPriceAuction non-fungible asset', async t => { // Carol decides to bid for the one cc - const carolExclusiveInvitation = await invitationIssuer.claim( + const carolExclusiveInvitation = await E(invitationIssuer).claim( carolInvitation, ); const carolInvitationValue = await E(zoe).getInvitationDetails( carolExclusiveInvitation, ); - const carolIssuers = zoe.getIssuers(carolInvitationValue.instance); + const carolIssuers = await E(zoe).getIssuers(carolInvitationValue.instance); t.is(carolInvitationValue.installation, installation, 'carolInstallationId'); t.deepEqual( @@ -531,7 +533,7 @@ test('zoe - secondPriceAuction non-fungible asset', async t => { // Carol escrows with zoe // Carol bids - const carolSeat = await zoe.offer( + const carolSeat = await E(zoe).offer( carolExclusiveInvitation, carolProposal, carolPayments, @@ -544,12 +546,14 @@ test('zoe - secondPriceAuction non-fungible asset', async t => { ); // Dave decides to bid for the one moola - const daveExclusiveInvitation = await invitationIssuer.claim(daveInvitation); + const daveExclusiveInvitation = await E(invitationIssuer).claim( + daveInvitation, + ); const daveInvitationValue = await E(zoe).getInvitationDetails( daveExclusiveInvitation, ); - const daveIssuers = zoe.getIssuers(daveInvitationValue.instance); + const daveIssuers = await E(zoe).getIssuers(daveInvitationValue.instance); t.is(daveInvitationValue.installation, installation, 'daveInstallation'); t.deepEqual( @@ -572,7 +576,7 @@ test('zoe - secondPriceAuction non-fungible asset', async t => { // Dave escrows with zoe // Dave bids - const daveSeat = await zoe.offer( + const daveSeat = await E(zoe).offer( daveExclusiveInvitation, daveProposal, davePayments, diff --git a/packages/zoe/test/unitTests/contracts/test-sellTickets.js b/packages/zoe/test/unitTests/contracts/test-sellTickets.js index 864058ef1e8..42342869084 100644 --- a/packages/zoe/test/unitTests/contracts/test-sellTickets.js +++ b/packages/zoe/test/unitTests/contracts/test-sellTickets.js @@ -12,7 +12,7 @@ import { E } from '@agoric/eventual-send'; import fakeVatAdmin from '../../../tools/fakeVatAdmin.js'; // noinspection ES6PreferShortImport -import { makeZoe } from '../../../src/zoeService/zoe.js'; +import { makeZoeKit } from '../../../src/zoeService/zoe.js'; import { defaultAcceptanceMsg } from '../../../src/contractSupport/index.js'; const filename = new URL(import.meta.url).pathname; @@ -23,7 +23,9 @@ const sellItemsRoot = `${dirname}/../../../src/contracts/sellItems.js`; test(`mint and sell tickets for multiple shows`, async t => { // Setup initial conditions - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const mintAndSellNFTBundle = await bundleSource(mintAndSellNFTRoot); const mintAndSellNFTInstallation = await E(zoe).install(mintAndSellNFTBundle); @@ -147,7 +149,9 @@ test(`mint and sell opera tickets`, async t => { const moola = value => AmountMath.make(value, moolaBrand); - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const mintAndSellNFTBundle = await bundleSource(mintAndSellNFTRoot); const mintAndSellNFTInstallation = await E(zoe).install(mintAndSellNFTBundle); @@ -314,7 +318,7 @@ test(`mint and sell opera tickets`, async t => { const jokerPaymentForTicket = jokerPurse.withdraw(pricePerItem); - const seat = await zoe.offer( + const seat = await E(zoe).offer( invitation, jokerProposal, harden({ @@ -386,7 +390,7 @@ test(`mint and sell opera tickets`, async t => { insufficientAmount, ); - const seat = await zoe.offer( + const seat = await E(zoe).offer( invitation, jokerProposal, harden({ @@ -541,7 +545,9 @@ test(`mint and sell opera tickets`, async t => { // test('Testing publicFacet.getAvailableItemsNotifier()', async t => { // Setup initial conditions - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const mintAndSellNFTBundle = await bundleSource(mintAndSellNFTRoot); const mintAndSellNFTInstallation = await E(zoe).install(mintAndSellNFTBundle); diff --git a/packages/zoe/test/unitTests/contracts/test-simpleExchange.js b/packages/zoe/test/unitTests/contracts/test-simpleExchange.js index 3d045012c85..532a5798cf5 100644 --- a/packages/zoe/test/unitTests/contracts/test-simpleExchange.js +++ b/packages/zoe/test/unitTests/contracts/test-simpleExchange.js @@ -31,7 +31,7 @@ test('simpleExchange with valid offers', async t => { simoleans, zoe, } = setup(); - const invitationIssuer = zoe.getInvitationIssuer(); + const invitationIssuer = await E(zoe).getInvitationIssuer(); const installation = await installationPFromSource(zoe, simpleExchange); // Setup Alice @@ -42,7 +42,7 @@ test('simpleExchange with valid offers', async t => { // 1: Alice creates a simpleExchange instance and spreads the publicFacet far // and wide with instructions on how to call makeInvitation(). - const { publicFacet, instance } = await zoe.startInstance(installation, { + const { publicFacet, instance } = await E(zoe).startInstance(installation, { Asset: moolaIssuer, Price: simoleanIssuer, }); @@ -117,9 +117,9 @@ test('simpleExchange with valid offers', async t => { const bobInstallation = await E(zoe).getInstallation(bobInvitation); // 5: Bob decides to join. - const bobExclusiveInvitation = await invitationIssuer.claim(bobInvitation); + const bobExclusiveInvitation = await E(invitationIssuer).claim(bobInvitation); - const bobIssuers = zoe.getIssuers(instance); + const bobIssuers = await E(zoe).getIssuers(instance); t.is(bobInstallation, installation); @@ -143,7 +143,7 @@ test('simpleExchange with valid offers', async t => { // 6: Bob escrows with zoe // 8: Bob submits the buy order to the exchange - const bobSeat = await zoe.offer( + const bobSeat = await E(zoe).offer( bobExclusiveInvitation, bobBuyOrderProposal, bobPayments, @@ -207,7 +207,7 @@ test('simpleExchange with multiple sell offers', async t => { simoleans, zoe, } = setup(); - const invitationIssuer = zoe.getInvitationIssuer(); + const invitationIssuer = await E(zoe).getInvitationIssuer(); const installation = await installationPFromSource(zoe, simpleExchange); // Setup Alice @@ -220,7 +220,7 @@ test('simpleExchange with multiple sell offers', async t => { // 1: Simon creates a simpleExchange instance and spreads the publicFacet // far and wide with instructions on how to use it. - const { publicFacet } = await zoe.startInstance(installation, { + const { publicFacet } = await E(zoe).startInstance(installation, { Asset: moolaIssuer, Price: simoleanIssuer, }); @@ -238,14 +238,14 @@ test('simpleExchange with multiple sell offers', async t => { const aliceInvitation1 = E(publicFacet).makeInvitation(); // 4: Alice adds her sell order to the exchange - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( aliceInvitation1, aliceSale1OrderProposal, alicePayments, ); // 5: Alice adds another sell order to the exchange - const aliceInvitation2 = await invitationIssuer.claim( + const aliceInvitation2 = await E(invitationIssuer).claim( await E(publicFacet).makeInvitation(), ); const aliceSale2OrderProposal = harden({ @@ -256,14 +256,14 @@ test('simpleExchange with multiple sell offers', async t => { const proposal2 = { Asset: aliceMoolaPurse.withdraw(moola(5)), }; - const aliceSeat2 = await zoe.offer( + const aliceSeat2 = await E(zoe).offer( aliceInvitation2, aliceSale2OrderProposal, proposal2, ); // 5: Alice adds a buy order to the exchange - const aliceInvitation3 = await invitationIssuer.claim( + const aliceInvitation3 = await E(invitationIssuer).claim( await E(publicFacet).makeInvitation(), ); const aliceBuyOrderProposal = harden({ @@ -272,7 +272,7 @@ test('simpleExchange with multiple sell offers', async t => { exit: { onDemand: null }, }); const proposal3 = { Price: aliceSimoleanPurse.withdraw(simoleans(18)) }; - const aliceSeat3 = await zoe.offer( + const aliceSeat3 = await E(zoe).offer( aliceInvitation3, aliceBuyOrderProposal, proposal3, @@ -310,7 +310,7 @@ test('simpleExchange with non-fungible assets', async t => { zoe, brands, } = setupNonFungible(); - const invitationIssuer = zoe.getInvitationIssuer(); + const invitationIssuer = await E(zoe).getInvitationIssuer(); const installation = await installationPFromSource(zoe, simpleExchange); // Setup Alice @@ -322,7 +322,7 @@ test('simpleExchange with non-fungible assets', async t => { // 1: Simon creates a simpleExchange instance and spreads the invitation far and // wide with instructions on how to use it. - const { publicFacet } = await zoe.startInstance(installation, { + const { publicFacet } = await E(zoe).startInstance(installation, { Asset: rpgIssuer, Price: ccIssuer, }); @@ -337,7 +337,7 @@ test('simpleExchange with non-fungible assets', async t => { }); const alicePayments = { Asset: aliceRpgPayment }; // 4: Alice adds her sell order to the exchange - const aliceSeat = await zoe.offer( + const aliceSeat = await E(zoe).offer( aliceInvitation, aliceSellOrderProposal, alicePayments, @@ -348,11 +348,11 @@ test('simpleExchange with non-fungible assets', async t => { // 5: Bob decides to join. const bobInstance = await E(zoe).getInstance(bobInvitation); const bobInstallation = await E(zoe).getInstallation(bobInvitation); - const bobExclusiveInvitation = await invitationIssuer.claim(bobInvitation); + const bobExclusiveInvitation = await E(invitationIssuer).claim(bobInvitation); t.is(bobInstallation, installation); - const bobIssuers = zoe.getIssuers(bobInstance); + const bobIssuers = await E(zoe).getIssuers(bobInstance); assert( bobIssuers.Asset === rpgIssuer, X`The Asset issuer should be the RPG issuer`, @@ -373,7 +373,7 @@ test('simpleExchange with non-fungible assets', async t => { // 6: Bob escrows with zoe // 8: Bob submits the buy order to the exchange - const bobSeat = await zoe.offer( + const bobSeat = await E(zoe).offer( bobExclusiveInvitation, bobBuyOrderProposal, bobPayments, diff --git a/packages/zoe/test/unitTests/contracts/test-throwInOfferHandler.js b/packages/zoe/test/unitTests/contracts/test-throwInOfferHandler.js index 996396a6cc0..710e9e8f114 100644 --- a/packages/zoe/test/unitTests/contracts/test-throwInOfferHandler.js +++ b/packages/zoe/test/unitTests/contracts/test-throwInOfferHandler.js @@ -7,7 +7,7 @@ import path from 'path'; import bundleSource from '@agoric/bundle-source'; import { E } from '@agoric/eventual-send'; -import { makeZoe } from '../../../src/zoeService/zoe.js'; +import { makeZoeKit } from '../../../src/zoeService/zoe.js'; import fakeVatAdmin from '../../../tools/fakeVatAdmin.js'; const filename = new URL(import.meta.url).pathname; @@ -16,7 +16,9 @@ const dirname = path.dirname(filename); const contractRoot = `${dirname}/throwInOfferHandler.js`; test('throw in offerHandler', async t => { - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // pack the contract const bundle = await bundleSource(contractRoot); diff --git a/packages/zoe/test/unitTests/contracts/test-useObj.js b/packages/zoe/test/unitTests/contracts/test-useObj.js index 6fe0af08c50..39907dc5fef 100644 --- a/packages/zoe/test/unitTests/contracts/test-useObj.js +++ b/packages/zoe/test/unitTests/contracts/test-useObj.js @@ -8,7 +8,7 @@ import bundleSource from '@agoric/bundle-source'; // noinspection ES6PreferShortImport import { E } from '@agoric/eventual-send'; -import { makeZoe } from '../../../src/zoeService/zoe.js'; +import { makeZoeKit } from '../../../src/zoeService/zoe.js'; import { setup } from '../setupBasicMints.js'; import fakeVatAdmin from '../../../tools/fakeVatAdmin.js'; @@ -20,12 +20,14 @@ const contractRoot = `${dirname}/useObjExample.js`; test('zoe - useObj', async t => { t.plan(3); const { moolaIssuer, moolaMint, moola } = setup(); - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // pack the contract const bundle = await bundleSource(contractRoot); // install the contract - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Setup Alice const aliceMoolaPayment = moolaMint.mintPayment(moola(3)); @@ -34,7 +36,7 @@ test('zoe - useObj', async t => { const issuerKeywordRecord = harden({ Pixels: moolaIssuer, }); - const { publicFacet } = await zoe.startInstance( + const { publicFacet } = await E(zoe).startInstance( installation, issuerKeywordRecord, ); @@ -48,7 +50,11 @@ test('zoe - useObj', async t => { const alicePayments = { Pixels: aliceMoolaPayment }; // Alice makes an offer - const aliceSeat = await zoe.offer(invitation, aliceProposal, alicePayments); + const aliceSeat = await E(zoe).offer( + invitation, + aliceProposal, + alicePayments, + ); const useObj = await E(aliceSeat).getOfferResult(); diff --git a/packages/zoe/test/unitTests/installFromSource.js b/packages/zoe/test/unitTests/installFromSource.js index ab133e27bf6..79f2419a421 100644 --- a/packages/zoe/test/unitTests/installFromSource.js +++ b/packages/zoe/test/unitTests/installFromSource.js @@ -1,6 +1,7 @@ // @ts-check import bundleSource from '@agoric/bundle-source'; +import { E } from '@agoric/eventual-send'; /** * @param {ZoeService} zoe @@ -8,4 +9,4 @@ import bundleSource from '@agoric/bundle-source'; * @returns {Promise} */ export const installationPFromSource = (zoe, path) => - bundleSource(path).then(b => zoe.install(b)); + bundleSource(path).then(b => E(zoe).install(b)); diff --git a/packages/zoe/test/unitTests/setupBasicMints.js b/packages/zoe/test/unitTests/setupBasicMints.js index 6fc839b4beb..e1cf960199a 100644 --- a/packages/zoe/test/unitTests/setupBasicMints.js +++ b/packages/zoe/test/unitTests/setupBasicMints.js @@ -2,7 +2,8 @@ import { makeIssuerKit, AmountMath } from '@agoric/ertp'; import { makeStore } from '@agoric/store'; -import { makeZoe } from '../../src/zoeService/zoe.js'; +import { E } from '@agoric/eventual-send'; +import { makeZoeKit } from '../../src/zoeService/zoe.js'; import fakeVatAdmin from '../../tools/fakeVatAdmin.js'; const setup = () => { @@ -21,7 +22,9 @@ const setup = () => { brands.init(k, allBundles[k].brand); } - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const makeSimpleMake = brand => value => AmountMath.make(value, brand); @@ -43,7 +46,7 @@ const setup = () => { * @property {(value: any) => Amount} moola * @property {(value: any) => Amount} simoleans * @property {(value: any) => Amount} bucks - * @property {ZoeService} zoe + * @property {ERef} zoe */ /** @type {BasicMints} */ diff --git a/packages/zoe/test/unitTests/setupMixedMints.js b/packages/zoe/test/unitTests/setupMixedMints.js index e2ee006b812..ea8d63e02fe 100644 --- a/packages/zoe/test/unitTests/setupMixedMints.js +++ b/packages/zoe/test/unitTests/setupMixedMints.js @@ -1,7 +1,8 @@ // @ts-check import { makeIssuerKit, AmountMath, AssetKind } from '@agoric/ertp'; -import { makeZoe } from '../../src/zoeService/zoe.js'; +import { E } from '@agoric/eventual-send'; +import { makeZoeKit } from '../../src/zoeService/zoe.js'; import fakeVatAdmin from '../../tools/fakeVatAdmin.js'; const setupMixed = () => { @@ -25,7 +26,9 @@ const setupMixed = () => { const cryptoCats = value => AmountMath.make(value, allBundles.cc.brand); const moola = value => AmountMath.make(value, allBundles.moola.brand); - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); return { zoe, ccIssuer, diff --git a/packages/zoe/test/unitTests/setupNonFungibleMints.js b/packages/zoe/test/unitTests/setupNonFungibleMints.js index 354263e58ec..1fcc751d518 100644 --- a/packages/zoe/test/unitTests/setupNonFungibleMints.js +++ b/packages/zoe/test/unitTests/setupNonFungibleMints.js @@ -1,7 +1,8 @@ // @ts-check import { makeIssuerKit, AmountMath, AssetKind } from '@agoric/ertp'; -import { makeZoe } from '../../src/zoeService/zoe.js'; +import { E } from '@agoric/eventual-send'; +import { makeZoeKit } from '../../src/zoeService/zoe.js'; import fakeVatAdmin from '../../tools/fakeVatAdmin.js'; const setupNonFungible = () => { @@ -21,7 +22,9 @@ const setupNonFungible = () => { function createRpgItem(name, power, desc = undefined) { return harden([{ name, description: desc || name, power }]); } - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const ccIssuer = issuers.get('cc'); const rpgIssuer = issuers.get('rpg'); diff --git a/packages/zoe/test/unitTests/test-bindDefaultFeePurse.js b/packages/zoe/test/unitTests/test-bindDefaultFeePurse.js new file mode 100644 index 00000000000..ae16b6129ad --- /dev/null +++ b/packages/zoe/test/unitTests/test-bindDefaultFeePurse.js @@ -0,0 +1,85 @@ +// @ts-check + +// eslint-disable-next-line import/no-extraneous-dependencies +import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js'; +import { E } from '@agoric/eventual-send'; +import { Far } from '@agoric/marshal'; + +import { bindDefaultFeePurse } from '../../src/zoeService/feePurse.js'; + +const zoe = Far('mockZoe', { + makeFeePurse: () => Far('feePurse', {}), + bindDefaultFeePurse: feePurse => bindDefaultFeePurse(zoe, feePurse), + // @ts-ignore Mocked for tests + install: (bundle, feePurse) => feePurse, + startInstance: ( + // @ts-ignore Mocked for tests + installation, + // @ts-ignore Mocked for tests + issuerKeywordRecord, + // @ts-ignore Mocked for tests + terms, + // @ts-ignore Mocked for tests + privateArgs, + feePurse, + ) => feePurse, + // @ts-ignore Mocked for tests + offer: (invitation, proposal, paymentKeywordRecord, offerArgs, feePurse) => + feePurse, + // @ts-ignore Mocked for tests + getPublicFacet: (instance, feePurse) => feePurse, +}); + +test('bindDefaultFeePurse', async t => { + const defaultFeePurse = await E(zoe).makeFeePurse(); + const customFeePurse = await E(zoe).makeFeePurse(); + // @ts-ignore Mocked for tests + const boundZoe = E(zoe).bindDefaultFeePurse(defaultFeePurse); + + // @ts-ignore Mocked for tests + t.is(await E(boundZoe).install(undefined), defaultFeePurse); + // @ts-ignore Mocked for tests + t.is(await E(boundZoe).install(undefined, customFeePurse), customFeePurse); + + t.is( + // @ts-ignore Mocked for tests + await E(boundZoe).startInstance(undefined, undefined, undefined, undefined), + defaultFeePurse, + ); + t.is( + await E(boundZoe).startInstance( + // @ts-ignore Mocked for tests + undefined, + undefined, + undefined, + undefined, + customFeePurse, + ), + customFeePurse, + ); + + t.is( + // @ts-ignore Mocked for tests + await E(boundZoe).offer(undefined, undefined, undefined, undefined), + defaultFeePurse, + ); + t.is( + await E(boundZoe).offer( + // @ts-ignore Mocked for tests + undefined, + undefined, + undefined, + undefined, + customFeePurse, + ), + customFeePurse, + ); + + // @ts-ignore Mocked for tests + t.is(await E(boundZoe).getPublicFacet(undefined), defaultFeePurse); + t.is( + // @ts-ignore Mocked for tests + await E(boundZoe).getPublicFacet(undefined, customFeePurse), + customFeePurse, + ); +}); diff --git a/packages/zoe/test/unitTests/test-feesCharged.js b/packages/zoe/test/unitTests/test-feesCharged.js new file mode 100644 index 00000000000..718bd1e5cd4 --- /dev/null +++ b/packages/zoe/test/unitTests/test-feesCharged.js @@ -0,0 +1,122 @@ +// @ts-check +// eslint-disable-next-line import/no-extraneous-dependencies +import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js'; + +import path from 'path'; + +import { AmountMath, AssetKind } from '@agoric/ertp'; +import { E } from '@agoric/eventual-send'; + +// eslint-disable-next-line import/no-extraneous-dependencies +import bundleSource from '@agoric/bundle-source'; + +// noinspection ES6PreferShortImport +import { makeZoeKit } from '../../src/zoeService/zoe.js'; +import { makeFakeVatAdmin } from '../../tools/fakeVatAdmin.js'; + +const filename = new URL(import.meta.url).pathname; +const dirname = path.dirname(filename); + +const contractRoot = `${dirname}/zcf/zcfTesterContract.js`; + +test(`fee charged for install, startInstance, offer, getPublicFacet`, async t => { + /** @type {ContractFacet} */ + let zcf; + const setZCF = jig => { + zcf = jig.zcf; + }; + // The contract provides the `zcf` via `setTestJig` upon `start`. + const fakeVatAdmin = makeFakeVatAdmin(setZCF); + const zoeFeesConfig = harden({ + getPublicFacetFee: 1n, + installFee: 2n, + startInstanceFee: 100n, + offerFee: 5n, + }); + + const feeIssuerConfig = { + name: 'RUN', + assetKind: AssetKind.NAT, + displayInfo: { decimalPlaces: 6, assetKind: AssetKind.NAT }, + initialFunds: 200n, + }; + + const { zoeService, initialFeeFunds, getFeeCollectionPurse } = makeZoeKit( + fakeVatAdmin.admin, + undefined, + feeIssuerConfig, + zoeFeesConfig, + ); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); + const feeIssuer = E(zoe).getFeeIssuer(); + const feeBrand = await E(feeIssuer).getBrand(); + + let expectedBalance = AmountMath.make(feeBrand, feeIssuerConfig.initialFunds); + + await E(feePurse).deposit(initialFeeFunds); + + const bundle = await bundleSource(contractRoot); + + t.true( + AmountMath.isEqual(await E(feePurse).getCurrentAmount(), expectedBalance), + ); + + const installation = await E(zoe).install(bundle); + + expectedBalance = AmountMath.subtract( + expectedBalance, + AmountMath.make(feeBrand, zoeFeesConfig.installFee), + ); + + t.true( + AmountMath.isEqual(await E(feePurse).getCurrentAmount(), expectedBalance), + ); + + const { instance } = await E(zoe).startInstance(installation); + + expectedBalance = AmountMath.subtract( + expectedBalance, + AmountMath.make(feeBrand, zoeFeesConfig.startInstanceFee), + ); + + t.true( + AmountMath.isEqual(await E(feePurse).getCurrentAmount(), expectedBalance), + ); + + const invitation = zcf.makeInvitation(() => {}, 'invitation'); + await E(zoe).offer(invitation); + + expectedBalance = AmountMath.subtract( + expectedBalance, + AmountMath.make(feeBrand, zoeFeesConfig.offerFee), + ); + + t.true( + AmountMath.isEqual(await E(feePurse).getCurrentAmount(), expectedBalance), + ); + + await E(zoe).getPublicFacet(instance); + + expectedBalance = AmountMath.subtract( + expectedBalance, + AmountMath.make(feeBrand, zoeFeesConfig.getPublicFacetFee), + ); + + t.true( + AmountMath.isEqual(await E(feePurse).getCurrentAmount(), expectedBalance), + ); + + const collectionPurse = getFeeCollectionPurse(); + + const allFees = AmountMath.make( + feeBrand, + zoeFeesConfig.installFee + + zoeFeesConfig.startInstanceFee + + zoeFeesConfig.offerFee + + zoeFeesConfig.getPublicFacetFee, + ); + t.true( + AmountMath.isEqual(await E(collectionPurse).getCurrentAmount(), allFees), + ); +}); diff --git a/packages/zoe/test/unitTests/test-makeKind.js b/packages/zoe/test/unitTests/test-makeKind.js index 6cc024c4bf6..22f8b091959 100644 --- a/packages/zoe/test/unitTests/test-makeKind.js +++ b/packages/zoe/test/unitTests/test-makeKind.js @@ -8,7 +8,7 @@ import path from 'path'; import bundleSource from '@agoric/bundle-source'; import { E } from '@agoric/eventual-send'; -import { makeZoe } from '../../src/zoeService/zoe.js'; +import { makeZoeKit } from '../../src/zoeService/zoe.js'; import fakeVatAdmin from '../../tools/fakeVatAdmin.js'; const filename = new URL(import.meta.url).pathname; @@ -18,9 +18,11 @@ const root = `${dirname}/../minimalMakeKindContract.js`; test('makeKind non-swingset', async t => { const bundle = await bundleSource(root); - const zoe = makeZoe(fakeVatAdmin); + const { zoeService } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const installation = await E(zoe).install(bundle); t.notThrows(() => makeKind()); t.notThrows(() => makeVirtualScalarWeakMap()); - await t.notThrowsAsync(() => zoe.startInstance(installation)); + await t.notThrowsAsync(() => E(zoe).startInstance(installation)); }); diff --git a/packages/zoe/test/unitTests/test-scriptedOracle.js b/packages/zoe/test/unitTests/test-scriptedOracle.js index d7edc795f07..8a870b3767c 100644 --- a/packages/zoe/test/unitTests/test-scriptedOracle.js +++ b/packages/zoe/test/unitTests/test-scriptedOracle.js @@ -10,7 +10,7 @@ import { E } from '@agoric/eventual-send'; import { assert } from '@agoric/assert'; import { makeFakeVatAdmin } from '../../tools/fakeVatAdmin.js'; -import { makeZoe } from '../../src/zoeService/zoe.js'; +import { makeZoeKit } from '../../src/zoeService/zoe.js'; import '../../exported.js'; import '../../src/contracts/exported.js'; @@ -44,7 +44,9 @@ test.before( /** @param {ExecutionContext} ot */ async ot => { // Outside of tests, we should use the long-lived Zoe on the // testnet. In this test, we must create a new Zoe. - const zoe = makeZoe(makeFakeVatAdmin().admin); + const { zoeService } = makeZoeKit(makeFakeVatAdmin().admin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const oracleContractBundle = await bundleSource(oracleContractPath); const bountyContractBundle = await bundleSource(bountyContractPath); diff --git a/packages/zoe/test/unitTests/test-zoe.js b/packages/zoe/test/unitTests/test-zoe.js index 8ea42f63565..d1a46e43618 100644 --- a/packages/zoe/test/unitTests/test-zoe.js +++ b/packages/zoe/test/unitTests/test-zoe.js @@ -4,6 +4,7 @@ import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js'; import path from 'path'; +import { AmountMath } from '@agoric/ertp'; import { E } from '@agoric/eventual-send'; import { makePromiseKit } from '@agoric/promise-kit'; import { passStyleOf } from '@agoric/marshal'; @@ -32,7 +33,7 @@ test(`zoe.getInvitationIssuer`, async t => { t.falsy(await E(invitationIssuer).isLive(invitation)); }); -test(`zoe.install bad bundle`, async t => { +test(`E(zoe).install bad bundle`, async t => { const { zoe } = setup(); // @ts-ignore deliberate invalid arguments for testing await t.throwsAsync(() => E(zoe).install(), { @@ -40,7 +41,7 @@ test(`zoe.install bad bundle`, async t => { }); }); -test(`zoe.install`, async t => { +test(`E(zoe).install`, async t => { const { zoe } = setup(); const contractPath = `${dirname}/../../src/contracts/atomicSwap`; const bundle = await bundleSource(contractPath); @@ -49,7 +50,7 @@ test(`zoe.install`, async t => { t.is(await E(installation).getBundle(), bundle); }); -test(`zoe.startInstance bad installation`, async t => { +test(`E(zoe).startInstance bad installation`, async t => { const { zoe } = setup(); // @ts-ignore deliberate invalid arguments for testing await t.throwsAsync(() => E(zoe).startInstance(), { @@ -68,7 +69,7 @@ function isEmptyFacet(t, facet) { t.deepEqual(Object.getOwnPropertyNames(facet), []); } -test(`zoe.startInstance no issuerKeywordRecord, no terms`, async t => { +test(`E(zoe).startInstance no issuerKeywordRecord, no terms`, async t => { const { zoe, installation } = await setupZCFTest(); const result = await E(zoe).startInstance(installation); // Note that deepEqual treats all empty objects (handles) as interchangeable. @@ -87,7 +88,7 @@ test(`zoe.startInstance no issuerKeywordRecord, no terms`, async t => { ]); }); -test(`zoe.startInstance promise for installation`, async t => { +test(`E(zoe).startInstance promise for installation`, async t => { const { zoe, installation } = await setupZCFTest(); const { promise: installationP, @@ -114,7 +115,7 @@ test(`zoe.startInstance promise for installation`, async t => { ]); }); -test(`zoe.startInstance - terms, issuerKeywordRecord switched`, async t => { +test(`E(zoe).startInstance - terms, issuerKeywordRecord switched`, async t => { const { zoe, installation } = await setupZCFTest(); const { moolaKit } = setup(); await t.throwsAsync( @@ -137,14 +138,14 @@ test(`zoe.startInstance - terms, issuerKeywordRecord switched`, async t => { ); }); -test(`zoe.offer`, async t => { +test(`E(zoe).offer`, async t => { const { zoe, zcf } = await setupZCFTest(); const invitation = zcf.makeInvitation(() => 'result', 'invitation'); const userSeat = E(zoe).offer(invitation); t.is(await E(userSeat).getOfferResult(), 'result'); }); -test(`zoe.offer - no invitation`, async t => { +test(`E(zoe).offer - no invitation`, async t => { const { zoe } = await setupZCFTest(); // @ts-ignore deliberate invalid arguments for testing await t.throwsAsync(() => E(zoe).offer(), { @@ -152,7 +153,7 @@ test(`zoe.offer - no invitation`, async t => { }); }); -test(`zoe.getPublicFacet`, async t => { +test(`E(zoe).getPublicFacet`, async t => { const { zoe } = setup(); const contractPath = `${dirname}/../../src/contracts/automaticRefund`; const bundle = await bundleSource(contractPath); @@ -163,7 +164,7 @@ test(`zoe.getPublicFacet`, async t => { t.is(await E(zoe).getPublicFacet(instance), publicFacet); }); -test(`zoe.getPublicFacet - no instance`, async t => { +test(`E(zoe).getPublicFacet - no instance`, async t => { const { zoe } = setup(); // @ts-ignore deliberate invalid arguments for testing await t.throwsAsync(() => E(zoe).getPublicFacet(), { @@ -371,3 +372,27 @@ test(`zoe.getInvitationDetails - no invitation`, async t => { message: /A Zoe invitation is required, not "\[undefined\]"/, }); }); + +test(`zoe.makeFeePurse`, async t => { + const { zoe, zcf, feeMintAccess } = await setupZCFTest(); + + const feePurse = E(zoe).makeFeePurse(); + const feeIssuer = E(zoe).getFeeIssuer(); + const feeBrand = await E(feeIssuer).getBrand(); + + const zcfMint = await zcf.registerFeeMint('RUN', feeMintAccess); + const { zcfSeat, userSeat } = zcf.makeEmptySeatKit(); + + const fee1000 = AmountMath.make(feeBrand, 1000n); + zcfMint.mintGains({ Fee: fee1000 }, zcfSeat); + + zcfSeat.exit(); + const payment = await E(userSeat).getPayout('Fee'); + await E(feePurse).deposit(payment); + + t.true(AmountMath.isEqual(await E(feePurse).getCurrentAmount(), fee1000)); + + await E(feePurse).withdraw(fee1000); + + t.true(AmountMath.isEmpty(await E(feePurse).getCurrentAmount())); +}); diff --git a/packages/zoe/test/unitTests/zcf/registerFeeMintContract.js b/packages/zoe/test/unitTests/zcf/registerFeeMintContract.js new file mode 100644 index 00000000000..1f5449bc4c6 --- /dev/null +++ b/packages/zoe/test/unitTests/zcf/registerFeeMintContract.js @@ -0,0 +1,41 @@ +// @ts-check + +import { AmountMath } from '@agoric/ertp'; +import { E } from '@agoric/eventual-send'; + +/** + * Tests zcf.registerFeeMint + * + * @type {ContractStartFn} + */ +const start = async (zcf, privateArgs) => { + // make the `zcf` and `instance` available to the tests + const instance = zcf.getInstance(); + zcf.setTestJig(() => harden({ instance })); + + const RUNZCFMint = await zcf.registerFeeMint( + 'RUN', + privateArgs.feeMintAccess, + ); + const { brand: RUNBrand } = RUNZCFMint.getIssuerRecord(); + const { zcfSeat, userSeat } = zcf.makeEmptySeatKit(); + RUNZCFMint.mintGains( + { + Winnings: AmountMath.make(RUNBrand, 10n), + }, + zcfSeat, + ); + + const creatorFacet = harden({ + getMintedAmount: () => zcfSeat.getAmountAllocated('Winnings'), + getMintedPayout: () => { + zcfSeat.exit(); + return E(userSeat).getPayout('Winnings'); + }, + }); + + return harden({ creatorFacet }); +}; + +harden(start); +export { start }; diff --git a/packages/zoe/test/unitTests/zcf/setupZcfTest.js b/packages/zoe/test/unitTests/zcf/setupZcfTest.js index 3886afa8147..8841b24c762 100644 --- a/packages/zoe/test/unitTests/zcf/setupZcfTest.js +++ b/packages/zoe/test/unitTests/zcf/setupZcfTest.js @@ -7,7 +7,7 @@ import { assert } from '@agoric/assert'; import path from 'path'; // noinspection ES6PreferShortImport -import { makeZoe } from '../../../src/zoeService/zoe.js'; +import { makeZoeKit } from '../../../src/zoeService/zoe.js'; import { makeFakeVatAdmin } from '../../../tools/fakeVatAdmin.js'; const filename = new URL(import.meta.url).pathname; @@ -23,7 +23,9 @@ export const setupZCFTest = async (issuerKeywordRecord, terms) => { }; // The contract provides the `zcf` via `setTestJig` upon `start`. const fakeVatAdmin = makeFakeVatAdmin(setZCF); - const zoe = makeZoe(fakeVatAdmin.admin); + const { zoeService, feeMintAccess } = makeZoeKit(fakeVatAdmin.admin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); const bundle = await bundleSource(contractRoot); const installation = await E(zoe).install(bundle); const { creatorFacet, instance } = await E(zoe).startInstance( @@ -34,5 +36,13 @@ export const setupZCFTest = async (issuerKeywordRecord, terms) => { const { vatAdminState } = fakeVatAdmin; // @ts-ignore fix types to understand that zcf is always defined assert(zcf !== undefined); - return { zoe, zcf, instance, installation, creatorFacet, vatAdminState }; + return { + zoe, + zcf, + instance, + installation, + creatorFacet, + vatAdminState, + feeMintAccess, + }; }; diff --git a/packages/zoe/test/unitTests/zcf/test-feeMintAccess.js b/packages/zoe/test/unitTests/zcf/test-feeMintAccess.js new file mode 100644 index 00000000000..3e62426df04 --- /dev/null +++ b/packages/zoe/test/unitTests/zcf/test-feeMintAccess.js @@ -0,0 +1,43 @@ +// @ts-check +// eslint-disable-next-line import/no-extraneous-dependencies +import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js'; + +import path from 'path'; + +import { E } from '@agoric/eventual-send'; +import { AmountMath } from '@agoric/ertp'; + +// eslint-disable-next-line import/no-extraneous-dependencies +import bundleSource from '@agoric/bundle-source'; + +// noinspection ES6PreferShortImport +import { makeZoeKit } from '../../../src/zoeService/zoe.js'; +import fakeVatAdmin from '../../../tools/fakeVatAdmin.js'; + +const filename = new URL(import.meta.url).pathname; +const dirname = path.dirname(filename); + +const contractRoot = `${dirname}/registerFeeMintContract.js`; + +test(`feeMintAccess`, async t => { + const { zoeService, feeMintAccess } = makeZoeKit(fakeVatAdmin); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = await E(zoeService).bindDefaultFeePurse(feePurse); + const bundle = await bundleSource(contractRoot); + const installation = await E(zoe).install(bundle); + const { creatorFacet } = await E(zoe).startInstance( + installation, + undefined, + undefined, + harden({ feeMintAccess }), + ); + const mintedAmount = await E(creatorFacet).getMintedAmount(); + const feeIssuer = E(zoe).getFeeIssuer(); + const feeBrand = await E(feeIssuer).getBrand(); + t.true(AmountMath.isEqual(mintedAmount, AmountMath.make(feeBrand, 10n))); + + const mintedPayment = await E(creatorFacet).getMintedPayout(); + const mintedAmount2 = await E(feeIssuer).getAmountOf(mintedPayment); + + t.true(AmountMath.isEqual(mintedAmount2, AmountMath.make(feeBrand, 10n))); +}); diff --git a/packages/zoe/test/unitTests/zcf/test-zcf.js b/packages/zoe/test/unitTests/zcf/test-zcf.js index 5698884dfaa..a9628e1ccab 100644 --- a/packages/zoe/test/unitTests/zcf/test-zcf.js +++ b/packages/zoe/test/unitTests/zcf/test-zcf.js @@ -15,8 +15,8 @@ import { assertAmountsEqual } from '../../zoeTestHelpers.js'; test(`zcf.getZoeService`, async t => { const { zoe, zcf } = await setupZCFTest(); - const zoeService = zcf.getZoeService(); - t.is(await zoeService, zoe); + const zoeService = await zcf.getZoeService(); + t.is(await E(zoeService).getFeeIssuer(), await E(zoe).getFeeIssuer()); }); test(`zcf.getInstance`, async t => { diff --git a/packages/zoe/test/unitTests/zcf/test-zcfSeat-exit.js b/packages/zoe/test/unitTests/zcf/test-zcfSeat-exit.js index c5a9ea6af52..dfffd7ddcec 100644 --- a/packages/zoe/test/unitTests/zcf/test-zcfSeat-exit.js +++ b/packages/zoe/test/unitTests/zcf/test-zcfSeat-exit.js @@ -8,7 +8,7 @@ import { E } from '@agoric/eventual-send'; import bundleSource from '@agoric/bundle-source'; // noinspection ES6PreferShortImport -import { makeZoe } from '../../../src/zoeService/zoe.js'; +import { makeZoeKit } from '../../../src/zoeService/zoe.js'; import { setup } from '../setupBasicMints.js'; import { makeFakeVatAdmin } from '../../../tools/fakeVatAdmin.js'; @@ -29,12 +29,14 @@ test(`zoe - wrongly throw zcfSeat.exit()`, async t => { testJig = jig; }; const { admin: fakeVatAdminSvc, vatAdminState } = makeFakeVatAdmin(setJig); - const zoe = makeZoe(fakeVatAdminSvc); + const { zoeService } = makeZoeKit(fakeVatAdminSvc); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // pack the contract const bundle = await bundleSource(contractRoot); // install the contract - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Alice creates an instance const issuerKeywordRecord = harden({ diff --git a/packages/zoe/test/unitTests/zcf/test-zcfSeat.js b/packages/zoe/test/unitTests/zcf/test-zcfSeat.js index 67ea4d127b5..dfe549d8083 100644 --- a/packages/zoe/test/unitTests/zcf/test-zcfSeat.js +++ b/packages/zoe/test/unitTests/zcf/test-zcfSeat.js @@ -8,7 +8,7 @@ import { E } from '@agoric/eventual-send'; import bundleSource from '@agoric/bundle-source'; // noinspection ES6PreferShortImport -import { makeZoe } from '../../../src/zoeService/zoe.js'; +import { makeZoeKit } from '../../../src/zoeService/zoe.js'; import { setup } from '../setupBasicMints.js'; import { makeFakeVatAdmin } from '../../../tools/fakeVatAdmin.js'; @@ -26,12 +26,14 @@ test(`zoe - zcfSeat.fail() doesn't throw`, async t => { testJig = jig; }; const { admin: fakeVatAdminSvc, vatAdminState } = makeFakeVatAdmin(setJig); - const zoe = makeZoe(fakeVatAdminSvc); + const { zoeService } = makeZoeKit(fakeVatAdminSvc); + const feePurse = E(zoeService).makeFeePurse(); + const zoe = E(zoeService).bindDefaultFeePurse(feePurse); // pack the contract const bundle = await bundleSource(contractRoot); // install the contract - const installation = await zoe.install(bundle); + const installation = await E(zoe).install(bundle); // Alice creates an instance const issuerKeywordRecord = harden({ diff --git a/packages/zoe/test/unitTests/zcf/zcfTesterContract.js b/packages/zoe/test/unitTests/zcf/zcfTesterContract.js index 2d8ae98138d..f447f7a9817 100644 --- a/packages/zoe/test/unitTests/zcf/zcfTesterContract.js +++ b/packages/zoe/test/unitTests/zcf/zcfTesterContract.js @@ -1,6 +1,5 @@ // @ts-check -import { E } from '@agoric/eventual-send'; import '../../../exported.js'; /** @@ -10,10 +9,9 @@ import '../../../exported.js'; */ const start = async zcf => { // make the `zcf` and `instance` available to the tests - const invitation = zcf.makeInvitation(() => {}, 'test'); - const zoe = zcf.getZoeService(); - const { instance } = await E(zoe).getInvitationDetails(invitation); + const instance = zcf.getInstance(); zcf.setTestJig(() => harden({ instance })); + return {}; }; diff --git a/packages/zoe/test/unitTests/zoe/test-createZCFVat.js b/packages/zoe/test/unitTests/zoe/test-createZCFVat.js index aa12c9737ce..2177cc6e74c 100644 --- a/packages/zoe/test/unitTests/zoe/test-createZCFVat.js +++ b/packages/zoe/test/unitTests/zoe/test-createZCFVat.js @@ -14,12 +14,24 @@ test('setupCreateZCFVat', async t => { const fakeVatAdminSvc = Far('fakeVatAdminSvc', { createMeter: () => {}, createUnlimitedMeter: () => {}, - createVatByName: name => name, - createVat: _bundle => 'zcfBundle', + createVatByName: _name => { + return harden({ adminNode: undefined, root: undefined }); + }, + createVat: _bundle => { + return harden({ adminNode: undefined, root: undefined }); + }, }); // @ts-ignore fakeVatAdminSvc is mocked - t.is(await setupCreateZCFVat(fakeVatAdminSvc, undefined)(), 'zcfBundle'); + t.deepEqual(await setupCreateZCFVat(fakeVatAdminSvc, undefined)(), { + meter: undefined, + adminNode: undefined, + root: undefined, + }); // @ts-ignore fakeVatAdminSvc is mocked - t.is(await setupCreateZCFVat(fakeVatAdminSvc, 'myVat')(), 'myVat'); + t.deepEqual(await setupCreateZCFVat(fakeVatAdminSvc, 'myVat')(), { + meter: undefined, + adminNode: undefined, + root: undefined, + }); }); diff --git a/packages/zoe/test/unitTests/zoe/test-feePurse.js b/packages/zoe/test/unitTests/zoe/test-feePurse.js new file mode 100644 index 00000000000..8aa1259b89d --- /dev/null +++ b/packages/zoe/test/unitTests/zoe/test-feePurse.js @@ -0,0 +1,51 @@ +// @ts-check + +// eslint-disable-next-line import/no-extraneous-dependencies +import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js'; + +import { makeIssuerKit, AssetKind, AmountMath } from '@agoric/ertp'; + +import { setupMakeFeePurse } from '../../../src/zoeService/feePurse.js'; + +const setup = () => { + const runIssuerKit = makeIssuerKit('RUN', AssetKind.NAT, { + decimalPlaces: 6, + }); + const { makeFeePurse, chargeZoeFee } = setupMakeFeePurse(runIssuerKit.issuer); + return { makeFeePurse, chargeZoeFee, runIssuerKit }; +}; + +test('feePurse starts empty', async t => { + const { makeFeePurse } = setup(); + const feePurse = await makeFeePurse(); + + t.true(AmountMath.isEmpty(feePurse.getCurrentAmount())); +}); + +test('depositing into and withdrawing from feePurse', async t => { + const { makeFeePurse, runIssuerKit } = setup(); + const feePurse = await makeFeePurse(); + + const run1000 = AmountMath.make(runIssuerKit.brand, 1000n); + const payment = runIssuerKit.mint.mintPayment(run1000); + feePurse.deposit(payment); + + t.true(AmountMath.isEqual(feePurse.getCurrentAmount(), run1000)); + + feePurse.withdraw(run1000); + + t.true(AmountMath.isEmpty(feePurse.getCurrentAmount())); +}); + +test('chargeZoeFee', async t => { + const { makeFeePurse, chargeZoeFee, runIssuerKit } = setup(); + const feePurse = await makeFeePurse(); + + const run1000 = AmountMath.make(runIssuerKit.brand, 1000n); + const payment = runIssuerKit.mint.mintPayment(run1000); + feePurse.deposit(payment); + + await chargeZoeFee(feePurse, run1000); + + t.true(AmountMath.isEmpty(feePurse.getCurrentAmount())); +}); diff --git a/packages/zoe/test/unitTests/zoe/test-installationStorage.js b/packages/zoe/test/unitTests/zoe/test-installationStorage.js index c314fe5600c..8e0a08f06bb 100644 --- a/packages/zoe/test/unitTests/zoe/test-installationStorage.js +++ b/packages/zoe/test/unitTests/zoe/test-installationStorage.js @@ -6,46 +6,54 @@ import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js'; import { makeInstallationStorage } from '../../../src/zoeService/installationStorage.js'; test('install, unwrap installations', async t => { - const { install, unwrapInstallation } = makeInstallationStorage(); + const chargeZoeFee = () => true; + const { install, unwrapInstallation } = makeInstallationStorage(chargeZoeFee); const fakeBundle = {}; + const feePurse = /** @type {FeePurse} */ ({}); - const installation = install(fakeBundle); + const installation = await install(fakeBundle, feePurse); const unwrapped = await unwrapInstallation(installation); t.is(unwrapped.installation, installation); t.is(unwrapped.bundle, fakeBundle); }); test('unwrap promise for installation', async t => { - const { install, unwrapInstallation } = makeInstallationStorage(); + const chargeZoeFee = () => true; + const { install, unwrapInstallation } = makeInstallationStorage(chargeZoeFee); const fakeBundle = {}; + const feePurse = /** @type {FeePurse} */ ({}); - const installation = install(fakeBundle); + const installation = await install(fakeBundle, feePurse); const unwrapped = await unwrapInstallation(Promise.resolve(installation)); t.is(unwrapped.installation, installation); t.is(unwrapped.bundle, fakeBundle); }); test('install several', async t => { - const { install, unwrapInstallation } = makeInstallationStorage(); + const chargeZoeFee = () => true; + const { install, unwrapInstallation } = makeInstallationStorage(chargeZoeFee); const fakeBundle1 = {}; const fakeBundle2 = {}; + const feePurse = /** @type {FeePurse} */ ({}); - const installation1 = install(fakeBundle1); + const installation1 = await install(fakeBundle1, feePurse); const unwrapped1 = await unwrapInstallation(installation1); t.is(unwrapped1.installation, installation1); t.is(unwrapped1.bundle, fakeBundle1); - const installation2 = install(fakeBundle2); + const installation2 = await install(fakeBundle2, feePurse); const unwrapped2 = await unwrapInstallation(installation2); t.is(unwrapped2.installation, installation2); t.is(unwrapped2.bundle, fakeBundle2); }); test('install same twice', async t => { - const { install, unwrapInstallation } = makeInstallationStorage(); + const chargeZoeFee = () => true; + const { install, unwrapInstallation } = makeInstallationStorage(chargeZoeFee); const fakeBundle1 = {}; + const feePurse = /** @type {FeePurse} */ ({}); - const installation1 = install(fakeBundle1); + const installation1 = await install(fakeBundle1, feePurse); const unwrapped1 = await unwrapInstallation(installation1); t.is(unwrapped1.installation, installation1); t.is(unwrapped1.bundle, fakeBundle1); @@ -53,7 +61,7 @@ test('install same twice', async t => { // If the same bundle is installed twice, the bundle is the same, // but the installation is different. Zoe does not currently care about // duplicate bundles. - const installation2 = install(fakeBundle1); + const installation2 = await install(fakeBundle1, feePurse); const unwrapped2 = await unwrapInstallation(installation2); t.is(unwrapped2.installation, installation2); t.not(installation2, installation1); diff --git a/packages/zoe/test/unitTests/zoe/test-instanceAdminStorage.js b/packages/zoe/test/unitTests/zoe/test-instanceAdminStorage.js index 259c953d380..73a2c8ba5f7 100644 --- a/packages/zoe/test/unitTests/zoe/test-instanceAdminStorage.js +++ b/packages/zoe/test/unitTests/zoe/test-instanceAdminStorage.js @@ -8,6 +8,8 @@ import { Far } from '@agoric/marshal'; import { makeInstanceAdminStorage } from '../../../src/zoeService/instanceAdminStorage.js'; test('makeInstanceAdminStorage', async t => { + const chargeZoeFee = () => {}; + const { getPublicFacet, getBrands, @@ -17,7 +19,7 @@ test('makeInstanceAdminStorage', async t => { getInstanceAdmin, initInstanceAdmin, deleteInstanceAdmin, - } = makeInstanceAdminStorage(); + } = makeInstanceAdminStorage(chargeZoeFee); const mockInstance1 = Far('mockInstance1', {}); const mockInstance2 = Far('mockInstance2', {}); @@ -46,19 +48,19 @@ test('makeInstanceAdminStorage', async t => { t.is(getInstanceAdmin(mockInstance1), mockInstanceAdmin1); // @ts-ignore instance is mocked - t.is(getPublicFacet(mockInstance1), 'publicFacet1'); + t.is(await getPublicFacet(mockInstance1), 'publicFacet1'); // @ts-ignore instance is mocked - t.is(getBrands(mockInstance2), 'brands2'); + t.is(await getBrands(mockInstance2), 'brands2'); // @ts-ignore instance is mocked - t.is(getIssuers(mockInstance1), 'issuers1'); + t.is(await getIssuers(mockInstance1), 'issuers1'); // @ts-ignore instance is mocked - t.is(getTerms(mockInstance1), 'terms1'); + t.is(await getTerms(mockInstance1), 'terms1'); // @ts-ignore instance is mocked - t.is(getInstallationForInstance(mockInstance1), 'installation1'); + t.is(await getInstallationForInstance(mockInstance1), 'installation1'); // @ts-ignore instance is mocked deleteInstanceAdmin(mockInstance2); @@ -69,13 +71,14 @@ test('makeInstanceAdminStorage', async t => { }); // @ts-ignore instance is mocked - t.throws(() => getPublicFacet(mockInstance2), { + await t.throwsAsync(() => getPublicFacet(mockInstance2), { message: '"instance" not found: "[Alleged: mockInstance2]"', }); }); test('add another instance admin for same instance', async t => { - const { initInstanceAdmin } = makeInstanceAdminStorage(); + const chargeZoeFee = () => {}; + const { initInstanceAdmin } = makeInstanceAdminStorage(chargeZoeFee); const mockInstance1 = Far('mockInstance1', {}); const mockInstanceAdmin1 = Far('mockInstanceAdmin1', {}); diff --git a/packages/zoe/tools/fakeVatAdmin.js b/packages/zoe/tools/fakeVatAdmin.js index 311738c8a2e..04c1127a316 100644 --- a/packages/zoe/tools/fakeVatAdmin.js +++ b/packages/zoe/tools/fakeVatAdmin.js @@ -3,6 +3,7 @@ import { E } from '@agoric/eventual-send'; import { makePromiseKit } from '@agoric/promise-kit'; import { Far } from '@agoric/marshal'; +import { makeNotifierKit } from '@agoric/notifier'; import { assert, details as X } from '@agoric/assert'; import { evalContractBundle } from '../src/contractFacet/evalContractCode.js'; @@ -31,8 +32,14 @@ function makeFakeVatAdmin(testContextSetter = undefined, makeRemote = x => x) { // test-only state can be provided from contracts // to their tests. const admin = Far('vatAdmin', { - createMeter: () => {}, - createUnlimitedMeter: () => {}, + createMeter: () => { + const notifierKit = makeNotifierKit(); + return harden({ getNotifier: () => notifierKit.notifier }); + }, + createUnlimitedMeter: () => { + const notifierKit = makeNotifierKit(); + return harden({ getNotifier: () => notifierKit.notifier }); + }, createVat: bundle => { return harden({ root: makeRemote(