penumbra_sdk_auction/
event.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
use crate::auction::dutch::{DutchAuctionDescription, DutchAuctionState};
use crate::auction::AuctionId;
use penumbra_sdk_asset::asset;
use penumbra_sdk_num::Amount;
use penumbra_sdk_proto::penumbra::core::component::auction::v1 as pb;

/// Event for a Dutch auction that has been scheduled.
pub fn dutch_auction_schedule_event(
    id: AuctionId,
    description: DutchAuctionDescription,
) -> pb::EventDutchAuctionScheduled {
    pb::EventDutchAuctionScheduled {
        auction_id: Some(id.into()),
        description: Some(description.into()),
    }
}

/// Event for an execution round of a Dutch auction.
pub fn dutch_auction_updated(
    id: AuctionId,
    state: DutchAuctionState,
) -> pb::EventDutchAuctionUpdated {
    pb::EventDutchAuctionUpdated {
        auction_id: Some(id.into()),
        state: Some(state.into()),
    }
}

/// Event for a Dutch auction that is ending because it has been closed by its owner.
pub fn dutch_auction_closed_by_user(
    id: AuctionId,
    state: DutchAuctionState,
) -> pb::EventDutchAuctionEnded {
    pb::EventDutchAuctionEnded {
        auction_id: Some(id.into()),
        state: Some(state.into()),
        reason: pb::event_dutch_auction_ended::Reason::ClosedByOwner as i32,
    }
}

/// Event for a Dutch auction that is ending because it has expired.
pub fn dutch_auction_expired(
    id: AuctionId,
    state: DutchAuctionState,
) -> pb::EventDutchAuctionEnded {
    pb::EventDutchAuctionEnded {
        auction_id: Some(id.into()),
        state: Some(state.into()),
        reason: pb::event_dutch_auction_ended::Reason::Expired as i32,
    }
}

/// Event for a Dutch auction that is ending because it has been completely filled.
pub fn dutch_auction_exhausted(
    id: AuctionId,
    state: DutchAuctionState,
) -> pb::EventDutchAuctionEnded {
    pb::EventDutchAuctionEnded {
        auction_id: Some(id.into()),
        state: Some(state.into()),
        reason: pb::event_dutch_auction_ended::Reason::Filled as i32,
    }
}

/// Event for a Dutch auction that is withdrawn by a user after ending.
pub fn dutch_auction_withdrawn(
    id: AuctionId,
    state: DutchAuctionState,
) -> pb::EventDutchAuctionWithdrawn {
    pb::EventDutchAuctionWithdrawn {
        auction_id: Some(id.into()),
        state: Some(state.into()),
    }
}

// Event for value flowing *into* the auction component.
pub fn auction_vcb_credit(
    asset_id: asset::Id,
    previous_balance: Amount,
    new_balance: Amount,
) -> pb::EventValueCircuitBreakerCredit {
    pb::EventValueCircuitBreakerCredit {
        asset_id: Some(asset_id.into()),
        previous_balance: Some(previous_balance.into()),
        new_balance: Some(new_balance.into()),
    }
}

// Event for value flowing *out of* the auction component.
pub fn auction_vcb_debit(
    asset_id: asset::Id,
    previous_balance: Amount,
    new_balance: Amount,
) -> pb::EventValueCircuitBreakerDebit {
    pb::EventValueCircuitBreakerDebit {
        asset_id: Some(asset_id.into()),
        previous_balance: Some(previous_balance.into()),
        new_balance: Some(new_balance.into()),
    }
}