1- import { AmountMath } from '@agoric/ertp' ;
1+ import { AmountMath , assertValueGetAssetKind } from '@agoric/ertp' ;
22import { E } from '@endo/eventual-send' ;
33import { q , Fail } from '@endo/errors' ;
44import { deeplyFulfilledObject , objectMap } from '@agoric/internal' ;
@@ -10,16 +10,30 @@ import './internal-types.js';
1010import { cleanKeywords } from '../cleanProposal.js' ;
1111
1212/**
13- * @import {LegacyWeakMap, WeakMapStore} from '@agoric/store';
13+ * @import {WeakMapStore} from '@agoric/store';
1414 */
1515
1616/**
1717 * Store the pool purses whose purpose is to escrow assets, with one
1818 * purse per brand.
1919 *
2020 * @param {import('@agoric/vat-data').Baggage } baggage
21+ * @param {GetAssetKindByBrand } _getAssetKindByBrand
2122 */
22- export const provideEscrowStorage = baggage => {
23+ export const provideEscrowStorage = ( baggage , _getAssetKindByBrand ) => {
24+ const getAssetKindByAmount = amount => {
25+ const { /* brand, */ value } = amount ;
26+ // const ak1 = getAssetKindByBrand(brand);
27+ const ak2 = assertValueGetAssetKind ( value ) ;
28+ // TODO this fails in escrowStorage.test.js, likely meaning we
29+ // don't do enough checking elsewhere that the storage assetKind is the
30+ // assetKind of the value.
31+ // ak1 === ak2 ||
32+ // // line break for ease of interactive breakpointing
33+ // Fail`${q(ak1)} must === ${q(ak2)}`;
34+ return ak2 ;
35+ } ;
36+
2337 /** @type {WeakMapStore<Brand, Purse> } */
2438 const brandToPurse = provideDurableWeakMapStore ( baggage , 'brandToPurse' ) ;
2539
@@ -112,7 +126,9 @@ export const provideEscrowStorage = baggage => {
112126 const deposits = await deeplyFulfilledObject ( depositPs ) ;
113127
114128 const initialAllocation = harden ( {
115- ...objectMap ( want , amount => AmountMath . makeEmptyFromAmount ( amount ) ) ,
129+ ...objectMap ( want , amount =>
130+ AmountMath . makeEmpty ( amount . brand , getAssetKindByAmount ( amount ) ) ,
131+ ) ,
116132 // Deposits should win in case of overlapping give/want keywords
117133 // (which are not allowed as of 2024-01).
118134 ...deposits ,
0 commit comments