Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement simple collateralized P2P funding #2479

Merged
merged 16 commits into from
Jun 28, 2021
Merged

Conversation

abitmore
Copy link
Member

@abitmore abitmore commented Jun 22, 2021

Resolves #2362.

Contents

3 new object types:

  • credit_offer_object (protocol)
  • credit_deal_object (protocol)
  • credit_deal_summary_object (implementation)

6 new operations:

  • credit_offer_create_operation
  • credit_offer_delete_operation
  • credit_offer_update_operation
  • credit_offer_accept_operation
  • credit_deal_repay_operation
  • credit_deal_expired_operation (virtual)

1 new program startup option:

  • api-limit-get-credit-offers

9 new database APIs:

  • list_credit_offers( limit, start_id )
  • get_credit_offers_by_owner( account_name_or_id, limit, start_id )
  • get_credit_offers_by_asset( asset_symbol_or_id, limit, start_id )
  • list_credit_deals( limit, start_id )
  • get_credit_deals_by_offer_id( offer_id, limit, start_id )
  • get_credit_deals_by_offer_owner( account_name_or_id, limit, start_id )
  • get_credit_deals_by_offer_borrower( account_name_or_id, limit, start_id )
  • get_credit_deals_by_debt_asset( asset_symbol_or_id, limit, start_id )
  • get_credit_deals_by_collateral_asset( asset_symbol_or_id, limit, start_id )

P.S. Refactored some code to fix build issues and code smells.

Code:

////////////////////////////////////
/// Credit offers and credit deals
/// @{
/**
* @brief Get a list of credit offers
* @param limit The limitation of items each query can fetch, not greater than a configured value
* @param start_id Start credit offer id, fetch items whose IDs are greater than or equal to this ID
* @return The credit offers
*
* @note
* 1. @p limit can be omitted or be null, if so the default value 101 will be used
* 2. @p start_id can be omitted or be null, if so the api will return the "first page" of data
* 3. can only omit one or more arguments in the end of the list, but not one or more in the middle
*/
vector<credit_offer_object> list_credit_offers(
const optional<uint32_t>& limit = 101,
const optional<credit_offer_id_type>& start_id = optional<credit_offer_id_type>() )const;
/**
* @brief Get a list of credit offers by the name or ID of the owner account
* @param account_name_or_id name or ID of the owner account
* @param limit The limitation of items each query can fetch, not greater than a configured value
* @param start_id Start credit offer id, fetch items whose IDs are greater than or equal to this ID
* @return The credit offers
*
* @note
* 1. if @p account_name_or_id cannot be tied to an account, an error will be returned
* 2. @p limit can be omitted or be null, if so the default value 101 will be used
* 3. @p start_id can be omitted or be null, if so the api will return the "first page" of data
* 4. can only omit one or more arguments in the end of the list, but not one or more in the middle
*/
vector<credit_offer_object> get_credit_offers_by_owner(
const std::string& account_name_or_id,
const optional<uint32_t>& limit = 101,
const optional<credit_offer_id_type>& start_id = optional<credit_offer_id_type>() )const;
/**
* @brief Get a list of credit offers by the symbol or ID of the asset type
* @param asset_symbol_or_id symbol or ID of the asset type
* @param limit The limitation of items each query can fetch, not greater than a configured value
* @param start_id Start credit offer id, fetch items whose IDs are greater than or equal to this ID
* @return The credit offers
*
* @note
* 1. if @p asset_symbol_or_id cannot be tied to an asset, an error will be returned
* 2. @p limit can be omitted or be null, if so the default value 101 will be used
* 3. @p start_id can be omitted or be null, if so the api will return the "first page" of data
* 4. can only omit one or more arguments in the end of the list, but not one or more in the middle
*/
vector<credit_offer_object> get_credit_offers_by_asset(
const std::string& asset_symbol_or_id,
const optional<uint32_t>& limit = 101,
const optional<credit_offer_id_type>& start_id = optional<credit_offer_id_type>() )const;
/**
* @brief Get a list of credit deals
* @param limit The limitation of items each query can fetch, not greater than a configured value
* @param start_id Start credit deal id, fetch items whose IDs are greater than or equal to this ID
* @return The credit deals
*
* @note
* 1. @p limit can be omitted or be null, if so the default value 101 will be used
* 2. @p start_id can be omitted or be null, if so the api will return the "first page" of data
* 3. can only omit one or more arguments in the end of the list, but not one or more in the middle
*/
vector<credit_deal_object> list_credit_deals(
const optional<uint32_t>& limit = 101,
const optional<credit_deal_id_type>& start_id = optional<credit_deal_id_type>() )const;
/**
* @brief Get a list of credit deals by the ID of a credit offer
* @param offer_id ID of the credit offer
* @param limit The limitation of items each query can fetch, not greater than a configured value
* @param start_id Start credit deal id, fetch items whose IDs are greater than or equal to this ID
* @return The credit deals
*
* @note
* 1. if @p offer_id cannot be tied to a credit offer, an empty list will be returned
* 2. @p limit can be omitted or be null, if so the default value 101 will be used
* 3. @p start_id can be omitted or be null, if so the api will return the "first page" of data
* 4. can only omit one or more arguments in the end of the list, but not one or more in the middle
*/
vector<credit_deal_object> get_credit_deals_by_offer_id(
const credit_offer_id_type& offer_id,
const optional<uint32_t>& limit = 101,
const optional<credit_deal_id_type>& start_id = optional<credit_deal_id_type>() )const;
/**
* @brief Get a list of credit deals by the name or ID of a credit offer owner account
* @param account_name_or_id name or ID of the credit offer owner account
* @param limit The limitation of items each query can fetch, not greater than a configured value
* @param start_id Start credit deal id, fetch items whose IDs are greater than or equal to this ID
* @return The credit deals
*
* @note
* 1. if @p account_name_or_id cannot be tied to an account, an error will be returned
* 2. @p limit can be omitted or be null, if so the default value 101 will be used
* 3. @p start_id can be omitted or be null, if so the api will return the "first page" of data
* 4. can only omit one or more arguments in the end of the list, but not one or more in the middle
*/
vector<credit_deal_object> get_credit_deals_by_offer_owner(
const std::string& account_name_or_id,
const optional<uint32_t>& limit = 101,
const optional<credit_deal_id_type>& start_id = optional<credit_deal_id_type>() )const;
/**
* @brief Get a list of credit deals by the name or ID of a borrower account
* @param account_name_or_id name or ID of the borrower account
* @param limit The limitation of items each query can fetch, not greater than a configured value
* @param start_id Start credit deal id, fetch items whose IDs are greater than or equal to this ID
* @return The credit deals
*
* @note
* 1. if @p account_name_or_id cannot be tied to an account, an error will be returned
* 2. @p limit can be omitted or be null, if so the default value 101 will be used
* 3. @p start_id can be omitted or be null, if so the api will return the "first page" of data
* 4. can only omit one or more arguments in the end of the list, but not one or more in the middle
*/
vector<credit_deal_object> get_credit_deals_by_borrower(
const std::string& account_name_or_id,
const optional<uint32_t>& limit = 101,
const optional<credit_deal_id_type>& start_id = optional<credit_deal_id_type>() )const;
/**
* @brief Get a list of credit deals by the symbol or ID of the debt asset type
* @param asset_symbol_or_id symbol or ID of the debt asset type
* @param limit The limitation of items each query can fetch, not greater than a configured value
* @param start_id Start credit deal id, fetch items whose IDs are greater than or equal to this ID
* @return The credit deals
*
* @note
* 1. if @p asset_symbol_or_id cannot be tied to an asset, an error will be returned
* 2. @p limit can be omitted or be null, if so the default value 101 will be used
* 3. @p start_id can be omitted or be null, if so the api will return the "first page" of data
* 4. can only omit one or more arguments in the end of the list, but not one or more in the middle
*/
vector<credit_deal_object> get_credit_deals_by_debt_asset(
const std::string& asset_symbol_or_id,
const optional<uint32_t>& limit = 101,
const optional<credit_deal_id_type>& start_id = optional<credit_deal_id_type>() )const;
/**
* @brief Get a list of credit deals by the symbol or ID of the collateral asset type
* @param asset_symbol_or_id symbol or ID of the collateral asset type
* @param limit The limitation of items each query can fetch, not greater than a configured value
* @param start_id Start credit deal id, fetch items whose IDs are greater than or equal to this ID
* @return The credit deals
*
* @note
* 1. if @p asset_symbol_or_id cannot be tied to an asset, an error will be returned
* 2. @p limit can be omitted or be null, if so the default value 101 will be used
* 3. @p start_id can be omitted or be null, if so the api will return the "first page" of data
* 4. can only omit one or more arguments in the end of the list, but not one or more in the middle
*/
vector<credit_deal_object> get_credit_deals_by_collateral_asset(
const std::string& asset_symbol_or_id,
const optional<uint32_t>& limit = 101,
const optional<credit_deal_id_type>& start_id = optional<credit_deal_id_type>() )const;
/// @}


