BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet 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;
50  time_point_sec auto_disable_time;
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  uint8_t auto_repay;
117 };
118 
119 struct by_latest_repay_time; // for protocol
120 struct by_offer_id; // for API
121 struct by_offer_owner; // for API
122 struct by_borrower; // for API
123 struct by_debt_asset; // for API
124 struct by_collateral_asset; // for API
125 
129 using credit_deal_multi_index_type = multi_index_container<
131  indexed_by<
132  ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
133  ordered_unique< tag<by_latest_repay_time>,
134  composite_key< credit_deal_object,
135  member< credit_deal_object, time_point_sec, &credit_deal_object::latest_repay_time >,
136  member< object, object_id_type, &object::id>
137  >
138  >,
139  ordered_unique< tag<by_offer_id>,
140  composite_key< credit_deal_object,
141  member< credit_deal_object, credit_offer_id_type, &credit_deal_object::offer_id >,
142  member< object, object_id_type, &object::id>
143  >
144  >,
145  ordered_unique< tag<by_offer_owner>,
146  composite_key< credit_deal_object,
147  member< credit_deal_object, account_id_type, &credit_deal_object::offer_owner >,
148  member< object, object_id_type, &object::id>
149  >
150  >,
151  ordered_unique< tag<by_borrower>,
152  composite_key< credit_deal_object,
153  member< credit_deal_object, account_id_type, &credit_deal_object::borrower >,
154  member< object, object_id_type, &object::id>
155  >
156  >,
157  ordered_unique< tag<by_debt_asset>,
158  composite_key< credit_deal_object,
159  member< credit_deal_object, asset_id_type, &credit_deal_object::debt_asset >,
160  member< object, object_id_type, &object::id>
161  >
162  >,
163  ordered_unique< tag<by_collateral_asset>,
164  composite_key< credit_deal_object,
165  member< credit_deal_object, asset_id_type, &credit_deal_object::collateral_asset >,
166  member< object, object_id_type, &object::id>
167  >
168  >
169  >
170 >;
171 
176 
177 
184 class credit_deal_summary_object : public abstract_object<credit_deal_summary_object,
185  implementation_ids, impl_credit_deal_summary_object_type>
186 {
187  public:
188  account_id_type borrower;
189  credit_offer_id_type offer_id;
190  account_id_type offer_owner;
191  asset_id_type debt_asset;
193 };
194 
195 struct by_offer_borrower; // for protocol
196 
200 using credit_deal_summary_index_type = multi_index_container<
202  indexed_by<
203  ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
204  ordered_unique< tag<by_offer_borrower>,
205  composite_key< credit_deal_summary_object,
206  member< credit_deal_summary_object, credit_offer_id_type, &credit_deal_summary_object::offer_id >,
207  member< credit_deal_summary_object, account_id_type, &credit_deal_summary_object::borrower >
208  >
209  >
210  >
211 >;
212 
217 
218 } } // graphene::chain
219 
223 
227 
graphene::chain::credit_deal_object::collateral_amount
share_type collateral_amount
How much funds in collateral.
Definition: credit_offer_object.hpp:113
graphene::chain::credit_deal_object
A credit deal describes the details of a borrower's borrowing of funds from a credit offer.
Definition: credit_offer_object.hpp:104
graphene::chain::credit_offer_object
A credit offer is a fund that can be used by other accounts who provide certain collateral.
Definition: credit_offer_object.hpp:39
graphene::chain::credit_offer_object::total_balance
share_type total_balance
Total size of the fund.
Definition: credit_offer_object.hpp:44
graphene::chain::credit_offer_object::asset_type
asset_id_type asset_type
Asset type in the fund.
Definition: credit_offer_object.hpp:43
graphene::chain::credit_deal_summary_object::offer_owner
account_id_type offer_owner
Owner of the credit offer, redundant info for ease of querying.
Definition: credit_offer_object.hpp:190
FC_REFLECT_TYPENAME
FC_REFLECT_TYPENAME(fc::log_message)
generic_index.hpp
graphene::chain::credit_deal_summary_object::total_debt_amount
share_type total_debt_amount
How much funds borrowed.
Definition: credit_offer_object.hpp:192
MAP_OBJECT_ID_TO_TYPE
#define MAP_OBJECT_ID_TO_TYPE(OBJECT)
Definition: object_id.hpp:93
graphene::chain::credit_offer_object::owner_account
account_id_type owner_account
Owner of the fund.
Definition: credit_offer_object.hpp:42
graphene::chain::credit_offer_multi_index_type
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
Definition: credit_offer_object.hpp:90
graphene::chain::credit_deal_multi_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
Definition: credit_offer_object.hpp:170
graphene::chain::credit_offer_object::acceptable_collateral
flat_map< asset_id_type, price > acceptable_collateral
Types and rates of acceptable collateral.
Definition: credit_offer_object.hpp:53
graphene::chain::credit_offer_object::enabled
bool enabled
Whether this offer is available.
Definition: credit_offer_object.hpp:49
graphene::db::abstract_object
Definition: object.hpp:107
graphene::chain::credit_deal_summary_object::offer_id
credit_offer_id_type offer_id
ID of the credit offer.
Definition: credit_offer_object.hpp:189
graphene::chain::credit_offer_object::fee_rate
uint32_t fee_rate
Fee rate, the demominator is GRAPHENE_FEE_RATE_DENOM.
Definition: credit_offer_object.hpp:46
graphene::chain::credit_deal_object::borrower
account_id_type borrower
Borrower.
Definition: credit_offer_object.hpp:107
graphene::chain::credit_deal_object::auto_repay
uint8_t auto_repay
The specified automatic repayment type.
Definition: credit_offer_object.hpp:116
fc::time_point_sec
Definition: time.hpp:74
graphene::chain::credit_deal_summary_object
A credit deal summary describes the summary of a borrower's borrowing of funds from a credit offer.
Definition: credit_offer_object.hpp:184
GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION
#define GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:85
graphene::chain::credit_deal_object::debt_asset
asset_id_type debt_asset
Asset type of the debt, redundant info for ease of querying.
Definition: credit_offer_object.hpp:110
graphene::chain::credit_deal_summary_index_type
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
Definition: credit_offer_object.hpp:211
graphene::chain::credit_deal_summary_object::borrower
account_id_type borrower
Borrower.
Definition: credit_offer_object.hpp:188
graphene::chain::credit_offer_object::auto_disable_time
time_point_sec auto_disable_time
The time when this offer will be disabled automatically.
Definition: credit_offer_object.hpp:50
graphene::chain::credit_deal_object::offer_id
credit_offer_id_type offer_id
ID of the credit offer.
Definition: credit_offer_object.hpp:108
graphene::chain::credit_deal_object::debt_amount
share_type debt_amount
How much funds borrowed.
Definition: credit_offer_object.hpp:111
graphene::chain::credit_deal_summary_object::debt_asset
asset_id_type debt_asset
Asset type of the debt, redundant info for ease of querying.
Definition: credit_offer_object.hpp:191
graphene::chain::credit_offer_object::acceptable_borrowers
flat_map< account_id_type, share_type > acceptable_borrowers
Allowed borrowers and their maximum amounts to borrow. No limitation if empty.
Definition: credit_offer_object.hpp:56
graphene::chain::credit_deal_object::fee_rate
uint32_t fee_rate
Fee rate, the demominator is GRAPHENE_FEE_RATE_DENOM.
Definition: credit_offer_object.hpp:114
types.hpp
graphene::db::generic_index
Definition: generic_index.hpp:43
graphene::chain::credit_deal_object::latest_repay_time
time_point_sec latest_repay_time
The deadline when the debt should be repaid.
Definition: credit_offer_object.hpp:115
graphene::chain::credit_deal_object::collateral_asset
asset_id_type collateral_asset
Asset type of the collateral.
Definition: credit_offer_object.hpp:112
graphene::chain::credit_offer_object::max_duration_seconds
uint32_t max_duration_seconds
The time limit that borrowed funds should be repaid.
Definition: credit_offer_object.hpp:47
graphene::chain::credit_deal_object::offer_owner
account_id_type offer_owner
Owner of the credit offer, redundant info for ease of querying.
Definition: credit_offer_object.hpp:109
graphene::chain::credit_offer_object::current_balance
share_type current_balance
Usable amount in the fund.
Definition: credit_offer_object.hpp:45
graphene::chain::credit_offer_object::min_deal_amount
share_type min_deal_amount
Minimum amount to borrow for each new deal.
Definition: credit_offer_object.hpp:48
graphene
Definition: api.cpp:48
fc::safe
Definition: safe.hpp:26