@gearbox-protocol/sdk 16.4.0-next.6 → 16.4.0-next.8
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/accounts/CreditAccountsServiceV310.js +0 -1
- package/dist/cjs/onchain/accounts/intents/index.js +6 -3
- package/dist/cjs/onchain/accounts/intents/maxBorrow.js +12 -8
- package/dist/cjs/onchain/validation/bundles/checkMidasAccountGreenlist.js +1 -3
- package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +0 -1
- package/dist/esm/onchain/accounts/intents/index.js +6 -3
- package/dist/esm/onchain/accounts/intents/maxBorrow.js +12 -8
- package/dist/esm/onchain/validation/bundles/checkMidasAccountGreenlist.js +1 -3
- package/dist/types/onchain/accounts/intents/index.d.ts +6 -3
- package/dist/types/onchain/accounts/intents/maxBorrow.d.ts +11 -4
- package/dist/types/onchain/validation/bundles/checkMidasAccountGreenlist.d.ts +1 -2
- package/dist/types/sdk/prepare/types.d.ts +11 -4
- package/package.json +1 -1
|
@@ -213,7 +213,6 @@ var CreditAccountsServiceV310 = class extends require_onchain_base_SDKConstruct.
|
|
|
213
213
|
}),
|
|
214
214
|
...callsAfter ?? []
|
|
215
215
|
];
|
|
216
|
-
calls = await this.#prependMidasReceiveGreenlist(cm.address, calls);
|
|
217
216
|
calls = await this.prependPriceUpdates(cm.address, calls);
|
|
218
217
|
const tx = reopenCreditAccount ? cmSuite.multicallTx(reopenCreditAccount, calls, rwaOptions) : cmSuite.openCreditAccountTx(to, calls, referralCode, rwaOptions);
|
|
219
218
|
tx.value = ethAmount.toString(10);
|
|
@@ -136,21 +136,24 @@ var CreditAccountOperationsService = class extends require_onchain_base_SDKConst
|
|
|
136
136
|
}
|
|
137
137
|
/**
|
|
138
138
|
* Largest loan a given collateral supports at `targetHF`, in the payout
|
|
139
|
-
* token's units — the ceiling a borrow form should offer
|
|
140
|
-
* {@link borrowIntent} will accept at the top of its range.
|
|
139
|
+
* token's units — the ceiling a borrow form should offer.
|
|
141
140
|
*
|
|
142
141
|
* Reads no account, like {@link leverageBand}: the borrow opens one. The
|
|
143
142
|
* collateral is valued the way the transaction will be judged, at safe
|
|
144
143
|
* prices and under the quota the borrow buys, and the answer is then held to
|
|
145
144
|
* what the market will lend.
|
|
146
145
|
*
|
|
146
|
+
* A ceiling, not a verdict: the facade's `minDebt` is a floor and is not
|
|
147
|
+
* applied here, so collateral too small for this market still answers with
|
|
148
|
+
* what it carries and {@link borrowIntent} is the one that refuses the loan.
|
|
149
|
+
*
|
|
147
150
|
* The default is {@link MIN_HF_LIMITED}, the threshold a form holds an
|
|
148
151
|
* account to.
|
|
149
152
|
*
|
|
150
153
|
* @param props - The manager, the SDK holding its market, the collateral put
|
|
151
154
|
* up, the token to be paid in, and optionally the health factor to land at
|
|
152
155
|
* @returns Amount in the payout token's units; `0n` where no loan of this
|
|
153
|
-
* shape can be funded
|
|
156
|
+
* shape can be funded at any size
|
|
154
157
|
*/
|
|
155
158
|
maxBorrow(props) {
|
|
156
159
|
const { targetHF = require_onchain_validation_helpers_health_factor_limits.MIN_HF_LIMITED, ...rest } = props;
|
|
@@ -24,14 +24,21 @@ const require_onchain_accounts_intents_collateral_valuation = require("./collate
|
|
|
24
24
|
* liquidity, the manager's own allowance and the facade's `maxDebt`, whichever
|
|
25
25
|
* binds first.
|
|
26
26
|
*
|
|
27
|
+
* The facade's `minDebt` is deliberately not applied. It is a floor, and a
|
|
28
|
+
* ceiling answered as `0n` because the collateral is too small for this market
|
|
29
|
+
* would tell a form nothing about what it is holding — the number a user needs
|
|
30
|
+
* to see is the one they are short of. Collateral that carries something
|
|
31
|
+
* therefore answers with it, whether or not the market would lend that little;
|
|
32
|
+
* a loan under the floor is refused by `borrow` itself, with `debtOutOfRange`
|
|
33
|
+
* naming both ends.
|
|
34
|
+
*
|
|
27
35
|
* Nothing is fetched or simulated — the account does not exist yet and every
|
|
28
36
|
* input is loaded market state, so a form can call this on each keystroke.
|
|
29
37
|
*
|
|
30
38
|
* @param props - {@link MaxBorrowProps}
|
|
31
|
-
* @returns Amount in the payout token's units; `0n`
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* hold yet
|
|
39
|
+
* @returns Amount in the payout token's units; `0n` where no loan of this
|
|
40
|
+
* shape exists at any size — a collateral that backs nothing at safe prices, a
|
|
41
|
+
* market with nothing left to lend, and a manager the SDK does not hold yet
|
|
35
42
|
**/
|
|
36
43
|
function maxBorrow(props) {
|
|
37
44
|
const { sdk, creditManager, collateralAmount, targetHF, quotaReserve } = props;
|
|
@@ -76,10 +83,7 @@ function maxBorrow(props) {
|
|
|
76
83
|
if (backed <= 0n) return 0n;
|
|
77
84
|
const ceiling = require_onchain_utils_bigint_math.BigIntMath.min(priceOracle.safeConvertFromUSD(underlying, backed / targetHF).value, suite.maxBorrowAmount().amount.value);
|
|
78
85
|
const unwrapsPayout = !!rwaAsset && require_onchain_accounts_intents_utils_common.eq(borrowToken, rwaAsset);
|
|
79
|
-
|
|
80
|
-
const intoUnderlying = (value) => unwrapsPayout ? require_onchain_accounts_intents_utils_common.toTargetDecimals(value, borrowToken, underlying, sdk) : priceOracle.safeConvert(borrowToken, underlying, value).value;
|
|
81
|
-
const amount = require_onchain_accounts_intents_utils_common.eq(borrowToken, underlying) ? ceiling : intoPayout(ceiling);
|
|
82
|
-
return (require_onchain_accounts_intents_utils_common.eq(borrowToken, underlying) ? amount : intoUnderlying(amount)) < suite.creditFacade.minDebt ? 0n : amount;
|
|
86
|
+
return require_onchain_accounts_intents_utils_common.eq(borrowToken, underlying) ? ceiling : unwrapsPayout ? require_onchain_accounts_intents_utils_common.toTargetDecimals(ceiling, underlying, borrowToken, sdk) : priceOracle.safeConvert(underlying, borrowToken, ceiling).value;
|
|
83
87
|
}
|
|
84
88
|
//#endregion
|
|
85
89
|
exports.maxBorrow = maxBorrow;
|
|
@@ -7,13 +7,11 @@ require("../helpers/index.js");
|
|
|
7
7
|
//#region src/onchain/validation/bundles/checkMidasAccountGreenlist.ts
|
|
8
8
|
/**
|
|
9
9
|
* Whether the credit account already holds the Midas greenlisted role
|
|
10
|
-
* this permissioned mToken requires of its holder
|
|
11
|
-
* grants it via `receiveGreenlist()`.
|
|
10
|
+
* this permissioned mToken requires of its holder.
|
|
12
11
|
*/
|
|
13
12
|
async function checkMidasAccountGreenlist(input) {
|
|
14
13
|
const { sdk, preview, nft, tokens } = input;
|
|
15
14
|
if (nft.protocol !== "midas") return [];
|
|
16
|
-
if (preview.midasGreenlistsAccount) return [];
|
|
17
15
|
if (tokens.length === 0) return [];
|
|
18
16
|
const account = preview.creditAccount;
|
|
19
17
|
if (!account) return tokens.map((token) => require_model_errors_operation_errors.accountNotMidasGreenlisted({
|
|
@@ -212,7 +212,6 @@ var CreditAccountsServiceV310 = class extends SDKConstruct {
|
|
|
212
212
|
}),
|
|
213
213
|
...callsAfter ?? []
|
|
214
214
|
];
|
|
215
|
-
calls = await this.#prependMidasReceiveGreenlist(cm.address, calls);
|
|
216
215
|
calls = await this.prependPriceUpdates(cm.address, calls);
|
|
217
216
|
const tx = reopenCreditAccount ? cmSuite.multicallTx(reopenCreditAccount, calls, rwaOptions) : cmSuite.openCreditAccountTx(to, calls, referralCode, rwaOptions);
|
|
218
217
|
tx.value = ethAmount.toString(10);
|
|
@@ -135,21 +135,24 @@ var CreditAccountOperationsService = class extends SDKConstruct {
|
|
|
135
135
|
}
|
|
136
136
|
/**
|
|
137
137
|
* Largest loan a given collateral supports at `targetHF`, in the payout
|
|
138
|
-
* token's units — the ceiling a borrow form should offer
|
|
139
|
-
* {@link borrowIntent} will accept at the top of its range.
|
|
138
|
+
* token's units — the ceiling a borrow form should offer.
|
|
140
139
|
*
|
|
141
140
|
* Reads no account, like {@link leverageBand}: the borrow opens one. The
|
|
142
141
|
* collateral is valued the way the transaction will be judged, at safe
|
|
143
142
|
* prices and under the quota the borrow buys, and the answer is then held to
|
|
144
143
|
* what the market will lend.
|
|
145
144
|
*
|
|
145
|
+
* A ceiling, not a verdict: the facade's `minDebt` is a floor and is not
|
|
146
|
+
* applied here, so collateral too small for this market still answers with
|
|
147
|
+
* what it carries and {@link borrowIntent} is the one that refuses the loan.
|
|
148
|
+
*
|
|
146
149
|
* The default is {@link MIN_HF_LIMITED}, the threshold a form holds an
|
|
147
150
|
* account to.
|
|
148
151
|
*
|
|
149
152
|
* @param props - The manager, the SDK holding its market, the collateral put
|
|
150
153
|
* up, the token to be paid in, and optionally the health factor to land at
|
|
151
154
|
* @returns Amount in the payout token's units; `0n` where no loan of this
|
|
152
|
-
* shape can be funded
|
|
155
|
+
* shape can be funded at any size
|
|
153
156
|
*/
|
|
154
157
|
maxBorrow(props) {
|
|
155
158
|
const { targetHF = MIN_HF_LIMITED, ...rest } = props;
|
|
@@ -23,14 +23,21 @@ import { collateralValuation } from "./collateral-valuation.js";
|
|
|
23
23
|
* liquidity, the manager's own allowance and the facade's `maxDebt`, whichever
|
|
24
24
|
* binds first.
|
|
25
25
|
*
|
|
26
|
+
* The facade's `minDebt` is deliberately not applied. It is a floor, and a
|
|
27
|
+
* ceiling answered as `0n` because the collateral is too small for this market
|
|
28
|
+
* would tell a form nothing about what it is holding — the number a user needs
|
|
29
|
+
* to see is the one they are short of. Collateral that carries something
|
|
30
|
+
* therefore answers with it, whether or not the market would lend that little;
|
|
31
|
+
* a loan under the floor is refused by `borrow` itself, with `debtOutOfRange`
|
|
32
|
+
* naming both ends.
|
|
33
|
+
*
|
|
26
34
|
* Nothing is fetched or simulated — the account does not exist yet and every
|
|
27
35
|
* input is loaded market state, so a form can call this on each keystroke.
|
|
28
36
|
*
|
|
29
37
|
* @param props - {@link MaxBorrowProps}
|
|
30
|
-
* @returns Amount in the payout token's units; `0n`
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* hold yet
|
|
38
|
+
* @returns Amount in the payout token's units; `0n` where no loan of this
|
|
39
|
+
* shape exists at any size — a collateral that backs nothing at safe prices, a
|
|
40
|
+
* market with nothing left to lend, and a manager the SDK does not hold yet
|
|
34
41
|
**/
|
|
35
42
|
function maxBorrow(props) {
|
|
36
43
|
const { sdk, creditManager, collateralAmount, targetHF, quotaReserve } = props;
|
|
@@ -74,10 +81,7 @@ function maxBorrow(props) {
|
|
|
74
81
|
if (backed <= 0n) return 0n;
|
|
75
82
|
const ceiling = BigIntMath.min(priceOracle.safeConvertFromUSD(underlying, backed / targetHF).value, suite.maxBorrowAmount().amount.value);
|
|
76
83
|
const unwrapsPayout = !!rwaAsset && eq(borrowToken, rwaAsset);
|
|
77
|
-
|
|
78
|
-
const intoUnderlying = (value) => unwrapsPayout ? toTargetDecimals(value, borrowToken, underlying, sdk) : priceOracle.safeConvert(borrowToken, underlying, value).value;
|
|
79
|
-
const amount = eq(borrowToken, underlying) ? ceiling : intoPayout(ceiling);
|
|
80
|
-
return (eq(borrowToken, underlying) ? amount : intoUnderlying(amount)) < suite.creditFacade.minDebt ? 0n : amount;
|
|
84
|
+
return eq(borrowToken, underlying) ? ceiling : unwrapsPayout ? toTargetDecimals(ceiling, underlying, borrowToken, sdk) : priceOracle.safeConvert(underlying, borrowToken, ceiling).value;
|
|
81
85
|
}
|
|
82
86
|
//#endregion
|
|
83
87
|
export { maxBorrow };
|
|
@@ -6,13 +6,11 @@ import "../helpers/index.js";
|
|
|
6
6
|
//#region src/onchain/validation/bundles/checkMidasAccountGreenlist.ts
|
|
7
7
|
/**
|
|
8
8
|
* Whether the credit account already holds the Midas greenlisted role
|
|
9
|
-
* this permissioned mToken requires of its holder
|
|
10
|
-
* grants it via `receiveGreenlist()`.
|
|
9
|
+
* this permissioned mToken requires of its holder.
|
|
11
10
|
*/
|
|
12
11
|
async function checkMidasAccountGreenlist(input) {
|
|
13
12
|
const { sdk, preview, nft, tokens } = input;
|
|
14
13
|
if (nft.protocol !== "midas") return [];
|
|
15
|
-
if (preview.midasGreenlistsAccount) return [];
|
|
16
14
|
if (tokens.length === 0) return [];
|
|
17
15
|
const account = preview.creditAccount;
|
|
18
16
|
if (!account) return tokens.map((token) => accountNotMidasGreenlisted({
|
|
@@ -139,21 +139,24 @@ declare class CreditAccountOperationsService extends SDKConstruct {
|
|
|
139
139
|
}): bigint;
|
|
140
140
|
/**
|
|
141
141
|
* Largest loan a given collateral supports at `targetHF`, in the payout
|
|
142
|
-
* token's units — the ceiling a borrow form should offer
|
|
143
|
-
* {@link borrowIntent} will accept at the top of its range.
|
|
142
|
+
* token's units — the ceiling a borrow form should offer.
|
|
144
143
|
*
|
|
145
144
|
* Reads no account, like {@link leverageBand}: the borrow opens one. The
|
|
146
145
|
* collateral is valued the way the transaction will be judged, at safe
|
|
147
146
|
* prices and under the quota the borrow buys, and the answer is then held to
|
|
148
147
|
* what the market will lend.
|
|
149
148
|
*
|
|
149
|
+
* A ceiling, not a verdict: the facade's `minDebt` is a floor and is not
|
|
150
|
+
* applied here, so collateral too small for this market still answers with
|
|
151
|
+
* what it carries and {@link borrowIntent} is the one that refuses the loan.
|
|
152
|
+
*
|
|
150
153
|
* The default is {@link MIN_HF_LIMITED}, the threshold a form holds an
|
|
151
154
|
* account to.
|
|
152
155
|
*
|
|
153
156
|
* @param props - The manager, the SDK holding its market, the collateral put
|
|
154
157
|
* up, the token to be paid in, and optionally the health factor to land at
|
|
155
158
|
* @returns Amount in the payout token's units; `0n` where no loan of this
|
|
156
|
-
* shape can be funded
|
|
159
|
+
* shape can be funded at any size
|
|
157
160
|
*/
|
|
158
161
|
maxBorrow(props: Omit<MaxBorrowProps, "targetHF"> & {
|
|
159
162
|
targetHF?: bigint;
|
|
@@ -33,14 +33,21 @@ interface MaxBorrowProps {
|
|
|
33
33
|
* liquidity, the manager's own allowance and the facade's `maxDebt`, whichever
|
|
34
34
|
* binds first.
|
|
35
35
|
*
|
|
36
|
+
* The facade's `minDebt` is deliberately not applied. It is a floor, and a
|
|
37
|
+
* ceiling answered as `0n` because the collateral is too small for this market
|
|
38
|
+
* would tell a form nothing about what it is holding — the number a user needs
|
|
39
|
+
* to see is the one they are short of. Collateral that carries something
|
|
40
|
+
* therefore answers with it, whether or not the market would lend that little;
|
|
41
|
+
* a loan under the floor is refused by `borrow` itself, with `debtOutOfRange`
|
|
42
|
+
* naming both ends.
|
|
43
|
+
*
|
|
36
44
|
* Nothing is fetched or simulated — the account does not exist yet and every
|
|
37
45
|
* input is loaded market state, so a form can call this on each keystroke.
|
|
38
46
|
*
|
|
39
47
|
* @param props - {@link MaxBorrowProps}
|
|
40
|
-
* @returns Amount in the payout token's units; `0n`
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* hold yet
|
|
48
|
+
* @returns Amount in the payout token's units; `0n` where no loan of this
|
|
49
|
+
* shape exists at any size — a collateral that backs nothing at safe prices, a
|
|
50
|
+
* market with nothing left to lend, and a manager the SDK does not hold yet
|
|
44
51
|
**/
|
|
45
52
|
declare function maxBorrow(props: MaxBorrowProps): bigint;
|
|
46
53
|
//#endregion
|
|
@@ -15,8 +15,7 @@ interface CheckMidasAccountGreenlistInput {
|
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
17
|
* Whether the credit account already holds the Midas greenlisted role
|
|
18
|
-
* this permissioned mToken requires of its holder
|
|
19
|
-
* grants it via `receiveGreenlist()`.
|
|
18
|
+
* this permissioned mToken requires of its holder.
|
|
20
19
|
*/
|
|
21
20
|
declare function checkMidasAccountGreenlist(input: CheckMidasAccountGreenlistInput): Promise<(AccountNotMidasGreenlistedError | UnexpectedFailureError)[]>;
|
|
22
21
|
//#endregion
|
|
@@ -784,10 +784,17 @@ interface IOpportunitiesPrepare {
|
|
|
784
784
|
* account does not exist yet, so there is nothing to read and a form can ask
|
|
785
785
|
* on every keystroke.
|
|
786
786
|
*
|
|
787
|
-
*
|
|
788
|
-
*
|
|
789
|
-
*
|
|
790
|
-
*
|
|
787
|
+
* It is a ceiling and not a verdict: the facade's `minDebt` is a floor, and
|
|
788
|
+
* holding the answer to it would tell a form `0` for collateral that does
|
|
789
|
+
* carry a loan, only a smaller one than this market lends. So a Max offered
|
|
790
|
+
* from here can still be refused by {@link borrow} with `debtOutOfRange`,
|
|
791
|
+
* which names the floor the amount fell short of.
|
|
792
|
+
*
|
|
793
|
+
* `0n` where this market funds no loan of this shape at any size — a
|
|
794
|
+
* collateral worth nothing at safe prices, a payout token equal to the
|
|
795
|
+
* collateral, a market with nothing left to lend, or a manager the SDK does
|
|
796
|
+
* not hold. Not the same as "any amount works", and a caller must not offer
|
|
797
|
+
* a Max for it.
|
|
791
798
|
**/
|
|
792
799
|
maxBorrow(strategy: StrategyInput, params: MaxBorrowParams): bigint;
|
|
793
800
|
/**
|