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.

getFeeXrp.js 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. "use strict";
  2. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  3. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  4. return new (P || (P = Promise))(function (resolve, reject) {
  5. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  6. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  7. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  8. step((generator = generator.apply(thisArg, _arguments || [])).next());
  9. });
  10. };
  11. var __importDefault = (this && this.__importDefault) || function (mod) {
  12. return (mod && mod.__esModule) ? mod : { "default": mod };
  13. };
  14. Object.defineProperty(exports, "__esModule", { value: true });
  15. const bignumber_js_1 = __importDefault(require("bignumber.js"));
  16. const errors_1 = require("../errors");
  17. const NUM_DECIMAL_PLACES = 6;
  18. const BASE_10 = 10;
  19. function getFeeXrp(client, cushion) {
  20. var _a;
  21. return __awaiter(this, void 0, void 0, function* () {
  22. const feeCushion = cushion !== null && cushion !== void 0 ? cushion : client.feeCushion;
  23. const serverInfo = (yield client.request({ command: 'server_info' })).result
  24. .info;
  25. const baseFee = (_a = serverInfo.validated_ledger) === null || _a === void 0 ? void 0 : _a.base_fee_xrp;
  26. if (baseFee == null) {
  27. throw new errors_1.XrplError('getFeeXrp: Could not get base_fee_xrp from server_info');
  28. }
  29. const baseFeeXrp = new bignumber_js_1.default(baseFee);
  30. if (serverInfo.load_factor == null) {
  31. serverInfo.load_factor = 1;
  32. }
  33. let fee = baseFeeXrp.times(serverInfo.load_factor).times(feeCushion);
  34. fee = bignumber_js_1.default.min(fee, client.maxFeeXRP);
  35. return new bignumber_js_1.default(fee.toFixed(NUM_DECIMAL_PLACES)).toString(BASE_10);
  36. });
  37. }
  38. exports.default = getFeeXrp;
  39. //# sourceMappingURL=getFeeXrp.js.map