diff --git a/lib/aiken-virtual-dex/types.ak b/lib/aiken-virtual-dex/types.ak index 4fc60ec..2d3ec44 100644 --- a/lib/aiken-virtual-dex/types.ak +++ b/lib/aiken-virtual-dex/types.ak @@ -71,7 +71,6 @@ pub type TradeAddressRedeemer { // 6. ChangeAccount pub type ChangeAddressDatum { ChangeNormalDatum - ChangeEmergencyDatum { valid_since: Int } } pub type ChangeAddressRedeemer { @@ -82,6 +81,7 @@ pub type ChangeAddressRedeemer { // 7. VirtualDex pub type VirtualDexDatum { + account_number: Int, long_token: (PolicyId, AssetName), short_token: (PolicyId, AssetName), price: Int, @@ -90,9 +90,10 @@ pub type VirtualDexDatum { } pub type VirtualDexRedeemer { - TakeOrder - CancelOrder + TakeOrder { order_taker: Address } MassTakeOrder { take_order_output: OutputReference } + CancelOrder + EmergencyCancel } // 8. EmergencyToken diff --git a/lib/aiken-virtual-dex/validators/virtual_dex.ak b/lib/aiken-virtual-dex/validators/virtual_dex.ak index dca4e54..90b4c5c 100644 --- a/lib/aiken-virtual-dex/validators/virtual_dex.ak +++ b/lib/aiken-virtual-dex/validators/virtual_dex.ak @@ -2,8 +2,8 @@ use aiken/transaction.{InlineDatum, ScriptContext, Spend, Transaction} use aiken/transaction/value.{PolicyId} use aiken_virtual_dex/common.{inputs_with} use aiken_virtual_dex/types.{ - CancelOrder, MassTakeOrder, OracleDatum, TakeOrder, VirtualDexDatum, - VirtualDexRedeemer, + CancelOrder, EmergencyCancel, MassTakeOrder, OracleDatum, TakeOrder, + VirtualDexDatum, VirtualDexRedeemer, } // pub fn valid_virtual_dex_redeemer(redeemers: Dict) -> Bool { @@ -34,9 +34,10 @@ pub fn virtual_dex_logic( // CreateContent { content_hash: _, owner: _ } -> True // _ -> False // } - TakeOrder -> True + TakeOrder { .. } -> True // for each script inputs, calculate the total should pay amount CancelOrder -> True + EmergencyCancel -> True } } diff --git a/specs/0_scripts.md b/specs/0_scripts.md index 65e8631..4e0ec8b 100644 --- a/specs/0_scripts.md +++ b/specs/0_scripts.md @@ -26,7 +26,7 @@ There are in total 7 scripts for the DeltaDeFi virtual dex to work. Below provid - The script to be compiled into different addresses according to account number, storing the change UTxO after transaction. -7. VirtualDEX +7. VirtualDEX - [specification](./7_virtual_dex) - The script governing the transaction logic. diff --git a/specs/5_trade_account.md b/specs/5_trade_account.md index a37933e..7db383b 100644 --- a/specs/5_trade_account.md +++ b/specs/5_trade_account.md @@ -23,7 +23,7 @@ - Reference to account info utxo - Signed by operation key & owner -2. Emergency operation - Redeemer `TradeEmergencyAction {new_owner_pub_key, new_owner_stake_cred}` +2. Emergency operation - Redeemer `TradeEmergencyAction {withdraw_output}` - Reference to account info utxo - Signed by owner diff --git a/specs/7_virtual_dex.md b/specs/7_virtual_dex.md new file mode 100644 index 0000000..b1c0f0e --- /dev/null +++ b/specs/7_virtual_dex.md @@ -0,0 +1,37 @@ +# Specification - VirtualDex + +## Parameter + +- `utxo_ref`: UTxO to be spent at minting + +## Datum + +- `account_number`: The account number of owner of order +- `long_token`: The `AssetClass` of token in long side +- `short_token`: The `AssetClass` of token in short side +- `price`: Order exchange in a rate of `price` \* `long token` = `short token` +- `is_lot_long`: If the user is selling short token for long token +- `log_size`: Quantity of `long token` in this order + +## User Action + +1. Core logic of taking orders - Redeemer `TakeOrder {order_taker}` + + - Reference to oracle utxo + - Reference to account info utxo of ann account owners + - Accumulate proceeds supposed send to order creators, check output value to them + - Cumulated amount send to `order_taker` + - Signed by operation owner + +2. Bypassing check if any other redeemer is with the core logic - Redeemer `MassTakeOrder { take_order_output }` + + - The output provided by redeemer is with correct redeemer of `TakeOrder` + +3. Cancelling order which is mistakenly listed onchain - Redeemer `CancelOrder` + + - signed by both `operating_key` and owner + +4. Emergency operation - Redeemer `EmergencyCancel` + + - Reference to account info utxo + - `EmergencyToken` is burnt in current transaction