|
| 1 | +# Simplicity DEX — Developer Guide |
| 2 | + |
| 3 | +This short guide helps contributors understand, build, test and extend the project. It focuses on practical commands and |
| 4 | +the patterns used across crates (not exhaustive; follow Rust and crate docs for deeper dives). |
| 5 | + |
| 6 | +## Project layout |
| 7 | + |
| 8 | +- crates/dex-cli — command line client and UX helpers |
| 9 | +- crates/dex-nostr-relay — relay logic, event parsing and storage |
| 10 | +- crates/global-utils — other helpers |
| 11 | + |
| 12 | +## Prerequisites |
| 13 | + |
| 14 | +- Install Rust |
| 15 | +- Create your nostr keypair (Can be generated here: https://start.nostr.net/) |
| 16 | + |
| 17 | +## Quick start |
| 18 | + |
| 19 | +1. Build: |
| 20 | + - cargo build -r |
| 21 | +2. Run CLI (local dev): |
| 22 | + - `cargo build -r` |
| 23 | + - `mkdir -p ./demo` |
| 24 | + - `mv ./target/release/simplicity-dex ./demo/simplicity-dex` |
| 25 | + - `cp ./.simplicity-dex.example/.simplicity-dex.config.toml ./demo/.simplicity-dex.config.toml` |
| 26 | + - `echo SEED_HEX=ffff0123456789abcdef0123456789abcdef0123456789abcdef0123456789ab > ./demo/.env` |
| 27 | +3. Insert your valid nostr keypair into `.simplicity-dex.config.toml` |
| 28 | + |
| 29 | +## Commands example execution |
| 30 | + |
| 31 | +Overall trading for dcd contracts can be split in two sides: taker and maker. |
| 32 | + |
| 33 | +Maker and Taker responsible for taking such steps: |
| 34 | + |
| 35 | +1) Maker initializes contract in Liquid; |
| 36 | +2) Maker funds contract with collateral and settlement tokens. (by now for test **collateral** = LBTC-Testnet, **settlement** = minted token from scratch) |
| 37 | +3) Taker funds contract with collateral tokens and takes contract parameters from already discovered maker event_id. |
| 38 | +4) Maker now can make: |
| 39 | + * Early collateral termination |
| 40 | + * Early settlement termination |
| 41 | +5) Taker now can make: |
| 42 | + * Early termination |
| 43 | +6) After `settlement-height` both maker and taker can use settlement exit to receive their tokens (collateral or settlement) depending on the settlement token price, which is signed with oracle. |
| 44 | + |
| 45 | +1. Create your own contract with your values. For example can be taken |
| 46 | + |
| 47 | +* `taker-funding-start-time` 1764328373 (timestamp can be taken from https://www.epochconverter.com/) |
| 48 | +* `taker-funding-end-time` 1764358373 (Block time when taker funding period ends) |
| 49 | +* `contract-expiry-time` 1764359373 (Block time when contract expires) |
| 50 | +* `early-termination-end-time` 1764359373 (Block time when early termination is no longer allowed) |
| 51 | +* `settlement-height` 2169368 (Block height at which oracle price is attested) |
| 52 | +* `principal-collateral-amount` 2000 (Base collateral amount) |
| 53 | +* `incentive-basis-points` 1000 (Incentive in basis points (1 bp = 0.01%)) |
| 54 | +* `filler-per-principal-collateral` 100 (Filler token ratio) |
| 55 | +* `strike-price` 25 (Oracle strike price for settlement) |
| 56 | +* `settlement-asset-entropy` `0ffa97b7ee6fcaac30b0c04803726f13c5176af59596874a3a770cbfd2a8d183` (Asset entropy (hex) for settlement) |
| 57 | +* `oracle-pubkey` `757f7c05d2d8f92ab37b880710491222a0d22b66be83ae68ff75cc6cb15dd2eb` (`./simplicity-dex helpers address --account-index 5`) |
| 58 | + |
| 59 | +Actual command in cli: |
| 60 | +```bash |
| 61 | +./simplicity-dex maker init |
| 62 | + --utxo-1 <FIRST_LBTC_UTXO> |
| 63 | + --utxo-2 <SECOND_LBTC_UTXO> |
| 64 | + --utxo-3 <THIRD_LBTC_UTXO> |
| 65 | + --taker-funding-start-time <TAKER_FUNDING_START_TIME> |
| 66 | + --taker-funding-end-time <TAKER_FUNDING_END_TIME> |
| 67 | + --contract-expiry-time <CONTRACT_EXPIRY_TIME> |
| 68 | + --early-termination-end-time <EARLY_TERMINATION_END_TIME> |
| 69 | + --settlement-height <SETTLEMENT_HEIGHT> |
| 70 | + --principal-collateral-amount <PRINCIPAL_COLLATERAL_AMOUNT> |
| 71 | + --incentive-basis-points <INCENTIVE_BASIS_POINTS> |
| 72 | + --filler-per-principal-collateral <FILLER_PER_PRINCIPAL_COLLATERAL> |
| 73 | + --strike-price <STRIKE_PRICE> |
| 74 | + --settlement-asset-entropy <SETTLEMENT_ASSET_ENTROPY> |
| 75 | + --oracle-pubkey <ORACLE_PUBLIC_KEY> |
| 76 | +``` |
| 77 | + |
| 78 | +2. Maker fund cli command: |
| 79 | +```bash |
| 80 | +./simplicity-dex maker fund |
| 81 | + --filler-utxo <FILLER_TOKEN_UTXO> |
| 82 | + --grant-coll-utxo <GRANTOR_COLLATERAL_TOKEN_UTXO> |
| 83 | + --grant-settl-utxo <GRANTOR_SETTLEMENT_TOKEN_UTXO> |
| 84 | + --settl-asset-utxo <SETTLEMENT_ASSET_UTXO> |
| 85 | + --fee-utxo <FEE_UTXO> |
| 86 | + --taproot-pubkey-gen <DCD_TAPROOT_PUBKEY_GEN> |
| 87 | +``` |
| 88 | + |
| 89 | +3. Taker has to fund |
| 90 | + |
| 91 | +```bash |
| 92 | +./simplicity-dex taker fund |
| 93 | + --filler-utxo <FILLER_TOKEN_UTXO> |
| 94 | + --collateral-utxo <COLLATERAL_TOKEN_UTXO> |
| 95 | + --collateral-amount-deposit <COLLATERAL_AMOUNT_TO_DEPOSIT> |
| 96 | + --maker-order-event-id <MAKER_ORDER_EVENT_ID> |
| 97 | +``` |
| 98 | + |
| 99 | +4. Taker can wait for specific `settlement-height` and gracefully exit contract: |
| 100 | +```bash |
| 101 | +./simplicity-dex taker settlement |
| 102 | + --filler-utxo <FILLER_TOKEN_UTXO> |
| 103 | + --asset-utxo <ASSET_UTXO> |
| 104 | + --fee-utxo <FEE_UTXO> |
| 105 | + --filler-to-burn <FILLER_AMOUNT_TO_BURN> |
| 106 | + --price-now <PRICE_AT_CURRENT_BLOCK_HEIGHT> |
| 107 | + --oracle-sign <ORACLE_SIGNATURE> |
| 108 | + --maker-order-event-id <MAKER_ORDER_EVENT_ID> |
| 109 | +``` |
| 110 | + |
| 111 | +5. Maker can wait for specific `settlement-height` and gracefully exit contract: |
| 112 | +```bash |
| 113 | + ./simplicity-dex maker settlement |
| 114 | + --grant-collateral-utxo <GRANTOR_COLLATERAL_TOKEN_UTXO> |
| 115 | + --grant-settlement-utxo <GRANTOR_SETTLEMENT_TOKEN_UTXO> |
| 116 | + --asset-utxo <ASSET_UTXO> |
| 117 | + --fee-utxo <FEE_UTXO> |
| 118 | + --grantor-amount-burn <GRANTOR_AMOUNT_TO_BURN> |
| 119 | + --price-now <PRICE_AT_CURRENT_BLOCK_HEIGHT> |
| 120 | + --oracle-sign <ORACLE_SIGNATURE> |
| 121 | + --maker-order-event-id <MAKER_ORDER_EVENT_ID> |
| 122 | +``` |
| 123 | + |
| 124 | +* Maker or Taker depending on the can use Merge(2/3/4) command to merge collateral tokens. |
| 125 | +This is made exactly for combining outs into one to eliminate execution of contract with usage of little fragments |
| 126 | +```bash |
| 127 | +./simplicity-dex helpers merge-tokens4 |
| 128 | + --token-utxo-1 <TOKEN_UTXO_1> |
| 129 | + --token-utxo-2 <TOKEN_UTXO_2> |
| 130 | + --token-utxo-3 <TOKEN_UTXO_3> |
| 131 | + --token-utxo-4 <TOKEN_UTXO_4> |
| 132 | + --fee-utxo <FEE_UTXO> |
| 133 | + --maker-order-event-id <MAKER_ORDER_EVENT_ID> |
| 134 | +``` |
| 135 | + |
| 136 | +* For early collateral termination Maker can use command: |
| 137 | +```bash |
| 138 | +./simplicity-dex maker termination-collateral |
| 139 | + --grantor-collateral-utxo <GRANTOR_COLLATERAL_TOKEN_UTXO> |
| 140 | + --collateral-utxo <COLLATERAL_TOKEN_UTXO> |
| 141 | + --fee-utxo <FEE_UTXO> |
| 142 | + --grantor-collateral-burn <GRANTOR_COLLATERAL_AMOUNT_TO_BURN> |
| 143 | + --maker-order-event-id <MAKER_ORDER_EVENT_ID> |
| 144 | +``` |
| 145 | + |
| 146 | +* For early settlement termination Maker can use command: |
| 147 | +```bash |
| 148 | +./simplicity-dex maker termination-settlement |
| 149 | + --settlement-asset-utxo <SETTLEMENT_ASSET_UTXO> |
| 150 | + --grantor-settlement-utxo <GRANTOR_SETTLEMENT_TOKEN_UTXO> |
| 151 | + --fee-utxo <FEE_UTXO> |
| 152 | + --grantor-settlement-amount-burn <GRANTOR_SETTLEMENT_AMOUNT_TO_BURN> |
| 153 | + --maker-order-event-id <MAKER_ORDER_EVENT_ID> |
| 154 | +``` |
| 155 | + |
| 156 | +* For early termination Taker can use command: |
| 157 | +```bash |
| 158 | +./simplicity-dex taker termination-early |
| 159 | + --filler-utxo <FILLER_TOKEN_UTXO> |
| 160 | + --collateral-utxo <COLLATERAL_TOKEN_UTXO> |
| 161 | + --fee-utxo <FEE_UTXO> |
| 162 | + --filler-to-return <FILLER_TOKEN_AMOUNT_TO_RETURN> |
| 163 | + --maker-order-event-id <MAKER_ORDER_EVENT_ID |
| 164 | +``` |
0 commit comments