plutus-use-cases-1.2.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

Methods

lift :: Future -> RTCompile DefaultUni fun (Term TyName Name DefaultUni fun ())

Typeable DefaultUni Future Source # 
Instance details

Defined in Plutus.Contracts.Future

Methods

typeRep :: Proxy Future -> RTCompile DefaultUni fun (Type TyName DefaultUni ())

type Rep Future Source # 
Instance details

Defined in Plutus.Contracts.Future

type Rep Future = D1 ('MetaData "Future" "Plutus.Contracts.Future" "plutus-use-cases-1.2.0.0-BuYOLXrynPcLosE012cowc" '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

  • ftoLong :: Account

    The owner of the "long" account (represented by a token)

  • ftoLongAccount :: ValidatorHash

    Address of the TokenAccount validator script for ftoLong. This hash can be derived from ftoLong, but only in off-chain code. We store it here so that we can lift it into on-chain code.

  • ftoShort :: Account

    The owner of the "short" account (represented by a token).

  • ftoShortAccount :: ValidatorHash

    Address of the TokenAccount validator script for ftoShort. The comment on ftoLongAccount applies to this as well.

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 #

FromJSON FutureAccounts Source # 
Instance details

Defined in Plutus.Contracts.Future

Methods

parseJSON :: Value -> Parser FutureAccounts

parseJSONList :: Value -> Parser [FutureAccounts]

ToJSON FutureAccounts Source # 
Instance details

Defined in Plutus.Contracts.Future

Methods

toJSON :: FutureAccounts -> Value

toEncoding :: FutureAccounts -> Encoding

toJSONList :: [FutureAccounts] -> Value

toEncodingList :: [FutureAccounts] -> Encoding

Lift DefaultUni FutureAccounts Source # 
Instance details

Defined in Plutus.Contracts.Future

Methods

lift :: FutureAccounts -> RTCompile DefaultUni fun (Term TyName Name DefaultUni fun ())

Typeable DefaultUni FutureAccounts Source # 
Instance details

Defined in Plutus.Contracts.Future

Methods

typeRep :: Proxy FutureAccounts -> RTCompile DefaultUni fun (Type TyName DefaultUni ())

type Rep FutureAccounts Source # 
Instance details

Defined in Plutus.Contracts.Future

type Rep FutureAccounts = D1 ('MetaData "FutureAccounts" "Plutus.Contracts.Future" "plutus-use-cases-1.2.0.0-BuYOLXrynPcLosE012cowc" '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 #

FromJSON FutureError Source # 
Instance details

Defined in Plutus.Contracts.Future

Methods

parseJSON :: Value -> Parser FutureError

parseJSONList :: Value -> Parser [FutureError]

ToJSON FutureError Source # 
Instance details

Defined in Plutus.Contracts.Future

Methods

toJSON :: FutureError -> Value

toEncoding :: FutureError -> Encoding

toJSONList :: [FutureError] -> Value

toEncodingList :: [FutureError] -> Encoding

AsCheckpointError FutureError Source # 
Instance details

Defined in Plutus.Contracts.Future

Methods

_CheckpointError :: Prism' FutureError CheckpointError

_JSONDecodeError :: Prism' FutureError Text

AsContractError FutureError Source # 
Instance details

Defined in Plutus.Contracts.Future

Methods

_ContractError :: Prism' FutureError ContractError

_WalletContractError :: Prism' FutureError WalletAPIError

_ChainIndexContractError :: Prism' FutureError (Text, ChainIndexResponse)

_ConstraintResolutionContractError :: Prism' FutureError MkTxError

_ToCardanoConvertContractError :: Prism' FutureError ToCardanoError

_ResumableContractError :: Prism' FutureError MatchingError

_CCheckpointContractError :: Prism' FutureError CheckpointError

_EndpointDecodeContractError :: Prism' FutureError (EndpointDescription, EndpointValue Value, Text)

_OtherContractError :: Prism' FutureError Text

AsSMContractError FutureError Source # 
Instance details

Defined in Plutus.Contracts.Future

Methods

_SMContractError :: Prism' FutureError SMContractError

_ChooserError :: Prism' FutureError Text

_UnableToExtractTransition :: Prism' FutureError ()

_SMCContractError :: Prism' FutureError ContractError

AsEscrowError FutureError Source # 
Instance details

Defined in Plutus.Contracts.Future

type Rep FutureError Source # 
Instance details

Defined in Plutus.Contracts.Future

type Rep FutureError = D1 ('MetaData "FutureError" "Plutus.Contracts.Future" "plutus-use-cases-1.2.0.0-BuYOLXrynPcLosE012cowc" 'False) ((C1 ('MetaCons "TokenSetupFailed" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 CurrencyError)) :+: C1 ('MetaCons "StateMachineError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 SMContractError))) :+: (C1 ('MetaCons "OtherFutureError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ContractError)) :+: (C1 ('MetaCons "EscrowFailed" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 EscrowError)) :+: C1 ('MetaCons "EscrowRefunded" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 RefundSuccess)))))

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

  • shortPK :: PaymentPubKeyHash

    Initial owner of the short token

  • longPK :: PaymentPubKeyHash

    Initial owner of the long token

  • contractStart :: POSIXTime

    Start of the futures contract itself. By this time the setup code has to be finished, otherwise the contract is void.

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 #

