In this example, we will consider a decentralized token sale, where the seller is providing buyback guarantees.

This guarantee is done in the following way: a seller requires a buyer to create a buy order at some price and of some token amount also. The rest is going to the seller.

Every order can have unique buyback properties (e.g. form a bonding curve).

We start with a buyback contract. It has expiration (buyerPk && sigmaProp(HEIGHT > 100) condition); otherwise, the box has been spent if asked the number of tokens sent back to the original seller.

    {
val defined = OUTPUTS(0).R2[Coll[(Coll[Byte], Long)]].isDefined &&  OUTPUTS(0).R4[Coll[Byte]].isDefined
(buyerPk && sigmaProp(HEIGHT > 100)) || sigmaProp (if (defined) {
allOf(Coll(
OUTPUTS(0).tokens(0)._1 == tokenId,
OUTPUTS(0).tokens(0)._2 >= tokenAmount,
OUTPUTS(0).propositionBytes == sellerPk.propBytes,
OUTPUTS(0).R4[Coll[Byte]].get == SELF.id)
)
} else { false } )
}

Sell contract is then as follows:
      {
sigmaProp(allOf(Coll(
blake2b256(OUTPUTS(0).propositionBytes) == bbh,

Where bbh is buyback script hash.