Skip to content

Commit

Permalink
chore(sendAnywhere): use agoric.getVBankAssets()
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc committed Jul 29, 2024
1 parent 25ef746 commit ad89f4a
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 25 deletions.
20 changes: 1 addition & 19 deletions packages/orchestration/src/examples/sendAnywhere.contract.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { makeStateRecord } from '@agoric/async-flow';
import { AmountShape } from '@agoric/ertp';
import { InvitationShape } from '@agoric/zoe/src/typeGuards.js';
import { Fail } from '@endo/errors';
import { E } from '@endo/far';
import { M } from '@endo/patterns';
import { withOrchestration } from '../utils/start-helper.js';
import * as flows from './sendAnywhere.flows.js';
Expand Down Expand Up @@ -50,7 +48,7 @@ const contract = async (
zcf,
privateArgs,
zone,
{ chainHub, orchestrateAll, vowTools, zoeTools },
{ chainHub, orchestrateAll, zoeTools },
) => {
const contractState = makeStateRecord(
/** @type {{ account: OrchestrationAccount<any> | undefined }} */ {
Expand All @@ -60,27 +58,11 @@ const contract = async (

const creatorFacet = prepareChainHubAdmin(zone, chainHub);

// TODO should be a provided helper
/** @type {(brand: Brand) => Vow<VBankAssetDetail>} */
const findBrandInVBank = vowTools.retriable(
zone,
'findBrandInVBank',
/** @param {Brand} brand */
async brand => {
const { agoricNames } = privateArgs;
const assets = await E(E(agoricNames).lookup('vbankAsset')).values();
const it = assets.find(a => a.brand === brand);
it || Fail`brand ${brand} not in agoricNames.vbankAsset`;
return it;
},
);

// orchestrate uses the names on orchestrationFns to do a "prepare" of the associated behavior
const orchFns = orchestrateAll(flows, {
zcf,
contractState,
localTransfer: zoeTools.localTransfer,
findBrandInVBank,
});

const publicFacet = zone.exo(
Expand Down
9 changes: 5 additions & 4 deletions packages/orchestration/src/examples/sendAnywhere.flows.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { NonNullish } from '@agoric/internal';
import { M, mustMatch } from '@endo/patterns';

/**
* @import {GuestOf} from '@agoric/async-flow';
* @import {VBankAssetDetail} from '@agoric/vats/tools/board-utils.js';
* @import {ZoeTools} from '../utils/zoe-tools.js';
* @import {Orchestrator, LocalAccountMethods, OrchestrationAccountI, OrchestrationFlow} from '../types.js';
*/
Expand All @@ -18,13 +18,12 @@ const { entries } = Object;
* @param {object} ctx
* @param {{ localAccount?: OrchestrationAccountI & LocalAccountMethods }} ctx.contractState
* @param {GuestOf<ZoeTools['localTransfer']>} ctx.localTransfer
* @param {(brand: Brand) => Promise<VBankAssetDetail>} ctx.findBrandInVBank
* @param {ZCFSeat} seat
* @param {{ chainName: string; destAddr: string }} offerArgs
*/
export async function sendIt(
orch,
{ contractState, localTransfer, findBrandInVBank },
{ contractState, localTransfer },
seat,
offerArgs,
) {
Expand All @@ -33,7 +32,9 @@ export async function sendIt(
// NOTE the proposal shape ensures that the `give` is a single asset
const { give } = seat.getProposal();
const [[_kw, amt]] = entries(give);
const { denom } = await findBrandInVBank(amt.brand);
const agoric = await orch.getChain('agoric');
const assets = await agoric.getVBankAssets();
const { denom } = NonNullish(assets.find(a => a.brand === amt.brand));
const chain = await orch.getChain(chainName);

if (!contractState.localAccount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ Generated by [AVA](https://avajs.dev).
1: {
contractState_kindHandle: 'Alleged: kind',
contractState_singleton: 'Alleged: contractState',
findBrandInVBank_kindHandle: 'Alleged: kind',
findBrandInVBank_singleton: 'Alleged: findBrandInVBank',
localTransfer_kindHandle: 'Alleged: kind',
localTransfer_singleton: 'Alleged: localTransfer',
},
Expand Down
Binary file not shown.

0 comments on commit ad89f4a

Please sign in to comment.