Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

WIP: Charge fees and meter #3674

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/dapp-svelte-wallet/api/src/lib-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const cmp = (a, b) => {

/**
* @typedef {Object} MakeWalletParams
* @property {ZoeService} zoe
* @property {ERef<ZoeService>} zoe
* @property {Board} board
* @property {NameHub} [agoricNames]
* @property {NameHub} [namesByAddress]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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 => {};
Expand Down
32 changes: 20 additions & 12 deletions packages/dapp-svelte-wallet/api/test/test-lib-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
);
Expand All @@ -71,15 +73,15 @@ 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,
});
const {
publicFacet: autoswapPublicFacet,
instance: autoswapInstanceHandle,
} = await zoe.startInstance(
} = await E(zoe).startInstance(
autoswapInstallationHandle,
autoswapIssuerKeywordRecord,
);
Expand Down Expand Up @@ -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
Expand All @@ -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 = [];
Expand Down Expand Up @@ -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 => {};
Expand All @@ -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);
});
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
8 changes: 5 additions & 3 deletions packages/deploy-script-support/test/unitTests/test-offer.js
Original file line number Diff line number Diff line change
@@ -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 => {
Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
@@ -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 => {
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
});
}
10 changes: 6 additions & 4 deletions packages/governance/test/unitTests/test-committee.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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([
Expand 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(
Expand Down
36 changes: 24 additions & 12 deletions packages/pegasus/bundles/install-on-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import pegasusBundle from './bundle-pegasus.js';
* @param {NameHub} param0.namesByAddress
* @param {ERef<ZoeService>} 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 => {
Expand All @@ -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',
Expand All @@ -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);
Expand All @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions packages/pegasus/test/test-peg.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down
20 changes: 17 additions & 3 deletions packages/swingset-runner/demo/exchangeBenchmark/vat-zoe.js
Original file line number Diff line number Diff line change
@@ -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;
},
});
}
Loading