Skip to content

Instantly share code, notes, and snippets.

View gyorgybalazsi's full-sized avatar

György Balázsi gyorgybalazsi

  • Rock Star Consulting
  • Budapest Hungary
  • 01:45 (UTC +02:00)
  • X @winnfield
View GitHub Profile
@gyorgybalazsi
gyorgybalazsi / FinLibId.hs
Last active August 27, 2020 14:13
Financial Library ID
-- | A versioned identifier backed by a set of signatories. Can be used as
-- a primary key or foreign key of a contract.
data Id = Id
with
signatories : Set Party
-- ^ The parties that need to sign a contract with this id and
-- that are responsible to ensure primary key uniqueness.
label : Text
-- ^ A label that makes a contract unique for a given set of signatories.
version : Int
@gyorgybalazsi
gyorgybalazsi / AssetDeposit.hs
Created August 27, 2020 14:15
Asset Deposit contract
-- | Represents a deposit of an asset in an account. The `account.id` and `asset.id` fields
-- can be used to link the contract to other contracts that provide further information
-- such as the type of the asset or reference data for it. This allows new asset classes
-- to be added without having to modify business processes that operate on generic
-- asset deposits.
template AssetDeposit
with
account : Account
-- ^ A deposit is allocated to an account and backed by the account.id.signatories.
-- Depending on the desired trust model this might be (i) both the provider and the
@gyorgybalazsi
gyorgybalazsi / SettlementInstruction.hs
Created August 27, 2020 14:41
Settlement Instruction
-- | Data describing settlement details.
data SettlementDetails = SettlementDetails
with
senderAccount : Account
-- ^ The sender account.
receiverAccount : Account
-- ^ The receiver account.
depositCid : Optional (ContractId AssetDeposit)
-- ^ The allocated asset deposit.
deriving (Eq, Show)
@gyorgybalazsi
gyorgybalazsi / EnsureSettlementInstruction.hs
Created August 27, 2020 14:47
ensure field of the SettlementInstruction contract
ensure length steps > 0 && asset.quantity > 0.0
&& all (\(s1,s2) -> s1.receiverAccount.owner == s2.senderAccount.owner) (zip steps $ tail steps)
@gyorgybalazsi
gyorgybalazsi / NextSender.hs
Created August 27, 2020 17:12
The nextSender function
nextSender : SettlementInstruction -> Optional Party
nextSender SettlementInstruction{..} = (.senderAccount.owner) <$> find (\step -> isNone step.depositCid) steps
@gyorgybalazsi
gyorgybalazsi / SettlementInstruction_AllocateNext.hs
Created August 27, 2020 17:52
AllocateNext choice of the SettlementInstruction template
choice SettlementInstruction_AllocateNext : ContractId SettlementInstruction
-- ^ Allocates an asset deposit to the next step of the settlement instruction.
-- In the simple case where both counterparties have an account with the same provider
-- a single allocation by the sender party is required.
with
depositCid : ContractId AssetDeposit
-- ^ Specifies the asset deposit contract to be allocated.
ctrl : Party
-- ^ The next sender.
controller ctrl
@gyorgybalazsi
gyorgybalazsi / SettlementInstruction_Process.hs
Created August 27, 2020 18:44
The SettlementInstruction_Process choice
controller masterAgreement.id.signatories can
SettlementInstruction_Process : [ContractId AssetDeposit]
-- ^ Processes a settlement instruction by transferring all allocated asset deposits.
-- This choice is often called from the trade itself to atomically settle all
-- assets involved.
do
mapA
(\x -> do
exerciseByKey @AssetSettlementRule x.senderAccount.id AssetSettlement_Transfer with
receiverAccountId = x.receiverAccount.id, depositCid = fromSome x.depositCid
@gyorgybalazsi
gyorgybalazsi / EquityOptionDetails.hs
Created September 2, 2020 07:32
Equity Option details
data OptionType = PUT | CALL deriving (Eq, Show)
data ExerciseType = EUROPEAN | AMERICAN deriving (Eq, Show)
data SettlementType = CASH | PHYSICAL deriving (Eq, Show)
@gyorgybalazsi
gyorgybalazsi / Entitlement.hs
Created September 2, 2020 15:19
Entitlement
-- | Reference data describing an asset that entitles the owner to receive the
-- underlying asset at the settlement date. Can be used to lifecycle asset
-- deposits, trades or dependent instruments.
template Entitlement
with
id : Id
-- ^ The asset id of the entitlement. Depending on the trust model the
-- signatories might be the issuer or a third party reference data provider
-- such as Reuters.
settlementDate : Date
@gyorgybalazsi
gyorgybalazsi / AssetAllocationSignatoriesObservers.hs
Created September 30, 2020 07:03
Asset Allocation signatories and observers
where
signatory union masterAgreement.id.signatories $ fromList sendersDone
observer insert masterAgreement.party1 $ insert masterAgreement.party2
$ union observers $ fromList sendersPending