3#include <eosio/asset.hpp>
4#include <eosio/eosio.hpp>
27inline uint128_t
mul(int64_t units, uint64_t acc) {
28 return static_cast<uint128_t
>(units) *
static_cast<uint128_t
>(acc);
33 const int64_t u = i.
units();
40 const int64_t u = i.
units();
43 if (remaining <= 0)
return i.
acc_join;
44 const uint128_t num =
static_cast<uint128_t
>(remaining) *
SCALE;
45 const uint128_t step = (num +
static_cast<uint128_t
>(u) - 1) /
static_cast<uint128_t
>(u);
46 return i.
acc_join +
static_cast<uint64_t
>(step);
58 const int64_t u = i.
units();
74 const int64_t u = i.
units();
87 if (b.
base <= 0)
return 0;
89 const int64_t left = b.
base - b.
s_fixed -
static_cast<int64_t
>(accrued /
SCALE);
90 return left > 0 ? left : 0;
95 b.
acc +=
static_cast<uint64_t
>(
static_cast<uint128_t
>(
amount) *
SCALE /
96 static_cast<uint128_t
>(b.
base));
102 int64_t
property = 0;
110 if (
amount <= 0 || units <= 0) {
114 const int64_t m = money_units > units ? units : (money_units > 0 ? money_units : 0);
115 p.
money =
static_cast<int64_t
>(
static_cast<uint128_t
>(
amount) *
static_cast<uint128_t
>(m) /
116 static_cast<uint128_t
>(units));
128 const int64_t u = i.
units();
130 if (excess < 0) excess = 0;
153 if (release_unused && i.
unused() > 0) {
164inline std::optional<mkt_invbranch>
get_branch(eosio::name coopname, eosio::name braname) {
166 auto it = branches.find(braname.value);
167 if (it == branches.end())
return std::nullopt;
174inline eosio::asset
free_of(eosio::name coopname, eosio::name braname) {
177 const eosio::asset free = b->unused_total - b->reserved;
182inline void fund_pool(eosio::name actor, eosio::name coopname, eosio::name braname,
183 eosio::asset
amount,
const checksum256& hash) {
185 std::make_tuple(coopname, braname,
amount, hash)).
send();
189inline void unfund_pool(eosio::name actor, eosio::name coopname, eosio::name braname,
190 eosio::asset
amount,
const checksum256& hash) {
192 std::make_tuple(coopname, braname,
amount, hash)).
send();
196inline void spent_pool(eosio::name actor, eosio::name coopname, eosio::name braname,
197 eosio::asset
amount,
const checksum256& hash) {
199 std::make_tuple(coopname, braname,
amount, hash)).
send();
205inline bool is_operator(eosio::name coopname, eosio::name braname, eosio::name username) {
207 return branch.trustee == username ||
branch.is_account_in_trusted(username);
212inline bool has_agreement(eosio::name coopname, eosio::name username, eosio::name braname) {
214 auto by_pair = agreements.get_index<
"byuserbr"_n>();
215 return by_pair.find(
combine_ids(username.value, braname.value)) != by_pair.end();
221 auto by_user = investors.get_index<
"byuser"_n>();
222 return by_user.find(username.value) != by_user.end();
230 auto by_user = investors.get_index<
"byuser"_n>();
231 for (
auto it = by_user.lower_bound(username.value);
232 it != by_user.end() && it->username == username; ++it) {
233 if (it->unused() <= 0)
continue;
234 auto bit = branches.find(it->braname.value);
235 if (bit == branches.end())
continue;
236 eosio::check(bit->unused_total.amount - it->unused() >= bit->reserved.amount,
237 "MARKETPLACE_INVEST_EXIT_RESERVED: Выход из кооператива невозможен: средства инициатора выделены под расход участка — дождитесь его закрытия");
249inline void add_investment(eosio::name coopname, eosio::name braname, eosio::name username,
250 eosio::asset money, eosio::asset property) {
253 auto bit = branches.find(braname.value);
254 if (bit == branches.end()) {
255 bit = branches.emplace(
RamPayer::of(branches, coopname), [&](
auto& b) {
269 auto by_pair = investors.get_index<
"bybruser"_n>();
270 auto it = by_pair.find(
combine_ids(braname.value, username.value));
271 const bool fresh = it == by_pair.end();
275 row.
id = investors.available_primary_key();
278 row.
status = Status::ACTIVE;
284 row.
joined_at = eosio::time_point_sec(eosio::current_time_point());
305 branches.modify(bit,
RamPayer::of(branches, coopname), [&](
auto& x) { x = b; });
307 investors.emplace(
RamPayer::of(investors, coopname), [&](
auto& x) { x = row; });
309 by_pair.modify(it,
RamPayer::of(investors, coopname), [&](
auto& x) { x = row; });
328 eosio::asset
amount,
const checksum256& order_hash) {
330 int64_t to_repay = 0;
334 auto bit = branches.find(braname.value);
335 if (bit != branches.end() && bit->base > 0) {
360 auto by_done = investors.get_index<
"bydone"_n>();
361 const uint128_t from =
combine_ids(braname.value, 0);
364 for (
auto it = by_done.lower_bound(from); it != by_done.end() && it->by_done() <= upto;
365 it = by_done.lower_bound(from)) {
370 by_done.modify(it,
RamPayer::of(investors, coopname), [&](
auto& x) { x = row; });
379 if (to_repay == left) {
381 for (
auto it = by_done.lower_bound(from); it != by_done.end() && it->by_done() < all;
382 it = by_done.lower_bound(from)) {
388 by_done.modify(it,
RamPayer::of(investors, coopname), [&](
auto& x) { x = row; });
398 if (excess.
total() > 0) {
403 if (excess.
money > 0)
408 branches.modify(bit,
RamPayer::of(branches, coopname), [&](
auto& x) { x = b; });
411 const int64_t rest =
amount.amount - to_repay;
423 eosio::name username) {
426 std::make_tuple(coopname, username)).
send();
static void apply(eosio::name actor, eosio::name coopname, eosio::name operation_code, eosio::name process_type, eosio::asset amount, eosio::name username, eosio::checksum256 process_hash, std::string memo)
Отправить inline action ledger2::apply.
Definition: ledger2.hpp:43
Константы контракта кооперативных участков
Definition: branch.hpp:55
static constexpr eosio::symbol _root_govern_symbol
Definition: consts.hpp:257
static constexpr eosio::name _marketplace
Definition: consts.hpp:193
permission_level
Definition: eosio.msig_tests.cpp:896
share_type amount
Definition: eosio.token_tests.cpp:174
void send(name contract, name action_name, name actor, Args &&... args)
Definition: actions.hpp:10
void accrue(eosio::name actor, eosio::name coopname, eosio::name braname, eosio::asset amount, eosio::name process_type, eosio::checksum256 process_hash, std::string memo)
Inline-вызов branch::accrue от контракта-источника членских взносов (requirement b6 «Экономика КУ»,...
Definition: branch.hpp:62
static constexpr eosio::name DONE
использованное возвращено, неиспользованное доступно к заявлению
Definition: table_marketplace_invest.hpp:49
static constexpr eosio::name ACTIVE
паевой взнос возвращается из экономии участка
Definition: table_marketplace_invest.hpp:48
Definition: invest.hpp:23
int64_t returned_of(const mkt_investor &i, uint64_t acc)
Возмещено инициатору при текущем счётчике участка, единицы актива.
Definition: invest.hpp:32
std::optional< mkt_invbranch > get_branch(eosio::name coopname, eosio::name braname)
Строка участка; без неё паевых взносов в участке нет.
Definition: invest.hpp:164
void unfund_pool(eosio::name actor, eosio::name coopname, eosio::name braname, eosio::asset amount, const checksum256 &hash)
Вернуть невыделенный остаток в средства инициаторов (marketplace::unfundipool).
Definition: invest.hpp:189
static constexpr uint64_t SCALE
Точность счётчика возврата: возвращено на единицу базы × SCALE.
Definition: table_marketplace_invest.hpp:43
void spent_pool(eosio::name actor, eosio::name coopname, eosio::name braname, eosio::asset amount, const checksum256 &hash)
Расход из средств инициаторов оплачен — в базу возврата (marketplace::spentipool).
Definition: invest.hpp:196
eosio::asset zero_asset()
Definition: invest.hpp:25
static constexpr uint64_t OUT_OF_RANGE
Ключ индекса для строк вне выборки (нет неиспользованных денег / вне базы).
Definition: table_marketplace_invest.hpp:45
bool is_operator(eosio::name coopname, eosio::name braname, eosio::name username)
Definition: invest.hpp:205
RepayParts split_repay(int64_t amount, int64_t money_units, int64_t units)
Definition: invest.hpp:108
eosio::asset free_of(eosio::name coopname, eosio::name braname)
Definition: invest.hpp:174
Claimable claimable_of(const mkt_invbranch &b, const mkt_investor &i)
Definition: invest.hpp:146
void enter_base(mkt_invbranch &b, mkt_investor &i)
Ввести инициатора в базу участка с текущей отметкой счётчика.
Definition: invest.hpp:72
uint64_t done_threshold(const mkt_investor &i)
Счётчик участка, при котором использованное инициатора вернётся целиком.
Definition: invest.hpp:39
void accept_repay(mkt_invbranch &b, int64_t amount)
Принять сумму возмещения в счётчик участка.
Definition: invest.hpp:94
bool has_agreement(eosio::name coopname, eosio::name username, eosio::name braname)
Definition: invest.hpp:212
void shift_base_money(mkt_invbranch &b, int64_t delta)
Definition: invest.hpp:51
uint128_t mul(int64_t units, uint64_t acc)
Definition: invest.hpp:27
void check_member_can_exit(eosio::name coopname, eosio::name username)
Definition: invest.hpp:227
void fund_pool(eosio::name actor, eosio::name coopname, eosio::name braname, eosio::asset amount, const checksum256 &hash)
Выделить средства инициаторов под расход или помощь участка (marketplace::fundipool).
Definition: invest.hpp:182
int64_t outstanding(const mkt_invbranch &b)
Definition: invest.hpp:86
RepayParts complete(mkt_invbranch &b, mkt_investor &i)
Definition: invest.hpp:126
void leave_base(mkt_invbranch &b, mkt_investor &i)
Вывести инициатора из базы участка, зафиксировав накопленное.
Definition: invest.hpp:57
bool has_investments(eosio::name coopname, eosio::name username)
Есть ли у пайщика строки инициатора: выходу нужно вычесть его из базы.
Definition: invest.hpp:219
std::string get_invest_surplus_memo()
Definition: memo.hpp:79
std::string get_invest_cost_cover_memo()
Definition: memo.hpp:83
std::string get_charge_due_distribute_memo()
Definition: memo.hpp:58
std::string get_invest_cost_uncover_memo()
Definition: memo.hpp:87
std::string get_invest_repay_memo()
Definition: memo.hpp:75
Canonical helpers контракта marketplace (Story 11.1).
Definition: dues.hpp:25
void add_investment(eosio::name coopname, eosio::name braname, eosio::name username, eosio::asset money, eosio::asset property)
Definition: invest.hpp:249
void release_investments_on_exit(eosio::name actor, eosio::name coopname, eosio::name username)
Definition: invest.hpp:422
void route_initiator_share(eosio::name actor, eosio::name coopname, eosio::name braname, eosio::asset amount, const checksum256 &order_hash)
Definition: invest.hpp:327
eosio::name of(const Table &table, eosio::name coopname)
Definition: ram_payer.hpp:78
constexpr eosio::name INVEST_COST_UNCOVER
Сторно погашения 26 на денежную долю переплаты возмещения, переведённой участку (только проводка Дт 2...
Definition: operations.hpp:134
constexpr eosio::name INVEST_REPAY
Возмещение паевых взносов инициаторов из экономии месяца участка (TRANSFER w.mkt.fee → w....
Definition: operations.hpp:130
constexpr eosio::name INVEST_COST_COVER
Погашение расходов и помощи участка, оплаченных деньгами инициаторов, членскими взносами (только пров...
Definition: operations.hpp:133
constexpr eosio::name INVEST_REPAY_SURPLUS
Переплата возмещения на границе завершения возврата — участку (TRANSFER w.mkt.repay → w....
Definition: operations.hpp:132
constexpr eosio::name DUE
Списание обеспечительной части по итогу периода участка (задача 99D-33): строка счётчика пайщика за п...
Definition: processes.hpp:81
action(permission_level{ _gateway, "active"_n}, _gateway, "adduser"_n, std::make_tuple(coopname, deposit->username, to_spread, to_circulation, eosio::current_time_point(), true)).send()
Definition: invest.hpp:140
int64_t unused
из неиспользованных денег
Definition: invest.hpp:142
int64_t total() const
Definition: invest.hpp:143
int64_t returned
из возмещённого
Definition: invest.hpp:141
Сумма возмещения, разделённая на долю денег и долю имущества.
Definition: invest.hpp:100
int64_t total() const
Definition: invest.hpp:103
int64_t property
без проводки: имущество на 10
Definition: invest.hpp:102
int64_t money
гасит 26 (Дт 86 / Кт 26)
Definition: invest.hpp:101
Паевые взносы инициаторов одного кооперативного участка и счётчик возврата (CRPS)....
Definition: table_marketplace_invest.hpp:108
eosio::binary_extension< int64_t > base_money
Definition: table_marketplace_invest.hpp:126
eosio::asset reserved
выделено в пул под расходы и помощь и ещё не израсходовано
Definition: table_marketplace_invest.hpp:113
eosio::asset unused_total
деньги инициаторов, ещё не израсходованные из пула и не забранные заявлением
Definition: table_marketplace_invest.hpp:112
eosio::asset surplus_total
переплата на границе завершения возврата, переданная на w.brn.common
Definition: table_marketplace_invest.hpp:116
eosio::asset money_total
внесено деньгами по строкам инициаторов участка (за вычетом забранного неиспользованного)
Definition: table_marketplace_invest.hpp:110
int64_t base_money_or_zero() const
Definition: table_marketplace_invest.hpp:129
eosio::asset property_total
внесено имуществом по цене приёма
Definition: table_marketplace_invest.hpp:111
uint128_t s_join
Σ units_i × acc_join_i по базе
Definition: table_marketplace_invest.hpp:119
int64_t base
Σ units активных инициаторов, единицы актива
Definition: table_marketplace_invest.hpp:117
eosio::asset repaid_total
возмещено из экономии участка на w.mkt.repay всего
Definition: table_marketplace_invest.hpp:115
uint64_t join_seq
Definition: table_marketplace_invest.hpp:121
uint64_t acc
возвращено на единицу базы × SCALE
Definition: table_marketplace_invest.hpp:118
int64_t s_fixed
Σ returned_fixed_i по базе
Definition: table_marketplace_invest.hpp:120
Инициатор кооперативного участка: одна строка на пару «участок — пайщик».
Definition: table_marketplace_invest.hpp:143
uint64_t acc_join
счётчик участка на момент последней фиксации
Definition: table_marketplace_invest.hpp:153
uint64_t acc_done
счётчик участка, при котором использованное будет возвращено целиком
Definition: table_marketplace_invest.hpp:154
eosio::asset used_money
из денег израсходовано пулом участка
Definition: table_marketplace_invest.hpp:150
eosio::asset money
внесено деньгами (за вычетом забранного неиспользованного)
Definition: table_marketplace_invest.hpp:148
eosio::time_point_sec joined_at
Definition: table_marketplace_invest.hpp:156
eosio::asset claimed
забрано из возвращённого заявлениями (без неиспользованного)
Definition: table_marketplace_invest.hpp:151
eosio::name braname
кооперативный участок
Definition: table_marketplace_invest.hpp:145
uint64_t join_seq
порядок входа в участок
Definition: table_marketplace_invest.hpp:155
eosio::name status
active | done (done с нулевым остатком — возмещено полностью)
Definition: table_marketplace_invest.hpp:147
eosio::asset property
внесено имуществом по цене приёма
Definition: table_marketplace_invest.hpp:149
eosio::binary_extension< eosio::asset > money_in
Definition: table_marketplace_invest.hpp:160
int64_t units() const
Definition: table_marketplace_invest.hpp:167
int64_t returned_fixed
возвращено на момент последней фиксации, единицы актива
Definition: table_marketplace_invest.hpp:152
eosio::name username
пайщик-инициатор
Definition: table_marketplace_invest.hpp:146
int64_t unused() const
Definition: table_marketplace_invest.hpp:170
uint64_t id
суррогатный ключ
Definition: table_marketplace_invest.hpp:144
eosio::asset money_in_or_current() const
Внесено деньгами всего; у строки прежней сборки — текущий остаток денег.
Definition: table_marketplace_invest.hpp:169
coobranch get_branch_or_fail(eosio::name coopname, eosio::name braname)
Definition: table_branch_branches.hpp:88
eosio::multi_index<"invbranches"_n, mkt_invbranch > mkt_invbranches_index
Definition: table_marketplace_invest.hpp:132
eosio::multi_index< "invagrbranch"_n, mkt_invagreement, eosio::indexed_by<"byuserbr"_n, eosio::const_mem_fun< mkt_invagreement, uint128_t, &mkt_invagreement::by_user_branch > >, eosio::indexed_by<"bybranch"_n, eosio::const_mem_fun< mkt_invagreement, uint64_t, &mkt_invagreement::by_branch > > > mkt_invagreements_index
Definition: table_marketplace_invest.hpp:89
eosio::multi_index< "investors"_n, mkt_investor, eosio::indexed_by<"bybranch"_n, eosio::const_mem_fun< mkt_investor, uint64_t, &mkt_investor::by_branch > >, eosio::indexed_by<"byuser"_n, eosio::const_mem_fun< mkt_investor, uint64_t, &mkt_investor::by_user > >, eosio::indexed_by<"bybruser"_n, eosio::const_mem_fun< mkt_investor, uint128_t, &mkt_investor::by_branch_user > >, eosio::indexed_by<"byunused"_n, eosio::const_mem_fun< mkt_investor, uint128_t, &mkt_investor::by_unused > >, eosio::indexed_by<"bydone"_n, eosio::const_mem_fun< mkt_investor, uint128_t, &mkt_investor::by_done > > > mkt_investors_index
Definition: table_marketplace_invest.hpp:192
static uint128_t combine_ids(const uint64_t &x, const uint64_t &y)
Definition: utils.hpp:7