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: make it possible to set decimalPlaces when calling startPSM #6348

Merged
merged 8 commits into from
Sep 29, 2022
2 changes: 2 additions & 0 deletions packages/agoric-cli/src/lib/psm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
29 changes: 21 additions & 8 deletions packages/inter-protocol/src/proposals/startPSM.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const startPSM = async (
consume: { contractGovernor, psm: psmInstall },
},
brand: {
consume: { [Stable.symbol]: stableP },
consume: { [Stable.symbol]: mintedP },
},
},
{
Expand All @@ -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],
Expand All @@ -79,23 +81,34 @@ 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,
value: electorateInvitationAmount,
},
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 },
},
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions packages/inter-protocol/test/psm/gov-add-psm-permit.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"feeMintAccess": "zoe",
"economicCommitteeCreatorFacet": "economicCommittee",
"psmCharterCreatorFacet": "psmCharter",
"provisionPoolStartResult": true,
"psmFacets": true,
"chainTimerService": "timer"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/inter-protocol/test/psm/gov-add-psm.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const DAI = {

const config = {
options: { anchorOptions: DAI },
WantStableFeeBP: 1n,
GiveStableFeeBP: 3n,
WantMintedFeeBP: 1n,
GiveMintedFeeBP: 3n,
MINT_LIMIT: 0n,
};

Expand Down