BitShares-Core  6.1.0
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, protocol_ids, credit_offer_object_type>
40 {
41  public:
42  account_id_type owner_account;
43  asset_id_type asset_type;
46  uint32_t fee_rate = 0;
47  uint32_t max_duration_seconds = 0;
49  bool enabled = false;
51 
53  flat_map<asset_id_type, price> acceptable_collateral;
54 
56  flat_map<account_id_type, share_type> acceptable_borrowers;
57 };
58 
59 struct by_auto_disable_time; // for protocol
60 struct by_owner; // for API
61 struct by_asset_type; // for API
62 
66 using credit_offer_multi_index_type = multi_index_container<
68  indexed_by<
69  ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
70  ordered_unique< tag<by_auto_disable_time>,
71  composite_key< credit_offer_object,
72  member< credit_offer_object, bool, &credit_offer_object::enabled >,
73  member< credit_offer_object, time_point_sec, &credit_offer_object::auto_disable_time >,
74  member< object, object_id_type, &object::id>
75  >
76  >,
77  ordered_unique< tag<by_owner>,
78  composite_key< credit_offer_object,
79  member< credit_offer_object, account_id_type, &credit_offer_object::owner_account >,
80  member< object, object_id_type, &object::id>
81  >
82  >,
83  ordered_unique< tag<by_asset_type>,
84  composite_key< credit_offer_object,
85  member< credit_offer_object, asset_id_type, &credit_offer_object::asset_type >,
86  member< object, object_id_type, &object::id>
87  >
88  >
89  >
90 >;
91 
96 
97 
104 class credit_deal_object : public abstract_object<credit_deal_object, protocol_ids, credit_deal_object_type>
105 {
106  public:
107  account_id_type borrower;
108  credit_offer_id_type offer_id;
109  account_id_type offer_owner;
110  asset_id_type debt_asset;
112  asset_id_type collateral_asset;
114  uint32_t fee_rate = 0;
116 };
117 
118 struct by_latest_repay_time; // for protocol
119 struct by_offer_id; // for API
120 struct by_offer_owner; // for API
121 struct by_borrower; // for API
122 struct by_debt_asset; // for API
123 struct by_collateral_asset; // for API
124 
128 using credit_deal_multi_index_type = multi_index_container<
130  indexed_by<
131  ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
132  ordered_unique< tag<by_latest_repay_time>,
133  composite_key< credit_deal_object,
134  member< credit_deal_object, time_point_sec, &credit_deal_object::latest_repay_time >,
135  member< object, object_id_type, &object::id>
136  >
137  >,
138  ordered_unique< tag<by_offer_id>,
139  composite_key< credit_deal_object,
140  member< credit_deal_object, credit_offer_id_type, &credit_deal_object::offer_id >,
141  member< object, object_id_type, &object::id>
142  >
143  >,
144  ordered_unique< tag<by_offer_owner>,
145  composite_key< credit_deal_object,
146  member< credit_deal_object, account_id_type, &credit_deal_object::offer_owner >,
147  member< object, object_id_type, &object::id>
148  >
149  >,
150  ordered_unique< tag<by_borrower>,
151  composite_key< credit_deal_object,
152  member< credit_deal_object, account_id_type, &credit_deal_object::borrower >,
153  member< object, object_id_type, &object::id>
154  >
155  >,
156  ordered_unique< tag<by_debt_asset>,
157  composite_key< credit_deal_object,
158  member< credit_deal_object, asset_id_type, &credit_deal_object::debt_asset >,
159  member< object, object_id_type, &object::id>
160  >
161  >,
162  ordered_unique< tag<by_collateral_asset>,
163  composite_key< credit_deal_object,
164  member< credit_deal_object, asset_id_type, &credit_deal_object::collateral_asset >,
165  member< object, object_id_type, &object::id>
166  >
167  >
168  >
169 >;
170 
175 
176 
183 class credit_deal_summary_object : public abstract_object<credit_deal_summary_object,
184  implementation_ids, impl_credit_deal_summary_object_type>
185 {
186  public:
187  account_id_type borrower;
188  credit_offer_id_type offer_id;
189  account_id_type offer_owner;
190  asset_id_type debt_asset;
192 };
193 
194 struct by_offer_borrower; // for protocol
195 
199 using credit_deal_summary_index_type = multi_index_container<
201  indexed_by<
202  ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
203  ordered_unique< tag<by_offer_borrower>,
204  composite_key< credit_deal_summary_object,
205  member< credit_deal_summary_object, credit_offer_id_type, &credit_deal_summary_object::offer_id >,
206  member< credit_deal_summary_object, account_id_type, &credit_deal_summary_object::borrower >
207  >
208  >
209  >
210 >;
211 
216 
217 } } // graphene::chain
218 
222 
226 
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:48
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:93
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.
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.