Skip to main content

xrpl_common_stdlib/objects/generated/
loan_broker.rs

1// GENERATED -- do not hand-edit. Run scripts/generate-ledger-objects.sh to regenerate.
2
3use crate::host::Result;
4use crate::objects::traits::CurrentLedgerObjectCommonFields;
5use crate::objects::traits::LedgerObjectCommonFields;
6use crate::objects::{current_ledger_object, ledger_object};
7use crate::sfield;
8use crate::types::account_id::AccountID;
9use crate::types::blob::StandardBlob;
10use crate::types::number::Number;
11use crate::types::uint::Hash256;
12
13/// Trait providing access to fields specific to LoanBroker objects in any ledger.
14pub trait LoanBrokerFields: LedgerObjectCommonFields {
15    /// Identifies the transaction ID that most recently modified this object.
16    fn previous_txn_id(&self) -> Result<Hash256> {
17        ledger_object::get_field(self.get_slot_num(), sfield::PreviousTxnID)
18    }
19
20    /// The sequence of the ledger that contains the transaction that most recently modified this
21    /// object.
22    fn previous_txn_lgr_seq(&self) -> Result<u32> {
23        ledger_object::get_field(self.get_slot_num(), sfield::PreviousTxnLgrSeq)
24    }
25
26    /// The transaction sequence number that created the LoanBroker.
27    fn sequence(&self) -> Result<u32> {
28        ledger_object::get_field(self.get_slot_num(), sfield::Sequence)
29    }
30
31    /// Identifies the page where this item is referenced in the owner's directory.
32    fn owner_node(&self) -> Result<u64> {
33        ledger_object::get_field(self.get_slot_num(), sfield::OwnerNode)
34    }
35
36    /// Identifies the page where this item is referenced in the `Vault` pseudo-account owner's
37    /// directory.
38    fn vault_node(&self) -> Result<u64> {
39        ledger_object::get_field(self.get_slot_num(), sfield::VaultNode)
40    }
41
42    /// The ID of the vault that provides the loaned assets.
43    fn vault_id(&self) -> Result<Hash256> {
44        ledger_object::get_field(self.get_slot_num(), sfield::VaultID)
45    }
46
47    /// The address of the `LoanBroker` pseudo-account.
48    fn account(&self) -> Result<AccountID> {
49        ledger_object::get_field(self.get_slot_num(), sfield::Account)
50    }
51
52    /// The account address of the vault owner.
53    fn owner(&self) -> Result<AccountID> {
54        ledger_object::get_field(self.get_slot_num(), sfield::Owner)
55    }
56
57    /// A sequential identifier for `Loan` ledger entires, incremented each time a new loan is
58    /// created by this `LoanBroker`.
59    fn loan_sequence(&self) -> Result<u32> {
60        ledger_object::get_field(self.get_slot_num(), sfield::LoanSequence)
61    }
62
63    /// Arbitrary metadata about the vault. Limited to 256 bytes.
64    fn data(&self) -> Result<Option<StandardBlob>> {
65        ledger_object::get_field_optional(self.get_slot_num(), sfield::Data)
66    }
67
68    /// The fee charged by the lending protocol on any loan interest, in units of 1/10th basis
69    /// points. Valid values are 0 to 10000 (inclusive), representing 0% to 10%.
70    fn management_fee_rate(&self) -> Result<Option<u16>> {
71        ledger_object::get_field_optional(self.get_slot_num(), sfield::ManagementFeeRate)
72    }
73
74    /// The number of active loans issued by the LoanBroker.
75    fn owner_count(&self) -> Result<Option<u32>> {
76        ledger_object::get_field_optional(self.get_slot_num(), sfield::OwnerCount)
77    }
78
79    /// The total asset amount the protocol owes the vault, including interest.
80    fn debt_total(&self) -> Result<Option<Number>> {
81        ledger_object::get_field_optional(self.get_slot_num(), sfield::DebtTotal)
82    }
83
84    /// The maximum amount the protocol can owe the vault. The default value of `0` means there is
85    /// no limit to the debt.
86    fn debt_maximum(&self) -> Result<Option<Number>> {
87        ledger_object::get_field_optional(self.get_slot_num(), sfield::DebtMaximum)
88    }
89
90    /// The total amount of first-loss capital deposited into the lending protocol.
91    fn cover_available(&self) -> Result<Option<Number>> {
92        ledger_object::get_field_optional(self.get_slot_num(), sfield::CoverAvailable)
93    }
94
95    /// The 1/10th basis point of the `DebtTotal` that the first-loss capital must cover. Valid
96    /// values are 0 to 100000 (inclusive), representing 0% to 100%.
97    fn cover_rate_minimum(&self) -> Result<Option<u32>> {
98        ledger_object::get_field_optional(self.get_slot_num(), sfield::CoverRateMinimum)
99    }
100
101    /// The 1/10th basis point of minimum required first-loss capital that is moved to an asset
102    /// vault to cover a loan default. Valid values are 0 to 100000 (inclusive), representing 0% to
103    /// 100%.
104    fn cover_rate_liquidation(&self) -> Result<Option<u32>> {
105        ledger_object::get_field_optional(self.get_slot_num(), sfield::CoverRateLiquidation)
106    }
107}
108
109/// Trait providing access to fields specific to the current LoanBroker object.
110pub trait CurrentLoanBrokerFields: CurrentLedgerObjectCommonFields {
111    /// Identifies the transaction ID that most recently modified this object.
112    fn previous_txn_id(&self) -> Result<Hash256> {
113        current_ledger_object::get_field(sfield::PreviousTxnID)
114    }
115
116    /// The sequence of the ledger that contains the transaction that most recently modified this
117    /// object.
118    fn previous_txn_lgr_seq(&self) -> Result<u32> {
119        current_ledger_object::get_field(sfield::PreviousTxnLgrSeq)
120    }
121
122    /// The transaction sequence number that created the LoanBroker.
123    fn sequence(&self) -> Result<u32> {
124        current_ledger_object::get_field(sfield::Sequence)
125    }
126
127    /// Identifies the page where this item is referenced in the owner's directory.
128    fn owner_node(&self) -> Result<u64> {
129        current_ledger_object::get_field(sfield::OwnerNode)
130    }
131
132    /// Identifies the page where this item is referenced in the `Vault` pseudo-account owner's
133    /// directory.
134    fn vault_node(&self) -> Result<u64> {
135        current_ledger_object::get_field(sfield::VaultNode)
136    }
137
138    /// The ID of the vault that provides the loaned assets.
139    fn vault_id(&self) -> Result<Hash256> {
140        current_ledger_object::get_field(sfield::VaultID)
141    }
142
143    /// The address of the `LoanBroker` pseudo-account.
144    fn account(&self) -> Result<AccountID> {
145        current_ledger_object::get_field(sfield::Account)
146    }
147
148    /// The account address of the vault owner.
149    fn owner(&self) -> Result<AccountID> {
150        current_ledger_object::get_field(sfield::Owner)
151    }
152
153    /// A sequential identifier for `Loan` ledger entires, incremented each time a new loan is
154    /// created by this `LoanBroker`.
155    fn loan_sequence(&self) -> Result<u32> {
156        current_ledger_object::get_field(sfield::LoanSequence)
157    }
158
159    /// Arbitrary metadata about the vault. Limited to 256 bytes.
160    fn data(&self) -> Result<Option<StandardBlob>> {
161        current_ledger_object::get_field_optional(sfield::Data)
162    }
163
164    /// The fee charged by the lending protocol on any loan interest, in units of 1/10th basis
165    /// points. Valid values are 0 to 10000 (inclusive), representing 0% to 10%.
166    fn management_fee_rate(&self) -> Result<Option<u16>> {
167        current_ledger_object::get_field_optional(sfield::ManagementFeeRate)
168    }
169
170    /// The number of active loans issued by the LoanBroker.
171    fn owner_count(&self) -> Result<Option<u32>> {
172        current_ledger_object::get_field_optional(sfield::OwnerCount)
173    }
174
175    /// The total asset amount the protocol owes the vault, including interest.
176    fn debt_total(&self) -> Result<Option<Number>> {
177        current_ledger_object::get_field_optional(sfield::DebtTotal)
178    }
179
180    /// The maximum amount the protocol can owe the vault. The default value of `0` means there is
181    /// no limit to the debt.
182    fn debt_maximum(&self) -> Result<Option<Number>> {
183        current_ledger_object::get_field_optional(sfield::DebtMaximum)
184    }
185
186    /// The total amount of first-loss capital deposited into the lending protocol.
187    fn cover_available(&self) -> Result<Option<Number>> {
188        current_ledger_object::get_field_optional(sfield::CoverAvailable)
189    }
190
191    /// The 1/10th basis point of the `DebtTotal` that the first-loss capital must cover. Valid
192    /// values are 0 to 100000 (inclusive), representing 0% to 100%.
193    fn cover_rate_minimum(&self) -> Result<Option<u32>> {
194        current_ledger_object::get_field_optional(sfield::CoverRateMinimum)
195    }
196
197    /// The 1/10th basis point of minimum required first-loss capital that is moved to an asset
198    /// vault to cover a loan default. Valid values are 0 to 100000 (inclusive), representing 0% to
199    /// 100%.
200    fn cover_rate_liquidation(&self) -> Result<Option<u32>> {
201        current_ledger_object::get_field_optional(sfield::CoverRateLiquidation)
202    }
203}
204
205#[derive(Debug, Clone, Copy, Eq, PartialEq)]
206pub struct LoanBroker {
207    pub(crate) slot_num: i32,
208}
209
210impl LoanBroker {
211    /// Binds this handle to a host-managed slot holding a LoanBroker ledger object.
212    pub fn new(slot_num: i32) -> Self {
213        Self { slot_num }
214    }
215}
216
217impl LedgerObjectCommonFields for LoanBroker {
218    fn get_slot_num(&self) -> i32 {
219        self.slot_num
220    }
221}
222
223impl LoanBrokerFields for LoanBroker {}
224
225#[cfg(test)]
226mod tests {
227    use super::*;
228    use crate::host::host_bindings_trait::MockHostBindings;
229    use crate::host::setup_mock;
230    use crate::objects::test_utils::*;
231
232    #[test]
233    fn read_all_fields() {
234        let mut mock = MockHostBindings::new();
235        mock_all_fields_present(&mut mock);
236        let _guard = setup_mock(mock);
237
238        let obj = LoanBroker::new(0);
239
240        assert!(obj.previous_txn_id().is_ok());
241        assert!(obj.previous_txn_lgr_seq().is_ok());
242        assert!(obj.sequence().is_ok());
243        assert!(obj.owner_node().is_ok());
244        assert!(obj.vault_node().is_ok());
245        assert!(obj.vault_id().is_ok());
246        assert!(obj.account().is_ok());
247        assert!(obj.owner().is_ok());
248        assert!(obj.loan_sequence().is_ok());
249        assert!(obj.data().is_ok());
250        assert!(obj.management_fee_rate().is_ok());
251        assert!(obj.owner_count().is_ok());
252        assert!(obj.debt_total().is_ok());
253        assert!(obj.debt_maximum().is_ok());
254        assert!(obj.cover_available().is_ok());
255        assert!(obj.cover_rate_minimum().is_ok());
256        assert!(obj.cover_rate_liquidation().is_ok());
257    }
258
259    #[test]
260    fn optional_fields_none() {
261        let mut mock = MockHostBindings::new();
262        mock_all_fields_not_found(&mut mock);
263        let _guard = setup_mock(mock);
264
265        let obj = LoanBroker::new(0);
266
267        assert!(obj.management_fee_rate().unwrap().is_none());
268        assert!(obj.owner_count().unwrap().is_none());
269        assert!(obj.cover_rate_minimum().unwrap().is_none());
270        assert!(obj.cover_rate_liquidation().unwrap().is_none());
271    }
272}