@proton/wrap-constants 0.0.54 → 0.0.57

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,6 @@
1
1
  import { string, object, array, literal, number, any, nativeEnum, boolean } from 'zod';
2
+ import cloneDeep from 'lodash.clonedeep';
3
+ import { BigNumber } from 'bignumber.js';
2
4
 
3
5
  var _similarChains, _explorerLinkByChain;
4
6
 
@@ -269,7 +271,7 @@ var initializeCoins = function initializeCoins(protonChain) {
269
271
  xtokenPrecision: 4,
270
272
  xtokenContract: 'loan.token',
271
273
  wallets: [],
272
- image: 'https://www.protonchain.com/images/tokens/loan.tokenLOAN.png',
274
+ image: 'https://raw.githubusercontent.com/eoscafe/eos-airdrops/master/logos/loan.png',
273
275
  coingeckoId: 'proton-loan'
274
276
  }, {
275
277
  allowSwap: true,
@@ -942,8 +944,47 @@ function _extends() {
942
944
  return _extends.apply(this, arguments);
943
945
  }
944
946
 
947
+ function _unsupportedIterableToArray(o, minLen) {
948
+ if (!o) return;
949
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
950
+ var n = Object.prototype.toString.call(o).slice(8, -1);
951
+ if (n === "Object" && o.constructor) n = o.constructor.name;
952
+ if (n === "Map" || n === "Set") return Array.from(o);
953
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
954
+ }
955
+
956
+ function _arrayLikeToArray(arr, len) {
957
+ if (len == null || len > arr.length) len = arr.length;
958
+
959
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
960
+
961
+ return arr2;
962
+ }
963
+
964
+ function _createForOfIteratorHelperLoose(o, allowArrayLike) {
965
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
966
+ if (it) return (it = it.call(o)).next.bind(it);
967
+
968
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
969
+ if (it) o = it;
970
+ var i = 0;
971
+ return function () {
972
+ if (i >= o.length) return {
973
+ done: true
974
+ };
975
+ return {
976
+ done: false,
977
+ value: o[i++]
978
+ };
979
+ };
980
+ }
981
+
982
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
983
+ }
984
+
945
985
  var WRAP_CONTRACT = 'proton.wrap';
946
986
  var WRAP_AUTH_ACTION = 'generateauth';
987
+ var FEE_FACTOR = 10000;
947
988
  var initializeConstants = function initializeConstants(chain) {
948
989
  var _initializeCoins = initializeCoins(chain),
949
990
  swapCoins = _initializeCoins.swapCoins,
@@ -956,7 +997,7 @@ var initializeConstants = function initializeConstants(chain) {
956
997
 
957
998
  var constants = {
958
999
  SWAP_CONTRACT: 'proton.swaps',
959
- FEE_FACTOR: 10000,
1000
+ FEE_FACTOR: FEE_FACTOR,
960
1001
  GOOGLE_MAPS_KEY: 'AIzaSyDb2_CrK032kSIqBXbkdwmaLKWELl0SxVs',
961
1002
  SWAP_URL: chain === 'proton' ? 'https://otc.protonswap.com' : 'https://otc-test.protonswap.com',
962
1003
  WRAP_SERVER_URL: chain === 'proton' ? 'https://www.api.bloks.io/proton-wrap-public2' : 'https://www.api.bloks.io/proton-wrap-testnet-public2',
@@ -1224,5 +1265,282 @@ var isSameToken = function isSameToken(token1, token2) {
1224
1265
  return token1.xtokenSymbol === token2.xtokenSymbol && token1.xtokenPrecision === token2.xtokenPrecision && token1.xtokenContract === token2.xtokenContract;
1225
1266
  };
1226
1267
 
1227
- export { Chains, ExtendedAssetParser, Networks, Status, Type, WRAP_AUTH_ACTION, WRAP_CONTRACT, accountParser, addressParser, authorizationParser, authorizationsParser, baseActionParser, baseActionSerializedParser, bloksRatesParser, createAbstractAuthParser, depositBodyParser, exchangeRateParser, exchangeRatesParser, explorerLinkByChain, generateAddressBodyParser, generateAddressResponse, generateAuthParser, initializeCoins, initializeConstants, isSameToken, otcOrderResponseParser, otcQuoteBodyParser, otcQuoteResponseParser, rateParser, similarChains, singleActionTransactionParser, transactionParser, webauthActionParser, withdrawBodyParser, withdrawHistoryMetalResponseParser, withdrawHistoryMetalSwapParser, withdrawMetalResponseParser, withdrawalFeeQuoteParser, wrapParser, wrapSetConfParser, wrapStartParser };
1268
+ var INode = function INode(key, data) {
1269
+ this.key = void 0;
1270
+ this.data = {};
1271
+ this.key = key;
1272
+
1273
+ if (data) {
1274
+ this.data = data;
1275
+ }
1276
+ };
1277
+ var ILink = function ILink(from, to, data) {
1278
+ this.from = void 0;
1279
+ this.to = void 0;
1280
+ this.data = {};
1281
+ this.from = from;
1282
+ this.to = to;
1283
+
1284
+ if (data) {
1285
+ this.data = data;
1286
+ }
1287
+ };
1288
+ var Graph = /*#__PURE__*/function () {
1289
+ function Graph() {
1290
+ this.nodes = [];
1291
+ this.links = [];
1292
+ this.lastPathFound = [];
1293
+
1294
+ this.isEquals = function (a, b) {
1295
+ return a.key === b.key;
1296
+ };
1297
+ }
1298
+
1299
+ var _proto = Graph.prototype;
1300
+
1301
+ _proto.addNode = function addNode(k, v) {
1302
+ var node = this.findNode(k);
1303
+
1304
+ if (!node) {
1305
+ this.nodes.push(new INode(k, v));
1306
+ }
1307
+ };
1308
+
1309
+ _proto.addNodes = function addNodes() {
1310
+ var _this = this;
1311
+
1312
+ for (var _len = arguments.length, nodes = new Array(_len), _key = 0; _key < _len; _key++) {
1313
+ nodes[_key] = arguments[_key];
1314
+ }
1315
+
1316
+ nodes.forEach(function (node) {
1317
+ return typeof node === "string" ? _this.addNode(node) : _this.addNode(node[0], node[1]);
1318
+ });
1319
+ };
1320
+
1321
+ _proto.findNode = function findNode(k) {
1322
+ var _this2 = this;
1323
+
1324
+ var inode = new INode(k);
1325
+ return this.nodes.find(function (node) {
1326
+ return _this2.isEquals(node, inode);
1327
+ });
1328
+ };
1329
+
1330
+ _proto.findNodes = function findNodes() {
1331
+ var _this3 = this;
1332
+
1333
+ for (var _len2 = arguments.length, keys = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
1334
+ keys[_key2] = arguments[_key2];
1335
+ }
1336
+
1337
+ return keys.map(function (k) {
1338
+ return _this3.findNode(k);
1339
+ });
1340
+ };
1341
+
1342
+ _proto.requireFindNodes = function requireFindNodes() {
1343
+ var nodes = this.findNodes.apply(this, arguments);
1344
+
1345
+ if (nodes.some(function (n) {
1346
+ return n === undefined;
1347
+ })) {
1348
+ throw new Error('One of the nodes does not exist');
1349
+ }
1350
+
1351
+ return nodes;
1352
+ };
1353
+
1354
+ _proto.addLink = function addLink(nodeA, nodeB, data) {
1355
+ var _this$requireFindNode = this.requireFindNodes(nodeA, nodeB),
1356
+ inodeA = _this$requireFindNode[0],
1357
+ inodeB = _this$requireFindNode[1];
1358
+
1359
+ this.links.push(new ILink(inodeA, inodeB, data));
1360
+ };
1361
+
1362
+ _proto.addLinks = function addLinks() {
1363
+ var _this4 = this;
1364
+
1365
+ for (var _len3 = arguments.length, links = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
1366
+ links[_key3] = arguments[_key3];
1367
+ }
1368
+
1369
+ links.forEach(function (link) {
1370
+ return _this4.addLink.apply(_this4, link);
1371
+ });
1372
+ }
1373
+ /**
1374
+ * Get all nodes linked
1375
+ * to from `node`.
1376
+ */
1377
+ ;
1378
+
1379
+ _proto.findLinkedNodes = function findLinkedNodes(node) {
1380
+ var _this5 = this;
1381
+
1382
+ return this.links.reduce(function (acc, link) {
1383
+ if (_this5.isEquals(link.from, node)) {
1384
+ acc.push(link.to);
1385
+ }
1386
+
1387
+ return acc;
1388
+ }, []);
1389
+ };
1390
+
1391
+ _proto.findAllPaths = function findAllPaths(from, to) {
1392
+ var _this6 = this;
1393
+
1394
+ var allPaths = [];
1395
+
1396
+ var _this$requireFindNode2 = this.requireFindNodes(from, to),
1397
+ fromNode = _this$requireFindNode2[0],
1398
+ toNode = _this$requireFindNode2[1];
1399
+
1400
+ var path = [fromNode];
1401
+ var seen = new Set();
1402
+
1403
+ var stuck = function stuck(x) {
1404
+ if (_this6.isEquals(x, toNode)) {
1405
+ return false;
1406
+ }
1407
+
1408
+ for (var _iterator = _createForOfIteratorHelperLoose(_this6.findLinkedNodes(x)), _step; !(_step = _iterator()).done;) {
1409
+ var y = _step.value;
1410
+
1411
+ if (!seen.has(y.key)) {
1412
+ seen.add(y.key);
1413
+
1414
+ if (!stuck(y)) {
1415
+ return false;
1416
+ }
1417
+ }
1418
+ }
1419
+
1420
+ return true;
1421
+ };
1422
+
1423
+ var search = function search(x) {
1424
+ if (_this6.isEquals(x, toNode)) {
1425
+ allPaths.push(cloneDeep(path));
1426
+ return;
1427
+ }
1428
+
1429
+ seen = new Set(path.map(function (p) {
1430
+ return p.key;
1431
+ }));
1432
+
1433
+ if (stuck(x)) {
1434
+ return;
1435
+ }
1436
+
1437
+ for (var _iterator2 = _createForOfIteratorHelperLoose(_this6.findLinkedNodes(x)), _step2; !(_step2 = _iterator2()).done;) {
1438
+ var y = _step2.value;
1439
+
1440
+ if (!path.includes(y)) {
1441
+ path.push(y);
1442
+ search(y);
1443
+ path.pop();
1444
+ }
1445
+ }
1446
+ };
1447
+
1448
+ search(fromNode);
1449
+ return allPaths;
1450
+ };
1451
+
1452
+ return Graph;
1453
+ }();
1454
+
1455
+ /**
1456
+ * XPR<>XUSDT (XPR -> XUSDT)
1457
+ *
1458
+ * pool1 * pool2
1459
+ * term = pool2 - --------------
1460
+ * pool1 + swap
1461
+ *
1462
+ * result = term - (term * fee)
1463
+ */
1464
+
1465
+ var compute_transfer = function compute_transfer(pool1, pool2, swap, exchange_fee, precision) {
1466
+ var term1 = pool2;
1467
+ var term2over = pool1.multipliedBy(pool2);
1468
+ var term2under = pool1.plus(swap);
1469
+ var term2 = term2over.dividedBy(term2under).integerValue(BigNumber.ROUND_DOWN);
1470
+ var term = term1.minus(term2);
1471
+ var fee = new BigNumber(exchange_fee).dividedBy(FEE_FACTOR);
1472
+ var result = term.minus(term.multipliedBy(fee));
1473
+ return result.integerValue(BigNumber.ROUND_DOWN).shiftedBy(-precision);
1474
+ };
1475
+ var compute_transfer_curve = function compute_transfer_curve(reserve_in, reserve_out, amount_in, exchange_fee, precision, amplifier) {
1476
+ if (amplifier === 0) {
1477
+ return compute_transfer(new BigNumber(reserve_in), new BigNumber(reserve_out), new BigNumber(amount_in), exchange_fee, precision);
1478
+ }
1479
+
1480
+ var MAX_ITERATIONS = 10;
1481
+ var sum = reserve_in + reserve_out;
1482
+ var D = sum;
1483
+ var D_prev = 0;
1484
+
1485
+ var F = function F(v) {
1486
+ return (v >= 0 ? 1 : -1) * Math.floor(Math.abs(v));
1487
+ };
1488
+
1489
+ var i = MAX_ITERATIONS;
1490
+
1491
+ while (D != D_prev && i--) {
1492
+ var prod1 = F(F(D * D / (reserve_in * 2)) * D / (reserve_out * 2));
1493
+ D_prev = D;
1494
+ D = F(2 * D * (amplifier * sum + prod1) / ((2 * amplifier - 1) * D + 3 * prod1));
1495
+ }
1496
+
1497
+ var b = reserve_in + amount_in + F(D / (amplifier * 2)) - D;
1498
+ var c = F(F(D * D / ((reserve_in + amount_in) * 2)) * D / (amplifier * 4));
1499
+ var x = D,
1500
+ x_prev = 0;
1501
+ i = MAX_ITERATIONS;
1502
+
1503
+ while (x != x_prev && i--) {
1504
+ x_prev = F(x);
1505
+ x = +new BigNumber(x * x + c).dividedBy(2 * x + b).toFixed(0, BigNumber.ROUND_DOWN);
1506
+ }
1507
+
1508
+ if (reserve_out <= x) {
1509
+ throw new Error("curve: insufficient reserve out");
1510
+ } // Fee
1511
+
1512
+
1513
+ var amount_out_with_fee = new BigNumber(reserve_out - x);
1514
+ var fee = amount_out_with_fee.multipliedBy(exchange_fee).dividedBy(FEE_FACTOR).toFixed(0, BigNumber.ROUND_DOWN);
1515
+ var amount_out = amount_out_with_fee.minus(fee);
1516
+ return amount_out.integerValue(BigNumber.ROUND_DOWN).shiftedBy(-precision);
1517
+ };
1518
+ var compute_liquidity = function compute_liquidity(amount_lt, pool, lt_supply, precision) {
1519
+ var over = amount_lt.multipliedBy(pool);
1520
+ var under = lt_supply;
1521
+ var result = over.dividedBy(under).integerValue(BigNumber.ROUND_DOWN);
1522
+ return +result.shiftedBy(-precision).toFixed(precision, BigNumber.ROUND_DOWN);
1523
+ };
1524
+ var isInputInvalid = function isInputInvalid(data, value, pool) {
1525
+ value = String(value);
1526
+ var isBackspace = data === null;
1527
+ var isNumber = !/[0-9]|\./.test(data);
1528
+ var isDoubleDot = data === '.' && value.indexOf('.') !== value.length - 1;
1529
+ var isPrecisionTooHigh = value && value.indexOf('.') !== -1 && value.split('.')[1].length > pool.xtokenPrecision;
1530
+ var isInvalid = !isBackspace && Boolean(isNumber || isDoubleDot || isPrecisionTooHigh);
1531
+ return isInvalid;
1532
+ };
1533
+ var applyDiscountToFee = function applyDiscountToFee(fee, staked) {
1534
+ if (staked >= 10000000) {
1535
+ return fee * 0;
1536
+ } else if (staked >= 1000000) {
1537
+ return fee * 0.33;
1538
+ } else if (staked >= 100000) {
1539
+ return fee * 0.66;
1540
+ } else {
1541
+ return fee;
1542
+ }
1543
+ };
1544
+
1545
+ export { Chains, ExtendedAssetParser, FEE_FACTOR, Graph, ILink, INode, Networks, Status, Type, WRAP_AUTH_ACTION, WRAP_CONTRACT, accountParser, addressParser, applyDiscountToFee, authorizationParser, authorizationsParser, baseActionParser, baseActionSerializedParser, bloksRatesParser, compute_liquidity, compute_transfer, compute_transfer_curve, createAbstractAuthParser, depositBodyParser, exchangeRateParser, exchangeRatesParser, explorerLinkByChain, generateAddressBodyParser, generateAddressResponse, generateAuthParser, initializeCoins, initializeConstants, isInputInvalid, isSameToken, otcOrderResponseParser, otcQuoteBodyParser, otcQuoteResponseParser, rateParser, similarChains, singleActionTransactionParser, transactionParser, webauthActionParser, withdrawBodyParser, withdrawHistoryMetalResponseParser, withdrawHistoryMetalSwapParser, withdrawMetalResponseParser, withdrawalFeeQuoteParser, wrapParser, wrapSetConfParser, wrapStartParser };
1228
1546
  //# sourceMappingURL=wrap-constants.esm.js.map