Skip to content

Commit

Permalink
feat: restore PSM state from former VM vstorage contents
Browse files Browse the repository at this point in the history
fixes: #6645
  • Loading branch information
dckc committed Apr 24, 2023
1 parent 8575a6d commit 65aeca5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
25 changes: 18 additions & 7 deletions packages/inter-protocol/src/proposals/startPSM.js
Original file line number Diff line number Diff line change
Expand Up @@ -680,16 +680,27 @@ export const restorePSM = async powers => {
const { psmCreatorFacet } = psmKitMap.get(anchorKit.brand);

if (!anchorKit) throw Fail`no anchor kit for ${keyAnchor}`;
const asAnchorAmount = amt => AmountMath.make(anchorKit.brand, amt.value);
const [anchorPmt, feePoolPmt] = await Promise.all([
E(anchorKit.mint).mintPayment(asAnchorAmount(metrics.anchorPoolBalance)),
E(anchorKit.mint).mintPayment(metrics.anchorPoolBalance),
E(feePurse).withdraw(metrics.feePoolBalance),
]);
// TODO:
// await E(psmCreatorFacet).restoreMetrics(metrics, {
// anchorPmt,
// feePoolPmt,
// });

const {
feePoolBalance: _f,
anchorPoolBalance: _a,
...nonPaymentMetrics
} = metrics;
await E(zoe).offer(
E(psmCreatorFacet).makeRestoreMetricsInvitation(),
{
give: {
Anchor: metrics.anchorPoolBalance,
Minted: metrics.feePoolBalance,
},
},
{ Anchor: anchorPmt, Minted: feePoolPmt },
nonPaymentMetrics,
);
}

return {
Expand Down
11 changes: 7 additions & 4 deletions packages/inter-protocol/test/psm/test-psm.js
Original file line number Diff line number Diff line change
Expand Up @@ -900,15 +900,18 @@ test('restore PSM: restore governance recreated brands', async t => {
const psmKit = await consume.psmKit;
const psm0 = psmKit.get(anchorBrand);
t.truthy(psm0);
const contractParams = await E(
E(zoe).getPublicFacet(psm0.psm),
).getGovernedParams();
/** @type {ERef<PsmPublicFacet>} */
const pf = E(zoe).getPublicFacet(psm0.psm);
const contractParams = await E(pf).getGovernedParams();

const omitElectorate = ({ Electorate: _, ...params }) => params;
t.deepEqual(
omitElectorate(contractParams),
omitElectorate(a0.governance.current),
);

// TODO: check metrics, esp. feePoolBalance, amount of anchor available
const { value: contractMetrics } = await E(
E(pf).getMetrics(),
).getUpdateSince();
t.deepEqual(contractMetrics, a0.metrics);
});

0 comments on commit 65aeca5

Please sign in to comment.