@usherlabs/cex-broker 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -37287,13 +37287,429 @@ var require_proxy_from_env = __commonJS((exports) => {
37287
37287
  exports.getProxyForUrl = getProxyForUrl;
37288
37288
  });
37289
37289
 
37290
- // node_modules/follow-redirects/debug.js
37290
+ // node_modules/ms/index.js
37291
+ var require_ms = __commonJS((exports, module) => {
37292
+ var s = 1000;
37293
+ var m = s * 60;
37294
+ var h = m * 60;
37295
+ var d = h * 24;
37296
+ var y = d * 365.25;
37297
+ module.exports = function(val, options) {
37298
+ options = options || {};
37299
+ var type2 = typeof val;
37300
+ if (type2 === "string" && val.length > 0) {
37301
+ return parse(val);
37302
+ } else if (type2 === "number" && isNaN(val) === false) {
37303
+ return options.long ? fmtLong(val) : fmtShort(val);
37304
+ }
37305
+ throw new Error("val is not a non-empty string or a valid number. val=" + JSON.stringify(val));
37306
+ };
37307
+ function parse(str) {
37308
+ str = String(str);
37309
+ if (str.length > 100) {
37310
+ return;
37311
+ }
37312
+ var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(str);
37313
+ if (!match) {
37314
+ return;
37315
+ }
37316
+ var n2 = parseFloat(match[1]);
37317
+ var type2 = (match[2] || "ms").toLowerCase();
37318
+ switch (type2) {
37319
+ case "years":
37320
+ case "year":
37321
+ case "yrs":
37322
+ case "yr":
37323
+ case "y":
37324
+ return n2 * y;
37325
+ case "days":
37326
+ case "day":
37327
+ case "d":
37328
+ return n2 * d;
37329
+ case "hours":
37330
+ case "hour":
37331
+ case "hrs":
37332
+ case "hr":
37333
+ case "h":
37334
+ return n2 * h;
37335
+ case "minutes":
37336
+ case "minute":
37337
+ case "mins":
37338
+ case "min":
37339
+ case "m":
37340
+ return n2 * m;
37341
+ case "seconds":
37342
+ case "second":
37343
+ case "secs":
37344
+ case "sec":
37345
+ case "s":
37346
+ return n2 * s;
37347
+ case "milliseconds":
37348
+ case "millisecond":
37349
+ case "msecs":
37350
+ case "msec":
37351
+ case "ms":
37352
+ return n2;
37353
+ default:
37354
+ return;
37355
+ }
37356
+ }
37357
+ function fmtShort(ms) {
37358
+ if (ms >= d) {
37359
+ return Math.round(ms / d) + "d";
37360
+ }
37361
+ if (ms >= h) {
37362
+ return Math.round(ms / h) + "h";
37363
+ }
37364
+ if (ms >= m) {
37365
+ return Math.round(ms / m) + "m";
37366
+ }
37367
+ if (ms >= s) {
37368
+ return Math.round(ms / s) + "s";
37369
+ }
37370
+ return ms + "ms";
37371
+ }
37372
+ function fmtLong(ms) {
37373
+ return plural(ms, d, "day") || plural(ms, h, "hour") || plural(ms, m, "minute") || plural(ms, s, "second") || ms + " ms";
37374
+ }
37375
+ function plural(ms, n2, name) {
37376
+ if (ms < n2) {
37377
+ return;
37378
+ }
37379
+ if (ms < n2 * 1.5) {
37380
+ return Math.floor(ms / n2) + " " + name;
37381
+ }
37382
+ return Math.ceil(ms / n2) + " " + name + "s";
37383
+ }
37384
+ });
37385
+
37386
+ // node_modules/debug/src/debug.js
37291
37387
  var require_debug = __commonJS((exports, module) => {
37388
+ exports = module.exports = createDebug.debug = createDebug["default"] = createDebug;
37389
+ exports.coerce = coerce;
37390
+ exports.disable = disable;
37391
+ exports.enable = enable;
37392
+ exports.enabled = enabled;
37393
+ exports.humanize = require_ms();
37394
+ exports.names = [];
37395
+ exports.skips = [];
37396
+ exports.formatters = {};
37397
+ var prevTime;
37398
+ function selectColor(namespace) {
37399
+ var hash3 = 0, i2;
37400
+ for (i2 in namespace) {
37401
+ hash3 = (hash3 << 5) - hash3 + namespace.charCodeAt(i2);
37402
+ hash3 |= 0;
37403
+ }
37404
+ return exports.colors[Math.abs(hash3) % exports.colors.length];
37405
+ }
37406
+ function createDebug(namespace) {
37407
+ function debug() {
37408
+ if (!debug.enabled)
37409
+ return;
37410
+ var self2 = debug;
37411
+ var curr = +new Date;
37412
+ var ms = curr - (prevTime || curr);
37413
+ self2.diff = ms;
37414
+ self2.prev = prevTime;
37415
+ self2.curr = curr;
37416
+ prevTime = curr;
37417
+ var args = new Array(arguments.length);
37418
+ for (var i2 = 0;i2 < args.length; i2++) {
37419
+ args[i2] = arguments[i2];
37420
+ }
37421
+ args[0] = exports.coerce(args[0]);
37422
+ if (typeof args[0] !== "string") {
37423
+ args.unshift("%O");
37424
+ }
37425
+ var index2 = 0;
37426
+ args[0] = args[0].replace(/%([a-zA-Z%])/g, function(match, format) {
37427
+ if (match === "%%")
37428
+ return match;
37429
+ index2++;
37430
+ var formatter2 = exports.formatters[format];
37431
+ if (typeof formatter2 === "function") {
37432
+ var val = args[index2];
37433
+ match = formatter2.call(self2, val);
37434
+ args.splice(index2, 1);
37435
+ index2--;
37436
+ }
37437
+ return match;
37438
+ });
37439
+ exports.formatArgs.call(self2, args);
37440
+ var logFn = debug.log || exports.log || console.log.bind(console);
37441
+ logFn.apply(self2, args);
37442
+ }
37443
+ debug.namespace = namespace;
37444
+ debug.enabled = exports.enabled(namespace);
37445
+ debug.useColors = exports.useColors();
37446
+ debug.color = selectColor(namespace);
37447
+ if (typeof exports.init === "function") {
37448
+ exports.init(debug);
37449
+ }
37450
+ return debug;
37451
+ }
37452
+ function enable(namespaces) {
37453
+ exports.save(namespaces);
37454
+ exports.names = [];
37455
+ exports.skips = [];
37456
+ var split2 = (typeof namespaces === "string" ? namespaces : "").split(/[\s,]+/);
37457
+ var len = split2.length;
37458
+ for (var i2 = 0;i2 < len; i2++) {
37459
+ if (!split2[i2])
37460
+ continue;
37461
+ namespaces = split2[i2].replace(/\*/g, ".*?");
37462
+ if (namespaces[0] === "-") {
37463
+ exports.skips.push(new RegExp("^" + namespaces.substr(1) + "$"));
37464
+ } else {
37465
+ exports.names.push(new RegExp("^" + namespaces + "$"));
37466
+ }
37467
+ }
37468
+ }
37469
+ function disable() {
37470
+ exports.enable("");
37471
+ }
37472
+ function enabled(name) {
37473
+ var i2, len;
37474
+ for (i2 = 0, len = exports.skips.length;i2 < len; i2++) {
37475
+ if (exports.skips[i2].test(name)) {
37476
+ return false;
37477
+ }
37478
+ }
37479
+ for (i2 = 0, len = exports.names.length;i2 < len; i2++) {
37480
+ if (exports.names[i2].test(name)) {
37481
+ return true;
37482
+ }
37483
+ }
37484
+ return false;
37485
+ }
37486
+ function coerce(val) {
37487
+ if (val instanceof Error)
37488
+ return val.stack || val.message;
37489
+ return val;
37490
+ }
37491
+ });
37492
+
37493
+ // node_modules/debug/src/browser.js
37494
+ var require_browser = __commonJS((exports, module) => {
37495
+ exports = module.exports = require_debug();
37496
+ exports.log = log;
37497
+ exports.formatArgs = formatArgs;
37498
+ exports.save = save;
37499
+ exports.load = load;
37500
+ exports.useColors = useColors;
37501
+ exports.storage = typeof chrome != "undefined" && typeof chrome.storage != "undefined" ? chrome.storage.local : localstorage();
37502
+ exports.colors = [
37503
+ "lightseagreen",
37504
+ "forestgreen",
37505
+ "goldenrod",
37506
+ "dodgerblue",
37507
+ "darkorchid",
37508
+ "crimson"
37509
+ ];
37510
+ function useColors() {
37511
+ if (typeof window !== "undefined" && window.process && window.process.type === "renderer") {
37512
+ return true;
37513
+ }
37514
+ return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31 || typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
37515
+ }
37516
+ exports.formatters.j = function(v) {
37517
+ try {
37518
+ return JSON.stringify(v);
37519
+ } catch (err2) {
37520
+ return "[UnexpectedJSONParseError]: " + err2.message;
37521
+ }
37522
+ };
37523
+ function formatArgs(args) {
37524
+ var useColors2 = this.useColors;
37525
+ args[0] = (useColors2 ? "%c" : "") + this.namespace + (useColors2 ? " %c" : " ") + args[0] + (useColors2 ? "%c " : " ") + "+" + exports.humanize(this.diff);
37526
+ if (!useColors2)
37527
+ return;
37528
+ var c = "color: " + this.color;
37529
+ args.splice(1, 0, c, "color: inherit");
37530
+ var index2 = 0;
37531
+ var lastC = 0;
37532
+ args[0].replace(/%[a-zA-Z%]/g, function(match) {
37533
+ if (match === "%%")
37534
+ return;
37535
+ index2++;
37536
+ if (match === "%c") {
37537
+ lastC = index2;
37538
+ }
37539
+ });
37540
+ args.splice(lastC, 0, c);
37541
+ }
37542
+ function log() {
37543
+ return typeof console === "object" && console.log && Function.prototype.apply.call(console.log, console, arguments);
37544
+ }
37545
+ function save(namespaces) {
37546
+ try {
37547
+ if (namespaces == null) {
37548
+ exports.storage.removeItem("debug");
37549
+ } else {
37550
+ exports.storage.debug = namespaces;
37551
+ }
37552
+ } catch (e) {}
37553
+ }
37554
+ function load() {
37555
+ var r;
37556
+ try {
37557
+ r = exports.storage.debug;
37558
+ } catch (e) {}
37559
+ if (!r && typeof process !== "undefined" && "env" in process) {
37560
+ r = process.env.DEBUG;
37561
+ }
37562
+ return r;
37563
+ }
37564
+ exports.enable(load());
37565
+ function localstorage() {
37566
+ try {
37567
+ return window.localStorage;
37568
+ } catch (e) {}
37569
+ }
37570
+ });
37571
+
37572
+ // node_modules/debug/src/node.js
37573
+ var require_node = __commonJS((exports, module) => {
37574
+ var tty = __require("tty");
37575
+ var util = __require("util");
37576
+ exports = module.exports = require_debug();
37577
+ exports.init = init;
37578
+ exports.log = log;
37579
+ exports.formatArgs = formatArgs;
37580
+ exports.save = save;
37581
+ exports.load = load;
37582
+ exports.useColors = useColors;
37583
+ exports.colors = [6, 2, 3, 4, 5, 1];
37584
+ exports.inspectOpts = Object.keys(process.env).filter(function(key) {
37585
+ return /^debug_/i.test(key);
37586
+ }).reduce(function(obj, key) {
37587
+ var prop3 = key.substring(6).toLowerCase().replace(/_([a-z])/g, function(_, k) {
37588
+ return k.toUpperCase();
37589
+ });
37590
+ var val = process.env[key];
37591
+ if (/^(yes|on|true|enabled)$/i.test(val))
37592
+ val = true;
37593
+ else if (/^(no|off|false|disabled)$/i.test(val))
37594
+ val = false;
37595
+ else if (val === "null")
37596
+ val = null;
37597
+ else
37598
+ val = Number(val);
37599
+ obj[prop3] = val;
37600
+ return obj;
37601
+ }, {});
37602
+ var fd2 = parseInt(process.env.DEBUG_FD, 10) || 2;
37603
+ if (fd2 !== 1 && fd2 !== 2) {
37604
+ util.deprecate(function() {}, "except for stderr(2) and stdout(1), any other usage of DEBUG_FD is deprecated. Override debug.log if you want to use a different log function (https://git.io/debug_fd)")();
37605
+ }
37606
+ var stream = fd2 === 1 ? process.stdout : fd2 === 2 ? process.stderr : createWritableStdioStream(fd2);
37607
+ function useColors() {
37608
+ return "colors" in exports.inspectOpts ? Boolean(exports.inspectOpts.colors) : tty.isatty(fd2);
37609
+ }
37610
+ exports.formatters.o = function(v) {
37611
+ this.inspectOpts.colors = this.useColors;
37612
+ return util.inspect(v, this.inspectOpts).split(`
37613
+ `).map(function(str) {
37614
+ return str.trim();
37615
+ }).join(" ");
37616
+ };
37617
+ exports.formatters.O = function(v) {
37618
+ this.inspectOpts.colors = this.useColors;
37619
+ return util.inspect(v, this.inspectOpts);
37620
+ };
37621
+ function formatArgs(args) {
37622
+ var name = this.namespace;
37623
+ var useColors2 = this.useColors;
37624
+ if (useColors2) {
37625
+ var c = this.color;
37626
+ var prefix = " \x1B[3" + c + ";1m" + name + " " + "\x1B[0m";
37627
+ args[0] = prefix + args[0].split(`
37628
+ `).join(`
37629
+ ` + prefix);
37630
+ args.push("\x1B[3" + c + "m+" + exports.humanize(this.diff) + "\x1B[0m");
37631
+ } else {
37632
+ args[0] = new Date().toUTCString() + " " + name + " " + args[0];
37633
+ }
37634
+ }
37635
+ function log() {
37636
+ return stream.write(util.format.apply(util, arguments) + `
37637
+ `);
37638
+ }
37639
+ function save(namespaces) {
37640
+ if (namespaces == null) {
37641
+ delete process.env.DEBUG;
37642
+ } else {
37643
+ process.env.DEBUG = namespaces;
37644
+ }
37645
+ }
37646
+ function load() {
37647
+ return process.env.DEBUG;
37648
+ }
37649
+ function createWritableStdioStream(fd3) {
37650
+ var stream2;
37651
+ var tty_wrap = process.binding("tty_wrap");
37652
+ switch (tty_wrap.guessHandleType(fd3)) {
37653
+ case "TTY":
37654
+ stream2 = new tty.WriteStream(fd3);
37655
+ stream2._type = "tty";
37656
+ if (stream2._handle && stream2._handle.unref) {
37657
+ stream2._handle.unref();
37658
+ }
37659
+ break;
37660
+ case "FILE":
37661
+ var fs = __require("fs");
37662
+ stream2 = new fs.SyncWriteStream(fd3, { autoClose: false });
37663
+ stream2._type = "fs";
37664
+ break;
37665
+ case "PIPE":
37666
+ case "TCP":
37667
+ var net = __require("net");
37668
+ stream2 = new net.Socket({
37669
+ fd: fd3,
37670
+ readable: false,
37671
+ writable: true
37672
+ });
37673
+ stream2.readable = false;
37674
+ stream2.read = null;
37675
+ stream2._type = "pipe";
37676
+ if (stream2._handle && stream2._handle.unref) {
37677
+ stream2._handle.unref();
37678
+ }
37679
+ break;
37680
+ default:
37681
+ throw new Error("Implement me. Unknown stream file type!");
37682
+ }
37683
+ stream2.fd = fd3;
37684
+ stream2._isStdio = true;
37685
+ return stream2;
37686
+ }
37687
+ function init(debug) {
37688
+ debug.inspectOpts = {};
37689
+ var keys2 = Object.keys(exports.inspectOpts);
37690
+ for (var i2 = 0;i2 < keys2.length; i2++) {
37691
+ debug.inspectOpts[keys2[i2]] = exports.inspectOpts[keys2[i2]];
37692
+ }
37693
+ }
37694
+ exports.enable(load());
37695
+ });
37696
+
37697
+ // node_modules/debug/src/index.js
37698
+ var require_src4 = __commonJS((exports, module) => {
37699
+ if (typeof process !== "undefined" && process.type === "renderer") {
37700
+ module.exports = require_browser();
37701
+ } else {
37702
+ module.exports = require_node();
37703
+ }
37704
+ });
37705
+
37706
+ // node_modules/follow-redirects/debug.js
37707
+ var require_debug2 = __commonJS((exports, module) => {
37292
37708
  var debug;
37293
37709
  module.exports = function() {
37294
37710
  if (!debug) {
37295
37711
  try {
37296
- debug = (()=>{throw new Error("Cannot require module "+"debug");})()("follow-redirects");
37712
+ debug = require_src4()("follow-redirects");
37297
37713
  } catch (error) {}
37298
37714
  if (typeof debug !== "function") {
37299
37715
  debug = function() {};
@@ -37311,7 +37727,7 @@ var require_follow_redirects = __commonJS((exports, module) => {
37311
37727
  var https = __require("https");
37312
37728
  var Writable = __require("stream").Writable;
37313
37729
  var assert4 = __require("assert");
37314
- var debug = require_debug();
37730
+ var debug = require_debug2();
37315
37731
  (function detectUnsupportedEnvironment() {
37316
37732
  var looksLikeNode = typeof process !== "undefined";
37317
37733
  var looksLikeBrowser = typeof window !== "undefined" && typeof document !== "undefined";
@@ -289786,7 +290202,9 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
289786
290202
  const transactionSchema = import_joi2.default.object({
289787
290203
  recipientAddress: import_joi2.default.string().required(),
289788
290204
  amount: import_joi2.default.number().positive().required(),
289789
- transactionHash: import_joi2.default.string().required()
290205
+ transactionHash: import_joi2.default.string().required(),
290206
+ since: import_joi2.default.number(),
290207
+ params: import_joi2.default.object().pattern(import_joi2.default.string(), import_joi2.default.string()).default({})
289790
290208
  });
289791
290209
  const { value, error } = transactionSchema.validate(call.request.payload ?? {});
289792
290210
  if (error) {
@@ -289796,7 +290214,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
289796
290214
  }, null);
289797
290215
  }
289798
290216
  try {
289799
- const deposits = await broker.fetchDeposits(symbol, 50);
290217
+ const deposits = await broker.fetchDeposits(symbol, value.since, 50, { ...value.params ?? {} });
289800
290218
  const deposit = deposits.find((deposit2) => deposit2.id === value.transactionHash || deposit2.txid === value.transactionHash);
289801
290219
  if (deposit) {
289802
290220
  log.info(`Amount ${value.amount} at ${value.transactionHash} . Paid to ${value.recipientAddress}`);
@@ -289819,7 +290237,8 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
289819
290237
  }
289820
290238
  case Action.FetchDepositAddresses: {
289821
290239
  const fetchDepositAddressesSchema = import_joi2.default.object({
289822
- chain: import_joi2.default.string().required()
290240
+ chain: import_joi2.default.string().required(),
290241
+ params: import_joi2.default.object().pattern(import_joi2.default.string(), import_joi2.default.string()).default({})
289823
290242
  });
289824
290243
  const {
289825
290244
  value: fetchDepositAddresses,
@@ -289833,9 +290252,11 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
289833
290252
  }
289834
290253
  try {
289835
290254
  const depositAddresses = broker.has.fetchDepositAddress === true ? await broker.fetchDepositAddress(symbol, {
289836
- network: fetchDepositAddresses.chain
290255
+ network: fetchDepositAddresses.chain,
290256
+ ...fetchDepositAddresses.params ?? {}
289837
290257
  }) : await broker.fetchDepositAddressesByNetwork(symbol, {
289838
- network: fetchDepositAddresses.chain
290258
+ network: fetchDepositAddresses.chain,
290259
+ ...fetchDepositAddresses.params ?? {}
289839
290260
  });
289840
290261
  if (depositAddresses) {
289841
290262
  return callback(null, {
@@ -289860,7 +290281,8 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
289860
290281
  const transferSchema = import_joi2.default.object({
289861
290282
  recipientAddress: import_joi2.default.string().required(),
289862
290283
  amount: import_joi2.default.number().positive().required(),
289863
- chain: import_joi2.default.string().required()
290284
+ chain: import_joi2.default.string().required(),
290285
+ params: import_joi2.default.object().pattern(import_joi2.default.string(), import_joi2.default.string()).default({})
289864
290286
  });
289865
290287
  const { value: transferValue, error: transferError } = transferSchema.validate(call.request.payload ?? {});
289866
290288
  if (transferError) {
@@ -289905,7 +290327,8 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
289905
290327
  amount: import_joi2.default.number().positive().required(),
289906
290328
  fromToken: import_joi2.default.string().required(),
289907
290329
  toToken: import_joi2.default.string().required(),
289908
- price: import_joi2.default.number().positive().required()
290330
+ price: import_joi2.default.number().positive().required(),
290331
+ params: import_joi2.default.object().pattern(import_joi2.default.string(), import_joi2.default.string()).default({})
289909
290332
  });
289910
290333
  const { value: orderValue, error: orderError } = createOrderSchema.validate(call.request.payload ?? {});
289911
290334
  if (orderError) {
@@ -289931,7 +290354,9 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
289931
290354
  message: `Invalid CEX key: ${cex3}. Supported keys: ${Object.keys(brokers).join(", ")}`
289932
290355
  }, null);
289933
290356
  }
289934
- const order = await broker.createOrder(symbol2, orderValue.orderType, from === orderValue.fromToken ? "sell" : "buy", Number(orderValue.amount), Number(orderValue.price));
290357
+ const order = await broker.createOrder(symbol2, orderValue.orderType, from === orderValue.fromToken ? "sell" : "buy", Number(orderValue.amount), Number(orderValue.price), {
290358
+ ...orderValue.params
290359
+ });
289935
290360
  callback(null, { result: JSON.stringify({ ...order }) });
289936
290361
  } catch (error) {
289937
290362
  log.error({ error });
@@ -289944,7 +290369,8 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
289944
290369
  }
289945
290370
  case Action.GetOrderDetails: {
289946
290371
  const getOrderSchema = import_joi2.default.object({
289947
- orderId: import_joi2.default.string().required()
290372
+ orderId: import_joi2.default.string().required(),
290373
+ params: import_joi2.default.object().pattern(import_joi2.default.string(), import_joi2.default.string()).default({})
289948
290374
  });
289949
290375
  const { value: getOrderValue, error: getOrderError } = getOrderSchema.validate(call.request.payload ?? {});
289950
290376
  if (getOrderError) {
@@ -289960,7 +290386,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
289960
290386
  message: `Invalid CEX key: ${cex3}. Supported keys: ${Object.keys(brokers).join(", ")}`
289961
290387
  }, null);
289962
290388
  }
289963
- const orderDetails = await broker.fetchOrder(getOrderValue.orderId);
290389
+ const orderDetails = await broker.fetchOrder(getOrderValue.orderId, { ...getOrderValue.params });
289964
290390
  callback(null, {
289965
290391
  result: JSON.stringify({
289966
290392
  orderId: orderDetails.id,
@@ -289983,7 +290409,8 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
289983
290409
  }
289984
290410
  case Action.CancelOrder: {
289985
290411
  const cancelOrderSchema = import_joi2.default.object({
289986
- orderId: import_joi2.default.string().required()
290412
+ orderId: import_joi2.default.string().required(),
290413
+ params: import_joi2.default.object().pattern(import_joi2.default.string(), import_joi2.default.string()).default({})
289987
290414
  });
289988
290415
  const { value: cancelOrderValue, error: cancelOrderError } = cancelOrderSchema.validate(call.request.payload ?? {});
289989
290416
  if (cancelOrderError) {
@@ -289992,7 +290419,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
289992
290419
  message: `ValidationError: ${cancelOrderError.message}`
289993
290420
  }, null);
289994
290421
  }
289995
- const cancelledOrder = await broker.cancelOrder(cancelOrderValue.orderId);
290422
+ const cancelledOrder = await broker.cancelOrder(cancelOrderValue.orderId, cancelOrderValue.params ?? {});
289996
290423
  callback(null, {
289997
290424
  result: JSON.stringify({ ...cancelledOrder })
289998
290425
  });
@@ -290000,7 +290427,9 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
290000
290427
  }
290001
290428
  case Action.FetchBalance:
290002
290429
  try {
290003
- const balance = await broker.fetchFreeBalance();
290430
+ const balance = await broker.fetchFreeBalance({
290431
+ ...call.request.payload ?? {}
290432
+ });
290004
290433
  const currencyBalance = balance[symbol];
290005
290434
  callback(null, {
290006
290435
  result: useVerity ? broker.last_proof : JSON.stringify({
@@ -0,0 +1,40 @@
1
+ import { type ExchangeCredentials, type PolicyConfig } from "./types";
2
+ export default class CEXBroker {
3
+ #private;
4
+ port: number;
5
+ private policy;
6
+ private brokers;
7
+ private whitelistIps;
8
+ private server;
9
+ private useVerity;
10
+ /**
11
+ * Loads environment variables prefixed with CEX_BROKER_
12
+ * Expected format:
13
+ * CEX_BROKER_<BROKER_NAME>_API_KEY
14
+ * CEX_BROKER_<BROKER_NAME>_API_SECRET
15
+ */
16
+ loadEnvConfig(): void;
17
+ /**
18
+ * Validates an exchange credential object structure.
19
+ */
20
+ loadExchangeCredentials(creds: unknown): asserts creds is ExchangeCredentials;
21
+ constructor(apiCredentials: ExchangeCredentials, policies: string | PolicyConfig, config?: {
22
+ port?: number;
23
+ whitelistIps?: string[];
24
+ useVerity?: boolean;
25
+ verityProverUrl?: string;
26
+ });
27
+ /**
28
+ * Watches the policy JSON file for changes, reloads policies, and reruns broker.
29
+ * @param filePath
30
+ */
31
+ private watchPolicyFile;
32
+ /**
33
+ * Stops Server and Stop watching the policy file, if applicable.
34
+ */
35
+ stop(): void;
36
+ /**
37
+ * Starts the broker, applying policies then running appropriate tasks.
38
+ */
39
+ run(): Promise<CEXBroker>;
40
+ }
package/dist/index.js CHANGED
@@ -35192,13 +35192,429 @@ var require_proxy_from_env = __commonJS((exports) => {
35192
35192
  exports.getProxyForUrl = getProxyForUrl;
35193
35193
  });
35194
35194
 
35195
- // node_modules/follow-redirects/debug.js
35195
+ // node_modules/ms/index.js
35196
+ var require_ms = __commonJS((exports, module) => {
35197
+ var s = 1000;
35198
+ var m = s * 60;
35199
+ var h = m * 60;
35200
+ var d = h * 24;
35201
+ var y = d * 365.25;
35202
+ module.exports = function(val, options) {
35203
+ options = options || {};
35204
+ var type2 = typeof val;
35205
+ if (type2 === "string" && val.length > 0) {
35206
+ return parse(val);
35207
+ } else if (type2 === "number" && isNaN(val) === false) {
35208
+ return options.long ? fmtLong(val) : fmtShort(val);
35209
+ }
35210
+ throw new Error("val is not a non-empty string or a valid number. val=" + JSON.stringify(val));
35211
+ };
35212
+ function parse(str) {
35213
+ str = String(str);
35214
+ if (str.length > 100) {
35215
+ return;
35216
+ }
35217
+ var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(str);
35218
+ if (!match) {
35219
+ return;
35220
+ }
35221
+ var n2 = parseFloat(match[1]);
35222
+ var type2 = (match[2] || "ms").toLowerCase();
35223
+ switch (type2) {
35224
+ case "years":
35225
+ case "year":
35226
+ case "yrs":
35227
+ case "yr":
35228
+ case "y":
35229
+ return n2 * y;
35230
+ case "days":
35231
+ case "day":
35232
+ case "d":
35233
+ return n2 * d;
35234
+ case "hours":
35235
+ case "hour":
35236
+ case "hrs":
35237
+ case "hr":
35238
+ case "h":
35239
+ return n2 * h;
35240
+ case "minutes":
35241
+ case "minute":
35242
+ case "mins":
35243
+ case "min":
35244
+ case "m":
35245
+ return n2 * m;
35246
+ case "seconds":
35247
+ case "second":
35248
+ case "secs":
35249
+ case "sec":
35250
+ case "s":
35251
+ return n2 * s;
35252
+ case "milliseconds":
35253
+ case "millisecond":
35254
+ case "msecs":
35255
+ case "msec":
35256
+ case "ms":
35257
+ return n2;
35258
+ default:
35259
+ return;
35260
+ }
35261
+ }
35262
+ function fmtShort(ms) {
35263
+ if (ms >= d) {
35264
+ return Math.round(ms / d) + "d";
35265
+ }
35266
+ if (ms >= h) {
35267
+ return Math.round(ms / h) + "h";
35268
+ }
35269
+ if (ms >= m) {
35270
+ return Math.round(ms / m) + "m";
35271
+ }
35272
+ if (ms >= s) {
35273
+ return Math.round(ms / s) + "s";
35274
+ }
35275
+ return ms + "ms";
35276
+ }
35277
+ function fmtLong(ms) {
35278
+ return plural(ms, d, "day") || plural(ms, h, "hour") || plural(ms, m, "minute") || plural(ms, s, "second") || ms + " ms";
35279
+ }
35280
+ function plural(ms, n2, name) {
35281
+ if (ms < n2) {
35282
+ return;
35283
+ }
35284
+ if (ms < n2 * 1.5) {
35285
+ return Math.floor(ms / n2) + " " + name;
35286
+ }
35287
+ return Math.ceil(ms / n2) + " " + name + "s";
35288
+ }
35289
+ });
35290
+
35291
+ // node_modules/debug/src/debug.js
35196
35292
  var require_debug = __commonJS((exports, module) => {
35293
+ exports = module.exports = createDebug.debug = createDebug["default"] = createDebug;
35294
+ exports.coerce = coerce;
35295
+ exports.disable = disable;
35296
+ exports.enable = enable;
35297
+ exports.enabled = enabled;
35298
+ exports.humanize = require_ms();
35299
+ exports.names = [];
35300
+ exports.skips = [];
35301
+ exports.formatters = {};
35302
+ var prevTime;
35303
+ function selectColor(namespace) {
35304
+ var hash3 = 0, i2;
35305
+ for (i2 in namespace) {
35306
+ hash3 = (hash3 << 5) - hash3 + namespace.charCodeAt(i2);
35307
+ hash3 |= 0;
35308
+ }
35309
+ return exports.colors[Math.abs(hash3) % exports.colors.length];
35310
+ }
35311
+ function createDebug(namespace) {
35312
+ function debug() {
35313
+ if (!debug.enabled)
35314
+ return;
35315
+ var self2 = debug;
35316
+ var curr = +new Date;
35317
+ var ms = curr - (prevTime || curr);
35318
+ self2.diff = ms;
35319
+ self2.prev = prevTime;
35320
+ self2.curr = curr;
35321
+ prevTime = curr;
35322
+ var args = new Array(arguments.length);
35323
+ for (var i2 = 0;i2 < args.length; i2++) {
35324
+ args[i2] = arguments[i2];
35325
+ }
35326
+ args[0] = exports.coerce(args[0]);
35327
+ if (typeof args[0] !== "string") {
35328
+ args.unshift("%O");
35329
+ }
35330
+ var index2 = 0;
35331
+ args[0] = args[0].replace(/%([a-zA-Z%])/g, function(match, format) {
35332
+ if (match === "%%")
35333
+ return match;
35334
+ index2++;
35335
+ var formatter2 = exports.formatters[format];
35336
+ if (typeof formatter2 === "function") {
35337
+ var val = args[index2];
35338
+ match = formatter2.call(self2, val);
35339
+ args.splice(index2, 1);
35340
+ index2--;
35341
+ }
35342
+ return match;
35343
+ });
35344
+ exports.formatArgs.call(self2, args);
35345
+ var logFn = debug.log || exports.log || console.log.bind(console);
35346
+ logFn.apply(self2, args);
35347
+ }
35348
+ debug.namespace = namespace;
35349
+ debug.enabled = exports.enabled(namespace);
35350
+ debug.useColors = exports.useColors();
35351
+ debug.color = selectColor(namespace);
35352
+ if (typeof exports.init === "function") {
35353
+ exports.init(debug);
35354
+ }
35355
+ return debug;
35356
+ }
35357
+ function enable(namespaces) {
35358
+ exports.save(namespaces);
35359
+ exports.names = [];
35360
+ exports.skips = [];
35361
+ var split2 = (typeof namespaces === "string" ? namespaces : "").split(/[\s,]+/);
35362
+ var len = split2.length;
35363
+ for (var i2 = 0;i2 < len; i2++) {
35364
+ if (!split2[i2])
35365
+ continue;
35366
+ namespaces = split2[i2].replace(/\*/g, ".*?");
35367
+ if (namespaces[0] === "-") {
35368
+ exports.skips.push(new RegExp("^" + namespaces.substr(1) + "$"));
35369
+ } else {
35370
+ exports.names.push(new RegExp("^" + namespaces + "$"));
35371
+ }
35372
+ }
35373
+ }
35374
+ function disable() {
35375
+ exports.enable("");
35376
+ }
35377
+ function enabled(name) {
35378
+ var i2, len;
35379
+ for (i2 = 0, len = exports.skips.length;i2 < len; i2++) {
35380
+ if (exports.skips[i2].test(name)) {
35381
+ return false;
35382
+ }
35383
+ }
35384
+ for (i2 = 0, len = exports.names.length;i2 < len; i2++) {
35385
+ if (exports.names[i2].test(name)) {
35386
+ return true;
35387
+ }
35388
+ }
35389
+ return false;
35390
+ }
35391
+ function coerce(val) {
35392
+ if (val instanceof Error)
35393
+ return val.stack || val.message;
35394
+ return val;
35395
+ }
35396
+ });
35397
+
35398
+ // node_modules/debug/src/browser.js
35399
+ var require_browser = __commonJS((exports, module) => {
35400
+ exports = module.exports = require_debug();
35401
+ exports.log = log;
35402
+ exports.formatArgs = formatArgs;
35403
+ exports.save = save;
35404
+ exports.load = load;
35405
+ exports.useColors = useColors;
35406
+ exports.storage = typeof chrome != "undefined" && typeof chrome.storage != "undefined" ? chrome.storage.local : localstorage();
35407
+ exports.colors = [
35408
+ "lightseagreen",
35409
+ "forestgreen",
35410
+ "goldenrod",
35411
+ "dodgerblue",
35412
+ "darkorchid",
35413
+ "crimson"
35414
+ ];
35415
+ function useColors() {
35416
+ if (typeof window !== "undefined" && window.process && window.process.type === "renderer") {
35417
+ return true;
35418
+ }
35419
+ return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31 || typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
35420
+ }
35421
+ exports.formatters.j = function(v) {
35422
+ try {
35423
+ return JSON.stringify(v);
35424
+ } catch (err2) {
35425
+ return "[UnexpectedJSONParseError]: " + err2.message;
35426
+ }
35427
+ };
35428
+ function formatArgs(args) {
35429
+ var useColors2 = this.useColors;
35430
+ args[0] = (useColors2 ? "%c" : "") + this.namespace + (useColors2 ? " %c" : " ") + args[0] + (useColors2 ? "%c " : " ") + "+" + exports.humanize(this.diff);
35431
+ if (!useColors2)
35432
+ return;
35433
+ var c = "color: " + this.color;
35434
+ args.splice(1, 0, c, "color: inherit");
35435
+ var index2 = 0;
35436
+ var lastC = 0;
35437
+ args[0].replace(/%[a-zA-Z%]/g, function(match) {
35438
+ if (match === "%%")
35439
+ return;
35440
+ index2++;
35441
+ if (match === "%c") {
35442
+ lastC = index2;
35443
+ }
35444
+ });
35445
+ args.splice(lastC, 0, c);
35446
+ }
35447
+ function log() {
35448
+ return typeof console === "object" && console.log && Function.prototype.apply.call(console.log, console, arguments);
35449
+ }
35450
+ function save(namespaces) {
35451
+ try {
35452
+ if (namespaces == null) {
35453
+ exports.storage.removeItem("debug");
35454
+ } else {
35455
+ exports.storage.debug = namespaces;
35456
+ }
35457
+ } catch (e) {}
35458
+ }
35459
+ function load() {
35460
+ var r;
35461
+ try {
35462
+ r = exports.storage.debug;
35463
+ } catch (e) {}
35464
+ if (!r && typeof process !== "undefined" && "env" in process) {
35465
+ r = process.env.DEBUG;
35466
+ }
35467
+ return r;
35468
+ }
35469
+ exports.enable(load());
35470
+ function localstorage() {
35471
+ try {
35472
+ return window.localStorage;
35473
+ } catch (e) {}
35474
+ }
35475
+ });
35476
+
35477
+ // node_modules/debug/src/node.js
35478
+ var require_node = __commonJS((exports, module) => {
35479
+ var tty = __require("tty");
35480
+ var util = __require("util");
35481
+ exports = module.exports = require_debug();
35482
+ exports.init = init;
35483
+ exports.log = log;
35484
+ exports.formatArgs = formatArgs;
35485
+ exports.save = save;
35486
+ exports.load = load;
35487
+ exports.useColors = useColors;
35488
+ exports.colors = [6, 2, 3, 4, 5, 1];
35489
+ exports.inspectOpts = Object.keys(process.env).filter(function(key) {
35490
+ return /^debug_/i.test(key);
35491
+ }).reduce(function(obj, key) {
35492
+ var prop3 = key.substring(6).toLowerCase().replace(/_([a-z])/g, function(_, k) {
35493
+ return k.toUpperCase();
35494
+ });
35495
+ var val = process.env[key];
35496
+ if (/^(yes|on|true|enabled)$/i.test(val))
35497
+ val = true;
35498
+ else if (/^(no|off|false|disabled)$/i.test(val))
35499
+ val = false;
35500
+ else if (val === "null")
35501
+ val = null;
35502
+ else
35503
+ val = Number(val);
35504
+ obj[prop3] = val;
35505
+ return obj;
35506
+ }, {});
35507
+ var fd2 = parseInt(process.env.DEBUG_FD, 10) || 2;
35508
+ if (fd2 !== 1 && fd2 !== 2) {
35509
+ util.deprecate(function() {}, "except for stderr(2) and stdout(1), any other usage of DEBUG_FD is deprecated. Override debug.log if you want to use a different log function (https://git.io/debug_fd)")();
35510
+ }
35511
+ var stream = fd2 === 1 ? process.stdout : fd2 === 2 ? process.stderr : createWritableStdioStream(fd2);
35512
+ function useColors() {
35513
+ return "colors" in exports.inspectOpts ? Boolean(exports.inspectOpts.colors) : tty.isatty(fd2);
35514
+ }
35515
+ exports.formatters.o = function(v) {
35516
+ this.inspectOpts.colors = this.useColors;
35517
+ return util.inspect(v, this.inspectOpts).split(`
35518
+ `).map(function(str) {
35519
+ return str.trim();
35520
+ }).join(" ");
35521
+ };
35522
+ exports.formatters.O = function(v) {
35523
+ this.inspectOpts.colors = this.useColors;
35524
+ return util.inspect(v, this.inspectOpts);
35525
+ };
35526
+ function formatArgs(args) {
35527
+ var name = this.namespace;
35528
+ var useColors2 = this.useColors;
35529
+ if (useColors2) {
35530
+ var c = this.color;
35531
+ var prefix = " \x1B[3" + c + ";1m" + name + " " + "\x1B[0m";
35532
+ args[0] = prefix + args[0].split(`
35533
+ `).join(`
35534
+ ` + prefix);
35535
+ args.push("\x1B[3" + c + "m+" + exports.humanize(this.diff) + "\x1B[0m");
35536
+ } else {
35537
+ args[0] = new Date().toUTCString() + " " + name + " " + args[0];
35538
+ }
35539
+ }
35540
+ function log() {
35541
+ return stream.write(util.format.apply(util, arguments) + `
35542
+ `);
35543
+ }
35544
+ function save(namespaces) {
35545
+ if (namespaces == null) {
35546
+ delete process.env.DEBUG;
35547
+ } else {
35548
+ process.env.DEBUG = namespaces;
35549
+ }
35550
+ }
35551
+ function load() {
35552
+ return process.env.DEBUG;
35553
+ }
35554
+ function createWritableStdioStream(fd3) {
35555
+ var stream2;
35556
+ var tty_wrap = process.binding("tty_wrap");
35557
+ switch (tty_wrap.guessHandleType(fd3)) {
35558
+ case "TTY":
35559
+ stream2 = new tty.WriteStream(fd3);
35560
+ stream2._type = "tty";
35561
+ if (stream2._handle && stream2._handle.unref) {
35562
+ stream2._handle.unref();
35563
+ }
35564
+ break;
35565
+ case "FILE":
35566
+ var fs = __require("fs");
35567
+ stream2 = new fs.SyncWriteStream(fd3, { autoClose: false });
35568
+ stream2._type = "fs";
35569
+ break;
35570
+ case "PIPE":
35571
+ case "TCP":
35572
+ var net = __require("net");
35573
+ stream2 = new net.Socket({
35574
+ fd: fd3,
35575
+ readable: false,
35576
+ writable: true
35577
+ });
35578
+ stream2.readable = false;
35579
+ stream2.read = null;
35580
+ stream2._type = "pipe";
35581
+ if (stream2._handle && stream2._handle.unref) {
35582
+ stream2._handle.unref();
35583
+ }
35584
+ break;
35585
+ default:
35586
+ throw new Error("Implement me. Unknown stream file type!");
35587
+ }
35588
+ stream2.fd = fd3;
35589
+ stream2._isStdio = true;
35590
+ return stream2;
35591
+ }
35592
+ function init(debug) {
35593
+ debug.inspectOpts = {};
35594
+ var keys2 = Object.keys(exports.inspectOpts);
35595
+ for (var i2 = 0;i2 < keys2.length; i2++) {
35596
+ debug.inspectOpts[keys2[i2]] = exports.inspectOpts[keys2[i2]];
35597
+ }
35598
+ }
35599
+ exports.enable(load());
35600
+ });
35601
+
35602
+ // node_modules/debug/src/index.js
35603
+ var require_src4 = __commonJS((exports, module) => {
35604
+ if (typeof process !== "undefined" && process.type === "renderer") {
35605
+ module.exports = require_browser();
35606
+ } else {
35607
+ module.exports = require_node();
35608
+ }
35609
+ });
35610
+
35611
+ // node_modules/follow-redirects/debug.js
35612
+ var require_debug2 = __commonJS((exports, module) => {
35197
35613
  var debug;
35198
35614
  module.exports = function() {
35199
35615
  if (!debug) {
35200
35616
  try {
35201
- debug = (()=>{throw new Error("Cannot require module "+"debug");})()("follow-redirects");
35617
+ debug = require_src4()("follow-redirects");
35202
35618
  } catch (error) {}
35203
35619
  if (typeof debug !== "function") {
35204
35620
  debug = function() {};
@@ -35216,7 +35632,7 @@ var require_follow_redirects = __commonJS((exports, module) => {
35216
35632
  var https = __require("https");
35217
35633
  var Writable = __require("stream").Writable;
35218
35634
  var assert4 = __require("assert");
35219
- var debug = require_debug();
35635
+ var debug = require_debug2();
35220
35636
  (function detectUnsupportedEnvironment() {
35221
35637
  var looksLikeNode = typeof process !== "undefined";
35222
35638
  var looksLikeBrowser = typeof window !== "undefined" && typeof document !== "undefined";
@@ -287675,7 +288091,9 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
287675
288091
  const transactionSchema = import_joi2.default.object({
287676
288092
  recipientAddress: import_joi2.default.string().required(),
287677
288093
  amount: import_joi2.default.number().positive().required(),
287678
- transactionHash: import_joi2.default.string().required()
288094
+ transactionHash: import_joi2.default.string().required(),
288095
+ since: import_joi2.default.number(),
288096
+ params: import_joi2.default.object().pattern(import_joi2.default.string(), import_joi2.default.string()).default({})
287679
288097
  });
287680
288098
  const { value, error } = transactionSchema.validate(call.request.payload ?? {});
287681
288099
  if (error) {
@@ -287685,7 +288103,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
287685
288103
  }, null);
287686
288104
  }
287687
288105
  try {
287688
- const deposits = await broker.fetchDeposits(symbol, 50);
288106
+ const deposits = await broker.fetchDeposits(symbol, value.since, 50, { ...value.params ?? {} });
287689
288107
  const deposit = deposits.find((deposit2) => deposit2.id === value.transactionHash || deposit2.txid === value.transactionHash);
287690
288108
  if (deposit) {
287691
288109
  log.info(`Amount ${value.amount} at ${value.transactionHash} . Paid to ${value.recipientAddress}`);
@@ -287708,7 +288126,8 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
287708
288126
  }
287709
288127
  case Action.FetchDepositAddresses: {
287710
288128
  const fetchDepositAddressesSchema = import_joi2.default.object({
287711
- chain: import_joi2.default.string().required()
288129
+ chain: import_joi2.default.string().required(),
288130
+ params: import_joi2.default.object().pattern(import_joi2.default.string(), import_joi2.default.string()).default({})
287712
288131
  });
287713
288132
  const {
287714
288133
  value: fetchDepositAddresses,
@@ -287722,9 +288141,11 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
287722
288141
  }
287723
288142
  try {
287724
288143
  const depositAddresses = broker.has.fetchDepositAddress === true ? await broker.fetchDepositAddress(symbol, {
287725
- network: fetchDepositAddresses.chain
288144
+ network: fetchDepositAddresses.chain,
288145
+ ...fetchDepositAddresses.params ?? {}
287726
288146
  }) : await broker.fetchDepositAddressesByNetwork(symbol, {
287727
- network: fetchDepositAddresses.chain
288147
+ network: fetchDepositAddresses.chain,
288148
+ ...fetchDepositAddresses.params ?? {}
287728
288149
  });
287729
288150
  if (depositAddresses) {
287730
288151
  return callback(null, {
@@ -287749,7 +288170,8 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
287749
288170
  const transferSchema = import_joi2.default.object({
287750
288171
  recipientAddress: import_joi2.default.string().required(),
287751
288172
  amount: import_joi2.default.number().positive().required(),
287752
- chain: import_joi2.default.string().required()
288173
+ chain: import_joi2.default.string().required(),
288174
+ params: import_joi2.default.object().pattern(import_joi2.default.string(), import_joi2.default.string()).default({})
287753
288175
  });
287754
288176
  const { value: transferValue, error: transferError } = transferSchema.validate(call.request.payload ?? {});
287755
288177
  if (transferError) {
@@ -287794,7 +288216,8 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
287794
288216
  amount: import_joi2.default.number().positive().required(),
287795
288217
  fromToken: import_joi2.default.string().required(),
287796
288218
  toToken: import_joi2.default.string().required(),
287797
- price: import_joi2.default.number().positive().required()
288219
+ price: import_joi2.default.number().positive().required(),
288220
+ params: import_joi2.default.object().pattern(import_joi2.default.string(), import_joi2.default.string()).default({})
287798
288221
  });
287799
288222
  const { value: orderValue, error: orderError } = createOrderSchema.validate(call.request.payload ?? {});
287800
288223
  if (orderError) {
@@ -287820,7 +288243,9 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
287820
288243
  message: `Invalid CEX key: ${cex3}. Supported keys: ${Object.keys(brokers).join(", ")}`
287821
288244
  }, null);
287822
288245
  }
287823
- const order = await broker.createOrder(symbol2, orderValue.orderType, from === orderValue.fromToken ? "sell" : "buy", Number(orderValue.amount), Number(orderValue.price));
288246
+ const order = await broker.createOrder(symbol2, orderValue.orderType, from === orderValue.fromToken ? "sell" : "buy", Number(orderValue.amount), Number(orderValue.price), {
288247
+ ...orderValue.params
288248
+ });
287824
288249
  callback(null, { result: JSON.stringify({ ...order }) });
287825
288250
  } catch (error) {
287826
288251
  log.error({ error });
@@ -287833,7 +288258,8 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
287833
288258
  }
287834
288259
  case Action.GetOrderDetails: {
287835
288260
  const getOrderSchema = import_joi2.default.object({
287836
- orderId: import_joi2.default.string().required()
288261
+ orderId: import_joi2.default.string().required(),
288262
+ params: import_joi2.default.object().pattern(import_joi2.default.string(), import_joi2.default.string()).default({})
287837
288263
  });
287838
288264
  const { value: getOrderValue, error: getOrderError } = getOrderSchema.validate(call.request.payload ?? {});
287839
288265
  if (getOrderError) {
@@ -287849,7 +288275,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
287849
288275
  message: `Invalid CEX key: ${cex3}. Supported keys: ${Object.keys(brokers).join(", ")}`
287850
288276
  }, null);
287851
288277
  }
287852
- const orderDetails = await broker.fetchOrder(getOrderValue.orderId);
288278
+ const orderDetails = await broker.fetchOrder(getOrderValue.orderId, { ...getOrderValue.params });
287853
288279
  callback(null, {
287854
288280
  result: JSON.stringify({
287855
288281
  orderId: orderDetails.id,
@@ -287872,7 +288298,8 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
287872
288298
  }
287873
288299
  case Action.CancelOrder: {
287874
288300
  const cancelOrderSchema = import_joi2.default.object({
287875
- orderId: import_joi2.default.string().required()
288301
+ orderId: import_joi2.default.string().required(),
288302
+ params: import_joi2.default.object().pattern(import_joi2.default.string(), import_joi2.default.string()).default({})
287876
288303
  });
287877
288304
  const { value: cancelOrderValue, error: cancelOrderError } = cancelOrderSchema.validate(call.request.payload ?? {});
287878
288305
  if (cancelOrderError) {
@@ -287881,7 +288308,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
287881
288308
  message: `ValidationError: ${cancelOrderError.message}`
287882
288309
  }, null);
287883
288310
  }
287884
- const cancelledOrder = await broker.cancelOrder(cancelOrderValue.orderId);
288311
+ const cancelledOrder = await broker.cancelOrder(cancelOrderValue.orderId, cancelOrderValue.params ?? {});
287885
288312
  callback(null, {
287886
288313
  result: JSON.stringify({ ...cancelledOrder })
287887
288314
  });
@@ -287889,7 +288316,9 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
287889
288316
  }
287890
288317
  case Action.FetchBalance:
287891
288318
  try {
287892
- const balance = await broker.fetchFreeBalance();
288319
+ const balance = await broker.fetchFreeBalance({
288320
+ ...call.request.payload ?? {}
288321
+ });
287893
288322
  const currencyBalance = balance[symbol];
287894
288323
  callback(null, {
287895
288324
  result: useVerity ? broker.last_proof : JSON.stringify({
@@ -0,0 +1,7 @@
1
+ import type { PolicyConfig } from "./types";
2
+ import * as grpc from "@grpc/grpc-js";
3
+ import type { Exchange } from "@usherlabs/ccxt";
4
+ export declare function getServer(policy: PolicyConfig, brokers: Record<string, {
5
+ primary: Exchange;
6
+ secondaryBrokers: Exchange[];
7
+ }>, whitelistIps: string[], useVerity: boolean, verityProverUrl: string): grpc.Server;
@@ -0,0 +1,66 @@
1
+ import type ccxt from "@usherlabs/ccxt";
2
+ export type WithdrawRule = {
3
+ networks: string[];
4
+ whitelist: string[];
5
+ amounts: {
6
+ ticker: string;
7
+ max: number;
8
+ min: number;
9
+ }[];
10
+ };
11
+ export type OrderRule = {
12
+ markets: string[];
13
+ limits: Array<{
14
+ from: string;
15
+ to: string;
16
+ min: number;
17
+ max: number;
18
+ }>;
19
+ };
20
+ export type PolicyConfig = {
21
+ withdraw: {
22
+ rule: WithdrawRule;
23
+ };
24
+ deposit: Record<string, null>;
25
+ order: {
26
+ rule: OrderRule;
27
+ };
28
+ };
29
+ export type Policy = {
30
+ isActive: boolean;
31
+ permissions: Array<"withdraw" | "transfer" | "convert">;
32
+ limits: {
33
+ dailyWithdrawLimit?: number;
34
+ dailyTransferredAmount?: number;
35
+ perTxTransferLimit?: number;
36
+ };
37
+ networks: string[];
38
+ conversionLimits: Array<{
39
+ from: string;
40
+ to: string;
41
+ min: number;
42
+ max: number;
43
+ }>;
44
+ };
45
+ type BrokerInstanceMap = {
46
+ [K in ISupportedBroker]: InstanceType<(typeof ccxt)[K]>;
47
+ };
48
+ export type BrokerMap = Partial<{
49
+ [K in ISupportedBroker]: BrokerInstanceMap[K];
50
+ }>;
51
+ export declare const BrokerList: readonly ["alpaca", "apex", "ascendex", "bequant", "bigone", "binance", "binancecoinm", "binanceus", "binanceusdm", "bingx", "bit2c", "bitbank", "bitbns", "bitfinex", "bitflyer", "bitget", "bithumb", "bitmart", "bitmex", "bitopro", "bitrue", "bitso", "bitstamp", "bitteam", "bittrade", "bitvavo", "blockchaincom", "blofin", "btcalpha", "btcbox", "btcmarkets", "btcturk", "bybit", "cex", "coinbase", "coinbaseadvanced", "coinbaseexchange", "coinbaseinternational", "coincatch", "coincheck", "coinex", "coinmate", "coinmetro", "coinone", "coinsph", "coinspot", "cryptocom", "cryptomus", "defx", "delta", "deribit", "derive", "digifinex", "ellipx", "exmo", "fmfwio", "gate", "gateio", "gemini", "hashkey", "hitbtc", "hollaex", "htx", "huobi", "hyperliquid", "independentreserve", "indodax", "kraken", "krakenfutures", "kucoin", "kucoinfutures", "latoken", "lbank", "luno", "mercado", "mexc", "modetrade", "myokx", "ndax", "novadax", "oceanex", "okcoin", "okx", "okxus", "onetrading", "oxfun", "p2b", "paradex", "paymium", "phemex", "poloniex", "probit", "timex", "tokocrypto", "tradeogre", "upbit", "vertex", "wavesexchange", "whitebit", "woo", "woofipro", "xt", "yobit", "zaif", "zonda"];
52
+ export type brokers = Required<BrokerMap>;
53
+ export type ISupportedBroker = (typeof BrokerList)[number];
54
+ export type SupportedBrokers = (typeof BrokerList)[number];
55
+ export declare const SupportedBroker: Record<"alpaca" | "apex" | "ascendex" | "bequant" | "bigone" | "binance" | "binancecoinm" | "binanceus" | "binanceusdm" | "bingx" | "bit2c" | "bitbank" | "bitbns" | "bitfinex" | "bitflyer" | "bitget" | "bithumb" | "bitmart" | "bitmex" | "bitopro" | "bitrue" | "bitso" | "bitstamp" | "bitteam" | "bittrade" | "bitvavo" | "blockchaincom" | "blofin" | "btcalpha" | "btcbox" | "btcmarkets" | "btcturk" | "bybit" | "cex" | "coinbase" | "coinbaseadvanced" | "coinbaseexchange" | "coinbaseinternational" | "coincatch" | "coincheck" | "coinex" | "coinmate" | "coinmetro" | "coinone" | "coinsph" | "coinspot" | "cryptocom" | "cryptomus" | "defx" | "delta" | "deribit" | "derive" | "digifinex" | "ellipx" | "exmo" | "fmfwio" | "gate" | "gateio" | "gemini" | "hashkey" | "hitbtc" | "hollaex" | "htx" | "huobi" | "hyperliquid" | "independentreserve" | "indodax" | "kraken" | "krakenfutures" | "kucoin" | "kucoinfutures" | "latoken" | "lbank" | "luno" | "mercado" | "mexc" | "modetrade" | "myokx" | "ndax" | "novadax" | "oceanex" | "okcoin" | "okx" | "okxus" | "onetrading" | "oxfun" | "p2b" | "paradex" | "paymium" | "phemex" | "poloniex" | "probit" | "timex" | "tokocrypto" | "tradeogre" | "upbit" | "vertex" | "wavesexchange" | "whitebit" | "woo" | "woofipro" | "xt" | "yobit" | "zaif" | "zonda", string>;
56
+ export type BrokerCredentials = {
57
+ apiKey: string;
58
+ apiSecret: string;
59
+ };
60
+ export type SecondaryKeys<T> = {
61
+ secondaryKeys: Array<T>;
62
+ };
63
+ export interface ExchangeCredentials {
64
+ [exchange: string]: BrokerCredentials & SecondaryKeys<BrokerCredentials>;
65
+ }
66
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usherlabs/cex-broker",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Unified gRPC API to CEXs by Usher Labs",
5
5
  "repository": "git@gitlab.com:usherlabs/cex-broker.git",
6
6
  "homepage": "https://usher.so/",
@@ -15,6 +15,7 @@
15
15
  "@types/bun": "latest",
16
16
  "bun-plugin-dts": "latest",
17
17
  "bun-types": "latest",
18
+ "cpx": "^1.5.0",
18
19
  "dotenv": "^17.2.0",
19
20
  "husky": "^9.1.7"
20
21
  },
@@ -27,12 +28,15 @@
27
28
  "scripts": {
28
29
  "proto-gen": "./proto-gen.sh",
29
30
  "start": "bun run ./src/index.ts",
31
+ "build": "bun run ./build.ts && bun run build:ts && bun run copy:dts",
32
+ "build:ts": "bunx tsc",
30
33
  "test": "bun test",
31
34
  "format": "bunx biome format --write",
32
35
  "lint": "bunx biome lint",
33
36
  "lint:fix": "bunx biome lint --write",
34
37
  "check": "bunx biome check",
35
38
  "check:fix": "bunx biome check --write",
39
+ "copy:dts": "cpx \"build/src/*.d.ts\" ./dist/",
36
40
  "prepare": "bunx husky",
37
41
  "postinstall": "./proto-gen.sh"
38
42
  },