Skip to content

Commit

Permalink
chore(sendAnywhere): use agoric.getVBankAssetInfo()
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc committed Jul 31, 2024
1 parent 09928c8 commit 590dd03
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 38 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
12 changes: 8 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,12 @@ 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.getVBankAssetInfo();
const { denom } = NonNullish(
assets.find(a => a.brand === amt.brand),
`${amt.brand} not registered in vbank`,
);
const chain = await orch.getChain(chainName);

if (!contractState.localAccount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,6 @@ Generated by [AVA](https://avajs.dev).
'ChainHub Admin_singleton': 'Alleged: ChainHub Admin',
'Send PF_kindHandle': 'Alleged: kind',
'Send PF_singleton': 'Alleged: Send PF',
orchestration: {
sendIt: {
asyncFlow_kindHandle: 'Alleged: kind',
endowments: {
0: {
contractState_kindHandle: 'Alleged: kind',
contractState_singleton: 'Alleged: contractState',
findBrandInVBank_kindHandle: 'Alleged: kind',
findBrandInVBank_singleton: 'Alleged: findBrandInVBank',
localTransfer_kindHandle: 'Alleged: kind',
localTransfer_singleton: 'Alleged: localTransfer',
},
},
},
},
},
orchestration: {
'Cosmos Orchestration Account Holder_kindHandle': 'Alleged: kind',
Expand All @@ -52,6 +37,17 @@ Generated by [AVA](https://avajs.dev).
Orchestrator_kindHandle: 'Alleged: kind',
RemoteChainFacade_kindHandle: 'Alleged: kind',
chainName: {},
sendIt: {
asyncFlow_kindHandle: 'Alleged: kind',
endowments: {
1: {
contractState_kindHandle: 'Alleged: kind',
contractState_singleton: 'Alleged: contractState',
localTransfer_kindHandle: 'Alleged: kind',
localTransfer_singleton: 'Alleged: localTransfer',
},
},
},
},
vows: {
PromiseWatcher_kindHandle: 'Alleged: kind',
Expand Down
Binary file not shown.

0 comments on commit 590dd03

Please sign in to comment.