Skip to content

Commit

Permalink
chore: launcherLarry market actor
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc committed Jan 13, 2024
1 parent 51148e1 commit bd11c8a
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions contract/test/market-actors.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// @ts-check
import { E, getInterfaceOf } from '@endo/far';
import { makePromiseKit } from '@endo/promise-kit';
import { AmountMath } from '@agoric/ertp/src/amountMath.js';
import { allValues, mapValues } from './wallet-tools.js';
import { makeIssuerKit } from '@agoric/ertp';

const { entries, fromEntries, keys } = Object;
const { Fail } = assert;
Expand Down Expand Up @@ -258,3 +260,50 @@ export const starterSam = async (t, mine, wellKnown) => {
t.deepEqual([...todo.keys()], []);
return done;
};

const seatLike = updates => {
const sync = {
result: makePromiseKit(),
payouts: makePromiseKit(),
};
(async () => {
for await (const update of updates) {
if (update.updated !== 'offerStatus') continue;
const { result, payouts } = update.status;
if (result) sync.result.resolve(result);
if (payouts) sync.payouts.resolve(payouts);
}
})();
return harden({
getOfferResult: () => sync.result.promise,
getPayouts: () => sync.payouts.promise,
});
};
/**
* @param {import('ava').ExecutionContext} t
* @param {{ wallet: import('./wallet-tools.js').MockWallet }} mine
* @param { WellKnown & { terms: { arbAssetName: { price }}} } wellKnown
*/
export const launcherLarry = async (t, { wallet }, wellKnown) => {
const { price } = wellKnown.terms.arbAssetName;
const BRD = makeIssuerKit('BRD');
const launched = { issuer: BRD.issuer, brand: BRD.brand };
t.log('Larry launched', launched);
await E(wallet.offers).addIssuer(BRD.issuer);
const instance = await wellKnown.instance.arbAssetName;
t.log('Larry offers', price, 'to publish');
const updates = await E(wallet.offers).executeOffer({
id: 'larry-brd-publish-1',
invitationSpec: {
source: 'contract',
instance,
publicInvitationMaker: 'makePublishAssetInvitation',
},
proposal: { give: { Pay: price } },
offerArgs: launched,
});
const seat = seatLike(updates);
const id = await E(seat).getOfferResult();
t.log('Larry published as', id);
return { ...launched, id };
};

0 comments on commit bd11c8a

Please sign in to comment.