Skip to content

Commit 12de3f0

Browse files
committed
fixup! start pushing want patterns into zoe
1 parent 671c77f commit 12de3f0

File tree

15 files changed

+84
-76
lines changed

15 files changed

+84
-76
lines changed

packages/ERTP/src/typeGuards.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { M, matches, getInterfaceGuardPayload } from '@endo/patterns';
44
/**
5-
* @import {AmountValue, Amount, AmountValueHasBound, AmountValueBound, AmountBound, Ratio} from './types.js'
5+
* @import {AmountValue, Amount, AmountValueHasBound, AmountValueBound, AmountBound, Ratio, NatValue} from './types.js'
66
* @import {TypedPattern} from '@agoric/internal'
77
* @import {CopyBag, CopySet, Pattern} from '@endo/patterns';
88
*/
@@ -117,8 +117,8 @@ harden(RatioShape);
117117
/**
118118
* Returns true if value is a Nat bigint.
119119
*
120-
* @param {AmountValue} value
121-
* @returns {value is import('./types.js').NatValue}
120+
* @param {AmountValueBound} value
121+
* @returns {value is NatValue}
122122
*/
123123
export const isNatValue = value => matches(value, NatValueShape);
124124
harden(isNatValue);

packages/zoe/exported.d.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import {
1010
AmountKeywordRecord as _AmountKeywordRecord,
1111
ContractMeta as _ContractMeta,
1212
Handle as _Handle,
13-
Installation as _Installation,
14-
Instance as _Instance,
1513
Invitation as _Invitation,
1614
InvitationAmount as _InvitationAmount,
1715
IssuerKeywordRecord as _IssuerKeywordRecord,
@@ -26,6 +24,11 @@ import {
2624
ZoeService as _ZoeService,
2725
} from './src/types-index.js';
2826

27+
import {
28+
Installation as _Installation,
29+
Instance as _Instance,
30+
} from './src/zoeService/utils.js';
31+
2932
declare global {
3033
// @ts-ignore TS2666: Exports and export assignments are not permitted in module augmentations.
3134
export {
@@ -35,7 +38,7 @@ declare global {
3538
_FeeIssuerConfig as FeeIssuerConfig,
3639
_Handle as Handle,
3740
_Installation as Installation,
38-
_Instance as Instance,
41+
// _Instance as Instance,
3942
_Invitation as Invitation,
4043
_InvitationAmount as InvitationAmount,
4144
_IssuerKeywordRecord as IssuerKeywordRecord,

packages/zoe/src/contractFacet/offerSafety.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { AmountMath } from '@agoric/ertp';
22

3+
/**
4+
* @import { AmountKeywordRecord, AmountBoundKeywordRecord } from '../zoeService/types.js'
5+
*/
6+
37
/**
48
* Helper to perform satisfiesWant and satisfiesGive. Is
59
* allocationAmount greater than or equal to requiredAmount for every
@@ -9,19 +13,19 @@ import { AmountMath } from '@agoric/ertp';
913
* isOfferSafe will still be boolean. When we have Multiples, satisfiesWant and
1014
* satisfiesGive will tell how many times the offer was matched.
1115
*
12-
* @param {AmountKeywordRecord} giveOrWant
16+
* @param {AmountBoundKeywordRecord} giveOrWant
1317
* @param {AmountKeywordRecord} allocation
1418
* @returns {0|1}
1519
*/
1620
const satisfiesInternal = (giveOrWant = {}, allocation) => {
17-
const isGTEByKeyword = ([keyword, requiredAmount]) => {
21+
const isGTEByKeyword = ([keyword, requiredAmountBound]) => {
1822
// If there is no allocation for a keyword, we know the giveOrWant
1923
// is not satisfied without checking further.
2024
if (allocation[keyword] === undefined) {
2125
return 0;
2226
}
2327
const allocationAmount = allocation[keyword];
24-
return AmountMath.isGTE(allocationAmount, requiredAmount) ? 1 : 0;
28+
return AmountMath.isGTE(allocationAmount, requiredAmountBound) ? 1 : 0;
2529
};
2630
return Object.entries(giveOrWant).every(isGTEByKeyword) ? 1 : 0;
2731
};

packages/zoe/src/contractFacet/types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@ import type {
1616
AmountKeywordRecord,
1717
ExitRule,
1818
FeeMintAccess,
19-
Instance,
2019
InvitationDetails,
2120
Keyword,
2221
ProposalRecord,
2322
StandardTerms,
2423
UserSeat,
2524
ZoeService,
2625
} from '../types-index.js';
27-
import type { ContractStartFunction } from '../zoeService/utils.js';
26+
import type { ContractStartFunction, Instance } from '../zoeService/utils.js';
2827

2928
/**
3029
* Any passable non-thenable. Often an explanatory string.

packages/zoe/src/contractSupport/ratio.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export const makeRatioFromAmounts = (numeratorAmount, denominatorAmount) => {
104104
* @returns {Amount<'nat'>}
105105
*/
106106
const multiplyHelper = (amount, ratio, divideOp) => {
107-
AmountMath.coerce(amount.brand, amount);
107+
amount = AmountMath.coerce(amount.brand, amount);
108108
assertIsRatio(ratio);
109109
amount.brand === ratio.denominator.brand ||
110110
Fail`amount's brand ${q(amount.brand)} must match ratio's denominator ${q(

packages/zoe/src/contracts/auction/firstPriceLogic.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ export const calcWinnerAndClose = (zcf, sellSeat, bidSeats) => {
1111
want: { Ask: minBid },
1212
} = sellSeat.getProposal();
1313

14-
/** @type {Brand<'nat'>} */
15-
const bidBrand = minBid.brand;
14+
const bidBrand = /** @type {Brand<'nat'>} */ (minBid.brand);
1615
const emptyBid = AmountMath.makeEmpty(bidBrand);
1716

1817
let highestBid = emptyBid;

packages/zoe/src/contracts/auction/secondPriceLogic.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ export const calcWinnerAndClose = (zcf, sellSeat, bidSeats) => {
1111
want: { Ask: minBid },
1212
} = sellSeat.getProposal();
1313

14-
/** @type {Brand<'nat'>} */
15-
const bidBrand = minBid.brand;
14+
const bidBrand = /** @type {Brand<'nat'>} */ (minBid.brand);
1615
const emptyBid = AmountMath.makeEmpty(bidBrand);
1716

1817
let highestBid = emptyBid;

packages/zoe/src/contracts/loan/borrow.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { assert, Fail } from '@endo/errors';
22
import { E } from '@endo/eventual-send';
33
import { Far } from '@endo/marshal';
44
import { makePromiseKit } from '@endo/promise-kit';
5+
import { M, mustMatch } from '@endo/patterns';
56
import { AmountMath } from '@agoric/ertp';
67

78
import {
@@ -16,6 +17,10 @@ import { calculateInterest, makeDebtCalculator } from './updateDebt.js';
1617
import { makeCloseLoanInvitation } from './close.js';
1718
import { makeAddCollateralInvitation } from './addCollateral.js';
1819

20+
/**
21+
* @import {NatAmount} from '@agoric/ertp';
22+
*/
23+
1924
/** @type {MakeBorrowInvitation} */
2025
export const makeBorrowInvitation = (zcf, config) => {
2126
const {
@@ -28,7 +33,9 @@ export const makeBorrowInvitation = (zcf, config) => {
2833
} = config;
2934

3035
// We can only lend what the lender has already escrowed.
31-
const maxLoan = lenderSeat.getAmountAllocated('Loan');
36+
const maxLoan = /** @type {NatAmount} */ (
37+
lenderSeat.getAmountAllocated('Loan')
38+
);
3239

3340
/** @type {OfferHandler} */
3441
const borrow = async borrowerSeat => {
@@ -43,7 +50,10 @@ export const makeBorrowInvitation = (zcf, config) => {
4350
borrowerSeat.getProposal().give.Collateral.brand
4451
),
4552
);
46-
const loanWanted = borrowerSeat.getProposal().want.Loan;
53+
const loanWanted = /** @type {NatAmount} */ (
54+
borrowerSeat.getProposal().want.Loan
55+
);
56+
mustMatch(loanWanted.value, M.nat());
4757
const loanBrand = zcf.getTerms().brands.Loan;
4858

4959
// The value of the collateral in the Loan brand

packages/zoe/src/internal-types.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
/// <reference types="@agoric/ertp/exported" />
33

44
/**
5-
* @import {Allocation, AnyTerms, BrandKeywordRecord, Completion, ContractStartFn, InvitationHandle, PaymentPKeywordRecord, UserSeat, ZoeIssuerRecord} from '@agoric/zoe';
65
* @import {Pattern} from '@endo/patterns';
6+
* @import {IssuerRecord} from '@agoric/ertp';
7+
* @import {Allocation, AnyTerms, BrandKeywordRecord, Completion, ContractStartFn, InvitationHandle, PaymentPKeywordRecord, UserSeat, ZoeIssuerRecord} from '@agoric/zoe';
78
*/
89

910
/**
@@ -196,7 +197,7 @@
196197
/**
197198
* @template {AssetKind} [K=AssetKind]
198199
* @typedef {object} ZoeMint
199-
* @property {() => import('@agoric/ertp').IssuerRecord<K>} getIssuerRecord
200+
* @property {() => IssuerRecord<K>} getIssuerRecord
200201
* @property {(totalToMint: Amount<K>) => void} mintAndEscrow
201202
* @property {(totalToBurn: Amount<K>) => void} withdrawAndBurn
202203
* Note that the burning is asynchronous, and so may not have happened by

packages/zoe/src/types.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
import type {
2-
Issuer,
3-
Brand,
4-
AssetKind,
5-
DisplayInfo,
6-
AnyAmount,
7-
} from '@agoric/ertp';
1+
import type { ERef } from '@endo/eventual-send';
82
import type { RemotableObject } from '@endo/pass-style';
9-
import type { Key } from '@endo/patterns';
3+
import type { Issuer, Brand } from '@agoric/ertp';
104

115
/**
126
* Alias for RemotableObject
@@ -24,10 +18,7 @@ export type Keyword = string;
2418
*/
2519
export type InvitationHandle = Handle<'Invitation'>;
2620
export type IssuerKeywordRecord = Record<Keyword, Issuer<any>>;
27-
export type IssuerPKeywordRecord = Record<
28-
Keyword,
29-
import('@endo/far').ERef<Issuer<any>>
30-
>;
21+
export type IssuerPKeywordRecord = Record<Keyword, ERef<Issuer<any>>>;
3122
export type BrandKeywordRecord = Record<Keyword, Brand<any>>;
3223
export type StandardTerms = {
3324
/**

0 commit comments

Comments
 (0)