Skip to content

Commit

Permalink
Merge pull request #5701 from Agoric/5356-smart-wallet-contract
Browse files Browse the repository at this point in the history
feat: contract for single smart wallet
  • Loading branch information
mergify[bot] authored Jul 6, 2022
2 parents 45cd0ee + 80f642b commit d07a502
Show file tree
Hide file tree
Showing 32 changed files with 624 additions and 107 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test-all-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ jobs:
run: cd packages/assert && yarn ${{ steps.vars.outputs.test }}
- name: yarn test (wallet/api)
run: cd packages/wallet/api && yarn ${{ steps.vars.outputs.test }}
- name: yarn test (wallet/contract)
run: cd packages/wallet/contract && yarn ${{ steps.vars.outputs.test }}
- name: yarn test (deployment)
run: cd packages/deployment && yarn ${{ steps.vars.outputs.test }}
- name: yarn test (ERTP)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"golang/cosmos",
"packages/*",
"packages/wallet/api",
"packages/wallet/contract",
"packages/wallet/ui"
],
"type": "module",
Expand Down
1 change: 1 addition & 0 deletions packages/agoric-cli/src/sdk-package-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default [
"@agoric/run-protocol",
"@agoric/same-structure",
"@agoric/sharing-service",
"@agoric/smart-wallet",
"@agoric/solo",
"@agoric/sparse-ints",
"@agoric/spawner",
Expand Down
4 changes: 4 additions & 0 deletions packages/casting/src/follower-cosmjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ export const makeCosmjsFollower = (
const getProvenValue = () => getProvenValueAtHeight(allegedBlockHeight);

const buf = await queryVerifier(getProvenValue, crash, getAllegedValue);
if (buf.length === 0) {
fail(Error('No query results'));
return;
}
attempt = 0;
if (!committer.isValid()) {
return;
Expand Down
5 changes: 4 additions & 1 deletion packages/deploy-script-support/src/depositInvitation.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import { E } from '@endo/far';

/** @type {MakeDepositInvitation} */
/**
* @param {ERef<Purse>} zoeInvitationPurse
* @returns {DepositInvitation}
*/
export const makeDepositInvitation = zoeInvitationPurse => {
/** @type {DepositInvitation} */
const depositInvitation = async invitationP => {
Expand Down
10 changes: 8 additions & 2 deletions packages/deploy-script-support/src/install.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
// @ts-check

import './externalTypes.js';
import './internalTypes.js';

import { E } from '@endo/far';

/** @type {MakeInstallSaveAndPublish} */
// XXX board is Board but specifying that leads to type errors with imports which aren't worth fixing right now
/**
* @param {BundleSource} bundleSource
* @param {ERef<ZoeService>} zoe
* @param {ERef<import('./startInstance.js').InstallationManager>} installationManager
* @param {ERef<any>} board
* @returns {InstallSaveAndPublish}
*/
export const makeInstall = (bundleSource, zoe, installationManager, board) => {
/** @type {InstallSaveAndPublish} */
const install = async (resolvedPath, contractPetname) => {
Expand Down
33 changes: 0 additions & 33 deletions packages/deploy-script-support/src/internalTypes.js

This file was deleted.

8 changes: 7 additions & 1 deletion packages/deploy-script-support/src/offer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import { E } from '@endo/far';
import { assert } from '@agoric/assert';
import { AmountMath } from '@agoric/ertp';

/** @type {MakeOfferAndFindInvitationAmount} */
/**
* @param {ERef<any>} walletAdmin - an internal type of the
* wallet, not defined here
* @param {ERef<ZoeService>} zoe
* @param {ERef<Purse>} zoeInvitationPurse
* @returns {{ offer: OfferHelper, findInvitationAmount: FindInvitationAmount }}
*/
export const makeOfferAndFindInvitationAmount = (
walletAdmin,
zoe,
Expand Down
7 changes: 6 additions & 1 deletion packages/deploy-script-support/src/saveIssuer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

import { E } from '@endo/far';

/** @type {MakeSaveIssuerHelper} */
/**
* @param {ERef<any>} walletAdmin - an internal type of the
* wallet, not defined here
* @param {ERef<import('./startInstance').IssuerManager>} issuerManager
* @returns {SaveIssuerHelper}
*/
export const makeSaveIssuer = (walletAdmin, issuerManager) => {
/** @type {SaveIssuerHelper} */
const saveIssuer = async (issuerP, brandPetname, pursePetname) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ test('install', async t => {

let addedInstallation;

/** @type {import('../../src/startInstance.js').InstallationManager} */
// @ts-expect-error mock
const installationManager = {
add: (_petname, installation) => (addedInstallation = installation),
add: (_petname, installation) => {
addedInstallation = installation;
return Promise.resolve();
},
};

const board = makeBoard();
Expand Down
41 changes: 16 additions & 25 deletions packages/run-protocol/src/proposals/econ-behaviors.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
// @ts-check

import { E, Far } from '@endo/far';
import { makeRatio } from '@agoric/zoe/src/contractSupport/index.js';
import { CENTRAL_ISSUER_NAME } from '@agoric/vats/src/core/utils.js';
import '../../exported.js';

import { AmountMath } from '@agoric/ertp';
import '@agoric/governance/exported.js';
import '@agoric/vats/exported.js';
import '@agoric/vats/src/core/types.js';

import { AmountMath } from '@agoric/ertp';
import { makeGovernedTerms } from '../vaultFactory/params.js';
import { makeAmmTerms } from '../vpool-xyk-amm/params.js';
import { makeReserveTerms } from '../reserve/params.js';

import '../../exported.js';

import { CENTRAL_ISSUER_NAME } from '@agoric/vats/src/core/utils.js';
import { getChildNode } from '@agoric/vats/src/lib-chainStorage.js';
import { makeRatio } from '@agoric/zoe/src/contractSupport/index.js';
import { E, Far } from '@endo/far';
import * as Collect from '../collect.js';
import { makeTracer } from '../makeTracer.js';
import { makeStakeReporter } from '../my-lien.js';
import { makeReserveTerms } from '../reserve/params.js';
import { makeRunStakeTerms } from '../runStake/params.js';
import { liquidationDetailTerms } from '../vaultFactory/liquidation.js';
import { makeStakeReporter } from '../my-lien.js';
import { makeTracer } from '../makeTracer.js';
import { makeGovernedTerms } from '../vaultFactory/params.js';
import { makeAmmTerms } from '../vpool-xyk-amm/params.js';

const trace = makeTracer('RunEconBehaviors', false);

Expand Down Expand Up @@ -216,9 +215,7 @@ export const setupAmm = async (
AmountMath.make(runBrand, minInitialPoolLiquidity),
);

const chainStoragePresence = await chainStorage;
const storageNode = await (chainStoragePresence &&
E(chainStoragePresence).getChildNode(AMM_STORAGE_PATH));
const storageNode = await getChildNode(chainStorage, AMM_STORAGE_PATH);
const marshaller = await E(board).getPublishingMarshaller();

const ammGovernorTerms = {
Expand Down Expand Up @@ -312,9 +309,7 @@ export const setupReserve = async ({

const feeMintAccess = await feeMintAccessP;

const chainStoragePresence = await chainStorage;
const storageNode = await (chainStoragePresence &&
E(chainStoragePresence).getChildNode(STORAGE_PATH));
const storageNode = await getChildNode(chainStorage, STORAGE_PATH);
const marshaller = E(board).getReadonlyMarshaller();

const reserveGovernorTerms = {
Expand Down Expand Up @@ -444,9 +439,7 @@ export const startVaultFactory = async (
const reservePublicFacet = await E(zoe).getPublicFacet(reserveInstance);
const timer = await chainTimerService;

const chainStoragePresence = await chainStorage;
const storageNode = await (chainStoragePresence &&
E(chainStoragePresence).getChildNode(STORAGE_PATH));
const storageNode = await getChildNode(chainStorage, STORAGE_PATH);
const marshaller = E(board).getReadonlyMarshaller();

const vaultFactoryTerms = makeGovernedTerms(
Expand Down Expand Up @@ -851,9 +844,7 @@ export const startRunStake = async (
},
);

const chainStoragePresence = await chainStorage;
const storageNode = await (chainStoragePresence &&
E(chainStoragePresence).getChildNode(STORAGE_PATH));
const storageNode = await getChildNode(chainStorage, STORAGE_PATH);
const marshaller = await E(board).getReadonlyMarshaller();

/** @type {{ publicFacet: GovernorPublic, creatorFacet: GovernedContractFacetAccess<unknown>}} */
Expand Down
7 changes: 3 additions & 4 deletions packages/run-protocol/src/proposals/startPSM.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// @ts-check
import { E } from '@endo/far';
import { AmountMath, AssetKind } from '@agoric/ertp';
import { CONTRACT_ELECTORATE, ParamTypes } from '@agoric/governance';
import { getChildNode } from '@agoric/vats/src/lib-chainStorage.js';
import { makeRatio } from '@agoric/zoe/src/contractSupport/index.js';
import { E } from '@endo/far';
import { reserveThenGetNamePaths } from './utils.js';

const BASIS_POINTS = 10000n;
Expand Down Expand Up @@ -107,9 +108,7 @@ export const startPSM = async (
},
};

const chainStoragePresence = await chainStorage;
const storageNode = await (chainStoragePresence &&
E(chainStoragePresence).getChildNode('psm'));
const storageNode = await getChildNode(chainStorage, 'psm');
const marshaller = E(board).getPublishingMarshaller();

const governorFacets = await E(zoe).startInstance(
Expand Down
2 changes: 1 addition & 1 deletion packages/run-protocol/src/proposals/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const reserveThenDeposit = async (
console.info('confirmed deposit for', debugName);
};

/** @type {<T>(store: any, key: string, make: () => T) => Promise<T>} */
/** @type {<T>(store: ERef<MapStore>, key: string, make: () => T) => Promise<T>} */
const provide = async (store, key, make) => {
const found = await E(store).get(key);
if (found) {
Expand Down
4 changes: 2 additions & 2 deletions packages/run-protocol/test/test-gov-collateral.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import centralSupplyBundle from '@agoric/vats/bundles/bundle-centralSupply.js';
import {
bridgeCoreEval,
makeClientManager,
setupClientManager,
} from '@agoric/vats/src/core/chain-behaviors.js';
import { extractCoreProposalBundles } from '@agoric/deploy-script-support/src/extract-proposal.js';
import { makeCoreProposalBehavior } from '@agoric/deploy-script-support/src/coreProposalBehavior.js';
Expand Down Expand Up @@ -169,7 +169,7 @@ const makeScenario = async (t, { env = process.env } = {}) => {
return Promise.all([
// @ts-expect-error TODO: align types better
addBankAssets(space),
makeClientManager(space),
setupClientManager(space),
makeAddressNameHubs(space),
// @ts-expect-error TODO: align types better
makeBoard(space),
Expand Down
6 changes: 3 additions & 3 deletions packages/vats/decentral-core-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@
"sharing": {
"sourceSpec": "@agoric/vats/src/vat-sharing.js"
},
"walletManager": {
"sourceSpec": "@agoric/vats/src/vat-walletManager.js"
"singleWallet": {
"sourceSpec": "@agoric/wallet/contract/src/singleWallet.js"
},
"zoe": {
"sourceSpec": "@agoric/vats/src/vat-zoe.js"
}
},
"defaultManagerType": "xs-worker"
}
}
6 changes: 3 additions & 3 deletions packages/vats/decentral-demo-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@
"sharing": {
"sourceSpec": "@agoric/vats/src/vat-sharing.js"
},
"walletManager": {
"sourceSpec": "@agoric/vats/src/vat-walletManager.js"
"singleWallet": {
"sourceSpec": "@agoric/wallet/contract/src/singleWallet.js"
},
"zoe": {
"sourceSpec": "@agoric/vats/src/vat-zoe.js"
}
},
"defaultManagerType": "xs-worker"
}
}
4 changes: 4 additions & 0 deletions packages/vats/scripts/build-bundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ const dirname = url.fileURLToPath(new URL('.', import.meta.url));
const sourceToBundle = [
[`../src/centralSupply.js`, `../bundles/bundle-centralSupply.js`],
[`../src/mintHolder.js`, `../bundles/bundle-mintHolder.js`],
[
`@agoric/wallet/contract/src/singleWallet.js`,
`../bundles/bundle-singleWallet.js`,
],
];

createBundles(sourceToBundle, dirname);
42 changes: 36 additions & 6 deletions packages/vats/src/core/basic-behaviors.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// @ts-check
import { E, Far } from '@endo/far';
import { AssetKind, makeIssuerKit } from '@agoric/ertp';

import { Nat } from '@agoric/nat';
import { makeScalarMapStore } from '@agoric/store';
import { provide } from '@agoric/store/src/stores/store-utils.js';
import { E, Far } from '@endo/far';
import { getChildNode } from '../lib-chainStorage.js';
import { makeNameHubKit } from '../nameHub.js';

import { feeIssuerConfig } from './utils.js';

const { details: X } = assert;
Expand Down Expand Up @@ -225,9 +224,39 @@ export const makeAddressNameHubs = async ({
harden(makeAddressNameHubs);

/** @param {BootstrapSpace} powers */
export const makeClientBanks = async ({ consume: { client, bankManager } }) => {
export const makeClientBanks = async ({
consume: {
agoricNames,
board,
namesByAddress,
namesByAddressAdmin,
client,
chainStorage,
bankManager,
zoe,
},
installation: {
consume: { singleWallet },
},
}) => {
const STORAGE_PATH = 'wallet';

const storageNode = await getChildNode(chainStorage, STORAGE_PATH);
const marshaller = E(board).getPublishingMarshaller();
return E(client).assignBundle([
address => ({ bank: E(bankManager).getBankForAddress(address) }),
address => {
const bank = E(bankManager).getBankForAddress(address);
const myAddressNameAdmin = E(namesByAddressAdmin).lookupAdmin(address);
const smartWallet = E(zoe).startInstance(
singleWallet,
{},
{ agoricNames, bank, namesByAddress, myAddressNameAdmin, board },
{ storageNode, marshaller },
);

// sets these values in REPL home by way of registerWallet
return { bank, smartWallet };
},
]);
};
harden(makeClientBanks);
Expand All @@ -238,12 +267,13 @@ export const installBootContracts = async ({
devices: { vatAdmin },
consume: { zoe },
installation: {
produce: { centralSupply, mintHolder },
produce: { centralSupply, mintHolder, singleWallet },
},
}) => {
for (const [name, producer] of Object.entries({
centralSupply,
mintHolder,
singleWallet,
})) {
const bundleCap = D(vatAdmin).getNamedBundleCap(name);
const bundle = D(bundleCap).getBundle();
Expand Down
Loading

0 comments on commit d07a502

Please sign in to comment.