@synthra-swap/sdk 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.
- package/README.md +12 -0
- package/chains.d.ts +1 -0
- package/chains.js +1 -0
- package/core.d.ts +1 -0
- package/core.js +1 -0
- package/dist/chain-registry.d.ts +22 -0
- package/dist/chain-registry.js +315 -0
- package/dist/chain-registry.js.map +1 -0
- package/dist/chains.d.ts +5 -0
- package/dist/chains.js +29 -0
- package/dist/chains.js.map +1 -0
- package/dist/core/addresses.d.ts +21 -0
- package/dist/core/addresses.js +76 -0
- package/dist/core/addresses.js.map +1 -0
- package/dist/core/chains.d.ts +51 -0
- package/dist/core/chains.js +82 -0
- package/dist/core/chains.js.map +1 -0
- package/dist/core/constants.d.ts +12 -0
- package/dist/core/constants.js +20 -0
- package/dist/core/constants.js.map +1 -0
- package/dist/core/entities/baseCurrency.d.ts +48 -0
- package/dist/core/entities/baseCurrency.js +29 -0
- package/dist/core/entities/baseCurrency.js.map +1 -0
- package/dist/core/entities/currency.d.ts +3 -0
- package/dist/core/entities/currency.js +3 -0
- package/dist/core/entities/currency.js.map +1 -0
- package/dist/core/entities/ether.d.ts +13 -0
- package/dist/core/entities/ether.js +32 -0
- package/dist/core/entities/ether.js.map +1 -0
- package/dist/core/entities/fractions/currencyAmount.d.ts +31 -0
- package/dist/core/entities/fractions/currencyAmount.js +74 -0
- package/dist/core/entities/fractions/currencyAmount.js.map +1 -0
- package/dist/core/entities/fractions/fraction.d.ts +24 -0
- package/dist/core/entities/fractions/fraction.js +106 -0
- package/dist/core/entities/fractions/fraction.js.map +1 -0
- package/dist/core/entities/fractions/index.d.ts +4 -0
- package/dist/core/entities/fractions/index.js +12 -0
- package/dist/core/entities/fractions/index.js.map +1 -0
- package/dist/core/entities/fractions/percent.d.ts +14 -0
- package/dist/core/entities/fractions/percent.js +45 -0
- package/dist/core/entities/fractions/percent.js.map +1 -0
- package/dist/core/entities/fractions/price.d.ts +38 -0
- package/dist/core/entities/fractions/price.js +75 -0
- package/dist/core/entities/fractions/price.js.map +1 -0
- package/dist/core/entities/index.d.ts +7 -0
- package/dist/core/entities/index.js +24 -0
- package/dist/core/entities/index.js.map +1 -0
- package/dist/core/entities/nativeCurrency.d.ts +8 -0
- package/dist/core/entities/nativeCurrency.js +16 -0
- package/dist/core/entities/nativeCurrency.js.map +1 -0
- package/dist/core/entities/nativeOnChain.d.ts +19 -0
- package/dist/core/entities/nativeOnChain.js +141 -0
- package/dist/core/entities/nativeOnChain.js.map +1 -0
- package/dist/core/entities/token.d.ts +48 -0
- package/dist/core/entities/token.js +71 -0
- package/dist/core/entities/token.js.map +1 -0
- package/dist/core/entities/weth9.d.ts +7 -0
- package/dist/core/entities/weth9.js +28 -0
- package/dist/core/entities/weth9.js.map +1 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.js +22 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/utils/computePriceImpact.d.ts +8 -0
- package/dist/core/utils/computePriceImpact.js +18 -0
- package/dist/core/utils/computePriceImpact.js.map +1 -0
- package/dist/core/utils/index.d.ts +4 -0
- package/dist/core/utils/index.js +12 -0
- package/dist/core/utils/index.js.map +1 -0
- package/dist/core/utils/sortedInsert.d.ts +1 -0
- package/dist/core/utils/sortedInsert.js +40 -0
- package/dist/core/utils/sortedInsert.js.map +1 -0
- package/dist/core/utils/sqrt.d.ts +7 -0
- package/dist/core/utils/sqrt.js +34 -0
- package/dist/core/utils/sqrt.js.map +1 -0
- package/dist/core/utils/validateAndParseAddress.d.ts +10 -0
- package/dist/core/utils/validateAndParseAddress.js +31 -0
- package/dist/core/utils/validateAndParseAddress.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/universal-router/entities/Command.d.ts +12 -0
- package/dist/universal-router/entities/Command.js +9 -0
- package/dist/universal-router/entities/Command.js.map +1 -0
- package/dist/universal-router/entities/index.d.ts +3 -0
- package/dist/universal-router/entities/index.js +20 -0
- package/dist/universal-router/entities/index.js.map +1 -0
- package/dist/universal-router/entities/protocols/index.d.ts +2 -0
- package/dist/universal-router/entities/protocols/index.js +19 -0
- package/dist/universal-router/entities/protocols/index.js.map +1 -0
- package/dist/universal-router/entities/protocols/uniswap.d.ts +32 -0
- package/dist/universal-router/entities/protocols/uniswap.js +143 -0
- package/dist/universal-router/entities/protocols/uniswap.js.map +1 -0
- package/dist/universal-router/entities/protocols/unwrapWETH.d.ts +12 -0
- package/dist/universal-router/entities/protocols/unwrapWETH.js +35 -0
- package/dist/universal-router/entities/protocols/unwrapWETH.js.map +1 -0
- package/dist/universal-router/entities/trade.d.ts +41 -0
- package/dist/universal-router/entities/trade.js +114 -0
- package/dist/universal-router/entities/trade.js.map +1 -0
- package/dist/universal-router/index.d.ts +5 -0
- package/dist/universal-router/index.js +31 -0
- package/dist/universal-router/index.js.map +1 -0
- package/dist/universal-router/swapRouter.d.ts +29 -0
- package/dist/universal-router/swapRouter.js +102 -0
- package/dist/universal-router/swapRouter.js.map +1 -0
- package/dist/universal-router/utils/constants.d.ts +8 -0
- package/dist/universal-router/utils/constants.js +21 -0
- package/dist/universal-router/utils/constants.js.map +1 -0
- package/dist/universal-router/utils/getNativeCurrencyValue.d.ts +2 -0
- package/dist/universal-router/utils/getNativeCurrencyValue.js +19 -0
- package/dist/universal-router/utils/getNativeCurrencyValue.js.map +1 -0
- package/dist/universal-router/utils/inputTokens.d.ts +16 -0
- package/dist/universal-router/utils/inputTokens.js +44 -0
- package/dist/universal-router/utils/inputTokens.js.map +1 -0
- package/dist/universal-router/utils/numbers.d.ts +6 -0
- package/dist/universal-router/utils/numbers.js +24 -0
- package/dist/universal-router/utils/numbers.js.map +1 -0
- package/dist/universal-router/utils/routerCommands.d.ts +29 -0
- package/dist/universal-router/utils/routerCommands.js +64 -0
- package/dist/universal-router/utils/routerCommands.js.map +1 -0
- package/dist/universal-router/utils/routerTradeAdapter.d.ts +40 -0
- package/dist/universal-router/utils/routerTradeAdapter.js +82 -0
- package/dist/universal-router/utils/routerTradeAdapter.js.map +1 -0
- package/dist/v3/abis.d.ts +6 -0
- package/dist/v3/abis.js +39 -0
- package/dist/v3/abis.js.map +1 -0
- package/dist/v3/constants.d.ts +18 -0
- package/dist/v3/constants.js +26 -0
- package/dist/v3/constants.js.map +1 -0
- package/dist/v3/entities/index.d.ts +7 -0
- package/dist/v3/entities/index.js +24 -0
- package/dist/v3/entities/index.js.map +1 -0
- package/dist/v3/entities/pool.d.ts +81 -0
- package/dist/v3/entities/pool.js +215 -0
- package/dist/v3/entities/pool.js.map +1 -0
- package/dist/v3/entities/position.d.ts +131 -0
- package/dist/v3/entities/position.js +250 -0
- package/dist/v3/entities/position.js.map +1 -0
- package/dist/v3/entities/route.d.ts +26 -0
- package/dist/v3/entities/route.js +77 -0
- package/dist/v3/entities/route.js.map +1 -0
- package/dist/v3/entities/tick.d.ts +13 -0
- package/dist/v3/entities/tick.js +19 -0
- package/dist/v3/entities/tick.js.map +1 -0
- package/dist/v3/entities/tickDataProvider.d.ts +31 -0
- package/dist/v3/entities/tickDataProvider.js +18 -0
- package/dist/v3/entities/tickDataProvider.js.map +1 -0
- package/dist/v3/entities/tickListDataProvider.d.ts +15 -0
- package/dist/v3/entities/tickListDataProvider.js +23 -0
- package/dist/v3/entities/tickListDataProvider.js.map +1 -0
- package/dist/v3/entities/trade.d.ts +220 -0
- package/dist/v3/entities/trade.js +442 -0
- package/dist/v3/entities/trade.js.map +1 -0
- package/dist/v3/index.d.ts +9 -0
- package/dist/v3/index.js +26 -0
- package/dist/v3/index.js.map +1 -0
- package/dist/v3/internalConstants.d.ts +6 -0
- package/dist/v3/internalConstants.js +15 -0
- package/dist/v3/internalConstants.js.map +1 -0
- package/dist/v3/multicall.d.ts +9 -0
- package/dist/v3/multicall.js +20 -0
- package/dist/v3/multicall.js.map +1 -0
- package/dist/v3/nonfungiblePositionManager.d.ts +146 -0
- package/dist/v3/nonfungiblePositionManager.js +231 -0
- package/dist/v3/nonfungiblePositionManager.js.map +1 -0
- package/dist/v3/payments.d.ts +24 -0
- package/dist/v3/payments.js +55 -0
- package/dist/v3/payments.js.map +1 -0
- package/dist/v3/quoter.d.ts +37 -0
- package/dist/v3/quoter.js +76 -0
- package/dist/v3/quoter.js.map +1 -0
- package/dist/v3/selfPermit.d.ts +25 -0
- package/dist/v3/selfPermit.js +37 -0
- package/dist/v3/selfPermit.js.map +1 -0
- package/dist/v3/swapRouter.d.ts +51 -0
- package/dist/v3/swapRouter.js +147 -0
- package/dist/v3/swapRouter.js.map +1 -0
- package/dist/v3/utils/calldata.d.ts +20 -0
- package/dist/v3/utils/calldata.js +22 -0
- package/dist/v3/utils/calldata.js.map +1 -0
- package/dist/v3/utils/computePoolAddress.d.ts +18 -0
- package/dist/v3/utils/computePoolAddress.js +22 -0
- package/dist/v3/utils/computePoolAddress.js.map +1 -0
- package/dist/v3/utils/encodeRouteToPath.d.ts +8 -0
- package/dist/v3/utils/encodeRouteToPath.js +32 -0
- package/dist/v3/utils/encodeRouteToPath.js.map +1 -0
- package/dist/v3/utils/encodeSqrtRatioX96.d.ts +9 -0
- package/dist/v3/utils/encodeSqrtRatioX96.js +22 -0
- package/dist/v3/utils/encodeSqrtRatioX96.js.map +1 -0
- package/dist/v3/utils/fullMath.d.ts +8 -0
- package/dist/v3/utils/fullMath.js +23 -0
- package/dist/v3/utils/fullMath.js.map +1 -0
- package/dist/v3/utils/index.d.ts +17 -0
- package/dist/v3/utils/index.js +34 -0
- package/dist/v3/utils/index.js.map +1 -0
- package/dist/v3/utils/isSorted.d.ts +7 -0
- package/dist/v3/utils/isSorted.js +19 -0
- package/dist/v3/utils/isSorted.js.map +1 -0
- package/dist/v3/utils/liquidityMath.d.ts +8 -0
- package/dist/v3/utils/liquidityMath.js +24 -0
- package/dist/v3/utils/liquidityMath.js.map +1 -0
- package/dist/v3/utils/maxLiquidityForAmounts.d.ts +14 -0
- package/dist/v3/utils/maxLiquidityForAmounts.js +89 -0
- package/dist/v3/utils/maxLiquidityForAmounts.js.map +1 -0
- package/dist/v3/utils/mostSignificantBit.d.ts +2 -0
- package/dist/v3/utils/mostSignificantBit.js +29 -0
- package/dist/v3/utils/mostSignificantBit.js.map +1 -0
- package/dist/v3/utils/nearestUsableTick.d.ts +6 -0
- package/dist/v3/utils/nearestUsableTick.js +27 -0
- package/dist/v3/utils/nearestUsableTick.js.map +1 -0
- package/dist/v3/utils/position.d.ts +8 -0
- package/dist/v3/utils/position.js +23 -0
- package/dist/v3/utils/position.js.map +1 -0
- package/dist/v3/utils/priceTickConversions.d.ts +15 -0
- package/dist/v3/utils/priceTickConversions.js +52 -0
- package/dist/v3/utils/priceTickConversions.js.map +1 -0
- package/dist/v3/utils/sqrtPriceMath.d.ts +13 -0
- package/dist/v3/utils/sqrtPriceMath.js +97 -0
- package/dist/v3/utils/sqrtPriceMath.js.map +1 -0
- package/dist/v3/utils/swapMath.d.ts +9 -0
- package/dist/v3/utils/swapMath.js +79 -0
- package/dist/v3/utils/swapMath.js.map +1 -0
- package/dist/v3/utils/tickLibrary.d.ts +14 -0
- package/dist/v3/utils/tickLibrary.js +53 -0
- package/dist/v3/utils/tickLibrary.js.map +1 -0
- package/dist/v3/utils/tickList.d.ts +23 -0
- package/dist/v3/utils/tickList.js +110 -0
- package/dist/v3/utils/tickList.js.map +1 -0
- package/dist/v3/utils/tickMath.d.ts +34 -0
- package/dist/v3/utils/tickMath.js +127 -0
- package/dist/v3/utils/tickMath.js.map +1 -0
- package/package.json +80 -0
- package/universal-router.d.ts +1 -0
- package/universal-router.js +1 -0
- package/v3.d.ts +1 -0
- package/v3.js +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chains.js","sourceRoot":"","sources":["../../src/core/chains.ts"],"names":[],"mappings":";;;AAAA,IAAY,OA6BX;AA7BD,WAAY,OAAO;IACjB,2CAAW,CAAA;IACX,yCAAU,CAAA;IACV,kDAAkB,CAAA;IAClB,8CAAa,CAAA;IACb,6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AAA;AACnF,CAAC;AAFD,gEAEC;AAED,IAAY,kBAgBX;AAhBD,WAAY,kBAAkB;IAC5B,8BAA8B;IAC9B,mCAAa,CAAA;IACb,qCAAe,CAAA;IACf,mCAAa,CAAA;IACb,qCAAe,CAAA;IACf,uCAAiB,CAAA;IACjB,iCAAW,CAAA;IACX,mCAAa,CAAA;IACb,wCAAkB,CAAA;IAClB,wCAAkB,CAAA;IAClB,mCAAa,CAAA;IACb,mCAAa,CAAA;IACb,uCAAiB,CAAA;IACjB,kCAAY,CAAA;IACZ,uCAAiB,CAAA;AACnB,CAAC,EAhBW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAgB7B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import JSBI from 'jsbi';
|
|
2
|
+
export type BigintIsh = JSBI | string | number;
|
|
3
|
+
export declare enum TradeType {
|
|
4
|
+
EXACT_INPUT = 0,
|
|
5
|
+
EXACT_OUTPUT = 1
|
|
6
|
+
}
|
|
7
|
+
export declare enum Rounding {
|
|
8
|
+
ROUND_DOWN = 0,
|
|
9
|
+
ROUND_HALF_UP = 1,
|
|
10
|
+
ROUND_UP = 2
|
|
11
|
+
}
|
|
12
|
+
export declare const MaxUint256: JSBI;
|
|
@@ -0,0 +1,20 @@
|
|
|
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.MaxUint256 = exports.Rounding = exports.TradeType = void 0;
|
|
7
|
+
const jsbi_1 = __importDefault(require("jsbi"));
|
|
8
|
+
var TradeType;
|
|
9
|
+
(function (TradeType) {
|
|
10
|
+
TradeType[TradeType["EXACT_INPUT"] = 0] = "EXACT_INPUT";
|
|
11
|
+
TradeType[TradeType["EXACT_OUTPUT"] = 1] = "EXACT_OUTPUT";
|
|
12
|
+
})(TradeType = exports.TradeType || (exports.TradeType = {}));
|
|
13
|
+
var Rounding;
|
|
14
|
+
(function (Rounding) {
|
|
15
|
+
Rounding[Rounding["ROUND_DOWN"] = 0] = "ROUND_DOWN";
|
|
16
|
+
Rounding[Rounding["ROUND_HALF_UP"] = 1] = "ROUND_HALF_UP";
|
|
17
|
+
Rounding[Rounding["ROUND_UP"] = 2] = "ROUND_UP";
|
|
18
|
+
})(Rounding = exports.Rounding || (exports.Rounding = {}));
|
|
19
|
+
exports.MaxUint256 = jsbi_1.default.BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff');
|
|
20
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/core/constants.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AAKvB,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,uDAAW,CAAA;IACX,yDAAY,CAAA;AACd,CAAC,EAHW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAGpB;AAED,IAAY,QAIX;AAJD,WAAY,QAAQ;IAClB,mDAAU,CAAA;IACV,yDAAa,CAAA;IACb,+CAAQ,CAAA;AACV,CAAC,EAJW,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAInB;AAEY,QAAA,UAAU,GAAG,cAAI,CAAC,MAAM,CAAC,oEAAoE,CAAC,CAAA"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Currency } from './currency';
|
|
2
|
+
import { Token } from './token';
|
|
3
|
+
/**
|
|
4
|
+
* A currency is any fungible financial instrument, including Ether, all ERC20 tokens, and other chain-native currencies
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class BaseCurrency {
|
|
7
|
+
/**
|
|
8
|
+
* Returns whether the currency is native to the chain and must be wrapped (e.g. Ether)
|
|
9
|
+
*/
|
|
10
|
+
abstract readonly isNative: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Returns whether the currency is a token that is usable by the protocol without wrapping
|
|
13
|
+
*/
|
|
14
|
+
abstract readonly isToken: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* The chain ID on which this currency resides
|
|
17
|
+
*/
|
|
18
|
+
readonly chainId: number;
|
|
19
|
+
/**
|
|
20
|
+
* The decimals used in representing currency amounts
|
|
21
|
+
*/
|
|
22
|
+
readonly decimals: number;
|
|
23
|
+
/**
|
|
24
|
+
* The symbol of the currency, i.e. a short textual non-unique identifier
|
|
25
|
+
*/
|
|
26
|
+
readonly symbol?: string;
|
|
27
|
+
/**
|
|
28
|
+
* The name of the currency, i.e. a descriptive textual non-unique identifier
|
|
29
|
+
*/
|
|
30
|
+
readonly name?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Constructs an instance of the base class `BaseCurrency`.
|
|
33
|
+
* @param chainId the chain ID on which this currency resides
|
|
34
|
+
* @param decimals decimals of the currency
|
|
35
|
+
* @param symbol symbol of the currency
|
|
36
|
+
* @param name of the currency
|
|
37
|
+
*/
|
|
38
|
+
protected constructor(chainId: number, decimals: number, symbol?: string, name?: string);
|
|
39
|
+
/**
|
|
40
|
+
* Returns whether this currency is functionally equivalent to the other currency
|
|
41
|
+
* @param other the other currency
|
|
42
|
+
*/
|
|
43
|
+
abstract equals(other: Currency): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Return the wrapped version of this currency that can be used with protocol contracts.
|
|
46
|
+
*/
|
|
47
|
+
abstract get wrapped(): Token;
|
|
48
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
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.BaseCurrency = void 0;
|
|
7
|
+
const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
|
|
8
|
+
/**
|
|
9
|
+
* A currency is any fungible financial instrument, including Ether, all ERC20 tokens, and other chain-native currencies
|
|
10
|
+
*/
|
|
11
|
+
class BaseCurrency {
|
|
12
|
+
/**
|
|
13
|
+
* Constructs an instance of the base class `BaseCurrency`.
|
|
14
|
+
* @param chainId the chain ID on which this currency resides
|
|
15
|
+
* @param decimals decimals of the currency
|
|
16
|
+
* @param symbol symbol of the currency
|
|
17
|
+
* @param name of the currency
|
|
18
|
+
*/
|
|
19
|
+
constructor(chainId, decimals, symbol, name) {
|
|
20
|
+
(0, tiny_invariant_1.default)(Number.isSafeInteger(chainId), 'CHAIN_ID');
|
|
21
|
+
(0, tiny_invariant_1.default)(decimals >= 0 && decimals < 255 && Number.isInteger(decimals), 'DECIMALS');
|
|
22
|
+
this.chainId = chainId;
|
|
23
|
+
this.decimals = decimals;
|
|
24
|
+
this.symbol = symbol;
|
|
25
|
+
this.name = name;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.BaseCurrency = BaseCurrency;
|
|
29
|
+
//# sourceMappingURL=baseCurrency.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseCurrency.js","sourceRoot":"","sources":["../../../src/core/entities/baseCurrency.ts"],"names":[],"mappings":";;;;;;AAAA,oEAAsC;AAItC;;GAEG;AACH,MAAsB,YAAY;IA2BhC;;;;;;OAMG;IACH,YAAsB,OAAe,EAAE,QAAgB,EAAE,MAAe,EAAE,IAAa;QACrF,IAAA,wBAAS,EAAC,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC,CAAA;QACpD,IAAA,wBAAS,EAAC,QAAQ,IAAI,CAAC,IAAI,QAAQ,GAAG,GAAG,IAAI,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,UAAU,CAAC,CAAA;QAEpF,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;CAYF;AAtDD,oCAsDC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"currency.js","sourceRoot":"","sources":["../../../src/core/entities/currency.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Currency } from './currency';
|
|
2
|
+
import { NativeCurrency } from './nativeCurrency';
|
|
3
|
+
import { Token } from './token';
|
|
4
|
+
/**
|
|
5
|
+
* Ether is the main usage of a 'native' currency, i.e. for Ethereum mainnet and all testnets
|
|
6
|
+
*/
|
|
7
|
+
export declare class Ether extends NativeCurrency {
|
|
8
|
+
protected constructor(chainId: number);
|
|
9
|
+
get wrapped(): Token;
|
|
10
|
+
private static _etherCache;
|
|
11
|
+
static onChain(chainId: number): Ether;
|
|
12
|
+
equals(other: Currency): boolean;
|
|
13
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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.Ether = void 0;
|
|
7
|
+
const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
|
|
8
|
+
const nativeCurrency_1 = require("./nativeCurrency");
|
|
9
|
+
const weth9_1 = require("./weth9");
|
|
10
|
+
/**
|
|
11
|
+
* Ether is the main usage of a 'native' currency, i.e. for Ethereum mainnet and all testnets
|
|
12
|
+
*/
|
|
13
|
+
class Ether extends nativeCurrency_1.NativeCurrency {
|
|
14
|
+
constructor(chainId) {
|
|
15
|
+
super(chainId, 18, 'ETH', 'Ether');
|
|
16
|
+
}
|
|
17
|
+
get wrapped() {
|
|
18
|
+
const weth9 = weth9_1.WETH9[this.chainId];
|
|
19
|
+
(0, tiny_invariant_1.default)(!!weth9, 'WRAPPED');
|
|
20
|
+
return weth9;
|
|
21
|
+
}
|
|
22
|
+
static onChain(chainId) {
|
|
23
|
+
var _a;
|
|
24
|
+
return (_a = this._etherCache[chainId]) !== null && _a !== void 0 ? _a : (this._etherCache[chainId] = new Ether(chainId));
|
|
25
|
+
}
|
|
26
|
+
equals(other) {
|
|
27
|
+
return other.isNative && other.chainId === this.chainId;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.Ether = Ether;
|
|
31
|
+
Ether._etherCache = {};
|
|
32
|
+
//# sourceMappingURL=ether.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ether.js","sourceRoot":"","sources":["../../../src/core/entities/ether.ts"],"names":[],"mappings":";;;;;;AAAA,oEAAsC;AAEtC,qDAAiD;AAEjD,mCAA+B;AAE/B;;GAEG;AACH,MAAa,KAAM,SAAQ,+BAAc;IACvC,YAAsB,OAAe;QACnC,KAAK,CAAC,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,CAAA;IACpC,CAAC;IAED,IAAW,OAAO;QAChB,MAAM,KAAK,GAAG,aAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QACjC,IAAA,wBAAS,EAAC,CAAC,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;QAC7B,OAAO,KAAK,CAAA;IACd,CAAC;IAIM,MAAM,CAAC,OAAO,CAAC,OAAe;;QACnC,OAAO,MAAA,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,mCAAI,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAA;IACtF,CAAC;IAEM,MAAM,CAAC,KAAe;QAC3B,OAAO,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,OAAO,KAAK,IAAI,CAAC,OAAO,CAAA;IACzD,CAAC;;AAnBH,sBAoBC;AATgB,iBAAW,GAAiC,EAAE,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import JSBI from 'jsbi';
|
|
2
|
+
import { Currency } from '../currency';
|
|
3
|
+
import { Token } from '../token';
|
|
4
|
+
import { Fraction } from './fraction';
|
|
5
|
+
import { BigintIsh, Rounding } from '../../constants';
|
|
6
|
+
export declare class CurrencyAmount<T extends Currency> extends Fraction {
|
|
7
|
+
readonly currency: T;
|
|
8
|
+
readonly decimalScale: JSBI;
|
|
9
|
+
/**
|
|
10
|
+
* Returns a new currency amount instance from the unitless amount of token, i.e. the raw amount
|
|
11
|
+
* @param currency the currency in the amount
|
|
12
|
+
* @param rawAmount the raw token or ether amount
|
|
13
|
+
*/
|
|
14
|
+
static fromRawAmount<T extends Currency>(currency: T, rawAmount: BigintIsh): CurrencyAmount<T>;
|
|
15
|
+
/**
|
|
16
|
+
* Construct a currency amount with a denominator that is not equal to 1
|
|
17
|
+
* @param currency the currency
|
|
18
|
+
* @param numerator the numerator of the fractional token amount
|
|
19
|
+
* @param denominator the denominator of the fractional token amount
|
|
20
|
+
*/
|
|
21
|
+
static fromFractionalAmount<T extends Currency>(currency: T, numerator: BigintIsh, denominator: BigintIsh): CurrencyAmount<T>;
|
|
22
|
+
protected constructor(currency: T, numerator: BigintIsh, denominator?: BigintIsh);
|
|
23
|
+
add(other: CurrencyAmount<T>): CurrencyAmount<T>;
|
|
24
|
+
subtract(other: CurrencyAmount<T>): CurrencyAmount<T>;
|
|
25
|
+
multiply(other: Fraction | BigintIsh): CurrencyAmount<T>;
|
|
26
|
+
divide(other: Fraction | BigintIsh): CurrencyAmount<T>;
|
|
27
|
+
toSignificant(significantDigits?: number, format?: object, rounding?: Rounding): string;
|
|
28
|
+
toFixed(decimalPlaces?: number, format?: object, rounding?: Rounding): string;
|
|
29
|
+
toExact(format?: object): string;
|
|
30
|
+
get wrapped(): CurrencyAmount<Token>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
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.CurrencyAmount = void 0;
|
|
7
|
+
const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
|
|
8
|
+
const jsbi_1 = __importDefault(require("jsbi"));
|
|
9
|
+
const fraction_1 = require("./fraction");
|
|
10
|
+
const big_js_1 = __importDefault(require("big.js"));
|
|
11
|
+
const toformat_1 = __importDefault(require("toformat"));
|
|
12
|
+
const constants_1 = require("../../constants");
|
|
13
|
+
const Big = (0, toformat_1.default)(big_js_1.default);
|
|
14
|
+
class CurrencyAmount extends fraction_1.Fraction {
|
|
15
|
+
/**
|
|
16
|
+
* Returns a new currency amount instance from the unitless amount of token, i.e. the raw amount
|
|
17
|
+
* @param currency the currency in the amount
|
|
18
|
+
* @param rawAmount the raw token or ether amount
|
|
19
|
+
*/
|
|
20
|
+
static fromRawAmount(currency, rawAmount) {
|
|
21
|
+
return new CurrencyAmount(currency, rawAmount);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Construct a currency amount with a denominator that is not equal to 1
|
|
25
|
+
* @param currency the currency
|
|
26
|
+
* @param numerator the numerator of the fractional token amount
|
|
27
|
+
* @param denominator the denominator of the fractional token amount
|
|
28
|
+
*/
|
|
29
|
+
static fromFractionalAmount(currency, numerator, denominator) {
|
|
30
|
+
return new CurrencyAmount(currency, numerator, denominator);
|
|
31
|
+
}
|
|
32
|
+
constructor(currency, numerator, denominator) {
|
|
33
|
+
super(numerator, denominator);
|
|
34
|
+
(0, tiny_invariant_1.default)(jsbi_1.default.lessThanOrEqual(this.quotient, constants_1.MaxUint256), 'AMOUNT');
|
|
35
|
+
this.currency = currency;
|
|
36
|
+
this.decimalScale = jsbi_1.default.exponentiate(jsbi_1.default.BigInt(10), jsbi_1.default.BigInt(currency.decimals));
|
|
37
|
+
}
|
|
38
|
+
add(other) {
|
|
39
|
+
(0, tiny_invariant_1.default)(this.currency.equals(other.currency), 'CURRENCY');
|
|
40
|
+
const added = super.add(other);
|
|
41
|
+
return CurrencyAmount.fromFractionalAmount(this.currency, added.numerator, added.denominator);
|
|
42
|
+
}
|
|
43
|
+
subtract(other) {
|
|
44
|
+
(0, tiny_invariant_1.default)(this.currency.equals(other.currency), 'CURRENCY');
|
|
45
|
+
const subtracted = super.subtract(other);
|
|
46
|
+
return CurrencyAmount.fromFractionalAmount(this.currency, subtracted.numerator, subtracted.denominator);
|
|
47
|
+
}
|
|
48
|
+
multiply(other) {
|
|
49
|
+
const multiplied = super.multiply(other);
|
|
50
|
+
return CurrencyAmount.fromFractionalAmount(this.currency, multiplied.numerator, multiplied.denominator);
|
|
51
|
+
}
|
|
52
|
+
divide(other) {
|
|
53
|
+
const divided = super.divide(other);
|
|
54
|
+
return CurrencyAmount.fromFractionalAmount(this.currency, divided.numerator, divided.denominator);
|
|
55
|
+
}
|
|
56
|
+
toSignificant(significantDigits = 6, format, rounding = constants_1.Rounding.ROUND_DOWN) {
|
|
57
|
+
return super.divide(this.decimalScale).toSignificant(significantDigits, format, rounding);
|
|
58
|
+
}
|
|
59
|
+
toFixed(decimalPlaces = this.currency.decimals, format, rounding = constants_1.Rounding.ROUND_DOWN) {
|
|
60
|
+
(0, tiny_invariant_1.default)(decimalPlaces <= this.currency.decimals, 'DECIMALS');
|
|
61
|
+
return super.divide(this.decimalScale).toFixed(decimalPlaces, format, rounding);
|
|
62
|
+
}
|
|
63
|
+
toExact(format = { groupSeparator: '' }) {
|
|
64
|
+
Big.DP = this.currency.decimals;
|
|
65
|
+
return new Big(this.quotient.toString()).div(this.decimalScale.toString()).toFormat(format);
|
|
66
|
+
}
|
|
67
|
+
get wrapped() {
|
|
68
|
+
if (this.currency.isToken)
|
|
69
|
+
return this;
|
|
70
|
+
return CurrencyAmount.fromFractionalAmount(this.currency.wrapped, this.numerator, this.denominator);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.CurrencyAmount = CurrencyAmount;
|
|
74
|
+
//# sourceMappingURL=currencyAmount.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"currencyAmount.js","sourceRoot":"","sources":["../../../../src/core/entities/fractions/currencyAmount.ts"],"names":[],"mappings":";;;;;;AAAA,oEAAsC;AACtC,gDAAuB;AAGvB,yCAAqC;AACrC,oDAAyB;AAEzB,wDAA+B;AAC/B,+CAAiE;AAEjE,MAAM,GAAG,GAAG,IAAA,kBAAQ,EAAC,gBAAI,CAAC,CAAA;AAE1B,MAAa,cAAmC,SAAQ,mBAAQ;IAI9D;;;;OAIG;IACI,MAAM,CAAC,aAAa,CAAqB,QAAW,EAAE,SAAoB;QAC/E,OAAO,IAAI,cAAc,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;IAChD,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,oBAAoB,CAChC,QAAW,EACX,SAAoB,EACpB,WAAsB;QAEtB,OAAO,IAAI,cAAc,CAAC,QAAQ,EAAE,SAAS,EAAE,WAAW,CAAC,CAAA;IAC7D,CAAC;IAED,YAAsB,QAAW,EAAE,SAAoB,EAAE,WAAuB;QAC9E,KAAK,CAAC,SAAS,EAAE,WAAW,CAAC,CAAA;QAC7B,IAAA,wBAAS,EAAC,cAAI,CAAC,eAAe,CAAC,IAAI,CAAC,QAAQ,EAAE,sBAAU,CAAC,EAAE,QAAQ,CAAC,CAAA;QACpE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,YAAY,GAAG,cAAI,CAAC,YAAY,CAAC,cAAI,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,cAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAA;IACxF,CAAC;IAEM,GAAG,CAAC,KAAwB;QACjC,IAAA,wBAAS,EAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,UAAU,CAAC,CAAA;Q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C,QAAQ,CAAC,QAAQ,EAC9C,MAAe,EACf,WAAqB,oBAAQ,CAAC,UAAU;QAExC,IAAA,wBAAS,EAAC,aAAa,IAAI,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAA;QAC9D,OAAO,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,aAAa,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAA;IACjF,CAAC;IAEM,OAAO,CAAC,SAAiB,EAAE,cAAc,EAAE,EAAE,EAAE;QACpD,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAA;QAC/B,OAAO,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IAC7F,CAAC;IAED,IAAW,OAAO;QAChB,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO;YAAE,OAAO,IAA6B,CAAA;QAC/D,OAAO,cAAc,CAAC,oBAAoB,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC,CAAA;IACrG,CAAC;CACF;AAlFD,wCAkFC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import JSBI from 'jsbi';
|
|
2
|
+
import { BigintIsh, Rounding } from '../../constants';
|
|
3
|
+
export declare class Fraction {
|
|
4
|
+
readonly numerator: JSBI;
|
|
5
|
+
readonly denominator: JSBI;
|
|
6
|
+
constructor(numerator: BigintIsh, denominator?: BigintIsh);
|
|
7
|
+
private static tryParseFraction;
|
|
8
|
+
get quotient(): JSBI;
|
|
9
|
+
get remainder(): Fraction;
|
|
10
|
+
invert(): Fraction;
|
|
11
|
+
add(other: Fraction | BigintIsh): Fraction;
|
|
12
|
+
subtract(other: Fraction | BigintIsh): Fraction;
|
|
13
|
+
lessThan(other: Fraction | BigintIsh): boolean;
|
|
14
|
+
equalTo(other: Fraction | BigintIsh): boolean;
|
|
15
|
+
greaterThan(other: Fraction | BigintIsh): boolean;
|
|
16
|
+
multiply(other: Fraction | BigintIsh): Fraction;
|
|
17
|
+
divide(other: Fraction | BigintIsh): Fraction;
|
|
18
|
+
toSignificant(significantDigits: number, format?: object, rounding?: Rounding): string;
|
|
19
|
+
toFixed(decimalPlaces: number, format?: object, rounding?: Rounding): string;
|
|
20
|
+
/**
|
|
21
|
+
* Helper method for converting any super class back to a fraction
|
|
22
|
+
*/
|
|
23
|
+
get asFraction(): Fraction;
|
|
24
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
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.Fraction = void 0;
|
|
7
|
+
const jsbi_1 = __importDefault(require("jsbi"));
|
|
8
|
+
const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
|
|
9
|
+
const decimal_js_light_1 = __importDefault(require("decimal.js-light"));
|
|
10
|
+
const big_js_1 = __importDefault(require("big.js"));
|
|
11
|
+
const toformat_1 = __importDefault(require("toformat"));
|
|
12
|
+
const constants_1 = require("../../constants");
|
|
13
|
+
const Decimal = (0, toformat_1.default)(decimal_js_light_1.default);
|
|
14
|
+
const Big = (0, toformat_1.default)(big_js_1.default);
|
|
15
|
+
const toSignificantRounding = {
|
|
16
|
+
[constants_1.Rounding.ROUND_DOWN]: Decimal.ROUND_DOWN,
|
|
17
|
+
[constants_1.Rounding.ROUND_HALF_UP]: Decimal.ROUND_HALF_UP,
|
|
18
|
+
[constants_1.Rounding.ROUND_UP]: Decimal.ROUND_UP
|
|
19
|
+
};
|
|
20
|
+
const toFixedRounding = {
|
|
21
|
+
[constants_1.Rounding.ROUND_DOWN]: 0 /* RoundingMode.RoundDown */,
|
|
22
|
+
[constants_1.Rounding.ROUND_HALF_UP]: 1 /* RoundingMode.RoundHalfUp */,
|
|
23
|
+
[constants_1.Rounding.ROUND_UP]: 3 /* RoundingMode.RoundUp */
|
|
24
|
+
};
|
|
25
|
+
class Fraction {
|
|
26
|
+
constructor(numerator, denominator = jsbi_1.default.BigInt(1)) {
|
|
27
|
+
this.numerator = jsbi_1.default.BigInt(numerator);
|
|
28
|
+
this.denominator = jsbi_1.default.BigInt(denominator);
|
|
29
|
+
}
|
|
30
|
+
static tryParseFraction(fractionish) {
|
|
31
|
+
if (fractionish instanceof jsbi_1.default || typeof fractionish === 'number' || typeof fractionish === 'string')
|
|
32
|
+
return new Fraction(fractionish);
|
|
33
|
+
if ('numerator' in fractionish && 'denominator' in fractionish)
|
|
34
|
+
return fractionish;
|
|
35
|
+
throw new Error('Could not parse fraction');
|
|
36
|
+
}
|
|
37
|
+
// performs floor division
|
|
38
|
+
get quotient() {
|
|
39
|
+
return jsbi_1.default.divide(this.numerator, this.denominator);
|
|
40
|
+
}
|
|
41
|
+
// remainder after floor division
|
|
42
|
+
get remainder() {
|
|
43
|
+
return new Fraction(jsbi_1.default.remainder(this.numerator, this.denominator), this.denominator);
|
|
44
|
+
}
|
|
45
|
+
invert() {
|
|
46
|
+
return new Fraction(this.denominator, this.numerator);
|
|
47
|
+
}
|
|
48
|
+
add(other) {
|
|
49
|
+
const otherParsed = Fraction.tryParseFraction(other);
|
|
50
|
+
if (jsbi_1.default.equal(this.denominator, otherParsed.denominator)) {
|
|
51
|
+
return new Fraction(jsbi_1.default.add(this.numerator, otherParsed.numerator), this.denominator);
|
|
52
|
+
}
|
|
53
|
+
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));
|
|
54
|
+
}
|
|
55
|
+
subtract(other) {
|
|
56
|
+
const otherParsed = Fraction.tryParseFraction(other);
|
|
57
|
+
if (jsbi_1.default.equal(this.denominator, otherParsed.denominator)) {
|
|
58
|
+
return new Fraction(jsbi_1.default.subtract(this.numerator, otherParsed.numerator), this.denominator);
|
|
59
|
+
}
|
|
60
|
+
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));
|
|
61
|
+
}
|
|
62
|
+
lessThan(other) {
|
|
63
|
+
const otherParsed = Fraction.tryParseFraction(other);
|
|
64
|
+
return jsbi_1.default.lessThan(jsbi_1.default.multiply(this.numerator, otherParsed.denominator), jsbi_1.default.multiply(otherParsed.numerator, this.denominator));
|
|
65
|
+
}
|
|
66
|
+
equalTo(other) {
|
|
67
|
+
const otherParsed = Fraction.tryParseFraction(other);
|
|
68
|
+
return jsbi_1.default.equal(jsbi_1.default.multiply(this.numerator, otherParsed.denominator), jsbi_1.default.multiply(otherParsed.numerator, this.denominator));
|
|
69
|
+
}
|
|
70
|
+
greaterThan(other) {
|
|
71
|
+
const otherParsed = Fraction.tryParseFraction(other);
|
|
72
|
+
return jsbi_1.default.greaterThan(jsbi_1.default.multiply(this.numerator, otherParsed.denominator), jsbi_1.default.multiply(otherParsed.numerator, this.denominator));
|
|
73
|
+
}
|
|
74
|
+
multiply(other) {
|
|
75
|
+
const otherParsed = Fraction.tryParseFraction(other);
|
|
76
|
+
return new Fraction(jsbi_1.default.multiply(this.numerator, otherParsed.numerator), jsbi_1.default.multiply(this.denominator, otherParsed.denominator));
|
|
77
|
+
}
|
|
78
|
+
divide(other) {
|
|
79
|
+
const otherParsed = Fraction.tryParseFraction(other);
|
|
80
|
+
return new Fraction(jsbi_1.default.multiply(this.numerator, otherParsed.denominator), jsbi_1.default.multiply(this.denominator, otherParsed.numerator));
|
|
81
|
+
}
|
|
82
|
+
toSignificant(significantDigits, format = { groupSeparator: '' }, rounding = constants_1.Rounding.ROUND_HALF_UP) {
|
|
83
|
+
(0, tiny_invariant_1.default)(Number.isInteger(significantDigits), `${significantDigits} is not an integer.`);
|
|
84
|
+
(0, tiny_invariant_1.default)(significantDigits > 0, `${significantDigits} is not positive.`);
|
|
85
|
+
Decimal.set({ precision: significantDigits + 1, rounding: toSignificantRounding[rounding] });
|
|
86
|
+
const quotient = new Decimal(this.numerator.toString())
|
|
87
|
+
.div(this.denominator.toString())
|
|
88
|
+
.toSignificantDigits(significantDigits);
|
|
89
|
+
return quotient.toFormat(quotient.decimalPlaces(), format);
|
|
90
|
+
}
|
|
91
|
+
toFixed(decimalPlaces, format = { groupSeparator: '' }, rounding = constants_1.Rounding.ROUND_HALF_UP) {
|
|
92
|
+
(0, tiny_invariant_1.default)(Number.isInteger(decimalPlaces), `${decimalPlaces} is not an integer.`);
|
|
93
|
+
(0, tiny_invariant_1.default)(decimalPlaces >= 0, `${decimalPlaces} is negative.`);
|
|
94
|
+
Big.DP = decimalPlaces;
|
|
95
|
+
Big.RM = toFixedRounding[rounding];
|
|
96
|
+
return new Big(this.numerator.toString()).div(this.denominator.toString()).toFormat(decimalPlaces, format);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Helper method for converting any super class back to a fraction
|
|
100
|
+
*/
|
|
101
|
+
get asFraction() {
|
|
102
|
+
return new Fraction(this.numerator, this.denominator);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.Fraction = Fraction;
|
|
106
|
+
//# sourceMappingURL=fraction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fraction.js","sourceRoot":"","sources":["../../../../src/core/entities/fractions/fraction.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AACvB,oEAAsC;AACtC,wEAAuC;AACvC,oDAA2C;AAC3C,wDAA+B;AAE/B,+CAAqD;AAErD,MAAM,OAAO,GAAG,IAAA,kBAAQ,EAA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AC,CAAA;QACzC,OAAO,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,aAAa,EAAE,EAAE,MAAM,CAAC,CAAA;IAC5D,CAAC;IAEM,OAAO,CACZ,aAAqB,EACrB,SAAiB,EAAE,cAAc,EAAE,EAAE,EAAE,EACvC,WAAqB,oBAAQ,CAAC,aAAa;QAE3C,IAAA,wBAAS,EAAC,MAAM,CAAC,SAAS,CAAC,aAAa,CAAC,EAAE,GAAG,aAAa,qBAAqB,CAAC,CAAA;QACjF,IAAA,wBAAS,EAAC,aAAa,IAAI,CAAC,EAAE,GAAG,aAAa,eAAe,CAAC,CAAA;QAE9D,GAAG,CAAC,EAAE,GAAG,aAAa,CAAA;QACtB,GAAG,CAAC,EAAE,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAA;QAClC,OAAO,IAAI,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC,CAAA;IAC5G,CAAC;IAED;;OAEG;IACH,IAAW,UAAU;QACnB,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC,CAAA;IACvD,CAAC;CACF;AArID,4BAqIC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Price = exports.Percent = exports.Fraction = exports.CurrencyAmount = void 0;
|
|
4
|
+
var currencyAmount_1 = require("./currencyAmount");
|
|
5
|
+
Object.defineProperty(exports, "CurrencyAmount", { enumerable: true, get: function () { return currencyAmount_1.CurrencyAmount; } });
|
|
6
|
+
var fraction_1 = require("./fraction");
|
|
7
|
+
Object.defineProperty(exports, "Fraction", { enumerable: true, get: function () { return fraction_1.Fraction; } });
|
|
8
|
+
var percent_1 = require("./percent");
|
|
9
|
+
Object.defineProperty(exports, "Percent", { enumerable: true, get: function () { return percent_1.Percent; } });
|
|
10
|
+
var price_1 = require("./price");
|
|
11
|
+
Object.defineProperty(exports, "Price", { enumerable: true, get: function () { return price_1.Price; } });
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/core/entities/fractions/index.ts"],"names":[],"mappings":";;;AAAA,mDAAiD;AAAxC,gHAAA,cAAc,OAAA;AACvB,uCAAqC;AAA5B,oGAAA,QAAQ,OAAA;AACjB,qCAAmC;AAA1B,kGAAA,OAAO,OAAA;AAChB,iCAA+B;AAAtB,8FAAA,KAAK,OAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BigintIsh, Rounding } from '../../constants';
|
|
2
|
+
import { Fraction } from './fraction';
|
|
3
|
+
export declare class Percent extends Fraction {
|
|
4
|
+
/**
|
|
5
|
+
* This boolean prevents a fraction from being interpreted as a Percent
|
|
6
|
+
*/
|
|
7
|
+
readonly isPercent: true;
|
|
8
|
+
add(other: Fraction | BigintIsh): Percent;
|
|
9
|
+
subtract(other: Fraction | BigintIsh): Percent;
|
|
10
|
+
multiply(other: Fraction | BigintIsh): Percent;
|
|
11
|
+
divide(other: Fraction | BigintIsh): Percent;
|
|
12
|
+
toSignificant(significantDigits?: number, format?: object, rounding?: Rounding): string;
|
|
13
|
+
toFixed(decimalPlaces?: number, format?: object, rounding?: Rounding): string;
|
|
14
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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.Percent = void 0;
|
|
7
|
+
const jsbi_1 = __importDefault(require("jsbi"));
|
|
8
|
+
const fraction_1 = require("./fraction");
|
|
9
|
+
const ONE_HUNDRED = new fraction_1.Fraction(jsbi_1.default.BigInt(100));
|
|
10
|
+
/**
|
|
11
|
+
* Converts a fraction to a percent
|
|
12
|
+
* @param fraction the fraction to convert
|
|
13
|
+
*/
|
|
14
|
+
function toPercent(fraction) {
|
|
15
|
+
return new Percent(fraction.numerator, fraction.denominator);
|
|
16
|
+
}
|
|
17
|
+
class Percent extends fraction_1.Fraction {
|
|
18
|
+
constructor() {
|
|
19
|
+
super(...arguments);
|
|
20
|
+
/**
|
|
21
|
+
* This boolean prevents a fraction from being interpreted as a Percent
|
|
22
|
+
*/
|
|
23
|
+
this.isPercent = true;
|
|
24
|
+
}
|
|
25
|
+
add(other) {
|
|
26
|
+
return toPercent(super.add(other));
|
|
27
|
+
}
|
|
28
|
+
subtract(other) {
|
|
29
|
+
return toPercent(super.subtract(other));
|
|
30
|
+
}
|
|
31
|
+
multiply(other) {
|
|
32
|
+
return toPercent(super.multiply(other));
|
|
33
|
+
}
|
|
34
|
+
divide(other) {
|
|
35
|
+
return toPercent(super.divide(other));
|
|
36
|
+
}
|
|
37
|
+
toSignificant(significantDigits = 5, format, rounding) {
|
|
38
|
+
return super.multiply(ONE_HUNDRED).toSignificant(significantDigits, format, rounding);
|
|
39
|
+
}
|
|
40
|
+
toFixed(decimalPlaces = 2, format, rounding) {
|
|
41
|
+
return super.multiply(ONE_HUNDRED).toFixed(decimalPlaces, format, rounding);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.Percent = Percent;
|
|
45
|
+
//# sourceMappingURL=percent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"percent.js","sourceRoot":"","sources":["../../../../src/core/entities/fractions/percent.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AAEvB,yCAAqC;AAErC,MAAM,WAAW,GAAG,IAAI,mBAAQ,CAAC,cAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;AAElD;;;GAGG;AACH,SAAS,SAAS,CAAC,QAAkB;IACnC,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAA;AAC9D,CAAC;AAED,MAAa,OAAQ,SAAQ,mBAAQ;IAArC;;QACE;;WAEG;QACa,cAAS,GAAS,IAAI,CAAA;IAyBxC,CAAC;IAvBC,GAAG,CAAC,KAA2B;QAC7B,OAAO,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAA;IACpC,CAAC;IAED,QAAQ,CAAC,KAA2B;QAClC,OAAO,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAA;IACzC,CAAC;IAED,QAAQ,CAAC,KAA2B;QAClC,OAAO,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAA;IACzC,CAAC;IAED,MAAM,CAAC,KAA2B;QAChC,OAAO,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;IACvC,CAAC;IAEM,aAAa,CAAC,oBAA4B,CAAC,EAAE,MAAe,EAAE,QAAmB;QACtF,OAAO,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,aAAa,CAAC,iBAAiB,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAA;IACvF,CAAC;IAEM,OAAO,CAAC,gBAAwB,CAAC,EAAE,MAAe,EAAE,QAAmB;QAC5E,OAAO,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,aAAa,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAA;IAC7E,CAAC;CACF;AA7BD,0BA6BC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { BigintIsh, Rounding } from '../../constants';
|
|
2
|
+
import { Currency } from '../currency';
|
|
3
|
+
import { Fraction } from './fraction';
|
|
4
|
+
import { CurrencyAmount } from './currencyAmount';
|
|
5
|
+
export declare class Price<TBase extends Currency, TQuote extends Currency> extends Fraction {
|
|
6
|
+
readonly baseCurrency: TBase;
|
|
7
|
+
readonly quoteCurrency: TQuote;
|
|
8
|
+
readonly scalar: Fraction;
|
|
9
|
+
/**
|
|
10
|
+
* Construct a price, either with the base and quote currency amount, or the
|
|
11
|
+
* @param args
|
|
12
|
+
*/
|
|
13
|
+
constructor(...args: [TBase, TQuote, BigintIsh, BigintIsh] | [{
|
|
14
|
+
baseAmount: CurrencyAmount<TBase>;
|
|
15
|
+
quoteAmount: CurrencyAmount<TQuote>;
|
|
16
|
+
}]);
|
|
17
|
+
/**
|
|
18
|
+
* Flip the price, switching the base and quote currency
|
|
19
|
+
*/
|
|
20
|
+
invert(): Price<TQuote, TBase>;
|
|
21
|
+
/**
|
|
22
|
+
* Multiply the price by another price, returning a new price. The other price must have the same base currency as this price's quote currency
|
|
23
|
+
* @param other the other price
|
|
24
|
+
*/
|
|
25
|
+
multiply<TOtherQuote extends Currency>(other: Price<TQuote, TOtherQuote>): Price<TBase, TOtherQuote>;
|
|
26
|
+
/**
|
|
27
|
+
* Return the amount of quote currency corresponding to a given amount of the base currency
|
|
28
|
+
* @param currencyAmount the amount of base currency to quote against the price
|
|
29
|
+
*/
|
|
30
|
+
quote(currencyAmount: CurrencyAmount<TBase>): CurrencyAmount<TQuote>;
|
|
31
|
+
/**
|
|
32
|
+
* Get the value scaled by decimals for formatting
|
|
33
|
+
* @private
|
|
34
|
+
*/
|
|
35
|
+
private get adjustedForDecimals();
|
|
36
|
+
toSignificant(significantDigits?: number, format?: object, rounding?: Rounding): string;
|
|
37
|
+
toFixed(decimalPlaces?: number, format?: object, rounding?: Rounding): string;
|
|
38
|
+
}
|