From 46aa80e1f8d8a73a8a7853ebcd937f5c2df64a42 Mon Sep 17 00:00:00 2001 From: Chris Hibbert Date: Wed, 28 Sep 2022 17:44:23 -0700 Subject: [PATCH] fix: make it possible to set decimalPlaces when calling startPSM (#6348) * fix: make it possible to set decimalPlaces when calling startPSM * fix: makeRatio wants bigInt * chore: type cleanup and provisioning permit * chore: some tests don't have defaults for anchor decimalPlaces * chore: rename stable token in startPSM to `minted` * fix(agoric-cli): look up correct brand for PSM trade * chore: ignore missing type for pair Co-authored-by: Dan Connolly Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- packages/agoric-cli/src/lib/psm.js | 2 ++ .../inter-protocol/src/proposals/startPSM.js | 29 ++++++++++++++----- .../test/psm/gov-add-psm-permit.json | 1 + .../inter-protocol/test/psm/gov-add-psm.js | 4 +-- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/packages/agoric-cli/src/lib/psm.js b/packages/agoric-cli/src/lib/psm.js index f3787279ed5..85f3b8de4be 100644 --- a/packages/agoric-cli/src/lib/psm.js +++ b/packages/agoric-cli/src/lib/psm.js @@ -51,6 +51,8 @@ export const makePSMSpendAction = (instance, brands, opts) => { brands, opts, opts.feePct ? opts.feePct / 100 : undefined, + // @ts-expect-error please update types. Not sure where pair goees. + opts.pair[1], ); console.warn('psm spend give', proposal.give); diff --git a/packages/inter-protocol/src/proposals/startPSM.js b/packages/inter-protocol/src/proposals/startPSM.js index 0ce49ab472e..bfdf8e2fdaa 100644 --- a/packages/inter-protocol/src/proposals/startPSM.js +++ b/packages/inter-protocol/src/proposals/startPSM.js @@ -44,7 +44,7 @@ export const startPSM = async ( consume: { contractGovernor, psm: psmInstall }, }, brand: { - consume: { [Stable.symbol]: stableP }, + consume: { [Stable.symbol]: mintedP }, }, }, { @@ -60,9 +60,11 @@ export const startPSM = async ( 'string', X`anchorOptions.denom must be a string, not ${denom}`, ); - const [stable, [anchorBrand, anchorIssuer], feeMintAccess] = + /** @type {[Brand<'nat'>, [Brand<'nat'>, Issuer<'nat'>], FeeMintAccess]} */ + // @ts-expect-error cast + const [minted, [anchorBrand, anchorIssuer], feeMintAccess] = await Promise.all([ - stableP, + mintedP, reserveThenGetNamePaths(agoricNamesAdmin, [ ['brand', keyword], ['issuer', keyword], @@ -79,11 +81,22 @@ export const startPSM = async ( E(E(zoe).getInvitationIssuer()).getAmountOf(poserInvitationP), ]); - const mintLimit = AmountMath.make(stable, MINT_LIMIT); + const [anchorInfo, mintedInfo] = await Promise.all( + [anchorBrand, minted].map(b => E(b).getDisplayInfo()), + ); + + const mintLimit = AmountMath.make(minted, MINT_LIMIT); + const anchorDecimalPlaces = anchorInfo.decimalPlaces || 1n; + const mintedDecimalPlaces = mintedInfo.decimalPlaces || 1n; const terms = await deeplyFulfilledObject( harden({ anchorBrand, - anchorPerMinted: makeRatio(100n, anchorBrand, 100n, stable), + anchorPerMinted: makeRatio( + 10n ** BigInt(anchorDecimalPlaces), + anchorBrand, + 10n ** BigInt(mintedDecimalPlaces), + minted, + ), governedParams: { [CONTRACT_ELECTORATE]: { type: ParamTypes.INVITATION, @@ -91,11 +104,11 @@ export const startPSM = async ( }, WantMintedFee: { type: ParamTypes.RATIO, - value: makeRatio(WantMintedFeeBP, stable, BASIS_POINTS), + value: makeRatio(WantMintedFeeBP, minted, BASIS_POINTS), }, GiveMintedFee: { type: ParamTypes.RATIO, - value: makeRatio(GiveMintedFeeBP, stable, BASIS_POINTS), + value: makeRatio(GiveMintedFeeBP, minted, BASIS_POINTS), }, MintLimit: { type: ParamTypes.AMOUNT, value: mintLimit }, }, @@ -167,7 +180,7 @@ export const startPSM = async ( psm, governorFacets.creatorFacet, anchorBrand, - stable, + minted, ), // @ts-expect-error TODO type for provisionPoolStartResult E(E.get(provisionPoolStartResult).creatorFacet).initPSM( diff --git a/packages/inter-protocol/test/psm/gov-add-psm-permit.json b/packages/inter-protocol/test/psm/gov-add-psm-permit.json index 66068702f3f..3c131e267ae 100644 --- a/packages/inter-protocol/test/psm/gov-add-psm-permit.json +++ b/packages/inter-protocol/test/psm/gov-add-psm-permit.json @@ -8,6 +8,7 @@ "feeMintAccess": "zoe", "economicCommitteeCreatorFacet": "economicCommittee", "psmCharterCreatorFacet": "psmCharter", + "provisionPoolStartResult": true, "psmFacets": true, "chainTimerService": "timer" }, diff --git a/packages/inter-protocol/test/psm/gov-add-psm.js b/packages/inter-protocol/test/psm/gov-add-psm.js index 8832e7a6774..41e33e5394a 100644 --- a/packages/inter-protocol/test/psm/gov-add-psm.js +++ b/packages/inter-protocol/test/psm/gov-add-psm.js @@ -20,8 +20,8 @@ const DAI = { const config = { options: { anchorOptions: DAI }, - WantStableFeeBP: 1n, - GiveStableFeeBP: 3n, + WantMintedFeeBP: 1n, + GiveMintedFeeBP: 3n, MINT_LIMIT: 0n, };