Amounts BasicTaker::remaining_offer (STAmountCalcSwitchovers const& amountCalcSwitchovers) const { // If the taker is done, then there's no offer to place. if (done ()) return Amounts (remaining_.in.zeroed(), remaining_.out.zeroed()); // Avoid math altogether if we didn't cross. if (original_ == remaining_) return original_; if (sell_) { assert (remaining_.in > zero); // We scale the output based on the remaining input: return Amounts (remaining_.in, divRound ( remaining_.in, quality_.rate (), issue_out_, true, amountCalcSwitchovers)); } assert (remaining_.out > zero); // We scale the input based on the remaining output: return Amounts (mulRound ( remaining_.out, quality_.rate (), issue_in_, true, amountCalcSwitchovers), remaining_.out); }
Amounts Taker::remaining_offer () const { // If the taker is done, then there's no offer to place. if (done ()) return Amounts (m_amount.in.zeroed(), m_amount.out.zeroed()); // Avoid math altogether if we didn't cross. if (m_amount == m_remain) return m_amount; if (m_options.sell) { assert (m_remain.in > zero); // We scale the output based on the remaining input: return Amounts (m_remain.in, divRound ( m_remain.in, m_quality.rate (), m_remain.out.issue (), true)); } assert (m_remain.out > zero); // We scale the input based on the remaining output: return Amounts (mulRound ( m_remain.out, m_quality.rate (), m_remain.in.issue (), true), m_remain.out); }
Amounts cross (Amounts offer, Quality quality) { if (reject (quality)) return Amounts (offer.in.zeroed (), offer.out.zeroed ()); // we need to emulate "unfunded offers" behavior if (get_funds (AccountID (0x4702), offer.out) == beast::zero) return Amounts (offer.in.zeroed (), offer.out.zeroed ()); if (done ()) return Amounts (offer.in.zeroed (), offer.out.zeroed ()); auto result = do_cross (offer, quality, AccountID (0x4702)); funds_ -= result.order.in; return result.order; }
void test_operations () { testcase ("operations"); Quality const q11 (Amounts ( STAmount (noIssue(), 731), STAmount (noIssue(), 731))); Quality qa (q11); Quality qb (q11); BEAST_EXPECT(qa == qb); BEAST_EXPECT(++qa != q11); BEAST_EXPECT(qa != qb); BEAST_EXPECT(--qb != q11); BEAST_EXPECT(qa != qb); BEAST_EXPECT(qb < qa); BEAST_EXPECT(qb++ < qa); BEAST_EXPECT(qb++ < qa); BEAST_EXPECT(qb++ == qa); BEAST_EXPECT(qa < qb); }
void test_ceil_in () { testcase ("ceil_in"); { // 1 in, 1 out: Quality q (Amounts (amount(1), amount(1))); ceil_in (q, 1, 1, // 1 in, 1 out 1, // limit: 1 1, 1); // 1 in, 1 out ceil_in (q, 10, 10, // 10 in, 10 out 5, // limit: 5 5, 5); // 5 in, 5 out ceil_in (q, 5, 5, // 5 in, 5 out 10, // limit: 10 5, 5); // 5 in, 5 out } { // 1 in, 2 out: Quality q (Amounts (amount(1), amount(2))); ceil_in (q, 40, 80, // 40 in, 80 out 40, // limit: 40 40, 80); // 40 in, 20 out ceil_in (q, 40, 80, // 40 in, 80 out 20, // limit: 20 20, 40); // 20 in, 40 out ceil_in (q, 40, 80, // 40 in, 80 out 60, // limit: 60 40, 80); // 40 in, 80 out } { // 2 in, 1 out: Quality q (Amounts (amount(2), amount(1))); ceil_in (q, 40, 20, // 40 in, 20 out 20, // limit: 20 20, 10); // 20 in, 10 out ceil_in (q, 40, 20, // 40 in, 20 out 40, // limit: 40 40, 20); // 40 in, 20 out ceil_in (q, 40, 20, // 40 in, 20 out 50, // limit: 40 40, 20); // 40 in, 20 out } }
static Amounts amounts (In in, Out out) { return Amounts (amount(in), amount(out)); }
void test_ceil_out () { testcase ("ceil_out"); { // 1 in, 1 out: Quality q (Amounts (amount(1),amount(1))); ceil_out (q, 1, 1, // 1 in, 1 out 1, // limit 1 1, 1); // 1 in, 1 out ceil_out (q, 10, 10, // 10 in, 10 out 5, // limit 5 5, 5); // 5 in, 5 out ceil_out (q, 10, 10, // 10 in, 10 out 20, // limit 20 10, 10); // 10 in, 10 out } { // 1 in, 2 out: Quality q (Amounts (amount(1),amount(2))); ceil_out (q, 40, 80, // 40 in, 80 out 40, // limit 40 20, 40); // 20 in, 40 out ceil_out (q, 40, 80, // 40 in, 80 out 80, // limit 80 40, 80); // 40 in, 80 out ceil_out (q, 40, 80, // 40 in, 80 out 100, // limit 100 40, 80); // 40 in, 80 out } { // 2 in, 1 out: Quality q (Amounts (amount(2),amount(1))); ceil_out (q, 40, 20, // 40 in, 20 out 20, // limit 20 40, 20); // 40 in, 20 out ceil_out (q, 40, 20, // 40 in, 20 out 40, // limit 40 40, 20); // 40 in, 20 out ceil_out (q, 40, 20, // 40 in, 20 out 10, // limit 10 20, 10); // 20 in, 10 out } }