Skip to content

Commit

Permalink
docs: specs of virtual dex
Browse files Browse the repository at this point in the history
  • Loading branch information
HinsonSIDAN committed Dec 9, 2023
1 parent 52879df commit 5663537
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 8 deletions.
7 changes: 4 additions & 3 deletions lib/aiken-virtual-dex/types.ak
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ pub type TradeAddressRedeemer {
// 6. ChangeAccount
pub type ChangeAddressDatum {
ChangeNormalDatum
ChangeEmergencyDatum { valid_since: Int }
}

pub type ChangeAddressRedeemer {
Expand All @@ -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,
Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions lib/aiken-virtual-dex/validators/virtual_dex.ak
Original file line number Diff line number Diff line change
Expand Up @@ -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<ScriptPurpose, Data>) -> Bool {
Expand Down Expand Up @@ -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
}
}
2 changes: 1 addition & 1 deletion specs/0_scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion specs/5_trade_account.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 37 additions & 0 deletions specs/7_virtual_dex.md
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5663537

Please sign in to comment.