plutus-use-cases-0.1.0.0: Collection of smart contracts to develop the plutus/wallet interface
Safe HaskellNone
LanguageHaskell2010

Plutus.Contracts.Future

Synopsis

Documentation

A futures contract in Plutus. This example illustrates a number of concepts.

  1. Maintaining a margin (a kind of deposit) during the duration of the contract to protect against breach of contract (see note [Futures in Plutus])
  2. Using oracle values to obtain current pricing information (see note [Oracles] in Plutus.Contracts)
  3. Writing contracts as state machines
  4. Using tokens to represent claims on future cash flows

data Future Source #

Basic data of a futures contract. Future contains all values that do not change during the lifetime of the contract.

Constructors

Future 

Fields

Instances

Instances details
Generic Future Source # 
Instance details

Defined in Plutus.Contracts.Future

Associated Types

type Rep Future :: Type -> Type Source #

Lift DefaultUni Future Source # 
Instance details

Defined in Plutus.Contracts.Future

Typeable DefaultUni Future Source # 
Instance details

Defined in Plutus.Contracts.Future

type Rep Future Source # 
Instance details

Defined in Plutus.Contracts.Future

type Rep Future = D1 ('MetaData "Future" "Plutus.Contracts.Future" "plutus-use-cases-0.1.0.0-sCb7ThsvWbFT6VPXrOzPF" 'False) (C1 ('MetaCons "Future" 'PrefixI 'True) ((S1 ('MetaSel ('Just "ftDeliveryDate") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 POSIXTime) :*: (S1 ('MetaSel ('Just "ftUnits") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Integer) :*: S1 ('MetaSel ('Just "ftUnitPrice") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Value))) :*: (S1 ('MetaSel ('Just "ftInitialMargin") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Value) :*: (S1 ('MetaSel ('Just "ftPriceOracle") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 PaymentPubKey) :*: S1 ('MetaSel ('Just "ftMarginPenalty") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Value)))))

data FutureAccounts Source #

The token accounts that represent ownership of the two sides of the future. When the contract is done, payments will be made to these accounts.

Constructors

FutureAccounts 

Fields

Instances

Instances details
Show FutureAccounts Source # 
Instance details

Defined in Plutus.Contracts.Future

Generic FutureAccounts Source # 
Instance details

Defined in Plutus.Contracts.Future

Associated Types

type Rep FutureAccounts :: Type -> Type Source #

ToJSON FutureAccounts Source # 
Instance details

Defined in Plutus.Contracts.Future

FromJSON FutureAccounts Source # 
Instance details

Defined in Plutus.Contracts.Future

Lift DefaultUni FutureAccounts Source # 
Instance details

Defined in Plutus.Contracts.Future

Typeable DefaultUni FutureAccounts Source # 
Instance details

Defined in Plutus.Contracts.Future

type Rep FutureAccounts Source # 
Instance details

Defined in Plutus.Contracts.Future

type Rep FutureAccounts = D1 ('MetaData "FutureAccounts" "Plutus.Contracts.Future" "plutus-use-cases-0.1.0.0-sCb7ThsvWbFT6VPXrOzPF" 'False) (C1 ('MetaCons "FutureAccounts" 'PrefixI 'True) ((S1 ('MetaSel ('Just "ftoLong") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Account) :*: S1 ('MetaSel ('Just "ftoLongAccount") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ValidatorHash)) :*: (S1 ('MetaSel ('Just "ftoShort") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Account) :*: S1 ('MetaSel ('Just "ftoShortAccount") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ValidatorHash))))

data FutureError Source #

Constructors

TokenSetupFailed CurrencyError

Something went wrong during the setup of the two tokens

StateMachineError SMContractError 
OtherFutureError ContractError 
EscrowFailed EscrowError

The escrow that initialises the future contract failed

EscrowRefunded RefundSuccess

The other party didn't make their payment in time so the contract never started.

Instances

Instances details
Show FutureError Source # 
Instance details

Defined in Plutus.Contracts.Future

Generic FutureError Source # 
Instance details

Defined in Plutus.Contracts.Future

Associated Types

type Rep FutureError :: Type -> Type Source #

ToJSON FutureError Source # 
Instance details

Defined in Plutus.Contracts.Future

FromJSON FutureError Source # 
Instance details

Defined in Plutus.Contracts.Future

AsContractError FutureError Source # 
Instance details

Defined in Plutus.Contracts.Future

AsSMContractError FutureError Source # 
Instance details

Defined in Plutus.Contracts.Future

AsCheckpointError FutureError Source # 
Instance details

Defined in Plutus.Contracts.Future

AsEscrowError FutureError Source # 
Instance details

Defined in Plutus.Contracts.Future

type Rep FutureError Source # 
Instance details

Defined in Plutus.Contracts.Future

type FutureSchema = (((Endpoint "initialise-future" (FutureSetup, Role) .\/ Endpoint "join-future" (FutureAccounts, FutureSetup)) .\/ Endpoint "increase-margin" (Value, Role)) .\/ Endpoint "settle-early" (SignedMessage (Observation Value))) .\/ Endpoint "settle-future" (SignedMessage (Observation Value)) Source #

data FutureSetup Source #

The data needed to initialise the futures contract.

Constructors

FutureSetup 

Fields

Instances

Instances details
Show FutureSetup Source # 
Instance details

Defined in Plutus.Contracts.Future

Generic FutureSetup Source # 
Instance details

Defined in Plutus.Contracts.Future

Associated Types

type Rep FutureSetup :: Type -> Type Source #

ToJSON FutureSetup Source # 
Instance details

Defined in Plutus.Contracts.Future

FromJSON FutureSetup Source # 
Instance details

Defined in Plutus.Contracts.Future

type Rep FutureSetup Source # 
Instance details

Defined in Plutus.Contracts.Future

type Rep FutureSetup = D1 ('MetaData "FutureSetup" "Plutus.Contracts.Future" "plutus-use-cases-0.1.0.0-sCb7ThsvWbFT6VPXrOzPF" 'False) (C1 ('MetaCons "FutureSetup" 'PrefixI 'True) (S1 ('MetaSel ('Just "shortPK") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 PaymentPubKeyHash) :*: (S1 ('MetaSel ('Just "longPK") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 PaymentPubKeyHash) :*: S1 ('MetaSel ('Just "contractStart") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 POSIXTime))))

data Role Source #

The two roles involved in the contract.

Constructors

Long 
Short 

Instances

Instances details
Show Role Source # 
Instance details

Defined in Plutus.Contracts.Future

Generic Role Source # 
Instance details

Defined in Plutus.Contracts.Future

Associated Types

type Rep Role :: Type -> Type Source #

Methods

from :: Role -> Rep Role x Source #

to :: Rep Role x -> Role Source #

ToJSON Role Source # 
Instance details

Defined in Plutus.Contracts.Future

FromJSON Role Source # 
Instance details

Defined in Plutus.Contracts.Future

UnsafeFromData Role Source # 
Instance details

Defined in Plutus.Contracts.Future

FromData Role Source # 
Instance details

Defined in Plutus.Contracts.Future

ToData Role Source # 
Instance details

Defined in Plutus.Contracts.Future

Eq Role Source # 
Instance details

Defined in Plutus.Contracts.Future

Methods

(==) :: Role -> Role -> Bool Source #

Lift DefaultUni Role Source # 
Instance details

Defined in Plutus.Contracts.Future

Typeable DefaultUni Role Source # 
Instance details

Defined in Plutus.Contracts.Future

type Rep Role Source # 
Instance details

Defined in Plutus.Contracts.Future

type Rep Role = D1 ('MetaData "Role" "Plutus.Contracts.Future" "plutus-use-cases-0.1.0.0-sCb7ThsvWbFT6VPXrOzPF" 'False) (C1 ('MetaCons "Long" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Short" 'PrefixI 'False) (U1 :: Type -> Type))

futureStateMachine :: Future -> FutureAccounts -> StateMachine FutureState FutureAction Source #

initialiseFuture :: (HasEndpoint "initialise-future" (FutureSetup, Role) s, AsFutureError e) => Future -> Promise w s e (StateMachineClient FutureState FutureAction) Source #

Initialise the contract by * Generating the tokens for long and short * Setting up an escrow contract for the initial margins * Paying the initial margin for the given role

initialState :: Future -> FutureState Source #

The initial state of the Future contract

setupTokens :: forall w s e. AsFutureError e => Contract w s e FutureAccounts Source #

Create two unique tokens that can be used for the short and long positions and return a FutureAccounts value for them.

Note that after setupTokens is complete, both tokens will be locked by a public key output belonging to the wallet that ran setupTokens.