Skip to content

Commit

Permalink
chore: add .asContinuingOffer to LOA holder
Browse files Browse the repository at this point in the history
  • Loading branch information
0xpatrickdev committed Jul 10, 2024
1 parent 0b6d5f3 commit bc12cbd
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 24 deletions.
16 changes: 4 additions & 12 deletions packages/orchestration/src/examples/stakeBld.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,13 @@ export const start = async (zcf, privateArgs, baggage) => {
async seat => {
const { give } = seat.getProposal();
trace('makeStakeBldInvitation', give);
const { holder, invitationMakers } = await makeLocalAccountKit();
const { holder } = await makeLocalAccountKit();
const { In } = await deeplyFulfilled(
withdrawFromSeat(zcf, seat, give),
);
await E(holder).deposit(In);
seat.exit();
return harden({
publicSubscribers: holder.getPublicTopics(),
invitationMakers,
account: holder,
});
return holder.asContinuingOffer();
},
'wantStake',
undefined,
Expand All @@ -118,12 +114,8 @@ export const start = async (zcf, privateArgs, baggage) => {
trace('makeCreateAccountInvitation');
return zcf.makeInvitation(async seat => {
seat.exit();
const { holder, invitationMakers } = await makeLocalAccountKit();
return harden({
publicSubscribers: holder.getPublicTopics(),
invitationMakers,
account: holder,
});
const { holder } = await makeLocalAccountKit();
return holder.asContinuingOffer();
}, 'wantLocalChainAccount');
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ const { Vow$ } = NetworkShape; // TODO #9611
/** @see {OrchestrationAccountI} */
export const IcaAccountHolderI = M.interface('IcaAccountHolder', {
...orchestrationAccountMethods,
asContinuingOffer: M.call().returns({
publicSubscribers: M.any(),
invitationMakers: M.any(),
holder: M.any(),
}),
getPublicTopics: M.call().returns(TopicsRecordShape),
delegate: M.call(ChainAddressShape, AmountArgShape).returns(VowShape),
redelegate: M.call(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,14 @@ export const prepareLocalOrchestrationAccountKit = (
},
},
holder: {
asContinuingOffer() {
const { holder, invitationMakers } = this.facets;
return harden({
publicSubscribers: holder.getPublicTopics(),
invitationMakers,
holder,
});
},
/**
* TODO: balance lookups for non-vbank assets
*
Expand Down
24 changes: 18 additions & 6 deletions packages/orchestration/src/orchestration-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
* - must not have chain-specific types without runtime narrowing by chain id
* - should remain relatively stable.
*/
import type {
Amount,
Brand,
NatAmount,
Payment,
} from '@agoric/ertp/src/types.js';
import type { Amount, Brand, NatAmount } from '@agoric/ertp/src/types.js';
import type { LocalChainAccount } from '@agoric/vats/src/localchain.js';
import type { Timestamp } from '@agoric/time';
import type { ContinuingOfferResult } from '@agoric/smart-wallet/src/types.js';
import type { TopicsRecord } from '@agoric/zoe/src/contractSupport/topics.js';
import type { CurrentWalletRecord } from '@agoric/smart-wallet/src/smartWallet.js';
import type {
ChainInfo,
CosmosChainAccountMethods,
Expand Down Expand Up @@ -172,6 +170,20 @@ export interface OrchestrationAccountI {
* @returns void
*/
transferSteps: (amount: AmountArg, msg: TransferMsg) => Promise<void>;

/**
* Returns `invitationMakers` and `publicSubscribers` to the account
* holder's smart wallet so they can continue interacting with the account
* and read account state in vstorage if published.
*/
asContinuingOffer: () => Promise<ContinuingOfferResult>;
/**
* Public topics are a map to different vstorage paths and subscribers that
* can be shared with on or offchain clients.
* When returned as part of a continuing invitation, it will appear
* in the {@link CurrentWalletRecord} in vstorage.
*/
getPublicTopics: () => Promise<TopicsRecord>;
}

/**
Expand Down
6 changes: 6 additions & 0 deletions packages/orchestration/src/utils/orchestrationAccount.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { M } from '@endo/patterns';
import { Shape as NetworkShape } from '@agoric/network';
import { VowShape } from '@agoric/vow';
import { TopicsRecordShape } from '@agoric/zoe/src/contractSupport/topics.js';
import { AmountArgShape, ChainAddressShape, CoinShape } from '../typeGuards.js';

/** @import {OrchestrationAccountI} from '../orchestration-api.js'; */
Expand All @@ -17,4 +18,9 @@ export const orchestrationAccountMethods = {
.optional(M.record())
.returns(VowShape),
transferSteps: M.call(AmountArgShape, M.any()).returns(VowShape),
asContinuingOffer: M.call().returns({
publicSubscribers: TopicsRecordShape,
invitationMakers: M.any(),
holder: M.remotable(),
}),
};
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ test('makeAccountInvitationMaker', async t => {

const userSeat = await E(zoe).offer(inv);
const offerResult = await E(userSeat).getOfferResult();
t.true('account' in offerResult, 'received account');
t.true('holder' in offerResult, 'received account holder');
t.truthy('invitationMakers' in offerResult, 'received continuing invitation');
t.like(offerResult.publicSubscribers, {
account: {
description: 'Account holder status',
storagePath: 'mockChainStorageRoot',
},
});
});

0 comments on commit bc12cbd

Please sign in to comment.