@agoric/wallet-backend 0.13.4-dev-eb9fb38.0 → 0.13.4-dev-0a2843b.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/wallet-backend",
3
- "version": "0.13.4-dev-eb9fb38.0+eb9fb38",
3
+ "version": "0.13.4-dev-0a2843b.0+0a2843b",
4
4
  "description": "Wallet backend",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -14,23 +14,22 @@
14
14
  "lint:eslint": "eslint ."
15
15
  },
16
16
  "devDependencies": {
17
- "@agoric/vats": "0.13.1-dev-eb9fb38.0+eb9fb38",
17
+ "@agoric/vats": "0.13.1-dev-0a2843b.0+0a2843b",
18
18
  "@endo/bundle-source": "^2.5.1",
19
19
  "@endo/init": "^0.5.56",
20
20
  "ava": "^5.2.0"
21
21
  },
22
22
  "dependencies": {
23
- "@agoric/assert": "0.5.2-dev-eb9fb38.0+eb9fb38",
24
- "@agoric/cache": "0.2.4-dev-eb9fb38.0+eb9fb38",
25
- "@agoric/ertp": "0.15.4-dev-eb9fb38.0+eb9fb38",
26
- "@agoric/inter-protocol": "0.13.2-dev-eb9fb38.0+eb9fb38",
27
- "@agoric/internal": "0.2.2-dev-eb9fb38.0+eb9fb38",
28
- "@agoric/notifier": "0.5.2-dev-eb9fb38.0+eb9fb38",
29
- "@agoric/smart-wallet": "0.4.3-dev-eb9fb38.0+eb9fb38",
30
- "@agoric/store": "0.8.4-dev-eb9fb38.0+eb9fb38",
31
- "@agoric/time": "0.2.2-dev-eb9fb38.0+eb9fb38",
32
- "@agoric/vat-data": "0.4.4-dev-eb9fb38.0+eb9fb38",
33
- "@agoric/zoe": "0.25.4-dev-eb9fb38.0+eb9fb38",
23
+ "@agoric/assert": "0.5.2-dev-0a2843b.0+0a2843b",
24
+ "@agoric/cache": "0.2.4-dev-0a2843b.0+0a2843b",
25
+ "@agoric/ertp": "0.15.4-dev-0a2843b.0+0a2843b",
26
+ "@agoric/internal": "0.2.2-dev-0a2843b.0+0a2843b",
27
+ "@agoric/notifier": "0.5.2-dev-0a2843b.0+0a2843b",
28
+ "@agoric/smart-wallet": "0.4.3-dev-0a2843b.0+0a2843b",
29
+ "@agoric/store": "0.8.4-dev-0a2843b.0+0a2843b",
30
+ "@agoric/time": "0.2.2-dev-0a2843b.0+0a2843b",
31
+ "@agoric/vat-data": "0.4.4-dev-0a2843b.0+0a2843b",
32
+ "@agoric/zoe": "0.25.4-dev-0a2843b.0+0a2843b",
34
33
  "@endo/eventual-send": "^0.17.2",
35
34
  "@endo/marshal": "^0.8.5",
36
35
  "@endo/nat": "^4.1.27",
@@ -58,5 +57,5 @@
58
57
  "publishConfig": {
59
58
  "access": "public"
60
59
  },
61
- "gitHead": "eb9fb387ccaf9e2a1c5187c3926601824522b2a3"
60
+ "gitHead": "0a2843b787b998a57ca5977b00f9432bb7201607"
62
61
  }
package/src/lib-wallet.js CHANGED
@@ -43,7 +43,6 @@ import { makePaymentActions } from './actions.js';
43
43
 
44
44
  import '@agoric/store/exported.js';
45
45
  import '@agoric/zoe/exported.js';
46
- import '@agoric/inter-protocol/exported.js';
47
46
 
48
47
  import './internal-types.js';
49
48
  import './types.js';
