diff --git a/contract/,tx.json b/contract/,tx.json deleted file mode 100644 index e69de29b..00000000 diff --git a/contract/package.json b/contract/package.json index 2d5403ce..fe6392cf 100644 --- a/contract/package.json +++ b/contract/package.json @@ -54,6 +54,7 @@ "@agoric/governance": "^0.10.4-u14.0", "@agoric/inter-protocol": "0.16.2-u14.1", "@agoric/vats": "0.15.2-u14.0", + "@agoric/vat-data": "0.5.3-u14.0", "@agoric/zoe": "^0.26.3-u14.0", "@endo/bundle-source": "^2.8.0", "@endo/far": "^0.2.22", diff --git a/contract/src/swaparoo.contract.js b/contract/src/swaparoo.contract.js index cf393b2e..dcccb8aa 100644 --- a/contract/src/swaparoo.contract.js +++ b/contract/src/swaparoo.contract.js @@ -15,6 +15,7 @@ import { import { ParamTypes } from '@agoric/governance/src/constants.js'; import { CONTRACT_ELECTORATE } from '@agoric/governance/src/contractGovernance/governParam.js'; import { handleParamGovernance } from '@agoric/governance/src/contractHelper.js'; +import { provide } from '@agoric/vat-data'; import { makeCollectFeesInvitation } from './collectFees.js'; import { fixHub } from './fixHub.js'; @@ -121,6 +122,18 @@ export const start = async (zcf, privateArgs, baggage) => { // TODO: update with Fee param const feeShape = makeNatAmountShape(feeBrand, params.getFee().value); + const generateOfferNonce = (() => { + // Provide the nonce durably so it can stay unique if contract upgrades. + // See: https://docs.agoric.com/guides/zoe/contract-upgrade.html#durability + let offerNonce = provide(baggage, 'offerNonce', () => -1); + + return () => { + offerNonce += 1; + baggage.set('offerNonce', offerNonce); + return offerNonce; + }; + })(); + /** * @param { ZCFSeat } firstSeat * @param {{ addr: string }} offerArgs @@ -158,9 +171,10 @@ export const start = async (zcf, privateArgs, baggage) => { return swapWithFee(zcf, firstSeat, secondSeat, feeSeat, params.getFee()); }; + const description = `matchOffer-${generateOfferNonce()}`; const secondSeatInvitation = await zcf.makeInvitation( secondSeatOfferHandler, - 'matchOffer', + description, { give: give1, want: want1 }, // "give" and "want" are from the proposer's perspective ); diff --git a/contract/test/snapshots/test-swap-wallet.js.md b/contract/test/snapshots/test-swap-wallet.js.md index 9d356e00..2e20c53d 100644 --- a/contract/test/snapshots/test-swap-wallet.js.md +++ b/contract/test/snapshots/test-swap-wallet.js.md @@ -49,7 +49,7 @@ Generated by [AVA](https://avajs.dev). { id: 'jack-123', invitationSpec: { - description: 'matchOffer', + description: 'matchOffer-0', instance: Object @Alleged: InstanceHandle {}, source: 'purse', }, diff --git a/contract/test/snapshots/test-swap-wallet.js.snap b/contract/test/snapshots/test-swap-wallet.js.snap index b8134522..de8f920a 100644 Binary files a/contract/test/snapshots/test-swap-wallet.js.snap and b/contract/test/snapshots/test-swap-wallet.js.snap differ diff --git a/contract/test/test-swap-wallet.js b/contract/test/test-swap-wallet.js index 675c84d4..16dbe219 100644 --- a/contract/test/test-swap-wallet.js +++ b/contract/test/test-swap-wallet.js @@ -161,6 +161,7 @@ const startAlice = async ( * @param {MockWallet} wallet * @param {Amount} beansAmount * @param {Amount} cowsAmount + * @param {string} offerDescription * @param {boolean} [jackPays] */ const startJack = async ( @@ -169,6 +170,7 @@ const startJack = async ( wallet, beansAmount, cowsAmount, + offerDescription, jackPays = false, ) => { const instance = wellKnown.instance[contractName]; @@ -188,7 +190,7 @@ const startJack = async ( invitationSpec: { source: 'purse', instance, - description: 'matchOffer', + description: offerDescription, }, proposal, }; @@ -278,7 +280,14 @@ test.serial('basic swap', async t => { await E(E.get(bldIssuerKit).mint).mintPayment(cowAmount), ); const jackSeat = seatLike( - await startJack(t, wellKnown, wallet.jack, fiveBeans, cowAmount), + await startJack( + t, + wellKnown, + wallet.jack, + fiveBeans, + cowAmount, + 'matchOffer-0', + ), ); const jackPayouts = await jackSeat.getPayoutAmounts(); diff --git a/yarn.lock b/yarn.lock index 5c9807b1..266777ea 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8453,7 +8453,7 @@ eslint@^8.47.0, eslint@^8.56.0: strip-ansi "^6.0.1" text-table "^0.2.0" -esm@agoric-labs/esm#Agoric-built, "esm@github:agoric-labs/esm#Agoric-built": +esm@agoric-labs/esm#Agoric-built: version "3.2.25" resolved "https://codeload.github.com/agoric-labs/esm/tar.gz/3603726ad4636b2f865f463188fcaade6375638e"