Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions main/guides/zoe/assets/trade-offer-safety-1.mmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ sequenceDiagram
end

box skyblue Contract Instance
participant C as gameAssetContract
participant C as offer-up.contract
end

A-)Zoe: getPublicFacet(instance)
A-)+Zoe: getTerms(instance)
Zoe--)-A: { issuers, brands, joinPrice }
Zoe--)-A: { issuers, brands, tradePrice }
2 changes: 1 addition & 1 deletion main/guides/zoe/assets/trade-offer-safety-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions main/guides/zoe/assets/trade-offer-safety-2.mmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ sequenceDiagram
end

box skyblue Contract
participant C as gameAssetContract
participant C as offer-up.contract
end

A-)C: makeJoinInvitation()
A-)C: makeTradeInvitation()
A-)Zoe: offer(toJoin, proposal, { Price })
A-)Zoe: E(seat).getPayout('Places')
A-)Zoe: E(seat).getPayout('Items')
2 changes: 1 addition & 1 deletion main/guides/zoe/assets/trade-offer-safety-2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions main/guides/zoe/assets/trade-offer-safety-3.mmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ sequenceDiagram
end

box skyblue Contract
participant C as gameAssetContract
participant C as offer-up.contract
end

A-)C: makeJoinInvitation()
A-)C: makeTradeInvitation()
activate C
C--)Zoe: makeInvitation(joinHandler, ...)
C--)Zoe: makeInvitation(tradeHandler, ...)
deactivate C
activate Zoe
Zoe--)-C: invitation
Expand All @@ -26,4 +26,4 @@ sequenceDiagram

Zoe--)Zoe: escrow Price pmt

Zoe--)-C: joinHandler(gameSeat)
Zoe--)-C: tradeHandler(buyerSeat)
2 changes: 1 addition & 1 deletion main/guides/zoe/assets/trade-offer-safety-3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions main/guides/zoe/assets/trade-offer-safety-4.mmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ sequenceDiagram
end

box skyblue Contract
participant C as gameAssetContract
participant C as offer-up.contract
end

Zoe--)C: joinHandler(gameSeat)
Zoe--)C: tradeHandler(buyerSeat)
activate C
C--)C: check proposal
C--)Zoe: mintGains(want)
Expand All @@ -25,4 +25,4 @@ sequenceDiagram

Zoe--)Zoe: check offer safety

C--)Zoe: playerSeat.exit(true)
C--)Zoe: buyerSeat.exit(true)
2 changes: 1 addition & 1 deletion main/guides/zoe/assets/trade-offer-safety-4.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions main/guides/zoe/assets/trade-offer-safety-5.mmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ sequenceDiagram
end

box skyblue Contract
participant C as gameAssetContract
participant C as offer-up.contract
end

