levana_perpswap_cosmos/contracts/position_token/
events.rs1use crate::prelude::*;
3use cosmwasm_std::{Addr, Event};
4use cw_utils::Expiration;
5
6#[derive(Debug)]
8pub struct MintEvent {
9 pub token_id: String,
11 pub owner: Addr,
13}
14
15impl From<MintEvent> for Event {
16 fn from(src: MintEvent) -> Self {
17 Event::new("mint").add_attributes(vec![
18 ("token_id", src.token_id.to_string()),
19 ("owner", src.owner.to_string()),
20 ])
21 }
22}
23
24impl TryFrom<Event> for MintEvent {
25 type Error = anyhow::Error;
26
27 fn try_from(evt: Event) -> anyhow::Result<Self> {
28 Ok(MintEvent {
29 token_id: evt.string_attr("token_id")?,
30 owner: evt.unchecked_addr_attr("owner")?,
31 })
32 }
33}
34
35#[derive(Debug)]
37pub struct BurnEvent {
38 pub token_id: String,
40}
41
42impl From<BurnEvent> for Event {
43 fn from(src: BurnEvent) -> Self {
44 Event::new("burn").add_attributes(vec![("token_id", src.token_id)])
45 }
46}
47
48impl TryFrom<Event> for BurnEvent {
49 type Error = anyhow::Error;
50
51 fn try_from(evt: Event) -> anyhow::Result<Self> {
52 Ok(BurnEvent {
53 token_id: evt.string_attr("token_id")?,
54 })
55 }
56}
57
58#[derive(Debug)]
63pub struct ApprovalEvent {
64 pub token_id: String,
66 pub spender: Addr,
68 pub expires: Expiration,
70}
71
72impl From<ApprovalEvent> for Event {
73 fn from(src: ApprovalEvent) -> Self {
74 Event::new("approval").add_attributes(vec![
75 ("token_id", src.token_id.to_string()),
76 ("spender", src.spender.to_string()),
77 ("expires", src.expires.to_string()),
78 ])
79 }
80}
81
82#[derive(Debug)]
84pub struct RevokeEvent {
85 pub token_id: String,
87 pub spender: Addr,
89}
90
91impl From<RevokeEvent> for Event {
92 fn from(src: RevokeEvent) -> Self {
93 Event::new("revoke").add_attributes(vec![
94 ("token_id", src.token_id.to_string()),
95 ("spender", src.spender.to_string()),
96 ])
97 }
98}
99
100#[derive(Debug)]
102pub struct ApproveAllEvent {
103 pub operator: Addr,
105 pub expires: Expiration,
107}
108
109impl From<ApproveAllEvent> for Event {
110 fn from(src: ApproveAllEvent) -> Self {
111 Event::new("approve-all").add_attributes(vec![
112 ("operator", src.operator.to_string()),
113 ("expires", src.expires.to_string()),
114 ])
115 }
116}
117
118#[derive(Debug)]
120pub struct RevokeAllEvent {
121 pub operator: Addr,
123}
124
125impl From<RevokeAllEvent> for Event {
126 fn from(src: RevokeAllEvent) -> Self {
127 Event::new("revoke-all").add_attributes(vec![("operator", src.operator.to_string())])
128 }
129}
130
131#[derive(Debug)]
133pub struct TransferEvent {
134 pub recipient: Addr,
136 pub token_id: String,
138}
139
140impl From<TransferEvent> for Event {
141 fn from(src: TransferEvent) -> Self {
142 Event::new("transfer").add_attributes(vec![
143 ("recipient", src.recipient.to_string()),
144 ("token_id", src.token_id),
145 ])
146 }
147}