Skip to content

Commit

Permalink
feat(vats): Mock ERTP face on mock orch assets
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Dec 18, 2024
1 parent c1d2b71 commit a99db2a
Show file tree
Hide file tree
Showing 15 changed files with 1,428 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/orchestration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"@agoric/zone": "^0.2.2",
"@endo/base64": "^1.0.9",
"@endo/errors": "^1.2.8",
"@endo/eventual-send": "^1.2.8",
"@endo/far": "^1.1.9",
"@endo/marshal": "^1.6.2",
"@endo/patterns": "^1.4.7",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { M } from '@endo/patterns';

import {
AmountShape,
BrandShape,
IssuerKitShape,
PaymentShape,
PurseShape,
} from '@agoric/ertp';
import { AnyNatAmountShape, DenomShape } from '../../typeGuards.js';
import { mockIssuerInterfaces } from './typeGuards.js';
import { MockOrchAccountShape } from '../mock-orch/typeGuards.js';

export const IssuerAdminShape = M.remotable('IssuerAdmin');
export const RecoverySetShape = M.remotable('RecoverySet');
export const RecoveryFacetShape = M.remotable('RecoverFacet');
export const Denom2IssuerKitShape = M.remotable('Denom2IssuerKit');
export const Brand2DenomShape = M.remotable('Brand2Denom');

const {
mintRecoveryPurse: _1, // omit
displayInfo: _2, // omit
...CoreIssuerKitShape
} = IssuerKitShape;

export const IssuerKitPlusShape = harden({
...CoreIssuerKitShape,
admin: IssuerAdminShape,
});

export const PaymentLedgerEntryShape = harden({
keyShape: PaymentShape,
valueShape: AnyNatAmountShape,
});

export const PaymentRecoveryEntryShape = harden({
keyShape: PaymentShape,
valueShape: RecoveryFacetShape,
});

export const Denom2IssuerKitEntryShape = harden({
keyShape: DenomShape,
valueShape: IssuerKitPlusShape,
});

export const Brand2DenomEntryShape = harden({
keyShape: BrandShape,
valueShape: DenomShape,
});

/**
* @param {Pattern} [brandShape]
* @param {Pattern} [assetKindShape]
* @param {Pattern} [amountShape]
*/
export const mockIssuerInterfacesPlus = (
brandShape = undefined,
assetKindShape = undefined,
amountShape = AmountShape,
) => {
const {
IssuerI,
MintI,
PaymentI,
PurseIKit: MockPurseIKit,
} = mockIssuerInterfaces(brandShape, assetKindShape, amountShape);

const RecoveryFacetI = M.interface('RecoveryFacet', {
initPayment: M.call(PaymentShape).returns(),
deletePayment: M.call(PaymentShape).returns(),
getRecoverySetStore: M.call().returns(RecoverySetShape),
getCurrentEncumberedBalance: M.call().returns(amountShape),
encumber: M.call(amountShape).returns(),
unencumber: M.call(amountShape).returns(),
getOrchAcct: M.call().returns(M.eref(MockOrchAccountShape)),
});

const MockPurseIKitPlus = {
...MockPurseIKit,
recoveryFacet: RecoveryFacetI,
};

const IssuerAdminI = M.interface('MockIssuerAdmin', {
makePurse: M.call(M.eref(MockOrchAccountShape)).returns(M.eref(PurseShape)),
});

return harden({
IssuerI,
MintI,
PaymentI,
PurseIKit: MockPurseIKitPlus,
IssuerAdminI,
});
};
harden(mockIssuerInterfacesPlus);
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import type { ERef } from '@endo/eventual-send';

import type { WeakMapStore, SetStore } from '@agoric/store';

import type { Payment, Amount } from '@agoric/ertp';
import type { MockOrchAccount } from '../mock-orch/types.ts';
import type { MockPurse } from './types.js';

export type PaymentLedgerMap = WeakMapStore<Payment, Amount>;

export type RecoverySet = SetStore<Payment>;

export type RecoveryFacet = {
/**
*
*/
initPayment: (payment: Payment) => void;

/**
*
*/
deletePayment: (payment: Payment) => void;

/**
* Awkward name because `getRecoverSet` is already a method of purse that
* return a copySet.
*/
getRecoverySetStore: () => RecoverySet;

/**
* Get the amount contained in all payments still in the recoverySet at
* this moment
*/
getCurrentEncumberedBalance: () => Amount;

/**
*
*/
encumber: (amount: Amount) => void;

/**
*
*/
unencumber: (amount: Amount) => void;

/**
*
*/
getOrchAcct: () => ERef<MockOrchAccount>;
};

export type PaymentRecoveryMap = WeakMapStore<Payment, RecoveryFacet>;

export type MockIssuerAdmin = {
makePurse: (orchAcctP: ERef<MockOrchAccount>) => ERef<MockPurse>;
};
Loading

0 comments on commit a99db2a

Please sign in to comment.