@nadohq/shared 0.1.0-alpha.8 → 0.1.0
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/abis/index.cjs +12 -12
- package/dist/abis/index.cjs.map +1 -1
- package/dist/abis/index.d.cts +6 -6
- package/dist/abis/index.d.ts +6 -6
- package/dist/abis/index.js +6 -6
- package/dist/abis/index.js.map +1 -1
- package/dist/{chunk-TUJ4HQKF.js → chunk-2GPIH63F.js} +3 -3
- package/dist/chunk-2GPIH63F.js.map +1 -0
- package/dist/consts/chainEnvToChain.cjs +2 -2
- package/dist/consts/chainEnvToChain.cjs.map +1 -1
- package/dist/consts/chainEnvToChain.d.cts +329 -39
- package/dist/consts/chainEnvToChain.d.ts +329 -39
- package/dist/consts/chainEnvToChain.js +3 -3
- package/dist/consts/chainEnvToChain.js.map +1 -1
- package/dist/consts/productIds.cjs +1 -1
- package/dist/consts/productIds.cjs.map +1 -1
- package/dist/consts/productIds.d.cts +1 -1
- package/dist/consts/productIds.d.ts +1 -1
- package/dist/consts/productIds.js +1 -1
- package/dist/consts/productIds.js.map +1 -1
- package/dist/deployments/core/deployment.inkMainnet.json +13 -0
- package/dist/deployments/core/deployment.inkSepolia.json +13 -0
- package/dist/deployments/index.cjs +6 -6
- package/dist/deployments/index.cjs.map +1 -1
- package/dist/deployments/index.js +5 -5
- package/dist/deployments/index.js.map +1 -1
- package/dist/eip712/eip712ValueTypes.cjs.map +1 -1
- package/dist/eip712/eip712ValueTypes.d.cts +3 -3
- package/dist/eip712/eip712ValueTypes.d.ts +3 -3
- package/dist/eip712/getNadoEIP712Domain.cjs.map +1 -1
- package/dist/eip712/getNadoEIP712Domain.js.map +1 -1
- package/dist/eip712/getNadoEIP712PrimaryType.d.cts +1 -1
- package/dist/eip712/getNadoEIP712PrimaryType.d.ts +1 -1
- package/dist/eip712/getNadoEIP712Types.d.cts +1 -1
- package/dist/eip712/getNadoEIP712Types.d.ts +1 -1
- package/dist/eip712/getNadoEIP712Values.d.cts +1 -1
- package/dist/eip712/getNadoEIP712Values.d.ts +1 -1
- package/dist/eip712/getSignedTransactionRequest.d.cts +1 -1
- package/dist/eip712/getSignedTransactionRequest.d.ts +1 -1
- package/dist/eip712/index.cjs +13 -13
- package/dist/eip712/index.cjs.map +1 -1
- package/dist/eip712/index.d.cts +9 -9
- package/dist/eip712/index.d.ts +9 -9
- package/dist/eip712/index.js +6 -6
- package/dist/eip712/index.js.map +1 -1
- package/dist/eip712/orderDigest.d.cts +1 -1
- package/dist/eip712/orderDigest.d.ts +1 -1
- package/dist/eip712/signableRequestType.d.cts +1 -1
- package/dist/eip712/signableRequestType.d.ts +1 -1
- package/dist/eip712/signatureParamTypes.cjs.map +1 -1
- package/dist/eip712/signatureParamTypes.d.cts +13 -13
- package/dist/eip712/signatureParamTypes.d.ts +13 -13
- package/dist/encoding/encoding.cjs +21 -0
- package/dist/encoding/encoding.cjs.map +1 -1
- package/dist/encoding/encoding.d.cts +28 -4
- package/dist/encoding/encoding.d.ts +28 -4
- package/dist/encoding/encoding.js +24 -1
- package/dist/encoding/encoding.js.map +1 -1
- package/dist/encoding/index.d.cts +3 -3
- package/dist/encoding/index.d.ts +3 -3
- package/dist/execute/approveDepositAllowance.cjs.map +1 -1
- package/dist/execute/approveDepositAllowance.d.cts +2 -2
- package/dist/execute/approveDepositAllowance.d.ts +2 -2
- package/dist/execute/approveDepositAllowance.js.map +1 -1
- package/dist/execute/depositCollateral.cjs.map +1 -1
- package/dist/execute/depositCollateral.d.cts +2 -2
- package/dist/execute/depositCollateral.d.ts +2 -2
- package/dist/execute/depositCollateral.js.map +1 -1
- package/dist/execute/index.d.cts +1 -1
- package/dist/execute/index.d.ts +1 -1
- package/dist/index.d.cts +35 -35
- package/dist/index.d.ts +35 -35
- package/dist/types/ChainEnv.cjs +1 -1
- package/dist/types/ChainEnv.cjs.map +1 -1
- package/dist/types/ChainEnv.d.cts +2 -2
- package/dist/types/ChainEnv.d.ts +2 -2
- package/dist/types/ChainEnv.js +1 -1
- package/dist/types/ChainEnv.js.map +1 -1
- package/dist/types/balanceTypes.cjs.map +1 -1
- package/dist/types/balanceTypes.d.cts +5 -5
- package/dist/types/balanceTypes.d.ts +5 -5
- package/dist/types/healthTypes.cjs.map +1 -1
- package/dist/types/healthTypes.d.cts +4 -4
- package/dist/types/healthTypes.d.ts +4 -4
- package/dist/types/index.cjs +7 -7
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.cts +4 -4
- package/dist/types/index.d.ts +4 -4
- package/dist/types/index.js +3 -3
- package/dist/types/index.js.map +1 -1
- package/dist/types/marketTypes.cjs.map +1 -1
- package/dist/types/marketTypes.d.cts +4 -4
- package/dist/types/marketTypes.d.ts +4 -4
- package/dist/types/orderAppendixTypes.cjs.map +1 -1
- package/dist/types/orderAppendixTypes.d.cts +27 -3
- package/dist/types/orderAppendixTypes.d.ts +27 -3
- package/dist/types/productTypes.cjs.map +1 -1
- package/dist/types/productTypes.d.cts +16 -16
- package/dist/types/productTypes.d.ts +16 -16
- package/dist/types/productTypes.js.map +1 -1
- package/dist/types/viemTypes.d.cts +1 -1
- package/dist/types/viemTypes.d.ts +1 -1
- package/dist/utils/balanceValue.cjs.map +1 -1
- package/dist/utils/balanceValue.d.cts +5 -5
- package/dist/utils/balanceValue.d.ts +5 -5
- package/dist/utils/balanceValue.js.map +1 -1
- package/dist/utils/bytes32.d.cts +1 -1
- package/dist/utils/bytes32.d.ts +1 -1
- package/dist/utils/bytes32.test.cjs +2 -2
- package/dist/utils/bytes32.test.cjs.map +1 -1
- package/dist/utils/bytes32.test.js +1 -1
- package/dist/utils/createDeterministicLinkedSignerPrivateKey.cjs.map +1 -1
- package/dist/utils/createDeterministicLinkedSignerPrivateKey.js.map +1 -1
- package/dist/utils/index.cjs +12 -12
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.cts +22 -22
- package/dist/utils/index.d.ts +22 -22
- package/dist/utils/index.js +6 -6
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/interest.cjs +9 -9
- package/dist/utils/interest.cjs.map +1 -1
- package/dist/utils/interest.d.cts +8 -8
- package/dist/utils/interest.d.ts +8 -8
- package/dist/utils/interest.js +10 -14
- package/dist/utils/interest.js.map +1 -1
- package/dist/utils/math/{BigDecimals.cjs → BigNumbers.cjs} +13 -13
- package/dist/utils/math/BigNumbers.cjs.map +1 -0
- package/dist/utils/math/BigNumbers.d.cts +10 -0
- package/dist/utils/math/BigNumbers.d.ts +10 -0
- package/dist/utils/math/BigNumbers.js +14 -0
- package/dist/utils/math/BigNumbers.js.map +1 -0
- package/dist/utils/math/{bigDecimal.cjs → bigNumber.cjs} +12 -14
- package/dist/utils/math/bigNumber.cjs.map +1 -0
- package/dist/utils/math/bigNumber.d.cts +17 -0
- package/dist/utils/math/bigNumber.d.ts +17 -0
- package/dist/utils/math/bigNumber.js +22 -0
- package/dist/utils/math/bigNumber.js.map +1 -0
- package/dist/utils/math/clamp.cjs +3 -3
- package/dist/utils/math/clamp.cjs.map +1 -1
- package/dist/utils/math/clamp.d.cts +5 -5
- package/dist/utils/math/clamp.d.ts +5 -5
- package/dist/utils/math/clamp.js +2 -2
- package/dist/utils/math/clamp.js.map +1 -1
- package/dist/utils/math/decimalAdjustment.cjs +5 -5
- package/dist/utils/math/decimalAdjustment.cjs.map +1 -1
- package/dist/utils/math/decimalAdjustment.d.cts +6 -6
- package/dist/utils/math/decimalAdjustment.d.ts +6 -6
- package/dist/utils/math/decimalAdjustment.js +5 -5
- package/dist/utils/math/decimalAdjustment.js.map +1 -1
- package/dist/utils/math/index.cjs +10 -10
- package/dist/utils/math/index.cjs.map +1 -1
- package/dist/utils/math/index.d.cts +7 -7
- package/dist/utils/math/index.d.ts +7 -7
- package/dist/utils/math/index.js +5 -5
- package/dist/utils/math/index.js.map +1 -1
- package/dist/utils/math/{sumBigDecimalBy.cjs → sumBigNumberBy.cjs} +10 -10
- package/dist/utils/math/sumBigNumberBy.cjs.map +1 -0
- package/dist/utils/math/sumBigNumberBy.d.cts +10 -0
- package/dist/utils/math/sumBigNumberBy.d.ts +10 -0
- package/dist/utils/math/sumBigNumberBy.js +13 -0
- package/dist/utils/math/sumBigNumberBy.js.map +1 -0
- package/dist/utils/math/toBigInt.cjs.map +1 -1
- package/dist/utils/math/toBigInt.d.cts +3 -3
- package/dist/utils/math/toBigInt.d.ts +3 -3
- package/dist/utils/math/toBigInt.js.map +1 -1
- package/dist/utils/math/toIntegerString.cjs +2 -2
- package/dist/utils/math/toIntegerString.cjs.map +1 -1
- package/dist/utils/math/toIntegerString.d.cts +3 -3
- package/dist/utils/math/toIntegerString.d.ts +3 -3
- package/dist/utils/math/toIntegerString.js +2 -2
- package/dist/utils/math/toIntegerString.js.map +1 -1
- package/dist/utils/orders/appendix/appendixIsolatedValue.cjs +50 -0
- package/dist/utils/orders/appendix/appendixIsolatedValue.cjs.map +1 -0
- package/dist/utils/orders/appendix/appendixIsolatedValue.d.cts +26 -0
- package/dist/utils/orders/appendix/appendixIsolatedValue.d.ts +26 -0
- package/dist/utils/orders/appendix/appendixIsolatedValue.js +31 -0
- package/dist/utils/orders/appendix/appendixIsolatedValue.js.map +1 -0
- package/dist/utils/orders/appendix/appendixTwapValue.cjs +3 -4
- package/dist/utils/orders/appendix/appendixTwapValue.cjs.map +1 -1
- package/dist/utils/orders/appendix/appendixTwapValue.d.cts +12 -14
- package/dist/utils/orders/appendix/appendixTwapValue.d.ts +12 -14
- package/dist/utils/orders/appendix/appendixTwapValue.js +3 -4
- package/dist/utils/orders/appendix/appendixTwapValue.js.map +1 -1
- package/dist/utils/orders/appendix/index.cjs +4 -4
- package/dist/utils/orders/appendix/index.cjs.map +1 -1
- package/dist/utils/orders/appendix/index.d.cts +3 -3
- package/dist/utils/orders/appendix/index.d.ts +3 -3
- package/dist/utils/orders/appendix/index.js +2 -2
- package/dist/utils/orders/appendix/index.js.map +1 -1
- package/dist/utils/orders/appendix/orderAppendix.test.cjs +67 -14
- package/dist/utils/orders/appendix/orderAppendix.test.cjs.map +1 -1
- package/dist/utils/orders/appendix/orderAppendix.test.js +66 -13
- package/dist/utils/orders/appendix/orderAppendix.test.js.map +1 -1
- package/dist/utils/orders/appendix/packOrderAppendix.cjs +9 -5
- package/dist/utils/orders/appendix/packOrderAppendix.cjs.map +1 -1
- package/dist/utils/orders/appendix/packOrderAppendix.d.cts +1 -1
- package/dist/utils/orders/appendix/packOrderAppendix.d.ts +1 -1
- package/dist/utils/orders/appendix/packOrderAppendix.js +9 -5
- package/dist/utils/orders/appendix/packOrderAppendix.js.map +1 -1
- package/dist/utils/orders/appendix/types.cjs.map +1 -1
- package/dist/utils/orders/appendix/types.d.cts +6 -4
- package/dist/utils/orders/appendix/types.d.ts +6 -4
- package/dist/utils/orders/appendix/unpackOrderAppendix.cjs +22 -5
- package/dist/utils/orders/appendix/unpackOrderAppendix.cjs.map +1 -1
- package/dist/utils/orders/appendix/unpackOrderAppendix.d.cts +2 -2
- package/dist/utils/orders/appendix/unpackOrderAppendix.d.ts +2 -2
- package/dist/utils/orders/appendix/unpackOrderAppendix.js +22 -5
- package/dist/utils/orders/appendix/unpackOrderAppendix.js.map +1 -1
- package/dist/utils/orders/index.cjs +3 -3
- package/dist/utils/orders/index.cjs.map +1 -1
- package/dist/utils/orders/index.d.cts +5 -5
- package/dist/utils/orders/index.d.ts +5 -5
- package/dist/utils/orders/index.js +1 -1
- package/dist/utils/orders/index.js.map +1 -1
- package/dist/utils/productTypeFilter.cjs.map +1 -1
- package/dist/utils/productTypeFilter.d.cts +2 -2
- package/dist/utils/productTypeFilter.d.ts +2 -2
- package/dist/utils/productTypeFilter.js.map +1 -1
- package/dist/utils/toPrintableObject.cjs +29 -11
- package/dist/utils/toPrintableObject.cjs.map +1 -1
- package/dist/utils/toPrintableObject.d.cts +7 -2
- package/dist/utils/toPrintableObject.d.ts +7 -2
- package/dist/utils/toPrintableObject.js +19 -11
- package/dist/utils/toPrintableObject.js.map +1 -1
- package/package.json +14 -7
- package/src/abis/index.ts +6 -6
- package/src/consts/chainEnvToChain.ts +2 -2
- package/src/consts/productIds.ts +1 -1
- package/src/deployments/core/deployment.inkMainnet.json +13 -0
- package/src/deployments/core/deployment.inkSepolia.json +13 -0
- package/src/deployments/index.ts +5 -5
- package/src/eip712/eip712ValueTypes.ts +2 -2
- package/src/eip712/getNadoEIP712Domain.ts +1 -1
- package/src/eip712/index.ts +6 -6
- package/src/eip712/signatureParamTypes.ts +13 -13
- package/src/encoding/encoding.ts +43 -1
- package/src/execute/approveDepositAllowance.ts +2 -2
- package/src/execute/depositCollateral.ts +2 -2
- package/src/types/ChainEnv.ts +1 -1
- package/src/types/balanceTypes.ts +4 -4
- package/src/types/healthTypes.ts +4 -4
- package/src/types/index.ts +3 -3
- package/src/types/marketTypes.ts +4 -4
- package/src/types/orderAppendixTypes.ts +27 -2
- package/src/types/productTypes.ts +16 -16
- package/src/utils/balanceValue.ts +4 -4
- package/src/utils/createDeterministicLinkedSignerPrivateKey.ts +1 -1
- package/src/utils/index.ts +6 -6
- package/src/utils/interest.ts +26 -31
- package/src/utils/math/BigNumbers.ts +8 -0
- package/src/utils/math/bigNumber.ts +31 -0
- package/src/utils/math/clamp.ts +4 -7
- package/src/utils/math/decimalAdjustment.ts +11 -10
- package/src/utils/math/index.ts +5 -5
- package/src/utils/math/sumBigNumberBy.ts +18 -0
- package/src/utils/math/toBigInt.ts +3 -3
- package/src/utils/math/toIntegerString.ts +4 -4
- package/src/utils/orders/appendix/appendixIsolatedValue.ts +49 -0
- package/src/utils/orders/appendix/appendixTwapValue.ts +14 -19
- package/src/utils/orders/appendix/index.ts +2 -2
- package/src/utils/orders/appendix/orderAppendix.test.ts +68 -11
- package/src/utils/orders/appendix/packOrderAppendix.ts +10 -6
- package/src/utils/orders/appendix/types.ts +9 -7
- package/src/utils/orders/appendix/unpackOrderAppendix.ts +24 -7
- package/src/utils/orders/index.ts +1 -1
- package/src/utils/productTypeFilter.ts +2 -2
- package/src/utils/toPrintableObject.ts +32 -12
- package/dist/chunk-TUJ4HQKF.js.map +0 -1
- package/dist/deployments/core/deployment.InkSepolia.json +0 -13
- package/dist/deployments/core/deployment.arbitrumOne.json +0 -18
- package/dist/utils/math/BigDecimals.cjs.map +0 -1
- package/dist/utils/math/BigDecimals.d.cts +0 -8
- package/dist/utils/math/BigDecimals.d.ts +0 -8
- package/dist/utils/math/BigDecimals.js +0 -14
- package/dist/utils/math/BigDecimals.js.map +0 -1
- package/dist/utils/math/bigDecimal.cjs.map +0 -1
- package/dist/utils/math/bigDecimal.d.cts +0 -18
- package/dist/utils/math/bigDecimal.d.ts +0 -18
- package/dist/utils/math/bigDecimal.js +0 -23
- package/dist/utils/math/bigDecimal.js.map +0 -1
- package/dist/utils/math/sumBigDecimalBy.cjs.map +0 -1
- package/dist/utils/math/sumBigDecimalBy.d.cts +0 -10
- package/dist/utils/math/sumBigDecimalBy.d.ts +0 -10
- package/dist/utils/math/sumBigDecimalBy.js +0 -13
- package/dist/utils/math/sumBigDecimalBy.js.map +0 -1
- package/src/deployments/core/deployment.InkSepolia.json +0 -13
- package/src/deployments/core/deployment.arbitrumOne.json +0 -18
- package/src/utils/math/BigDecimals.ts +0 -8
- package/src/utils/math/bigDecimal.ts +0 -32
- package/src/utils/math/sumBigDecimalBy.ts +0 -18
package/dist/utils/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["export * from './
|
|
1
|
+
{"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["export * from './asyncResult';\nexport * from './balanceValue';\nexport * from './bytes32';\nexport * from './createDeterministicLinkedSignerPrivateKey';\nexport * from './errors';\nexport * from './getValidatedAddress';\nexport * from './getValidatedHex';\nexport * from './interest';\nexport * from './isWriteableContract';\nexport * from './mapValues';\nexport * from './math';\nexport * from './orders';\nexport * from './productTypeFilter';\nexport * from './time';\nexport * from './toPrintableObject';\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,8BAAd;AACA,0BAAc,+BADd;AAEA,0BAAc,0BAFd;AAGA,0BAAc,4DAHd;AAIA,0BAAc,+BAJd;AAKA,0BAAc,sCALd;AAMA,0BAAc,kCANd;AAOA,0BAAc,2BAPd;AAQA,0BAAc,sCARd;AASA,0BAAc,4BATd;AAUA,0BAAc,6BAVd;AAWA,0BAAc,+BAXd;AAYA,0BAAc,oCAZd;AAaA,0BAAc,uBAbd;AAcA,0BAAc,oCAdd;","names":[]}
|
package/dist/utils/index.d.cts
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { getDefaultRecvTime } from './orders/recvTime.cjs';
|
|
3
|
-
export { packTwapOrderAppendixValue, unpackTwapOrderAppendixValue } from './orders/appendix/appendixTwapValue.cjs';
|
|
4
|
-
export { unpackOrderAppendix } from './orders/appendix/unpackOrderAppendix.cjs';
|
|
5
|
-
export { packOrderAppendix } from './orders/appendix/packOrderAppendix.cjs';
|
|
6
|
-
export { PackedOrderAppendixBits } from './orders/appendix/types.cjs';
|
|
7
|
-
export { bitMaskValue } from './orders/appendix/bitMaskValue.cjs';
|
|
8
|
-
export { calcBorrowRateForTimeRange, calcBorrowRatePerSecond, calcRealizedDepositRateForTimeRange, calcTotalBorrowed, calcTotalDeposited, calcUtilizationRatio } from './interest.cjs';
|
|
9
|
-
export { isPerpBalance, isPerpProduct, isSpotBalance, isSpotProduct } from './productTypeFilter.cjs';
|
|
1
|
+
export { AsyncResult, asyncResult } from './asyncResult.cjs';
|
|
10
2
|
export { calcPerpBalanceNotionalValue, calcPerpBalanceValue, calcSpotBalanceValue } from './balanceValue.cjs';
|
|
11
3
|
export { subaccountFromBytes32, subaccountFromHex, subaccountNameBytesToStr, subaccountNameToBytes12, subaccountToBytes32, subaccountToHex } from './bytes32.cjs';
|
|
12
4
|
export { createDeterministicLinkedSignerPrivateKey } from './createDeterministicLinkedSignerPrivateKey.cjs';
|
|
13
|
-
export { isWriteableContract } from './isWriteableContract.cjs';
|
|
14
5
|
export { WalletNotProvidedError } from './errors/WalletNotProvidedError.cjs';
|
|
15
|
-
export { BigDecimalish, toBigDecimal } from './math/bigDecimal.cjs';
|
|
16
|
-
export { toIntegerString } from './math/toIntegerString.cjs';
|
|
17
|
-
export { toBigInt } from './math/toBigInt.cjs';
|
|
18
|
-
export { clampBigDecimal } from './math/clamp.cjs';
|
|
19
|
-
export { sumBigDecimalBy } from './math/sumBigDecimalBy.cjs';
|
|
20
|
-
export { NADO_PRODUCT_DECIMALS, addDecimals, removeDecimals } from './math/decimalAdjustment.cjs';
|
|
21
|
-
export { BigDecimals } from './math/BigDecimals.cjs';
|
|
22
|
-
export { AsyncResult, asyncResult } from './asyncResult.cjs';
|
|
23
6
|
export { getValidatedAddress } from './getValidatedAddress.cjs';
|
|
24
7
|
export { getValidatedHex } from './getValidatedHex.cjs';
|
|
8
|
+
export { calcBorrowRateForTimeRange, calcBorrowRatePerSecond, calcRealizedDepositRateForTimeRange, calcTotalBorrowed, calcTotalDeposited, calcUtilizationRatio } from './interest.cjs';
|
|
9
|
+
export { isWriteableContract } from './isWriteableContract.cjs';
|
|
25
10
|
export { mapValues } from './mapValues.cjs';
|
|
11
|
+
export { BigNumberish, toBigNumber } from './math/bigNumber.cjs';
|
|
12
|
+
export { BigNumbers } from './math/BigNumbers.cjs';
|
|
13
|
+
export { clampBigNumber } from './math/clamp.cjs';
|
|
14
|
+
export { NADO_PRODUCT_DECIMALS, addDecimals, removeDecimals } from './math/decimalAdjustment.cjs';
|
|
15
|
+
export { sumBigNumberBy } from './math/sumBigNumberBy.cjs';
|
|
16
|
+
export { toBigInt } from './math/toBigInt.cjs';
|
|
17
|
+
export { toIntegerString } from './math/toIntegerString.cjs';
|
|
18
|
+
export { packTwapOrderAppendixValue, unpackTwapOrderAppendixValue } from './orders/appendix/appendixTwapValue.cjs';
|
|
19
|
+
export { bitMaskValue } from './orders/appendix/bitMaskValue.cjs';
|
|
20
|
+
export { packOrderAppendix } from './orders/appendix/packOrderAppendix.cjs';
|
|
21
|
+
export { PackedOrderAppendixBits } from './orders/appendix/types.cjs';
|
|
22
|
+
export { unpackOrderAppendix } from './orders/appendix/unpackOrderAppendix.cjs';
|
|
23
|
+
export { getOrderNonce, getRecvTimeFromOrderNonce } from './orders/orderNonce.cjs';
|
|
24
|
+
export { getDefaultRecvTime } from './orders/recvTime.cjs';
|
|
25
|
+
export { isPerpBalance, isPerpProduct, isSpotBalance, isSpotProduct } from './productTypeFilter.cjs';
|
|
26
26
|
export { TimeInSeconds, millisToSeconds, nowInSeconds } from './time.cjs';
|
|
27
27
|
export { toPrintableObject } from './toPrintableObject.cjs';
|
|
28
|
-
|
|
29
|
-
import '../types/orderAppendixTypes.cjs';
|
|
30
|
-
import '../types/OrderExecutionType.cjs';
|
|
31
|
-
import '../types/productTypes.cjs';
|
|
28
|
+
import 'bignumber.js';
|
|
32
29
|
import '../types/balanceTypes.cjs';
|
|
33
30
|
import '../types/healthTypes.cjs';
|
|
31
|
+
import '../types/productTypes.cjs';
|
|
34
32
|
import 'viem';
|
|
35
33
|
import '../types/bytes.cjs';
|
|
36
34
|
import '../types/subaccountTypes.cjs';
|
|
37
35
|
import '../types/viemTypes.cjs';
|
|
36
|
+
import '../types/orderAppendixTypes.cjs';
|
|
37
|
+
import '../types/OrderExecutionType.cjs';
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { getDefaultRecvTime } from './orders/recvTime.js';
|
|
3
|
-
export { packTwapOrderAppendixValue, unpackTwapOrderAppendixValue } from './orders/appendix/appendixTwapValue.js';
|
|
4
|
-
export { unpackOrderAppendix } from './orders/appendix/unpackOrderAppendix.js';
|
|
5
|
-
export { packOrderAppendix } from './orders/appendix/packOrderAppendix.js';
|
|
6
|
-
export { PackedOrderAppendixBits } from './orders/appendix/types.js';
|
|
7
|
-
export { bitMaskValue } from './orders/appendix/bitMaskValue.js';
|
|
8
|
-
export { calcBorrowRateForTimeRange, calcBorrowRatePerSecond, calcRealizedDepositRateForTimeRange, calcTotalBorrowed, calcTotalDeposited, calcUtilizationRatio } from './interest.js';
|
|
9
|
-
export { isPerpBalance, isPerpProduct, isSpotBalance, isSpotProduct } from './productTypeFilter.js';
|
|
1
|
+
export { AsyncResult, asyncResult } from './asyncResult.js';
|
|
10
2
|
export { calcPerpBalanceNotionalValue, calcPerpBalanceValue, calcSpotBalanceValue } from './balanceValue.js';
|
|
11
3
|
export { subaccountFromBytes32, subaccountFromHex, subaccountNameBytesToStr, subaccountNameToBytes12, subaccountToBytes32, subaccountToHex } from './bytes32.js';
|
|
12
4
|
export { createDeterministicLinkedSignerPrivateKey } from './createDeterministicLinkedSignerPrivateKey.js';
|
|
13
|
-
export { isWriteableContract } from './isWriteableContract.js';
|
|
14
5
|
export { WalletNotProvidedError } from './errors/WalletNotProvidedError.js';
|
|
15
|
-
export { BigDecimalish, toBigDecimal } from './math/bigDecimal.js';
|
|
16
|
-
export { toIntegerString } from './math/toIntegerString.js';
|
|
17
|
-
export { toBigInt } from './math/toBigInt.js';
|
|
18
|
-
export { clampBigDecimal } from './math/clamp.js';
|
|
19
|
-
export { sumBigDecimalBy } from './math/sumBigDecimalBy.js';
|
|
20
|
-
export { NADO_PRODUCT_DECIMALS, addDecimals, removeDecimals } from './math/decimalAdjustment.js';
|
|
21
|
-
export { BigDecimals } from './math/BigDecimals.js';
|
|
22
|
-
export { AsyncResult, asyncResult } from './asyncResult.js';
|
|
23
6
|
export { getValidatedAddress } from './getValidatedAddress.js';
|
|
24
7
|
export { getValidatedHex } from './getValidatedHex.js';
|
|
8
|
+
export { calcBorrowRateForTimeRange, calcBorrowRatePerSecond, calcRealizedDepositRateForTimeRange, calcTotalBorrowed, calcTotalDeposited, calcUtilizationRatio } from './interest.js';
|
|
9
|
+
export { isWriteableContract } from './isWriteableContract.js';
|
|
25
10
|
export { mapValues } from './mapValues.js';
|
|
11
|
+
export { BigNumberish, toBigNumber } from './math/bigNumber.js';
|
|
12
|
+
export { BigNumbers } from './math/BigNumbers.js';
|
|
13
|
+
export { clampBigNumber } from './math/clamp.js';
|
|
14
|
+
export { NADO_PRODUCT_DECIMALS, addDecimals, removeDecimals } from './math/decimalAdjustment.js';
|
|
15
|
+
export { sumBigNumberBy } from './math/sumBigNumberBy.js';
|
|
16
|
+
export { toBigInt } from './math/toBigInt.js';
|
|
17
|
+
export { toIntegerString } from './math/toIntegerString.js';
|
|
18
|
+
export { packTwapOrderAppendixValue, unpackTwapOrderAppendixValue } from './orders/appendix/appendixTwapValue.js';
|
|
19
|
+
export { bitMaskValue } from './orders/appendix/bitMaskValue.js';
|
|
20
|
+
export { packOrderAppendix } from './orders/appendix/packOrderAppendix.js';
|
|
21
|
+
export { PackedOrderAppendixBits } from './orders/appendix/types.js';
|
|
22
|
+
export { unpackOrderAppendix } from './orders/appendix/unpackOrderAppendix.js';
|
|
23
|
+
export { getOrderNonce, getRecvTimeFromOrderNonce } from './orders/orderNonce.js';
|
|
24
|
+
export { getDefaultRecvTime } from './orders/recvTime.js';
|
|
25
|
+
export { isPerpBalance, isPerpProduct, isSpotBalance, isSpotProduct } from './productTypeFilter.js';
|
|
26
26
|
export { TimeInSeconds, millisToSeconds, nowInSeconds } from './time.js';
|
|
27
27
|
export { toPrintableObject } from './toPrintableObject.js';
|
|
28
|
-
|
|
29
|
-
import '../types/orderAppendixTypes.js';
|
|
30
|
-
import '../types/OrderExecutionType.js';
|
|
31
|
-
import '../types/productTypes.js';
|
|
28
|
+
import 'bignumber.js';
|
|
32
29
|
import '../types/balanceTypes.js';
|
|
33
30
|
import '../types/healthTypes.js';
|
|
31
|
+
import '../types/productTypes.js';
|
|
34
32
|
import 'viem';
|
|
35
33
|
import '../types/bytes.js';
|
|
36
34
|
import '../types/subaccountTypes.js';
|
|
37
35
|
import '../types/viemTypes.js';
|
|
36
|
+
import '../types/orderAppendixTypes.js';
|
|
37
|
+
import '../types/OrderExecutionType.js';
|
package/dist/utils/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
// src/utils/index.ts
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./interest.js";
|
|
4
|
-
export * from "./productTypeFilter.js";
|
|
2
|
+
export * from "./asyncResult.js";
|
|
5
3
|
export * from "./balanceValue.js";
|
|
6
4
|
export * from "./bytes32.js";
|
|
7
5
|
export * from "./createDeterministicLinkedSignerPrivateKey.js";
|
|
8
|
-
export * from "./isWriteableContract.js";
|
|
9
6
|
export * from "./errors/index.js";
|
|
10
|
-
export * from "./math/index.js";
|
|
11
|
-
export * from "./asyncResult.js";
|
|
12
7
|
export * from "./getValidatedAddress.js";
|
|
13
8
|
export * from "./getValidatedHex.js";
|
|
9
|
+
export * from "./interest.js";
|
|
10
|
+
export * from "./isWriteableContract.js";
|
|
14
11
|
export * from "./mapValues.js";
|
|
12
|
+
export * from "./math/index.js";
|
|
13
|
+
export * from "./orders/index.js";
|
|
14
|
+
export * from "./productTypeFilter.js";
|
|
15
15
|
export * from "./time.js";
|
|
16
16
|
export * from "./toPrintableObject.js";
|
|
17
17
|
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["export * from './
|
|
1
|
+
{"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["export * from './asyncResult';\nexport * from './balanceValue';\nexport * from './bytes32';\nexport * from './createDeterministicLinkedSignerPrivateKey';\nexport * from './errors';\nexport * from './getValidatedAddress';\nexport * from './getValidatedHex';\nexport * from './interest';\nexport * from './isWriteableContract';\nexport * from './mapValues';\nexport * from './math';\nexport * from './orders';\nexport * from './productTypeFilter';\nexport * from './time';\nexport * from './toPrintableObject';\n"],"mappings":";AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
package/dist/utils/interest.cjs
CHANGED
|
@@ -31,18 +31,18 @@ module.exports = __toCommonJS(interest_exports);
|
|
|
31
31
|
var import_math = require("./math/index.cjs");
|
|
32
32
|
var import_time = require("./time.cjs");
|
|
33
33
|
function calcTotalBorrowed(totalBorrowsNormalized, cumulativeBorrowsMultiplierX18) {
|
|
34
|
-
return (0, import_math.
|
|
34
|
+
return (0, import_math.toBigNumber)(totalBorrowsNormalized).multipliedBy(
|
|
35
35
|
(0, import_math.removeDecimals)(cumulativeBorrowsMultiplierX18)
|
|
36
36
|
);
|
|
37
37
|
}
|
|
38
38
|
function calcTotalDeposited(totalDepositsNormalized, cumulativeDepositsMultiplierX18) {
|
|
39
|
-
return (0, import_math.
|
|
39
|
+
return (0, import_math.toBigNumber)(totalDepositsNormalized).multipliedBy(
|
|
40
40
|
(0, import_math.removeDecimals)(cumulativeDepositsMultiplierX18)
|
|
41
41
|
);
|
|
42
42
|
}
|
|
43
43
|
function calcUtilizationRatio(product) {
|
|
44
44
|
if (product.totalDeposited.eq(0) || product.totalBorrowed.eq(0)) {
|
|
45
|
-
return (0, import_math.
|
|
45
|
+
return (0, import_math.toBigNumber)(0);
|
|
46
46
|
}
|
|
47
47
|
return product.totalBorrowed.abs().div(product.totalDeposited);
|
|
48
48
|
}
|
|
@@ -55,13 +55,13 @@ function calcBorrowRatePerSecond(product) {
|
|
|
55
55
|
} = product;
|
|
56
56
|
const utilization = calcUtilizationRatio(product);
|
|
57
57
|
if (utilization.eq(0)) {
|
|
58
|
-
return (0, import_math.
|
|
58
|
+
return (0, import_math.toBigNumber)(0);
|
|
59
59
|
}
|
|
60
60
|
const pastInflection = utilization.gt(interestInflectionUtil);
|
|
61
61
|
let annualRate;
|
|
62
62
|
if (pastInflection) {
|
|
63
63
|
const utilizationTerm = interestLargeCap.times(
|
|
64
|
-
(0, import_math.
|
|
64
|
+
(0, import_math.toBigNumber)(utilization).minus(interestInflectionUtil).div(import_math.BigNumbers.ONE.minus(interestInflectionUtil))
|
|
65
65
|
);
|
|
66
66
|
annualRate = interestFloor.plus(interestSmallCap).plus(utilizationTerm);
|
|
67
67
|
} else {
|
|
@@ -72,15 +72,15 @@ function calcBorrowRatePerSecond(product) {
|
|
|
72
72
|
}
|
|
73
73
|
function calcBorrowRateForTimeRange(product, seconds, minDepositRate) {
|
|
74
74
|
const borrowRatePerSecond = calcBorrowRatePerSecond(product);
|
|
75
|
-
const borrowRateForTime = borrowRatePerSecond.plus(1).toNumber() ** (0, import_math.
|
|
76
|
-
return (0, import_math.
|
|
75
|
+
const borrowRateForTime = borrowRatePerSecond.plus(1).toNumber() ** (0, import_math.toBigNumber)(seconds).toNumber() - 1;
|
|
76
|
+
return (0, import_math.toBigNumber)(borrowRateForTime).plus((0, import_math.toBigNumber)(minDepositRate));
|
|
77
77
|
}
|
|
78
78
|
function calcRealizedDepositRateForTimeRange(product, seconds, interestFeeFrac, minDepositRate) {
|
|
79
79
|
const utilization = calcUtilizationRatio(product);
|
|
80
80
|
if (utilization.eq(0)) {
|
|
81
|
-
return (0, import_math.
|
|
81
|
+
return (0, import_math.toBigNumber)(0);
|
|
82
82
|
}
|
|
83
|
-
return utilization.times(calcBorrowRateForTimeRange(product, seconds, (0, import_math.
|
|
83
|
+
return utilization.times(calcBorrowRateForTimeRange(product, seconds, (0, import_math.toBigNumber)(0))).times(import_math.BigNumbers.ONE.minus((0, import_math.toBigNumber)(interestFeeFrac))).plus((0, import_math.toBigNumber)(minDepositRate));
|
|
84
84
|
}
|
|
85
85
|
// Annotate the CommonJS export names for ESM import in node:
|
|
86
86
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/interest.ts"],"sourcesContent":["import { SpotProduct } from '../types/productTypes';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/utils/interest.ts"],"sourcesContent":["import BigNumber from 'bignumber.js';\nimport { SpotProduct } from '../types/productTypes';\nimport { BigNumberish, BigNumbers, removeDecimals, toBigNumber } from './math';\nimport { TimeInSeconds } from './time';\n\n/**\n * Calculate amount total borrowed for a product\n */\nexport function calcTotalBorrowed(\n totalBorrowsNormalized: BigNumberish,\n cumulativeBorrowsMultiplierX18: BigNumberish,\n): BigNumber {\n return toBigNumber(totalBorrowsNormalized).multipliedBy(\n removeDecimals(cumulativeBorrowsMultiplierX18),\n );\n}\n\n/**\n * Calculate amount total deposited for a product.\n */\nexport function calcTotalDeposited(\n totalDepositsNormalized: BigNumberish,\n cumulativeDepositsMultiplierX18: BigNumberish,\n): BigNumber {\n return toBigNumber(totalDepositsNormalized).multipliedBy(\n removeDecimals(cumulativeDepositsMultiplierX18),\n );\n}\n\n/**\n * Calculates utilization ratio = abs(total borrowed / total deposited)\n *\n * @param product Spot product\n */\nexport function calcUtilizationRatio(product: SpotProduct) {\n if (product.totalDeposited.eq(0) || product.totalBorrowed.eq(0)) {\n return toBigNumber(0);\n }\n return product.totalBorrowed.abs().div(product.totalDeposited);\n}\n\n/**\n * Calculates per-second borrow interest rate for a product. For example, a returned rate of 0.1 indicates 10% borrower\n * interest. The calculation for interest rate is as follows:\n *\n * If utilization ratio > inflection:\n * annual rate = (1 - utilization ratio) / (1 - inflection) * interestLargeCap + interestFloor + interestSmallCap\n *\n * If utilization ratio < inflection:\n * annual rate = utilization * interestSmallCap / inflection + utilization\n *\n * The returned rate is annual rate / 31536000 seconds per year.\n *\n * @param product Spot product\n */\nexport function calcBorrowRatePerSecond(product: SpotProduct) {\n const {\n interestFloor,\n interestInflectionUtil,\n interestSmallCap,\n interestLargeCap,\n } = product;\n const utilization = calcUtilizationRatio(product);\n if (utilization.eq(0)) {\n return toBigNumber(0);\n }\n const pastInflection = utilization.gt(interestInflectionUtil);\n\n let annualRate: BigNumber;\n if (pastInflection) {\n const utilizationTerm = interestLargeCap.times(\n toBigNumber(utilization)\n .minus(interestInflectionUtil)\n .div(BigNumbers.ONE.minus(interestInflectionUtil)),\n );\n annualRate = interestFloor.plus(interestSmallCap).plus(utilizationTerm);\n } else {\n const utilizationTerm = utilization\n .div(interestInflectionUtil)\n .times(interestSmallCap);\n annualRate = interestFloor.plus(utilizationTerm);\n }\n\n return annualRate.div(TimeInSeconds.YEAR);\n}\n\n/**\n * Calculates borrower interest rate compounded for a period of time.\n *\n * @param product Spot product\n * @param seconds Number of seconds for the time period\n */\nexport function calcBorrowRateForTimeRange(\n product: SpotProduct,\n seconds: BigNumberish,\n minDepositRate: BigNumberish,\n) {\n const borrowRatePerSecond = calcBorrowRatePerSecond(product);\n\n // Convert to number for this, with some loss of precision, but using `.pow()` causes us to hit browser resource limits\n const borrowRateForTime =\n borrowRatePerSecond.plus(1).toNumber() ** toBigNumber(seconds).toNumber() -\n 1;\n return toBigNumber(borrowRateForTime).plus(toBigNumber(minDepositRate));\n}\n\n/**\n * Calculate depositor interest rate compounded for a period of time.\n *\n * @param product Spot product\n * @param seconds Number of seconds for the time period\n * @param interestFeeFrac Fraction of paid borrower interest that is paid as a fee (0.2 = 20% fee)\n */\nexport function calcRealizedDepositRateForTimeRange(\n product: SpotProduct,\n seconds: BigNumberish,\n interestFeeFrac: BigNumberish,\n minDepositRate: BigNumberish,\n) {\n const utilization = calcUtilizationRatio(product);\n if (utilization.eq(0)) {\n return toBigNumber(0);\n }\n return utilization\n .times(calcBorrowRateForTimeRange(product, seconds, toBigNumber(0)))\n .times(BigNumbers.ONE.minus(toBigNumber(interestFeeFrac)))\n .plus(toBigNumber(minDepositRate));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,kBAAsE;AACtE,kBAA8B;AAKvB,SAAS,kBACd,wBACA,gCACW;AACX,aAAO,yBAAY,sBAAsB,EAAE;AAAA,QACzC,4BAAe,8BAA8B;AAAA,EAC/C;AACF;AAKO,SAAS,mBACd,yBACA,iCACW;AACX,aAAO,yBAAY,uBAAuB,EAAE;AAAA,QAC1C,4BAAe,+BAA+B;AAAA,EAChD;AACF;AAOO,SAAS,qBAAqB,SAAsB;AACzD,MAAI,QAAQ,eAAe,GAAG,CAAC,KAAK,QAAQ,cAAc,GAAG,CAAC,GAAG;AAC/D,eAAO,yBAAY,CAAC;AAAA,EACtB;AACA,SAAO,QAAQ,cAAc,IAAI,EAAE,IAAI,QAAQ,cAAc;AAC/D;AAgBO,SAAS,wBAAwB,SAAsB;AAC5D,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AACJ,QAAM,cAAc,qBAAqB,OAAO;AAChD,MAAI,YAAY,GAAG,CAAC,GAAG;AACrB,eAAO,yBAAY,CAAC;AAAA,EACtB;AACA,QAAM,iBAAiB,YAAY,GAAG,sBAAsB;AAE5D,MAAI;AACJ,MAAI,gBAAgB;AAClB,UAAM,kBAAkB,iBAAiB;AAAA,UACvC,yBAAY,WAAW,EACpB,MAAM,sBAAsB,EAC5B,IAAI,uBAAW,IAAI,MAAM,sBAAsB,CAAC;AAAA,IACrD;AACA,iBAAa,cAAc,KAAK,gBAAgB,EAAE,KAAK,eAAe;AAAA,EACxE,OAAO;AACL,UAAM,kBAAkB,YACrB,IAAI,sBAAsB,EAC1B,MAAM,gBAAgB;AACzB,iBAAa,cAAc,KAAK,eAAe;AAAA,EACjD;AAEA,SAAO,WAAW,IAAI,0BAAc,IAAI;AAC1C;AAQO,SAAS,2BACd,SACA,SACA,gBACA;AACA,QAAM,sBAAsB,wBAAwB,OAAO;AAG3D,QAAM,oBACJ,oBAAoB,KAAK,CAAC,EAAE,SAAS,SAAK,yBAAY,OAAO,EAAE,SAAS,IACxE;AACF,aAAO,yBAAY,iBAAiB,EAAE,SAAK,yBAAY,cAAc,CAAC;AACxE;AASO,SAAS,oCACd,SACA,SACA,iBACA,gBACA;AACA,QAAM,cAAc,qBAAqB,OAAO;AAChD,MAAI,YAAY,GAAG,CAAC,GAAG;AACrB,eAAO,yBAAY,CAAC;AAAA,EACtB;AACA,SAAO,YACJ,MAAM,2BAA2B,SAAS,aAAS,yBAAY,CAAC,CAAC,CAAC,EAClE,MAAM,uBAAW,IAAI,UAAM,yBAAY,eAAe,CAAC,CAAC,EACxD,SAAK,yBAAY,cAAc,CAAC;AACrC;","names":[]}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
+
import BigNumber__default from 'bignumber.js';
|
|
1
2
|
import { SpotProduct } from '../types/productTypes.cjs';
|
|
2
|
-
import {
|
|
3
|
-
import BigDecimal from 'bignumber.js';
|
|
3
|
+
import { BigNumberish } from './math/bigNumber.cjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Calculate amount total borrowed for a product
|
|
7
7
|
*/
|
|
8
|
-
declare function calcTotalBorrowed(totalBorrowsNormalized:
|
|
8
|
+
declare function calcTotalBorrowed(totalBorrowsNormalized: BigNumberish, cumulativeBorrowsMultiplierX18: BigNumberish): BigNumber__default;
|
|
9
9
|
/**
|
|
10
10
|
* Calculate amount total deposited for a product.
|
|
11
11
|
*/
|
|
12
|
-
declare function calcTotalDeposited(totalDepositsNormalized:
|
|
12
|
+
declare function calcTotalDeposited(totalDepositsNormalized: BigNumberish, cumulativeDepositsMultiplierX18: BigNumberish): BigNumber__default;
|
|
13
13
|
/**
|
|
14
14
|
* Calculates utilization ratio = abs(total borrowed / total deposited)
|
|
15
15
|
*
|
|
16
16
|
* @param product Spot product
|
|
17
17
|
*/
|
|
18
|
-
declare function calcUtilizationRatio(product: SpotProduct):
|
|
18
|
+
declare function calcUtilizationRatio(product: SpotProduct): BigNumber__default;
|
|
19
19
|
/**
|
|
20
20
|
* Calculates per-second borrow interest rate for a product. For example, a returned rate of 0.1 indicates 10% borrower
|
|
21
21
|
* interest. The calculation for interest rate is as follows:
|
|
@@ -30,14 +30,14 @@ declare function calcUtilizationRatio(product: SpotProduct): BigDecimal;
|
|
|
30
30
|
*
|
|
31
31
|
* @param product Spot product
|
|
32
32
|
*/
|
|
33
|
-
declare function calcBorrowRatePerSecond(product: SpotProduct):
|
|
33
|
+
declare function calcBorrowRatePerSecond(product: SpotProduct): BigNumber__default;
|
|
34
34
|
/**
|
|
35
35
|
* Calculates borrower interest rate compounded for a period of time.
|
|
36
36
|
*
|
|
37
37
|
* @param product Spot product
|
|
38
38
|
* @param seconds Number of seconds for the time period
|
|
39
39
|
*/
|
|
40
|
-
declare function calcBorrowRateForTimeRange(product: SpotProduct, seconds:
|
|
40
|
+
declare function calcBorrowRateForTimeRange(product: SpotProduct, seconds: BigNumberish, minDepositRate: BigNumberish): BigNumber__default;
|
|
41
41
|
/**
|
|
42
42
|
* Calculate depositor interest rate compounded for a period of time.
|
|
43
43
|
*
|
|
@@ -45,6 +45,6 @@ declare function calcBorrowRateForTimeRange(product: SpotProduct, seconds: BigDe
|
|
|
45
45
|
* @param seconds Number of seconds for the time period
|
|
46
46
|
* @param interestFeeFrac Fraction of paid borrower interest that is paid as a fee (0.2 = 20% fee)
|
|
47
47
|
*/
|
|
48
|
-
declare function calcRealizedDepositRateForTimeRange(product: SpotProduct, seconds:
|
|
48
|
+
declare function calcRealizedDepositRateForTimeRange(product: SpotProduct, seconds: BigNumberish, interestFeeFrac: BigNumberish, minDepositRate: BigNumberish): BigNumber__default;
|
|
49
49
|
|
|
50
50
|
export { calcBorrowRateForTimeRange, calcBorrowRatePerSecond, calcRealizedDepositRateForTimeRange, calcTotalBorrowed, calcTotalDeposited, calcUtilizationRatio };
|
package/dist/utils/interest.d.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
+
import BigNumber__default from 'bignumber.js';
|
|
1
2
|
import { SpotProduct } from '../types/productTypes.js';
|
|
2
|
-
import {
|
|
3
|
-
import BigDecimal from 'bignumber.js';
|
|
3
|
+
import { BigNumberish } from './math/bigNumber.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Calculate amount total borrowed for a product
|
|
7
7
|
*/
|
|
8
|
-
declare function calcTotalBorrowed(totalBorrowsNormalized:
|
|
8
|
+
declare function calcTotalBorrowed(totalBorrowsNormalized: BigNumberish, cumulativeBorrowsMultiplierX18: BigNumberish): BigNumber__default;
|
|
9
9
|
/**
|
|
10
10
|
* Calculate amount total deposited for a product.
|
|
11
11
|
*/
|
|
12
|
-
declare function calcTotalDeposited(totalDepositsNormalized:
|
|
12
|
+
declare function calcTotalDeposited(totalDepositsNormalized: BigNumberish, cumulativeDepositsMultiplierX18: BigNumberish): BigNumber__default;
|
|
13
13
|
/**
|
|
14
14
|
* Calculates utilization ratio = abs(total borrowed / total deposited)
|
|
15
15
|
*
|
|
16
16
|
* @param product Spot product
|
|
17
17
|
*/
|
|
18
|
-
declare function calcUtilizationRatio(product: SpotProduct):
|
|
18
|
+
declare function calcUtilizationRatio(product: SpotProduct): BigNumber__default;
|
|
19
19
|
/**
|
|
20
20
|
* Calculates per-second borrow interest rate for a product. For example, a returned rate of 0.1 indicates 10% borrower
|
|
21
21
|
* interest. The calculation for interest rate is as follows:
|
|
@@ -30,14 +30,14 @@ declare function calcUtilizationRatio(product: SpotProduct): BigDecimal;
|
|
|
30
30
|
*
|
|
31
31
|
* @param product Spot product
|
|
32
32
|
*/
|
|
33
|
-
declare function calcBorrowRatePerSecond(product: SpotProduct):
|
|
33
|
+
declare function calcBorrowRatePerSecond(product: SpotProduct): BigNumber__default;
|
|
34
34
|
/**
|
|
35
35
|
* Calculates borrower interest rate compounded for a period of time.
|
|
36
36
|
*
|
|
37
37
|
* @param product Spot product
|
|
38
38
|
* @param seconds Number of seconds for the time period
|
|
39
39
|
*/
|
|
40
|
-
declare function calcBorrowRateForTimeRange(product: SpotProduct, seconds:
|
|
40
|
+
declare function calcBorrowRateForTimeRange(product: SpotProduct, seconds: BigNumberish, minDepositRate: BigNumberish): BigNumber__default;
|
|
41
41
|
/**
|
|
42
42
|
* Calculate depositor interest rate compounded for a period of time.
|
|
43
43
|
*
|
|
@@ -45,6 +45,6 @@ declare function calcBorrowRateForTimeRange(product: SpotProduct, seconds: BigDe
|
|
|
45
45
|
* @param seconds Number of seconds for the time period
|
|
46
46
|
* @param interestFeeFrac Fraction of paid borrower interest that is paid as a fee (0.2 = 20% fee)
|
|
47
47
|
*/
|
|
48
|
-
declare function calcRealizedDepositRateForTimeRange(product: SpotProduct, seconds:
|
|
48
|
+
declare function calcRealizedDepositRateForTimeRange(product: SpotProduct, seconds: BigNumberish, interestFeeFrac: BigNumberish, minDepositRate: BigNumberish): BigNumber__default;
|
|
49
49
|
|
|
50
50
|
export { calcBorrowRateForTimeRange, calcBorrowRatePerSecond, calcRealizedDepositRateForTimeRange, calcTotalBorrowed, calcTotalDeposited, calcUtilizationRatio };
|
package/dist/utils/interest.js
CHANGED
|
@@ -1,25 +1,21 @@
|
|
|
1
1
|
import "../chunk-5WRI5ZAA.js";
|
|
2
2
|
|
|
3
3
|
// src/utils/interest.ts
|
|
4
|
-
import {
|
|
5
|
-
BigDecimals,
|
|
6
|
-
removeDecimals,
|
|
7
|
-
toBigDecimal
|
|
8
|
-
} from "./math/index.js";
|
|
4
|
+
import { BigNumbers, removeDecimals, toBigNumber } from "./math/index.js";
|
|
9
5
|
import { TimeInSeconds } from "./time.js";
|
|
10
6
|
function calcTotalBorrowed(totalBorrowsNormalized, cumulativeBorrowsMultiplierX18) {
|
|
11
|
-
return
|
|
7
|
+
return toBigNumber(totalBorrowsNormalized).multipliedBy(
|
|
12
8
|
removeDecimals(cumulativeBorrowsMultiplierX18)
|
|
13
9
|
);
|
|
14
10
|
}
|
|
15
11
|
function calcTotalDeposited(totalDepositsNormalized, cumulativeDepositsMultiplierX18) {
|
|
16
|
-
return
|
|
12
|
+
return toBigNumber(totalDepositsNormalized).multipliedBy(
|
|
17
13
|
removeDecimals(cumulativeDepositsMultiplierX18)
|
|
18
14
|
);
|
|
19
15
|
}
|
|
20
16
|
function calcUtilizationRatio(product) {
|
|
21
17
|
if (product.totalDeposited.eq(0) || product.totalBorrowed.eq(0)) {
|
|
22
|
-
return
|
|
18
|
+
return toBigNumber(0);
|
|
23
19
|
}
|
|
24
20
|
return product.totalBorrowed.abs().div(product.totalDeposited);
|
|
25
21
|
}
|
|
@@ -32,13 +28,13 @@ function calcBorrowRatePerSecond(product) {
|
|
|
32
28
|
} = product;
|
|
33
29
|
const utilization = calcUtilizationRatio(product);
|
|
34
30
|
if (utilization.eq(0)) {
|
|
35
|
-
return
|
|
31
|
+
return toBigNumber(0);
|
|
36
32
|
}
|
|
37
33
|
const pastInflection = utilization.gt(interestInflectionUtil);
|
|
38
34
|
let annualRate;
|
|
39
35
|
if (pastInflection) {
|
|
40
36
|
const utilizationTerm = interestLargeCap.times(
|
|
41
|
-
|
|
37
|
+
toBigNumber(utilization).minus(interestInflectionUtil).div(BigNumbers.ONE.minus(interestInflectionUtil))
|
|
42
38
|
);
|
|
43
39
|
annualRate = interestFloor.plus(interestSmallCap).plus(utilizationTerm);
|
|
44
40
|
} else {
|
|
@@ -49,15 +45,15 @@ function calcBorrowRatePerSecond(product) {
|
|
|
49
45
|
}
|
|
50
46
|
function calcBorrowRateForTimeRange(product, seconds, minDepositRate) {
|
|
51
47
|
const borrowRatePerSecond = calcBorrowRatePerSecond(product);
|
|
52
|
-
const borrowRateForTime = borrowRatePerSecond.plus(1).toNumber() **
|
|
53
|
-
return
|
|
48
|
+
const borrowRateForTime = borrowRatePerSecond.plus(1).toNumber() ** toBigNumber(seconds).toNumber() - 1;
|
|
49
|
+
return toBigNumber(borrowRateForTime).plus(toBigNumber(minDepositRate));
|
|
54
50
|
}
|
|
55
51
|
function calcRealizedDepositRateForTimeRange(product, seconds, interestFeeFrac, minDepositRate) {
|
|
56
52
|
const utilization = calcUtilizationRatio(product);
|
|
57
53
|
if (utilization.eq(0)) {
|
|
58
|
-
return
|
|
54
|
+
return toBigNumber(0);
|
|
59
55
|
}
|
|
60
|
-
return utilization.times(calcBorrowRateForTimeRange(product, seconds,
|
|
56
|
+
return utilization.times(calcBorrowRateForTimeRange(product, seconds, toBigNumber(0))).times(BigNumbers.ONE.minus(toBigNumber(interestFeeFrac))).plus(toBigNumber(minDepositRate));
|
|
61
57
|
}
|
|
62
58
|
export {
|
|
63
59
|
calcBorrowRateForTimeRange,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/interest.ts"],"sourcesContent":["import { SpotProduct } from '../types/productTypes';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/utils/interest.ts"],"sourcesContent":["import BigNumber from 'bignumber.js';\nimport { SpotProduct } from '../types/productTypes';\nimport { BigNumberish, BigNumbers, removeDecimals, toBigNumber } from './math';\nimport { TimeInSeconds } from './time';\n\n/**\n * Calculate amount total borrowed for a product\n */\nexport function calcTotalBorrowed(\n totalBorrowsNormalized: BigNumberish,\n cumulativeBorrowsMultiplierX18: BigNumberish,\n): BigNumber {\n return toBigNumber(totalBorrowsNormalized).multipliedBy(\n removeDecimals(cumulativeBorrowsMultiplierX18),\n );\n}\n\n/**\n * Calculate amount total deposited for a product.\n */\nexport function calcTotalDeposited(\n totalDepositsNormalized: BigNumberish,\n cumulativeDepositsMultiplierX18: BigNumberish,\n): BigNumber {\n return toBigNumber(totalDepositsNormalized).multipliedBy(\n removeDecimals(cumulativeDepositsMultiplierX18),\n );\n}\n\n/**\n * Calculates utilization ratio = abs(total borrowed / total deposited)\n *\n * @param product Spot product\n */\nexport function calcUtilizationRatio(product: SpotProduct) {\n if (product.totalDeposited.eq(0) || product.totalBorrowed.eq(0)) {\n return toBigNumber(0);\n }\n return product.totalBorrowed.abs().div(product.totalDeposited);\n}\n\n/**\n * Calculates per-second borrow interest rate for a product. For example, a returned rate of 0.1 indicates 10% borrower\n * interest. The calculation for interest rate is as follows:\n *\n * If utilization ratio > inflection:\n * annual rate = (1 - utilization ratio) / (1 - inflection) * interestLargeCap + interestFloor + interestSmallCap\n *\n * If utilization ratio < inflection:\n * annual rate = utilization * interestSmallCap / inflection + utilization\n *\n * The returned rate is annual rate / 31536000 seconds per year.\n *\n * @param product Spot product\n */\nexport function calcBorrowRatePerSecond(product: SpotProduct) {\n const {\n interestFloor,\n interestInflectionUtil,\n interestSmallCap,\n interestLargeCap,\n } = product;\n const utilization = calcUtilizationRatio(product);\n if (utilization.eq(0)) {\n return toBigNumber(0);\n }\n const pastInflection = utilization.gt(interestInflectionUtil);\n\n let annualRate: BigNumber;\n if (pastInflection) {\n const utilizationTerm = interestLargeCap.times(\n toBigNumber(utilization)\n .minus(interestInflectionUtil)\n .div(BigNumbers.ONE.minus(interestInflectionUtil)),\n );\n annualRate = interestFloor.plus(interestSmallCap).plus(utilizationTerm);\n } else {\n const utilizationTerm = utilization\n .div(interestInflectionUtil)\n .times(interestSmallCap);\n annualRate = interestFloor.plus(utilizationTerm);\n }\n\n return annualRate.div(TimeInSeconds.YEAR);\n}\n\n/**\n * Calculates borrower interest rate compounded for a period of time.\n *\n * @param product Spot product\n * @param seconds Number of seconds for the time period\n */\nexport function calcBorrowRateForTimeRange(\n product: SpotProduct,\n seconds: BigNumberish,\n minDepositRate: BigNumberish,\n) {\n const borrowRatePerSecond = calcBorrowRatePerSecond(product);\n\n // Convert to number for this, with some loss of precision, but using `.pow()` causes us to hit browser resource limits\n const borrowRateForTime =\n borrowRatePerSecond.plus(1).toNumber() ** toBigNumber(seconds).toNumber() -\n 1;\n return toBigNumber(borrowRateForTime).plus(toBigNumber(minDepositRate));\n}\n\n/**\n * Calculate depositor interest rate compounded for a period of time.\n *\n * @param product Spot product\n * @param seconds Number of seconds for the time period\n * @param interestFeeFrac Fraction of paid borrower interest that is paid as a fee (0.2 = 20% fee)\n */\nexport function calcRealizedDepositRateForTimeRange(\n product: SpotProduct,\n seconds: BigNumberish,\n interestFeeFrac: BigNumberish,\n minDepositRate: BigNumberish,\n) {\n const utilization = calcUtilizationRatio(product);\n if (utilization.eq(0)) {\n return toBigNumber(0);\n }\n return utilization\n .times(calcBorrowRateForTimeRange(product, seconds, toBigNumber(0)))\n .times(BigNumbers.ONE.minus(toBigNumber(interestFeeFrac)))\n .plus(toBigNumber(minDepositRate));\n}\n"],"mappings":";;;AAEA,SAAuB,YAAY,gBAAgB,mBAAmB;AACtE,SAAS,qBAAqB;AAKvB,SAAS,kBACd,wBACA,gCACW;AACX,SAAO,YAAY,sBAAsB,EAAE;AAAA,IACzC,eAAe,8BAA8B;AAAA,EAC/C;AACF;AAKO,SAAS,mBACd,yBACA,iCACW;AACX,SAAO,YAAY,uBAAuB,EAAE;AAAA,IAC1C,eAAe,+BAA+B;AAAA,EAChD;AACF;AAOO,SAAS,qBAAqB,SAAsB;AACzD,MAAI,QAAQ,eAAe,GAAG,CAAC,KAAK,QAAQ,cAAc,GAAG,CAAC,GAAG;AAC/D,WAAO,YAAY,CAAC;AAAA,EACtB;AACA,SAAO,QAAQ,cAAc,IAAI,EAAE,IAAI,QAAQ,cAAc;AAC/D;AAgBO,SAAS,wBAAwB,SAAsB;AAC5D,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AACJ,QAAM,cAAc,qBAAqB,OAAO;AAChD,MAAI,YAAY,GAAG,CAAC,GAAG;AACrB,WAAO,YAAY,CAAC;AAAA,EACtB;AACA,QAAM,iBAAiB,YAAY,GAAG,sBAAsB;AAE5D,MAAI;AACJ,MAAI,gBAAgB;AAClB,UAAM,kBAAkB,iBAAiB;AAAA,MACvC,YAAY,WAAW,EACpB,MAAM,sBAAsB,EAC5B,IAAI,WAAW,IAAI,MAAM,sBAAsB,CAAC;AAAA,IACrD;AACA,iBAAa,cAAc,KAAK,gBAAgB,EAAE,KAAK,eAAe;AAAA,EACxE,OAAO;AACL,UAAM,kBAAkB,YACrB,IAAI,sBAAsB,EAC1B,MAAM,gBAAgB;AACzB,iBAAa,cAAc,KAAK,eAAe;AAAA,EACjD;AAEA,SAAO,WAAW,IAAI,cAAc,IAAI;AAC1C;AAQO,SAAS,2BACd,SACA,SACA,gBACA;AACA,QAAM,sBAAsB,wBAAwB,OAAO;AAG3D,QAAM,oBACJ,oBAAoB,KAAK,CAAC,EAAE,SAAS,KAAK,YAAY,OAAO,EAAE,SAAS,IACxE;AACF,SAAO,YAAY,iBAAiB,EAAE,KAAK,YAAY,cAAc,CAAC;AACxE;AASO,SAAS,oCACd,SACA,SACA,iBACA,gBACA;AACA,QAAM,cAAc,qBAAqB,OAAO;AAChD,MAAI,YAAY,GAAG,CAAC,GAAG;AACrB,WAAO,YAAY,CAAC;AAAA,EACtB;AACA,SAAO,YACJ,MAAM,2BAA2B,SAAS,SAAS,YAAY,CAAC,CAAC,CAAC,EAClE,MAAM,WAAW,IAAI,MAAM,YAAY,eAAe,CAAC,CAAC,EACxD,KAAK,YAAY,cAAc,CAAC;AACrC;","names":[]}
|
|
@@ -17,21 +17,21 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
|
-
// src/utils/math/
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
23
|
-
|
|
20
|
+
// src/utils/math/BigNumbers.ts
|
|
21
|
+
var BigNumbers_exports = {};
|
|
22
|
+
__export(BigNumbers_exports, {
|
|
23
|
+
BigNumbers: () => BigNumbers
|
|
24
24
|
});
|
|
25
|
-
module.exports = __toCommonJS(
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
ZERO: (0,
|
|
29
|
-
ONE: (0,
|
|
30
|
-
INF: (0,
|
|
31
|
-
MAX_I128: (0,
|
|
25
|
+
module.exports = __toCommonJS(BigNumbers_exports);
|
|
26
|
+
var import_bigNumber = require("./bigNumber.cjs");
|
|
27
|
+
var BigNumbers = Object.freeze({
|
|
28
|
+
ZERO: (0, import_bigNumber.toBigNumber)(0),
|
|
29
|
+
ONE: (0, import_bigNumber.toBigNumber)(1),
|
|
30
|
+
INF: (0, import_bigNumber.toBigNumber)(Infinity),
|
|
31
|
+
MAX_I128: (0, import_bigNumber.toBigNumber)("170141183460469231731687303715884105727")
|
|
32
32
|
});
|
|
33
33
|
// Annotate the CommonJS export names for ESM import in node:
|
|
34
34
|
0 && (module.exports = {
|
|
35
|
-
|
|
35
|
+
BigNumbers
|
|
36
36
|
});
|
|
37
|
-
//# sourceMappingURL=
|
|
37
|
+
//# sourceMappingURL=BigNumbers.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/math/BigNumbers.ts"],"sourcesContent":["import { toBigNumber } from './bigNumber';\n\nexport const BigNumbers = Object.freeze({\n ZERO: toBigNumber(0),\n ONE: toBigNumber(1),\n INF: toBigNumber(Infinity),\n MAX_I128: toBigNumber('170141183460469231731687303715884105727'),\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAA4B;AAErB,IAAM,aAAa,OAAO,OAAO;AAAA,EACtC,UAAM,8BAAY,CAAC;AAAA,EACnB,SAAK,8BAAY,CAAC;AAAA,EAClB,SAAK,8BAAY,QAAQ;AAAA,EACzB,cAAU,8BAAY,yCAAyC;AACjE,CAAC;","names":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import "../../chunk-5WRI5ZAA.js";
|
|
2
|
+
|
|
3
|
+
// src/utils/math/BigNumbers.ts
|
|
4
|
+
import { toBigNumber } from "./bigNumber.js";
|
|
5
|
+
var BigNumbers = Object.freeze({
|
|
6
|
+
ZERO: toBigNumber(0),
|
|
7
|
+
ONE: toBigNumber(1),
|
|
8
|
+
INF: toBigNumber(Infinity),
|
|
9
|
+
MAX_I128: toBigNumber("170141183460469231731687303715884105727")
|
|
10
|
+
});
|
|
11
|
+
export {
|
|
12
|
+
BigNumbers
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=BigNumbers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/math/BigNumbers.ts"],"sourcesContent":["import { toBigNumber } from './bigNumber';\n\nexport const BigNumbers = Object.freeze({\n ZERO: toBigNumber(0),\n ONE: toBigNumber(1),\n INF: toBigNumber(Infinity),\n MAX_I128: toBigNumber('170141183460469231731687303715884105727'),\n});\n"],"mappings":";;;AAAA,SAAS,mBAAmB;AAErB,IAAM,aAAa,OAAO,OAAO;AAAA,EACtC,MAAM,YAAY,CAAC;AAAA,EACnB,KAAK,YAAY,CAAC;AAAA,EAClB,KAAK,YAAY,QAAQ;AAAA,EACzB,UAAU,YAAY,yCAAyC;AACjE,CAAC;","names":[]}
|
|
@@ -27,20 +27,19 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
|
|
30
|
-
// src/utils/math/
|
|
31
|
-
var
|
|
32
|
-
__export(
|
|
33
|
-
|
|
34
|
-
toBigDecimal: () => toBigDecimal
|
|
30
|
+
// src/utils/math/bigNumber.ts
|
|
31
|
+
var bigNumber_exports = {};
|
|
32
|
+
__export(bigNumber_exports, {
|
|
33
|
+
toBigNumber: () => toBigNumber
|
|
35
34
|
});
|
|
36
|
-
module.exports = __toCommonJS(
|
|
35
|
+
module.exports = __toCommonJS(bigNumber_exports);
|
|
37
36
|
var import_bignumber = __toESM(require("bignumber.js"), 1);
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
function toBigNumber(val) {
|
|
38
|
+
if (import_bignumber.default.isBigNumber(val)) {
|
|
39
|
+
return val;
|
|
40
|
+
}
|
|
40
41
|
const bnConstructorVal = (() => {
|
|
41
|
-
if (val
|
|
42
|
-
return val;
|
|
43
|
-
} else if (typeof val === "string" || typeof val === "number") {
|
|
42
|
+
if (typeof val === "string" || typeof val === "number") {
|
|
44
43
|
return val;
|
|
45
44
|
} else if (typeof val === "bigint") {
|
|
46
45
|
return val.toString();
|
|
@@ -51,7 +50,6 @@ function toBigDecimal(val) {
|
|
|
51
50
|
}
|
|
52
51
|
// Annotate the CommonJS export names for ESM import in node:
|
|
53
52
|
0 && (module.exports = {
|
|
54
|
-
|
|
55
|
-
toBigDecimal
|
|
53
|
+
toBigNumber
|
|
56
54
|
});
|
|
57
|
-
//# sourceMappingURL=
|
|
55
|
+
//# sourceMappingURL=bigNumber.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/math/bigNumber.ts"],"sourcesContent":["import BigNumber from 'bignumber.js';\n\n/**\n * BigNumber is the type from `bignumber.js`.\n * Includes valid values & instances for BigNumber.\n *\n * @see https://mikemcl.github.io/bignumber.js/\n */\nexport type BigNumberish = BigNumber | BigNumber.Value | bigint;\n\n/**\n * Converts a value to an instance of BigNumber\n *\n * @param val\n */\nexport function toBigNumber(val: BigNumberish): BigNumber {\n if (BigNumber.isBigNumber(val)) {\n return val;\n }\n\n const bnConstructorVal = (() => {\n if (typeof val === 'string' || typeof val === 'number') {\n return val;\n } else if (typeof val === 'bigint') {\n return val.toString();\n }\n // This is unlikely to occur, but it's here for completeness. Uses the suggestion here: https://typescript-eslint.io/rules/no-base-to-string/#alternatives\n return JSON.stringify(val);\n })();\n return new BigNumber(bnConstructorVal);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAsB;AAef,SAAS,YAAY,KAA8B;AACxD,MAAI,iBAAAA,QAAU,YAAY,GAAG,GAAG;AAC9B,WAAO;AAAA,EACT;AAEA,QAAM,oBAAoB,MAAM;AAC9B,QAAI,OAAO,QAAQ,YAAY,OAAO,QAAQ,UAAU;AACtD,aAAO;AAAA,IACT,WAAW,OAAO,QAAQ,UAAU;AAClC,aAAO,IAAI,SAAS;AAAA,IACtB;AAEA,WAAO,KAAK,UAAU,GAAG;AAAA,EAC3B,GAAG;AACH,SAAO,IAAI,iBAAAA,QAAU,gBAAgB;AACvC;","names":["BigNumber"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import BigNumber__default from 'bignumber.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* BigNumber is the type from `bignumber.js`.
|
|
5
|
+
* Includes valid values & instances for BigNumber.
|
|
6
|
+
*
|
|
7
|
+
* @see https://mikemcl.github.io/bignumber.js/
|
|
8
|
+
*/
|
|
9
|
+
type BigNumberish = BigNumber__default | BigNumber__default.Value | bigint;
|
|
10
|
+
/**
|
|
11
|
+
* Converts a value to an instance of BigNumber
|
|
12
|
+
*
|
|
13
|
+
* @param val
|
|
14
|
+
*/
|
|
15
|
+
declare function toBigNumber(val: BigNumberish): BigNumber__default;
|
|
16
|
+
|
|
17
|
+
export { type BigNumberish, toBigNumber };
|