A-)+Zoe: E(seat).getPayout('Places')
A-)+Zoe: E(seat).getPayout('Items')
Note over Zoe: ... many steps above ...
Zoe--)-A: placesPayment
A-)+Zoe: E(issuers.Place).getAmountOf(placesPayment)
Zoe--)-A: { brand: Place brand,<br> value: [['Park Place, 1n], ['Boardwalk', 1n]]
Zoe--)-A: itemsPayment
A-)+Zoe: E(issuers.Items).getAmountOf(itemsPayment)
Zoe--)-A: { brand: Item brand,<br> value: [['map', 1n], ['scroll', 1n]]
2 changes: 1 addition & 1 deletion main/guides/zoe/assets/trade-offer-safety-5.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion main/guides/zoe/contract-upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The `adminFacet` is defined by Zoe and includes methods to upgrade the contract.
Governance of the right to upgrade is a complex topic that we cover only briefly here.

- When [BLD staker governance](https://community.agoric.com/t/about-the-governance-category/15) makes a decision to start a contract using [swingset.CoreEval](../coreeval/),
to date, the `adminFacet` is stored in the bootstrap vat, allowing
to date, the `adminFacet` is stored in the bootstrap [vat](/glossary/#vat), allowing
the BLD stakers to upgrade such a contract in a later `swingset.CoreEval`.
- The `adminFacet` reference can be discarded, so that noone can upgrade
the contract from within the JavaScript VM. (BLD staker governace
Expand Down
50 changes: 25 additions & 25 deletions main/guides/zoe/contract-walkthru.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ t.is(typeof installation, 'object');
The `installation` identifies the basic contract that we'll
go over in detail in the sections below.

::: details gameAssetContract.js listing
::: details offer-up.contract.js listing

<<< @/../snippets/zoe/src/gameAssetContract.js#file
<<< @/../snippets/zoe/src/offer-up.contract.js#file

:::

Expand All @@ -113,7 +113,7 @@ yarn ava test/test-contract.js -m 'Start the contract'
```
✔ Start the contract (652ms)
ℹ terms: {
joinPrice: {
tradePrice: {
brand: Object @Alleged: PlayMoney brand {},
value: 5n,
},
Expand All @@ -130,7 +130,7 @@ the contract should use for its business:
```js{8}
const money = makeIssuerKit('PlayMoney');
const issuers = { Price: money.issuer };
const terms = { joinPrice: AmountMath.make(money.brand, 5n) };
const terms = { tradePrice: AmountMath.make(money.brand, 5n) };
t.log('terms:', terms);

/** @type {ERef<Installation<GameContractFn>>} */
Expand All @@ -146,14 +146,14 @@ _See also [E(zoe).startInstance(...)](/reference/zoe-api/zoe.md#e-zoe-startinsta

Let's take a look at what happens in the contract when it starts. A _facet_ of Zoe, the _Zoe Contract Facet_, is passed to the contract `start` function.
The contract uses this `zcf` to get its terms. Likewise it uses `zcf` to
make a `gameSeat` where it can store assets that it receives in trade
as well as a `mint` for making assets consisting of collections (bags) of Places:
make a `proceeds` seat where it can store assets that it receives in trade
as well as a `mint` for making assets consisting of collections (bags) of Items:

<<< @/../snippets/zoe/src/gameAssetContract.js#start
<<< @/../snippets/zoe/src/offer-up.contract.js#start

It defines a `joinShape` and `joinHandler` but doesn't do anything with them yet. They will come into play later. It defines and returns its `publicFacet` and stands by.
It defines a `proposalShape` and `tradeHandler` but doesn't do anything with them yet. They will come into play later. It defines and returns a [hardened](/glossary/#harden) `publicFacet` object and stands by.

<<< @/../snippets/zoe/src/gameAssetContract.js#started
<<< @/../snippets/zoe/src/offer-up.contract.js#started

## Trading with Offer Safety

Expand All @@ -164,23 +164,23 @@ yarn ava test/test-contract.js -m 'Alice trades*'
```

```
✔ Alice trades: give some play money, want some game places (674ms)
✔ Alice trades: give some play money, want items (309ms)
ℹ Object @Alleged: InstanceHandle {}
ℹ Alice gives {
Price: {
brand: Object @Alleged: PlayMoney brand {},
value: 5n,
},
}
ℹ Alice payout brand Object @Alleged: Place brand {}
ℹ Alice payout brand Object @Alleged: Item brand {}
ℹ Alice payout value Object @copyBag {
payload: [
[
'Park Place',
'scroll',
1n,
],
[
'Boardwalk',
'map',
1n,
],
],
Expand Down Expand Up @@ -209,14 +209,14 @@ Alice starts by using the `instance` to get the contract's `publicFacet` and `te

<<< @/../snippets/zoe/contracts/alice-trade.js#queryInstance

Then she constructs a _proposal_ to give the `joinPrice` in exchange
for 1 Park Place and 1 Boardwalk, denominated in the game's `Place` brand; and she withdraws a payment from her purse:
Then she constructs a _proposal_ to give the `tradePrice` in exchange
for 1 map and 1 scroll, denominated in the game's `Item` brand; and she withdraws a payment from her purse:

<<< @/../snippets/zoe/contracts/alice-trade.js#makeProposal

She then requests an _invitation_ to join the game; makes an _offer_ with
(a promise for) this invitation, her proposal, and her payment;
and awaits her **Places** payout:
and awaits her **Items** payout:

<img src="./assets/trade-offer-safety-2.svg"
style="border: 2px solid" width="600" />
Expand All @@ -241,33 +241,33 @@ when you are [creating an instance](#starting-a-contract-instance) or by using

:::

The contract gets Alice's `E(publicFacet).makeJoinInvitation()` call and uses `zcf` to make an invitation with an associated handler, description, and proposal shape. Zoe gets Alice's `E(zoe).offer(...)` call, checks the proposal against the proposal shape, escrows the payment, and invokes the handler.
The contract gets Alice's `E(publicFacet).makeTradeInvitation()` call and uses `zcf` to make an invitation with an associated handler, description, and proposal shape. Zoe gets Alice's `E(zoe).offer(...)` call, checks the proposal against the proposal shape, escrows the payment, and invokes the handler.

<img src="./assets/trade-offer-safety-3.svg"
style="border: 2px solid" width="600" />

<<< @/../snippets/zoe/src/gameAssetContract.js#makeInvitation
<<< @/../snippets/zoe/src/offer-up.contract.js#makeInvitation

The offer handler is invoked with a _seat_ representing the party making the offer.
It extracts the `give` and `want` from the party's offer and checks that
they are giving at least the `joinPrice` and not asking for too many
places in return.
they are giving at least the `tradePrice` and not asking for too many
items in return.

With all these prerequisites met, the handler instructs `zcf` to mint the requested
**Place** assets, allocate what the player is giving into its own `gameSeat`,
and allocate the minted places to the player. Finally, it concludes its business with the player.
**Item** assets, allocate what the player is giving into its own `proceeds` seat,
and allocate the minted items to the player. Finally, it concludes its business with the player.

<img src="./assets/trade-offer-safety-4.svg"
style="border: 2px solid" width="600" />

<<< @/../snippets/zoe/src/gameAssetContract.js#handler
<<< @/../snippets/zoe/src/offer-up.contract.js#handler

Zoe checks that the contract's instructions are consistent with
the offer and with conservation of assets. Then it allocates
the escrowed payment to the contract's gameSeat and pays out
the escrowed payment to the contract's proceeds seat and pays out
the place NFTs to Alice in response to the earlier `getPayout(...)` call.

Alice asks the `Place` issuer what her payout is worth
Alice asks the `Item` issuer what her payout is worth
and tests that it's what she wanted.

<img src="./assets/trade-offer-safety-5.svg"
Expand Down
18 changes: 9 additions & 9 deletions snippets/zoe/contracts/alice-trade.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,31 @@ export const alice = async (t, zoe, instance, purse) => {
// #region queryInstance
const publicFacet = E(zoe).getPublicFacet(instance);
const terms = await E(zoe).getTerms(instance);
const { issuers, brands, joinPrice } = terms;
const { issuers, brands, tradePrice } = terms;
// #endregion queryInstance

// #region makeProposal
const choices = ['Park Place', 'Boardwalk'];
const choices = ['map', 'scroll'];
const choiceBag = makeCopyBag(choices.map(name => [name, 1n]));
const proposal = {
give: { Price: joinPrice },
want: { Places: AmountMath.make(brands.Place, choiceBag) },
give: { Price: tradePrice },
want: { Places: AmountMath.make(brands.Item, choiceBag) },
};
const Price = await E(purse).withdraw(joinPrice);
const Price = await E(purse).withdraw(tradePrice);
t.log('Alice gives', proposal.give);
// #endregion makeProposal

// #region trade
const toJoin = E(publicFacet).makeJoinInvitation();
const toJoin = E(publicFacet).makeTradeInvitation();

const seat = E(zoe).offer(toJoin, proposal, { Price });
const places = await E(seat).getPayout('Places');
const items = await E(seat).getPayout('Items');
// #endregion trade

// #region payouts
const actual = await E(issuers.Place).getAmountOf(places);
const actual = await E(issuers.Item).getAmountOf(items);
t.log('Alice payout brand', actual.brand);
t.log('Alice payout value', actual.value);
t.deepEqual(actual, proposal.want.Places);
t.deepEqual(actual, proposal.want.Items);
// #endregion payouts
};
2 changes: 1 addition & 1 deletion snippets/zoe/contracts/test-bundle-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { makeZoeKitForTest } from '@agoric/zoe/tools/setup-zoe.js';

// #region contractPath
const myRequire = createRequire(import.meta.url);
const contractPath = myRequire.resolve(`../src/gameAssetContract.js`);
const contractPath = myRequire.resolve(`../src/offer-up.contract.js`);
// #endregion contractPath

test('bundleSource() bundles the contract for use with zoe', async t => {
Expand Down
80 changes: 0 additions & 80 deletions snippets/zoe/src/gameAssetContract.js

This file was deleted.

Loading
Loading