Tasks:

  • protocol changes
    • test cases
  • database APIs
    • test cases
  • by the way, update samet fund code w.r.t. extendable operation results

@abitmore abitmore linked an issue Jun 22, 2021 that may be closed by this pull request
17 tasks
When a credit offer's acceptable borrowers map is empty and a
borrower already has an active credit deal made from that
offer, the borrower was unable to make a new credit deal from
that offer.
@abitmore abitmore force-pushed the pr-2362-credit-offer branch 3 times, most recently from 1aa256c to 886ee83 Compare June 26, 2021 04:54
- list_credit_offers( limit, start_id )
- get_credit_offers_by_owner( account_name_or_id, limit, start_id )
- get_credit_offers_by_asset( asset_symbol_or_id, limit, start_id )
- list_credit_deals( limit, start_id )
- get_credit_deals_by_offer_id( offer_id, limit, start_id )
- get_credit_deals_by_offer_owner( account_name_or_id, limit, start_id )
- get_credit_deals_by_borrower( account_name_or_id, limit, start_id )
- get_credit_deals_by_debt_asset( asset_symbol_or_id, limit, start_id )
- get_credit_deals_by_collateral_asset( asset_symbol_or_id, limit, start_id )

BTW refactored database APIs for SameT Funds.
Replace magic numbers with more meaningful variables
@abitmore abitmore marked this pull request as ready for review June 28, 2021 00:02
@sonarcloud
Copy link

sonarcloud bot commented Jun 28, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 33 Code Smells

89.6% 89.6% Coverage
0.4% 0.4% Duplication

@abitmore abitmore merged commit d5f3bfa into hardfork Jun 28, 2021
@abitmore abitmore deleted the pr-2362-credit-offer branch June 28, 2021 21:19
@abitmore abitmore mentioned this pull request Jun 28, 2021
17 tasks
@abitmore abitmore mentioned this pull request Sep 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Simple collateralized P2P funding
1 participant