@openocean.finance/openocean-sdk 1.2.7 → 1.2.9
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/lib/api/index.d.ts +3 -3
- package/lib/index.js +2 -50
- package/lib/index.js.LICENSE.txt +1 -25
- package/lib/swapSdk/Approve.d.ts +1 -1
- package/lib/swapSdk/RequestVo.d.ts +1 -1
- package/lib/v1/constants.d.ts +1 -1
- package/package.json +4 -4
- package/lib/api/index.js +0 -139
- package/lib/api/vo/RequestVo.js +0 -398
- package/lib/asset/abi/ERC20_abi.js +0 -119
- package/lib/asset/abi/aggregator.js +0 -391
- package/lib/config/index.js +0 -33
- package/lib/swapSdk/Approve.js +0 -342
- package/lib/swapSdk/NotoMobile.js +0 -141
- package/lib/swapSdk/RequestVo.js +0 -94
- package/lib/swapSdk/Swap.js +0 -1123
- package/lib/swapSdk/getAllowance.js +0 -97
- package/lib/swapSdk/getBalance.js +0 -280
- package/lib/swapSdk/index.js +0 -257
- package/lib/swapSdk/qrcode.js +0 -969
- package/lib/utils/ajx.js +0 -150
- package/lib/utils/index.js +0 -369
- package/lib/utils/web3.js +0 -9
- package/lib/v1/abis/ERC20.js +0 -22
- package/lib/v1/abis/IUniswapV2Pair.js +0 -1434
- package/lib/v1/constants.js +0 -71
- package/lib/v1/entities/currency.js +0 -39
- package/lib/v1/entities/fractions/currencyAmount.js +0 -83
- package/lib/v1/entities/fractions/fraction.js +0 -109
- package/lib/v1/entities/fractions/index.js +0 -21
- package/lib/v1/entities/fractions/percent.js +0 -37
- package/lib/v1/entities/fractions/price.js +0 -90
- package/lib/v1/entities/fractions/tokenAmount.js +0 -43
- package/lib/v1/entities/index.js +0 -22
- package/lib/v1/entities/pair.js +0 -210
- package/lib/v1/entities/route.js +0 -43
- package/lib/v1/entities/token.js +0 -87
- package/lib/v1/entities/trade.js +0 -336
- package/lib/v1/errors.js +0 -56
- package/lib/v1/fetcher.js +0 -140
- package/lib/v1/router.js +0 -97
- package/lib/v1/utils.js +0 -87
package/lib/v1/constants.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
var _a;
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.SOLIDITY_TYPE_MAXIMA = exports.SolidityType = exports._1000 = exports._998 = exports._100 = exports.TEN = exports.FIVE = exports.THREE = exports.TWO = exports.ONE = exports.ZERO = exports.MINIMUM_LIQUIDITY = exports.INIT_CODE_HASH = exports.FACTORY_ADDRESS = exports.Rounding = exports.TradeType = exports.ChainId = void 0;
|
|
8
|
-
var jsbi_1 = __importDefault(require("jsbi"));
|
|
9
|
-
var ChainId;
|
|
10
|
-
(function (ChainId) {
|
|
11
|
-
ChainId[ChainId["ETH"] = 1] = "ETH";
|
|
12
|
-
ChainId[ChainId["MAINNET"] = 56] = "MAINNET";
|
|
13
|
-
ChainId[ChainId["ONTEVM"] = 56] = "ONTEVM";
|
|
14
|
-
ChainId[ChainId["BSCTESTNET"] = 97] = "BSCTESTNET";
|
|
15
|
-
ChainId[ChainId["POLYGON"] = 137] = "POLYGON";
|
|
16
|
-
ChainId[ChainId["KAVA"] = 2222] = "KAVA";
|
|
17
|
-
ChainId[ChainId["AVAX"] = 43114] = "AVAX";
|
|
18
|
-
})(ChainId = exports.ChainId || (exports.ChainId = {}));
|
|
19
|
-
var TradeType;
|
|
20
|
-
(function (TradeType) {
|
|
21
|
-
TradeType[TradeType["EXACT_INPUT"] = 0] = "EXACT_INPUT";
|
|
22
|
-
TradeType[TradeType["EXACT_OUTPUT"] = 1] = "EXACT_OUTPUT";
|
|
23
|
-
})(TradeType = exports.TradeType || (exports.TradeType = {}));
|
|
24
|
-
var Rounding;
|
|
25
|
-
(function (Rounding) {
|
|
26
|
-
Rounding[Rounding["ROUND_DOWN"] = 0] = "ROUND_DOWN";
|
|
27
|
-
Rounding[Rounding["ROUND_HALF_UP"] = 1] = "ROUND_HALF_UP";
|
|
28
|
-
Rounding[Rounding["ROUND_UP"] = 2] = "ROUND_UP";
|
|
29
|
-
})(Rounding = exports.Rounding || (exports.Rounding = {}));
|
|
30
|
-
// export const FACTORY_ADDRESS = '0xF22b5afBe6152ca43fAE20DDA4F75575BABD0c5A'
|
|
31
|
-
// export const INIT_CODE_HASH = '0xe7da666f616ba3bdb18c6908b22d556a41659bdd652762c246b8d1fa4f7506b4'
|
|
32
|
-
exports.FACTORY_ADDRESS = {
|
|
33
|
-
1: '0x1F8c25f8DA3990Ecd3632eE4F02C2eA37755C3c6',
|
|
34
|
-
56: '0xd76d8C2A7CA0a1609Aea0b9b5017B3F7782891bf',
|
|
35
|
-
58: '0x1AA8c24ac757758e27E66E619429cA87d3Fc28BB',
|
|
36
|
-
97: '0xd76d8C2A7CA0a1609Aea0b9b5017B3F7782891bf',
|
|
37
|
-
137: '0xd76d8C2A7CA0a1609Aea0b9b5017B3F7782891bf',
|
|
38
|
-
2222: '0x6dd434082EAB5Cd134B33719ec1FF05fE985B97b',
|
|
39
|
-
42161: '0x01Ec93c289cB003e741f621cDD4FE837243f8905',
|
|
40
|
-
43114: '0x042AF448582d0a3cE3CFa5b65c2675e88610B18d'
|
|
41
|
-
};
|
|
42
|
-
exports.INIT_CODE_HASH = {
|
|
43
|
-
1: '0x338b9651a8c140547a88432caaff04a13e79d54b23e3cfec1e37fb3051125fab',
|
|
44
|
-
56: '0xe7da666f616ba3bdb18c6908b22d556a41659bdd652762c246b8d1fa4f7506b4',
|
|
45
|
-
58: '0xe7da666f616ba3bdb18c6908b22d556a41659bdd652762c246b8d1fa4f7506b4',
|
|
46
|
-
97: '0xe7da666f616ba3bdb18c6908b22d556a41659bdd652762c246b8d1fa4f7506b4',
|
|
47
|
-
137: '0x0415568b317738f62f1608a814ac51b81c10e7300e23f4b1395231fc8251e7e4',
|
|
48
|
-
2222: '0xc26b7c10cfd3e76ca96f0c5d9191b4c2e08295897ffd6e452ae36b1f11f6fec3',
|
|
49
|
-
42161: '0xc26b7c10cfd3e76ca96f0c5d9191b4c2e08295897ffd6e452ae36b1f11f6fec3',
|
|
50
|
-
43114: '0x0761dc23a5b0e399fc92b9c3ea676b0314153899f2e30483c7217dcc02046630'
|
|
51
|
-
};
|
|
52
|
-
exports.MINIMUM_LIQUIDITY = jsbi_1.default.BigInt(1000);
|
|
53
|
-
// exports for internal consumption
|
|
54
|
-
exports.ZERO = jsbi_1.default.BigInt(0);
|
|
55
|
-
exports.ONE = jsbi_1.default.BigInt(1);
|
|
56
|
-
exports.TWO = jsbi_1.default.BigInt(2);
|
|
57
|
-
exports.THREE = jsbi_1.default.BigInt(3);
|
|
58
|
-
exports.FIVE = jsbi_1.default.BigInt(5);
|
|
59
|
-
exports.TEN = jsbi_1.default.BigInt(10);
|
|
60
|
-
exports._100 = jsbi_1.default.BigInt(100);
|
|
61
|
-
exports._998 = jsbi_1.default.BigInt(998);
|
|
62
|
-
exports._1000 = jsbi_1.default.BigInt(1000);
|
|
63
|
-
var SolidityType;
|
|
64
|
-
(function (SolidityType) {
|
|
65
|
-
SolidityType["uint8"] = "uint8";
|
|
66
|
-
SolidityType["uint256"] = "uint256";
|
|
67
|
-
})(SolidityType = exports.SolidityType || (exports.SolidityType = {}));
|
|
68
|
-
exports.SOLIDITY_TYPE_MAXIMA = (_a = {},
|
|
69
|
-
_a[SolidityType.uint8] = jsbi_1.default.BigInt('0xff'),
|
|
70
|
-
_a[SolidityType.uint256] = jsbi_1.default.BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'),
|
|
71
|
-
_a);
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.MATIC = exports.ETHER = exports.Currency = void 0;
|
|
7
|
-
var jsbi_1 = __importDefault(require("jsbi"));
|
|
8
|
-
var constants_1 = require("../constants");
|
|
9
|
-
var utils_1 = require("../utils");
|
|
10
|
-
/**
|
|
11
|
-
* A currency is any fungible financial instrument on Ethereum, including Ether and all ERC20 tokens.
|
|
12
|
-
*
|
|
13
|
-
* The only instance of the base class `Currency` is Ether.
|
|
14
|
-
*/
|
|
15
|
-
var Currency = /** @class */ (function () {
|
|
16
|
-
/**
|
|
17
|
-
* Constructs an instance of the base class `Currency`. The only instance of the base class `Currency` is `Currency.ETHER`.
|
|
18
|
-
* @param decimals decimals of the currency
|
|
19
|
-
* @param symbol symbol of the currency
|
|
20
|
-
* @param name of the currency
|
|
21
|
-
*/
|
|
22
|
-
function Currency(decimals, symbol, name) {
|
|
23
|
-
(0, utils_1.validateSolidityTypeInstance)(jsbi_1.default.BigInt(decimals), constants_1.SolidityType.uint8);
|
|
24
|
-
this.decimals = decimals;
|
|
25
|
-
this.symbol = symbol;
|
|
26
|
-
this.name = name;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* The only instance of the base class `Currency`.
|
|
30
|
-
*/
|
|
31
|
-
Currency.ETHER = new Currency(18, 'BNB', 'Binance');
|
|
32
|
-
Currency.MATIC = new Currency(18, 'MATIC', 'Polygon');
|
|
33
|
-
return Currency;
|
|
34
|
-
}());
|
|
35
|
-
exports.Currency = Currency;
|
|
36
|
-
var ETHER = Currency.ETHER;
|
|
37
|
-
exports.ETHER = ETHER;
|
|
38
|
-
var MATIC = Currency.MATIC;
|
|
39
|
-
exports.MATIC = MATIC;
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
-
};
|
|
20
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.CurrencyAmount = void 0;
|
|
22
|
-
var token_1 = require("../token");
|
|
23
|
-
var currency_1 = require("../currency");
|
|
24
|
-
var tiny_invariant_1 = __importDefault(require("tiny-invariant"));
|
|
25
|
-
var jsbi_1 = __importDefault(require("jsbi"));
|
|
26
|
-
var big_js_1 = __importDefault(require("big.js"));
|
|
27
|
-
var toformat_1 = __importDefault(require("toformat"));
|
|
28
|
-
var constants_1 = require("../../constants");
|
|
29
|
-
var utils_1 = require("../../utils");
|
|
30
|
-
var fraction_1 = require("./fraction");
|
|
31
|
-
var Big = (0, toformat_1.default)(big_js_1.default);
|
|
32
|
-
var CurrencyAmount = /** @class */ (function (_super) {
|
|
33
|
-
__extends(CurrencyAmount, _super);
|
|
34
|
-
// amount _must_ be raw, i.e. in the native representation
|
|
35
|
-
function CurrencyAmount(currency, amount) {
|
|
36
|
-
var _this = this;
|
|
37
|
-
var parsedAmount = (0, utils_1.parseBigintIsh)(amount);
|
|
38
|
-
(0, utils_1.validateSolidityTypeInstance)(parsedAmount, constants_1.SolidityType.uint256);
|
|
39
|
-
_this = _super.call(this, parsedAmount, jsbi_1.default.exponentiate(constants_1.TEN, jsbi_1.default.BigInt(currency.decimals))) || this;
|
|
40
|
-
_this.currency = currency;
|
|
41
|
-
return _this;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Helper that calls the constructor with the ETHER currency
|
|
45
|
-
* @param amount ether amount in wei
|
|
46
|
-
*/
|
|
47
|
-
CurrencyAmount.ether = function (amount) {
|
|
48
|
-
return new CurrencyAmount(currency_1.ETHER, amount);
|
|
49
|
-
};
|
|
50
|
-
Object.defineProperty(CurrencyAmount.prototype, "raw", {
|
|
51
|
-
get: function () {
|
|
52
|
-
return this.numerator;
|
|
53
|
-
},
|
|
54
|
-
enumerable: false,
|
|
55
|
-
configurable: true
|
|
56
|
-
});
|
|
57
|
-
CurrencyAmount.prototype.add = function (other) {
|
|
58
|
-
(0, tiny_invariant_1.default)((0, token_1.currencyEquals)(this.currency, other.currency), 'TOKEN');
|
|
59
|
-
return new CurrencyAmount(this.currency, jsbi_1.default.add(this.raw, other.raw));
|
|
60
|
-
};
|
|
61
|
-
CurrencyAmount.prototype.subtract = function (other) {
|
|
62
|
-
(0, tiny_invariant_1.default)((0, token_1.currencyEquals)(this.currency, other.currency), 'TOKEN');
|
|
63
|
-
return new CurrencyAmount(this.currency, jsbi_1.default.subtract(this.raw, other.raw));
|
|
64
|
-
};
|
|
65
|
-
CurrencyAmount.prototype.toSignificant = function (significantDigits, format, rounding) {
|
|
66
|
-
if (significantDigits === void 0) { significantDigits = 6; }
|
|
67
|
-
if (rounding === void 0) { rounding = constants_1.Rounding.ROUND_DOWN; }
|
|
68
|
-
return _super.prototype.toSignificant.call(this, significantDigits, format, rounding);
|
|
69
|
-
};
|
|
70
|
-
CurrencyAmount.prototype.toFixed = function (decimalPlaces, format, rounding) {
|
|
71
|
-
if (decimalPlaces === void 0) { decimalPlaces = this.currency.decimals; }
|
|
72
|
-
if (rounding === void 0) { rounding = constants_1.Rounding.ROUND_DOWN; }
|
|
73
|
-
(0, tiny_invariant_1.default)(decimalPlaces <= this.currency.decimals, 'DECIMALS');
|
|
74
|
-
return _super.prototype.toFixed.call(this, decimalPlaces, format, rounding);
|
|
75
|
-
};
|
|
76
|
-
CurrencyAmount.prototype.toExact = function (format) {
|
|
77
|
-
if (format === void 0) { format = { groupSeparator: '' }; }
|
|
78
|
-
Big.DP = this.currency.decimals;
|
|
79
|
-
return new Big(this.numerator.toString()).div(this.denominator.toString()).toFormat(format);
|
|
80
|
-
};
|
|
81
|
-
return CurrencyAmount;
|
|
82
|
-
}(fraction_1.Fraction));
|
|
83
|
-
exports.CurrencyAmount = CurrencyAmount;
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
var _a, _b;
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.Fraction = void 0;
|
|
8
|
-
var tiny_invariant_1 = __importDefault(require("tiny-invariant"));
|
|
9
|
-
var jsbi_1 = __importDefault(require("jsbi"));
|
|
10
|
-
var decimal_js_light_1 = __importDefault(require("decimal.js-light"));
|
|
11
|
-
var big_js_1 = __importDefault(require("big.js"));
|
|
12
|
-
var toformat_1 = __importDefault(require("toformat"));
|
|
13
|
-
var constants_1 = require("../../constants");
|
|
14
|
-
var constants_2 = require("../../constants");
|
|
15
|
-
var utils_1 = require("../../utils");
|
|
16
|
-
var Decimal = (0, toformat_1.default)(decimal_js_light_1.default);
|
|
17
|
-
var Big = (0, toformat_1.default)(big_js_1.default);
|
|
18
|
-
var toSignificantRounding = (_a = {},
|
|
19
|
-
_a[constants_1.Rounding.ROUND_DOWN] = Decimal.ROUND_DOWN,
|
|
20
|
-
_a[constants_1.Rounding.ROUND_HALF_UP] = Decimal.ROUND_HALF_UP,
|
|
21
|
-
_a[constants_1.Rounding.ROUND_UP] = Decimal.ROUND_UP,
|
|
22
|
-
_a);
|
|
23
|
-
var toFixedRounding = (_b = {},
|
|
24
|
-
_b[constants_1.Rounding.ROUND_DOWN] = 0 /* RoundDown */,
|
|
25
|
-
_b[constants_1.Rounding.ROUND_HALF_UP] = 1 /* RoundHalfUp */,
|
|
26
|
-
_b[constants_1.Rounding.ROUND_UP] = 3 /* RoundUp */,
|
|
27
|
-
_b);
|
|
28
|
-
var Fraction = /** @class */ (function () {
|
|
29
|
-
function Fraction(numerator, denominator) {
|
|
30
|
-
if (denominator === void 0) { denominator = constants_2.ONE; }
|
|
31
|
-
this.numerator = (0, utils_1.parseBigintIsh)(numerator);
|
|
32
|
-
this.denominator = (0, utils_1.parseBigintIsh)(denominator);
|
|
33
|
-
}
|
|
34
|
-
Object.defineProperty(Fraction.prototype, "quotient", {
|
|
35
|
-
// performs floor division
|
|
36
|
-
get: function () {
|
|
37
|
-
return jsbi_1.default.divide(this.numerator, this.denominator);
|
|
38
|
-
},
|
|
39
|
-
enumerable: false,
|
|
40
|
-
configurable: true
|
|
41
|
-
});
|
|
42
|
-
Object.defineProperty(Fraction.prototype, "remainder", {
|
|
43
|
-
// remainder after floor division
|
|
44
|
-
get: function () {
|
|
45
|
-
return new Fraction(jsbi_1.default.remainder(this.numerator, this.denominator), this.denominator);
|
|
46
|
-
},
|
|
47
|
-
enumerable: false,
|
|
48
|
-
configurable: true
|
|
49
|
-
});
|
|
50
|
-
Fraction.prototype.invert = function () {
|
|
51
|
-
return new Fraction(this.denominator, this.numerator);
|
|
52
|
-
};
|
|
53
|
-
Fraction.prototype.add = function (other) {
|
|
54
|
-
var otherParsed = other instanceof Fraction ? other : new Fraction((0, utils_1.parseBigintIsh)(other));
|
|
55
|
-
if (jsbi_1.default.equal(this.denominator, otherParsed.denominator)) {
|
|
56
|
-
return new Fraction(jsbi_1.default.add(this.numerator, otherParsed.numerator), this.denominator);
|
|
57
|
-
}
|
|
58
|
-
return new Fraction(jsbi_1.default.add(jsbi_1.default.multiply(this.numerator, otherParsed.denominator), jsbi_1.default.multiply(otherParsed.numerator, this.denominator)), jsbi_1.default.multiply(this.denominator, otherParsed.denominator));
|
|
59
|
-
};
|
|
60
|
-
Fraction.prototype.subtract = function (other) {
|
|
61
|
-
var otherParsed = other instanceof Fraction ? other : new Fraction((0, utils_1.parseBigintIsh)(other));
|
|
62
|
-
if (jsbi_1.default.equal(this.denominator, otherParsed.denominator)) {
|
|
63
|
-
return new Fraction(jsbi_1.default.subtract(this.numerator, otherParsed.numerator), this.denominator);
|
|
64
|
-
}
|
|
65
|
-
return new Fraction(jsbi_1.default.subtract(jsbi_1.default.multiply(this.numerator, otherParsed.denominator), jsbi_1.default.multiply(otherParsed.numerator, this.denominator)), jsbi_1.default.multiply(this.denominator, otherParsed.denominator));
|
|
66
|
-
};
|
|
67
|
-
Fraction.prototype.lessThan = function (other) {
|
|
68
|
-
var otherParsed = other instanceof Fraction ? other : new Fraction((0, utils_1.parseBigintIsh)(other));
|
|
69
|
-
return jsbi_1.default.lessThan(jsbi_1.default.multiply(this.numerator, otherParsed.denominator), jsbi_1.default.multiply(otherParsed.numerator, this.denominator));
|
|
70
|
-
};
|
|
71
|
-
Fraction.prototype.equalTo = function (other) {
|
|
72
|
-
var otherParsed = other instanceof Fraction ? other : new Fraction((0, utils_1.parseBigintIsh)(other));
|
|
73
|
-
return jsbi_1.default.equal(jsbi_1.default.multiply(this.numerator, otherParsed.denominator), jsbi_1.default.multiply(otherParsed.numerator, this.denominator));
|
|
74
|
-
};
|
|
75
|
-
Fraction.prototype.greaterThan = function (other) {
|
|
76
|
-
var otherParsed = other instanceof Fraction ? other : new Fraction((0, utils_1.parseBigintIsh)(other));
|
|
77
|
-
return jsbi_1.default.greaterThan(jsbi_1.default.multiply(this.numerator, otherParsed.denominator), jsbi_1.default.multiply(otherParsed.numerator, this.denominator));
|
|
78
|
-
};
|
|
79
|
-
Fraction.prototype.multiply = function (other) {
|
|
80
|
-
var otherParsed = other instanceof Fraction ? other : new Fraction((0, utils_1.parseBigintIsh)(other));
|
|
81
|
-
return new Fraction(jsbi_1.default.multiply(this.numerator, otherParsed.numerator), jsbi_1.default.multiply(this.denominator, otherParsed.denominator));
|
|
82
|
-
};
|
|
83
|
-
Fraction.prototype.divide = function (other) {
|
|
84
|
-
var otherParsed = other instanceof Fraction ? other : new Fraction((0, utils_1.parseBigintIsh)(other));
|
|
85
|
-
return new Fraction(jsbi_1.default.multiply(this.numerator, otherParsed.denominator), jsbi_1.default.multiply(this.denominator, otherParsed.numerator));
|
|
86
|
-
};
|
|
87
|
-
Fraction.prototype.toSignificant = function (significantDigits, format, rounding) {
|
|
88
|
-
if (format === void 0) { format = { groupSeparator: '' }; }
|
|
89
|
-
if (rounding === void 0) { rounding = constants_1.Rounding.ROUND_HALF_UP; }
|
|
90
|
-
(0, tiny_invariant_1.default)(Number.isInteger(significantDigits), "".concat(significantDigits, " is not an integer."));
|
|
91
|
-
(0, tiny_invariant_1.default)(significantDigits > 0, "".concat(significantDigits, " is not positive."));
|
|
92
|
-
Decimal.set({ precision: significantDigits + 1, rounding: toSignificantRounding[rounding] });
|
|
93
|
-
var quotient = new Decimal(this.numerator.toString())
|
|
94
|
-
.div(this.denominator.toString())
|
|
95
|
-
.toSignificantDigits(significantDigits);
|
|
96
|
-
return quotient.toFormat(quotient.decimalPlaces(), format);
|
|
97
|
-
};
|
|
98
|
-
Fraction.prototype.toFixed = function (decimalPlaces, format, rounding) {
|
|
99
|
-
if (format === void 0) { format = { groupSeparator: '' }; }
|
|
100
|
-
if (rounding === void 0) { rounding = constants_1.Rounding.ROUND_HALF_UP; }
|
|
101
|
-
(0, tiny_invariant_1.default)(Number.isInteger(decimalPlaces), "".concat(decimalPlaces, " is not an integer."));
|
|
102
|
-
(0, tiny_invariant_1.default)(decimalPlaces >= 0, "".concat(decimalPlaces, " is negative."));
|
|
103
|
-
Big.DP = decimalPlaces;
|
|
104
|
-
Big.RM = toFixedRounding[rounding];
|
|
105
|
-
return new Big(this.numerator.toString()).div(this.denominator.toString()).toFormat(decimalPlaces, format);
|
|
106
|
-
};
|
|
107
|
-
return Fraction;
|
|
108
|
-
}());
|
|
109
|
-
exports.Fraction = Fraction;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./fraction"), exports);
|
|
18
|
-
__exportStar(require("./percent"), exports);
|
|
19
|
-
__exportStar(require("./tokenAmount"), exports);
|
|
20
|
-
__exportStar(require("./currencyAmount"), exports);
|
|
21
|
-
__exportStar(require("./price"), exports);
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.Percent = void 0;
|
|
19
|
-
var constants_1 = require("../../constants");
|
|
20
|
-
var fraction_1 = require("./fraction");
|
|
21
|
-
var _100_PERCENT = new fraction_1.Fraction(constants_1._100);
|
|
22
|
-
var Percent = /** @class */ (function (_super) {
|
|
23
|
-
__extends(Percent, _super);
|
|
24
|
-
function Percent() {
|
|
25
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
26
|
-
}
|
|
27
|
-
Percent.prototype.toSignificant = function (significantDigits, format, rounding) {
|
|
28
|
-
if (significantDigits === void 0) { significantDigits = 5; }
|
|
29
|
-
return this.multiply(_100_PERCENT).toSignificant(significantDigits, format, rounding);
|
|
30
|
-
};
|
|
31
|
-
Percent.prototype.toFixed = function (decimalPlaces, format, rounding) {
|
|
32
|
-
if (decimalPlaces === void 0) { decimalPlaces = 2; }
|
|
33
|
-
return this.multiply(_100_PERCENT).toFixed(decimalPlaces, format, rounding);
|
|
34
|
-
};
|
|
35
|
-
return Percent;
|
|
36
|
-
}(fraction_1.Fraction));
|
|
37
|
-
exports.Percent = Percent;
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
-
};
|
|
20
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.Price = void 0;
|
|
22
|
-
var token_1 = require("../token");
|
|
23
|
-
var tokenAmount_1 = require("./tokenAmount");
|
|
24
|
-
var token_2 = require("../token");
|
|
25
|
-
var tiny_invariant_1 = __importDefault(require("tiny-invariant"));
|
|
26
|
-
var jsbi_1 = __importDefault(require("jsbi"));
|
|
27
|
-
var constants_1 = require("../../constants");
|
|
28
|
-
var fraction_1 = require("./fraction");
|
|
29
|
-
var currencyAmount_1 = require("./currencyAmount");
|
|
30
|
-
var Price = /** @class */ (function (_super) {
|
|
31
|
-
__extends(Price, _super);
|
|
32
|
-
// denominator and numerator _must_ be raw, i.e. in the native representation
|
|
33
|
-
function Price(baseCurrency, quoteCurrency, denominator, numerator) {
|
|
34
|
-
var _this = _super.call(this, numerator, denominator) || this;
|
|
35
|
-
_this.baseCurrency = baseCurrency;
|
|
36
|
-
_this.quoteCurrency = quoteCurrency;
|
|
37
|
-
_this.scalar = new fraction_1.Fraction(jsbi_1.default.exponentiate(constants_1.TEN, jsbi_1.default.BigInt(baseCurrency.decimals)), jsbi_1.default.exponentiate(constants_1.TEN, jsbi_1.default.BigInt(quoteCurrency.decimals)));
|
|
38
|
-
return _this;
|
|
39
|
-
}
|
|
40
|
-
Price.fromRoute = function (route) {
|
|
41
|
-
var prices = [];
|
|
42
|
-
for (var _i = 0, _a = route.pairs.entries(); _i < _a.length; _i++) {
|
|
43
|
-
var _b = _a[_i], i = _b[0], pair = _b[1];
|
|
44
|
-
prices.push(route.path[i].equals(pair.token0)
|
|
45
|
-
? new Price(pair.reserve0.currency, pair.reserve1.currency, pair.reserve0.raw, pair.reserve1.raw)
|
|
46
|
-
: new Price(pair.reserve1.currency, pair.reserve0.currency, pair.reserve1.raw, pair.reserve0.raw));
|
|
47
|
-
}
|
|
48
|
-
return prices.slice(1).reduce(function (accumulator, currentValue) { return accumulator.multiply(currentValue); }, prices[0]);
|
|
49
|
-
};
|
|
50
|
-
Object.defineProperty(Price.prototype, "raw", {
|
|
51
|
-
get: function () {
|
|
52
|
-
return new fraction_1.Fraction(this.numerator, this.denominator);
|
|
53
|
-
},
|
|
54
|
-
enumerable: false,
|
|
55
|
-
configurable: true
|
|
56
|
-
});
|
|
57
|
-
Object.defineProperty(Price.prototype, "adjusted", {
|
|
58
|
-
get: function () {
|
|
59
|
-
return _super.prototype.multiply.call(this, this.scalar);
|
|
60
|
-
},
|
|
61
|
-
enumerable: false,
|
|
62
|
-
configurable: true
|
|
63
|
-
});
|
|
64
|
-
Price.prototype.invert = function () {
|
|
65
|
-
return new Price(this.quoteCurrency, this.baseCurrency, this.numerator, this.denominator);
|
|
66
|
-
};
|
|
67
|
-
Price.prototype.multiply = function (other) {
|
|
68
|
-
(0, tiny_invariant_1.default)((0, token_2.currencyEquals)(this.quoteCurrency, other.baseCurrency), 'TOKEN');
|
|
69
|
-
var fraction = _super.prototype.multiply.call(this, other);
|
|
70
|
-
return new Price(this.baseCurrency, other.quoteCurrency, fraction.denominator, fraction.numerator);
|
|
71
|
-
};
|
|
72
|
-
// performs floor division on overflow
|
|
73
|
-
Price.prototype.quote = function (currencyAmount) {
|
|
74
|
-
(0, tiny_invariant_1.default)((0, token_2.currencyEquals)(currencyAmount.currency, this.baseCurrency), 'TOKEN');
|
|
75
|
-
if (this.quoteCurrency instanceof token_1.Token) {
|
|
76
|
-
return new tokenAmount_1.TokenAmount(this.quoteCurrency, _super.prototype.multiply.call(this, currencyAmount.raw).quotient);
|
|
77
|
-
}
|
|
78
|
-
return currencyAmount_1.CurrencyAmount.ether(_super.prototype.multiply.call(this, currencyAmount.raw).quotient);
|
|
79
|
-
};
|
|
80
|
-
Price.prototype.toSignificant = function (significantDigits, format, rounding) {
|
|
81
|
-
if (significantDigits === void 0) { significantDigits = 6; }
|
|
82
|
-
return this.adjusted.toSignificant(significantDigits, format, rounding);
|
|
83
|
-
};
|
|
84
|
-
Price.prototype.toFixed = function (decimalPlaces, format, rounding) {
|
|
85
|
-
if (decimalPlaces === void 0) { decimalPlaces = 4; }
|
|
86
|
-
return this.adjusted.toFixed(decimalPlaces, format, rounding);
|
|
87
|
-
};
|
|
88
|
-
return Price;
|
|
89
|
-
}(fraction_1.Fraction));
|
|
90
|
-
exports.Price = Price;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
-
};
|
|
20
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.TokenAmount = void 0;
|
|
22
|
-
var currencyAmount_1 = require("./currencyAmount");
|
|
23
|
-
var tiny_invariant_1 = __importDefault(require("tiny-invariant"));
|
|
24
|
-
var jsbi_1 = __importDefault(require("jsbi"));
|
|
25
|
-
var TokenAmount = /** @class */ (function (_super) {
|
|
26
|
-
__extends(TokenAmount, _super);
|
|
27
|
-
// amount _must_ be raw, i.e. in the native representation
|
|
28
|
-
function TokenAmount(token, amount) {
|
|
29
|
-
var _this = _super.call(this, token, amount) || this;
|
|
30
|
-
_this.token = token;
|
|
31
|
-
return _this;
|
|
32
|
-
}
|
|
33
|
-
TokenAmount.prototype.add = function (other) {
|
|
34
|
-
(0, tiny_invariant_1.default)(this.token.equals(other.token), 'TOKEN');
|
|
35
|
-
return new TokenAmount(this.token, jsbi_1.default.add(this.raw, other.raw));
|
|
36
|
-
};
|
|
37
|
-
TokenAmount.prototype.subtract = function (other) {
|
|
38
|
-
(0, tiny_invariant_1.default)(this.token.equals(other.token), 'TOKEN');
|
|
39
|
-
return new TokenAmount(this.token, jsbi_1.default.subtract(this.raw, other.raw));
|
|
40
|
-
};
|
|
41
|
-
return TokenAmount;
|
|
42
|
-
}(currencyAmount_1.CurrencyAmount));
|
|
43
|
-
exports.TokenAmount = TokenAmount;
|
package/lib/v1/entities/index.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./token"), exports);
|
|
18
|
-
__exportStar(require("./pair"), exports);
|
|
19
|
-
__exportStar(require("./route"), exports);
|
|
20
|
-
__exportStar(require("./trade"), exports);
|
|
21
|
-
__exportStar(require("./currency"), exports);
|
|
22
|
-
__exportStar(require("./fractions"), exports);
|