From 38edd994af3b03ad5d77d73c4007f758d30ed203 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 | 60 ++++++++++++------- 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/packages/inter-protocol/src/proposals/addAssetToVault.js b/packages/inter-protocol/src/proposals/addAssetToVault.js index 3b632b27f92e..83426acd815f 100644 --- a/packages/inter-protocol/src/proposals/addAssetToVault.js +++ b/packages/inter-protocol/src/proposals/addAssetToVault.js @@ -18,7 +18,8 @@ export * from './startPSM.js'; * @property {number} [decimalPlaces] * @property {string} [proposedName] * @property {string} keyword - * @property {string} oracleBrand + * @property {string} [issuerName] + * @property {string} [oracleBrand] * @property {number} [initialPrice] */ @@ -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), ]); }; @@ -62,18 +67,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'); + assert.typeof(decimalPlaces, 'number'); const terms = { - keyword, + keyword: issuerName, // "keyword" is a misnomer in mintHolder terms assetKind: AssetKind.NAT, displayInfo: { decimalPlaces, @@ -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, }); @@ -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), ]); }; @@ -118,11 +128,12 @@ export const registerScaledPriceAuthority = async ( { options: { interchainAssetOptions } }, ) => { const { - keyword, - oracleBrand, + keyword: kwd, + issuerName = kwd, + oracleBrand = issuerName, initialPrice: initialPriceRaw, } = interchainAssetOptions; - assert.typeof(keyword, 'string'); + assert.typeof(issuerName, 'string'); assert.typeof(oracleBrand, 'string'); const [ @@ -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'), [ @@ -191,7 +202,7 @@ export const registerScaledPriceAuthority = async ( const spaKit = await E(startUpgradable)({ installation: scaledPriceAuthority, - label: `scaledPriceAuthority-${keyword}`, + label: `scaledPriceAuthority-${issuerName}`, terms, }); @@ -233,12 +244,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 +264,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.