You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

account-order.js 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. exports.parseAccountOrder = void 0;
  7. const bignumber_js_1 = __importDefault(require("bignumber.js"));
  8. const amount_1 = __importDefault(require("./amount"));
  9. const utils_1 = require("./utils");
  10. const common_1 = require("../../common");
  11. const flags_1 = require("./flags");
  12. function computeQuality(takerGets, takerPays) {
  13. const quotient = new bignumber_js_1.default(takerPays.value).dividedBy(takerGets.value);
  14. return quotient.precision(16, bignumber_js_1.default.ROUND_HALF_UP).toString();
  15. }
  16. function parseAccountOrder(address, order) {
  17. const direction = (order.flags & flags_1.orderFlags.Sell) === 0 ? 'buy' : 'sell';
  18. const takerGetsAmount = amount_1.default(order.taker_gets);
  19. const takerPaysAmount = amount_1.default(order.taker_pays);
  20. const quantity = direction === 'buy' ? takerPaysAmount : takerGetsAmount;
  21. const totalPrice = direction === 'buy' ? takerGetsAmount : takerPaysAmount;
  22. const specification = common_1.removeUndefined({
  23. direction: direction,
  24. quantity: quantity,
  25. totalPrice: totalPrice,
  26. passive: (order.flags & flags_1.orderFlags.Passive) !== 0 || undefined,
  27. expirationTime: utils_1.parseTimestamp(order.expiration)
  28. });
  29. const makerExchangeRate = order.quality
  30. ? utils_1.adjustQualityForXRP(order.quality.toString(), takerGetsAmount.currency, takerPaysAmount.currency)
  31. : computeQuality(takerGetsAmount, takerPaysAmount);
  32. const properties = {
  33. maker: address,
  34. sequence: order.seq,
  35. makerExchangeRate: makerExchangeRate
  36. };
  37. return { specification, properties };
  38. }
  39. exports.parseAccountOrder = parseAccountOrder;
  40. //# sourceMappingURL=account-order.js.map