@@ -598,35 +597,6 @@ export function makeWalletRoot({
598
597
  .then(update => updateOrResubscribe(id, seat, update));
599
598
  }
600
599
 
601
- /**
602
- * @param {() => ( Promise | undefined )} get - The function whose return value
603
- * to memoize.
604
- */
605
- const makeMemoizedGetter = get => {
606
- let pk;
607
- const doGet = () => pk.resolve(get());
608
-
609
- return () => {
610
- if (pk === undefined) {
611
- pk = makePromiseKit();
612
- doGet();
613
- }
614
- return pk.promise;
615
- };
616
- };
617
-
618
- const getAttIssuer = makeMemoizedGetter(() =>
619
- E(agoricNames)?.lookup('issuer', 'Attestation'),
620
- );
621
-
622
- /** @type import('@endo/promise-kit').PromiseKit<AttestationTool> */
623
- const attMakerPK = makePromiseKit();
624
-
625
- const { getAccountState } = E(attMakerPK.promise);
626
-
627
- const makeAttestationAmount = async bldAmount =>
628
- E(attMakerPK.promise).wrapLienedAmount(bldAmount);
629
-
630
600
  async function executeOffer(compiledOfferP) {
631
601
  // =====================
632
602
  // === AWAITING TURN ===
@@ -642,60 +612,20 @@ export function makeWalletRoot({
642
612
  /** @type {Map<Payment, Purse>} */
643
613
  const paymentToPurse = new Map();
644
614
 
645
- // Track which gives/wants are attestations.
646
- const keywordToAttestation = new Map();
647
-
648
615
  // We now have everything we need to provide Zoe, so do the actual withdrawals.
649
616
  // Payments are made for the keywords in proposal.give.
650
617
  const keywordPaymentPs = Object.entries(proposal.give || harden({})).map(
651
- async ([keyword, { type, ...amount }]) => {
618
+ async ([keyword, amount]) => {
652
619
  const purse = purseKeywordRecord[keyword];
653
620
  purse !== undefined ||
654
621
  Fail`purse was not found for keyword ${q(keyword)}`;
655
622
 
656
- if (type === 'Attestation') {
657
- const payment = await E(attMakerPK.promise).makeAttestation(amount);
658
-
659
- const attestationIssuer = await getAttIssuer();
660
-
661
- keywordToAttestation.set(
662
- keyword,
663
- await E(attestationIssuer).getAmountOf(payment),
664
- );
665
-
666
- return [keyword, payment];
667
- }
668
-
669
623
  const payment = await E(purse).withdraw(amount);
670
624
  paymentToPurse.set(payment, purse);
671
625
  return [keyword, payment];
672
626
  },
673
627
  );
674
628
 
675
- // Get Attestation-branded amounts for Attestastation "wants".
676
- await Promise.all(
677
- Object.entries(proposal.want || harden({})).map(
678
- async ([keyword, { type, ...amount }]) => {
679
- if (type === 'Attestation') {
680
- const attestationAmount = await makeAttestationAmount(amount);
681
- keywordToAttestation.set(keyword, attestationAmount);
682
- }
683
- },
684
- ),
685
- );
686
-
687
- const depositAttestation = async payoutP => {
688
- const [issuer, payout] = await Promise.all([getAttIssuer(), payoutP]);
689
-
690
- const amount = await E(issuer).getAmountOf(payout);
691
- const invitation = await E(attMakerPK.promise).makeReturnAttInvitation();
692
- const depositProposal = harden({ give: { Attestation: amount } });
693
- const payments = harden({ Attestation: payout });
694
-
695
- const userSeat = E(zoe).offer(invitation, depositProposal, payments);
696
- await E(userSeat).getOfferResult();
697
- };
698
-
699
629
  // Try reclaiming any of our payments that we successfully withdrew, but
700
630
  // were left unclaimed.
701
631
  const tryReclaimingWithdrawnPayments = () =>
@@ -705,11 +635,7 @@ export function makeWalletRoot({
705
635
  keywordPaymentPs.map(async keywordPaymentP => {
706
636
  // Wait for the withdrawal to complete. This protects against a race
707
637
  // when updating paymentToPurse.
708
- const [keyword, payment] = await keywordPaymentP;
709
-
710
- if (keywordToAttestation.has(keyword)) {
711
- return depositAttestation(payment);
712
- }
638
+ const [_keyword, payment] = await keywordPaymentP;
713
639
 
714
640
  // Find out where it came from.
715
641
  const purse = paymentToPurse.get(payment);
@@ -745,27 +671,6 @@ export function makeWalletRoot({
745
671
 
746
672
  const paymentKeywordRecord = harden(Object.fromEntries(paymentKeywords));
747
673
 
748
- // Convert gives'/wants' BLD amounts to Attestation amounts for
749
- // Attestations.
750
- const convertToAttestationAmounts = ([keyword, { type, ...amount }]) => {
751
- if (type === 'Attestation') {
752
- amount = keywordToAttestation.get(keyword);
753
- }
754
- return [keyword, amount];
755
- };
756
-
757
- if (proposal.give) {
758
- proposal.give = Object.fromEntries(
759
- Object.entries(proposal.give).map(convertToAttestationAmounts),
760
- );
761
- }
762
-
763
- if (proposal.want) {
764
- proposal.want = Object.fromEntries(
765
- Object.entries(proposal.want).map(convertToAttestationAmounts),
766
- );
767
- }
768
-
769
674
  const seat = E(zoe).offer(
770
675
  inviteP,
771
676
  harden(proposal),
@@ -783,10 +688,6 @@ export function makeWalletRoot({
783
688
  .then(payoutObj => {
784
689
  return Promise.all(
785
690
  Object.entries(payoutObj).map(([keyword, payoutP]) => {
786
- if (keywordToAttestation.has(keyword)) {
787
- return depositAttestation(payoutP);
788
- }
789
-
790
691
  // We try to find a purse for this keyword, but even if we don't,
791
692
  // we still make it a normal incoming payment.
792
693
  const purseOrUndefined = purseKeywordRecord[keyword];
@@ -1013,7 +914,7 @@ export function makeWalletRoot({
1013
914
  const compile = amountKeywordRecord => {
1014
915
  return Object.fromEntries(
1015
916
  Object.entries(amountKeywordRecord).map(
1016
- ([keyword, { pursePetname, value, type }]) => {
917
+ ([keyword, { pursePetname, value }]) => {
1017
918
  // Automatically convert numbers to Nats.
1018
919
  if (typeof value === 'number') {
1019
920
  value = Nat(value);
@@ -1022,7 +923,7 @@ export function makeWalletRoot({
1022
923
  purseKeywordRecord[keyword] = purse;
1023
924
  const brand = purseToBrand.get(purse);
1024
925
 
1025
- return [keyword, { brand, value, type }];
926
+ return [keyword, { brand, value }];
1026
927
  },
1027
928
  ),
1028
929
  );
@@ -1845,15 +1746,11 @@ export function makeWalletRoot({
1845
1746
  return E(firstValue).lookup(...remaining);
1846
1747
  },
1847
1748
  getMarshaller: () => marshaller,
1848
- resolveAttMaker: attMaker => attMakerPK.resolve(attMaker),
1849
- getAttMaker: () => attMakerPK.promise,
1850
1749
  getDappCacheCoordinator: dappOrigin =>
1851
1750
  dappOrigins.get(dappOrigin).cacheCoordinator,
1852
1751
  getCacheCoordinator: () => sharedCacheCoordinator,
1853
1752
  saveOfferResult,
1854
1753
  getOfferResult,
1855
- getAccountState,
1856
- makeAttestationAmount,
1857
1754
  waitForDappApproval,
1858
1755
  getDappsNotifier() {
1859
1756
  return dappsNotifier;
package/src/wallet.js CHANGED
@@ -186,10 +186,6 @@ export function buildRootObject(vatPowers) {
186
186
  await approve();
187
187
  return walletAdmin.addOffer(offer, { ...meta, dappOrigin });
188
188
  },
189
- async getAccountState() {
190
- await approve();
191
- return walletAdmin.getAccountState();
192
- },
193
189
  async getOffersNotifier(status = null) {
194
190
  await approve();
195
191
  const { notifier, updater } = makeNotifierKit(inboxState);
@@ -43,13 +43,12 @@ const test = anyTest;
43
43
  * zoe: ZoeService,
44
44
  * automaticRefundInstallation: Installation,
45
45
  * autoswapInstallation: Installation,
46
- * attestationInstallation: Installation,
47
46
  * }} LibWalletTestContext
48
47
  */
49
48
 
50
49
  async function setupTest(
51
50
  /** @type {import('ava').ExecutionContext<LibWalletTestContext>} */ t,
52
- { autoswap = false, automaticRefund = false, attestation = false } = {},
51
+ { autoswap = false, automaticRefund = false } = {},
53
52
  ) {
54
53
  const pursesStateChangeLog = [];
55
54
  const inboxStateChangeLog = [];
@@ -97,71 +96,24 @@ async function setupTest(
97
96
  instance: null,
98
97
  };
99
98
 
100
- const attestationP = (attestation &&
101
- (async () => {
102
- const { publicFacet, instance } = await E(t.context.zoe).startInstance(
103
- t.context.attestationInstallation,
104
- );
105
- const {
106
- issuers: { Attestation: issuer },
107
- brands: { Attestation: brand },
108
- } = await E(t.context.zoe).getTerms(instance);
109
-
110
- const names = {
111
- lookup: (/** @type {string[]} */ ...namePath) => {
112
- if (namePath[0] === 'issuer' && namePath[1] === 'Attestation') {
113
- return issuer;
114
- }
115
- return null;
116
- },
117
- };
118
- return { names, issuer, brand, publicFacet };
119
- })()) || {
120
- names: null,
121
- issuer: null,
122
- brand: null,
123
- publicFacet: null,
124
- };
125
-
126
99
  const [
127
100
  {
128
101
  creatorInvitation: automaticRefundInvitation,
129
102
  instance: automaticRefundInstance,
130
103
  },
131
104
  { invite: addLiquidityInvite, instance: autoswapInstanceHandle },
132
- {
133
- names: fakeAgoricNames,
134
- issuer: attestationIssuer,
135
- brand: attestationBrand,
136
- publicFacet: attestationPublicFacet,
137
- },
138
- ] = await Promise.all([automaticRefundP, autoswapP, attestationP]);
105
+ ] = await Promise.all([automaticRefundP, autoswapP]);
139
106
 
140
107
  const { admin: wallet, initialized } = makeWalletRoot({
141
108
  zoe: t.context.zoe,
142
109
  board,
143
110
  myAddressNameAdmin: makeFakeMyAddressNameAdmin(),
144
- // @ts-expect-error
145
- agoricNames: fakeAgoricNames,
146
111
  pursesStateChangeHandler,
147
112
  inboxStateChangeHandler,
148
113
  });
149
114
  await initialized;
150
115
 
151
- if (attestation) {
152
- assert(attestationBrand);
153
- wallet.resolveAttMaker({
154
- makeReturnAttInvitation: attestationPublicFacet.makeReturnAttInvitation,
155
- makeAttestation: (/** @type {any} */ value) =>
156
- attestationPublicFacet.mintAttestation(value),
157
- wrapLienedAmount: ({ value }) => AmountMath.make(attestationBrand, value),
158
- });
159
- }
160
-
161
116
  return {
162
- attestationIssuer,
163
- attestationPublicFacet,
164
- attestationBrand,
165
117
  moolaBundle,
166
118
  simoleanBundle,
167
119
  rpgBundle,
@@ -212,20 +164,10 @@ test.before(async t => {
212
164
  const autoswapBundle = await bundleSource(autoswapContractRoot);
213
165
  const autoswapInstallation = await E(zoe).install(autoswapBundle);
214
166
 
215
- // Create attestationExample instance
216
- const url = await importMetaResolve(
217
- './attestationExample.js',
218
- import.meta.url,
219
- );
220
- const path = new URL(url).pathname;
221
- const attestationBundle = await bundleSource(path);
222
- const attestationInstallation = await E(zoe).install(attestationBundle);
223
-
224
167
  t.context = {
225
168
  zoe,
226
169
  automaticRefundInstallation,
227
170
  autoswapInstallation,
228
- attestationInstallation,
229
171
  };
230
172
  });
231
173
 
@@ -1303,157 +1245,6 @@ test('lib-wallet performAction acceptOffer', async t => {
1303
1245
  );
1304
1246
  });
1305
1247
 
1306
- test('lib-wallet can give attestations in offers', async t => {
1307
- const {
1308
- wallet,
1309
- attestationPublicFacet,
1310
- attestationBrand,
1311
- attestationIssuer,
1312
- } = await setupTest(t, { attestation: true });
1313
-
1314
- assert(attestationIssuer);
1315
- assert(attestationBrand);
1316
- const issuerManager = wallet.getIssuerManager();
1317
- await issuerManager.add('Attestation', attestationIssuer);
1318
- await wallet.makeEmptyPurse('Attestation', 'staking purse');
1319
-
1320
- const invitation = await attestationPublicFacet.makeReturnAttInvitation();
1321
-
1322
- const rawId = '123-arbitrary';
1323
- const id = `unknown#${rawId}`;
1324
- const offer = {
1325
- id: rawId,
1326
- invitation,
1327
- proposalTemplate: {
1328
- give: {
1329
- Attestation: {
1330
- pursePetname: 'staking purse',
1331
- value: 30n,
1332
- type: 'Attestation',
1333
- },
1334
- },
1335
- exit: {
1336
- onDemand: null,
1337
- },
1338
- },
1339
- };
1340
-
1341
- await wallet.addOffer(offer);
1342
- const accepted = await wallet.acceptOffer(id);
1343
- assert(accepted);
1344
- const { depositedP } = accepted;
1345
- await depositedP;
1346
-
1347
- // There should be two calls. The first is call to give the attestation
1348
- // as proposed. The second call is to return the unallocated attestation
1349
- // back to the attMaker (which in this test uses the same method).
1350
- const callHistory = await attestationPublicFacet.getCallHistory();
1351
- t.deepEqual(callHistory.returnProposals, [
1352
- {
1353
- exit: {
1354
- onDemand: null,
1355
- },
1356
- give: {
1357
- Attestation: AmountMath.make(attestationBrand, 30n),
1358
- },
1359
- want: {},
1360
- },
1361
- {
1362
- exit: {
1363
- onDemand: null,
1364
- },
1365
- give: {
1366
- Attestation: AmountMath.make(attestationBrand, 30n),
1367
- },
1368
- want: {},
1369
- },
1370
- ]);
1371
- t.deepEqual(callHistory.returnAllocations, [
1372
- {
1373
- Attestation: AmountMath.make(attestationBrand, 30n),
1374
- },
1375
- {
1376
- Attestation: AmountMath.make(attestationBrand, 30n),
1377
- },
1378
- ]);
1379
- });
1380
-
1381
- test('lib-wallet can want attestations in offers', async t => {
1382
- const {
1383
- wallet,
1384
- attestationPublicFacet,
1385
- attestationBrand,
1386
- attestationIssuer,
1387
- } = await setupTest(t, { attestation: true });
1388
-
1389
- assert(attestationIssuer);
1390
- assert(attestationBrand);
1391
- const issuerManager = wallet.getIssuerManager();
1392
- await issuerManager.add('Attestation', attestationIssuer);
1393
- await wallet.makeEmptyPurse('Attestation', 'staking purse');
1394
-
1395
- const invitation = await attestationPublicFacet.makeWantAttInvitation();
1396
-
1397
- const rawId = '123-arbitrary';
1398
- const id = `unknown#${rawId}`;
1399
- const offer = {
1400
- id: rawId,
1401
- invitation,
1402
- proposalTemplate: {
1403
- want: {
1404
- Attestation: {
1405
- pursePetname: 'staking purse',
1406
- value: 65n,
1407
- type: 'Attestation',
1408
- },
1409
- },
1410
- exit: {
1411
- onDemand: null,
1412
- },
1413
- },
1414
- };
1415
-
1416
- await wallet.addOffer(offer);
1417
- const accepted = await wallet.acceptOffer(id);
1418
- assert(accepted);
1419
- const { depositedP } = accepted;
1420
- await depositedP;
1421
-
1422
- const callHistory = await attestationPublicFacet.getCallHistory();
1423
- t.deepEqual(callHistory.wantProposals, [
1424
- {
1425
- exit: {
1426
- onDemand: null,
1427
- },
1428
- want: {
1429
- Attestation: AmountMath.make(attestationBrand, 65n),
1430
- },
1431
- give: {},
1432
- },
1433
- ]);
1434
- t.deepEqual(callHistory.wantAllocations, [
1435
- { Attestation: AmountMath.make(attestationBrand, 0n) },
1436
- ]);
1437
- // When an attestation payout is recieved, the wallet should return it to the
1438
- // attMaker:
1439
- t.deepEqual(callHistory.returnProposals, [
1440
- {
1441
- exit: {
1442
- onDemand: null,
1443
- },
1444
- give: {
1445
- Attestation: AmountMath.make(attestationBrand, 65n),
1446
- },
1447
- want: {},
1448
- },
1449
- ]);
1450
- t.deepEqual(callHistory.returnAllocations, [
1451
- {
1452
- Attestation: AmountMath.make(attestationBrand, 65n),
1453
- },
1454
- ]);
1455
- });
1456
-
1457
1248
  test('addOffer invitationQuery', async t => {
1458
1249
  const {
1459
1250
  moolaBundle,
@@ -1,65 +0,0 @@
1
- // @ts-check
2
- import '@agoric/zoe/exported.js';
3
- import { AmountMath } from '@agoric/ertp';
4
- import { E } from '@endo/eventual-send';
5
- import { Far } from '@endo/marshal';
6
-
7
- /** @param {ZCF} zcf */
8
- export const start = async zcf => {
9
- const mint = await zcf.makeZCFMint('Attestation');
10
- const { brand } = await mint.getIssuerRecord();
11
- const callHistory = {
12
- /** @type Array<string> */
13
- wantProposals: [],
14
- /** @type Array<string> */
15
- wantAllocations: [],
16
- /** @type Array<string> */
17
- returnProposals: [],
18
- /** @type Array<string> */
19
- returnAllocations: [],
20
- };
21
-
22
- const mintAttestation = ({ value }) => {
23
- const { userSeat, zcfSeat } = zcf.makeEmptySeatKit();
24
- mint.mintGains({ Attestation: AmountMath.make(brand, value) }, zcfSeat);
25
- zcfSeat.exit();
26
- return E(userSeat).getPayout('Attestation');
27
- };
28
-
29
- const handleWantAtt = seat => {
30
- const proposal = seat.getProposal();
31
- callHistory.wantProposals.push(proposal);
32
- callHistory.wantAllocations.push(seat.getCurrentAllocation());
33
- mint.mintGains(
34
- { Attestation: AmountMath.make(brand, proposal.want.Attestation.value) },
35
- seat,
36
- );
37
- seat.exit();
38
- return 'good job';
39
- };
40
-
41
- const handleReturnAtt = seat => {
42
- const proposal = seat.getProposal();
43
- callHistory.returnProposals.push(proposal);
44
- callHistory.returnAllocations.push(seat.getCurrentAllocation());
45
- seat.exit();
46
- return 'thank you for that';
47
- };
48
-
49
- const makeWantAttInvitation = () =>
50
- zcf.makeInvitation(handleWantAtt, 'WantAtt');
51
-
52
- const makeReturnAttInvitation = () =>
53
- zcf.makeInvitation(handleReturnAtt, 'ReturnAtt');
54
-
55
- const getCallHistory = () => callHistory;
56
-
57
- const publicFacet = Far('attestation public facet', {
58
- mintAttestation,
59
- makeWantAttInvitation,
60
- makeReturnAttInvitation,
61
- getCallHistory,
62
- });
63
-
64
- return harden({ publicFacet });
65
- };