Skip to content

Commit

Permalink
fix(addAssetToVault): support issuerName separate from keyword Agoric…
Browse files Browse the repository at this point in the history
  • Loading branch information
0xpatrickdev committed Aug 22, 2023
1 parent 59581aa commit 90e8ce1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 20 deletions.
51 changes: 31 additions & 20 deletions packages/inter-protocol/src/proposals/addAssetToVault.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ export * from './startPSM.js';
* @property {string} [issuerBoardId]
* @property {string} [denom]
* @property {number} [decimalPlaces]
* @property {string} [proposedName]
* @property {string} proposedName
* @property {string} keyword
* @property {string} [issuerName]
* @property {string} oracleBrand
* @property {number} [initialPrice]
*/
Expand All @@ -32,18 +33,22 @@ export const publishInterchainAssetFromBoardId = async (
{ consume: { board, agoricNamesAdmin } },
{ options: { interchainAssetOptions } },
) => {
const { issuerBoardId, keyword } = interchainAssetOptions;
const {
issuerBoardId,
keyword,
issuerName = keyword,
} = interchainAssetOptions;
// Incompatible with denom.
assert.equal(interchainAssetOptions.denom, undefined);
assert.typeof(issuerBoardId, 'string');
assert.typeof(keyword, 'string');
assert.typeof(issuerName, 'string');

const issuer = await E(board).getValue(issuerBoardId);
const brand = await E(issuer).getBrand();

return Promise.all([
E(E(agoricNamesAdmin).lookupAdmin('issuer')).update(keyword, issuer),
E(E(agoricNamesAdmin).lookupAdmin('brand')).update(keyword, brand),
E(E(agoricNamesAdmin).lookupAdmin('issuer')).update(issuerName, issuer),
E(E(agoricNamesAdmin).lookupAdmin('brand')).update(issuerName, brand),
]);
};

Expand All @@ -62,18 +67,23 @@ export const publishInterchainAssetFromBank = async (
},
{ options: { interchainAssetOptions } },
) => {
const { denom, decimalPlaces, proposedName, keyword } =
interchainAssetOptions;
const {
denom,
decimalPlaces,
keyword,
issuerName = keyword,
proposedName,
} = interchainAssetOptions;

// Incompatible with issuerBoardId.
assert.equal(interchainAssetOptions.issuerBoardId, undefined);
assert.typeof(denom, 'string');
assert.typeof(keyword, 'string');
assert.typeof(decimalPlaces, 'number');
assert.typeof(issuerName, 'string');
assert.typeof(proposedName, 'string');
assert.typeof(decimalPlaces, 'number');

const terms = {
keyword,
keyword: issuerName, // "keyword" is a misnomer in mintHolder terms
assetKind: AssetKind.NAT,
displayInfo: {
decimalPlaces,
Expand All @@ -83,7 +93,7 @@ export const publishInterchainAssetFromBank = async (

const { creatorFacet: mint, publicFacet: issuer } = await E(startUpgradable)({
installation: mintHolder,
label: keyword,
label: issuerName,
privateArgs: undefined,
terms,
});
Expand All @@ -94,9 +104,9 @@ export const publishInterchainAssetFromBank = async (
await E(E.get(reserveKit).creatorFacet).addIssuer(issuer, keyword);

await Promise.all([
E(E(agoricNamesAdmin).lookupAdmin('issuer')).update(keyword, issuer),
E(E(agoricNamesAdmin).lookupAdmin('brand')).update(keyword, brand),
E(bankManager).addAsset(denom, keyword, proposedName, kit),
E(E(agoricNamesAdmin).lookupAdmin('issuer')).update(issuerName, issuer),
E(E(agoricNamesAdmin).lookupAdmin('brand')).update(issuerName, brand),
E(bankManager).addAsset(denom, issuerName, proposedName, kit),
]);
};

Expand All @@ -118,11 +128,12 @@ export const registerScaledPriceAuthority = async (
{ options: { interchainAssetOptions } },
) => {
const {
keyword,
keyword: kwd,
issuerName = kwd,
oracleBrand,
initialPrice: initialPriceRaw,
} = interchainAssetOptions;
assert.typeof(keyword, 'string');
assert.typeof(issuerName, 'string');
assert.typeof(oracleBrand, 'string');

const [
Expand All @@ -133,7 +144,7 @@ export const registerScaledPriceAuthority = async (
] = await Promise.all([
priceAuthority,
reserveThenGetNames(E(agoricNamesAdmin).lookupAdmin('brand'), [
keyword,
issuerName,
'IST',
]),
reserveThenGetNames(E(agoricNamesAdmin).lookupAdmin('oracleBrand'), [
Expand Down Expand Up @@ -191,7 +202,7 @@ export const registerScaledPriceAuthority = async (

const spaKit = await E(startUpgradable)({
installation: scaledPriceAuthority,
label: `scaledPriceAuthority-${keyword}`,
label: `scaledPriceAuthority-${issuerName}`,
terms,
});

Expand Down Expand Up @@ -233,8 +244,8 @@ export const addAssetToVault = async (
},
},
) => {
const { keyword, oracleBrand } = interchainAssetOptions;
assert.typeof(keyword, 'string');
const { keyword, issuerName = keyword, oracleBrand } = interchainAssetOptions;
assert.typeof(issuerName, 'string');
assert.typeof(oracleBrand, 'string');
const [interchainIssuer] = await reserveThenGetNames(
E(agoricNamesAdmin).lookupAdmin('issuer'),
Expand Down
1 change: 1 addition & 0 deletions packages/vats/src/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const agoricNamesReserved = harden({
psm: 'Parity Stability Module',
econCommitteeCharter: 'Charter for Econ Governance questions',
priceAggregator: 'simple price aggregator',
scaledPriceAuthority: 'scaled price authority',
},
instance: {
economicCommittee: 'Economic Committee',
Expand Down
2 changes: 2 additions & 0 deletions packages/vats/src/mintHolder.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
/** @typedef {import('@agoric/vat-data').Baggage} Baggage */

/**
* NOTE: "keyword" connotes initial caps constraint, which doesn't apply here.
*
* @template {AssetKind} K
* @typedef {{
* keyword: string;
Expand Down

0 comments on commit 90e8ce1

Please sign in to comment.