@gearbox-protocol/sdk 17.0.0-next.1 → 17.0.0-next.2
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/cjs/onchain/validation/bundles/checkCreditOperation.js +2 -1
- package/dist/cjs/onchain/validation/checkSimulation.js +2 -1
- package/dist/cjs/onchain/validation/checks/checkDebtLimits.js +6 -2
- package/dist/esm/onchain/validation/bundles/checkCreditOperation.js +2 -1
- package/dist/esm/onchain/validation/checkSimulation.js +2 -1
- package/dist/esm/onchain/validation/checks/checkDebtLimits.js +6 -2
- package/dist/types/model/errors/operation-errors.d.ts +5 -0
- package/dist/types/onchain/validation/checks/checkDebtLimits.d.ts +4 -0
- package/package.json +1 -1
|
@@ -33,7 +33,8 @@ async function checkCreditOperation(args) {
|
|
|
33
33
|
minDebt: suite.creditFacade.minDebt,
|
|
34
34
|
maxDebt: suite.creditFacade.maxDebt,
|
|
35
35
|
underlying,
|
|
36
|
-
allowZero: !isOpening
|
|
36
|
+
allowZero: !isOpening,
|
|
37
|
+
ceiling: suite.maxBorrowAmount()
|
|
37
38
|
}),
|
|
38
39
|
...require_onchain_validation_bundles_checkDraw.checkDraw(suite, preview, underlying),
|
|
39
40
|
...require_onchain_validation_bundles_checkObtained.checkObtained(suite, preview),
|
|
@@ -40,7 +40,8 @@ function checkSimulation(sdk, input, options = {}) {
|
|
|
40
40
|
minDebt: suite.creditFacade.minDebt,
|
|
41
41
|
maxDebt: suite.creditFacade.maxDebt,
|
|
42
42
|
underlying: require_onchain_validation_helpers_token.toToken(sdk, suite.market.pool.underlying),
|
|
43
|
-
allowZero: true
|
|
43
|
+
allowZero: true,
|
|
44
|
+
ceiling: suite.maxBorrowAmount()
|
|
44
45
|
}),
|
|
45
46
|
...require_onchain_validation_bundles_checkAccountQuotas.checkAccountQuotas(suite, state),
|
|
46
47
|
...require_onchain_validation_bundles_checkHealthFactors.checkHealthFactors(state, options)
|
|
@@ -6,12 +6,16 @@ require("../helpers/index.js");
|
|
|
6
6
|
//#region src/onchain/validation/checks/checkDebtLimits.ts
|
|
7
7
|
/** A debt the facade would revert on. */
|
|
8
8
|
function checkDebtLimits(args) {
|
|
9
|
-
const { debt, minDebt, maxDebt, underlying, allowZero } = args;
|
|
9
|
+
const { debt, minDebt, maxDebt, underlying, allowZero, ceiling } = args;
|
|
10
10
|
if (!(debt > maxDebt || debt < minDebt && !(allowZero && debt === 0n))) return [];
|
|
11
11
|
return [require_model_errors_operation_errors.debtOutOfRange({
|
|
12
12
|
requested: require_onchain_validation_helpers_amount.amountOf(underlying, debt),
|
|
13
13
|
minDebt: require_onchain_validation_helpers_amount.amountOf(underlying, minDebt),
|
|
14
|
-
maxDebt: require_onchain_validation_helpers_amount.amountOf(underlying, maxDebt)
|
|
14
|
+
maxDebt: require_onchain_validation_helpers_amount.amountOf(underlying, maxDebt),
|
|
15
|
+
ceiling: ceiling && {
|
|
16
|
+
amount: require_onchain_validation_helpers_amount.amountOf(underlying, ceiling.value),
|
|
17
|
+
limit: ceiling.limit
|
|
18
|
+
}
|
|
15
19
|
})];
|
|
16
20
|
}
|
|
17
21
|
//#endregion
|
|
@@ -32,7 +32,8 @@ async function checkCreditOperation(args) {
|
|
|
32
32
|
minDebt: suite.creditFacade.minDebt,
|
|
33
33
|
maxDebt: suite.creditFacade.maxDebt,
|
|
34
34
|
underlying,
|
|
35
|
-
allowZero: !isOpening
|
|
35
|
+
allowZero: !isOpening,
|
|
36
|
+
ceiling: suite.maxBorrowAmount()
|
|
36
37
|
}),
|
|
37
38
|
...checkDraw(suite, preview, underlying),
|
|
38
39
|
...checkObtained(suite, preview),
|
|
@@ -39,7 +39,8 @@ function checkSimulation(sdk, input, options = {}) {
|
|
|
39
39
|
minDebt: suite.creditFacade.minDebt,
|
|
40
40
|
maxDebt: suite.creditFacade.maxDebt,
|
|
41
41
|
underlying: toToken(sdk, suite.market.pool.underlying),
|
|
42
|
-
allowZero: true
|
|
42
|
+
allowZero: true,
|
|
43
|
+
ceiling: suite.maxBorrowAmount()
|
|
43
44
|
}),
|
|
44
45
|
...checkAccountQuotas(suite, state),
|
|
45
46
|
...checkHealthFactors(state, options)
|
|
@@ -5,12 +5,16 @@ import "../helpers/index.js";
|
|
|
5
5
|
//#region src/onchain/validation/checks/checkDebtLimits.ts
|
|
6
6
|
/** A debt the facade would revert on. */
|
|
7
7
|
function checkDebtLimits(args) {
|
|
8
|
-
const { debt, minDebt, maxDebt, underlying, allowZero } = args;
|
|
8
|
+
const { debt, minDebt, maxDebt, underlying, allowZero, ceiling } = args;
|
|
9
9
|
if (!(debt > maxDebt || debt < minDebt && !(allowZero && debt === 0n))) return [];
|
|
10
10
|
return [debtOutOfRange({
|
|
11
11
|
requested: amountOf(underlying, debt),
|
|
12
12
|
minDebt: amountOf(underlying, minDebt),
|
|
13
|
-
maxDebt: amountOf(underlying, maxDebt)
|
|
13
|
+
maxDebt: amountOf(underlying, maxDebt),
|
|
14
|
+
ceiling: ceiling && {
|
|
15
|
+
amount: amountOf(underlying, ceiling.value),
|
|
16
|
+
limit: ceiling.limit
|
|
17
|
+
}
|
|
14
18
|
})];
|
|
15
19
|
}
|
|
16
20
|
//#endregion
|
|
@@ -82,6 +82,11 @@ interface DebtOutOfRangeError extends IGearboxError {
|
|
|
82
82
|
requested: TokenAmount;
|
|
83
83
|
minDebt: TokenAmount;
|
|
84
84
|
maxDebt: TokenAmount;
|
|
85
|
+
/** What the market will really lend; absent where the raiser only throws. */
|
|
86
|
+
ceiling?: {
|
|
87
|
+
amount: TokenAmount;
|
|
88
|
+
limit: BorrowLimitCause;
|
|
89
|
+
};
|
|
85
90
|
}
|
|
86
91
|
/** {@inheritDoc DebtOutOfRangeError} */
|
|
87
92
|
declare function debtOutOfRange(args: Omit<DebtOutOfRangeError, "code" | "message">): DebtOutOfRangeError;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Token } from "../../../model/primitives.js";
|
|
2
2
|
import { DebtOutOfRangeError } from "../../../model/errors/operation-errors.js";
|
|
3
3
|
import "../../../model/index.js";
|
|
4
|
+
import { MaxBorrowAmount } from "../../market/credit/types.js";
|
|
5
|
+
import "../../market/index.js";
|
|
4
6
|
//#region src/onchain/validation/checks/checkDebtLimits.d.ts
|
|
5
7
|
interface DebtLimitsArgs {
|
|
6
8
|
debt: bigint;
|
|
@@ -14,6 +16,8 @@ interface DebtLimitsArgs {
|
|
|
14
16
|
* rather than assumed.
|
|
15
17
|
*/
|
|
16
18
|
allowZero: boolean;
|
|
19
|
+
/** From the caller's suite; a caller that raises to throw advises nobody. */
|
|
20
|
+
ceiling?: MaxBorrowAmount;
|
|
17
21
|
}
|
|
18
22
|
/** A debt the facade would revert on. */
|
|
19
23
|
declare function checkDebtLimits(args: DebtLimitsArgs): DebtOutOfRangeError[];
|