-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move
estimate_hive_collateral
function into protocol
library.
- Loading branch information
1 parent
852e66d
commit 4c3973a
Showing
2 changed files
with
30 additions
and
7 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
libraries/protocol/include/hive/protocol/hive_collateral.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma once | ||
|
||
#include <hive/protocol/asset.hpp> | ||
#include <hive/protocol/config.hpp> | ||
|
||
namespace hive { namespace protocol { | ||
struct hive_collateral | ||
{ | ||
static asset estimate_hive_collateral( const price& current_median_history, const price& current_min_history, const asset& hbd_amount_to_get ) | ||
{ | ||
//must reflect calculations from collateralized_convert_evaluator::do_apply | ||
|
||
FC_ASSERT( !static_cast<price>( current_median_history ).is_null(), "Cannot estimate conversion collateral because there is no price feed." ); | ||
|
||
auto needed_hive = multiply_with_fee( hbd_amount_to_get, current_min_history, | ||
HIVE_COLLATERALIZED_CONVERSION_FEE, HIVE_SYMBOL ); | ||
uint128_t _amount = ( uint128_t( needed_hive.amount.value ) * HIVE_CONVERSION_COLLATERAL_RATIO ) / HIVE_100_PERCENT; | ||
asset required_collateral = asset( fc::uint128_to_uint64(_amount), HIVE_SYMBOL ); | ||
|
||
return required_collateral; | ||
} | ||
}; | ||
|
||
} } // hive::protocol | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters