Skip to the content.

The managed assets pattern

Intent

Creating a level of indirection between the creator of the smart contract and a potential customer.

Consequences

Structure

Note that this seat structure diagram does not specify how the customer got hold of the customerInvitation. This is because the way that the customer obtained the customerInvitation is irrelevant for the managed assets pattern. An example of how the customer could have gotten the customerInvitation is via the independent participation pattern.

Participants

Implementation

const start = async zcf => {
  const { zcfSeat: internalSeat } = zcf.makeEmptySeatKit();
  const makeDepositOfferHandler = depositSeat => {
    //some reallocation to internalSeat
  }
  const makeWithdrawOfferHandler = withdrawSeat => {
    //some reallocation from internalSeat
  }
  const customerOfferHandler = customerSeat => {
    //some reallocation to internalSeat
  }
  const creatorFacet = Far('creatorFacet', {
    makeDepositInvitation: () => zcf.makeInvitation(makeDepositOfferHandler, 'deposit'),
    makeWithdrawInvitation: () => zcf.makeInvitation(makeWithdrawOfferHandler, 'withdraw')
  });
  return harden({ creatorFacet });
};
harden(start);
export { start };

The smart contract has an internal seat internalSeat which is used as a level of indirection between the creator and the customer. A customer will perform all of its trades with the internalSeat. The smart contract returns a creatorFacet. This creatorFacet provides the creator with methods to create depositInvitations and withdrawInvitations. A depositInvitation can be used in an offer to deposit inventory to the internalSeat. A withdrawInvitation can be used in an offer to withdraw gains made from the trades from the internalSeat. Note that in the code above the customerOfferHandler is not linked to any invitation. The contract designer should determine how invitations are made available to customers.

Known uses