penumbra_sdk_auction/
event.rs

1use crate::auction::dutch::{DutchAuctionDescription, DutchAuctionState};
2use crate::auction::AuctionId;
3use penumbra_sdk_asset::asset;
4use penumbra_sdk_num::Amount;
5use penumbra_sdk_proto::penumbra::core::component::auction::v1 as pb;
6
7/// Event for a Dutch auction that has been scheduled.
8pub fn dutch_auction_schedule_event(
9    id: AuctionId,
10    description: DutchAuctionDescription,
11) -> pb::EventDutchAuctionScheduled {
12    pb::EventDutchAuctionScheduled {
13        auction_id: Some(id.into()),
14        description: Some(description.into()),
15    }
16}
17
18/// Event for an execution round of a Dutch auction.
19pub fn dutch_auction_updated(
20    id: AuctionId,
21    state: DutchAuctionState,
22) -> pb::EventDutchAuctionUpdated {
23    pb::EventDutchAuctionUpdated {
24        auction_id: Some(id.into()),
25        state: Some(state.into()),
26    }
27}
28
29/// Event for a Dutch auction that is ending because it has been closed by its owner.
30pub fn dutch_auction_closed_by_user(
31    id: AuctionId,
32    state: DutchAuctionState,
33) -> pb::EventDutchAuctionEnded {
34    pb::EventDutchAuctionEnded {
35        auction_id: Some(id.into()),
36        state: Some(state.into()),
37        reason: pb::event_dutch_auction_ended::Reason::ClosedByOwner as i32,
38    }
39}
40
41/// Event for a Dutch auction that is ending because it has expired.
42pub fn dutch_auction_expired(
43    id: AuctionId,
44    state: DutchAuctionState,
45) -> pb::EventDutchAuctionEnded {
46    pb::EventDutchAuctionEnded {
47        auction_id: Some(id.into()),
48        state: Some(state.into()),
49        reason: pb::event_dutch_auction_ended::Reason::Expired as i32,
50    }
51}
52
53/// Event for a Dutch auction that is ending because it has been completely filled.
54pub fn dutch_auction_exhausted(
55    id: AuctionId,
56    state: DutchAuctionState,
57) -> pb::EventDutchAuctionEnded {
58    pb::EventDutchAuctionEnded {
59        auction_id: Some(id.into()),
60        state: Some(state.into()),
61        reason: pb::event_dutch_auction_ended::Reason::Filled as i32,
62    }
63}
64
65/// Event for a Dutch auction that is withdrawn by a user after ending.
66pub fn dutch_auction_withdrawn(
67    id: AuctionId,
68    state: DutchAuctionState,
69) -> pb::EventDutchAuctionWithdrawn {
70    pb::EventDutchAuctionWithdrawn {
71        auction_id: Some(id.into()),
72        state: Some(state.into()),
73    }
74}
75
76// Event for value flowing *into* the auction component.
77pub fn auction_vcb_credit(
78    asset_id: asset::Id,
79    previous_balance: Amount,
80    new_balance: Amount,
81) -> pb::EventValueCircuitBreakerCredit {
82    pb::EventValueCircuitBreakerCredit {
83        asset_id: Some(asset_id.into()),
84        previous_balance: Some(previous_balance.into()),
85        new_balance: Some(new_balance.into()),
86    }
87}
88
89// Event for value flowing *out of* the auction component.
90pub fn auction_vcb_debit(
91    asset_id: asset::Id,
92    previous_balance: Amount,
93    new_balance: Amount,
94) -> pb::EventValueCircuitBreakerDebit {
95    pb::EventValueCircuitBreakerDebit {
96        asset_id: Some(asset_id.into()),
97        previous_balance: Some(previous_balance.into()),
98        new_balance: Some(new_balance.into()),
99    }
100}