Skip to content

Commit 1efc171

Browse files
committed
fixup! zoe
1 parent 48b7c40 commit 1efc171

File tree

5 files changed

+38
-9
lines changed

5 files changed

+38
-9
lines changed

packages/ERTP/src/amountMath.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const helpers = {
8383
* @param {V} value
8484
* @returns {AssetKind}
8585
*/
86-
const assertValueGetAssetKind = value => {
86+
export const assertValueGetAssetKind = value => {
8787
const kind = kindOf(value);
8888
switch (kind) {
8989
case 'bigint': {

packages/ERTP/src/purse.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { M, makeCopySet } from '@agoric/store';
33
import { AmountMath } from './amountMath.js';
44
import { makeTransientNotifierKit } from './transientNotifier.js';
55
import { makeAmountStore } from './amountStore.js';
6+
import { kindOf } from '@endo/patterns';
67

78
/** @import {AssetKind, RecoverySetsOption, Brand, Payment} from './types.js' */
89

@@ -114,10 +115,16 @@ export const preparePurseKind = (
114115

115116
const optRecoverySet = maybeRecoverySet(state);
116117
const balanceStore = makeAmountStore(state, 'currentBalance');
118+
let amount;
119+
if (kindOf(amountBound) === 'match:containerHas') {
120+
throw Fail`TODO handle match:containerHas`;
121+
} else {
122+
amount = amountBound;
123+
}
117124
// Note COMMIT POINT within withdrawInternal.
118125
const payment = withdrawInternal(
119126
balanceStore,
120-
amountBound,
127+
amount,
121128
optRecoverySet,
122129
);
123130
updateBalance(purse, balanceStore.getAmount());

packages/zoe/src/zoeService/escrowStorage.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AmountMath } from '@agoric/ertp';
1+
import { AmountMath, assertValueGetAssetKind } from '@agoric/ertp';
22
import { E } from '@endo/eventual-send';
33
import { q, Fail } from '@endo/errors';
44
import { deeplyFulfilledObject, objectMap } from '@agoric/internal';
@@ -10,16 +10,30 @@ import './internal-types.js';
1010
import { 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,

packages/zoe/src/zoeService/zoeStorageManager.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ export const makeZoeStorageManager = (
7171
// EscrowStorage holds the purses that Zoe uses for escrow. This
7272
// object should be closely held and tracked: all of the digital
7373
// assets that users escrow are contained within these purses.
74-
const escrowStorage = provideEscrowStorage(zoeBaggage);
74+
const escrowStorage = provideEscrowStorage(zoeBaggage, brand =>
75+
issuerStorage.getAssetKindByBrand(brand),
76+
);
7577

7678
// Add a purse for escrowing user funds (not for fees). Create the
7779
// local, non-remote escrow purse for the fee mint immediately.

packages/zoe/test/unitTests/zoe/escrowStorage.test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { test } from '@agoric/swingset-vat/tools/prepare-test-env-ava.js';
2-
import { AmountMath, makeIssuerKit, AssetKind } from '@agoric/ertp';
3-
2+
import { Fail } from '@endo/errors';
43
import { E } from '@endo/eventual-send';
4+
5+
import { AmountMath, makeIssuerKit, AssetKind } from '@agoric/ertp';
56
import { makeScalarBigMapStore } from '@agoric/vat-data';
67
import { provideEscrowStorage } from '../../../src/zoeService/escrowStorage.js';
78
import {
@@ -13,6 +14,7 @@ test('provideEscrowStorage', async t => {
1314
const { createPurse, provideLocalPurse, withdrawPayments, depositPayments } =
1415
provideEscrowStorage(
1516
makeScalarBigMapStore('zoe baggage', { durable: true }),
17+
_brand => 'nat',
1618
);
1719

1820
const stableKit = makeIssuerKit(
@@ -138,6 +140,7 @@ const setupPurses = async createPurse => {
138140
test('payments without matching give keywords', async t => {
139141
const { createPurse, depositPayments } = provideEscrowStorage(
140142
makeScalarBigMapStore('zoe baggage', { durable: true }),
143+
_brand => Fail`Not in a mock test`,
141144
);
142145

143146
const { ticketKit, stableKit } = await setupPurses(createPurse);
@@ -175,6 +178,7 @@ test('payments without matching give keywords', async t => {
175178
test(`give keywords without matching payments`, async t => {
176179
const { createPurse, depositPayments } = provideEscrowStorage(
177180
makeScalarBigMapStore('zoe baggage', { durable: true }),
181+
_brand => Fail`Not in a mock test`,
178182
);
179183

180184
const { ticketKit, stableKit } = await setupPurses(createPurse);

0 commit comments

Comments
 (0)