Skip to content

Commit

Permalink
feat(vats): publish vbank asset list with agoricNames (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc committed Dec 22, 2022
1 parent edfc628 commit b8ad33f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
13 changes: 12 additions & 1 deletion packages/vats/src/core/basic-behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,13 @@ harden(mintInitialSupply);
* }} powers
*/
export const addBankAssets = async ({
consume: { initialSupply, bridgeManager, loadCriticalVat, zoe },
consume: {
agoricNamesAdmin,
initialSupply,
bridgeManager,
loadCriticalVat,
zoe,
},
produce: { bankManager, bldIssuerKit },
installation: {
consume: { mintHolder },
Expand Down Expand Up @@ -384,8 +390,13 @@ export const addBankAssets = async ({
const bldKit = { mint: bldMint, issuer: bldIssuer, brand: bldBrand };
bldIssuerKit.resolve(bldKit);

const assetAdmin = E(agoricNamesAdmin).lookupAdmin('vbankAsset');
const nameUpdater = Far('AssetHub', {
update: (name, val) => E(assetAdmin).update(name, val),
});
const bankMgr = await E(E(loadCriticalVat)('bank')).makeBankManager(
bridgeManager,
nameUpdater,
);
bankManager.resolve(bankMgr);

Expand Down
1 change: 1 addition & 0 deletions packages/vats/src/core/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ const SHARED_CHAIN_BOOTSTRAP_MANIFEST = harden({
},
[addBankAssets.name]: {
consume: {
agoricNamesAdmin: true,
initialSupply: true,
bridgeManager: true,
// TODO: re-org loadCriticalVat to be subject to permits
Expand Down
38 changes: 37 additions & 1 deletion packages/vats/src/vat-bank.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ const makePurseController = (
* @property {string} proposedName
*/

/**
* @typedef { AssetDescriptor & {
* issuer: Issuer<'nat'>, // settled identity
* displayInfo: DisplayInfo,
* }} AssetInfo
*/

/**
* @typedef {object} Bank
* @property {() => Subscription<AssetDescriptor>} getAssetSubscription Returns
Expand All @@ -108,8 +115,13 @@ export function buildRootObject() {
* @param {ERef<import('./types.js').BridgeManager | undefined>} [bankBridgeManagerP] a bridge
* manager for the "remote" bank (such as on cosmos-sdk). If not supplied
* (such as on sim-chain), we just use local purses.
* @param {ERef<{ update: import('./types.js').NameAdmin['update'] }>} [nameAdmin] update facet of
* a NameHub; see addAsset for detail.
*/
async makeBankManager(bankBridgeManagerP = undefined) {
async makeBankManager(
bankBridgeManagerP = undefined,
nameAdmin = undefined,
) {
const bankBridgeManager = await bankBridgeManagerP;
/** @type {WeakStore<Brand, AssetRecord>} */
const brandToAssetRecord = makeWeakStore('brand');
Expand Down Expand Up @@ -319,6 +331,10 @@ export function buildRootObject() {

/**
* Add an asset to the bank, and publish it to the subscriptions.
* If nameAdmin is defined, update with denom to AssetInfo entry.
*
* Note that AssetInfo has the settled identity of the issuer,
* not just a promise for it.
*
* @param {string} denom lower-level denomination string
* @param {string} issuerName
Expand Down Expand Up @@ -361,6 +377,26 @@ export function buildRootObject() {
proposedName,
}),
);

if (nameAdmin) {
// publish settled issuer identity
void Promise.all([kit.issuer, E(kit.brand).getDisplayInfo()]).then(
([issuer, displayInfo]) =>
E(nameAdmin).update(
denom,
/** @type { AssetInfo } */ (
harden({
brand,
issuer,
issuerName,
denom,
proposedName,
displayInfo,
})
),
),
);
}
},
getBankForAddress,
});
Expand Down

0 comments on commit b8ad33f

Please sign in to comment.