Skip to main content

bark_json/cli/
fees.rs

1use bitcoin::Amount;
2#[cfg(feature = "utoipa")]
3use utoipa::ToSchema;
4use ark::fees::PpmFeeRate;
5
6/// Complete fee schedule for all operations.
7#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)]
8#[cfg_attr(feature = "utoipa", derive(ToSchema))]
9pub struct FeeSchedule {
10	pub board: BoardFees,
11	pub offboard: OffboardFees,
12	pub refresh: RefreshFees,
13	pub lightning_receive: LightningReceiveFees,
14	pub lightning_send: LightningSendFees,
15}
16
17impl From<ark::fees::FeeSchedule> for FeeSchedule {
18	fn from(v: ark::fees::FeeSchedule) -> Self {
19		Self {
20			board: v.board.into(),
21			offboard: v.offboard.into(),
22			refresh: v.refresh.into(),
23			lightning_receive: v.lightning_receive.into(),
24			lightning_send: v.lightning_send.into(),
25		}
26	}
27}
28
29impl From<FeeSchedule> for ark::fees::FeeSchedule {
30	fn from(v: FeeSchedule) -> Self {
31		Self {
32			board: v.board.into(),
33			offboard: v.offboard.into(),
34			refresh: v.refresh.into(),
35			lightning_receive: v.lightning_receive.into(),
36			lightning_send: v.lightning_send.into(),
37		}
38	}
39}
40
41/// Entry in a table to calculate the PPM (parts per million) fee rate of a transaction based on how
42/// new a VTXO is.
43#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Deserialize, Serialize)]
44#[cfg_attr(feature = "utoipa", derive(ToSchema))]
45pub struct PpmExpiryFeeEntry {
46	/// A threshold for the number of blocks until a VTXO expires for the `ppm` amount to apply.
47	/// As an example, if this value is set to 50 and a VTXO expires in 60 blocks, this
48	/// [PpmExpiryFeeEntry] will be used to calculate the fee unless another entry exists with an
49	/// `expiry_blocks_threshold` with a value between 51 and 60 (inclusive).
50	pub expiry_blocks_threshold: u32,
51	/// PPM (parts per million) fee rate to apply for this expiry period.
52	#[cfg_attr(feature = "utoipa", schema(value_type = u64))]
53	pub ppm: PpmFeeRate,
54}
55
56impl From<ark::fees::PpmExpiryFeeEntry> for PpmExpiryFeeEntry {
57	fn from(v: ark::fees::PpmExpiryFeeEntry) -> Self {
58		Self {
59			expiry_blocks_threshold: v.expiry_blocks_threshold,
60			ppm: v.ppm,
61		}
62	}
63}
64
65impl From<PpmExpiryFeeEntry> for ark::fees::PpmExpiryFeeEntry {
66	fn from(v: PpmExpiryFeeEntry) -> Self {
67		Self {
68			expiry_blocks_threshold: v.expiry_blocks_threshold,
69			ppm: v.ppm,
70		}
71	}
72}
73
74/// Fees for boarding the ark.
75#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Deserialize, Serialize)]
76#[cfg_attr(feature = "utoipa", derive(ToSchema))]
77pub struct BoardFees {
78	/// Minimum fee to charge.
79	#[serde(rename = "min_fee_sat", with = "bitcoin::amount::serde::as_sat")]
80	#[cfg_attr(feature = "utoipa", schema(value_type = u64))]
81	pub min_fee: Amount,
82	/// A fee applied to every transaction regardless of value.
83	#[serde(rename = "base_fee_sat", with = "bitcoin::amount::serde::as_sat")]
84	#[cfg_attr(feature = "utoipa", schema(value_type = u64))]
85	pub base_fee: Amount,
86	/// PPM (parts per million) fee rate to apply based on the value of the transaction.
87	#[cfg_attr(feature = "utoipa", schema(value_type = u64))]
88	pub ppm: PpmFeeRate,
89}
90
91impl From<ark::fees::BoardFees> for BoardFees {
92	fn from(v: ark::fees::BoardFees) -> Self {
93		Self {
94			min_fee: v.min_fee,
95			base_fee: v.base_fee,
96			ppm: v.ppm,
97		}
98	}
99}
100
101impl From<BoardFees> for ark::fees::BoardFees {
102	fn from(v: BoardFees) -> Self {
103		Self {
104			min_fee: v.min_fee,
105			base_fee: v.base_fee,
106			ppm: v.ppm,
107		}
108	}
109}
110
111/// Fees for offboarding from the ark.
112#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)]
113#[cfg_attr(feature = "utoipa", derive(ToSchema))]
114pub struct OffboardFees {
115	/// A fee applied to every transaction regardless of value.
116	#[serde(rename = "base_fee_sat", with = "bitcoin::amount::serde::as_sat")]
117	#[cfg_attr(feature = "utoipa", schema(value_type = u64))]
118	pub base_fee: Amount,
119	/// Fixed number of virtual bytes charged offboard on top of the output size
120	///
121	/// The fee for an offboard will be this value, plus the offboard output virtual size,
122	/// multiplied with the offboard fee rate, plus the `base_fee`, and plus the additional fee
123	/// calculated with the `ppm_expiry_table`.
124	pub fixed_additional_vb: u64,
125	/// A table mapping how soon a VTXO will expire to a PPM (parts per million) fee rate.
126	/// The table should be sorted by each `expiry_blocks_threshold` value in ascending order.
127	pub ppm_expiry_table: Vec<PpmExpiryFeeEntry>,
128}
129
130impl From<ark::fees::OffboardFees> for OffboardFees {
131	fn from(v: ark::fees::OffboardFees) -> Self {
132		Self {
133			base_fee: v.base_fee,
134			fixed_additional_vb: v.fixed_additional_vb,
135			ppm_expiry_table: v.ppm_expiry_table.into_iter().map(Into::into).collect(),
136		}
137	}
138}
139
140impl From<OffboardFees> for ark::fees::OffboardFees {
141	fn from(v: OffboardFees) -> Self {
142		Self {
143			base_fee: v.base_fee,
144			fixed_additional_vb: v.fixed_additional_vb,
145			ppm_expiry_table: v.ppm_expiry_table.into_iter().map(Into::into).collect(),
146		}
147	}
148}
149
150/// Fees for refresh operations.
151#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)]
152#[cfg_attr(feature = "utoipa", derive(ToSchema))]
153pub struct RefreshFees {
154	/// A fee applied to every transaction regardless of value.
155	#[serde(rename = "base_fee_sat", with = "bitcoin::amount::serde::as_sat")]
156	#[cfg_attr(feature = "utoipa", schema(value_type = u64))]
157	pub base_fee: Amount,
158	/// A table mapping how soon a VTXO will expire to a PPM (parts per million) fee rate.
159	/// The table should be sorted by each `expiry_blocks_threshold` value in ascending order.
160	pub ppm_expiry_table: Vec<PpmExpiryFeeEntry>,
161}
162
163impl From<ark::fees::RefreshFees> for RefreshFees {
164	fn from(v: ark::fees::RefreshFees) -> Self {
165		Self {
166			base_fee: v.base_fee,
167			ppm_expiry_table: v.ppm_expiry_table.into_iter().map(Into::into).collect(),
168		}
169	}
170}
171
172impl From<RefreshFees> for ark::fees::RefreshFees {
173	fn from(v: RefreshFees) -> Self {
174		Self {
175			base_fee: v.base_fee,
176			ppm_expiry_table: v.ppm_expiry_table.into_iter().map(Into::into).collect(),
177		}
178	}
179}
180
181/// Fees for lightning receive operations.
182#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Deserialize, Serialize)]
183#[cfg_attr(feature = "utoipa", derive(ToSchema))]
184pub struct LightningReceiveFees {
185	/// A fee applied to every transaction regardless of value.
186	#[serde(rename = "base_fee_sat", with = "bitcoin::amount::serde::as_sat")]
187	#[cfg_attr(feature = "utoipa", schema(value_type = u64))]
188	pub base_fee: Amount,
189	/// PPM (parts per million) fee rate to apply based on the value of the transaction.
190	#[cfg_attr(feature = "utoipa", schema(value_type = u64))]
191	pub ppm: PpmFeeRate,
192}
193
194impl From<ark::fees::LightningReceiveFees> for LightningReceiveFees {
195	fn from(v: ark::fees::LightningReceiveFees) -> Self {
196		Self {
197			base_fee: v.base_fee,
198			ppm: v.ppm,
199		}
200	}
201}
202
203impl From<LightningReceiveFees> for ark::fees::LightningReceiveFees {
204	fn from(v: LightningReceiveFees) -> Self {
205		Self {
206			base_fee: v.base_fee,
207			ppm: v.ppm,
208		}
209	}
210}
211
212/// Fees for lightning send operations.
213#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)]
214#[cfg_attr(feature = "utoipa", derive(ToSchema))]
215pub struct LightningSendFees {
216	/// Minimum fee to charge.
217	#[serde(rename = "min_fee_sat", with = "bitcoin::amount::serde::as_sat")]
218	#[cfg_attr(feature = "utoipa", schema(value_type = u64))]
219	pub min_fee: Amount,
220	/// A fee applied to every transaction regardless of value.
221	#[serde(rename = "base_fee_sat", with = "bitcoin::amount::serde::as_sat")]
222	#[cfg_attr(feature = "utoipa", schema(value_type = u64))]
223	pub base_fee: Amount,
224	/// A table mapping how soon a VTXO will expire to a PPM (parts per million) fee rate.
225	/// The table should be sorted by each `expiry_blocks_threshold` value in ascending order.
226	pub ppm_expiry_table: Vec<PpmExpiryFeeEntry>,
227}
228
229impl From<ark::fees::LightningSendFees> for LightningSendFees {
230	fn from(v: ark::fees::LightningSendFees) -> Self {
231		Self {
232			min_fee: v.min_fee,
233			base_fee: v.base_fee,
234			ppm_expiry_table: v.ppm_expiry_table.into_iter().map(Into::into).collect(),
235		}
236	}
237}
238
239impl From<LightningSendFees> for ark::fees::LightningSendFees {
240	fn from(v: LightningSendFees) -> Self {
241		Self {
242			min_fee: v.min_fee,
243			base_fee: v.base_fee,
244			ppm_expiry_table: v.ppm_expiry_table.into_iter().map(Into::into).collect(),
245		}
246	}
247}