diff --git a/packages/vats/src/orch-purse/mock-orch-chain.js b/packages/vats/src/orch-purse/mock-orch-chain.js index 189edd797fa0..ae30fbeb1d48 100644 --- a/packages/vats/src/orch-purse/mock-orch-chain.js +++ b/packages/vats/src/orch-purse/mock-orch-chain.js @@ -16,14 +16,6 @@ import { * @import {Zone} from '@agoric/base-zone' */ -const makeMinDenomInfo = (chain, _denom) => { - const brand = {}; // TODO the whole thing - return harden({ - brand, - chain, - }); -}; - /** * @param {Zone} zone */ @@ -31,28 +23,28 @@ export const prepareMinOrchestrator = zone => { const makeMinOrchAccount = zone.exoClass( 'MinOrchAccount', MinOrchAccountI, - (chain, ledger) => { - const addrValue = `${ledger.size()}`; - return { chain, ledger, addrValue }; + (chains, denoms, accounts, chain) => { + const acctAddrValue = `${accounts.size()}`; + return { chains, denoms, accounts, chain, acctAddrValue }; }, { getAddress() { - const { chain, addrValue: value } = this.state; + const { chain, acctAddrValue } = this.state; const { chainId } = chain.getChainInfo(); - return harden({ chainId, value }); + return harden({ chainId, value: acctAddrValue }); }, getBalances() { - const { ledger, addrValue } = this.state; - const { balances } = ledger.get(addrValue); + const { ledger, acctAddrValue } = this.state; + const { balances } = ledger.get(acctAddrValue); return [...balances.values()]; }, getBalance(denom) { - const { ledger, addrValue } = this.state; - const { balances } = ledger.get(addrValue); + const { ledger, acctAddrValue } = this.state; + const { balances } = ledger.get(acctAddrValue); return balances.get(denom); }, - transfer(destAddr, denomAmount) { - + transfer(_destAddr, _denomAmount) { + // TODO }, }, ); @@ -60,19 +52,10 @@ export const prepareMinOrchestrator = zone => { const makeMinChain = zone.exoClass( 'MinChain', MinChainI, - chainName => ({ + (chains, denoms, chainName) => ({ + chains, + denoms, chainId: chainName, - denoms: zone.mapStore('denoms', { - keyShape: M.string(), // denom - valueShape: MinDenomInfoShape, - }), - ledger: zone.mapStore('accounts', { - keyShape: M.string(), // addrValue - valueShape: { - account: MinOrchAccountShape, - balances: M.remotable('balances'), - }, - }), }), { getChainInfo() { @@ -80,12 +63,14 @@ export const prepareMinOrchestrator = zone => { return harden({ chainId }); }, makeAccount() { - const { ledger } = this.state; const { self } = this; - const account = makeMinOrchAccount(self, ledger); - const { value: addrValue } = account.getAddress(); - ledger.init( - addrValue, + const { chains, denoms, chainId } = this.state; + const { accounts } = chains.get(chainId); + + const account = makeMinOrchAccount(chains, denoms, accounts, self); + const { value: acctAddrValue } = account.getAddress(); + accounts.init( + acctAddrValue, harden({ account, balances: zone.mapStore('balances', { @@ -96,16 +81,8 @@ export const prepareMinOrchestrator = zone => { ); return account; }, - getDenomInfo(denom) { - const { denoms } = this.state; - const { self } = this; - return provideLazy(denoms, denom, d => makeMinDenomInfo(self, d)); - }, - asAmount(denomAmount) { - const { self } = this; - const { denom, value } = denomAmount; - const { brand } = self.getDenomInfo(denom); - return AmountMath.make(brand, value); + makeDenom(_denom) { + // TODO return orchIssuerKit }, }, ); @@ -115,14 +92,48 @@ export const prepareMinOrchestrator = zone => { MinOrchestratorI, () => ({ chains: zone.mapStore('chains', { - keyShape: M.string(), - valueShape: MinChainShape, + keyShape: M.string(), // chainName === chainId + valueShape: { + chain: MinChainShape, + denoms: M.remotable('denoms'), + accounts: M.remotable('accounts'), + }, + }), + denoms: zone.mapStore('denoms', { + keyShape: M.string(), // denom + valueShape: MinDenomInfoShape, }), }), { getChain(chainName) { - const { chains } = this.state; - return provideLazy(chains, chainName, makeMinChain); + const { chains, denoms } = this.state; + const { chain } = provideLazy(chains, chainName, cName => { + const ch = makeMinChain(chains, denoms, cName); + chains.init( + chainName, + harden({ + ch, + accounts: zone.mapStore('accounts', { + keyShape: M.string(), // acctAddrValue + valueShape: { + account: MinOrchAccountShape, + balances: M.remotable('balances'), + }, + }), + }), + ); + }); + return chain; + }, + getDenomInfo(denom) { + const { denoms } = this.state; + return denoms.get(denom); + }, + asAmount(denomAmount) { + const { self } = this; + const { denom, value } = denomAmount; + const { brand } = self.getDenomInfo(denom); + return AmountMath.make(brand, value); }, }, ); diff --git a/packages/vats/src/orch-purse/typeGuards.js b/packages/vats/src/orch-purse/typeGuards.js index 8ad2dc75e6eb..0df8582efd92 100644 --- a/packages/vats/src/orch-purse/typeGuards.js +++ b/packages/vats/src/orch-purse/typeGuards.js @@ -62,9 +62,8 @@ export const MinChainI = M.interface('MinChain', { getChainInfo: M.call().returns(M.eref(ChainInfoShape)), makeAccount: M.call().returns(M.eref(MinOrchAccountShape)), - // In the real API, these are on OrchestratorI - getDenomInfo: M.call(DenomShape).returns(MinDenomInfoShape), - asAmount: M.call(DenomAmountShape).returns(AmountShape), + // TODO returns(OrchIssuerKitShape) + makeDenom: M.call(DenomShape).returns(M.any()), }); /** @@ -73,6 +72,8 @@ export const MinChainI = M.interface('MinChain', { */ export const MinOrchestratorI = M.interface('MinOrchestrator', { getChain: M.call(M.string()).returns(M.eref(MinChainShape)), + getDenomInfo: M.call(DenomShape).returns(MinDenomInfoShape), + asAmount: M.call(DenomAmountShape).returns(AmountShape), }); // //////////////////////// ERTP-like ////////////////////////////////////////// diff --git a/packages/vats/src/orch-purse/types.ts b/packages/vats/src/orch-purse/types.ts index 41bb0e566275..79d25bfcaa58 100644 --- a/packages/vats/src/orch-purse/types.ts +++ b/packages/vats/src/orch-purse/types.ts @@ -13,7 +13,7 @@ import type { Denom, DenomAmount, ChainAddress } from '@agoric/orchestration'; */ export type MinChainAcctAddr = { chainId: string; - value: string; + value: string; // acctAddrValue }; /** @@ -50,9 +50,7 @@ export type MinChain = { getChainInfo(): ERef; makeAccount(): ERef; - // In the real API, these are on Orchestrator - getDenomInfo(denom: Denom): MinDenomInfo; - asAmount(denomAmount: DenomAmount): Amount; + makeDenom(denom: Denom): any; // TODO OrchIssuerKit }; /** @@ -60,6 +58,8 @@ export type MinChain = { */ export type MinOrchestrator = { getChain(chainName: string): ERef; + getDenomInfo(denom: Denom): MinDenomInfo; + asAmount(denomAmount: DenomAmount): Amount; }; // //////////////////////// ERTP-like //////////////////////////////////////////