From f5198ed52fb607ac217dfc192e028eba654db365 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Fri, 27 Sep 2024 14:11:38 -0700 Subject: [PATCH] chore: sharedLocalAccount pattern --- .../src/examples/send-anywhere.contract.js | 10 +++- .../src/examples/send-anywhere.flows.js | 23 +++------ .../src/examples/shared.flows.js | 17 +++++++ .../examples/staking-combinations.contract.js | 10 +++- .../examples/staking-combinations.flows.js | 20 +++----- .../snapshots/send-anywhere.test.ts.md | 27 +++++++--- .../snapshots/send-anywhere.test.ts.snap | Bin 1258 -> 1418 bytes .../snapshots/staking-combinations.test.ts.md | 12 ++--- .../staking-combinations.test.ts.snap | Bin 2471 -> 2527 bytes .../test/fixtures/zoe-tools.contract.js | 13 +++-- .../test/fixtures/zoe-tools.flows.js | 47 +++++------------- .../test/snapshots/ibc-mocks.test.ts.md | 6 +++ .../test/snapshots/ibc-mocks.test.ts.snap | Bin 414 -> 602 bytes 13 files changed, 100 insertions(+), 85 deletions(-) create mode 100644 packages/orchestration/src/examples/shared.flows.js diff --git a/packages/orchestration/src/examples/send-anywhere.contract.js b/packages/orchestration/src/examples/send-anywhere.contract.js index 09e44913cbcd..887efe763cef 100644 --- a/packages/orchestration/src/examples/send-anywhere.contract.js +++ b/packages/orchestration/src/examples/send-anywhere.contract.js @@ -2,6 +2,7 @@ import { InvitationShape } from '@agoric/zoe/src/typeGuards.js'; import { M } from '@endo/patterns'; import { withOrchestration } from '../utils/start-helper.js'; import * as flows from './send-anywhere.flows.js'; +import * as sharedFlows from './shared.flows.js'; import { prepareChainHubAdmin } from '../exos/chain-hub-admin.js'; import { AnyNatAmountShape } from '../typeGuards.js'; @@ -32,13 +33,18 @@ const contract = async ( zcf, privateArgs, zone, - { atomicProvider, chainHub, orchestrateAll, zoeTools }, + { atomicProvider, chainHub, orchestrate, orchestrateAll, vowTools, zoeTools }, ) => { const creatorFacet = prepareChainHubAdmin(zone, chainHub); + const sharedLocalAccount = await atomicProvider.provideAsync( + 'localAccount', + key => vowTools.when(orchestrate(key, {}, sharedFlows.makeLocalAccount)()), + ); + // orchestrate uses the names on orchestrationFns to do a "prepare" of the associated behavior const orchFns = orchestrateAll(flows, { - atomicProvider, + sharedLocalAccount, zoeTools, }); diff --git a/packages/orchestration/src/examples/send-anywhere.flows.js b/packages/orchestration/src/examples/send-anywhere.flows.js index 4c5905ee3418..0acf45360158 100644 --- a/packages/orchestration/src/examples/send-anywhere.flows.js +++ b/packages/orchestration/src/examples/send-anywhere.flows.js @@ -4,9 +4,9 @@ import { M, mustMatch } from '@endo/patterns'; /** * @import {GuestInterface} from '@agoric/async-flow'; + * @import {LocalOrchestrationAccountKit} from '../exos/local-orchestration-account.js'; * @import {ZoeTools} from '../utils/zoe-tools.js'; - * @import {AtomicProvider} from '@agoric/store/src/stores/store-utils.js'; - * @import {Orchestrator, OrchestrationFlow, OrchestrationAccount} from '../types.js'; + * @import {Orchestrator, OrchestrationFlow, LocalAccountMethods} from '../types.js'; */ const { entries } = Object; @@ -18,14 +18,14 @@ const { entries } = Object; * @satisfies {OrchestrationFlow} * @param {Orchestrator} orch * @param {object} ctx - * @param {AtomicProvider} ctx.atomicProvider + * @param {GuestInterface} ctx.sharedLocalAccount * @param {GuestInterface} ctx.zoeTools * @param {ZCFSeat} seat * @param {{ chainName: string; destAddr: string }} offerArgs */ export const sendIt = async ( orch, - { atomicProvider, zoeTools: { localTransfer, withdrawToSeat } }, + { sharedLocalAccount, zoeTools: { localTransfer, withdrawToSeat } }, seat, offerArgs, ) => { @@ -42,23 +42,14 @@ export const sendIt = async ( ); const chain = await orch.getChain(chainName); - const localAccount = await atomicProvider.provideAsync( - 'localAccount', - async () => { - const agoricChain = await orch.getChain('agoric'); - return agoricChain.makeAccount(); - }, - ); - const info = await chain.getChainInfo(); const { chainId } = info; assert(typeof chainId === 'string', 'bad chainId'); - await localTransfer(seat, localAccount, give); + await localTransfer(seat, sharedLocalAccount, give); try { - await localAccount.transfer( - { denom, value: amt.value }, + await sharedLocalAccount.transfer( { value: destAddr, encoding: 'bech32', @@ -67,7 +58,7 @@ export const sendIt = async ( { denom, value: amt.value }, ); } catch (e) { - await withdrawToSeat(localAccount, seat, give); + await withdrawToSeat(sharedLocalAccount, seat, give); const errorMsg = `IBC Transfer failed ${q(e)}`; seat.exit(errorMsg); throw makeError(errorMsg); diff --git a/packages/orchestration/src/examples/shared.flows.js b/packages/orchestration/src/examples/shared.flows.js new file mode 100644 index 000000000000..2e1601719a99 --- /dev/null +++ b/packages/orchestration/src/examples/shared.flows.js @@ -0,0 +1,17 @@ +/** + * @import {Orchestrator, OrchestrationFlow, LocalAccountMethods} from '../types.js'; + */ + +// in guest file (the orchestration functions) +// the second argument is all the endowments provided + +/** + * @satisfies {OrchestrationFlow} + * @param {Orchestrator} orch + * @returns {Promise} + */ +export const makeLocalAccount = async orch => { + const agoricChain = await orch.getChain('agoric'); + return agoricChain.makeAccount(); +}; +harden(makeLocalAccount); diff --git a/packages/orchestration/src/examples/staking-combinations.contract.js b/packages/orchestration/src/examples/staking-combinations.contract.js index 9e59dd0a3f91..32b5ca9d3552 100644 --- a/packages/orchestration/src/examples/staking-combinations.contract.js +++ b/packages/orchestration/src/examples/staking-combinations.contract.js @@ -12,6 +12,7 @@ import { CosmosOrchestrationInvitationMakersI } from '../exos/cosmos-orchestrati import { ChainAddressShape, DelegationShape } from '../typeGuards.js'; import { withOrchestration } from '../utils/start-helper.js'; import * as flows from './staking-combinations.flows.js'; +import * as sharedFlows from './shared.flows.js'; import { prepareChainHubAdmin } from '../exos/chain-hub-admin.js'; /** @@ -43,7 +44,7 @@ const contract = async ( zcf, privateArgs, zone, - { atomicProvider, orchestrateAll, zoeTools, chainHub }, + { atomicProvider, orchestrate, orchestrateAll, zoeTools, chainHub, vowTools }, ) => { const StakingCombinationsInvitationMakersI = M.interface( 'StakingCombinationsInvitationMakersI', @@ -117,8 +118,13 @@ const contract = async ( StakingCombinationsInvitationMakersI, ); + const sharedLocalAccount = await atomicProvider.provideAsync( + 'localAccount', + key => vowTools.when(orchestrate(key, {}, sharedFlows.makeLocalAccount)()), + ); + const orchFns = orchestrateAll(flows, { - atomicProvider, + sharedLocalAccount, makeCombineInvitationMakers, makeExtraInvitationMaker, flows, diff --git a/packages/orchestration/src/examples/staking-combinations.flows.js b/packages/orchestration/src/examples/staking-combinations.flows.js index 27fb3d10ef9f..2d69e502a22d 100644 --- a/packages/orchestration/src/examples/staking-combinations.flows.js +++ b/packages/orchestration/src/examples/staking-combinations.flows.js @@ -2,7 +2,7 @@ * @import {GuestInterface} from '@agoric/async-flow'; * @import {Orchestrator, OrchestrationFlow, AmountArg, CosmosValidatorAddress, ChainAddress, LocalAccountMethods, OrchestrationAccountI} from '../types.js' * @import {ContinuingOfferResult, InvitationMakers} from '@agoric/smart-wallet/src/types.js'; - * @import {AtomicProvider} from '@agoric/store/src/stores/store-utils.js'; + * @import {LocalOrchestrationAccountKit} from '../exos/local-orchestration-account.js'; * @import {MakeCombineInvitationMakers} from '../exos/combine-invitation-makers.js'; * @import {CosmosOrchestrationAccount} from '../exos/cosmos-orchestration-account.js'; * @import {ZoeTools} from '../utils/zoe-tools.js'; @@ -49,7 +49,7 @@ harden(makeAccount); * @satisfies {OrchestrationFlow} * @param {Orchestrator} orch * @param {object} ctx - * @param {AtomicProvider} ctx.atomicProvider + * @param {GuestInterface} ctx.sharedLocalAccount * @param {GuestInterface} ctx.zoeTools * @param {GuestInterface} account * @param {ZCFSeat} seat @@ -58,7 +58,7 @@ harden(makeAccount); */ export const depositAndDelegate = async ( orch, - { atomicProvider, zoeTools }, + { sharedLocalAccount, zoeTools }, account, seat, validator, @@ -67,22 +67,14 @@ export const depositAndDelegate = async ( trace('depositAndDelegate', account, seat, validator); mustMatch(validator, ChainAddressShape); - const localAccount = await atomicProvider.provideAsync( - 'localAccount', - async () => { - const agoricChain = await orch.getChain('agoric'); - return agoricChain.makeAccount(); - }, - ); - const { give } = seat.getProposal(); - await zoeTools.localTransfer(seat, localAccount, give); + await zoeTools.localTransfer(seat, sharedLocalAccount, give); const address = account.getAddress(); try { - await localAccount.transfer(give.Stake, address); + await sharedLocalAccount.transfer(address, give.Stake); } catch (cause) { - await zoeTools.withdrawToSeat(localAccount, seat, give); + await zoeTools.withdrawToSeat(sharedLocalAccount, seat, give); const errMsg = makeError(`ibc transfer failed ${q(cause)}`); seat.exit(errMsg); throw errMsg; diff --git a/packages/orchestration/test/examples/snapshots/send-anywhere.test.ts.md b/packages/orchestration/test/examples/snapshots/send-anywhere.test.ts.md index 3b2dd4411082..c35b356a7522 100644 --- a/packages/orchestration/test/examples/snapshots/send-anywhere.test.ts.md +++ b/packages/orchestration/test/examples/snapshots/send-anywhere.test.ts.md @@ -28,7 +28,17 @@ Generated by [AVA](https://avajs.dev). ChainHub_kindHandle: 'Alleged: kind', ChainHub_singleton: 'Alleged: ChainHub', brandDenom: {}, - chainInfos: {}, + chainInfos: { + agoric: { + chainId: 'agoric-3', + icqEnabled: false, + stakingTokens: [ + { + denom: 'ubld', + }, + ], + }, + }, connectionInfos: {}, denom: {}, }, @@ -37,16 +47,17 @@ Generated by [AVA](https://avajs.dev). 'ChainHub Admin_singleton': 'Alleged: ChainHub Admin', 'Send PF_kindHandle': 'Alleged: kind', 'Send PF_singleton': 'Alleged: Send PF', - atomicProvider: {}, + atomicProvider: { + localAccount: 'Alleged: Local Orchestration Account Kit holder', + }, orchestration: { + localAccount: { + asyncFlow_kindHandle: 'Alleged: kind', + }, sendIt: { asyncFlow_kindHandle: 'Alleged: kind', endowments: { 0: { - atomicProvider: { - provideAsync_kindHandle: 'Alleged: kind', - provideAsync_singleton: 'Alleged: provideAsync', - }, zoeTools: { localTransfer_kindHandle: 'Alleged: kind', localTransfer_singleton: 'Alleged: localTransfer', @@ -64,7 +75,9 @@ Generated by [AVA](https://avajs.dev). LocalChainFacade_kindHandle: 'Alleged: kind', Orchestrator_kindHandle: 'Alleged: kind', RemoteChainFacade_kindHandle: 'Alleged: kind', - chainName: {}, + chainName: { + agoric: 'Alleged: LocalChainFacade public', + }, ibcTools: { IBCTransferSenderKit_kindHandle: 'Alleged: kind', ibcResultWatcher_kindHandle: 'Alleged: kind', diff --git a/packages/orchestration/test/examples/snapshots/send-anywhere.test.ts.snap b/packages/orchestration/test/examples/snapshots/send-anywhere.test.ts.snap index 6e3d6042f3e0efe4d579f27bc51406cfef11509b..b2b5e51308b41c9f4c7c61aa7163c71ddabf6508 100644 GIT binary patch literal 1418 zcmV;51$FvCRzVSWSonJHty1oUAo(r zp7dqrZ8B!^UOMyAxSlKsR-xkEUM!*riboHE;ze37o{C@(wovdO;z7`hie!?R%)HsI zJDXE7zu*7k{XgI2!_Af@^saN|29u_=Si42rZQ5q0!)f2?2i?yRkWHI^> zjc82(rvSVU;1+=U0R9CqOMvGHFhepml38uN#&k)D|Fv4Jf|NkAAQjAzM4co-(lzqX z@qtZS7Hg~xT9)Z_8YfNpO4sDZGUbNFJX&edvRIoLFEmD&qGRSP(}is?dl!ObLQWIF zgLBl`;(F5(Ll?RpfHb{BO};#6xyX+pL~vtQXUd5tD?EXS>TZ@u$2XFWr4f~ zysQE5XuwAr@U^C>IH0OX-O+%18qmlAujUl`e585`O6KPljh@LDy&T3ZoLNQOF?ri! zQgDxO(3cJ~6+QK1=EzG^@VFiw}l5l#$X{-jBjYVA-11=lO!rI-w3h8{}l+da50F`@KoQGU}ZuFZ}r$+3qKR9(o z#6Hc!S=JMh#WPdr}f zdk>%Xv;RM{pwV$hjH@}}+PxaE8`ABfUj)5!7&lhrwq8v<_I@_P{sfx2(I4ID^=%vM z@XE2J4V!Xjli8yg%xW12zdGGRNLUNVB)roOK410`A_q8l> zqyju!L1?1p!xNPxUaA1iiW1eCa8&c|ISYhbthg`Ee)GQ>uuhJ+`aY=upR4)`k-Yy< z0dA|b`gSuW6rS+~&wm3Qv@9dw&hG(tv^NBs>_m;EAFcwARe{Ya@L3i3wW^rjA2FR$ zZ-DNQ@%lXW-6AXUWa Y`Fo{7Hzl(hj--IPNqrQ) z+9p5pP9KX100000000A>S3PVaMHK$Vzw6j*$N5h#;_Tu%7*&W9O(VT>Y?xaXZ%{8155*-~9LQv<5>k!2?oP?mHKu`e!uVZ_6HZj?_ zviyDDn>X)g-t%V%RY#Z&@6JOeZRxODmDXys#%zz%mRA?jyYtYpsHAU~K29Qw?uTeZ zs{mLBa38=4fS&>U17MB-uMl98WXdG7S$&t8l90jI@$qpG9V81K$>j;)sq9JqSRWS*JE%ZC8Ed#}Fd8bg3zQWFj#{bm5wH=1G@ITW}xV3&5#E(eb)b zEPRvz?j?Ye1W--_H%N)1Mj7Q z<23MP8hDgeq?w5HX&U%74P46rJOg}@0e;E=-IRx^+W@nYJiag-pMKS*+})|mCVmCSxuWS^>Y}vaOM=bXY-oFq~LwR z>_8o6Dt4xp?XH)$;Bh@zthBi=+~XaWwptge;gE$ZQ45i4EDQ`p$Z9LCi`tG9E{p5N z{EnoO#kob1kWX{N-k9ojVw;<<(;9R4X@j|*&-yyRDi2r{YCCP0^(a3CDF=?|RD`?P zmZoU3Taj$#+P;??wAKG*df-}z(Z&XC`62KtE~5r$<@8mE8=#4SFp{3~K(`Wna()k7 zYOLx~Zrxy9G<~c*7Qp<6YKNhql#ik|H5@$IgG}br4NC z{`nQ*HHBwv2ARf^X^J+N#;R~GHm^c9udfS}I_H?Y#NfQ*+w-Gep(eFrcm3?p6%qS3 zi`%RzB#U=^k&v$fiOBi2|0ZoRA9@^sG`ni<3gPr>{_g;iZ&9` zM$;qF>_}7_iRMP4V&o-%C4Y~G%^)gJeKpoY92Vw1CLc>(~&b53V=~i zXfu)hg!r{~yD+S^jK{dOCeJLht82?EyDsJ40du=A5pyro!*t(AN(D0L_nW#{d8T diff --git a/packages/orchestration/test/examples/snapshots/staking-combinations.test.ts.md b/packages/orchestration/test/examples/snapshots/staking-combinations.test.ts.md index afcd6ed2fd1a..254094821f75 100644 --- a/packages/orchestration/test/examples/snapshots/staking-combinations.test.ts.md +++ b/packages/orchestration/test/examples/snapshots/staking-combinations.test.ts.md @@ -102,13 +102,14 @@ Generated by [AVA](https://avajs.dev). 'ChainHub Admin_singleton': 'Alleged: ChainHub Admin', CombinedInvitationMakers_kindHandle: 'Alleged: kind', StakingCombinationsInvitationMakers_kindHandle: 'Alleged: kind', + atomicProvider: { + localAccount: 'Alleged: Local Orchestration Account Kit holder', + }, orchestration: { depositAndDelegate: { asyncFlow_kindHandle: 'Alleged: kind', endowments: { 0: { - contractState_kindHandle: 'Alleged: kind', - contractState_singleton: 'Alleged: contractState', flows: { depositAndDelegate_kindHandle: 'Alleged: kind', depositAndDelegate_singleton: 'Alleged: depositAndDelegate', @@ -130,12 +131,13 @@ Generated by [AVA](https://avajs.dev). }, }, }, + localAccount: { + asyncFlow_kindHandle: 'Alleged: kind', + }, makeAccount: { asyncFlow_kindHandle: 'Alleged: kind', endowments: { 0: { - contractState_kindHandle: 'Alleged: kind', - contractState_singleton: 'Alleged: contractState', flows: { depositAndDelegate_kindHandle: 'Alleged: kind', depositAndDelegate_singleton: 'Alleged: depositAndDelegate', @@ -161,8 +163,6 @@ Generated by [AVA](https://avajs.dev). asyncFlow_kindHandle: 'Alleged: kind', endowments: { 0: { - contractState_kindHandle: 'Alleged: kind', - contractState_singleton: 'Alleged: contractState', flows: { depositAndDelegate_kindHandle: 'Alleged: kind', depositAndDelegate_singleton: 'Alleged: depositAndDelegate', diff --git a/packages/orchestration/test/examples/snapshots/staking-combinations.test.ts.snap b/packages/orchestration/test/examples/snapshots/staking-combinations.test.ts.snap index 406237967cd19ffb5aa5ec256a4d339d32f20cb7..05db3949b1dc5f9e00ffec8c63841acf608c13e3 100644 GIT binary patch literal 2527 zcmV<52_W`CRzVxEk00000000B+T5D_^R~7zdz3bhz_u+jwyX!~1e#TDY)Nzugse+K>#EMm? zvFtp63X;3C*Sk~C&MY&tcGH4TB#J1c1R^4S&>s+06-5XMP!-ZDN`D{$sz8Jvg&!3{ zC5mW-ghUYqgd*74-PxIY*N=5k5t9AG+MV-#=bpLe+;h&H*>5jpWK~?&FI}gGWX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kwt@QIrE=g{{=EPgI5D90053YsA2#B diff --git a/packages/orchestration/test/fixtures/zoe-tools.contract.js b/packages/orchestration/test/fixtures/zoe-tools.contract.js index 4ab64fe9cac9..81df2f8f6312 100644 --- a/packages/orchestration/test/fixtures/zoe-tools.contract.js +++ b/packages/orchestration/test/fixtures/zoe-tools.contract.js @@ -9,6 +9,7 @@ import { M } from '@endo/patterns'; import { withOrchestration } from '../../src/utils/start-helper.js'; import { prepareChainHubAdmin } from '../../src/exos/chain-hub-admin.js'; import * as flows from './zoe-tools.flows.js'; +import * as sharedFlows from '../../src/examples/shared.flows.js'; import fetchedChainInfo from '../../src/fetched-chain-info.js'; const { values } = Object; @@ -46,12 +47,17 @@ const contract = async ( zcf, privateArgs, zone, - { atomicProvider, chainHub, orchestrateAll, zoeTools }, + { atomicProvider, chainHub, orchestrate, orchestrateAll, vowTools, zoeTools }, ) => { const creatorFacet = prepareChainHubAdmin(zone, chainHub); + const sharedLocalAccount = await atomicProvider.provideAsync( + 'localAccount', + key => vowTools.when(orchestrate(key, {}, sharedFlows.makeLocalAccount)()), + ); + const orchFns = orchestrateAll(flows, { - atomicProvider, + sharedLocalAccount, zoeTools, }); @@ -60,7 +66,8 @@ const contract = async ( const assets = /** @type {AssetInfo[]} */ ( await E(E(privateArgs.agoricNames).lookup('vbankAsset')).values() ); - for (const chainName of ['agoric', 'cosmoshub']) { + // 'agoric' was registered by mocaLocalAccount above + for (const chainName of ['cosmoshub']) { chainHub.registerChain(chainName, fetchedChainInfo[chainName]); } for (const brand of values(zcf.getTerms().brands)) { diff --git a/packages/orchestration/test/fixtures/zoe-tools.flows.js b/packages/orchestration/test/fixtures/zoe-tools.flows.js index 803d5b9a2652..9e445a3fd8f9 100644 --- a/packages/orchestration/test/fixtures/zoe-tools.flows.js +++ b/packages/orchestration/test/fixtures/zoe-tools.flows.js @@ -12,6 +12,7 @@ const { values } = Object; /** * @import {GuestInterface} from '@agoric/async-flow'; * @import {AtomicProvider} from '@agoric/store/src/stores/store-utils.js'; + * @import {LocalOrchestrationAccountKit} from '../../src/exos/local-orchestration-account.js'; * @import {Orchestrator, LocalAccountMethods, OrchestrationAccountI, OrchestrationFlow, ChainAddress} from '@agoric/orchestration'; * @import {ZoeTools} from '../../src/utils/zoe-tools.js'; */ @@ -24,14 +25,14 @@ const { values } = Object; * @satisfies {OrchestrationFlow} * @param {Orchestrator} orch * @param {object} ctx - * @param {AtomicProvider} ctx.atomicProvider + * @param {GuestInterface} ctx.sharedLocalAccount * @param {GuestInterface} ctx.zoeTools * @param {ZCFSeat} seat * @param {{ destAddr: ChainAddress }} offerArgs */ export const depositSend = async ( orch, - { atomicProvider, zoeTools: { localTransfer, withdrawToSeat } }, + { sharedLocalAccount, zoeTools: { localTransfer, withdrawToSeat } }, seat, offerArgs, ) => { @@ -41,20 +42,12 @@ export const depositSend = async ( const { give } = seat.getProposal(); - const localAccount = await atomicProvider.provideAsync( - 'localAccount', - async () => { - const agoricChain = await orch.getChain('agoric'); - return agoricChain.makeAccount(); - }, - ); - - await localTransfer(seat, localAccount, give); + await localTransfer(seat, sharedLocalAccount, give); try { - await localAccount.sendAll(destAddr, values(give)); + await sharedLocalAccount.sendAll(destAddr, values(give)); } catch (error) { - await withdrawToSeat(localAccount, seat, give); + await withdrawToSeat(sharedLocalAccount, seat, give); const errMsg = makeError(`SendAll failed ${q(error)}`); seat.exit(errMsg); throw errMsg; @@ -70,27 +63,19 @@ harden(depositSend); * @satisfies {OrchestrationFlow} * @param {Orchestrator} orch * @param {object} ctx - * @param {AtomicProvider} ctx.atomicProvider + * @param {GuestInterface} ctx.sharedLocalAccount * @param {GuestInterface} ctx.zoeTools * @param {ZCFSeat} seat */ export const deposit = async ( orch, - { atomicProvider, zoeTools: { localTransfer } }, + { sharedLocalAccount, zoeTools: { localTransfer } }, seat, ) => { const { give } = seat.getProposal(); - const localAccount = await atomicProvider.provideAsync( - 'localAccount', - async () => { - const agoricChain = await orch.getChain('agoric'); - return agoricChain.makeAccount(); - }, - ); - try { - await localTransfer(seat, localAccount, give); + await localTransfer(seat, sharedLocalAccount, give); } catch (e) { seat.exit(e); throw e; @@ -105,27 +90,19 @@ harden(deposit); * @satisfies {OrchestrationFlow} * @param {Orchestrator} orch * @param {object} ctx - * @param {AtomicProvider} ctx.atomicProvider + * @param {GuestInterface} ctx.sharedLocalAccount * @param {GuestInterface} ctx.zoeTools * @param {ZCFSeat} seat */ export const withdraw = async ( orch, - { atomicProvider, zoeTools: { withdrawToSeat } }, + { sharedLocalAccount, zoeTools: { withdrawToSeat } }, seat, ) => { const { want } = seat.getProposal(); - const localAccount = await atomicProvider.provideAsync( - 'localAccount', - async () => { - const agoricChain = await orch.getChain('agoric'); - return agoricChain.makeAccount(); - }, - ); - try { - await withdrawToSeat(localAccount, seat, want); + await withdrawToSeat(sharedLocalAccount, seat, want); } catch (e) { seat.exit(e); throw e; diff --git a/packages/orchestration/test/snapshots/ibc-mocks.test.ts.md b/packages/orchestration/test/snapshots/ibc-mocks.test.ts.md index 5f53d4aa6bcb..3c44283847eb 100644 --- a/packages/orchestration/test/snapshots/ibc-mocks.test.ts.md +++ b/packages/orchestration/test/snapshots/ibc-mocks.test.ts.md @@ -15,3 +15,9 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 'eyJkYXRhIjoiQ2pvS0ZBb0xZMjl6Ylc5ek1YUmxjM1FTQlhWaGRHOXRFaUl2WTI5emJXOXpMbUpoYm1zdWRqRmlaWFJoTVM1UmRXVnllUzlDWVd4aGJtTmwiLCJtZW1vIjoiIn0=' + +## build Query Response + +> Snapshot 1 + + 'eyJyZXN1bHQiOiJleUprWVhSaElqb2lRMnhSZVZWbmNGRkRhbmRMUXpKT2RtTXlNWFpqZWtZd1dsaE9NRVZvU21waU0wNTBZak5PTWxsWGVIWmpSMVo1VFZoU2JHTXpVV0ZIVkVWM1RVUkJkMDFFUVhkTlJFRjNUVVJCZDAxRVFYZE5SRUYzVFVSQmQwMUVRVk5GUVc5R1pGZEdNR0l5TUZOQ2VrVjNUVVJCZDAxRVFUMGlmUT09In0=' diff --git a/packages/orchestration/test/snapshots/ibc-mocks.test.ts.snap b/packages/orchestration/test/snapshots/ibc-mocks.test.ts.snap index 4b5394256b18a1c6b75f2a615f881b4dec68718f..0464dbf7c877dfffdac8847030b5dd166065c870 100644 GIT binary patch literal 602 zcmV-g0;T;yRzV{R#lN8Xpc&YSeH)Y%mquO5<} z%KNgbleR0GzWef&Wl5hzzuwL+XVYE0o4tSYbC#cclt&BgRn2&R>#I1Tg;zD@)*2y1 z+TMt^B*;c_6$F_eXKspum=TLwVWMypno&^%bLMtquA70Iv7}f&3Mj&K1#PhEmqgiC zeD=o71lP1$Bw{rms3`6dPn0ogn=!5V5E2*>Z@b3kJrd`OX0fZ`#pyn!QU zPorIVf9v;B;N#TOtI@}Q_`_fP_Ax)4UiE)};r}-IpPAcZh~y$gqa>BSj`hyY6^^+X zD}o)i)rCl0y52<8Nw~HI^X%OC(I#q1%G)M3_?!v4r$#5j@f!vNb3-GjwdQBNoQ#R< z_sk5h8T#i2ns;qeclm#c_~P;fb`(GakOOqBh=#MlWJJYm|9K!d@N z4Y&L?i&_9AJy0MBroff2$kK5*6pCrzp;f>E{9C#FG*WP4xw1pb<1;uAZq0Te94IK; o<*>6UZe6*`0*bWFxZG?lIKaz1C$2V}p_^&8Kl@5E^#KC_01=fc0{{R3 literal 414 zcmV;P0b%|@RzVmQ2<00000000AZ&rNchFaSVdx1CPcy@8J)xhA`A92*-N;aWz2?1WJVkOahF zBeP3ay+PN>S#pD1D8nR+W-@&zc;Ef6)YJ#v{(ewh(HT{zr@~~@*iC=RgH~P9R>7~=*K&gGr7i_ zEyunjX2#;cQ#RyV-k_8;wXkr=7{0~UNalxiOc5j&b6Ocg2D2QEavgTD?cW)m0i0-@ IRLTJW08=f+F#rGn