Skip to content

Commit 6dd13d2

Browse files
rodrigoioyzclaude
andcommitted
Write README with full project documentation
Covers: what Synth Peso is, mint/burn/liquidate flow, Pyth Lazer integration details, build instructions and project structure. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 65dc004 commit 6dd13d2

1 file changed

Lines changed: 143 additions & 1 deletion

File tree

README.md

Lines changed: 143 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,143 @@
1-
🚀 Pyth Cardano Hackathon 2026Team: Los Magníficos!Agustin Salinas (@AgustinBadi)Mauricio Navarrete (@lordkhyron)Rodrigo Oyarzun (@Rodrigoioyz)Contact: librenotgratis@tuta.io📋 Contribution InformationCategoryDetailsContribution Type✅ Hackathon SubmissionProject NameExample SubmissionPyth Product🟢 Pyth Price FeedsBlockchain₳ Cardano📝 Description(Empty)🛠️ Quick Start Guide(Empty)✅ Quality Checklist[x] Make it beautiful: Clean hierarchy and formatting.[x] Code Standards: Follows existing repository patterns.[x] Security: No hardcoded values; uses environment variables.[x] Verification: Locally tested and verified.
1+
🚀 Pyth Cardano Hackathon 2026
2+
3+
Team: Los Magníficos!
4+
Agustin Salinas (@AgustinBadi)
5+
Mauricio Navarrete (@lordkhyron)
6+
Rodrigo Oyarzun (@Rodrigoioyz)
7+
Contact: librenotgratis@tuta.io
8+
9+
📋 Contribution Information
10+
11+
| Category | Details |
12+
|---|---|
13+
| Contribution Type | ✅ Hackathon Submission |
14+
| Project Name | Synth Peso |
15+
| Pyth Product | 🟢 Pyth Price Feeds (Pyth Lazer) |
16+
| Blockchain | ₳ Cardano |
17+
18+
---
19+
20+
## 📝 What is Synth Peso?
21+
22+
**Synth Peso** is a synthetic ADA/USD stablecoin protocol built on Cardano. Users lock ADA as collateral and mint synth tokens pegged to the USD value of that ADA, as determined in real-time by the **Pyth Lazer oracle**. Burning synth tokens returns the corresponding ADA from the collateral pool.
23+
24+
The protocol enforces:
25+
- **Overcollateralization** — you can only mint a fraction of your ADA's USD value (controlled by `collateral_ratio`)
26+
- **Health checks on withdrawal** — you cannot burn synth and withdraw ADA if it leaves the position below the liquidation threshold
27+
- **Open liquidation** — anyone can liquidate an undercollateralized position
28+
- **Owner-only burns** — only the position owner (verified via signature) can voluntarily burn and withdraw
29+
30+
---
31+
32+
## ⚙️ How It Works
33+
34+
### Mint (ADA → Synth USD)
35+
36+
1. User sends ADA to the pool UTxO
37+
2. The on-chain validator reads the live ADA/USD price from Pyth Lazer
38+
3. It computes: `synth_to_mint = (ada_deposited × collateral_ratio / 100) × price`
39+
4. The minting policy mints exactly that amount of synth tokens to the user
40+
41+
### Burn (Synth USD → ADA)
42+
43+
1. User submits synth tokens to burn
44+
2. Validator reads live oracle price
45+
3. Computes ADA to return: `ada_returned = synth_burned / price`
46+
4. Checks remaining position health: `health = (remaining_ada × price) / remaining_debt ≥ liquidation_threshold`
47+
5. Verifies the transaction is signed by the position owner
48+
6. ADA is released from the pool
49+
50+
### Liquidate
51+
52+
1. Any user can trigger liquidation on an undercollateralized position (`health < liquidation_threshold`)
53+
2. The liquidator burns synth tokens and receives the corresponding ADA from the pool
54+
3. No owner signature required — the position's health condition is the only gate
55+
56+
---
57+
58+
## 🔮 How Pyth Lazer is Used
59+
60+
The contract uses [`pyth-network/pyth-lazer-cardano`](https://github.com/pyth-network/pyth-lazer-cardano) (pinned at commit `f78b676`).
61+
62+
### On-chain price reading
63+
64+
```aiken
65+
let updates = pyth.get_updates(pyth_policy_id, tx)
66+
expect [update] = updates
67+
expect Some(feed) = list.find(feeds, fn(f) { u32.as_int(f.feed_id) == ada_usd_feed_id })
68+
expect Some(Some(raw_price)) = feed.price
69+
expect Some(exponent) = feed.exponent
70+
// real_price = raw_price × 10^exponent
71+
```
72+
73+
### How the price reaches the contract
74+
75+
Every mint/burn/liquidate transaction must include:
76+
77+
1. **Pyth State NFT** as a reference input (identified by `pyth_policy_id`) — never spent
78+
2. **A 0-ADA withdrawal** from the Pyth verify script, carrying the signed price message as the redeemer
79+
80+
The Pyth verify script validates the **Ed25519 signature** on each price message before the main validator runs. By the time `get_updates` is called, the price is already cryptographically authenticated.
81+
82+
### Price feed
83+
84+
- **Asset:** ADA/USD
85+
- **Feed ID:** 16
86+
- **Exponent:** -8 (i.e. `raw_price = 70_000_000``$0.70 per ADA`)
87+
- **No contention:** The Pyth State NFT is a reference input — multiple users can mint/burn in the same block without UTxO conflicts
88+
89+
---
90+
91+
## 🛠️ How to Build
92+
93+
### Prerequisites
94+
95+
- [Aiken](https://aiken-lang.org) v1.1.19
96+
97+
```bash
98+
aikup install v1.1.19
99+
```
100+
101+
### Build
102+
103+
```bash
104+
cd on-chain
105+
aiken build
106+
```
107+
108+
This compiles the contracts and generates `on-chain/plutus.json` (the Plutus blueprint).
109+
110+
### Run tests
111+
112+
```bash
113+
cd on-chain
114+
aiken check
115+
```
116+
117+
All 25 unit tests in `lib/utils.ak` cover:
118+
- `health_ratio` — collateral/debt ratio calculation
119+
- `can_adjust` / `is_liquidatable` — position health gates
120+
- `liquidator_payout` / `protocol_payout` — ADA distribution on liquidation
121+
- `compute_expected_synth_amount` — ADA → synth USD conversion (mint and burn directions)
122+
123+
### Project structure
124+
125+
```
126+
on-chain/
127+
validators/
128+
synth-dolar.ak # Main validator: mint policy + spend guard
129+
lib/
130+
utils.ak # Math helpers + 25 unit tests
131+
types/
132+
cdp.ak # CdpDatum type
133+
aiken.toml # Dependencies
134+
```
135+
136+
---
137+
138+
✅ Quality Checklist
139+
140+
- [x] Make it beautiful: Clean hierarchy and formatting.
141+
- [x] Code Standards: Follows existing repository patterns.
142+
- [x] Security: No hardcoded values; uses environment variables.
143+
- [x] Verification: Locally tested and verified.

0 commit comments

Comments
 (0)