Skip to content

Commit

Permalink
Merge branch 'master' into 3596-ico-max-supply
Browse files Browse the repository at this point in the history
  • Loading branch information
mvandeberg committed Feb 11, 2020
2 parents 8484091 + 14b7631 commit c2a53cc
Show file tree
Hide file tree
Showing 13 changed files with 159 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class smt_ico_object : public object< smt_ico_object_type, smt_ico_object >
time_point_sec contribution_begin_time;
time_point_sec contribution_end_time;
time_point_sec launch_time;
share_type steem_units_min = -1;
share_type steem_satoshi_min = -1;
uint32_t min_unit_ratio = 0;
uint32_t max_unit_ratio = 0;
asset contributed = asset( 0, STEEM_SYMBOL );
Expand Down Expand Up @@ -217,7 +217,7 @@ class smt_ico_tier_object : public object< smt_ico_tier_object_type, smt_ico_tie

id_type id;
asset_symbol_type symbol;
share_type steem_units_cap = -1;
share_type steem_satoshi_cap = -1;
shared_smt_generation_unit generation_unit;
};

Expand Down Expand Up @@ -379,17 +379,17 @@ typedef multi_index_container <
allocator< smt_ico_object >
> smt_ico_index;

struct by_symbol_steem_units_cap;
struct by_symbol_steem_satoshi_cap;

