Skip to content

Commit

Permalink
style: Improve the consistency of code samples
Browse files Browse the repository at this point in the history
  • Loading branch information
gibson042 committed Dec 1, 2023
1 parent d5c4159 commit 1d70859
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 95 deletions.
2 changes: 1 addition & 1 deletion main/glossary/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ Before a contract can be installed on Zoe, its source code must be bundled. This
```js
import bundleSource from '@endo/bundle-source';
const atomicSwapBundle = await bundleSource(
require.resolve('@agoric/zoe/src/contracts/atomicSwap'),
require.resolve('@agoric/zoe/src/contracts/atomicSwap'),
);
```
The installation operation returns an `installation`, which is an object with a single
Expand Down
4 changes: 2 additions & 2 deletions main/guides/js-programming/notifiers.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ const consume = async subscription => {
}
};
consume(subscription);
// eventually prints
// Eventually prints:
// non-final-value a
// non-final-value b
// the iteration finished
Expand All @@ -221,7 +221,7 @@ const observer = harden({
fail: reason => console.log('failed', reason),
});
observeIteration(subscription, observer);
// eventually prints
// Eventually prints:
// non-final-value a
// non-final-value b
// finished done
Expand Down
4 changes: 2 additions & 2 deletions main/guides/zoe/actual-contracts/PSM.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ this proposal doesn’t have (or need) an exit condition.

```js
const myProposal = {
give: {In: giveAnchorAmount },
want: {Out: wantMintedAmount }
give: { In: giveAnchorAmount },
want: { Out: wantMintedAmount }
};
```
4. Create a payment record containing the external stable tokens you’re trading to the PSM.
Expand Down
2 changes: 1 addition & 1 deletion main/guides/zoe/contracts/barter-exchange.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ keeps an order book, and each time it receives a new offer, it looks
for matches throughout the order book.

The Barter Exchange only accepts offers that look like
`{ give: { In: amount }, want: { Out: amount}` }
`{ give: { In: amount }, want: { Out: amount }` }

The want amount will be matched, while the give amount is a maximum. Each
successful trader gets their `want` and may trade with counter-parties who
Expand Down
4 changes: 3 additions & 1 deletion main/guides/zoe/contracts/covered-call.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ with the key "afterDeadline":
{
give: { ... },
want: { ... },
exit: {afterDeadline: { deadline: time, timer: chainTimer } },
exit: {
afterDeadline: { deadline: time, timer: chainTimer },
},
}
```

Expand Down
18 changes: 9 additions & 9 deletions main/reference/ertp-api/amount-math.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ not equal, an error is thrown and no changes are made.
Creates an **Amount** from a given **Value** and a **Brand**.

```js
//amount837 = { value: 837n, brand: quatloos }
// amount837 = { brand: quatloosBrand, value: 837n }
const amount837 = AmountMath.make(quatloosBrand, 837n);
```

Expand Down Expand Up @@ -53,7 +53,7 @@ Returns the **Value** from the given **Amount**.
```js
const quatloos123 = AmountMath.make(quatloosBrand, 123n);

