Skip to the content.

The composite contract pattern

Intent

Reusing a generic smart contract by wrapping the generic smart contract within another smart contract that configures the generic smart contract.

Consequences

Structure

Participants

Implementation

const start = zcf => {
    const zoe = zcf.getZoeService();
    const startInstanceOfWrappedContract = ({
      installationWrappedContract,
      /*other parameters*/
    }) => {
      const issuerKeywordRecord = harden({/*issuer keywords*/});
      //...
      return E(zoe).startInstance(
        installationWrappedContract,
        issuerKeywordRecord,
        /*terms*/
      );
    };
    const creatorFacet = Far('creatorFacet', {
      startInstanceOfWrappedContract
    });
    return harden({ creatorFacet });
  };
  harden(start);
  export { start };

The composite pattern consists of 2 smart contracts: an outer smart contract called the wrapper smart contract, and an inner smart contract called the wrapped smart contract. The wrapped smart contract is a generic smart contract that is to be configured. The wrapper smart contract starts an instance of the wrapped smart contract and configures this wrapped smart contract. The wrapper smart contract then returns the objects returned by the wrapped smart contract.

Known uses

/