@proton/wrap-constants 0.0.56 → 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.
- package/dist/constants.d.ts +1 -0
- package/dist/graph.d.ts +30 -0
- package/dist/index.d.ts +2 -0
- package/dist/math.d.ts +17 -0
- package/dist/parsers/pool.d.ts +6 -11
- package/dist/wrap-constants.cjs.development.js +331 -2
- package/dist/wrap-constants.cjs.development.js.map +1 -1
- package/dist/wrap-constants.cjs.production.min.js +1 -1
- package/dist/wrap-constants.cjs.production.min.js.map +1 -1
- package/dist/wrap-constants.esm.js +321 -3
- package/dist/wrap-constants.esm.js.map +1 -1
- package/package.json +4 -2
- package/src/coins.ts +1 -1
- package/src/constants.ts +2 -1
- package/src/graph.ts +126 -0
- package/src/index.ts +3 -1
- package/src/math.ts +107 -0
- package/src/parsers/pool.ts +7 -6
package/dist/constants.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Coin, CoinWallet } from './coins';
|
|
2
2
|
export declare const WRAP_CONTRACT = "proton.wrap";
|
|
3
3
|
export declare const WRAP_AUTH_ACTION = "generateauth";
|
|
4
|
+
export declare const FEE_FACTOR = 10000;
|
|
4
5
|
export declare const initializeConstants: (chain: string) => {
|
|
5
6
|
SWAP_CONTRACT: string;
|
|
6
7
|
FEE_FACTOR: number;
|
package/dist/graph.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export declare class INode<T> {
|
|
2
|
+
key: string;
|
|
3
|
+
data: T;
|
|
4
|
+
constructor(key: string, data?: T);
|
|
5
|
+
}
|
|
6
|
+
export declare class ILink<T> {
|
|
7
|
+
from: INode<T>;
|
|
8
|
+
to: INode<T>;
|
|
9
|
+
data: T;
|
|
10
|
+
constructor(from: INode<T>, to: INode<T>, data?: T);
|
|
11
|
+
}
|
|
12
|
+
export declare class Graph<T> {
|
|
13
|
+
nodes: INode<T>[];
|
|
14
|
+
links: ILink<T>[];
|
|
15
|
+
lastPathFound: INode<T>[];
|
|
16
|
+
isEquals: (a: INode<T>, b: INode<T>) => boolean;
|
|
17
|
+
addNode(k: string, v?: T): void;
|
|
18
|
+
addNodes(...nodes: (string | [string, T?])[]): void;
|
|
19
|
+
findNode(k: string): INode<T> | undefined;
|
|
20
|
+
findNodes(...keys: string[]): (INode<T> | undefined)[];
|
|
21
|
+
requireFindNodes(...keys: string[]): INode<T>[];
|
|
22
|
+
addLink(nodeA: string, nodeB: string, data?: T): void;
|
|
23
|
+
addLinks(...links: [nodeA: string, nodeB: string, data?: T][]): void;
|
|
24
|
+
/**
|
|
25
|
+
* Get all nodes linked
|
|
26
|
+
* to from `node`.
|
|
27
|
+
*/
|
|
28
|
+
findLinkedNodes(node: INode<T>): INode<T>[];
|
|
29
|
+
findAllPaths(from: string, to: string): INode<T>[][];
|
|
30
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/math.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BigNumber as BN } from 'bignumber.js';
|
|
2
|
+
/**
|
|
3
|
+
* XPR<>XUSDT (XPR -> XUSDT)
|
|
4
|
+
*
|
|
5
|
+
* pool1 * pool2
|
|
6
|
+
* term = pool2 - --------------
|
|
7
|
+
* pool1 + swap
|
|
8
|
+
*
|
|
9
|
+
* result = term - (term * fee)
|
|
10
|
+
*/
|
|
11
|
+
export declare const compute_transfer: (pool1: BN.Instance, pool2: BN.Instance, swap: BN.Instance, exchange_fee: number, precision: number) => BN;
|
|
12
|
+
export declare const compute_transfer_curve: (reserve_in: number, reserve_out: number, amount_in: number, exchange_fee: number, precision: number, amplifier: number) => BN;
|
|
13
|
+
export declare const compute_liquidity: (amount_lt: BN.Instance, pool: BN.Instance, lt_supply: BN.Instance, precision: number) => number;
|
|
14
|
+
export declare const isInputInvalid: (data: string, value: string | number, pool: {
|
|
15
|
+
xtokenPrecision: number;
|
|
16
|
+
}) => boolean;
|
|
17
|
+
export declare const applyDiscountToFee: (fee: number, staked: number) => number;
|
package/dist/parsers/pool.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Coin } from "../coins";
|
|
2
2
|
import { ExtendedAsset } from '@bloks/numbers';
|
|
3
|
+
import { INode } from "../graph";
|
|
3
4
|
export interface RawPool {
|
|
4
5
|
lt_symbol: string;
|
|
5
6
|
creator: string;
|
|
@@ -25,8 +26,8 @@ export interface Pool extends Omit<RawPool, 'pool1' | 'pool2'> {
|
|
|
25
26
|
lt_symbol: string;
|
|
26
27
|
creator: string;
|
|
27
28
|
memo: string;
|
|
28
|
-
pool1:
|
|
29
|
-
pool2:
|
|
29
|
+
pool1: ExtendedTokenWithRate;
|
|
30
|
+
pool2: ExtendedTokenWithRate;
|
|
30
31
|
hash: string;
|
|
31
32
|
fee: {
|
|
32
33
|
exchange_fee: number;
|
|
@@ -42,14 +43,8 @@ export declare type ExtendedTokenWithRate = ExtendedToken & {
|
|
|
42
43
|
rate: number;
|
|
43
44
|
};
|
|
44
45
|
export declare type PoolTable = {
|
|
45
|
-
pool1:
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
pool2: ExtendedToken & {
|
|
49
|
-
rate: number;
|
|
50
|
-
};
|
|
51
|
-
path: {
|
|
52
|
-
data: Pool;
|
|
53
|
-
}[];
|
|
46
|
+
pool1: ExtendedTokenWithRate;
|
|
47
|
+
pool2: ExtendedTokenWithRate;
|
|
48
|
+
path: INode<Pool>[];
|
|
54
49
|
getPathString: () => string;
|
|
55
50
|
} | undefined;
|
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
|
+
|
|
5
7
|
var z = require('zod');
|
|
8
|
+
var cloneDeep = _interopDefault(require('lodash.clonedeep'));
|
|
9
|
+
var bignumber_js = require('bignumber.js');
|
|
6
10
|
|
|
7
11
|
var _similarChains, _explorerLinkByChain;
|
|
8
12
|
|
|
@@ -269,7 +273,7 @@ var initializeCoins = function initializeCoins(protonChain) {
|
|
|
269
273
|
xtokenPrecision: 4,
|
|
270
274
|
xtokenContract: 'loan.token',
|
|
271
275
|
wallets: [],
|
|
272
|
-
image: 'https://
|
|
276
|
+
image: 'https://raw.githubusercontent.com/eoscafe/eos-airdrops/master/logos/loan.png',
|
|
273
277
|
coingeckoId: 'proton-loan'
|
|
274
278
|
}, {
|
|
275
279
|
allowSwap: true,
|
|
@@ -942,8 +946,47 @@ function _extends() {
|
|
|
942
946
|
return _extends.apply(this, arguments);
|
|
943
947
|
}
|
|
944
948
|
|
|
949
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
950
|
+
if (!o) return;
|
|
951
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
952
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
953
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
954
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
955
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
function _arrayLikeToArray(arr, len) {
|
|
959
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
960
|
+
|
|
961
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
962
|
+
|
|
963
|
+
return arr2;
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
|
967
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
968
|
+
if (it) return (it = it.call(o)).next.bind(it);
|
|
969
|
+
|
|
970
|
+
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
971
|
+
if (it) o = it;
|
|
972
|
+
var i = 0;
|
|
973
|
+
return function () {
|
|
974
|
+
if (i >= o.length) return {
|
|
975
|
+
done: true
|
|
976
|
+
};
|
|
977
|
+
return {
|
|
978
|
+
done: false,
|
|
979
|
+
value: o[i++]
|
|
980
|
+
};
|
|
981
|
+
};
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
985
|
+
}
|
|
986
|
+
|
|
945
987
|
var WRAP_CONTRACT = 'proton.wrap';
|
|
946
988
|
var WRAP_AUTH_ACTION = 'generateauth';
|
|
989
|
+
var FEE_FACTOR = 10000;
|
|
947
990
|
var initializeConstants = function initializeConstants(chain) {
|
|
948
991
|
var _initializeCoins = initializeCoins(chain),
|
|
949
992
|
swapCoins = _initializeCoins.swapCoins,
|
|
@@ -956,7 +999,7 @@ var initializeConstants = function initializeConstants(chain) {
|
|
|
956
999
|
|
|
957
1000
|
var constants = {
|
|
958
1001
|
SWAP_CONTRACT: 'proton.swaps',
|
|
959
|
-
FEE_FACTOR:
|
|
1002
|
+
FEE_FACTOR: FEE_FACTOR,
|
|
960
1003
|
GOOGLE_MAPS_KEY: 'AIzaSyDb2_CrK032kSIqBXbkdwmaLKWELl0SxVs',
|
|
961
1004
|
SWAP_URL: chain === 'proton' ? 'https://otc.protonswap.com' : 'https://otc-test.protonswap.com',
|
|
962
1005
|
WRAP_SERVER_URL: chain === 'proton' ? 'https://www.api.bloks.io/proton-wrap-public2' : 'https://www.api.bloks.io/proton-wrap-testnet-public2',
|
|
@@ -1220,16 +1263,301 @@ var isSameToken = function isSameToken(token1, token2) {
|
|
|
1220
1263
|
return token1.xtokenSymbol === token2.xtokenSymbol && token1.xtokenPrecision === token2.xtokenPrecision && token1.xtokenContract === token2.xtokenContract;
|
|
1221
1264
|
};
|
|
1222
1265
|
|
|
1266
|
+
var INode = function INode(key, data) {
|
|
1267
|
+
this.key = void 0;
|
|
1268
|
+
this.data = {};
|
|
1269
|
+
this.key = key;
|
|
1270
|
+
|
|
1271
|
+
if (data) {
|
|
1272
|
+
this.data = data;
|
|
1273
|
+
}
|
|
1274
|
+
};
|
|
1275
|
+
var ILink = function ILink(from, to, data) {
|
|
1276
|
+
this.from = void 0;
|
|
1277
|
+
this.to = void 0;
|
|
1278
|
+
this.data = {};
|
|
1279
|
+
this.from = from;
|
|
1280
|
+
this.to = to;
|
|
1281
|
+
|
|
1282
|
+
if (data) {
|
|
1283
|
+
this.data = data;
|
|
1284
|
+
}
|
|
1285
|
+
};
|
|
1286
|
+
var Graph = /*#__PURE__*/function () {
|
|
1287
|
+
function Graph() {
|
|
1288
|
+
this.nodes = [];
|
|
1289
|
+
this.links = [];
|
|
1290
|
+
this.lastPathFound = [];
|
|
1291
|
+
|
|
1292
|
+
this.isEquals = function (a, b) {
|
|
1293
|
+
return a.key === b.key;
|
|
1294
|
+
};
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
var _proto = Graph.prototype;
|
|
1298
|
+
|
|
1299
|
+
_proto.addNode = function addNode(k, v) {
|
|
1300
|
+
var node = this.findNode(k);
|
|
1301
|
+
|
|
1302
|
+
if (!node) {
|
|
1303
|
+
this.nodes.push(new INode(k, v));
|
|
1304
|
+
}
|
|
1305
|
+
};
|
|
1306
|
+
|
|
1307
|
+
_proto.addNodes = function addNodes() {
|
|
1308
|
+
var _this = this;
|
|
1309
|
+
|
|
1310
|
+
for (var _len = arguments.length, nodes = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1311
|
+
nodes[_key] = arguments[_key];
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
nodes.forEach(function (node) {
|
|
1315
|
+
return typeof node === "string" ? _this.addNode(node) : _this.addNode(node[0], node[1]);
|
|
1316
|
+
});
|
|
1317
|
+
};
|
|
1318
|
+
|
|
1319
|
+
_proto.findNode = function findNode(k) {
|
|
1320
|
+
var _this2 = this;
|
|
1321
|
+
|
|
1322
|
+
var inode = new INode(k);
|
|
1323
|
+
return this.nodes.find(function (node) {
|
|
1324
|
+
return _this2.isEquals(node, inode);
|
|
1325
|
+
});
|
|
1326
|
+
};
|
|
1327
|
+
|
|
1328
|
+
_proto.findNodes = function findNodes() {
|
|
1329
|
+
var _this3 = this;
|
|
1330
|
+
|
|
1331
|
+
for (var _len2 = arguments.length, keys = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
1332
|
+
keys[_key2] = arguments[_key2];
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
return keys.map(function (k) {
|
|
1336
|
+
return _this3.findNode(k);
|
|
1337
|
+
});
|
|
1338
|
+
};
|
|
1339
|
+
|
|
1340
|
+
_proto.requireFindNodes = function requireFindNodes() {
|
|
1341
|
+
var nodes = this.findNodes.apply(this, arguments);
|
|
1342
|
+
|
|
1343
|
+
if (nodes.some(function (n) {
|
|
1344
|
+
return n === undefined;
|
|
1345
|
+
})) {
|
|
1346
|
+
throw new Error('One of the nodes does not exist');
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
return nodes;
|
|
1350
|
+
};
|
|
1351
|
+
|
|
1352
|
+
_proto.addLink = function addLink(nodeA, nodeB, data) {
|
|
1353
|
+
var _this$requireFindNode = this.requireFindNodes(nodeA, nodeB),
|
|
1354
|
+
inodeA = _this$requireFindNode[0],
|
|
1355
|
+
inodeB = _this$requireFindNode[1];
|
|
1356
|
+
|
|
1357
|
+
this.links.push(new ILink(inodeA, inodeB, data));
|
|
1358
|
+
};
|
|
1359
|
+
|
|
1360
|
+
_proto.addLinks = function addLinks() {
|
|
1361
|
+
var _this4 = this;
|
|
1362
|
+
|
|
1363
|
+
for (var _len3 = arguments.length, links = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
1364
|
+
links[_key3] = arguments[_key3];
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1367
|
+
links.forEach(function (link) {
|
|
1368
|
+
return _this4.addLink.apply(_this4, link);
|
|
1369
|
+
});
|
|
1370
|
+
}
|
|
1371
|
+
/**
|
|
1372
|
+
* Get all nodes linked
|
|
1373
|
+
* to from `node`.
|
|
1374
|
+
*/
|
|
1375
|
+
;
|
|
1376
|
+
|
|
1377
|
+
_proto.findLinkedNodes = function findLinkedNodes(node) {
|
|
1378
|
+
var _this5 = this;
|
|
1379
|
+
|
|
1380
|
+
return this.links.reduce(function (acc, link) {
|
|
1381
|
+
if (_this5.isEquals(link.from, node)) {
|
|
1382
|
+
acc.push(link.to);
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
return acc;
|
|
1386
|
+
}, []);
|
|
1387
|
+
};
|
|
1388
|
+
|
|
1389
|
+
_proto.findAllPaths = function findAllPaths(from, to) {
|
|
1390
|
+
var _this6 = this;
|
|
1391
|
+
|
|
1392
|
+
var allPaths = [];
|
|
1393
|
+
|
|
1394
|
+
var _this$requireFindNode2 = this.requireFindNodes(from, to),
|
|
1395
|
+
fromNode = _this$requireFindNode2[0],
|
|
1396
|
+
toNode = _this$requireFindNode2[1];
|
|
1397
|
+
|
|
1398
|
+
var path = [fromNode];
|
|
1399
|
+
var seen = new Set();
|
|
1400
|
+
|
|
1401
|
+
var stuck = function stuck(x) {
|
|
1402
|
+
if (_this6.isEquals(x, toNode)) {
|
|
1403
|
+
return false;
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
for (var _iterator = _createForOfIteratorHelperLoose(_this6.findLinkedNodes(x)), _step; !(_step = _iterator()).done;) {
|
|
1407
|
+
var y = _step.value;
|
|
1408
|
+
|
|
1409
|
+
if (!seen.has(y.key)) {
|
|
1410
|
+
seen.add(y.key);
|
|
1411
|
+
|
|
1412
|
+
if (!stuck(y)) {
|
|
1413
|
+
return false;
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
return true;
|
|
1419
|
+
};
|
|
1420
|
+
|
|
1421
|
+
var search = function search(x) {
|
|
1422
|
+
if (_this6.isEquals(x, toNode)) {
|
|
1423
|
+
allPaths.push(cloneDeep(path));
|
|
1424
|
+
return;
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
seen = new Set(path.map(function (p) {
|
|
1428
|
+
return p.key;
|
|
1429
|
+
}));
|
|
1430
|
+
|
|
1431
|
+
if (stuck(x)) {
|
|
1432
|
+
return;
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
for (var _iterator2 = _createForOfIteratorHelperLoose(_this6.findLinkedNodes(x)), _step2; !(_step2 = _iterator2()).done;) {
|
|
1436
|
+
var y = _step2.value;
|
|
1437
|
+
|
|
1438
|
+
if (!path.includes(y)) {
|
|
1439
|
+
path.push(y);
|
|
1440
|
+
search(y);
|
|
1441
|
+
path.pop();
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
};
|
|
1445
|
+
|
|
1446
|
+
search(fromNode);
|
|
1447
|
+
return allPaths;
|
|
1448
|
+
};
|
|
1449
|
+
|
|
1450
|
+
return Graph;
|
|
1451
|
+
}();
|
|
1452
|
+
|
|
1453
|
+
/**
|
|
1454
|
+
* XPR<>XUSDT (XPR -> XUSDT)
|
|
1455
|
+
*
|
|
1456
|
+
* pool1 * pool2
|
|
1457
|
+
* term = pool2 - --------------
|
|
1458
|
+
* pool1 + swap
|
|
1459
|
+
*
|
|
1460
|
+
* result = term - (term * fee)
|
|
1461
|
+
*/
|
|
1462
|
+
|
|
1463
|
+
var compute_transfer = function compute_transfer(pool1, pool2, swap, exchange_fee, precision) {
|
|
1464
|
+
var term1 = pool2;
|
|
1465
|
+
var term2over = pool1.multipliedBy(pool2);
|
|
1466
|
+
var term2under = pool1.plus(swap);
|
|
1467
|
+
var term2 = term2over.dividedBy(term2under).integerValue(bignumber_js.BigNumber.ROUND_DOWN);
|
|
1468
|
+
var term = term1.minus(term2);
|
|
1469
|
+
var fee = new bignumber_js.BigNumber(exchange_fee).dividedBy(FEE_FACTOR);
|
|
1470
|
+
var result = term.minus(term.multipliedBy(fee));
|
|
1471
|
+
return result.integerValue(bignumber_js.BigNumber.ROUND_DOWN).shiftedBy(-precision);
|
|
1472
|
+
};
|
|
1473
|
+
var compute_transfer_curve = function compute_transfer_curve(reserve_in, reserve_out, amount_in, exchange_fee, precision, amplifier) {
|
|
1474
|
+
if (amplifier === 0) {
|
|
1475
|
+
return compute_transfer(new bignumber_js.BigNumber(reserve_in), new bignumber_js.BigNumber(reserve_out), new bignumber_js.BigNumber(amount_in), exchange_fee, precision);
|
|
1476
|
+
}
|
|
1477
|
+
|
|
1478
|
+
var MAX_ITERATIONS = 10;
|
|
1479
|
+
var sum = reserve_in + reserve_out;
|
|
1480
|
+
var D = sum;
|
|
1481
|
+
var D_prev = 0;
|
|
1482
|
+
|
|
1483
|
+
var F = function F(v) {
|
|
1484
|
+
return (v >= 0 ? 1 : -1) * Math.floor(Math.abs(v));
|
|
1485
|
+
};
|
|
1486
|
+
|
|
1487
|
+
var i = MAX_ITERATIONS;
|
|
1488
|
+
|
|
1489
|
+
while (D != D_prev && i--) {
|
|
1490
|
+
var prod1 = F(F(D * D / (reserve_in * 2)) * D / (reserve_out * 2));
|
|
1491
|
+
D_prev = D;
|
|
1492
|
+
D = F(2 * D * (amplifier * sum + prod1) / ((2 * amplifier - 1) * D + 3 * prod1));
|
|
1493
|
+
}
|
|
1494
|
+
|
|
1495
|
+
var b = reserve_in + amount_in + F(D / (amplifier * 2)) - D;
|
|
1496
|
+
var c = F(F(D * D / ((reserve_in + amount_in) * 2)) * D / (amplifier * 4));
|
|
1497
|
+
var x = D,
|
|
1498
|
+
x_prev = 0;
|
|
1499
|
+
i = MAX_ITERATIONS;
|
|
1500
|
+
|
|
1501
|
+
while (x != x_prev && i--) {
|
|
1502
|
+
x_prev = F(x);
|
|
1503
|
+
x = +new bignumber_js.BigNumber(x * x + c).dividedBy(2 * x + b).toFixed(0, bignumber_js.BigNumber.ROUND_DOWN);
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1506
|
+
if (reserve_out <= x) {
|
|
1507
|
+
throw new Error("curve: insufficient reserve out");
|
|
1508
|
+
} // Fee
|
|
1509
|
+
|
|
1510
|
+
|
|
1511
|
+
var amount_out_with_fee = new bignumber_js.BigNumber(reserve_out - x);
|
|
1512
|
+
var fee = amount_out_with_fee.multipliedBy(exchange_fee).dividedBy(FEE_FACTOR).toFixed(0, bignumber_js.BigNumber.ROUND_DOWN);
|
|
1513
|
+
var amount_out = amount_out_with_fee.minus(fee);
|
|
1514
|
+
return amount_out.integerValue(bignumber_js.BigNumber.ROUND_DOWN).shiftedBy(-precision);
|
|
1515
|
+
};
|
|
1516
|
+
var compute_liquidity = function compute_liquidity(amount_lt, pool, lt_supply, precision) {
|
|
1517
|
+
var over = amount_lt.multipliedBy(pool);
|
|
1518
|
+
var under = lt_supply;
|
|
1519
|
+
var result = over.dividedBy(under).integerValue(bignumber_js.BigNumber.ROUND_DOWN);
|
|
1520
|
+
return +result.shiftedBy(-precision).toFixed(precision, bignumber_js.BigNumber.ROUND_DOWN);
|
|
1521
|
+
};
|
|
1522
|
+
var isInputInvalid = function isInputInvalid(data, value, pool) {
|
|
1523
|
+
value = String(value);
|
|
1524
|
+
var isBackspace = data === null;
|
|
1525
|
+
var isNumber = !/[0-9]|\./.test(data);
|
|
1526
|
+
var isDoubleDot = data === '.' && value.indexOf('.') !== value.length - 1;
|
|
1527
|
+
var isPrecisionTooHigh = value && value.indexOf('.') !== -1 && value.split('.')[1].length > pool.xtokenPrecision;
|
|
1528
|
+
var isInvalid = !isBackspace && Boolean(isNumber || isDoubleDot || isPrecisionTooHigh);
|
|
1529
|
+
return isInvalid;
|
|
1530
|
+
};
|
|
1531
|
+
var applyDiscountToFee = function applyDiscountToFee(fee, staked) {
|
|
1532
|
+
if (staked >= 10000000) {
|
|
1533
|
+
return fee * 0;
|
|
1534
|
+
} else if (staked >= 1000000) {
|
|
1535
|
+
return fee * 0.33;
|
|
1536
|
+
} else if (staked >= 100000) {
|
|
1537
|
+
return fee * 0.66;
|
|
1538
|
+
} else {
|
|
1539
|
+
return fee;
|
|
1540
|
+
}
|
|
1541
|
+
};
|
|
1542
|
+
|
|
1223
1543
|
exports.ExtendedAssetParser = ExtendedAssetParser;
|
|
1544
|
+
exports.FEE_FACTOR = FEE_FACTOR;
|
|
1545
|
+
exports.Graph = Graph;
|
|
1546
|
+
exports.ILink = ILink;
|
|
1547
|
+
exports.INode = INode;
|
|
1224
1548
|
exports.WRAP_AUTH_ACTION = WRAP_AUTH_ACTION;
|
|
1225
1549
|
exports.WRAP_CONTRACT = WRAP_CONTRACT;
|
|
1226
1550
|
exports.accountParser = accountParser;
|
|
1227
1551
|
exports.addressParser = addressParser;
|
|
1552
|
+
exports.applyDiscountToFee = applyDiscountToFee;
|
|
1228
1553
|
exports.authorizationParser = authorizationParser;
|
|
1229
1554
|
exports.authorizationsParser = authorizationsParser;
|
|
1230
1555
|
exports.baseActionParser = baseActionParser;
|
|
1231
1556
|
exports.baseActionSerializedParser = baseActionSerializedParser;
|
|
1232
1557
|
exports.bloksRatesParser = bloksRatesParser;
|
|
1558
|
+
exports.compute_liquidity = compute_liquidity;
|
|
1559
|
+
exports.compute_transfer = compute_transfer;
|
|
1560
|
+
exports.compute_transfer_curve = compute_transfer_curve;
|
|
1233
1561
|
exports.createAbstractAuthParser = createAbstractAuthParser;
|
|
1234
1562
|
exports.depositBodyParser = depositBodyParser;
|
|
1235
1563
|
exports.exchangeRateParser = exchangeRateParser;
|
|
@@ -1240,6 +1568,7 @@ exports.generateAddressResponse = generateAddressResponse;
|
|
|
1240
1568
|
exports.generateAuthParser = generateAuthParser;
|
|
1241
1569
|
exports.initializeCoins = initializeCoins;
|
|
1242
1570
|
exports.initializeConstants = initializeConstants;
|
|
1571
|
+
exports.isInputInvalid = isInputInvalid;
|
|
1243
1572
|
exports.isSameToken = isSameToken;
|
|
1244
1573
|
exports.otcOrderResponseParser = otcOrderResponseParser;
|
|
1245
1574
|
exports.otcQuoteBodyParser = otcQuoteBodyParser;
|