Smart Contract Design Document
Below session illustrates the detailed logic, structure, pseudocode, and flow diagram of the DeltaDeFi smart contract
Detailed Logic, Structure & Pseudocode of the Smart Contract
Below 2 validators illustrate the detailed logic, structures and pseudocode code of the smart contract of DeltaDeFi
Take Orders Validator
Parameters:
oracle_nft: The policy id ofOracleNFTparam_long_token: The long side of token in trading pairsparam_short_token: The short side of token in trading pairs
Datum:
account_address: The address of the account number of the owneris_long: If the current order is for buying long token (buy_token)list_price_times_10k: Order exchange in a rate oflist_price*lot_size= quantity ofparam_short_tokenlot_size: Quantity ofsell tokenin this orderowner:The pub key hash of owner of the order
User Action:
Core logic of taking orders - Redeemer
TakeOrdersWithdrawal script of
take_ordersvalidating
Cancelling order which is mistakenly listed onchain - Redeemer
CancelOrderWhole value spent to
Accountwith correct owner in datumsigned by both
operating_keyand owner
Pseudocode:
Virtual DEX Validator
Parameters:
oracle_nft: The policy id ofOracleNFTtake_orders: The script hash oftake_orderswithdrawal script
User Action:
Normal operation:Reference to oracle utxo
Accumulate proceeds supposed send to order creators, check output value to them
Signed by operation key
Pseudocode:
Flow Diagram
The flow diagram shows the flows for different scenarios. The first scenario illustrates an ADA seller creates an order and the order matches another subsequent order requesting to sell USD stablecoin. After the validation of the smart contract, the smart contract will unlock the funds and execute the transactions shown per user wallet. The expected output to each user wallet ("account'") is shown in the diagram for the first scenario. The second scenario is basically the reverse situation compared to first scenario.

Last updated