Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zoe contract typings #1488

Merged
merged 4 commits into from
Aug 16, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"bootstrap": "bootstrap",
"bundles": {
"zcf": {
"sourceSpec": "@agoric/zoe/src/contractFacet/contractFacet.js"
"sourceSpec": "@agoric/zoe/contractFacet"
}
},
"vats": {
Expand Down
2 changes: 1 addition & 1 deletion packages/cosmic-swingset/lib/ag-solo/vats/solo-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"bootstrap": "bootstrap",
"bundles": {
"zcf": {
"sourceSpec": "@agoric/zoe/src/contractFacet/contractFacet.js"
"sourceSpec": "@agoric/zoe/contractFacet"
}
},
"vats": {
Expand Down
4 changes: 2 additions & 2 deletions packages/eventual-send/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ type ERef<T> = PromiseLike<T> | T;

type Unpromise<T> = T extends ERef<infer U> ? U : T;

type Parameters<T> = T extends (... args: infer T) => any ? T : never;
type ReturnType<T> = T extends (... args: any[]) => infer T ? T : never;
type Parameters<T> = T extends (...args: infer T) => any ? T : any;
type ReturnType<T> = T extends (...args: any[]) => infer T ? T : any;

interface EHandler<T> {
get?: (p: T, name: Property) => any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"bootstrap": "bootstrap",
"bundles": {
"zcf": {
"sourceSpec": "@agoric/zoe/src/contractFacet/contractFacet.js"
"sourceSpec": "@agoric/zoe/contractFacet"
}
},
"vats": {
Expand Down
1 change: 1 addition & 0 deletions packages/zoe/contractFacet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './src/contractFacet/contractFacet';
1 change: 1 addition & 0 deletions packages/zoe/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
},
"files": [
"src/",
"*.js",
"NEWS.md"
],
"eslintConfig": {
Expand Down
1 change: 1 addition & 0 deletions packages/zoe/src/contracts/automaticRefund.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const start = zcf => {
};
const makeRefundInvitation = () => zcf.makeInvitation(refund, 'getRefund');

/** @type {AutomaticRefundPublicFacet} */
const publicFacet = harden({
getOffersCount: () => offersCount,
makeInvitation: makeRefundInvitation,
Expand Down
1 change: 1 addition & 0 deletions packages/zoe/src/contracts/autoswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ const start = async zcf => {

const getPoolAllocation = poolSeat.getCurrentAllocation;

/** @type {AutoswapPublicFacet} */
const publicFacet = harden({
getCurrentPrice,
getLiquidityIssuer: () => liquidityIssuer,
Expand Down
49 changes: 49 additions & 0 deletions packages/zoe/src/contracts/exported.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* @typedef {Object} SellItemsPublicFacet
* @property {() => Issuer} getItemsIssuer
* @property {() => Amount} getAvailableItems
*
* @typedef {Object} SellItemsCreatorOnly
* @property {() => Promise<Invitation>} makeBuyerInvitation
*
* @typedef {SellItemsPublicFacet & SellItemsCreatorOnly} SellItemsCreatorFacet
*/

/**
* @typedef {Object} SellItemsParameters
* @property {Record<string, any>} customValueProperties
* @property {number} count
* @property {Issuer} moneyIssuer
* @property {Installation} sellItemsInstallation
* @property {Amount} pricePerItem
*
* @typedef {Object} SellItemsResult
* @property {UserSeat} sellItemsCreatorSeat
* @property {SellItemsCreatorFacet} sellItemsCreatorFacet
* @property {Instance} sellItemsInstance
* @property {SellItemsPublicFacet} sellItemsPublicFacet
*
* @typedef {Object} MintAndSellNFTCreatorFacet
* @property {(sellParams: SellItemsParameters) => Promise<SellItemsResult>} sellTokens
* @property {() => Issuer} getIssuer
*/

/**
* @typedef {Object} AutoswapPublicFacet
* @property {() => Promise<Invitation>} makeSwapInvitation
* @property {() => Promise<Invitation>} makeAddLiquidityInvitation
* @property {() => Promise<Invitation>} makeRemoveLiquidityInvitation
* @property {() => Issuer} getLiquidityIssuer
* @property {(from: Amount, toBrand: Brand) => Amount} getCurrentPrice
* @property {() => Record<string, Amount>} getPoolAllocation
*/
/**
* @typedef {Object} AutomaticRefundPublicFacet
* @property {() => number} getOffersCount
* @property {() => Promise<Invitation>} makeInvitation
*/
/**
* @typedef {Object} SimpleExchangePublicFacet
* @property {() => Promise<Invitation>} makeInvitation
* @property {() => Notifier<any>} getNotifier
*/
24 changes: 19 additions & 5 deletions packages/zoe/src/contracts/mintAndSellNFT.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import '../../exported';
* This contract mints non-fungible tokens and creates a selling contract
* instance to sell the tokens in exchange for some sort of money.
*
* startInstance() returns an invitation that, when exercised, returns a
* startInstance() returns a creatorFacet which is a
* ticketMaker with a `.sellTokens()` method. `.sellTokens()` takes a
* specification of what is being sold, such as:
* {
Expand Down Expand Up @@ -77,9 +77,21 @@ const start = zcf => {
const sellItemsTerms = harden({
pricePerItem,
});
return E(zoeService)
.startInstance(sellItemsInstallation, issuerKeywordRecord, sellItemsTerms)
.then(({ creatorInvitation, creatorFacet, instance, publicFacet }) => {
/**
* @type {Promise<{
* creatorInvitation: Invitation,
* creatorFacet: SellItemsCreatorFacet,
* instance: Instance,
* publicFacet: SellItemsPublicFacet,
* }>}
*/
const instanceRecordP = E(zoeService).startInstance(
sellItemsInstallation,
issuerKeywordRecord,
sellItemsTerms,
);
return instanceRecordP.then(
({ creatorInvitation, creatorFacet, instance, publicFacet }) => {
return E(zoeService)
.offer(creatorInvitation, proposal, paymentKeywordRecord)
.then(sellItemsCreatorSeat => {
Expand All @@ -90,9 +102,11 @@ const start = zcf => {
sellItemsPublicFacet: publicFacet,
});
});
});
},
);
};

/** @type {MintAndSellNFTCreatorFacet} */
const creatorFacet = harden({ sellTokens, getIssuer: () => issuer });

return harden({ creatorFacet });
Expand Down
2 changes: 2 additions & 0 deletions packages/zoe/src/contracts/sellItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,13 @@ const start = zcf => {

const getItemsIssuer = () => issuers.Items;

/** @type {SellItemsPublicFacet} */
const publicFacet = {
getAvailableItems,
getItemsIssuer,
};

/** @type {SellItemsCreatorFacet} */
const creatorFacet = {
makeBuyerInvitation: () => {
const itemsAmount = sellerSeat.getAmountAllocated('Items');
Expand Down
1 change: 1 addition & 0 deletions packages/zoe/src/contracts/simpleExchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ const start = zcf => {
const makeExchangeInvitation = () =>
zcf.makeInvitation(exchangeOfferHandler, 'exchange');

/** @type {SimpleExchangePublicFacet} */
const publicFacet = harden({
makeInvitation: makeExchangeInvitation,
getNotifier: () => notifier,
Expand Down
10 changes: 5 additions & 5 deletions packages/zoe/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
* @property {(instance: Instance) => IssuerKeywordRecord} getIssuers
* @property {(instance: Instance) => BrandKeywordRecord} getBrands
* @property {(instance: Instance) => Object} getTerms
* @property {(invitation: invitation) => Promise<Instance>} getInstance
* @property {(invitation: invitation) => Promise<Installation>} getInstallation
* @property {(invitation: invitation) => Promise<InvitationDetails>}
* @property {(invitation: Invitation) => Promise<Instance>} getInstance
* @property {(invitation: Invitation) => Promise<Installation>} getInstallation
* @property {(invitation: Invitation) => Promise<InvitationDetails>}
* getInvitationDetails - return an object with the instance,
* installation, description, invitation handle, and any custom properties
* specific to the contract.
Expand Down Expand Up @@ -122,8 +122,8 @@

/**
* @typedef {Object} StartInstanceResult
* @property {Record<string, Function>} creatorFacet
* @property {Record<string, Function>} publicFacet
* @property {any} creatorFacet
* @property {any} publicFacet
* @property {Instance} instance
* @property {Payment} creatorInvitation
*/
Expand Down