typedef multi_index_container <
smt_ico_tier_object,
indexed_by <
ordered_unique< tag< by_id >,
member< smt_ico_tier_object, smt_ico_tier_object_id_type, &smt_ico_tier_object::id > >,
ordered_unique< tag< by_symbol_steem_units_cap >,
ordered_unique< tag< by_symbol_steem_satoshi_cap >,
composite_key< smt_ico_tier_object,
member< smt_ico_tier_object, asset_symbol_type, &smt_ico_tier_object::symbol >,
member< smt_ico_tier_object, share_type, &smt_ico_tier_object::steem_units_cap >
member< smt_ico_tier_object, share_type, &smt_ico_tier_object::steem_satoshi_cap >
>,
composite_key_compare< std::less< asset_symbol_type >, std::less< share_type > >
>
Expand Down Expand Up @@ -475,7 +475,7 @@ FC_REFLECT( steem::chain::smt_ico_object,
(contribution_begin_time)
(contribution_end_time)
(launch_time)
(steem_units_min)
(steem_satoshi_min)
(min_unit_ratio)
(max_unit_ratio)
(contributed)
Expand All @@ -489,7 +489,7 @@ FC_REFLECT( steem::chain::shared_smt_generation_unit,
FC_REFLECT( steem::chain::smt_ico_tier_object,
(id)
(symbol)
(steem_units_cap)
(steem_satoshi_cap)
(generation_unit)
)

Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/required_action_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void smt_ico_evaluation_evaluator::do_apply( const smt_ico_evaluation_action& a
const smt_token_object& token = _db.get< smt_token_object, by_symbol >( a.symbol );
const smt_ico_object& ico = _db.get< smt_ico_object, by_symbol >( token.liquid_symbol );

if ( ico.contributed.amount >= ico.steem_units_min )
if ( ico.contributed.amount >= ico.steem_satoshi_min )
{
_db.modify( token, []( smt_token_object& o )
{
Expand Down
39 changes: 25 additions & 14 deletions libraries/chain/smt_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ void smt_create_evaluator::do_apply( const smt_create_operation& o )
FC_ASSERT( token_ptr->control_account == o.control_account, "You do not control this SMT. Control Account: ${a}", ("a", token_ptr->control_account) );
FC_ASSERT( token_ptr->phase == smt_phase::setup, "SMT cannot be reset if setup is completed. Phase: ${p}", ("p", token_ptr->phase) );
FC_ASSERT( !util::smt::last_emission_time( _db, token_ptr->liquid_symbol ), "Cannot reset an SMT that has existing token emissions." );
FC_ASSERT( util::smt::ico::ico_tier_size(_db, token_ptr->liquid_symbol ) == 0, "Cannot reset an SMT that has existing ICO tiers." );

_db.remove( *token_ptr );
}
Expand Down Expand Up @@ -170,21 +171,21 @@ void smt_setup_evaluator::do_apply( const smt_setup_operation& o )
const smt_token_object& _token = common_pre_setup_evaluation( _db, o.symbol, o.control_account );
share_type hard_cap;

if ( o.steem_units_min > 0 )
if ( o.steem_satoshi_min > 0 )
{
auto possible_hard_cap = util::smt::ico::get_ico_steem_hard_cap( _db, o.symbol );

FC_ASSERT( possible_hard_cap.valid(),
"An SMT with a Steem Units Minimum of ${s} cannot succeed without an ICO tier.", ("s", o.steem_units_min) );
"An SMT with a Steem Satoshi Minimum of ${s} cannot succeed without an ICO tier.", ("s", o.steem_satoshi_min) );

hard_cap = *possible_hard_cap;

FC_ASSERT( o.steem_units_min <= hard_cap,
"The Steem Units Minimum must be less than the hard cap. Steem Units Minimum: ${s}, Hard Cap: ${c}",
("s", o.steem_units_min)("c", hard_cap) );
FC_ASSERT( o.steem_satoshi_min <= hard_cap,
"The Steem Satoshi Minimum must be less than the hard cap. Steem Satoshi Minimum: ${s}, Hard Cap: ${c}",
("s", o.steem_satoshi_min)("c", hard_cap) );
}

auto ico_tiers = _db.get_index< smt_ico_tier_index, by_symbol_steem_units_cap >().equal_range( _token.liquid_symbol );
auto ico_tiers = _db.get_index< smt_ico_tier_index, by_symbol_steem_satoshi_cap >().equal_range( _token.liquid_symbol );
share_type prev_tier_cap = 0;
share_type total_tokens = 0;

Expand All @@ -196,7 +197,7 @@ void smt_setup_evaluator::do_apply( const smt_setup_operation& o )

// This is done with share_types, which are safe< int64_t >. Overflow is detected but does not provide
// a useful error message. Do the checks manually to provide actionable information.
fc::uint128_t new_tokens = ( ( ico_tiers.first->steem_units_cap - prev_tier_cap ).value / ico_tiers.first->generation_unit.steem_unit_sum() );
fc::uint128_t new_tokens = ( ( ico_tiers.first->steem_satoshi_cap - prev_tier_cap ).value / ico_tiers.first->generation_unit.steem_unit_sum() );

new_tokens *= o.min_unit_ratio;
FC_ASSERT( new_tokens.hi == 0 && new_tokens.lo <= uint64_t( std::numeric_limits<int64_t>::max() ),
Expand All @@ -207,7 +208,7 @@ void smt_setup_evaluator::do_apply( const smt_setup_operation& o )
"Overflow detected in ICO tier '${t}'", ("tier", *ico_tiers.first) );

total_tokens += new_tokens.to_int64();
prev_tier_cap = ico_tiers.first->steem_units_cap;
prev_tier_cap = ico_tiers.first->steem_satoshi_cap;
}

FC_ASSERT( total_tokens < STEEM_MAX_SHARE_SUPPLY,
Expand All @@ -228,7 +229,7 @@ void smt_setup_evaluator::do_apply( const smt_setup_operation& o )
token_ico_obj.contribution_begin_time = o.contribution_begin_time;
token_ico_obj.contribution_end_time = o.contribution_end_time;
token_ico_obj.launch_time = o.launch_time;
token_ico_obj.steem_units_min = o.steem_units_min;
token_ico_obj.steem_satoshi_min = o.steem_satoshi_min;
token_ico_obj.min_unit_ratio = o.min_unit_ratio;
token_ico_obj.max_unit_ratio = o.max_unit_ratio;
} );
Expand All @@ -251,12 +252,12 @@ void smt_setup_ico_tier_evaluator::do_apply( const smt_setup_ico_tier_operation&

if ( o.remove )
{
auto key = boost::make_tuple( token.liquid_symbol, o.steem_units_cap );
const auto* ito = _db.find< smt_ico_tier_object, by_symbol_steem_units_cap >( key );
auto key = boost::make_tuple( token.liquid_symbol, o.steem_satoshi_cap );
const auto* ito = _db.find< smt_ico_tier_object, by_symbol_steem_satoshi_cap >( key );

FC_ASSERT( ito != nullptr,
"The specified ICO tier does not exist. Symbol: ${s}, Steem Units Cap: ${c}",
("s", token.liquid_symbol)("c", o.steem_units_cap)
"The specified ICO tier does not exist. Symbol: ${s}, Steem Satoshi Cap: ${c}",
("s", token.liquid_symbol)("c", o.steem_satoshi_cap)
);

_db.remove( *ito );
Expand All @@ -273,7 +274,7 @@ void smt_setup_ico_tier_evaluator::do_apply( const smt_setup_ico_tier_operation&
_db.create< smt_ico_tier_object >( [&]( smt_ico_tier_object& ito )
{
ito.symbol = token.liquid_symbol;
ito.steem_units_cap = o.steem_units_cap;
ito.steem_satoshi_cap = o.steem_satoshi_cap;
ito.generation_unit = generation_policy.generation_unit;
});
}
Expand Down Expand Up @@ -313,6 +314,16 @@ void smt_setup_emissions_evaluator::do_apply( const smt_setup_emissions_operatio
("s", SMT_EMISSION_MIN_INTERVAL_SECONDS)("end", *end_time) );
}

for ( const auto& e : o.emissions_unit.token_unit )
{
if ( smt::unit_target::is_account_name_type( e.first ) )
{
std::string name = smt::unit_target::get_unit_target_account( e.first );
auto acc = _db.find< account_object, by_name >( name );
FC_ASSERT( acc != nullptr, "Invalid emission destination, account ${a} must exist", ("a", name) );
}
}

_db.create< smt_token_emissions_object >( [&]( smt_token_emissions_object& eo )
{
eo.symbol = smt.liquid_symbol;
Expand Down
22 changes: 11 additions & 11 deletions libraries/chain/util/smt_token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ bool schedule_next_contributor_payout( database& db, const asset_symbol_type& a
payout_action.symbol = itr->symbol;

const auto& ico = db.get< smt_ico_object, by_symbol >( itr->symbol );
const auto& ico_tier_idx = db.get_index< smt_ico_tier_index, by_symbol_steem_units_cap >();
const auto& ico_tier_idx = db.get_index< smt_ico_tier_index, by_symbol_steem_satoshi_cap >();

using generation_unit_share = std::tuple< smt_generation_unit, share_type >;

Expand All @@ -251,8 +251,8 @@ bool schedule_next_contributor_payout( database& db, const asset_symbol_type& a
{
auto tier_contributions = unprocessed_contributions;

if ( ico.processed_contributions + unprocessed_contributions > ico_tier->steem_units_cap )
tier_contributions = ico_tier->steem_units_cap - ico.processed_contributions;
if ( ico.processed_contributions + unprocessed_contributions > ico_tier->steem_satoshi_cap )
tier_contributions = ico_tier->steem_satoshi_cap - ico.processed_contributions;

generation_unit_shares.push_back( std::make_tuple( ico_tier->generation_unit, tier_contributions ) );

Expand Down Expand Up @@ -322,7 +322,7 @@ bool schedule_founder_payout( database& db, const asset_symbol_type& a )
{
bool action_scheduled = false;
const auto& ico = db.get< smt_ico_object, by_symbol >( a );
const auto& ico_tier_idx = db.get_index< smt_ico_tier_index, by_symbol_steem_units_cap >();
const auto& ico_tier_idx = db.get_index< smt_ico_tier_index, by_symbol_steem_satoshi_cap >();

using generation_unit_share = std::tuple< smt_generation_unit, share_type >;

Expand All @@ -334,12 +334,12 @@ bool schedule_founder_payout( database& db, const asset_symbol_type& a )
{
auto tier_contributions = unprocessed_contributions;

if ( ico.contributed.amount > ico_tier->steem_units_cap )
if ( ico.contributed.amount > ico_tier->steem_satoshi_cap )
{
if ( last_ico_tier != ico_tier_idx.end() )
tier_contributions = last_ico_tier->steem_units_cap - ico_tier->steem_units_cap;
tier_contributions = last_ico_tier->steem_satoshi_cap - ico_tier->steem_satoshi_cap;
else
tier_contributions = ico_tier->steem_units_cap;
tier_contributions = ico_tier->steem_satoshi_cap;
}

generation_unit_shares.push_back( std::make_tuple( ico_tier->generation_unit, tier_contributions ) );
Expand Down Expand Up @@ -445,15 +445,15 @@ bool schedule_founder_payout( database& db, const asset_symbol_type& a )

fc::optional< share_type > get_ico_steem_hard_cap( database& db, const asset_symbol_type& a )
{
const auto& idx = db.get_index< smt_ico_tier_index, by_symbol_steem_units_cap >();
const auto& idx = db.get_index< smt_ico_tier_index, by_symbol_steem_satoshi_cap >();

const auto range = idx.equal_range( a );

auto itr = range.second;
while ( itr != range.first )
{
--itr;
return itr->steem_units_cap;
return itr->steem_satoshi_cap;
}

return {};
Expand All @@ -463,7 +463,7 @@ void remove_ico_objects( database& db, const asset_symbol_type& symbol )
{
db.remove( db.get< smt_ico_object, by_symbol >( symbol ) );

const auto& ico_tier_idx = db.get_index< smt_ico_tier_index, by_symbol_steem_units_cap >();
const auto& ico_tier_idx = db.get_index< smt_ico_tier_index, by_symbol_steem_satoshi_cap >();
auto itr = ico_tier_idx.lower_bound( symbol );
while( itr != ico_tier_idx.end() && itr->symbol == symbol )
{
Expand All @@ -478,7 +478,7 @@ std::size_t ico_tier_size( database& db, const asset_symbol_type& symbol )
{
std::size_t num_ico_tiers = 0;

const auto& ico_tier_idx = db.get_index< smt_ico_tier_index, by_symbol_steem_units_cap >();
const auto& ico_tier_idx = db.get_index< smt_ico_tier_index, by_symbol_steem_satoshi_cap >();
auto ico_tier_itr = ico_tier_idx.lower_bound( symbol );
while ( ico_tier_itr != ico_tier_idx.end() && ico_tier_itr->symbol == symbol )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ namespace steem { namespace plugins { namespace condenser_api {
contribution_begin_time( op.contribution_begin_time ),
contribution_end_time( op.contribution_end_time ),
launch_time( op.launch_time ),
steem_units_min( op.steem_units_min ),
steem_satoshi_min( op.steem_satoshi_min ),
min_unit_ratio( op.min_unit_ratio ),
max_unit_ratio( op.max_unit_ratio )
{
Expand All @@ -748,7 +748,7 @@ namespace steem { namespace plugins { namespace condenser_api {
op.contribution_begin_time = contribution_begin_time;
op.contribution_end_time = contribution_end_time;
op.launch_time = launch_time;
op.steem_units_min = steem_units_min;
op.steem_satoshi_min = steem_satoshi_min;
op.min_unit_ratio = min_unit_ratio;
op.max_unit_ratio = max_unit_ratio;

Expand All @@ -764,7 +764,7 @@ namespace steem { namespace plugins { namespace condenser_api {
time_point_sec contribution_end_time;
time_point_sec launch_time;

share_type steem_units_min;
share_type steem_satoshi_min;
uint32_t min_unit_ratio = 0;
uint32_t max_unit_ratio = 0;

Expand All @@ -777,7 +777,7 @@ namespace steem { namespace plugins { namespace condenser_api {
legacy_smt_setup_ico_tier_operation( const smt_setup_ico_tier_operation& op ) :
control_account( op.control_account ),
symbol( op.symbol ),
steem_units_cap( op.steem_units_cap ),
steem_satoshi_cap( op.steem_satoshi_cap ),
remove( op.remove )
{
op.generation_policy.visit( convert_to_legacy_static_variant< legacy_smt_generation_policy >( generation_policy ) );
Expand All @@ -788,7 +788,7 @@ namespace steem { namespace plugins { namespace condenser_api {
smt_setup_ico_tier_operation op;
op.control_account = control_account;
op.symbol = symbol;
op.steem_units_cap = steem_units_cap;
op.steem_satoshi_cap = steem_satoshi_cap;
op.generation_policy = generation_policy;
op.remove = remove;

Expand All @@ -798,7 +798,7 @@ namespace steem { namespace plugins { namespace condenser_api {
account_name_type control_account;
asset_symbol_type symbol;

share_type steem_units_cap;
share_type steem_satoshi_cap;
legacy_smt_generation_policy generation_policy;
bool remove = false;
extensions_type extensions;
Expand Down Expand Up @@ -1908,9 +1908,9 @@ FC_REFLECT( steem::plugins::condenser_api::legacy_delegate_vesting_shares_operat
FC_REFLECT( steem::plugins::condenser_api::legacy_author_reward_operation, (author)(permlink)(sbd_payout)(steem_payout)(vesting_payout) )
FC_REFLECT( steem::plugins::condenser_api::legacy_curation_reward_operation, (curator)(reward)(comment_author)(comment_permlink) )
FC_REFLECT( steem::plugins::condenser_api::legacy_comment_reward_operation, (author)(permlink)(payout) )
FC_REFLECT( steem::plugins::condenser_api::legacy_smt_setup_operation, (control_account)(symbol)(max_supply)(contribution_begin_time)(contribution_end_time)(launch_time)(steem_units_min)(min_unit_ratio)(max_unit_ratio)(extensions) )
FC_REFLECT( steem::plugins::condenser_api::legacy_smt_setup_operation, (control_account)(symbol)(max_supply)(contribution_begin_time)(contribution_end_time)(launch_time)(steem_satoshi_min)(min_unit_ratio)(max_unit_ratio)(extensions) )
FC_REFLECT( steem::plugins::condenser_api::legacy_smt_set_setup_parameters_operation, (control_account)(symbol)(setup_parameters)(extensions) )
FC_REFLECT( steem::plugins::condenser_api::legacy_smt_setup_ico_tier_operation, (control_account)(symbol)(steem_units_cap)(generation_policy)(remove)(extensions) )
FC_REFLECT( steem::plugins::condenser_api::legacy_smt_setup_ico_tier_operation, (control_account)(symbol)(steem_satoshi_cap)(generation_policy)(remove)(extensions) )
FC_REFLECT( steem::plugins::condenser_api::legacy_smt_set_runtime_parameters_operation, (control_account)(symbol)(runtime_parameters)(extensions))
FC_REFLECT( steem::plugins::condenser_api::legacy_fill_convert_request_operation, (owner)(requestid)(amount_in)(amount_out) )
FC_REFLECT( steem::plugins::condenser_api::legacy_liquidity_reward_operation, (owner)(payout) )
Expand Down
8 changes: 4 additions & 4 deletions libraries/protocol/include/steem/protocol/smt_operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct smt_setup_operation : public base_operation
time_point_sec contribution_end_time;
time_point_sec launch_time;

share_type steem_units_min;
share_type steem_satoshi_min;

uint32_t min_unit_ratio = 0;
uint32_t max_unit_ratio = 0;
Expand All @@ -96,7 +96,7 @@ struct smt_setup_ico_tier_operation : public base_operation
account_name_type control_account;
asset_symbol_type symbol;

share_type steem_units_cap;
share_type steem_satoshi_cap;
smt_generation_policy generation_policy;
bool remove = false;

Expand Down Expand Up @@ -239,7 +239,7 @@ FC_REFLECT(
(contribution_begin_time)
(contribution_end_time)
(launch_time)
(steem_units_min)
(steem_satoshi_min)
(min_unit_ratio)
(max_unit_ratio)
(extensions)
Expand Down Expand Up @@ -267,7 +267,7 @@ FC_REFLECT(
steem::protocol::smt_setup_ico_tier_operation,
(control_account)
(symbol)
(steem_units_cap)
(steem_satoshi_cap)
(generation_policy)
(remove)
(extensions)
Expand Down
2 changes: 2 additions & 0 deletions libraries/protocol/include/steem/protocol/smt_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#define SMT_DESTINATION_REWARDS unit_target_type( SMT_DESTINATION_PREFIX "rewards" )
#define SMT_DESTINATION_VESTING unit_target_type( SMT_DESTINATION_PREFIX "vesting" )

#define SMT_DESTINATION_ACCOUNT_VESTING(name) unit_target_type( SMT_DESTINATION_ACCOUNT_PREFIX name SMT_DESTINATION_VESTING_SUFFIX )

namespace steem { namespace protocol { namespace smt {

namespace unit_target {
Expand Down
6 changes: 3 additions & 3 deletions libraries/protocol/smt_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ void smt_setup_ico_tier_operation::validate()const
{
smt_admin_operation_validate( *this );

FC_ASSERT( steem_units_cap >= 0, "Steem units cap must be greater than or equal to 0" );
FC_ASSERT( steem_units_cap <= STEEM_MAX_SHARE_SUPPLY, "Steem units cap must be less than or equal to ${n}", ("n", STEEM_MAX_SHARE_SUPPLY) );
FC_ASSERT( steem_satoshi_cap >= 0, "Steem satoshi cap must be greater than or equal to 0" );
FC_ASSERT( steem_satoshi_cap <= STEEM_MAX_SHARE_SUPPLY, "Steem satoshi cap must be less than or equal to ${n}", ("n", STEEM_MAX_SHARE_SUPPLY) );

validate_visitor vtor;
generation_policy.visit( vtor );
Expand Down Expand Up @@ -221,7 +221,7 @@ void smt_setup_operation::validate()const
FC_ASSERT( contribution_begin_time > STEEM_GENESIS_TIME, "Contribution begin time must be greater than ${t}", ("t", STEEM_GENESIS_TIME) );
FC_ASSERT( contribution_end_time >= contribution_begin_time, "Contribution end time must be equal to or later than contribution begin time" );
FC_ASSERT( launch_time >= contribution_end_time, "Launch time must be equal to or later than the contribution end time" );
FC_ASSERT( steem_units_min >= 0, "Steem units min must be greater than or equal to 0" );
FC_ASSERT( steem_satoshi_min >= 0, "Steem satoshi minimum must be greater than or equal to 0" );
}

struct smt_set_runtime_parameters_operation_visitor
Expand Down
Loading

0 comments on commit c2a53cc

Please sign in to comment.