@chainflip/utils 2.2.0-alpha.3 → 2.2.0-alpha.5
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/lending.cjs +29 -0
- package/dist/lending.d.cts +30 -0
- package/dist/lending.d.mts +30 -0
- package/dist/lending.mjs +22 -0
- package/dist/number.cjs +4 -0
- package/dist/number.d.cts +3 -1
- package/dist/number.d.mts +3 -1
- package/dist/number.mjs +3 -1
- package/package.json +1 -1
package/dist/lending.cjs
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
const require_number = require('./number.cjs');
|
|
4
|
+
let bignumber_js = require("bignumber.js");
|
|
5
|
+
bignumber_js = require_runtime.__toESM(bignumber_js, 1);
|
|
6
|
+
|
|
7
|
+
//#region src/lending.ts
|
|
8
|
+
const ppmToBps = (ppmAmount) => Math.trunc(ppmAmount / 100);
|
|
9
|
+
const ppmToDecimal = (ppmAmount) => ppmAmount / 1e6;
|
|
10
|
+
const calculateLoanToValueBps = ({ totalBorrowAmountUsd, totalCollateralBalanceUsd }) => {
|
|
11
|
+
if (totalCollateralBalanceUsd === 0) return 0;
|
|
12
|
+
return Math.trunc(totalBorrowAmountUsd / totalCollateralBalanceUsd * 1e4);
|
|
13
|
+
};
|
|
14
|
+
const calculateBorrowPowerUsedBps = ({ totalBorrowAmountUsd, totalCollateralBalanceUsd, thresholdDecimal }) => {
|
|
15
|
+
if (totalCollateralBalanceUsd === 0 || thresholdDecimal === 0) return 0;
|
|
16
|
+
return Math.trunc(totalBorrowAmountUsd / (totalCollateralBalanceUsd * thresholdDecimal) * 1e4);
|
|
17
|
+
};
|
|
18
|
+
const calculateTotalEffectiveBorrowableAmount = ({ totalAmount, totalAvailableAmount, utilisationCapBps }) => {
|
|
19
|
+
const totalBorrowedAmount = totalAmount - totalAvailableAmount;
|
|
20
|
+
const totalEffectiveBorrowableAmount = new bignumber_js.default(totalAmount).multipliedBy(utilisationCapBps ?? 1e4).div(1e4).toFixed();
|
|
21
|
+
return require_number.bigintMax(BigInt(totalEffectiveBorrowableAmount) - totalBorrowedAmount, 0n);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
exports.calculateBorrowPowerUsedBps = calculateBorrowPowerUsedBps;
|
|
26
|
+
exports.calculateLoanToValueBps = calculateLoanToValueBps;
|
|
27
|
+
exports.calculateTotalEffectiveBorrowableAmount = calculateTotalEffectiveBorrowableAmount;
|
|
28
|
+
exports.ppmToBps = ppmToBps;
|
|
29
|
+
exports.ppmToDecimal = ppmToDecimal;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/lending.d.ts
|
|
2
|
+
declare const ppmToBps: (ppmAmount: number) => number;
|
|
3
|
+
declare const ppmToDecimal: (ppmAmount: number) => number;
|
|
4
|
+
declare const calculateLoanToValueBps: ({
|
|
5
|
+
totalBorrowAmountUsd,
|
|
6
|
+
totalCollateralBalanceUsd
|
|
7
|
+
}: {
|
|
8
|
+
totalBorrowAmountUsd: number;
|
|
9
|
+
totalCollateralBalanceUsd: number;
|
|
10
|
+
}) => number;
|
|
11
|
+
declare const calculateBorrowPowerUsedBps: ({
|
|
12
|
+
totalBorrowAmountUsd,
|
|
13
|
+
totalCollateralBalanceUsd,
|
|
14
|
+
thresholdDecimal
|
|
15
|
+
}: {
|
|
16
|
+
totalBorrowAmountUsd: number;
|
|
17
|
+
totalCollateralBalanceUsd: number;
|
|
18
|
+
thresholdDecimal: number;
|
|
19
|
+
}) => number;
|
|
20
|
+
declare const calculateTotalEffectiveBorrowableAmount: ({
|
|
21
|
+
totalAmount,
|
|
22
|
+
totalAvailableAmount,
|
|
23
|
+
utilisationCapBps
|
|
24
|
+
}: {
|
|
25
|
+
totalAmount: bigint;
|
|
26
|
+
totalAvailableAmount: bigint;
|
|
27
|
+
utilisationCapBps?: number | null;
|
|
28
|
+
}) => bigint;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { calculateBorrowPowerUsedBps, calculateLoanToValueBps, calculateTotalEffectiveBorrowableAmount, ppmToBps, ppmToDecimal };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/lending.d.ts
|
|
2
|
+
declare const ppmToBps: (ppmAmount: number) => number;
|
|
3
|
+
declare const ppmToDecimal: (ppmAmount: number) => number;
|
|
4
|
+
declare const calculateLoanToValueBps: ({
|
|
5
|
+
totalBorrowAmountUsd,
|
|
6
|
+
totalCollateralBalanceUsd
|
|
7
|
+
}: {
|
|
8
|
+
totalBorrowAmountUsd: number;
|
|
9
|
+
totalCollateralBalanceUsd: number;
|
|
10
|
+
}) => number;
|
|
11
|
+
declare const calculateBorrowPowerUsedBps: ({
|
|
12
|
+
totalBorrowAmountUsd,
|
|
13
|
+
totalCollateralBalanceUsd,
|
|
14
|
+
thresholdDecimal
|
|
15
|
+
}: {
|
|
16
|
+
totalBorrowAmountUsd: number;
|
|
17
|
+
totalCollateralBalanceUsd: number;
|
|
18
|
+
thresholdDecimal: number;
|
|
19
|
+
}) => number;
|
|
20
|
+
declare const calculateTotalEffectiveBorrowableAmount: ({
|
|
21
|
+
totalAmount,
|
|
22
|
+
totalAvailableAmount,
|
|
23
|
+
utilisationCapBps
|
|
24
|
+
}: {
|
|
25
|
+
totalAmount: bigint;
|
|
26
|
+
totalAvailableAmount: bigint;
|
|
27
|
+
utilisationCapBps?: number | null;
|
|
28
|
+
}) => bigint;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { calculateBorrowPowerUsedBps, calculateLoanToValueBps, calculateTotalEffectiveBorrowableAmount, ppmToBps, ppmToDecimal };
|
package/dist/lending.mjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { bigintMax } from "./number.mjs";
|
|
2
|
+
import BigNumber from "bignumber.js";
|
|
3
|
+
|
|
4
|
+
//#region src/lending.ts
|
|
5
|
+
const ppmToBps = (ppmAmount) => Math.trunc(ppmAmount / 100);
|
|
6
|
+
const ppmToDecimal = (ppmAmount) => ppmAmount / 1e6;
|
|
7
|
+
const calculateLoanToValueBps = ({ totalBorrowAmountUsd, totalCollateralBalanceUsd }) => {
|
|
8
|
+
if (totalCollateralBalanceUsd === 0) return 0;
|
|
9
|
+
return Math.trunc(totalBorrowAmountUsd / totalCollateralBalanceUsd * 1e4);
|
|
10
|
+
};
|
|
11
|
+
const calculateBorrowPowerUsedBps = ({ totalBorrowAmountUsd, totalCollateralBalanceUsd, thresholdDecimal }) => {
|
|
12
|
+
if (totalCollateralBalanceUsd === 0 || thresholdDecimal === 0) return 0;
|
|
13
|
+
return Math.trunc(totalBorrowAmountUsd / (totalCollateralBalanceUsd * thresholdDecimal) * 1e4);
|
|
14
|
+
};
|
|
15
|
+
const calculateTotalEffectiveBorrowableAmount = ({ totalAmount, totalAvailableAmount, utilisationCapBps }) => {
|
|
16
|
+
const totalBorrowedAmount = totalAmount - totalAvailableAmount;
|
|
17
|
+
const totalEffectiveBorrowableAmount = new BigNumber(totalAmount).multipliedBy(utilisationCapBps ?? 1e4).div(1e4).toFixed();
|
|
18
|
+
return bigintMax(BigInt(totalEffectiveBorrowableAmount) - totalBorrowedAmount, 0n);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { calculateBorrowPowerUsedBps, calculateLoanToValueBps, calculateTotalEffectiveBorrowableAmount, ppmToBps, ppmToDecimal };
|
package/dist/number.cjs
CHANGED
|
@@ -2,6 +2,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
|
|
3
3
|
//#region src/number.ts
|
|
4
4
|
const hexEncodeNumber = (num) => `0x${num.toString(16)}`;
|
|
5
|
+
const bigintMin = (...args) => args.reduce((min, current) => current < min ? current : min);
|
|
6
|
+
const bigintMax = (...args) => args.reduce((max, current) => current > max ? current : max);
|
|
5
7
|
|
|
6
8
|
//#endregion
|
|
9
|
+
exports.bigintMax = bigintMax;
|
|
10
|
+
exports.bigintMin = bigintMin;
|
|
7
11
|
exports.hexEncodeNumber = hexEncodeNumber;
|
package/dist/number.d.cts
CHANGED
|
@@ -2,5 +2,7 @@ import { HexString } from "./types.cjs";
|
|
|
2
2
|
|
|
3
3
|
//#region src/number.d.ts
|
|
4
4
|
declare const hexEncodeNumber: (num: number | bigint) => HexString;
|
|
5
|
+
declare const bigintMin: (...args: bigint[]) => bigint;
|
|
6
|
+
declare const bigintMax: (...args: bigint[]) => bigint;
|
|
5
7
|
//#endregion
|
|
6
|
-
export { hexEncodeNumber };
|
|
8
|
+
export { bigintMax, bigintMin, hexEncodeNumber };
|
package/dist/number.d.mts
CHANGED
|
@@ -2,5 +2,7 @@ import { HexString } from "./types.mjs";
|
|
|
2
2
|
|
|
3
3
|
//#region src/number.d.ts
|
|
4
4
|
declare const hexEncodeNumber: (num: number | bigint) => HexString;
|
|
5
|
+
declare const bigintMin: (...args: bigint[]) => bigint;
|
|
6
|
+
declare const bigintMax: (...args: bigint[]) => bigint;
|
|
5
7
|
//#endregion
|
|
6
|
-
export { hexEncodeNumber };
|
|
8
|
+
export { bigintMax, bigintMin, hexEncodeNumber };
|
package/dist/number.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
//#region src/number.ts
|
|
2
2
|
const hexEncodeNumber = (num) => `0x${num.toString(16)}`;
|
|
3
|
+
const bigintMin = (...args) => args.reduce((min, current) => current < min ? current : min);
|
|
4
|
+
const bigintMax = (...args) => args.reduce((max, current) => current > max ? current : max);
|
|
3
5
|
|
|
4
6
|
//#endregion
|
|
5
|
-
export { hexEncodeNumber };
|
|
7
|
+
export { bigintMax, bigintMin, hexEncodeNumber };
|