// returns 123n
// Returns 123n
const myValue = AmountMath.getValue(quatloosBrand, quatloos123);
```
## AmountMath.makeEmpty(brand, assetKind)
Expand All @@ -64,7 +64,7 @@ const myValue = AmountMath.getValue(quatloosBrand, quatloos123);
Returns the **Amount** representing an empty **Amount** for the *brand* parameter's
**Brand**. This is the identity element for **AmountMath.add()**
and **AmountMath.subtract()**. The empty **Value** depends
on whether the *assetKind* is **AssetKind.NAT** (*0n*), **AssetKind.COPY_SET** (*[]*), or **AssetKind.COPY_BAG** (*[]*).
on whether the *assetKind* is **AssetKind.NAT** (`0n`), **AssetKind.COPY_SET** (`[]`), or **AssetKind.COPY_BAG** (`[]`).

```js
// Returns an empty amount.
Expand All @@ -81,9 +81,9 @@ Returns the **Amount** representing an empty **Amount**, using another
**Amount** as the template for the **[Brand](./brand.md)** and **[Value](./ertp-data-types.md#value)**.

```js
// quatloosAmount837 = { value: 837n, brand: quatloos }
// quatloosAmount837 = { brand: quatloos, value: 837n }
const quatloosAmount837 = AmountMath.make(quatloosBrand, 837n);
// Returns an amount = { value: 0n, brand: quatloos }
// Returns an amount = { brand: quatloos, value: 0n }
const quatloosAmount0 = AmountMath.makeEmptyFromAmount(quatloosAmount837);
```

Expand All @@ -100,10 +100,10 @@ If the optional *brand* argument doesn't match the **Amount**'s **Brand**, an er
const empty = AmountMath.makeEmpty(quatloosBrand, AssetKind.NAT);
const quatloos1 = AmountMath.make(quatloosBrand, 1n);

// returns true
// Returns true
const result = AmountMath.isEmpty(empty);

// returns false
// Returns false
const result = AmountMath.isEmpty(quatloos1);
```

Expand Down Expand Up @@ -254,7 +254,7 @@ If the optional *brand* argument doesn't match the **Brand** of *x* and *y*, an
const smallerAmount = AmountMath.make(quatloosBrand, 5n);
const largerAmount = AmountMath.make(quatloosBrand, 10n);
//returns smallerAmount
// Returns smallerAmount
const comparisonResult = AmountMath.min(smallerAmount, largerAmount);
```

Expand All @@ -274,7 +274,7 @@ If the optional *brand* argument doesn't match the **Brand** of *x* and *y*, an
const smallerAmount = AmountMath.make(quatloosBrand, 5n);
const largerAmount = AmountMath.make(quatloosBrand, 10n);
//returns largerAmount
// Returns largerAmount
const comparisonResult = AmountMath.max(smallerAmount, largerAmount);
```

Expand Down
31 changes: 18 additions & 13 deletions main/reference/ertp-api/issuer.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ makeIssuerKit('title', AssetKind.COPY_SET);
```

```js
const { issuer: quatloosIssuer, mint: quatloosMint, brand: quatloosBrand } =
makeIssuerKit('quatloos');
const { issuer: quatloosIssuer, mint: quatloosMint, brand: quatloosBrand } =
makeIssuerKit('quatloos');
// This is merely an amount, describing assets, not minting assets
const quatloos2 = AmountMath.make(quatloosBrand, 2n);

const { issuer: titleIssuer, mint: titleMint, brand: titleBrand } =
makeIssuerKit('propertyTitle');
const { issuer: titleIssuer, mint: titleMint, brand: titleBrand } =
makeIssuerKit('propertyTitle');
// These are merely amounts describing digital assets, not minting assets.
const cornerProperty = AmountMath.make(propertyTitleBrand, ['1292826']);
const adjacentProperty = AmountMath.make(propertyTitleBrand, ['1028393']);
Expand Down Expand Up @@ -119,7 +119,8 @@ source cannot be trusted to provide its own true value, the **Issuer** must be u
validate its **[Brand](./brand.md)** and report how much the returned **Amount** contains.

```js
const { issuer: quatloosIssuer, mint: quatloosMint, brand: quatloosBrand} = makeIssuerKit('quatloos');
const { issuer: quatloosIssuer, mint: quatloosMint, brand: quatloosBrand } =
makeIssuerKit('quatloos');
const quatloosPayment = quatloosMint.mintPayment(AmountMath.make(quatloosBrand, 100n));
quatloosIssuer.getAmountOf(quatloosPayment); // returns an amount of 100 Quatloos
```
Expand Down Expand Up @@ -167,8 +168,8 @@ and the original **Payment** is unmodified.
If *payment* is a promise, the operation proceeds after it resolves to a **Payment**.

```js
const { issuer: quatloosIssuer, mint: quatloosMint, brand: quatloosBrand } =
makeIssuerKit('quatloos');
const { issuer: quatloosIssuer, mint: quatloosMint, brand: quatloosBrand } =
makeIssuerKit('quatloos');
const amountToBurn = AmountMath.make(quatloosBrand, 10n);
const paymentToBurn = quatloosMint.mintPayment(amountToBurn);

Expand All @@ -192,7 +193,8 @@ and the original **Payment** is unmodified.
If *payment* is a promise, the operation proceeds after it resolves to a **Payment**.

```js
const { mint: quatloosMint, issuer: quatloosIssuer, brand: quatloosBrand } = makeIssuerKit('quatloos');
const { issuer: quatloosIssuer, mint: quatloosMint, brand: quatloosBrand } =
makeIssuerKit('quatloos');
const amountExpectedToTransfer = AmountMath.make(quatloosBrand, 2n);
const originalPayment = quatloosMint.mintPayment(amountExpectedToTransfer);

Expand All @@ -216,14 +218,15 @@ and the original **Payment** is unmodified.
Each **Payment** in *paymentsArray* must be associated with the same **[Brand](./brand.md)** as the **Issuer**.

```js
const { mint: quatloosMint, issuer: quatloosIssuer, brand: quatloosBrand } = makeIssuerKit('quatloos');
// create an array of 100 payments of 1 quatloo each
const { issuer: quatloosIssuer, mint: quatloosMint, brand: quatloosBrand } =
makeIssuerKit('quatloos');
// Create an array of 100 payments of 1 quatloo each
const payments = [];
for (let i = 0; i < 100; i += 1) {
payments.push(quatloosMint.mintPayment(AmountMath.make(quatloosBrand, 1n)));
}

// combinedpayment equals 100
// combinedPayment equals 100
const combinedPayment = quatloosIssuer.combine(payments);
```

Expand All @@ -243,7 +246,8 @@ If *payment* is a promise, the operation proceeds after it resolves to a **Payme
*payment* and *paymentAmountA* must both be associated with the same **[Brand](./brand.md)** as the **Issuer**.

```js
const { mint: quatloosMint, issuer: quatloosIssuer, brand: quatloosBrand } = makeIssuerKit('quatloos');
const { issuer: quatloosIssuer, mint: quatloosMint, brand: quatloosBrand } =
makeIssuerKit('quatloos');
const oldPayment = quatloosMint.mintPayment(AmountMath.make(quatloosBrand, 20n));
// After the split, paymentA has 5 quatloos and paymentB has 15.
const [paymentA, paymentB] = quatloosIssuer.split(oldPayment, AmountMath.make(quatloosBrand, 5n));
Expand All @@ -265,7 +269,8 @@ If the **Amounts** in *amountArray* don't add up to the value of *payment*, the
*payment* and each **Amount** in *amountArray* must be associated with the same **[Brand](./brand.md)** as **Issuer**.

```js
const { mint: quatloosMint, issuer: quatloosIssuer, brand: quatloosBrand} = makeIssuerKit('quatloos');
const { issuer: quatloosIssuer, mint: quatloosMint, brand: quatloosBrand } =
makeIssuerKit('quatloos');
const oldPayment = quatloosMint.mintPayment(AmountMath.make(quatloosBrand, 100n));
const goodAmounts = Array(10).fill(AmountMath.make(quatloosBrand, 10n));

Expand Down
6 changes: 3 additions & 3 deletions main/reference/ertp-api/mint.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ in an unchangeable one-to-one relationship with a particular **Issuer**.
const { issuer: quatloosIssuer, mint: quatloosMint } = makeIssuerKit('quatloos');
const quatloosMintIssuer = quatloosMint.getIssuer();

// returns true
// Returns true
issuer === quatloosMintIssuer;
```

Expand All @@ -31,8 +31,8 @@ From its creation, a **Mint** is always in an unchangeable
one-to-one relationship with a **Brand**.

```js
const { issuer: quatloosIssuer, mint: quatloosMint
brand: quatloosBrand } = makeIssuerKit('quatloos');
const { issuer: quatloosIssuer, mint: quatloosMint, brand: quatloosBrand } =
makeIssuerKit('quatloos');

const quatloos1000 = amountMath.make(quatloosBrand, 1000n);
// newPayment will have a balance of 1000 Quatloos
Expand Down
2 changes: 1 addition & 1 deletion main/reference/ertp-api/payment.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Any successful operation by an **Issuer** on a **Payment** verifies it.

```js
const payment = quatloosMint.mintPayment(AmountMath.make(quatloosBrand, 10n));
//Should return 'quatloos'
// Should return 'quatloos'
const allegedBrand = payment.getAllegedBrand();
```

Expand Down
7 changes: 4 additions & 3 deletions main/reference/ertp-api/purse.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ method on the **[Issuer](./issuer.md)** associated with the **Brand** of assets
new **Purse** to hold.

```js
const {issuer: quatloosIssuer} = makeIssuerKit{'quatloos'};
const { issuer: quatloosIssuer } = makeIssuerKit('quatloos');
const quatloosPurse = quatloosIssuer.makeEmptyPurse();
```

Expand Down Expand Up @@ -86,8 +86,8 @@ may pass them by. This is safe, as even if all the assets are withdrawn, the
deposit still works on an empty **Purse**.

```js
const { issuer: quatloosIssuer, mint: quatloosMint, brand: quatloosBrand } =
makeIssuerKit('quatloos');
const { issuer: quatloosIssuer, mint: quatloosMint, brand: quatloosBrand } =
makeIssuerKit('quatloos');
const quatloosPurse = quatloosIssuer.makeEmptyPurse();
const payment = quatloosMint.mintPayment(AmountMath.make(quatloosBrand, 123n));
const quatloos123 = AmountMath.make(quatloosBrand, 123n);
Expand Down Expand Up @@ -158,6 +158,7 @@ const depositOnlyFacet = purse.getDepositFacet();
// a payment, thus depositing the payment assets in the Purse associated with the deposit facet.
depositOnlyFacet.receive(payment);
```

Once you have created a **DepositFacet**, there is one method you can call
on it, **[aDepositFacet.receive()](#adepositfacet-receive-payment-optamount)**. The **DepositFacet** takes a **Payment**
and adds it to the balance of the **DepositFacet**'s associated **Purse**. The **Payment**
Expand Down
2 changes: 1 addition & 1 deletion main/reference/repl/board.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Errors:
```js
// Continuing from the example above in getValue(), the id returns its associated value
command[3] E(home.board).getValue("1403739213")
// returns the "abc" value
// Returns the "abc" value
history[3] [Alleged: presence o-102]{}
```

Expand Down
2 changes: 1 addition & 1 deletion main/reference/repl/networking.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ The other side of `connect()` is a "listening port". These ports are waiting for
To get a listening port, you need a `NetworkInterface` object (such as the one on your `ag-solo` under `home.network`) and ask it to `bind()` to an endpoint. You can either provide a specific port name, or allow the API to allocate a random one for you. The endpoint specifies the type of connection that this port will be able to accept (IBC, TCP, etc), and some properties of that connection. `bind()` uses a "multiaddress" to encode this information.

```js
// ask for a random allocation - ends with a slash
// Ask for a random allocation - ends with a slash
E(home.network).bind('/ibc-port/')
.then(port => usePort(port));

Expand Down
16 changes: 8 additions & 8 deletions main/reference/zoe-api/ratio-math.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,11 @@ denominator, and then the **Ratios** are added.

For example:

1. Let's assume *left* = {numerator: 44n kilometers, denominator: 3n hours} and
*right* = {numerator: 25n kilometers, denominator: 2n hours}.
1. Let's assume *left* = { numerator: 44n kilometers, denominator: 3n hours } and
*right* = { numerator: 25n kilometers, denominator: 2n hours }.
2. *left* would be multiplied by 2/2, and *right* would be multiplied by 3/3, resulting in
*left* = {numerator: 88n kilometers, denominator: 6n hours} and *right* = {numerator: 75n kilometers, denominator: 6n hours}
3. *left* and *right* would then be added together, resulting in {numerator: 163n kilometers, denominator: 6n hours}.
*left* = { numerator: 88n kilometers, denominator: 6n hours } and *right* = { numerator: 75n kilometers, denominator: 6n hours }
3. *left* and *right* would then be added together, resulting in { numerator: 163n kilometers, denominator: 6n hours }.
This **Ratio** would then be returned.


Expand All @@ -298,11 +298,11 @@ denominator, and then *right* is subtracted from *left*.

For example:

1. Let's assume *left* = {numerator: 44n kilometers, denominator: 3n hours} and
*right* = {numerator: 25n kilometers, denominator: 2n hours}.
1. Let's assume *left* = { numerator: 44n kilometers, denominator: 3n hours } and
*right* = { numerator: 25n kilometers, denominator: 2n hours }.
2. *left* would be multiplied by 2/2, and *right* would be multiplied by 3/3, resulting in
*left* = {numerator: 88n kilometers, denominator: 6n hours} and *right* = {numerator: 75n kilometers, denominator: 6n hours}
3. *right* would then be subtracted from *left* would then be added together, resulting in {numerator: 13n kilometers, denominator: 6n hours}.
*left* = { numerator: 88n kilometers, denominator: 6n hours } and *right* = { numerator: 75n kilometers, denominator: 6n hours }
3. *right* would then be subtracted from *left* would then be added together, resulting in { numerator: 13n kilometers, denominator: 6n hours }.
This **Ratio** would then be returned.

## multiplyRatios(left, right)
Expand Down
Loading

0 comments on commit 1d70859

Please sign in to comment.