Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data Future = Future {
- ftDeliveryDate :: POSIXTime
- ftUnits :: Integer
- ftUnitPrice :: Value
- ftInitialMargin :: Value
- ftPriceOracle :: PaymentPubKey
- ftMarginPenalty :: Value
- data FutureAccounts = FutureAccounts {
- ftoLong :: Account
- ftoLongAccount :: ValidatorHash
- ftoShort :: Account
- ftoShortAccount :: ValidatorHash
- mkAccounts :: Account -> Account -> FutureAccounts
- data FutureError
- = TokenSetupFailed CurrencyError
- | StateMachineError SMContractError
- | OtherFutureError ContractError
- | EscrowFailed EscrowError
- | EscrowRefunded 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))
- data FutureSetup = FutureSetup {
- shortPK :: PaymentPubKeyHash
- longPK :: PaymentPubKeyHash
- contractStart :: POSIXTime
- data Role
- futureContract :: Future -> Contract () FutureSchema FutureError ()
- futureStateMachine :: Future -> FutureAccounts -> StateMachine FutureState FutureAction
- validator :: Future -> FutureAccounts -> Validator
- initialiseFuture :: (HasEndpoint "initialise-future" (FutureSetup, Role) s, AsFutureError e) => Future -> Promise w s e (StateMachineClient FutureState FutureAction)
- initialMargin :: Future -> Value
- futureAddress :: Future -> FutureAccounts -> Address
- tokenFor :: Role -> FutureAccounts -> Value
- initialState :: Future -> FutureState
- typedValidator :: Future -> FutureAccounts -> TypedValidator (StateMachine FutureState FutureAction)
- setupTokens :: forall w s e. AsFutureError e => Contract w s e FutureAccounts
- setupTokensTrace :: EmulatorTrace ()
Documentation
A futures contract in Plutus. This example illustrates a number of concepts.
- Maintaining a margin (a kind of deposit) during the duration of the contract to protect against breach of contract (see note [Futures in Plutus])
- Using oracle values to obtain current pricing information (see note [Oracles] in Plutus.Contracts)
- Writing contracts as state machines
- Using tokens to represent claims on future cash flows
Basic data of a futures contract. Future
contains all values that do not
change during the lifetime of the contract.
Future | |
|
Instances
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.
FutureAccounts | |
|
Instances
mkAccounts :: Account -> Account -> FutureAccounts Source #
data FutureError Source #
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
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.
FutureSetup | |
|
Instances
The two roles involved in the contract.
Instances
Show Role Source # | |
Generic Role Source # | |
FromJSON Role Source # | |
Defined in Plutus.Contracts.Future parseJSON :: Value -> Parser Role parseJSONList :: Value -> Parser [Role] | |
ToJSON Role Source # | |
Defined in Plutus.Contracts.Future | |
ToData Role Source # | |
Defined in Plutus.Contracts.Future toBuiltinData :: Role -> BuiltinData | |
FromData Role Source # | |
Defined in Plutus.Contracts.Future fromBuiltinData :: BuiltinData -> Maybe Role | |
Eq Role Source # | |
Defined in Plutus.Contracts.Future | |
UnsafeFromData Role Source # | |
Defined in Plutus.Contracts.Future unsafeFromBuiltinData :: BuiltinData -> Role | |
Lift DefaultUni Role Source # | |
Defined in Plutus.Contracts.Future | |
Typeable DefaultUni Role Source # | |
Defined in Plutus.Contracts.Future | |
type Rep Role Source # | |
futureContract :: Future -> Contract () FutureSchema FutureError () Source #
futureStateMachine :: Future -> FutureAccounts -> StateMachine FutureState FutureAction Source #
validator :: Future -> FutureAccounts -> Validator 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
initialMargin :: Future -> Value Source #
futureAddress :: Future -> FutureAccounts -> Address Source #
tokenFor :: Role -> FutureAccounts -> Value Source #
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 #