Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(addAssetToVault): support issuerName separate from keyword #8229

Merged
merged 4 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ export const defaultProposalBuilder = async (
const {
issuerBoardId = env.INTERCHAIN_ISSUER_BOARD_ID,
denom = env.INTERCHAIN_DENOM,
oracleBrand = 'ATOM',
decimalPlaces = 6,
keyword = 'ATOM',
proposedName = oracleBrand,
issuerName = keyword,
oracleBrand = issuerName,
decimalPlaces = 6,
proposedName = issuerName,
initialPrice = undefined,
} = interchainAssetOptions;

Expand All @@ -45,6 +46,7 @@ export const defaultProposalBuilder = async (
decimalPlaces,
initialPrice,
keyword,
issuerName,
proposedName,
oracleBrand,
},
Expand Down
61 changes: 39 additions & 22 deletions packages/inter-protocol/src/proposals/addAssetToVault.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
*/

Expand All @@ -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),
]);
};

Expand All @@ -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,
Expand All @@ -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,
});
Expand All @@ -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),
]);
};

Expand All @@ -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 [
Expand All @@ -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'), [
Expand Down Expand Up @@ -191,7 +203,7 @@ export const registerScaledPriceAuthority = async (

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

Expand Down Expand Up @@ -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');
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions packages/vats/src/core/types-ambient.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ type WellKnownName = {
| 'Pegasus'
| 'reserve'
| 'psm'
| 'scaledPriceAuthority'
| 'econCommitteeCharter'
| 'priceAggregator';
instance:
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider explaining why the imperfect name remains

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. I considered it, but I don't see a concise explanation.

Changing the name wouldn't require upgrading the existing contract vats. It would just require remembering that the old ones use a different name. It might even be possible to support a new name property and deprecate the keyword property.

I suppose the real reason the keyword name remains is: changing it isn't necessary to address #8235.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

require remembering that the old ones use a different name
That seems reason enough to me.

the keyword name remains is: changing it isn't necessary

Fair. Though with this PR that imperfect name is tech debt. We should at least document the rationale to take on the debt.

*
* @template {AssetKind} K
* @typedef {{
* keyword: string;
Expand Down
Loading