Skip to content

Commit

Permalink
fix: make it possible to set decimalPlaces when calling startPSM (#6348)
Browse files Browse the repository at this point in the history
* 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 <connolly@agoric.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 29, 2022
1 parent a27d71d commit 46aa80e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
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

0 comments on commit 46aa80e

Please sign in to comment.