How to use @agoric/bundle-source - 8 common examples

To help you get started, we’ve selected a few @agoric/bundle-source examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Agoric / ERTP / test / unitTests / core / zoe / contracts / test-coveredCall.js View on Github external
test('zoe - coveredCall with swap for invite', async t => {
  try {
    // Setup the environment
    const { mints, assays } = setup();
    const [moolaMint, simoleanMint, bucksMint] = mints;
    const [moolaAssay, simoleanAssay, bucksAssay] = assays;
    const timer = buildManualTimer(console.log);
    const zoe = await makeZoe({ require });
    // Pack the contract.
    const { source, moduleFormat } = await bundleSource(coveredCallRoot);

    const coveredCallInstallationHandle = zoe.install(source, moduleFormat);
    const {
      source: swapSource,
      moduleFormat: swapModuleFormat,
    } = await bundleSource(publicSwapRoot);

    const swapInstallationId = zoe.install(swapSource, swapModuleFormat);

    // Setup Alice
    // Alice starts with 3 moola
    const aliceMoolaPurse = moolaMint.mint(moolaAssay.makeUnits(3));
    const aliceMoolaPayment = aliceMoolaPurse.withdrawAll();
    const aliceSimoleanPurse = simoleanMint.mint(simoleanAssay.makeUnits(0));

    // Setup Bob
    // Bob starts with nothing
    const bobMoolaPurse = moolaMint.mint(moolaAssay.makeUnits(0));
    const bobSimoleanPurse = simoleanMint.mint(simoleanAssay.makeUnits(0));
    const bobBucksPurse = bucksMint.mint(bucksAssay.makeUnits(0));

    // Setup Dave
github Agoric / ERTP / test / unitTests / core / zoe / contracts / test-coveredCall.js View on Github external
test(`zoe - coveredCall - alice's deadline expires, cancelling alice and bob`, async t => {
  try {
    const { mints: defaultMints, assays: defaultAssays } = setup();
    const mints = defaultMints.slice(0, 2);
    const assays = defaultAssays.slice(0, 2);
    const zoe = await makeZoe({ require });
    const escrowReceiptAssay = zoe.getEscrowReceiptAssay();
    // Pack the contract.
    const { source, moduleFormat } = await bundleSource(coveredCallRoot);

    const coveredCallInstallationHandle = zoe.install(source, moduleFormat);

    // Setup Alice
    const aliceMoolaPurse = mints[0].mint(assays[0].makeUnits(3));
    const aliceMoolaPayment = aliceMoolaPurse.withdrawAll();
    const aliceSimoleanPurse = mints[1].mint(assays[1].makeUnits(0));

    // Setup Bob
    const bobMoolaPurse = mints[0].mint(assays[0].makeUnits(0));
    const bobSimoleanPurse = mints[1].mint(assays[1].makeUnits(7));
    const bobSimoleanPayment = bobSimoleanPurse.withdrawAll();

    // 1: Alice creates a coveredCall instance

    const terms = {
github Agoric / ERTP / test / unitTests / core / zoe / contracts / test-simpleExchange.js View on Github external
test('zoe - simpleExchange', async t => {
  try {
    const { assays: originalAssays, mints, unitOps } = setup();
    const assays = originalAssays.slice(0, 2);
    const zoe = await makeZoe({ require });
    const escrowReceiptAssay = zoe.getEscrowReceiptAssay();
    // Pack the contract.
    const { source, moduleFormat } = await bundleSource(simpleExchangeRoot);

    const installationHandle = zoe.install(source, moduleFormat);

    // Setup Alice
    const aliceMoolaPurse = mints[0].mint(assays[0].makeUnits(3));
    const aliceSimoleanPurse = mints[1].mint(assays[1].makeUnits(0));
    const aliceMoolaPayment = aliceMoolaPurse.withdrawAll();

    // Setup Bob
    const bobMoolaPurse = mints[0].mint(assays[0].makeUnits(0));
    const bobSimoleanPurse = mints[1].mint(assays[1].makeUnits(7));
    const bobSimoleanPayment = bobSimoleanPurse.withdrawAll();

    // 1: Alice creates a simpleExchange instance
    const {
      instance: aliceExchange,
github Agoric / ERTP / test / unitTests / core / zoe / contracts / test-publicSwap.js View on Github external
test('zoe - publicSwap', async t => {
  try {
    const { assays: defaultAssays, mints } = setup();
    const assays = defaultAssays.slice(0, 2);
    const zoe = await makeZoe({ require });
    const escrowReceiptAssay = zoe.getEscrowReceiptAssay();
    // pack the contract
    const { source, moduleFormat } = await bundleSource(publicSwapRoot);
    // install the contract
    const installationHandle = zoe.install(source, moduleFormat);

    // Setup Alice
    const aliceMoolaPurse = mints[0].mint(assays[0].makeUnits(3));
    const aliceMoolaPayment = aliceMoolaPurse.withdrawAll();
    const aliceSimoleanPurse = mints[1].mint(assays[1].makeUnits(0));

    // Setup Bob
    const bobMoolaPurse = mints[0].mint(assays[0].makeUnits(0));
    const bobSimoleanPurse = mints[1].mint(assays[1].makeUnits(7));
    const bobSimoleanPayment = bobSimoleanPurse.withdrawAll();

    // 1: Alice creates a publicSwap instance
    const {
      instance: aliceSwap,
github Agoric / ERTP / test / unitTests / core / zoe / contracts / test-automaticRefund.js View on Github external
},
    });
    const alicePayments = [aliceMoolaPayment, undefined];

    const {
      escrowReceipt: aliceEscrowReceipt,
      cancelObj,
      payout: payoutP,
    } = await zoe.escrow(aliceOfferRules, alicePayments);

    cancelObj.cancel();

    const alicePayout = await payoutP;

    // Pack the contract.
    const { source, moduleFormat } = await bundleSource(automaticRefundRoot);
    const installationHandle = zoe.install(source, moduleFormat);
    const terms = harden({
      assays,
    });
    const { instance: aliceAutomaticRefund } = await zoe.makeInstance(
      installationHandle,
      terms,
    );

    t.rejects(
      aliceAutomaticRefund.makeOffer(aliceEscrowReceipt),
      /Error: offer was cancelled/,
    );

    // Alice got back what she put in
    t.deepEquals(
github Agoric / ERTP / test / unitTests / core / zoe / contracts / test-autoswap.js View on Github external
const escrowReceiptAssay = zoe.getEscrowReceiptAssay();

    // Setup Alice
    const aliceMoolaPurse = mints[0].mint(assays[0].makeUnits(10000));
    const aliceMoolaPayment = aliceMoolaPurse.withdrawAll();
    const aliceSimoleanPurse = mints[1].mint(assays[1].makeUnits(10000));
    const aliceSimoleanPayment = aliceSimoleanPurse.withdrawAll();

    // Setup Bob
    const bobMoolaPurse = mints[0].mint(assays[0].makeUnits(1000));
    const bobMoolaPayment = bobMoolaPurse.withdrawAll();

    // 1: Alice creates an autoswap instance

    // Pack the contract.
    const { source, moduleFormat } = await bundleSource(autoswapRoot);

    const installationHandle = zoe.install(source, moduleFormat);
    const terms = {
      assays,
    };
    const {
      instance: aliceAutoswap,
      instanceHandle,
      terms: aliceTerms,
    } = await zoe.makeInstance(installationHandle, terms);
    const liquidityAssay = aliceAutoswap.getLiquidityAssay();
    const allAssays = [...terms.assays, liquidityAssay];
    t.deepEquals(aliceTerms.assays, allAssays);

    // 2: Alice adds liquidity
    const aliceOfferRules = harden({
github Agoric / ERTP / test / unitTests / core / zoe / contracts / test-publicAuction.js View on Github external
const bobSimoleanPayment = bobSimoleanPurse.withdrawAll();

    // Setup Carol
    const carolMoolaPurse = mints[0].mint(assays[0].makeUnits(0));
    const carolSimoleanPurse = mints[1].mint(assays[1].makeUnits(7));
    const carolSimoleanPayment = carolSimoleanPurse.withdrawAll();

    // Setup Dave
    const daveMoolaPurse = mints[0].mint(assays[0].makeUnits(0));
    const daveSimoleanPurse = mints[1].mint(assays[1].makeUnits(5));
    const daveSimoleanPayment = daveSimoleanPurse.withdrawAll();

    // 1: Alice creates a secondPriceAuction instance

    // Pack the contract.
    const { source, moduleFormat } = await bundleSource(publicAuctionRoot);

    const installationHandle = zoe.install(source, moduleFormat);
    const numBidsAllowed = 3;
    const {
      instance: aliceAuction,
      instanceHandle,
    } = await zoe.makeInstance(installationHandle, { assays, numBidsAllowed });

    // 2: Alice escrows with zoe
    const aliceOfferRules = harden({
      payoutRules: [
        {
          kind: 'offerExactly',
          units: assays[0].makeUnits(1),
        },
        {
github Agoric / ERTP / test / unitTests / core / zoe / contracts / test-myFirstDapp.js View on Github external
const { assays: defaultAssays, mints } = setup();
    const zoe = await makeZoe({ require });
    const assays = defaultAssays.slice(0, 2);

    // Setup Alice
    const aliceMoolaPurse = mints[0].mint(assays[0].makeUnits(1));
    const aliceMoolaPayment = aliceMoolaPurse.withdrawAll();
    const aliceSimoleanPurse = mints[1].mint(assays[1].makeUnits(1));
    const aliceSimoleanPayment = aliceSimoleanPurse.withdrawAll();

    // Setup Bob
    const bobMoolaPurse = mints[0].mint(assays[0].makeUnits(1));
    const bobMoolaPayment = bobMoolaPurse.withdrawAll();

    // Pack the contract.
    const { source, moduleFormat } = await bundleSource(myFirstDappRoot);
    const installationHandle = zoe.install(source, moduleFormat);
    const { instance: myFirstDapp, instanceHandle } = await zoe.makeInstance(
      installationHandle,
      {
        assays,
      },
    );
    const liquidityAssay = myFirstDapp.getLiquidityAssay();
    const allAssays = [...assays, liquidityAssay];

    // Alice adds liquidity
    const aliceOfferRules = harden({
      payoutRules: [
        {
          kind: 'offerExactly',
          units: allAssays[0].makeUnits(1),

@agoric/bundle-source

Create source bundles from ES Modules

Apache-2.0
Latest version published 3 years ago

Package Health Score

45 / 100
Full package analysis

Popular @agoric/bundle-source functions

Similar packages