From a67061691e1bf845ef9fd16e33c265bdbd944554 Mon Sep 17 00:00:00 2001 From: Dan Connolly Date: Mon, 21 Aug 2023 17:45:02 -0500 Subject: [PATCH] fix(addAssetToVault): support issuerName separate from keyword - default proposedName to issuerName The type for proposedName is optional but there was a runtime typecheck for string. - default oracleBrand to issuerName --- .../src/proposals/addAssetToVault.js | 61 ++++++++++++------- 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/packages/inter-protocol/src/proposals/addAssetToVault.js b/packages/inter-protocol/src/proposals/addAssetToVault.js index cbe39b02ff3..3f15fc73dba 100644 --- a/packages/inter-protocol/src/proposals/addAssetToVault.js +++ b/packages/inter-protocol/src/proposals/addAssetToVault.js @@ -16,9 +16,11 @@ export * from './startPSM.js'; * @property {string} [issuerBoardId] * @property {string} [denom] * @property {number} [decimalPlaces] - * @property {string} [proposedName] - * @property {string} keyword - * @property {string} oracleBrand + * @property {string} keyword - used in regstering with reserve, vaultFactory + * @property {string} [issuerName] - used in agoricNames for compatibility: + * defaults to `keyword` if not provided + * @property {string} [proposedName] - defaults to `issuerName` if not provided + * @property {string} [oracleBrand] - defaults to `issuerName` if not provided * @property {number} [initialPrice] */ @@ -32,18 +34,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), ]); }; @@ -62,18 +68,23 @@ export const publishInterchainAssetFromBank = async ( }, { options: { interchainAssetOptions } }, ) => { - const { denom, decimalPlaces, proposedName, keyword } = - interchainAssetOptions; + const { + denom, + decimalPlaces, + keyword, + issuerName = keyword, + proposedName = keyword, + } = 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'); const terms = { - keyword, + keyword: issuerName, // "keyword" is a misnomer in mintHolder terms assetKind: AssetKind.NAT, displayInfo: { decimalPlaces, @@ -83,7 +94,7 @@ export const publishInterchainAssetFromBank = async ( const { creatorFacet: mint, publicFacet: issuer } = await E(startUpgradable)({ installation: mintHolder, - label: keyword, + label: issuerName, privateArgs: undefined, terms, }); @@ -94,9 +105,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), ]); }; @@ -119,10 +130,11 @@ export const registerScaledPriceAuthority = async ( ) => { const { keyword, - oracleBrand, + issuerName = keyword, + oracleBrand = issuerName, initialPrice: initialPriceRaw, } = interchainAssetOptions; - assert.typeof(keyword, 'string'); + assert.typeof(issuerName, 'string'); assert.typeof(oracleBrand, 'string'); const [ @@ -133,7 +145,7 @@ export const registerScaledPriceAuthority = async ( ] = await Promise.all([ priceAuthority, reserveThenGetNames(E(agoricNamesAdmin).lookupAdmin('brand'), [ - keyword, + issuerName, 'IST', ]), reserveThenGetNames(E(agoricNamesAdmin).lookupAdmin('oracleBrand'), [ @@ -191,7 +203,7 @@ export const registerScaledPriceAuthority = async ( const spaKit = await E(startUpgradable)({ installation: scaledPriceAuthority, - label: `scaledPriceAuthority-${keyword}`, + label: `scaledPriceAuthority-${issuerName}`, terms, }); @@ -233,12 +245,17 @@ export const addAssetToVault = async ( }, }, ) => { - const { keyword, oracleBrand } = interchainAssetOptions; + const { + keyword, + issuerName = keyword, + oracleBrand = issuerName, + } = interchainAssetOptions; assert.typeof(keyword, 'string'); + assert.typeof(issuerName, 'string'); assert.typeof(oracleBrand, 'string'); const [interchainIssuer] = await reserveThenGetNames( E(agoricNamesAdmin).lookupAdmin('issuer'), - [keyword], + [issuerName], ); const oracleInstanceName = instanceNameFor(oracleBrand, 'USD'); @@ -248,7 +265,7 @@ export const addAssetToVault = async ( const stable = await stableP; const vaultFactoryCreator = E.get(vaultFactoryKit).creatorFacet; - await E(vaultFactoryCreator).addVaultType(interchainIssuer, oracleBrand, { + await E(vaultFactoryCreator).addVaultType(interchainIssuer, keyword, { debtLimit: AmountMath.make(stable, BigInt(debtLimitValue)), interestRate: makeRatio(interestRateValue, stable), // The rest of these we use safe defaults.