Skip to content

Commit

Permalink
feat: defineInertInvitation
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Nov 14, 2024
1 parent 642a057 commit f756412
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
12 changes: 7 additions & 5 deletions packages/fast-usdc/src/fast-usdc.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { prepareLiquidityPoolKit } from './exos/liquidity-pool.js';
import { prepareSettler } from './exos/settler.js';
import { prepareStatusManager } from './exos/status-manager.js';
import { prepareTransactionFeedKit } from './exos/transaction-feed.js';
import { defineInertInvitation } from './utils/zoe.js';

const trace = makeTracer('FastUsdc');

Expand Down Expand Up @@ -86,6 +87,11 @@ export const contract = async (zcf, privateArgs, zone, tools) => {
{ makeRecorderKit },
);

const makeTestSubmissionInvitation = defineInertInvitation(
zcf,
'test of submitting evidence',
);

const creatorFacet = zone.exo('Fast USDC Creator', undefined, {
simulateFeesFromAdvance(amount, payment) {
console.log('🚧🚧 UNTIL: advance fees are implemented 🚧🚧');
Expand All @@ -109,11 +115,7 @@ export const contract = async (zcf, privateArgs, zone, tools) => {
// TODO(bootstrap integration): force this to throw and confirm that it
// shows up in the the smart-wallet UpdateRecord `error` property
feedKit.admin.submitEvidence(evidence);
return zcf.makeInvitation(async cSeat => {
trace('Offer made on noop invitation');
cSeat.exit();
return 'noop; evidence was pushed in the invitation maker call';
}, 'noop invitation');
return makeTestSubmissionInvitation();
},
makeDepositInvitation() {
// eslint-disable-next-line no-use-before-define
Expand Down
28 changes: 28 additions & 0 deletions packages/fast-usdc/src/utils/zoe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { makeTracer } from '@agoric/internal';

const trace = makeTracer('ZoeUtils');

/**
* Used for "continuing offer" invitations in which the caller does not need
* anything in return. In those cases there is no Zoe offer safety and the
* invitation making function can perform the request itself.
*
* But smart-wallet expects an invitation maker to make an invitation, so this
* function abstracts making such an inert invitation and logs consistently when
* it is used.
*
* When this is used by an invitation maker that performs the operation, receiving
* one of these invitations is evidence that the operation took place.
*
* @param {ZCF} zcf
* @param {string} description @see {@link ZCF.makeInvitation}
* @returns {() => Promise<Invitation>} an arg-less invitation maker
*/
export const defineInertInvitation = (zcf, description) => {
return () =>
zcf.makeInvitation(seat => {
trace(`ℹ️ An offer was made on an inert invitation for ${description}`);
seat.exit();
return 'inert; nothing should be expected from this offer';
}, description);
};
2 changes: 1 addition & 1 deletion packages/fast-usdc/test/fast-usdc.contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ test('start', async t => {
const seat = await E(zoe).offer(inv);
t.is(
await E(seat).getOfferResult(),
'noop; evidence was pushed in the invitation maker call',
'inert; nothing should be expected from this offer',
);
});

Expand Down

0 comments on commit f756412

Please sign in to comment.