Skip to the content.

The salesperson pattern

Intent

Creation of a smart contract where 1 instance of the smart contract will allow for an arbitrary amount of trades, where each trade is an exchange between a customer and the creator.

Consequences

Structure

Again, the way that the buyer gets hold of the customerInvitation is a design choice made by the smart contract designer: it is not included in this pattern.

Participants

Implementation

const start = zcf => {
  let internalSeat;
  const sellOfferHandler = creatorSeat => {
    internalSeat = creatorSeat;
    //...
  };
  const buyOfferHandler = customerSeat => {
    //some trade between customerSeat and internalSeat
  };
  const creatorInvitation = zcf.makeInvitation(sellOfferHandler, 'sell');  
  return harden({ creatorInvitation });
};
harden(start);
export { start };

The smart contract has an internal seat internalSeat. The first thing that the creator should do, is register itself as the seller. The offer handler linked to the creatorInvitation will set the internalSeat equal to the creatorSeat. Thus, by offering the creatorInvitation, the creator can register itself as the salesperson. All customers will trade with this internalSeat: the offer handler related to the customerInvitation will perform some kind of reallocation between the customerSeat and the internalSeat. Just as in the managed assets pattern, the high-level overview of the implementation of the salesperson pattern does not include how the invitation linked to the buyOfferHandler is obtained. This is a decision that should be made by the contract designer.

Known uses