Skip to content

Commit 7173cad

Browse files
authored
feat: implement Dutch auction liquidation interface with commit-reveal front-running protection (#746)
- Add auction-types shared library with Auction, AuctionConfig, BidCommitment, BidReveal, BidResult types - Add liquidation-auction contract with full Dutch auction lifecycle - Support linear and exponential price decay functions - Configurable starting premium, floor discount, and auction duration - Partial fills with commit-reveal scheme for MEV protection - Auction cancellation when position health is restored - Event emissions for all auction lifecycle events (start, bid, settle, cancel) - Add both contracts to workspace Cargo.toml Closes #446
1 parent 40f50b3 commit 7173cad

5 files changed

Lines changed: 728 additions & 0 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "auction-types"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[lib]
7+
crate-type = ["lib", "rlib"]
8+
9+
[dependencies]
10+
soroban-sdk = { workspace = true }
11+
12+
[dev-dependencies]
13+
soroban-sdk = { workspace = true, features = ["testutils"] }
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#![no_std]
2+
3+
use soroban_sdk::{contracterror, contracttype, Address, BytesN};
4+
5+
#[contracttype]
6+
#[derive(Clone, Debug, PartialEq)]
7+
pub enum AuctionState {
8+
Pending,
9+
Active,
10+
PartiallyFilled,
11+
FullyFilled,
12+
Settled,
13+
Cancelled,
14+
}
15+
16+
#[contracttype]
17+
#[derive(Clone, Debug, PartialEq)]
18+
pub struct AuctionConfig {
19+
pub starting_premium_bps: i128,
20+
pub floor_discount_bps: i128,
21+
pub auction_duration: u64,
22+
pub price_decay_function: PriceDecayFunction,
23+
pub min_bid_size: i128,
24+
pub commit_phase_duration: u64,
25+
pub reveal_phase_duration: u64,
26+
}
27+
28+
#[contracttype]
29+
#[derive(Clone, Debug, PartialEq)]
30+
pub enum PriceDecayFunction {
31+
Linear,
32+
Exponential,
33+
}
34+
35+
#[contracttype]
36+
#[derive(Clone, Debug, PartialEq)]
37+
pub struct Auction {
38+
pub id: u64,
39+
pub pool: Address,
40+
pub user: Address,
41+
pub collateral_asset: Address,
42+
pub debt_asset: Address,
43+
pub collateral_amount: i128,
44+
pub debt_amount: i128,
45+
pub start_time: u64,
46+
pub end_time: u64,
47+
pub starting_price: i128,
48+
pub floor_price: i128,
49+
pub current_price: i128,
50+
pub remaining_collateral: i128,
51+
pub filled_amount: i128,
52+
pub state: AuctionState,
53+
pub config: AuctionConfig,
54+
pub created_at: u64,
55+
}
56+
57+
#[contracttype]
58+
#[derive(Clone, Debug, PartialEq)]
59+
pub struct BidCommitment {
60+
pub bidder: Address,
61+
pub commitment_hash: BytesN<32>,
62+
pub auction_id: u64,
63+
pub timestamp: u64,
64+
}
65+
66+
#[contracttype]
67+
#[derive(Clone, Debug, PartialEq)]
68+
pub struct BidReveal {
69+
pub bidder: Address,
70+
pub auction_id: u64,
71+
pub collateral_amount: i128,
72+
pub max_price: i128,
73+
pub nonce: BytesN<32>,
74+
pub timestamp: u64,
75+
}
76+
77+
#[contracttype]
78+
#[derive(Clone, Debug, PartialEq)]
79+
pub struct BidResult {
80+
pub auction_id: u64,
81+
pub bidder: Address,
82+
pub collateral_filled: i128,
83+
pub price_paid: i128,
84+
pub debt_repaid: i128,
85+
}
86+
87+
#[contracterror]
88+
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
89+
#[repr(u32)]
90+
pub enum AuctionError {
91+
AlreadyInitialized = 1,
92+
NotAuthorized = 2,
93+
AuctionNotFound = 3,
94+
InvalidState = 4,
95+
AuctionExpired = 5,
96+
AuctionNotExpired = 6,
97+
InsufficientCollateral = 7,
98+
InvalidBidAmount = 8,
99+
CommitmentAlreadyExists = 9,
100+
CommitmentNotFound = 10,
101+
RevealPhaseNotActive = 11,
102+
InvalidReveal = 12,
103+
BidTooLow = 13,
104+
AlreadyFilled = 14,
105+
InvalidConfig = 15,
106+
AuctionStillActive = 16,
107+
PositionHealthRestored = 17,
108+
NoBidsReceived = 18,
109+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "liquidation-auction"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[lib]
7+
crate-type = ["cdylib", "rlib"]
8+
9+
[dependencies]
10+
soroban-sdk = { workspace = true }
11+
lending-types = { path = "../lending-types" }
12+
auction-types = { path = "../auction-types" }
13+
14+
[dev-dependencies]
15+
soroban-sdk = { workspace = true, features = ["testutils"] }
16+
17+
[[example]]
18+
name = "deploy"
19+
path = "examples/deploy.rs"
20+
crate-type = ["bin"]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
use liquidation_auction::{LiquidationAuctionContract, LiquidationAuctionContractClient};
2+
use soroban_sdk::{Address, Env};
3+
4+
// Example: deploy the contract
5+
pub fn deploy(env: &Env) {
6+
let contract_id = env
7+
.deployer()
8+
.with_current_contract("")
9+
.deploy(LiquidationAuctionContract);
10+
let _client = LiquidationAuctionContractClient::new(env, &contract_id);
11+
}

0 commit comments

Comments
 (0)