BitShares-Core  6.0.1
BitShares blockchain implementation and command-line interface software
credit_offer_object.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 Abit More, and contributors.
3  *
4  * The MIT License
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 #pragma once
25 
26 #include <graphene/chain/types.hpp>
28 
29 #include <boost/multi_index/composite_key.hpp>
30 
31 namespace graphene { namespace chain {
32 
39 class credit_offer_object : public abstract_object<credit_offer_object>
40 {
41  public:
42  static constexpr uint8_t space_id = protocol_ids;
43  static constexpr uint8_t type_id = credit_offer_object_type;
44 
45  account_id_type owner_account;
46  asset_id_type asset_type;
49  uint32_t fee_rate = 0;
50  uint32_t max_duration_seconds = 0;
52  bool enabled = false;
54 
56  flat_map<asset_id_type, price> acceptable_collateral;
57 
59  flat_map<account_id_type, share_type> acceptable_borrowers;
60 };
61 
62 struct by_auto_disable_time; // for protocol
63 struct by_owner; // for API
64 struct by_asset_type; // for API
65 
69 using credit_offer_multi_index_type = multi_index_container<
71  indexed_by<
72  ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
73  ordered_unique< tag<by_auto_disable_time>,
74  composite_key< credit_offer_object,
75  member< credit_offer_object, bool, &credit_offer_object::enabled >,
76  member< credit_offer_object, time_point_sec, &credit_offer_object::auto_disable_time >,
77  member< object, object_id_type, &object::id>
78  >
79  >,
80  ordered_unique< tag<by_owner>,
81  composite_key< credit_offer_object,
82  member< credit_offer_object, account_id_type, &credit_offer_object::owner_account >,
83  member< object, object_id_type, &object::id>
84  >
85  >,
86  ordered_unique< tag<by_asset_type>,
87  composite_key< credit_offer_object,
88  member< credit_offer_object, asset_id_type, &credit_offer_object::asset_type >,
89  member< object, object_id_type, &object::id>
90  >
91  >
92  >
93 >;
94 
99 
100 
107 class credit_deal_object : public abstract_object<credit_deal_object>
108 {
109  public:
110  static constexpr uint8_t space_id = protocol_ids;
111  static constexpr uint8_t type_id = credit_deal_object_type;
112 
113  account_id_type borrower;
114  credit_offer_id_type offer_id;
115  account_id_type offer_owner;
116  asset_id_type debt_asset;
118  asset_id_type collateral_asset;
120  uint32_t fee_rate = 0;
122 };
123 
124 struct by_latest_repay_time; // for protocol
125 struct by_offer_id; // for API
126 struct by_offer_owner; // for API
127 struct by_borrower; // for API
128 struct by_debt_asset; // for API
129 struct by_collateral_asset; // for API
130 
134 using credit_deal_multi_index_type = multi_index_container<
136  indexed_by<
137  ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
138  ordered_unique< tag<by_latest_repay_time>,
139  composite_key< credit_deal_object,
140  member< credit_deal_object, time_point_sec, &credit_deal_object::latest_repay_time >,
141  member< object, object_id_type, &object::id>
142  >
143  >,
144  ordered_unique< tag<by_offer_id>,
145  composite_key< credit_deal_object,
146  member< credit_deal_object, credit_offer_id_type, &credit_deal_object::offer_id >,
147  member< object, object_id_type, &object::id>
148  >
149  >,
150  ordered_unique< tag<by_offer_owner>,
151  composite_key< credit_deal_object,
152  member< credit_deal_object, account_id_type, &credit_deal_object::offer_owner >,
153  member< object, object_id_type, &object::id>
154  >
155  >,
156  ordered_unique< tag<by_borrower>,
157  composite_key< credit_deal_object,
158  member< credit_deal_object, account_id_type, &credit_deal_object::borrower >,
159  member< object, object_id_type, &object::id>
160  >
161  >,
162  ordered_unique< tag<by_debt_asset>,
163  composite_key< credit_deal_object,
164  member< credit_deal_object, asset_id_type, &credit_deal_object::debt_asset >,
165  member< object, object_id_type, &object::id>
166  >
167  >,
168  ordered_unique< tag<by_collateral_asset>,
169  composite_key< credit_deal_object,
170  member< credit_deal_object, asset_id_type, &credit_deal_object::collateral_asset >,
171  member< object, object_id_type, &object::id>
172  >
173  >
174  >
175 >;
176 
181 
182 
189 class credit_deal_summary_object : public abstract_object<credit_deal_summary_object>
190 {
191  public:
192  static constexpr uint8_t space_id = implementation_ids;
193  static constexpr uint8_t type_id = impl_credit_deal_summary_object_type;
194 
195  account_id_type borrower;
196  credit_offer_id_type offer_id;
197  account_id_type offer_owner;
198  asset_id_type debt_asset;
200 };
201 
202 struct by_offer_borrower; // for protocol
203 
207 using credit_deal_summary_index_type = multi_index_container<
209  indexed_by<
210  ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
211  ordered_unique< tag<by_offer_borrower>,
212  composite_key< credit_deal_summary_object,
213  member< credit_deal_summary_object, credit_offer_id_type, &credit_deal_summary_object::offer_id >,
214  member< credit_deal_summary_object, account_id_type, &credit_deal_summary_object::borrower >
215  >
216  >
217  >
218 >;
219 
224 
225 } } // graphene::chain
226 
230 
234 
share_type total_debt_amount
How much funds borrowed.
A credit offer is a fund that can be used by other accounts who provide certain collateral.
account_id_type offer_owner
Owner of the credit offer, redundant info for ease of querying.
share_type collateral_amount
How much funds in collateral.
asset_id_type asset_type
Asset type in the fund.
A credit deal describes the details of a borrower&#39;s borrowing of funds from a credit offer...
Definition: api.cpp:56
asset_id_type debt_asset
Asset type of the debt, redundant info for ease of querying.
#define MAP_OBJECT_ID_TO_TYPE(OBJECT)
Definition: object_id.hpp:98
A credit deal summary describes the summary of a borrower&#39;s borrowing of funds from a credit offer...
share_type current_balance
Usable amount in the fund.
account_id_type offer_owner
Owner of the credit offer, redundant info for ease of querying.
credit_offer_id_type offer_id
ID of the credit offer.
bool enabled
Whether this offer is available.
FC_REFLECT_TYPENAME(fc::log_message)
uint32_t fee_rate
Fee rate, the demominator is GRAPHENE_FEE_RATE_DENOM.
share_type total_balance
Total size of the fund.
#define GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:85
asset_id_type debt_asset
Asset type of the debt, redundant info for ease of querying.
multi_index_container< credit_offer_object, indexed_by< ordered_unique< tag< by_id >, member< object, object_id_type, &object::id > >, ordered_unique< tag< by_auto_disable_time >, composite_key< credit_offer_object, member< credit_offer_object, bool, &credit_offer_object::enabled >, member< credit_offer_object, time_point_sec, &credit_offer_object::auto_disable_time >, member< object, object_id_type, &object::id > > >, ordered_unique< tag< by_owner >, composite_key< credit_offer_object, member< credit_offer_object, account_id_type, &credit_offer_object::owner_account >, member< object, object_id_type, &object::id > > >, ordered_unique< tag< by_asset_type >, composite_key< credit_offer_object, member< credit_offer_object, asset_id_type, &credit_offer_object::asset_type >, member< object, object_id_type, &object::id > > > > > credit_offer_multi_index_type
uint32_t max_duration_seconds
The time limit that borrowed funds should be repaid.
flat_map< asset_id_type, price > acceptable_collateral
Types and rates of acceptable collateral.
share_type debt_amount
How much funds borrowed.
flat_map< account_id_type, share_type > acceptable_borrowers
Allowed borrowers and their maximum amounts to borrow. No limitation if empty.
Use the Curiously Recurring Template Pattern to automatically add the ability to clone, serialize, and move objects polymorphically.
Definition: object.hpp:86
account_id_type owner_account
Owner of the fund.
time_point_sec latest_repay_time
The deadline when the debt should be repaid.
multi_index_container< credit_deal_summary_object, indexed_by< ordered_unique< tag< by_id >, member< object, object_id_type, &object::id > >, ordered_unique< tag< by_offer_borrower >, composite_key< credit_deal_summary_object, member< credit_deal_summary_object, credit_offer_id_type, &credit_deal_summary_object::offer_id >, member< credit_deal_summary_object, account_id_type, &credit_deal_summary_object::borrower > > > > > credit_deal_summary_index_type
multi_index_container< credit_deal_object, indexed_by< ordered_unique< tag< by_id >, member< object, object_id_type, &object::id > >, ordered_unique< tag< by_latest_repay_time >, composite_key< credit_deal_object, member< credit_deal_object, time_point_sec, &credit_deal_object::latest_repay_time >, member< object, object_id_type, &object::id > > >, ordered_unique< tag< by_offer_id >, composite_key< credit_deal_object, member< credit_deal_object, credit_offer_id_type, &credit_deal_object::offer_id >, member< object, object_id_type, &object::id > > >, ordered_unique< tag< by_offer_owner >, composite_key< credit_deal_object, member< credit_deal_object, account_id_type, &credit_deal_object::offer_owner >, member< object, object_id_type, &object::id > > >, ordered_unique< tag< by_borrower >, composite_key< credit_deal_object, member< credit_deal_object, account_id_type, &credit_deal_object::borrower >, member< object, object_id_type, &object::id > > >, ordered_unique< tag< by_debt_asset >, composite_key< credit_deal_object, member< credit_deal_object, asset_id_type, &credit_deal_object::debt_asset >, member< object, object_id_type, &object::id > > >, ordered_unique< tag< by_collateral_asset >, composite_key< credit_deal_object, member< credit_deal_object, asset_id_type, &credit_deal_object::collateral_asset >, member< object, object_id_type, &object::id > > > > > credit_deal_multi_index_type
credit_offer_id_type offer_id
ID of the credit offer.
asset_id_type collateral_asset
Asset type of the collateral.
share_type min_deal_amount
Minimum amount to borrow for each new deal.
time_point_sec auto_disable_time
The time when this offer will be disabled automatically.