@fileverse-dev/formulajs 4.4.12-mod-3 → 4.4.12-mod-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.
@@ -1,4 +1,4 @@
1
- /* @fileverse-dev/formulajs v4.4.12-mod-3 */
1
+ /* @fileverse-dev/formulajs v4.4.12-mod-4 */
2
2
  var _excluded = [ "confirmations", "dataDecoded" ];
3
3
 
4
4
  function _objectWithoutProperties(e, t) {
@@ -18333,10 +18333,35 @@ function _typeof(o) {
18333
18333
  })));
18334
18334
  return _TALLY.apply(this, arguments);
18335
18335
  }
18336
- var duneSimParamsSchema = objectType({
18337
- wallet: stringType().nonempty(),
18338
- type: enumType([ "activity" ])
18336
+ var historicalPrices = stringType().regex(/^\s*(\d{1,2})(\s*,\s*\d{1,2}){0,2}\s*$/, "Up to 3 comma-separated hour offsets").refine((function(s) {
18337
+ return s.split(",").map((function(x) {
18338
+ return +x.trim();
18339
+ })).every((function(n) {
18340
+ return n >= 1 && n <= 24;
18341
+ }));
18342
+ }), {
18343
+ message: "Each offset must be between 1 and 24"
18344
+ });
18345
+ var activity = objectType({
18346
+ type: literalType("activity"),
18347
+ input1: stringType().nonempty(),
18348
+ input2: stringType().optional(),
18349
+ input3: numberType()["int"]().min(1).max(100).optional()
18350
+ });
18351
+ var tokenHolders = objectType({
18352
+ type: literalType("token_holders"),
18353
+ input1: stringType().nonempty(),
18354
+ input2: stringType().nonempty(),
18355
+ input3: numberType()["int"]().min(1).max(500).optional()
18356
+ });
18357
+ var price = objectType({
18358
+ type: literalType("price"),
18359
+ input1: stringType().nonempty(),
18360
+ input2: historicalPrices.optional(),
18361
+ input3: stringType().optional(),
18362
+ input4: numberType()["int"]().min(1).max(500).optional()
18339
18363
  });
18364
+ var duneSimParamsSchema = discriminatedUnionType("type", [ activity, price, tokenHolders ]);
18340
18365
  function flattenObject(obj) {
18341
18366
  var parentKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
18342
18367
  var res = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
@@ -18362,29 +18387,75 @@ function _typeof(o) {
18362
18387
  }
18363
18388
  return res;
18364
18389
  }
18390
+ var SUPPORTED_TOKEN_NAMES = {
18391
+ eth: 1,
18392
+ base: 8453,
18393
+ polygon: 137,
18394
+ arbitrum: 42161,
18395
+ optimism: 10,
18396
+ gnosis: 100,
18397
+ bsc: 56,
18398
+ avalanche: 43114,
18399
+ fantom: 250,
18400
+ scroll: 534352,
18401
+ linea: 59144
18402
+ };
18365
18403
  function DUNESIM() {
18366
18404
  return _DUNESIM.apply(this, arguments);
18367
18405
  }
18368
18406
  function _DUNESIM() {
18369
18407
  _DUNESIM = _asyncToGenerator(_regeneratorRuntime().mark((function _callee29() {
18370
- var _argsToArray31, _argsToArray32, type, wallet, address, apiKey, url, _getUrlAndHeaders1, finalUrl, HEADERS, response, json, activity, _args32 = arguments;
18408
+ var _ref26, _json$activity, _ref27, _json$holders, _ref28, _json$tokens, _argsToArray31, _argsToArray32, type, input1, input2, input3, input4, route, buildQuery, address, qs, chain, _qs, _qs2, _chain, apiKey, url, _getUrlAndHeaders1, finalUrl, HEADERS, res, json, _data6, result, _args32 = arguments;
18371
18409
  return _regeneratorRuntime().wrap((function _callee29$(_context32) {
18372
18410
  while (1) switch (_context32.prev = _context32.next) {
18373
18411
  case 0:
18374
18412
  _context32.prev = 0;
18375
- _argsToArray31 = argsToArray(_args32), _argsToArray32 = _slicedToArray(_argsToArray31, 2),
18376
- type = _argsToArray32[0], wallet = _argsToArray32[1];
18413
+ _argsToArray31 = argsToArray(_args32), _argsToArray32 = _slicedToArray(_argsToArray31, 5),
18414
+ type = _argsToArray32[0], input1 = _argsToArray32[1], input2 = _argsToArray32[2],
18415
+ input3 = _argsToArray32[3], input4 = _argsToArray32[4];
18377
18416
  validateParams(duneSimParamsSchema, {
18378
- wallet: wallet,
18379
- type: type
18417
+ type: type,
18418
+ input1: input1,
18419
+ input2: input2,
18420
+ input3: input3,
18421
+ input4: input4
18380
18422
  });
18381
- _context32.next = 5;
18382
- return fromEnsNameToAddress$1.validateAndGetAddress(wallet);
18423
+ route = "";
18424
+ buildQuery = function buildQuery(pairs) {
18425
+ var parts = pairs.filter((function(_ref22) {
18426
+ var _ref23 = _slicedToArray(_ref22, 2), _ = _ref23[0], v = _ref23[1];
18427
+ return v !== undefined && v !== "";
18428
+ })).map((function(_ref24) {
18429
+ var _ref25 = _slicedToArray(_ref24, 2), k = _ref25[0], v = _ref25[1];
18430
+ return "".concat(k, "=").concat(encodeURIComponent(v));
18431
+ }));
18432
+ return parts.length ? "?".concat(parts.join("&")) : "";
18433
+ };
18434
+ if (!(type === "activity")) {
18435
+ _context32.next = 11;
18436
+ break;
18437
+ }
18438
+ _context32.next = 8;
18439
+ return fromEnsNameToAddress$1.validateAndGetAddress(input1);
18383
18440
 
18384
- case 5:
18441
+ case 8:
18385
18442
  address = _context32.sent;
18386
- apiKey = window.localStorage.getItem(SERVICES_API_KEY.DuneSim);
18387
- url = "https://api.sim.dune.com/v1/evm/activity/".concat(address);
18443
+ qs = buildQuery([ [ "chain_ids", SUPPORTED_TOKEN_NAMES[input2] || input2 ], [ "limit", input3 ] ]);
18444
+ route = "activity/".concat(address).concat(qs);
18445
+
18446
+ case 11:
18447
+ if (type === "price") {
18448
+ chain = SUPPORTED_TOKEN_NAMES[input1] || input2;
18449
+ _qs = buildQuery([ [ "chain_ids", chain ], [ "historical_prices", input3 ], [ "limit", input4 ] ]);
18450
+ route = "token-info/native".concat(_qs);
18451
+ }
18452
+ if (type === "token_holders") {
18453
+ _qs2 = buildQuery([ [ "limit", input3 ] ]);
18454
+ _chain = SUPPORTED_TOKEN_NAMES[input2] || input2;
18455
+ route = "token-holders/".concat(_chain, "/").concat(input1).concat(_qs2);
18456
+ }
18457
+ apiKey = "sim_pMrywDRiseEAGd6qOWbyMmwLnnlvC5EA";
18458
+ url = "https://api.sim.dune.com/v1/evm/".concat(route);
18388
18459
  _getUrlAndHeaders1 = getUrlAndHeaders({
18389
18460
  url: url,
18390
18461
  serviceName: "DuneSim",
@@ -18392,41 +18463,45 @@ function _typeof(o) {
18392
18463
  "X-Sim-Api-Key": apiKey
18393
18464
  }
18394
18465
  }), finalUrl = _getUrlAndHeaders1.URL, HEADERS = _getUrlAndHeaders1.HEADERS;
18395
- _context32.next = 11;
18466
+ _context32.next = 18;
18396
18467
  return fetch(finalUrl, {
18397
18468
  method: "GET",
18398
18469
  headers: HEADERS
18399
18470
  });
18400
18471
 
18401
- case 11:
18402
- response = _context32.sent;
18403
- if (response.ok) {
18404
- _context32.next = 14;
18472
+ case 18:
18473
+ res = _context32.sent;
18474
+ if (res.ok) {
18475
+ _context32.next = 21;
18405
18476
  break;
18406
18477
  }
18407
- throw new NetworkError(SERVICES_API_KEY.DuneSim, response.status);
18478
+ throw new NetworkError(SERVICES_API_KEY.DuneSim, res.status);
18408
18479
 
18409
- case 14:
18410
- _context32.next = 16;
18411
- return response.json();
18480
+ case 21:
18481
+ _context32.next = 23;
18482
+ return res.json();
18412
18483
 
18413
- case 16:
18484
+ case 23:
18414
18485
  json = _context32.sent;
18415
- activity = (json === null || json === void 0 ? void 0 : json.activity) || [];
18416
- return _context32.abrupt("return", activity.map((function(item) {
18486
+ _data6 = type === "activity" ? (_ref26 = (_json$activity = json === null || json === void 0 ? void 0 : json.activity) !== null && _json$activity !== void 0 ? _json$activity : json) !== null && _ref26 !== void 0 ? _ref26 : [] : type === "token_holders" ? (_ref27 = (_json$holders = json === null || json === void 0 ? void 0 : json.holders) !== null && _json$holders !== void 0 ? _json$holders : json) !== null && _ref27 !== void 0 ? _ref27 : [] : type === "price" ? (_ref28 = (_json$tokens = json === null || json === void 0 ? void 0 : json.tokens) !== null && _json$tokens !== void 0 ? _json$tokens : json) !== null && _ref28 !== void 0 ? _ref28 : [] : json !== null && json !== void 0 ? json : [];
18487
+ result = _data6.map((function(item) {
18417
18488
  return flattenObject(item);
18418
- })));
18489
+ }));
18490
+ console.log({
18491
+ result: result
18492
+ });
18493
+ return _context32.abrupt("return", result);
18419
18494
 
18420
- case 21:
18421
- _context32.prev = 21;
18495
+ case 30:
18496
+ _context32.prev = 30;
18422
18497
  _context32.t0 = _context32["catch"](0);
18423
18498
  return _context32.abrupt("return", errorMessageHandler(_context32.t0, "DUNESIM"));
18424
18499
 
18425
- case 24:
18500
+ case 33:
18426
18501
  case "end":
18427
18502
  return _context32.stop();
18428
18503
  }
18429
- }), _callee29, null, [ [ 0, 21 ] ]);
18504
+ }), _callee29, null, [ [ 0, 30 ] ]);
18430
18505
  })));
18431
18506
  return _DUNESIM.apply(this, arguments);
18432
18507
  }