29 namespace graphene {
namespace chain {
46 assert( elapsed_seconds > 0 );
53 total_vested =
static_cast<uint64_t
>(fc::uint128_t(
begin_balance.
value ) * elapsed_seconds
60 assert( total_vested >= 0 );
63 assert( withdrawn_already >= 0 );
65 allowed_withdraw = total_vested - withdrawn_already;
66 assert( allowed_withdraw >= 0 );
95 assert(ctx.
now >= coin_seconds_earned_last_update);
96 int64_t delta_seconds = (ctx.
now - coin_seconds_earned_last_update).to_seconds();
97 assert(delta_seconds >= 0);
100 delta_coin_seconds *= delta_seconds;
103 coin_seconds_earned_cap *= std::max(vesting_seconds, 1u);
105 return std::min(coin_seconds_earned + delta_coin_seconds, coin_seconds_earned_cap);
110 coin_seconds_earned = compute_coin_seconds_earned(ctx);
111 coin_seconds_earned_last_update = ctx.
now;
116 if(ctx.
now <= start_claim)
118 fc::uint128_t cs_earned = compute_coin_seconds_earned(ctx);
119 fc::uint128_t withdraw_available = cs_earned / std::max(vesting_seconds, 1u);
126 update_coin_seconds_earned(ctx);
137 update_coin_seconds_earned(ctx);
139 coin_seconds_needed *= std::max(vesting_seconds, 1u);
142 assert(coin_seconds_needed <= coin_seconds_earned);
144 coin_seconds_earned -= coin_seconds_needed;
193 #define VESTING_VISITOR(NAME, MAYBE_CONST) \ 194 struct NAME ## _visitor \ 197 std::declval<linear_vesting_policy>().NAME( \ 198 std::declval<vesting_policy_context>()) \ 202 const asset& balance, \ 203 const time_point_sec& now, \ 204 const asset& amount \ 206 : ctx(balance, now, amount) {} \ 208 template< typename Policy > \ 210 operator()(MAYBE_CONST Policy& policy) MAYBE_CONST \ 212 return policy.NAME(ctx); \ 215 vesting_policy_context ctx; \ 228 return policy.visit(is_deposit_allowed_visitor(balance, now, amount));
233 bool result = policy.visit(is_withdraw_allowed_visitor(balance, now, amount));
236 assert((amount <= balance) || (!result));
242 on_deposit_visitor vtor(balance, now, amount);
249 on_deposit_vested_visitor vtor(balance, now, amount);
256 return policy.visit(is_deposit_vested_allowed_visitor(balance, now, amount));
261 assert(amount <= balance);
262 on_withdraw_visitor vtor(balance, now, amount);
270 return policy.visit(get_allowed_withdraw_visitor(balance, now, amount));
void on_withdraw(const vesting_policy_context &ctx)
bool is_withdraw_allowed(const vesting_policy_context &ctx) const
asset get_allowed_withdraw(const vesting_policy_context &ctx) const
fc::time_point_sec begin_timestamp
This is the time at which funds begin vesting.
asset get_allowed_withdraw(const time_point_sec &now) const
bool is_withdraw_allowed(const vesting_policy_context &ctx) const
uint32_t vesting_duration_seconds
Duration of the vesting period, in seconds. Must be greater than 0 and greater than vesting_cliff_sec...
uint32_t vesting_cliff_seconds
No amount may be withdrawn before this many seconds of the vesting period have elapsed.
bool is_deposit_vested_allowed(const vesting_policy_context &) const
void on_deposit_vested(const vesting_policy_context &ctx)
bool is_deposit_allowed(const fc::time_point_sec &now, const asset &amount) const
void update_coin_seconds_earned(const vesting_policy_context &ctx)
void on_deposit(const vesting_policy_context &ctx)
fc::uint128_t compute_coin_seconds_earned(const vesting_policy_context &ctx) const
bool is_deposit_allowed(const vesting_policy_context &ctx) const
void deposit(const fc::time_point_sec &now, const asset &amount)
Deposit amount into vesting balance, requiring it to vest before withdrawal.
void on_withdraw(const vesting_policy_context &ctx)
void on_deposit_vested(const vesting_policy_context &)
void on_deposit(const vesting_policy_context &ctx)
bool is_deposit_allowed(const vesting_policy_context &ctx) const
asset get_allowed_withdraw(const vesting_policy_context &ctx) const
bool is_deposit_allowed(const vesting_policy_context &ctx) const
bool is_deposit_vested_allowed(const fc::time_point_sec &now, const asset &amount) const
asset get_allowed_withdraw(const vesting_policy_context &ctx) const
share_type begin_balance
The total amount of asset to vest.
void withdraw(const fc::time_point_sec &now, const asset &amount)
#define GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION(type)
void deposit_vested(const fc::time_point_sec &now, const asset &amount)
Deposit amount into vesting balance, making the new funds vest immediately.
bool sum_below_max_shares(const asset &a, const asset &b)
bool is_withdraw_allowed(const vesting_policy_context &ctx) const
void on_deposit_vested(const vesting_policy_context &)
VESTING_VISITOR(on_deposit,)
defines vesting in terms of coin-days accrued which allows for dynamic deposit/withdraw ...
constexpr int64_t GRAPHENE_MAX_SHARE_SUPPLY(1000000000000000LL)
void on_deposit(const vesting_policy_context &ctx)
bool is_deposit_vested_allowed(const vesting_policy_context &ctx) const
void on_withdraw(const vesting_policy_context &ctx)
bool is_withdraw_allowed(const fc::time_point_sec &now, const asset &amount) const
Linear vesting balance with cliff.