nym_vesting_contract_common/
lib.rs1#![warn(clippy::expect_used)]
5#![warn(clippy::unwrap_used)]
6
7use cosmwasm_schema::cw_serde;
8use cosmwasm_std::{Addr, Coin};
9use nym_mixnet_contract_common::NodeId;
10
11pub mod account;
12pub mod error;
13pub mod events;
14pub mod messages;
15pub mod types;
16
17pub use account::Account;
18pub use error::VestingContractError;
19pub use messages::{ExecuteMsg, InitMsg, MigrateMsg, QueryMsg};
20pub use types::*;
21
22#[cw_serde]
24pub struct OriginalVestingResponse {
25 pub amount: Coin,
27
28 pub number_of_periods: usize,
30
31 pub period_duration: u64,
33}
34
35impl OriginalVestingResponse {
36 pub fn amount(&self) -> Coin {
37 self.amount.clone()
38 }
39
40 pub fn number_of_periods(&self) -> usize {
41 self.number_of_periods
42 }
43
44 pub fn period_duration(&self) -> u64 {
45 self.period_duration
46 }
47
48 pub fn new(amount: Coin, number_of_periods: usize, period_duration: u64) -> Self {
49 Self {
50 amount,
51 number_of_periods,
52 period_duration,
53 }
54 }
55}
56
57#[cw_serde]
59pub struct DelegationTimesResponse {
60 pub owner: Addr,
62
63 pub account_id: u32,
65
66 pub mix_id: NodeId,
68
69 pub delegation_timestamps: Vec<u64>,
71}
72
73#[cw_serde]
75pub struct AllDelegationsResponse {
76 pub delegations: Vec<VestingDelegation>,
78
79 pub start_next_after: Option<(u32, NodeId, u64)>,
81}
82
83#[cw_serde]
85pub struct AccountVestingCoins {
86 pub account_id: u32,
88
89 pub owner: Addr,
91
92 pub still_vesting: Coin,
94}
95
96#[cw_serde]
98pub struct VestingCoinsResponse {
99 pub accounts: Vec<AccountVestingCoins>,
101
102 pub start_next_after: Option<Addr>,
104}
105
106#[cw_serde]
108pub struct BaseVestingAccountInfo {
109 pub account_id: u32,
111
112 pub owner: Addr,
114 }
116
117#[cw_serde]
119pub struct AccountsResponse {
120 pub accounts: Vec<BaseVestingAccountInfo>,
122
123 pub start_next_after: Option<Addr>,
125}
126
127#[cfg(test)]
128mod test {
129 use cosmwasm_std::Uint128;
130 use nym_contracts_common::Percent;
131 use std::str::FromStr;
132
133 use crate::PledgeCap;
134
135 #[test]
136 fn test_pledge_cap_from_str() {
137 assert_eq!(
138 PledgeCap::from_str("0.1").unwrap(),
139 PledgeCap::Percent(Percent::from_percentage_value(10).unwrap())
140 );
141 assert_eq!(
142 PledgeCap::from_str("0,1").unwrap(),
143 PledgeCap::Percent(Percent::from_percentage_value(10).unwrap())
144 );
145 assert_eq!(
146 PledgeCap::from_str("100_000_000_000").unwrap(),
147 PledgeCap::Absolute(Uint128::new(100_000_000_000))
148 );
149 assert_eq!(
150 PledgeCap::from_str("100000000000").unwrap(),
151 PledgeCap::Absolute(Uint128::new(100_000_000_000))
152 );
153 }
154}