@nadohq/shared 0.1.0-alpha.51 → 0.1.0-alpha.52
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/types/balanceTypes.d.cts +4 -4
- package/dist/types/balanceTypes.d.ts +4 -4
- package/dist/types/healthTypes.d.cts +4 -4
- package/dist/types/healthTypes.d.ts +4 -4
- package/dist/types/marketTypes.d.cts +4 -4
- package/dist/types/marketTypes.d.ts +4 -4
- package/dist/types/productTypes.d.cts +16 -16
- package/dist/types/productTypes.d.ts +16 -16
- package/dist/utils/balanceValue.d.cts +4 -4
- package/dist/utils/balanceValue.d.ts +4 -4
- package/dist/utils/interest.d.cts +7 -7
- package/dist/utils/interest.d.ts +7 -7
- package/dist/utils/math/BigDecimals.d.cts +6 -4
- package/dist/utils/math/BigDecimals.d.ts +6 -4
- package/dist/utils/math/bigDecimal.d.cts +3 -3
- package/dist/utils/math/bigDecimal.d.ts +3 -3
- package/dist/utils/math/clamp.d.cts +4 -4
- package/dist/utils/math/clamp.d.ts +4 -4
- package/dist/utils/math/decimalAdjustment.d.cts +2 -2
- package/dist/utils/math/decimalAdjustment.d.ts +2 -2
- package/dist/utils/math/sumBigDecimalBy.d.cts +2 -2
- package/dist/utils/math/sumBigDecimalBy.d.ts +2 -2
- package/dist/utils/toPrintableObject.d.cts +2 -2
- package/dist/utils/toPrintableObject.d.ts +2 -2
- package/package.json +4 -4
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BigDecimal__default from 'bignumber.js';
|
|
2
2
|
import { HealthType } from './healthTypes.cjs';
|
|
3
3
|
import { ProductEngineType, SpotProduct, PerpProduct } from './productTypes.cjs';
|
|
4
4
|
|
|
5
5
|
type BalanceSide = 'long' | 'short';
|
|
6
|
-
type BalanceHealthContributions = Record<HealthType,
|
|
6
|
+
type BalanceHealthContributions = Record<HealthType, BigDecimal__default>;
|
|
7
7
|
/**
|
|
8
8
|
* Shared properties of a product balance
|
|
9
9
|
*/
|
|
10
10
|
interface BaseBalance {
|
|
11
11
|
type: ProductEngineType;
|
|
12
12
|
productId: number;
|
|
13
|
-
amount:
|
|
13
|
+
amount: BigDecimal__default;
|
|
14
14
|
healthContributions: BalanceHealthContributions;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
@@ -22,7 +22,7 @@ interface PerpBalance extends BaseBalance {
|
|
|
22
22
|
* As there is no "quote" product for the perp engine, this is a representation of the net quote balance
|
|
23
23
|
* associated with the position. The entry cost and funding is rolled into this.
|
|
24
24
|
*/
|
|
25
|
-
vQuoteBalance:
|
|
25
|
+
vQuoteBalance: BigDecimal__default;
|
|
26
26
|
}
|
|
27
27
|
type PerpBalanceWithProduct = PerpBalance & PerpProduct;
|
|
28
28
|
/**
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BigDecimal__default from 'bignumber.js';
|
|
2
2
|
import { HealthType } from './healthTypes.js';
|
|
3
3
|
import { ProductEngineType, SpotProduct, PerpProduct } from './productTypes.js';
|
|
4
4
|
|
|
5
5
|
type BalanceSide = 'long' | 'short';
|
|
6
|
-
type BalanceHealthContributions = Record<HealthType,
|
|
6
|
+
type BalanceHealthContributions = Record<HealthType, BigDecimal__default>;
|
|
7
7
|
/**
|
|
8
8
|
* Shared properties of a product balance
|
|
9
9
|
*/
|
|
10
10
|
interface BaseBalance {
|
|
11
11
|
type: ProductEngineType;
|
|
12
12
|
productId: number;
|
|
13
|
-
amount:
|
|
13
|
+
amount: BigDecimal__default;
|
|
14
14
|
healthContributions: BalanceHealthContributions;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
@@ -22,7 +22,7 @@ interface PerpBalance extends BaseBalance {
|
|
|
22
22
|
* As there is no "quote" product for the perp engine, this is a representation of the net quote balance
|
|
23
23
|
* associated with the position. The entry cost and funding is rolled into this.
|
|
24
24
|
*/
|
|
25
|
-
vQuoteBalance:
|
|
25
|
+
vQuoteBalance: BigDecimal__default;
|
|
26
26
|
}
|
|
27
27
|
type PerpBalanceWithProduct = PerpBalance & PerpProduct;
|
|
28
28
|
/**
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BigDecimal__default from 'bignumber.js';
|
|
2
2
|
|
|
3
3
|
type HealthType = 'maintenance' | 'initial' | 'unweighted';
|
|
4
4
|
interface HealthStatus {
|
|
5
|
-
health:
|
|
6
|
-
assets:
|
|
7
|
-
liabilities:
|
|
5
|
+
health: BigDecimal__default;
|
|
6
|
+
assets: BigDecimal__default;
|
|
7
|
+
liabilities: BigDecimal__default;
|
|
8
8
|
}
|
|
9
9
|
type HealthStatusByType = Record<HealthType, HealthStatus>;
|
|
10
10
|
interface HealthGroup {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BigDecimal__default from 'bignumber.js';
|
|
2
2
|
|
|
3
3
|
type HealthType = 'maintenance' | 'initial' | 'unweighted';
|
|
4
4
|
interface HealthStatus {
|
|
5
|
-
health:
|
|
6
|
-
assets:
|
|
7
|
-
liabilities:
|
|
5
|
+
health: BigDecimal__default;
|
|
6
|
+
assets: BigDecimal__default;
|
|
7
|
+
liabilities: BigDecimal__default;
|
|
8
8
|
}
|
|
9
9
|
type HealthStatusByType = Record<HealthType, HealthStatus>;
|
|
10
10
|
interface HealthGroup {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BigDecimal__default from 'bignumber.js';
|
|
2
2
|
import { ProductEngineType, Product, PerpProduct, SpotProduct } from './productTypes.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -8,9 +8,9 @@ interface Market {
|
|
|
8
8
|
productId: number;
|
|
9
9
|
type: ProductEngineType;
|
|
10
10
|
product: Product;
|
|
11
|
-
minSize:
|
|
12
|
-
priceIncrement:
|
|
13
|
-
sizeIncrement:
|
|
11
|
+
minSize: BigDecimal__default;
|
|
12
|
+
priceIncrement: BigDecimal__default;
|
|
13
|
+
sizeIncrement: BigDecimal__default;
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
16
|
* Perp market with perp product info
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BigDecimal__default from 'bignumber.js';
|
|
2
2
|
import { ProductEngineType, Product, PerpProduct, SpotProduct } from './productTypes.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -8,9 +8,9 @@ interface Market {
|
|
|
8
8
|
productId: number;
|
|
9
9
|
type: ProductEngineType;
|
|
10
10
|
product: Product;
|
|
11
|
-
minSize:
|
|
12
|
-
priceIncrement:
|
|
13
|
-
sizeIncrement:
|
|
11
|
+
minSize: BigDecimal__default;
|
|
12
|
+
priceIncrement: BigDecimal__default;
|
|
13
|
+
sizeIncrement: BigDecimal__default;
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
16
|
* Perp market with perp product info
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BigDecimal__default from 'bignumber.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Representation of the ProductEngineType enum used within the contract
|
|
@@ -19,20 +19,20 @@ declare function toProductEngineType(val: number): ProductEngineType;
|
|
|
19
19
|
interface BaseProduct {
|
|
20
20
|
type: ProductEngineType;
|
|
21
21
|
productId: number;
|
|
22
|
-
oraclePrice:
|
|
23
|
-
longWeightInitial:
|
|
24
|
-
shortWeightInitial:
|
|
25
|
-
longWeightMaintenance:
|
|
26
|
-
shortWeightMaintenance:
|
|
22
|
+
oraclePrice: BigDecimal__default;
|
|
23
|
+
longWeightInitial: BigDecimal__default;
|
|
24
|
+
shortWeightInitial: BigDecimal__default;
|
|
25
|
+
longWeightMaintenance: BigDecimal__default;
|
|
26
|
+
shortWeightMaintenance: BigDecimal__default;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* Represents a product stored in PerpEngine
|
|
30
30
|
*/
|
|
31
31
|
interface PerpProduct extends BaseProduct {
|
|
32
32
|
type: ProductEngineType.PERP;
|
|
33
|
-
openInterest:
|
|
34
|
-
cumulativeFundingLong:
|
|
35
|
-
cumulativeFundingShort:
|
|
33
|
+
openInterest: BigDecimal__default;
|
|
34
|
+
cumulativeFundingLong: BigDecimal__default;
|
|
35
|
+
cumulativeFundingShort: BigDecimal__default;
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
38
|
* Represents a product stored in SpotEngine.
|
|
@@ -42,13 +42,13 @@ interface PerpProduct extends BaseProduct {
|
|
|
42
42
|
interface SpotProduct extends BaseProduct {
|
|
43
43
|
type: ProductEngineType.SPOT;
|
|
44
44
|
tokenAddr: string;
|
|
45
|
-
interestFloor:
|
|
46
|
-
interestInflectionUtil:
|
|
47
|
-
interestSmallCap:
|
|
48
|
-
interestLargeCap:
|
|
49
|
-
minDepositRate:
|
|
50
|
-
totalDeposited:
|
|
51
|
-
totalBorrowed:
|
|
45
|
+
interestFloor: BigDecimal__default;
|
|
46
|
+
interestInflectionUtil: BigDecimal__default;
|
|
47
|
+
interestSmallCap: BigDecimal__default;
|
|
48
|
+
interestLargeCap: BigDecimal__default;
|
|
49
|
+
minDepositRate: BigDecimal__default;
|
|
50
|
+
totalDeposited: BigDecimal__default;
|
|
51
|
+
totalBorrowed: BigDecimal__default;
|
|
52
52
|
}
|
|
53
53
|
type Product = PerpProduct | SpotProduct;
|
|
54
54
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BigDecimal__default from 'bignumber.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Representation of the ProductEngineType enum used within the contract
|
|
@@ -19,20 +19,20 @@ declare function toProductEngineType(val: number): ProductEngineType;
|
|
|
19
19
|
interface BaseProduct {
|
|
20
20
|
type: ProductEngineType;
|
|
21
21
|
productId: number;
|
|
22
|
-
oraclePrice:
|
|
23
|
-
longWeightInitial:
|
|
24
|
-
shortWeightInitial:
|
|
25
|
-
longWeightMaintenance:
|
|
26
|
-
shortWeightMaintenance:
|
|
22
|
+
oraclePrice: BigDecimal__default;
|
|
23
|
+
longWeightInitial: BigDecimal__default;
|
|
24
|
+
shortWeightInitial: BigDecimal__default;
|
|
25
|
+
longWeightMaintenance: BigDecimal__default;
|
|
26
|
+
shortWeightMaintenance: BigDecimal__default;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* Represents a product stored in PerpEngine
|
|
30
30
|
*/
|
|
31
31
|
interface PerpProduct extends BaseProduct {
|
|
32
32
|
type: ProductEngineType.PERP;
|
|
33
|
-
openInterest:
|
|
34
|
-
cumulativeFundingLong:
|
|
35
|
-
cumulativeFundingShort:
|
|
33
|
+
openInterest: BigDecimal__default;
|
|
34
|
+
cumulativeFundingLong: BigDecimal__default;
|
|
35
|
+
cumulativeFundingShort: BigDecimal__default;
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
38
|
* Represents a product stored in SpotEngine.
|
|
@@ -42,13 +42,13 @@ interface PerpProduct extends BaseProduct {
|
|
|
42
42
|
interface SpotProduct extends BaseProduct {
|
|
43
43
|
type: ProductEngineType.SPOT;
|
|
44
44
|
tokenAddr: string;
|
|
45
|
-
interestFloor:
|
|
46
|
-
interestInflectionUtil:
|
|
47
|
-
interestSmallCap:
|
|
48
|
-
interestLargeCap:
|
|
49
|
-
minDepositRate:
|
|
50
|
-
totalDeposited:
|
|
51
|
-
totalBorrowed:
|
|
45
|
+
interestFloor: BigDecimal__default;
|
|
46
|
+
interestInflectionUtil: BigDecimal__default;
|
|
47
|
+
interestSmallCap: BigDecimal__default;
|
|
48
|
+
interestLargeCap: BigDecimal__default;
|
|
49
|
+
minDepositRate: BigDecimal__default;
|
|
50
|
+
totalDeposited: BigDecimal__default;
|
|
51
|
+
totalBorrowed: BigDecimal__default;
|
|
52
52
|
}
|
|
53
53
|
type Product = PerpProduct | SpotProduct;
|
|
54
54
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PerpBalanceWithProduct, SpotBalanceWithProduct } from '../types/balanceTypes.cjs';
|
|
2
|
-
import
|
|
2
|
+
import BigDecimal__default from 'bignumber.js';
|
|
3
3
|
import '../types/healthTypes.cjs';
|
|
4
4
|
import '../types/productTypes.cjs';
|
|
5
5
|
|
|
@@ -8,18 +8,18 @@ import '../types/productTypes.cjs';
|
|
|
8
8
|
*
|
|
9
9
|
* @param balanceWithProduct
|
|
10
10
|
*/
|
|
11
|
-
declare function calcSpotBalanceValue(balanceWithProduct: SpotBalanceWithProduct):
|
|
11
|
+
declare function calcSpotBalanceValue(balanceWithProduct: SpotBalanceWithProduct): BigDecimal__default;
|
|
12
12
|
/**
|
|
13
13
|
* Calculates the notional value of a perp balance, in terms of quote units
|
|
14
14
|
*
|
|
15
15
|
* @param balanceWithProduct
|
|
16
16
|
*/
|
|
17
|
-
declare function calcPerpBalanceNotionalValue(balanceWithProduct: PerpBalanceWithProduct):
|
|
17
|
+
declare function calcPerpBalanceNotionalValue(balanceWithProduct: PerpBalanceWithProduct): BigDecimal__default;
|
|
18
18
|
/**
|
|
19
19
|
* Calculates the true quote value of a perp balance, which is the same as its unrealized pnl / unsettled quote, in terms of quote units
|
|
20
20
|
*
|
|
21
21
|
* @param balanceWithProduct
|
|
22
22
|
*/
|
|
23
|
-
declare function calcPerpBalanceValue(balanceWithProduct: PerpBalanceWithProduct):
|
|
23
|
+
declare function calcPerpBalanceValue(balanceWithProduct: PerpBalanceWithProduct): BigDecimal__default;
|
|
24
24
|
|
|
25
25
|
export { calcPerpBalanceNotionalValue, calcPerpBalanceValue, calcSpotBalanceValue };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PerpBalanceWithProduct, SpotBalanceWithProduct } from '../types/balanceTypes.js';
|
|
2
|
-
import
|
|
2
|
+
import BigDecimal__default from 'bignumber.js';
|
|
3
3
|
import '../types/healthTypes.js';
|
|
4
4
|
import '../types/productTypes.js';
|
|
5
5
|
|
|
@@ -8,18 +8,18 @@ import '../types/productTypes.js';
|
|
|
8
8
|
*
|
|
9
9
|
* @param balanceWithProduct
|
|
10
10
|
*/
|
|
11
|
-
declare function calcSpotBalanceValue(balanceWithProduct: SpotBalanceWithProduct):
|
|
11
|
+
declare function calcSpotBalanceValue(balanceWithProduct: SpotBalanceWithProduct): BigDecimal__default;
|
|
12
12
|
/**
|
|
13
13
|
* Calculates the notional value of a perp balance, in terms of quote units
|
|
14
14
|
*
|
|
15
15
|
* @param balanceWithProduct
|
|
16
16
|
*/
|
|
17
|
-
declare function calcPerpBalanceNotionalValue(balanceWithProduct: PerpBalanceWithProduct):
|
|
17
|
+
declare function calcPerpBalanceNotionalValue(balanceWithProduct: PerpBalanceWithProduct): BigDecimal__default;
|
|
18
18
|
/**
|
|
19
19
|
* Calculates the true quote value of a perp balance, which is the same as its unrealized pnl / unsettled quote, in terms of quote units
|
|
20
20
|
*
|
|
21
21
|
* @param balanceWithProduct
|
|
22
22
|
*/
|
|
23
|
-
declare function calcPerpBalanceValue(balanceWithProduct: PerpBalanceWithProduct):
|
|
23
|
+
declare function calcPerpBalanceValue(balanceWithProduct: PerpBalanceWithProduct): BigDecimal__default;
|
|
24
24
|
|
|
25
25
|
export { calcPerpBalanceNotionalValue, calcPerpBalanceValue, calcSpotBalanceValue };
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { SpotProduct } from '../types/productTypes.cjs';
|
|
2
2
|
import { BigDecimalish } from './math/bigDecimal.cjs';
|
|
3
|
-
import
|
|
3
|
+
import BigDecimal__default from 'bignumber.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Calculate amount total borrowed for a product
|
|
7
7
|
*/
|
|
8
|
-
declare function calcTotalBorrowed(totalBorrowsNormalized: BigDecimalish, cumulativeBorrowsMultiplierX18: BigDecimalish):
|
|
8
|
+
declare function calcTotalBorrowed(totalBorrowsNormalized: BigDecimalish, cumulativeBorrowsMultiplierX18: BigDecimalish): BigDecimal__default;
|
|
9
9
|
/**
|
|
10
10
|
* Calculate amount total deposited for a product.
|
|
11
11
|
*/
|
|
12
|
-
declare function calcTotalDeposited(totalDepositsNormalized: BigDecimalish, cumulativeDepositsMultiplierX18: BigDecimalish):
|
|
12
|
+
declare function calcTotalDeposited(totalDepositsNormalized: BigDecimalish, cumulativeDepositsMultiplierX18: BigDecimalish): BigDecimal__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): BigDecimal__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): BigDecimal__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: BigDecimalish, minDepositRate: BigDecimalish):
|
|
40
|
+
declare function calcBorrowRateForTimeRange(product: SpotProduct, seconds: BigDecimalish, minDepositRate: BigDecimalish): BigDecimal__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: BigDecimalish, interestFeeFrac: BigDecimalish, minDepositRate: BigDecimalish):
|
|
48
|
+
declare function calcRealizedDepositRateForTimeRange(product: SpotProduct, seconds: BigDecimalish, interestFeeFrac: BigDecimalish, minDepositRate: BigDecimalish): BigDecimal__default;
|
|
49
49
|
|
|
50
50
|
export { calcBorrowRateForTimeRange, calcBorrowRatePerSecond, calcRealizedDepositRateForTimeRange, calcTotalBorrowed, calcTotalDeposited, calcUtilizationRatio };
|
package/dist/utils/interest.d.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { SpotProduct } from '../types/productTypes.js';
|
|
2
2
|
import { BigDecimalish } from './math/bigDecimal.js';
|
|
3
|
-
import
|
|
3
|
+
import BigDecimal__default from 'bignumber.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Calculate amount total borrowed for a product
|
|
7
7
|
*/
|
|
8
|
-
declare function calcTotalBorrowed(totalBorrowsNormalized: BigDecimalish, cumulativeBorrowsMultiplierX18: BigDecimalish):
|
|
8
|
+
declare function calcTotalBorrowed(totalBorrowsNormalized: BigDecimalish, cumulativeBorrowsMultiplierX18: BigDecimalish): BigDecimal__default;
|
|
9
9
|
/**
|
|
10
10
|
* Calculate amount total deposited for a product.
|
|
11
11
|
*/
|
|
12
|
-
declare function calcTotalDeposited(totalDepositsNormalized: BigDecimalish, cumulativeDepositsMultiplierX18: BigDecimalish):
|
|
12
|
+
declare function calcTotalDeposited(totalDepositsNormalized: BigDecimalish, cumulativeDepositsMultiplierX18: BigDecimalish): BigDecimal__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): BigDecimal__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): BigDecimal__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: BigDecimalish, minDepositRate: BigDecimalish):
|
|
40
|
+
declare function calcBorrowRateForTimeRange(product: SpotProduct, seconds: BigDecimalish, minDepositRate: BigDecimalish): BigDecimal__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: BigDecimalish, interestFeeFrac: BigDecimalish, minDepositRate: BigDecimalish):
|
|
48
|
+
declare function calcRealizedDepositRateForTimeRange(product: SpotProduct, seconds: BigDecimalish, interestFeeFrac: BigDecimalish, minDepositRate: BigDecimalish): BigDecimal__default;
|
|
49
49
|
|
|
50
50
|
export { calcBorrowRateForTimeRange, calcBorrowRatePerSecond, calcRealizedDepositRateForTimeRange, calcTotalBorrowed, calcTotalDeposited, calcUtilizationRatio };
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import * as BigDecimal from 'bignumber.js';
|
|
2
|
+
|
|
1
3
|
declare const BigDecimals: Readonly<{
|
|
2
|
-
ZERO: BigNumber;
|
|
3
|
-
ONE: BigNumber;
|
|
4
|
-
INF: BigNumber;
|
|
5
|
-
MAX_I128: BigNumber;
|
|
4
|
+
ZERO: BigDecimal.BigNumber;
|
|
5
|
+
ONE: BigDecimal.BigNumber;
|
|
6
|
+
INF: BigDecimal.BigNumber;
|
|
7
|
+
MAX_I128: BigDecimal.BigNumber;
|
|
6
8
|
}>;
|
|
7
9
|
|
|
8
10
|
export { BigDecimals };
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import * as BigDecimal from 'bignumber.js';
|
|
2
|
+
|
|
1
3
|
declare const BigDecimals: Readonly<{
|
|
2
|
-
ZERO: BigNumber;
|
|
3
|
-
ONE: BigNumber;
|
|
4
|
-
INF: BigNumber;
|
|
5
|
-
MAX_I128: BigNumber;
|
|
4
|
+
ZERO: BigDecimal.BigNumber;
|
|
5
|
+
ONE: BigDecimal.BigNumber;
|
|
6
|
+
INF: BigDecimal.BigNumber;
|
|
7
|
+
MAX_I128: BigDecimal.BigNumber;
|
|
6
8
|
}>;
|
|
7
9
|
|
|
8
10
|
export { BigDecimals };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BigDecimal__default from 'bignumber.js';
|
|
2
2
|
export { default as BigDecimal } from 'bignumber.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -7,12 +7,12 @@ export { default as BigDecimal } from 'bignumber.js';
|
|
|
7
7
|
*
|
|
8
8
|
* @see https://mikemcl.github.io/bignumber.js/
|
|
9
9
|
*/
|
|
10
|
-
type BigDecimalish =
|
|
10
|
+
type BigDecimalish = BigDecimal__default | BigDecimal__default.Value | bigint;
|
|
11
11
|
/**
|
|
12
12
|
* Converts a value to an instance of BigDecimal
|
|
13
13
|
*
|
|
14
14
|
* @param val
|
|
15
15
|
*/
|
|
16
|
-
declare function toBigDecimal(val: BigDecimalish):
|
|
16
|
+
declare function toBigDecimal(val: BigDecimalish): BigDecimal__default;
|
|
17
17
|
|
|
18
18
|
export { type BigDecimalish, toBigDecimal };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BigDecimal__default from 'bignumber.js';
|
|
2
2
|
export { default as BigDecimal } from 'bignumber.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -7,12 +7,12 @@ export { default as BigDecimal } from 'bignumber.js';
|
|
|
7
7
|
*
|
|
8
8
|
* @see https://mikemcl.github.io/bignumber.js/
|
|
9
9
|
*/
|
|
10
|
-
type BigDecimalish =
|
|
10
|
+
type BigDecimalish = BigDecimal__default | BigDecimal__default.Value | bigint;
|
|
11
11
|
/**
|
|
12
12
|
* Converts a value to an instance of BigDecimal
|
|
13
13
|
*
|
|
14
14
|
* @param val
|
|
15
15
|
*/
|
|
16
|
-
declare function toBigDecimal(val: BigDecimalish):
|
|
16
|
+
declare function toBigDecimal(val: BigDecimalish): BigDecimal__default;
|
|
17
17
|
|
|
18
18
|
export { type BigDecimalish, toBigDecimal };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BigDecimal__default from 'bignumber.js';
|
|
2
2
|
|
|
3
3
|
interface ClampOptions {
|
|
4
|
-
min?:
|
|
5
|
-
max?:
|
|
4
|
+
min?: BigDecimal__default;
|
|
5
|
+
max?: BigDecimal__default;
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
8
|
* Clamps a value between optional minimum and maximum values.
|
|
@@ -10,6 +10,6 @@ interface ClampOptions {
|
|
|
10
10
|
* @param val
|
|
11
11
|
* @param opts Clamp options
|
|
12
12
|
*/
|
|
13
|
-
declare function clampBigDecimal(val:
|
|
13
|
+
declare function clampBigDecimal(val: BigDecimal__default, opts: ClampOptions): BigDecimal__default;
|
|
14
14
|
|
|
15
15
|
export { clampBigDecimal };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BigDecimal__default from 'bignumber.js';
|
|
2
2
|
|
|
3
3
|
interface ClampOptions {
|
|
4
|
-
min?:
|
|
5
|
-
max?:
|
|
4
|
+
min?: BigDecimal__default;
|
|
5
|
+
max?: BigDecimal__default;
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
8
|
* Clamps a value between optional minimum and maximum values.
|
|
@@ -10,6 +10,6 @@ interface ClampOptions {
|
|
|
10
10
|
* @param val
|
|
11
11
|
* @param opts Clamp options
|
|
12
12
|
*/
|
|
13
|
-
declare function clampBigDecimal(val:
|
|
13
|
+
declare function clampBigDecimal(val: BigDecimal__default, opts: ClampOptions): BigDecimal__default;
|
|
14
14
|
|
|
15
15
|
export { clampBigDecimal };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BigDecimalish } from './bigDecimal.cjs';
|
|
2
|
-
import
|
|
2
|
+
import BigDecimal__default from 'bignumber.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* All Nado balances have 18 decimals. Ex. 1e18 = 1.0
|
|
@@ -12,7 +12,7 @@ declare const NADO_PRODUCT_DECIMALS = 18;
|
|
|
12
12
|
* - If `T` is a `number`, the result is a `number`.
|
|
13
13
|
* - Otherwise, the result is a `BigDecimal`.
|
|
14
14
|
*/
|
|
15
|
-
type AdjustDecimalsResult<T extends BigDecimalish | undefined> = T extends undefined ? undefined : T extends number ? number :
|
|
15
|
+
type AdjustDecimalsResult<T extends BigDecimalish | undefined> = T extends undefined ? undefined : T extends number ? number : BigDecimal__default;
|
|
16
16
|
/**
|
|
17
17
|
* Adds the specified # of decimals to the number. For example, value = 1, decimals = 2, returns 100.
|
|
18
18
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BigDecimalish } from './bigDecimal.js';
|
|
2
|
-
import
|
|
2
|
+
import BigDecimal__default from 'bignumber.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* All Nado balances have 18 decimals. Ex. 1e18 = 1.0
|
|
@@ -12,7 +12,7 @@ declare const NADO_PRODUCT_DECIMALS = 18;
|
|
|
12
12
|
* - If `T` is a `number`, the result is a `number`.
|
|
13
13
|
* - Otherwise, the result is a `BigDecimal`.
|
|
14
14
|
*/
|
|
15
|
-
type AdjustDecimalsResult<T extends BigDecimalish | undefined> = T extends undefined ? undefined : T extends number ? number :
|
|
15
|
+
type AdjustDecimalsResult<T extends BigDecimalish | undefined> = T extends undefined ? undefined : T extends number ? number : BigDecimal__default;
|
|
16
16
|
/**
|
|
17
17
|
* Adds the specified # of decimals to the number. For example, value = 1, decimals = 2, returns 100.
|
|
18
18
|
*
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BigDecimal__default from 'bignumber.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Util function to sum BigDecimal values, inspired by Lodash
|
|
5
5
|
* @param collection
|
|
6
6
|
* @param iteratee
|
|
7
7
|
*/
|
|
8
|
-
declare function sumBigDecimalBy<T>(collection: T[] | null | undefined, iteratee: (value: T) =>
|
|
8
|
+
declare function sumBigDecimalBy<T>(collection: T[] | null | undefined, iteratee: (value: T) => BigDecimal__default.Value): BigDecimal__default;
|
|
9
9
|
|
|
10
10
|
export { sumBigDecimalBy };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BigDecimal__default from 'bignumber.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Util function to sum BigDecimal values, inspired by Lodash
|
|
5
5
|
* @param collection
|
|
6
6
|
* @param iteratee
|
|
7
7
|
*/
|
|
8
|
-
declare function sumBigDecimalBy<T>(collection: T[] | null | undefined, iteratee: (value: T) =>
|
|
8
|
+
declare function sumBigDecimalBy<T>(collection: T[] | null | undefined, iteratee: (value: T) => BigDecimal__default.Value): BigDecimal__default;
|
|
9
9
|
|
|
10
10
|
export { sumBigDecimalBy };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BigDecimal__default from 'bignumber.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Util for converting any BigDecimal types into a string so that it can be logged nicely.
|
|
5
5
|
* Handles cyclic references by returning '[Circular]' for already-visited objects.
|
|
6
6
|
*/
|
|
7
7
|
declare function toPrintableObject(obj: null | undefined, seen?: WeakSet<object>): null;
|
|
8
|
-
declare function toPrintableObject(obj:
|
|
8
|
+
declare function toPrintableObject(obj: BigDecimal__default | bigint, seen?: WeakSet<object>): string;
|
|
9
9
|
declare function toPrintableObject(obj: unknown, seen?: WeakSet<object>): object;
|
|
10
10
|
|
|
11
11
|
export { toPrintableObject };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BigDecimal__default from 'bignumber.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Util for converting any BigDecimal types into a string so that it can be logged nicely.
|
|
5
5
|
* Handles cyclic references by returning '[Circular]' for already-visited objects.
|
|
6
6
|
*/
|
|
7
7
|
declare function toPrintableObject(obj: null | undefined, seen?: WeakSet<object>): null;
|
|
8
|
-
declare function toPrintableObject(obj:
|
|
8
|
+
declare function toPrintableObject(obj: BigDecimal__default | bigint, seen?: WeakSet<object>): string;
|
|
9
9
|
declare function toPrintableObject(obj: unknown, seen?: WeakSet<object>): object;
|
|
10
10
|
|
|
11
11
|
export { toPrintableObject };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nadohq/shared",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.52",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "Shared utilities, types, and contract helpers for Nado SDK",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"module": "./dist/index.js",
|
|
42
42
|
"types": "./dist/index.d.ts",
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"bignumber.js": "^
|
|
44
|
+
"bignumber.js": "^10.0.2",
|
|
45
45
|
"viem": "*"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@jest/globals": "*",
|
|
52
|
-
"bignumber.js": "^
|
|
52
|
+
"bignumber.js": "^10.0.2",
|
|
53
53
|
"viem": "workspace:*"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "41f74df94ad4408c93f5b0e577513b535106d30d"
|
|
56
56
|
}
|