Skip to content

Commit

Permalink
Merge pull request #4745 from Agoric/dc-bld-vat
Browse files Browse the repository at this point in the history
feat(vats): move BLD mint, issuer to its own vat (DRAFT)
  • Loading branch information
mergify[bot] authored Mar 6, 2022
2 parents 48ff086 + 0acce28 commit 748616f
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 25 deletions.
1 change: 1 addition & 0 deletions packages/run-protocol/scripts/build-bundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ async function main() {
`${bundlesDir}/bundle-vaultFactory.js`,
],
[`${srcDir}/centralSupply.js`, `${bundlesDir}/bundle-centralSupply.js`],
[`${srcDir}/mintHolder.js`, `${bundlesDir}/bundle-mintHolder.js`],
[
`${srcDir}/vaultFactory/liquidateMinimum.js`,
`${bundlesDir}/bundle-liquidateMinimum.js`,
Expand Down
4 changes: 2 additions & 2 deletions packages/run-protocol/src/importedBundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import liquidateBundle from '../bundles/bundle-liquidateMinimum.js';
import ammBundle from '../bundles/bundle-amm.js';
import vaultFactoryBundle from '../bundles/bundle-vaultFactory.js';
import centralSupplyBundle from '../bundles/bundle-centralSupply.js';
import mintHolderBundle from '../bundles/bundle-mintHolder.js';

/** @type { Record<string, { moduleFormat: string }>} */
export const governanceBundles = {
contractGovernor: contractGovernorBundle,
committee: committeeBundle,
Expand All @@ -17,12 +17,12 @@ export const governanceBundles = {
};
harden(governanceBundles);

/** @type { Record<string, { moduleFormat: string }>} */
export const economyBundles = {
liquidate: liquidateBundle,
amm: ammBundle,
VaultFactory: vaultFactoryBundle,
centralSupply: centralSupplyBundle,
mintHolder: mintHolderBundle,
};
harden(economyBundles);

Expand Down
30 changes: 30 additions & 0 deletions packages/run-protocol/src/mintHolder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// @ts-check
// @jessie-check

import { makeIssuerKit } from '@agoric/ertp';

/**
* This contract holds one mint; it basically wraps
* makeIssuerKit in its own contract, and hence in
* its own vat.
*
* @param {ContractFacet} zcf
* @returns {{ publicFacet: Issuer, creatorFacet: Mint }}
*
* @typedef {{
* keyword: string,
* assetKind: AssetKind,
* displayInfo: DisplayInfo,
* }} CustomTerms
*/
export const start = zcf => {
const { keyword, assetKind, displayInfo } = zcf.getTerms();

const { mint, issuer } = makeIssuerKit(keyword, assetKind, displayInfo);

return {
publicFacet: issuer,
creatorFacet: mint,
};
};
harden(start);
25 changes: 18 additions & 7 deletions packages/vats/src/core/basic-behaviors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-check
import { E, Far } from '@endo/far';
import { AssetKind, makeIssuerKit } from '@agoric/ertp';
import { AssetKind } from '@agoric/ertp';

import { Nat } from '@agoric/nat';
import { makeNameHubKit } from '../nameHub.js';
Expand Down Expand Up @@ -219,7 +219,7 @@ harden(mintInitialSupply);
* }} powers
*/
export const addBankAssets = async ({
consume: { initialSupply, bridgeManager, loadVat, zoe },
consume: { initialSupply, bridgeManager, loadVat, zoe, mintHolderBundle },
produce: { bankManager, bldIssuerKit },
issuer: { produce: produceIssuer },
brand: { produce: produceBrand },
Expand All @@ -231,11 +231,22 @@ export const addBankAssets = async ({
]);
const runKit = { issuer: runIssuer, brand: runBrand, payment };

const bldKit = makeIssuerKit(
Tokens.BLD.name,
AssetKind.NAT,
Tokens.BLD.displayInfo,
); // TODO(#4578): move BLD issuerKit to its own vat
const bundle = await mintHolderBundle;

/** @type {{ creatorFacet: ERef<Mint>, publicFacet: ERef<Issuer> }} */
const { creatorFacet: bldMint, publicFacet: bldIssuer } = E.get(
E(zoe).startInstance(
E(zoe).install(bundle),
harden({}),
harden({
keyword: Tokens.BLD.name,
assetKind: AssetKind.NAT,
displayInfo: Tokens.BLD.displayInfo,
}),
),
);
const bldBrand = await E(bldIssuer).getBrand();
const bldKit = { mint: bldMint, issuer: bldIssuer, brand: bldBrand };
bldIssuerKit.resolve(bldKit);

const bankMgr = E(E(loadVat)('bank')).makeBankManager(bridgeManager);
Expand Down
8 changes: 7 additions & 1 deletion packages/vats/src/core/chain-behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,17 @@ export const connectChainFaucet = async ({ consume: { client } }) => {
};
harden(connectChainFaucet);

// XXX: move shareBootContractBundles belongs in basic-behaviors.js
/** @param {BootstrapPowers} powers */
export const shareBootContractBundles = async ({
produce: { centralSupplyBundle: centralP, pegasusBundle: pegasusP },
produce: {
centralSupplyBundle: centralP,
pegasusBundle: pegasusP,
mintHolderBundle,
},
}) => {
centralP.resolve(economyBundles.centralSupply);
mintHolderBundle.resolve(economyBundles.mintHolder);
pegasusP.resolve(pegasusBundle);
};

Expand Down
12 changes: 9 additions & 3 deletions packages/vats/src/core/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ const SHARED_BOOTSTRAP_MANIFEST = harden({
home: { produce: { bank: 'bank' } },
},
shareBootContractBundles: {
produce: { centralSupplyBundle: true, pegasusBundle: true },
produce: {
centralSupplyBundle: true,
mintHolderBundle: true,
pegasusBundle: true,
},
},
mintInitialSupply: {
vatParameters: {
Expand All @@ -94,13 +98,14 @@ const SHARED_BOOTSTRAP_MANIFEST = harden({
// TODO: re-org loadVat to be subject to permits
loadVat: true,
zoe: true,
mintHolderBundle: true,
},
produce: {
bankManager: 'bank',
bldIssuerKit: true,
},
issuer: { produce: { BLD: true, RUN: 'zoe' } },
brand: { produce: { BLD: true, RUN: 'zoe' } },
issuer: { produce: { BLD: 'BLD', RUN: 'zoe' } },
brand: { produce: { BLD: 'BLD', RUN: 'zoe' } },
},
makeProvisioner: {
consume: {
Expand Down Expand Up @@ -365,6 +370,7 @@ export const SIM_CHAIN_POST_BOOT_MANIFEST = harden({
fundAMM: {
consume: {
centralSupplyBundle: true,
mintHolderBundle: true,
chainTimerService: 'timer',
bldIssuerKit: true,
feeMintAccess: true,
Expand Down
9 changes: 6 additions & 3 deletions packages/vats/src/core/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
*/

/**
* @typedef {{ resolve: (v: T) => void }} Producer<T>
* @typedef {{ resolve: (v: ERef<T>) => void }} Producer<T>
* @template T
*/
/**
Expand Down Expand Up @@ -174,6 +174,7 @@
* ammBundle: ERef<SourceBundle>,
* vaultBundles: ERef<Record<string, SourceBundle>>,
* centralSupplyBundle: ERef<SourceBundle>,
* mintHolderBundle: ERef<SourceBundle>,
* feeMintAccess: ERef<FeeMintAccess>,
* governanceBundles: ERef<Record<string, SourceBundle>>,
* initialSupply: ERef<Payment>,
Expand All @@ -199,6 +200,7 @@
* governanceBundles: Producer<Record<string, SourceBundle>>,
* initialSupply: Producer<Payment>,
* centralSupplyBundle: Producer<SourceBundle>,
* mintHolderBundle: Producer<SourceBundle>,
* feeMintAccess: Producer<FeeMintAccess>,
* priceAuthorityVat: Producer<PriceAuthorityVat>,
* priceAuthority: Producer<PriceAuthority>,
Expand Down Expand Up @@ -237,7 +239,7 @@
* consume: EconomyBootstrapPowers['consume'] & {
* bankManager: BankManager,
* board: ERef<Board>,
* bldIssuerKit: ERef<IssuerKit>,
* bldIssuerKit: ERef<RemoteIssuerKit>,
* bridgeManager: ERef<OptionalBridgeManager>,
* client: ERef<ClientManager>,
* clientCreator: ERef<ClientCreator>,
Expand All @@ -249,7 +251,7 @@
* },
* produce: EconomyBootstrapPowers['produce'] & {
* bankManager: Producer<BankManager>,
* bldIssuerKit: Producer<IssuerKit>,
* bldIssuerKit: Producer<RemoteIssuerKit>,
* board: Producer<ERef<Board>>,
* bridgeManager: Producer<OptionalBridgeManager>,
* client: Producer<ClientManager>,
Expand All @@ -262,6 +264,7 @@
* namesByAddressAdmin: Producer<NameAdmin>,
* },
* }} BootstrapSpace
* @typedef {{ mint: ERef<Mint>, issuer: ERef<Issuer>, brand: Brand }} RemoteIssuerKit
* @typedef {ReturnType<Awaited<BankVat>['makeBankManager']>} BankManager
* @typedef {ERef<ReturnType<import('../vat-bank.js').buildRootObject>>} BankVat
* @typedef {ERef<ReturnType<import('../vat-provisioning.js').buildRootObject>>} ProvisioningVat
Expand Down
12 changes: 7 additions & 5 deletions packages/vats/src/demoIssuers.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ const provideCoin = async (name, mints) => {
*
* TODO: sync this type with end-user docs?
* @typedef {{
* issuer: Issuer,
* issuer: ERef<Issuer>,
* issuerPetname: string,
* payment: Payment,
* brand: Brand,
Expand Down Expand Up @@ -395,7 +395,7 @@ export const ammPoolRunDeposits = issuers => {
/**
* @param {Payment} bootstrapPayment
* @param {Record<string, bigint>} balances
* @param {{ issuer: Issuer, brand: Brand }} central
* @param {{ issuer: ERef<Issuer>, brand: Brand }} central
*/
export const splitAllCentralPayments = async (
bootstrapPayment,
Expand Down Expand Up @@ -427,8 +427,8 @@ export const splitAllCentralPayments = async (
/**
* @param {string} issuerName
* @param {typeof AMMDemoState['ATOM']} record
* @param {Record<string, { issuer: Issuer, brand: Brand }>} kits
* @param {{ issuer: Issuer, brand: Brand }} central
* @param {Record<string, { issuer: ERef<Issuer>, brand: Brand }>} kits
* @param {{ issuer: ERef<Issuer>, brand: Brand }} central
*/
export const poolRates = (issuerName, record, kits, central) => {
/** @param { bigint } n */
Expand Down Expand Up @@ -557,6 +557,7 @@ export const fundAMM = async ({

assert(kit.issuer, `No issuer for ${issuerName}`);
const liquidityIssuer = E(ammPublicFacet).addPool(
// @ts-expect-error TODO: addPool should take ERef<Issuer>
kit.issuer,
issuerName,
);
Expand All @@ -581,8 +582,9 @@ export const fundAMM = async ({
}),
);

const issuerPresence = await kit.issuer;
return E(vaultFactoryCreator).addVaultType(
kit.issuer,
issuerPresence,
issuerName,
rates,
);
Expand Down
6 changes: 3 additions & 3 deletions packages/vats/src/vat-bank.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ const makePurseController = (

/**
* @typedef {Object} AssetIssuerKit
* @property {Mint} [mint]
* @property {Issuer} issuer
* @property {ERef<Mint>} [mint]
* @property {ERef<Issuer>} issuer
* @property {Brand} brand
*/

Expand All @@ -88,7 +88,7 @@ const makePurseController = (
/**
* @typedef {Object} AssetDescriptor
* @property {Brand} brand
* @property {Issuer} issuer
* @property {ERef<Issuer>} issuer
* @property {string} issuerName
* @property {string} denom
* @property {string} proposedName
Expand Down
1 change: 1 addition & 0 deletions packages/vats/test/test-clientBundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ test('connectFaucet produces payments', async t => {
produce.bldIssuerKit.resolve(bldKit);
const runIssuer = E(zoe).getFeeIssuer();
produce.bankManager.resolve(
// @ts-ignore never mind other methods
Promise.resolve(
// @ts-ignore never mind other methods
Far('mockBankManager', {
Expand Down
3 changes: 2 additions & 1 deletion packages/vats/test/test-vat-bank.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ test('communication', async t => {
message: /"brand" not found/,
});

/** @type {undefined | IteratorResult<{brand: Brand, issuer: Issuer, proposedName: string}>} */
/** @type {undefined | IteratorResult<{brand: Brand, issuer: ERef<Issuer>, proposedName: string}>} */
let itResult;
const p = it.next().then(r => (itResult = r));
t.is(itResult, undefined);
Expand Down Expand Up @@ -206,6 +206,7 @@ test('mintInitialSupply, addBankAssets bootstrap actions', async t => {
produce.agoricNames.resolve(agoricNames);

produce.centralSupplyBundle.resolve(economyBundles.centralSupply);
produce.mintHolderBundle.resolve(economyBundles.mintHolder);

const { zoeService, feeMintAccess } = makeZoeKit(
makeFakeVatAdmin(() => {}).admin,
Expand Down

0 comments on commit 748616f

Please sign in to comment.