Skip to content

Commit

Permalink
Merge pull request #8071 from Agoric/7226-sw-nft-issuer
Browse files Browse the repository at this point in the history
feat(smart-wallet): trading in well-known non-vbank assets
  • Loading branch information
dckc authored and mhofman committed Aug 7, 2023
2 parents c1eb2b9 + ca09526 commit d619852
Show file tree
Hide file tree
Showing 14 changed files with 713 additions and 37 deletions.
2 changes: 2 additions & 0 deletions packages/boot/test/bootstrapTests/drivers.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export const makeWalletFactoryDriver = async (
storage.data,
`published.wallet.${walletAddress}.current`,
fromCapData,
-1,
);
},

Expand All @@ -121,6 +122,7 @@ export const makeWalletFactoryDriver = async (
storage.data,
`published.wallet.${walletAddress}`,
fromCapData,
-1,
);
},
});
Expand Down
2 changes: 1 addition & 1 deletion packages/boot/test/bootstrapTests/supports.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ export const makeSwingsetTestKit = async (
const { fromCapData } = boardSlottingMarshaller(slotToBoardRemote);

const readLatest = path => {
const data = unmarshalFromVstorage(storage.data, path, fromCapData);
const data = unmarshalFromVstorage(storage.data, path, fromCapData, -1);
trace('readLatest', path, 'returning', inspect(data, false, 20, true));
return data;
};
Expand Down
7 changes: 6 additions & 1 deletion packages/boot/test/bootstrapTests/test-vaults-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,12 @@ test('propose change to auction governance param', async t => {

const { fromCapData } = makeMarshal(undefined, slotToBoardRemote);
const key = `published.committees.Economic_Committee.latestQuestion`;
const lastQuestion = unmarshalFromVstorage(storage.data, key, fromCapData);
const lastQuestion = unmarshalFromVstorage(
storage.data,
key,
fromCapData,
-1,
);
const changes = lastQuestion?.issue?.spec?.changes;
t.log('check Economic_Committee.latestQuestion against proposal');
t.like(changes, { StartFrequency: { relValue: 300n } });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ test('want stable', async t => {
t.log('Fund the wallet');
assert(anchor.mint);
const payment = anchor.mint.mintPayment(anchor.make(swapSize));
// @ts-expect-error deposit does take a FarRef<Payment>
await wallet.getDepositFacet().receive(payment);

t.log('Execute the swap');
Expand Down Expand Up @@ -169,7 +168,6 @@ test('want stable (insufficient funds)', async t => {
t.log('Fund the wallet insufficiently');
assert(anchor.mint);
const payment = anchor.mint.mintPayment(anchor.make(anchorFunding));
// @ts-expect-error deposit does take a FarRef<Payment>
await wallet.getDepositFacet().receive(payment);

t.log('Execute the swap');
Expand Down Expand Up @@ -382,10 +380,9 @@ test('deposit multiple payments to unknown brand', async t => {
// assume that if the call succeeds then it's in durable storage.
for await (const amt of [1n, 2n]) {
const payment = rial.mint.mintPayment(rial.make(amt));
// @ts-expect-error deposit does take a FarRef<Payment>
const result = await wallet.getDepositFacet().receive(harden(payment));
// successful request but not deposited
t.deepEqual(result, { brand: rial.brand, value: 0n });
await t.throwsAsync(wallet.getDepositFacet().receive(harden(payment)), {
message: /cannot deposit .*: no purse/,
});
}
});

Expand Down
7 changes: 4 additions & 3 deletions packages/internal/src/marshal.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ harden(assertCapData);
* @param {Map<string, string>} data
* @param {string} key
* @param {ReturnType<typeof import('@endo/marshal').makeMarshal>['fromCapData']} fromCapData
* @param {number} [index] index of the desired value in a deserialized stream cell
* @param {number} index index of the desired value in a deserialized stream cell
*/
export const unmarshalFromVstorage = (data, key, fromCapData, index = -1) => {
export const unmarshalFromVstorage = (data, key, fromCapData, index) => {
const serialized = data.get(key) || Fail`no data for ${key}`;
assert.typeof(serialized, 'string');
assert.typeof(index, 'number');

const streamCell = JSON.parse(serialized);
if (!isStreamCell(streamCell)) {
Expand Down Expand Up @@ -102,7 +103,7 @@ export const makeHistoryReviver = (entries, slotToVal = undefined) => {
const vsMap = new Map(entries);
const fromCapData = (...args) =>
Reflect.apply(board.fromCapData, board, args);
const getItem = key => unmarshalFromVstorage(vsMap, key, fromCapData);
const getItem = key => unmarshalFromVstorage(vsMap, key, fromCapData, -1);
const children = prefix => {
prefix.endsWith('.') || Fail`prefix must end with '.'`;
return harden([
Expand Down
5 changes: 3 additions & 2 deletions packages/internal/src/storage-test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,15 @@ export const makeMockChainStorageRoot = () => {
*
* @param {string} path
* @param {import('./lib-chainStorage.js').Marshaller} marshaller
* @param {number} [index]
* @returns {unknown}
*/
getBody: (path, marshaller = defaultMarshaller) => {
getBody: (path, marshaller = defaultMarshaller, index = -1) => {
data.size || Fail`no data in storage`;
/** @type {ReturnType<typeof import('@endo/marshal').makeMarshal>['fromCapData']} */
const fromCapData = (...args) =>
Reflect.apply(marshaller.fromCapData, marshaller, args);
return unmarshalFromVstorage(data, path, fromCapData);
return unmarshalFromVstorage(data, path, fromCapData, index);
},
keys: () => [...data.keys()],
});
Expand Down
1 change: 1 addition & 0 deletions packages/smart-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"devDependencies": {
"@agoric/cosmic-proto": "^0.3.0",
"@endo/bundle-source": "^2.5.2",
"@endo/captp": "^3.1.2",
"@endo/init": "^0.5.57",
"ava": "^5.3.0",
Expand Down
9 changes: 5 additions & 4 deletions packages/smart-wallet/src/offers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { E, passStyleOf } from '@endo/far';
import { deeplyFulfilledObject } from '@agoric/internal';
import { makePaymentsHelper } from './payments.js';

/**
Expand Down Expand Up @@ -80,15 +81,15 @@ export const makeOfferExecutor = ({
// 1. Prepare values and validate synchronously.
const { id, invitationSpec, proposal, offerArgs } = offerSpec;

/** @type {PaymentKeywordRecord | undefined} */
const paymentKeywordRecord = await (proposal?.give &&
deeplyFulfilledObject(paymentsManager.withdrawGive(proposal.give)));

const invitation = invitationFromSpec(invitationSpec);
const invitationAmount = await E(invitationIssuer).getAmountOf(
invitation,
);

const paymentKeywordRecord = proposal?.give
? paymentsManager.withdrawGive(proposal.give)
: undefined;

// 2. Begin executing offer
// No explicit signal to user that we reached here but if anything above
// failed they'd get an 'error' status update.
Expand Down
Loading

0 comments on commit d619852

Please sign in to comment.