FromJSON FutureSetup Source # 
Instance details

Defined in Plutus.Contracts.Future

Methods

parseJSON :: Value -> Parser FutureSetup

parseJSONList :: Value -> Parser [FutureSetup]

ToJSON FutureSetup Source # 
Instance details

Defined in Plutus.Contracts.Future

Methods

toJSON :: FutureSetup -> Value

toEncoding :: FutureSetup -> Encoding

toJSONList :: [FutureSetup] -> Value

toEncodingList :: [FutureSetup] -> Encoding

type Rep FutureSetup Source # 
Instance details

Defined in Plutus.Contracts.Future

type Rep FutureSetup = D1 ('MetaData "FutureSetup" "Plutus.Contracts.Future" "plutus-use-cases-1.2.0.0-BuYOLXrynPcLosE012cowc" '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 #

FromJSON Role Source # 
Instance details

Defined in Plutus.Contracts.Future

Methods

parseJSON :: Value -> Parser Role

parseJSONList :: Value -> Parser [Role]

ToJSON Role Source # 
Instance details

Defined in Plutus.Contracts.Future

Methods

toJSON :: Role -> Value

toEncoding :: Role -> Encoding

toJSONList :: [Role] -> Value

toEncodingList :: [Role] -> Encoding

ToData Role Source # 
Instance details

Defined in Plutus.Contracts.Future

Methods

toBuiltinData :: Role -> BuiltinData

FromData Role Source # 
Instance details

Defined in Plutus.Contracts.Future

Methods

fromBuiltinData :: BuiltinData -> Maybe Role

Eq Role Source # 
Instance details

Defined in Plutus.Contracts.Future

Methods

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

UnsafeFromData Role Source # 
Instance details

Defined in Plutus.Contracts.Future

Methods

unsafeFromBuiltinData :: BuiltinData -> Role

Lift DefaultUni Role Source # 
Instance details

Defined in Plutus.Contracts.Future

Methods

lift :: Role -> RTCompile DefaultUni fun (Term TyName Name DefaultUni fun ())

Typeable DefaultUni Role Source # 
Instance details

Defined in Plutus.Contracts.Future

Methods

typeRep :: Proxy Role -> RTCompile DefaultUni fun (Type TyName DefaultUni ())

type Rep Role Source # 
Instance details

Defined in Plutus.Contracts.Future

type Rep Role = D1 ('MetaData "Role" "Plutus.Contracts.Future" "plutus-use-cases-1.2.0.0-BuYOLXrynPcLosE012cowc" '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

typedValidator :: Future -> FutureAccounts -> TypedValidator (StateMachine FutureState FutureAction) Source #

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.

setupTokensTrace :: EmulatorTrace () Source #