Skip to content

Commit 23ed67c

Browse files
authored
WIP: Breaking changes in Zoe and ERTP in Beta - Part 1 (#2986)
* refactor!: remove deprecated `kickOut` (#2984) * refactor!: remove makePercent (#2987) * refactor!: move fakeVatAdmin to tools/, and remove from contractFacet/ (#2985) * refactor!: Rename AmountMathKind and MathKind to AssetKind (#3054)
1 parent 25d5d43 commit 23ed67c

File tree

72 files changed

+477
-727
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+477
-727
lines changed

packages/ERTP/src/amountMath.js

+28-26
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,27 @@ import {
1313
looksLikeBrand,
1414
} from './typeGuards';
1515

16-
// We want an enum, but narrowed to the AmountMathKind type.
16+
// We want an enum, but narrowed to the AssetKind type.
1717
/**
18-
* Constants for the kinds of amountMath we support.
18+
* Constants for the kinds of assets we support.
1919
*
2020
* @type {{ NAT: 'nat', SET: 'set' }}
2121
*/
22-
const MathKind = {
22+
const AssetKind = {
2323
NAT: 'nat',
2424
SET: 'set',
2525
};
26-
harden(MathKind);
26+
harden(AssetKind);
2727

2828
/**
2929
* Amounts describe digital assets. From an amount, you can learn the
30-
* kind of digital asset as well as "how much" or "how many". Amounts
31-
* have two parts: a brand (the kind of digital asset) and the value
32-
* (the answer to "how much"). For example, in the phrase "5 bucks",
33-
* "bucks" takes the role of the brand and the value is 5. Amounts
34-
* can describe fungible and non-fungible digital assets. Amounts are
35-
* pass-by-copy and can be made by and sent to anyone.
30+
* brand of digital asset as well as "how much" or "how many". Amounts
31+
* have two parts: a brand (loosely speaking, the type of digital
32+
* asset) and the value (the answer to "how much"). For example, in
33+
* the phrase "5 bucks", "bucks" takes the role of the brand and the
34+
* value is 5. Amounts can describe fungible and non-fungible digital
35+
* assets. Amounts are pass-by-copy and can be made by and sent to
36+
* anyone.
3637
*
3738
* The issuer has an internal table that maps purses and payments to
3839
* amounts. The issuer must be able to do things such as add digital
@@ -51,15 +52,16 @@ harden(MathKind);
5152
*
5253
* amountMath uses mathHelpers to do most of the work, but then adds
5354
* the brand to the result. The function `value` gets the value from
54-
* the amount by removing the brand (amount -> value), and the function
55-
* `make` adds the brand to produce an amount (value -> amount). The
56-
* function `coerce` takes an amount and checks it, returning an amount (amount
57-
* -> amount).
55+
* the amount by removing the brand (amount -> value), and the
56+
* function `make` adds the brand to produce an amount (value ->
57+
* amount). The function `coerce` takes an amount and checks it,
58+
* returning an amount (amount -> amount).
5859
*
59-
* Each issuer of digital assets has an associated brand in a one-to-one
60-
* mapping. In untrusted contexts, such as in analyzing payments and
61-
* amounts, we can get the brand and find the issuer which matches the
62-
* brand. The issuer and the brand mutually validate each other.
60+
* Each issuer of digital assets has an associated brand in a
61+
* one-to-one mapping. In untrusted contexts, such as in analyzing
62+
* payments and amounts, we can get the brand and find the issuer
63+
* which matches the brand. The issuer and the brand mutually validate
64+
* each other.
6365
*/
6466

6567
/** @type {{ nat: NatMathHelpers, set: SetMathHelpers }} */
@@ -82,8 +84,8 @@ const getHelpersFromValue = value => {
8284
assert.fail(X`value ${value} must be a bigint or an array`);
8385
};
8486

85-
/** @type {(amount: Amount) => AmountMathKind} */
86-
const getMathKind = amount => {
87+
/** @type {(amount: Amount) => AssetKind} */
88+
const getAssetKind = amount => {
8789
if (looksLikeSetValue(amount.value)) {
8890
return 'set';
8991
}
@@ -199,16 +201,16 @@ const AmountMath = {
199201
},
200202
// @ts-ignore TODO Why doesn't this type correctly?
201203
getValue: (brand, amount) => AmountMath.coerce(brand, amount).value,
202-
makeEmpty: (brand, mathKind = MathKind.NAT) => {
204+
makeEmpty: (brand, assetKind = AssetKind.NAT) => {
203205
assert(
204-
helpers[mathKind],
205-
X`${mathKind} must be MathKind.NAT or MathKind.SET`,
206+
helpers[assetKind],
207+
X`${assetKind} must be AssetKind.NAT or AssetKind.SET`,
206208
);
207209
assertLooksLikeBrand(brand);
208-
return noCoerceMake(helpers[mathKind].doMakeEmpty(), brand);
210+
return noCoerceMake(helpers[assetKind].doMakeEmpty(), brand);
209211
},
210212
makeEmptyFromAmount: amount =>
211-
AmountMath.makeEmpty(amount.brand, getMathKind(amount)),
213+
AmountMath.makeEmpty(amount.brand, getAssetKind(amount)),
212214
isEmpty: (amount, brand = undefined) => {
213215
assertLooksLikeAmount(amount);
214216
optionalBrandCheck(amount, brand);
@@ -253,4 +255,4 @@ harden(AmountMath);
253255
*/
254256
const amountMath = AmountMath;
255257

256-
export { amountMath, AmountMath, MathKind, getMathKind };
258+
export { amountMath, AmountMath, AssetKind, getAssetKind };

packages/ERTP/src/displayInfo.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,20 @@ function assertDisplayInfo(allegedDisplayInfo) {
4646
passStyleOf(allegedDisplayInfo) === 'copyRecord',
4747
X`A displayInfo can only be a pass-by-copy record: ${allegedDisplayInfo}`,
4848
);
49-
const displayInfoKeys = harden(['decimalPlaces']);
49+
const displayInfoKeys = harden(['decimalPlaces', 'assetKind']);
5050
assertKeysAllowed(displayInfoKeys, allegedDisplayInfo);
5151
}
5252
export { assertDisplayInfo };
5353

5454
/**
55-
* @param {DisplayInfo} [allegedDisplayInfo={}]
55+
* @param {AdditionalDisplayInfo} allegedDisplayInfo
56+
* @param {AssetKind} assetKind
5657
* @returns {DisplayInfo}
5758
*/
58-
export const coerceDisplayInfo = (allegedDisplayInfo = {}) => {
59-
const copyDisplayInfo = pureCopy(allegedDisplayInfo);
59+
export const coerceDisplayInfo = (allegedDisplayInfo, assetKind) => {
60+
const copyDisplayInfo = pureCopy(
61+
harden({ ...allegedDisplayInfo, assetKind }),
62+
);
6063
assertDisplayInfo(copyDisplayInfo);
6164
return copyDisplayInfo;
6265
};

packages/ERTP/src/issuer.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Far } from '@agoric/marshal';
99
import { makeNotifierKit } from '@agoric/notifier';
1010
import { isPromise } from '@agoric/promise-kit';
1111

12-
import { amountMath, MathKind } from './amountMath';
12+
import { amountMath, AssetKind } from './amountMath';
1313
import { makeFarName, ERTPKind } from './interfaces';
1414
import { coerceDisplayInfo } from './displayInfo';
1515
import { makePaymentMaker } from './payment';
@@ -21,11 +21,17 @@ import './types';
2121
*/
2222
function makeIssuerKit(
2323
allegedName,
24-
amountMathKind = MathKind.NAT,
24+
assetKind = AssetKind.NAT,
2525
displayInfo = harden({}),
2626
) {
2727
assert.typeof(allegedName, 'string');
28-
displayInfo = coerceDisplayInfo(displayInfo);
28+
assert(
29+
Object.values(AssetKind).includes(assetKind),
30+
X`The assetKind ${assetKind} must be either AssetKind.NAT or AssetKind.SET`,
31+
);
32+
33+
// add assetKind to displayInfo, or override if present
34+
const cleanDisplayInfo = coerceDisplayInfo(displayInfo, assetKind);
2935

3036
/** @type {Brand} */
3137
const brand = Far(makeFarName(allegedName, ERTPKind.BRAND), {
@@ -38,7 +44,7 @@ function makeIssuerKit(
3844
getAllegedName: () => allegedName,
3945

4046
// Give information to UI on how to display the amount.
41-
getDisplayInfo: () => displayInfo,
47+
getDisplayInfo: () => cleanDisplayInfo,
4248
});
4349

4450
/** @type {(left: Amount, right: Amount) => Amount } */
@@ -51,7 +57,7 @@ function makeIssuerKit(
5157
const isEqual = (left, right) => amountMath.isEqual(left, right, brand);
5258

5359
/** @type {Amount} */
54-
const emptyAmount = amountMath.makeEmpty(brand, amountMathKind);
60+
const emptyAmount = amountMath.makeEmpty(brand, assetKind);
5561

5662
const makePayment = makePaymentMaker(allegedName, brand);
5763

@@ -193,7 +199,8 @@ function makeIssuerKit(
193199
const issuer = Far(makeFarName(allegedName, ERTPKind.ISSUER), {
194200
getBrand: () => brand,
195201
getAllegedName: () => allegedName,
196-
getAmountMathKind: () => amountMathKind,
202+
getAssetKind: () => assetKind,
203+
getDisplayInfo: () => cleanDisplayInfo,
197204
makeEmptyPurse: makePurse,
198205

199206
isLive: paymentP => {
@@ -283,6 +290,7 @@ function makeIssuerKit(
283290
mint,
284291
issuer,
285292
brand,
293+
displayInfo: cleanDisplayInfo,
286294
});
287295
}
288296

packages/ERTP/src/mathHelpers/setMathHelpers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const hashBadly = thing => {
3636
return getKeyForRecord(thing);
3737
}
3838
assert.fail(
39-
X`typeof ${typeof thing} is not allowed in an amount of MathKind.SET`,
39+
X`typeof ${typeof thing} is not allowed in an amount of AssetKind.SET`,
4040
);
4141
};
4242

0 commit comments

Comments
 (0)