3#include <sysio/check.hpp>
13 const double S0 =
supply.amount;
14 const double R0 = reserve.
balance.amount;
15 const double dR = payment.amount;
16 const double F = reserve.
weight;
18 double dS = S0 * ( std::pow(1. + dR / R0, F) - 1. );
27 const double R0 = reserve.
balance.amount;
28 const double S0 =
supply.amount;
29 const double dS = -tokens.amount;
30 const double Fi = double(1) / reserve.
weight;
32 double dR = R0 * ( std::pow(1. + dS / S0, Fi) - 1. );
41 const auto& sell_symbol = from.symbol;
42 const auto& base_symbol = base.balance.symbol;
44 check( sell_symbol != to,
"cannot convert to the same symbol" );
47 if ( sell_symbol == base_symbol && to == quote_symbol ) {
50 }
else if ( sell_symbol == quote_symbol && to == base_symbol ) {
54 check(
false,
"invalid conversion" );
61 const auto& sell_symbol = from.symbol;
62 const auto& base_symbol = base.balance.symbol;
64 check( sell_symbol != to,
"cannot convert to the same symbol" );
67 if ( sell_symbol == base_symbol && to == quote_symbol ) {
71 }
else if ( sell_symbol == quote_symbol && to == base_symbol ) {
76 check(
false,
"invalid conversion" );
85 const double ib = inp_reserve;
86 const double ob = out_reserve;
87 const double in = inp;
91 if ( out < 0 ) out = 0;
100 const double ob = out_reserve;
101 const double ib = inp_reserve;
103 int64_t inp = (ib * out) / (ob - out);
105 if ( inp < 0 ) inp = 0;
static int64_t get_bancor_input(int64_t out_reserve, int64_t inp_reserve, int64_t out)
asset convert_to_exchange(connector &reserve, const asset &payment)
asset convert(const asset &from, const symbol &to)
asset convert_from_exchange(connector &reserve, const asset &tokens)
asset direct_convert(const asset &from, const symbol &to)
static int64_t get_bancor_output(int64_t inp_reserve, int64_t out_reserve, int64_t inp)