@gearbox-protocol/sdk 17.13.0-next.8 → 18.0.0-next.1
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/dev/index.js +2 -0
- package/dist/cjs/dev/lowerHealthFactor.js +32 -0
- package/dist/cjs/model/analytics.schema.js +10 -2
- package/dist/cjs/model/index.js +1 -0
- package/dist/cjs/onchain/accounts/liquidations/LiquidationsService.js +42 -25
- package/dist/esm/dev/AccountOpener.js +1 -1
- package/dist/esm/dev/index.js +2 -1
- package/dist/esm/dev/lowerHealthFactor.js +31 -0
- package/dist/esm/dev/withdrawalUtils.js +1 -1
- package/dist/esm/history/trace/extractTransfers.js +1 -1
- package/dist/esm/model/analytics.schema.js +12 -5
- package/dist/esm/model/index.js +2 -2
- package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +2 -2
- package/dist/esm/onchain/accounts/liquidations/LiquidationsService.js +43 -26
- package/dist/esm/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
- package/dist/esm/onchain/base/TokensMeta.js +3 -3
- package/dist/esm/onchain/core/createAddressProvider.js +1 -1
- package/dist/esm/onchain/market/adapters/contracts/AccountMigratorAdapterContract.js +1 -1
- package/dist/esm/onchain/market/adapters/contracts/ERC4626AdapterContract.js +1 -1
- package/dist/esm/onchain/market/credit/CreditFacadeV310BaseContract.js +1 -1
- package/dist/esm/onchain/market/pool/PoolV310Contract.js +1 -1
- package/dist/esm/onchain/market/rwa/createDegenNFT.js +1 -1
- package/dist/esm/onchain/market/zapper/IETHZapperContract.js +1 -1
- package/dist/esm/onchain/market/zapper/ZapperContract.js +1 -1
- package/dist/esm/onchain/preview/preview/previewPoolPositionOperation.js +2 -2
- package/dist/esm/onchain/utils/viem/simulateWithPriceUpdates.js +1 -1
- package/dist/types/dev/index.d.ts +2 -1
- package/dist/types/dev/lowerHealthFactor.d.ts +34 -0
- package/dist/types/model/analytics.d.ts +25 -5
- package/dist/types/model/analytics.schema.d.ts +126 -16
- package/dist/types/model/index.d.ts +3 -3
- package/dist/types/model/liquidations.d.ts +3 -4
- package/dist/types/onchain/accounts/liquidations/LiquidationsService.d.ts +9 -10
- package/dist/types/onchain/accounts/liquidations/types.d.ts +10 -33
- package/package.json +1 -1
package/dist/cjs/dev/index.js
CHANGED
|
@@ -18,6 +18,7 @@ const require_dev_midasUtils = require("./midasUtils.js");
|
|
|
18
18
|
const require_dev_kycUtils = require("./kycUtils.js");
|
|
19
19
|
const require_dev_logSplitterTransport = require("./logSplitterTransport.js");
|
|
20
20
|
const require_dev_ltUtils = require("./ltUtils.js");
|
|
21
|
+
const require_dev_lowerHealthFactor = require("./lowerHealthFactor.js");
|
|
21
22
|
const require_dev_migrateFaucet = require("./migrateFaucet.js");
|
|
22
23
|
const require_dev_providers = require("./providers.js");
|
|
23
24
|
const require_dev_replaceStorage = require("./replaceStorage.js");
|
|
@@ -75,6 +76,7 @@ exports.isRangeError = require_dev_logSplitterTransport.isRangeError;
|
|
|
75
76
|
exports.isRateLimitError = require_dev_isRateLimitError.isRateLimitError;
|
|
76
77
|
exports.isTransientError = require_dev_isTransientError.isTransientError;
|
|
77
78
|
exports.logSplitterTransport = require_dev_logSplitterTransport.logSplitterTransport;
|
|
79
|
+
exports.lowerHealthFactor = require_dev_lowerHealthFactor.lowerHealthFactor;
|
|
78
80
|
exports.makePendingWithdrawalsClaimable = require_dev_withdrawalUtils.makePendingWithdrawalsClaimable;
|
|
79
81
|
exports.migrateFaucet = require_dev_migrateFaucet.migrateFaucet;
|
|
80
82
|
exports.providerConfigSchema = require_dev_RevolverTransport.providerConfigSchema;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_onchain_utils_mappers = require("../onchain/utils/mappers.js");
|
|
3
|
+
require("../onchain/index.js");
|
|
4
|
+
const require_dev_calcLiquidatableLTs = require("./calcLiquidatableLTs.js");
|
|
5
|
+
const require_dev_ltUtils = require("./ltUtils.js");
|
|
6
|
+
//#region src/dev/lowerHealthFactor.ts
|
|
7
|
+
/**
|
|
8
|
+
* Lowers liquidation thresholds of credit account's credit manager on anvil, so that account's health factor drops to `hf`.
|
|
9
|
+
* Does not update LTs held in sdk's cached credit manager state.
|
|
10
|
+
*/
|
|
11
|
+
async function lowerHealthFactor(anvil, sdk, ca, options = {}) {
|
|
12
|
+
const { hf, logger } = options;
|
|
13
|
+
if (ca.debt === 0n) throw new Error("warning: zero-debt account");
|
|
14
|
+
const cm = sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
15
|
+
const newLTs = await require_dev_calcLiquidatableLTs.calcLiquidatableLTs(sdk, ca, hf, logger);
|
|
16
|
+
const oldLTs = {};
|
|
17
|
+
for (const t of require_onchain_utils_mappers.TypedObjectUtils.keys(newLTs)) oldLTs[t] = cm.creditManager.liquidationThresholds.mustGet(t);
|
|
18
|
+
await require_dev_ltUtils.setLTs(anvil, cm.state, newLTs, logger);
|
|
19
|
+
const account = await sdk.accounts.getCreditAccountData(ca.creditAccount);
|
|
20
|
+
if (!account) throw new Error(`cannot find credit account ${ca.creditAccount}`);
|
|
21
|
+
logger?.debug({
|
|
22
|
+
hfNew: account.healthFactor.toString(),
|
|
23
|
+
hfOld: ca.healthFactor.toString()
|
|
24
|
+
});
|
|
25
|
+
return {
|
|
26
|
+
account,
|
|
27
|
+
oldLTs,
|
|
28
|
+
newLTs
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
exports.lowerHealthFactor = lowerHealthFactor;
|
|
@@ -152,14 +152,21 @@ const analyticsPositionPageSchema = zod_v4.z.object({
|
|
|
152
152
|
const analyticsContractOptionSchema = zod_v4.z.object({
|
|
153
153
|
chainId: require_model_primitives_schema.chainIdSchema,
|
|
154
154
|
address: require_onchain_utils_zod.ZodAddress(),
|
|
155
|
-
name: zod_v4.z.string()
|
|
155
|
+
name: zod_v4.z.string(),
|
|
156
|
+
underlyingToken: require_model_primitives_schema.underlyingTokenSchema,
|
|
157
|
+
curator: require_model_curators_schema.curatorSchema
|
|
158
|
+
});
|
|
159
|
+
/** {@link AnalyticsCuratorOption} */
|
|
160
|
+
const analyticsCuratorOptionSchema = zod_v4.z.object({
|
|
161
|
+
name: require_model_curators_schema.curatorNameSchema,
|
|
162
|
+
url: zod_v4.z.string().nullable()
|
|
156
163
|
});
|
|
157
164
|
/** {@link AnalyticsPositionFilterOptions} */
|
|
158
165
|
const analyticsPositionFilterOptionsSchema = zod_v4.z.object({
|
|
159
166
|
pools: zod_v4.z.array(analyticsContractOptionSchema),
|
|
160
167
|
creditManagers: zod_v4.z.array(analyticsContractOptionSchema),
|
|
161
168
|
assets: zod_v4.z.array(require_model_primitives_schema.tokenSchema),
|
|
162
|
-
curators: zod_v4.z.array(
|
|
169
|
+
curators: zod_v4.z.array(analyticsCuratorOptionSchema)
|
|
163
170
|
});
|
|
164
171
|
/** Chain scope of a filter-options read, shared by the client and backend. */
|
|
165
172
|
const analyticsPositionFilterOptionsQuerySchema = zod_v4.z.codec(analyticsPositionListQueryParamsSchema.pick({ chainIds: true }), analyticsPositionListOptionsSchema.pick({ chainIds: true }), {
|
|
@@ -213,6 +220,7 @@ exports.analyticsChartQueryParamsSchema = analyticsChartQueryParamsSchema;
|
|
|
213
220
|
exports.analyticsChartQuerySchema = analyticsChartQuerySchema;
|
|
214
221
|
exports.analyticsContractOptionSchema = analyticsContractOptionSchema;
|
|
215
222
|
exports.analyticsContractRefSchema = analyticsContractRefSchema;
|
|
223
|
+
exports.analyticsCuratorOptionSchema = analyticsCuratorOptionSchema;
|
|
216
224
|
exports.analyticsPositionFilterOptionsQuerySchema = analyticsPositionFilterOptionsQuerySchema;
|
|
217
225
|
exports.analyticsPositionFilterOptionsSchema = analyticsPositionFilterOptionsSchema;
|
|
218
226
|
exports.analyticsPositionListOptionsSchema = analyticsPositionListOptionsSchema;
|
package/dist/cjs/model/index.js
CHANGED
|
@@ -58,6 +58,7 @@ exports.analyticsChartQueryParamsSchema = require_model_analytics_schema.analyti
|
|
|
58
58
|
exports.analyticsChartQuerySchema = require_model_analytics_schema.analyticsChartQuerySchema;
|
|
59
59
|
exports.analyticsContractOptionSchema = require_model_analytics_schema.analyticsContractOptionSchema;
|
|
60
60
|
exports.analyticsContractRefSchema = require_model_analytics_schema.analyticsContractRefSchema;
|
|
61
|
+
exports.analyticsCuratorOptionSchema = require_model_analytics_schema.analyticsCuratorOptionSchema;
|
|
61
62
|
exports.analyticsPositionFilterOptionsQuerySchema = require_model_analytics_schema.analyticsPositionFilterOptionsQuerySchema;
|
|
62
63
|
exports.analyticsPositionFilterOptionsSchema = require_model_analytics_schema.analyticsPositionFilterOptionsSchema;
|
|
63
64
|
exports.analyticsPositionListOptionsSchema = require_model_analytics_schema.analyticsPositionListOptionsSchema;
|
|
@@ -23,6 +23,7 @@ require("../../market/index.js");
|
|
|
23
23
|
const require_onchain_accounts_liquidations_constants = require("./constants.js");
|
|
24
24
|
const require_onchain_accounts_liquidations_partialLiquidation = require("./partialLiquidation.js");
|
|
25
25
|
const require_onchain_accounts_liquidations_skipLiquidatableAccount = require("./skipLiquidatableAccount.js");
|
|
26
|
+
let viem = require("viem");
|
|
26
27
|
//#region src/onchain/accounts/liquidations/LiquidationsService.ts
|
|
27
28
|
/**
|
|
28
29
|
* Service for discovering liquidatable credit accounts and previewing manual
|
|
@@ -121,14 +122,15 @@ var LiquidationsService = class extends require_onchain_base_SDKConstruct.SDKCon
|
|
|
121
122
|
* full one: what the liquidator pays, what it receives and what it must
|
|
122
123
|
* approve, plus {@link LiquidationDetails.isPartiallyLiquidatable}.
|
|
123
124
|
*
|
|
124
|
-
* A local estimate
|
|
125
|
-
*
|
|
125
|
+
* A local estimate, not onchain read: no price feed updates are applied, so
|
|
126
|
+
* `ignoreReservePrices` has no effect here.
|
|
127
|
+
* Parameters left out of `props` are derived from current state.
|
|
126
128
|
*
|
|
127
|
-
* @throws For
|
|
128
|
-
* `tokenOut` can be picked.
|
|
129
|
+
* @throws For markets with a wrapped RWA underlying (Securitize), for a
|
|
130
|
+
* `tokenOut` that cannot be seized, and when no `tokenOut` can be picked.
|
|
129
131
|
**/
|
|
130
132
|
async getPartialLiquidationDetails(props) {
|
|
131
|
-
const { creditAccount, blockNumber } = props;
|
|
133
|
+
const { creditAccount, liquidator, blockNumber } = props;
|
|
132
134
|
const ca = await this.#getCreditAccountData(creditAccount, blockNumber);
|
|
133
135
|
const suite = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
134
136
|
const { priceOracle } = suite.market;
|
|
@@ -137,6 +139,13 @@ var LiquidationsService = class extends require_onchain_base_SDKConstruct.SDKCon
|
|
|
137
139
|
const { liquidationDiscount } = suite.liquidationFees();
|
|
138
140
|
const seizedValue = repaidAmount * require_onchain_constants_math.PERCENTAGE_FACTOR / BigInt(liquidationDiscount);
|
|
139
141
|
const seizedAmount = priceOracle.convert(underlying, tokenOut, repaidAmount) * require_onchain_constants_math.PERCENTAGE_FACTOR / BigInt(liquidationDiscount);
|
|
142
|
+
const nft = await suite.degenNFT();
|
|
143
|
+
let isLiquidatorEligible = !nft;
|
|
144
|
+
if (nft && liquidator) {
|
|
145
|
+
const requirements = await nft.getOpenAccountRequirements(liquidator, { tokenOutAddress: tokenOut });
|
|
146
|
+
isLiquidatorEligible = nft.isRegistered(requirements);
|
|
147
|
+
}
|
|
148
|
+
const [kycToken] = nft && !isLiquidatorEligible ? await nft.getTokens() : [];
|
|
140
149
|
return {
|
|
141
150
|
...this.#buildAccount(ca, suite),
|
|
142
151
|
repaymentAmount: priceOracle.toTokenAmount(underlying, repaidAmount),
|
|
@@ -147,7 +156,9 @@ var LiquidationsService = class extends require_onchain_base_SDKConstruct.SDKCon
|
|
|
147
156
|
...priceOracle.toTokenAmount(tokenOut, seizedAmount),
|
|
148
157
|
token: this.sdk.tokensMeta.mustGetToken(this.sdk.tokensMeta.depositedToken(tokenOut))
|
|
149
158
|
}],
|
|
150
|
-
isLiquidatorEligible
|
|
159
|
+
isLiquidatorEligible,
|
|
160
|
+
kycProtocol: isLiquidatorEligible ? void 0 : nft?.protocol,
|
|
161
|
+
kycToken: kycToken ? this.sdk.tokensMeta.getToken(kycToken) : void 0,
|
|
151
162
|
isCreditAccountFrozen: false,
|
|
152
163
|
approve: repaidAmount === 0n ? void 0 : {
|
|
153
164
|
spender: suite.creditManager.address,
|
|
@@ -163,17 +174,18 @@ var LiquidationsService = class extends require_onchain_base_SDKConstruct.SDKCon
|
|
|
163
174
|
* discounted collateral sent to the liquidator. Parameters left out of
|
|
164
175
|
* `props` are derived from current state.
|
|
165
176
|
*
|
|
166
|
-
* @throws For
|
|
167
|
-
* `tokenOut`
|
|
168
|
-
* liquidated, see
|
|
177
|
+
* @throws For markets with a wrapped RWA underlying (Securitize), for a
|
|
178
|
+
* `tokenOut` that cannot be seized, when no `tokenOut` can be picked, and
|
|
179
|
+
* when the account cannot be partially liquidated, see
|
|
180
|
+
* {@link LiquidationDetails.isPartiallyLiquidatable}.
|
|
169
181
|
**/
|
|
170
182
|
async buildPartialLiquidationTx(props) {
|
|
171
|
-
const { creditAccount, liquidator, blockNumber } = props;
|
|
183
|
+
const { creditAccount, liquidator, ignoreReservePrices, blockNumber } = props;
|
|
172
184
|
const ca = await this.#getCreditAccountData(creditAccount, blockNumber);
|
|
173
185
|
const suite = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
174
186
|
const params = this.#getPartialLiquidationParams(ca, suite, props);
|
|
175
187
|
if (!params.isPartiallyLiquidatable) throw new Error(`credit account ${this.labelAddress(creditAccount)} cannot be partially liquidated`);
|
|
176
|
-
const updates = await this.sdk.accounts.getOnDemandPriceUpdates(ca,
|
|
188
|
+
const updates = await this.sdk.accounts.getOnDemandPriceUpdates(ca, ignoreReservePrices);
|
|
177
189
|
const tx = suite.creditFacade.partiallyLiquidateCreditAccount(ca.creditAccount, params.tokenOut, params.repaidAmount, params.minSeizedAmount, liquidator, updates);
|
|
178
190
|
this.logger?.debug(`built tx to partially liquidate credit account ${this.labelAddress(creditAccount)} to ${this.labelAddress(liquidator)}`);
|
|
179
191
|
return {
|
|
@@ -185,9 +197,6 @@ var LiquidationsService = class extends require_onchain_base_SDKConstruct.SDKCon
|
|
|
185
197
|
* Optimal partial liquidation of a credit account: the collateral to seize
|
|
186
198
|
* and the amounts that bring its health factor close to `optimalHF`.
|
|
187
199
|
*
|
|
188
|
-
* Prices come from the last synced oracle state and `ca`, not from fresh
|
|
189
|
-
* price updates. Withdrawal phantom tokens are never seized.
|
|
190
|
-
*
|
|
191
200
|
* @param ca - Credit account to partially liquidate.
|
|
192
201
|
* @param optimalHF - Health factor to aim for, in basis points. Defaults to
|
|
193
202
|
* {@link CreditSuite.optimalHFForPartialLiquidation}.
|
|
@@ -196,11 +205,12 @@ var LiquidationsService = class extends require_onchain_base_SDKConstruct.SDKCon
|
|
|
196
205
|
* @throws If no `tokenOut` can be picked.
|
|
197
206
|
**/
|
|
198
207
|
getOptimalPartialLiquidation(ca, optimalHF, liquidationThresholds) {
|
|
208
|
+
const suite = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
199
209
|
return require_onchain_accounts_liquidations_partialLiquidation.optimalPartialLiquidation({
|
|
200
|
-
suite
|
|
210
|
+
suite,
|
|
201
211
|
account: ca,
|
|
202
212
|
optimalHF,
|
|
203
|
-
exclude: (token) => this.#
|
|
213
|
+
exclude: (token) => this.#isUnseizable(suite, token),
|
|
204
214
|
liquidationThresholds
|
|
205
215
|
});
|
|
206
216
|
}
|
|
@@ -336,24 +346,32 @@ var LiquidationsService = class extends require_onchain_base_SDKConstruct.SDKCon
|
|
|
336
346
|
/**
|
|
337
347
|
* Everything a partial liquidation of a credit account needs, with any
|
|
338
348
|
* parameter the caller pinned down taken as given and the rest derived from
|
|
339
|
-
* current state. A derived `tokenOut` is never a
|
|
349
|
+
* current state. A derived `tokenOut` is never a token that cannot be seized.
|
|
340
350
|
*
|
|
341
|
-
* @throws For
|
|
342
|
-
* the
|
|
343
|
-
* which does not redeem instantly,
|
|
344
|
-
*
|
|
351
|
+
* @throws For markets with a wrapped RWA underlying (Securitize), whose
|
|
352
|
+
* repayment the liquidator cannot fund, for a `tokenOut` that cannot be
|
|
353
|
+
* seized (a withdrawal phantom token, which does not redeem instantly, or a
|
|
354
|
+
* phantom token that unwraps to the underlying), if a derived `tokenOut`
|
|
355
|
+
* cannot be picked, and if the seized token is not a collateral token of the
|
|
356
|
+
* credit manager.
|
|
345
357
|
**/
|
|
346
358
|
#getPartialLiquidationParams(ca, suite, overrides) {
|
|
347
359
|
const label = this.labelAddress(ca.creditAccount);
|
|
348
|
-
if (suite.
|
|
349
|
-
if (overrides.tokenOut && this.#
|
|
360
|
+
if (this.sdk.tokensMeta.isRWAUnderlying(this.sdk.tokensMeta.mustGet(suite.underlying))) throw new Error(`cannot partially liquidate ${label}: markets with a wrapped RWA underlying are not supported`);
|
|
361
|
+
if (overrides.tokenOut && this.#isUnseizable(suite, overrides.tokenOut)) throw new Error(`cannot partially liquidate ${label}: ${this.labelAddress(overrides.tokenOut)} cannot be seized`);
|
|
350
362
|
return require_onchain_accounts_liquidations_partialLiquidation.partialLiquidationParams({
|
|
351
363
|
suite,
|
|
352
364
|
account: ca,
|
|
353
365
|
overrides,
|
|
354
|
-
exclude: (token) => this.#
|
|
366
|
+
exclude: (token) => this.#isUnseizable(suite, token)
|
|
355
367
|
});
|
|
356
368
|
}
|
|
369
|
+
/**
|
|
370
|
+
* The facade reverts when a phantom tokenOut unwraps to the underlying
|
|
371
|
+
**/
|
|
372
|
+
#isUnseizable(suite, token) {
|
|
373
|
+
return this.#isWithdrawalPhantom(token) || (0, viem.isAddressEqual)(this.sdk.tokensMeta.depositedToken(token), suite.underlying);
|
|
374
|
+
}
|
|
357
375
|
async #getCreditAccountData(creditAccount, blockNumber) {
|
|
358
376
|
const ca = await this.sdk.accounts.getCreditAccountData(creditAccount, blockNumber);
|
|
359
377
|
if (!ca) throw new Error(`credit account ${creditAccount} not found`);
|
|
@@ -426,7 +444,6 @@ var LiquidationsService = class extends require_onchain_base_SDKConstruct.SDKCon
|
|
|
426
444
|
};
|
|
427
445
|
}
|
|
428
446
|
#isPartiallyLiquidatable(ca, suite) {
|
|
429
|
-
if (suite.market.rwa) return false;
|
|
430
447
|
try {
|
|
431
448
|
return this.#getPartialLiquidationParams(ca, suite, {}).isPartiallyLiquidatable;
|
|
432
449
|
} catch (e) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ierc20Abi } from "../abi/iERC20.js";
|
|
2
1
|
import { iCreditFacadeV310Abi } from "../abi/310/generated.js";
|
|
2
|
+
import { ierc20Abi } from "../abi/iERC20.js";
|
|
3
3
|
import { AddressMap } from "../onchain/utils/AddressMap.js";
|
|
4
4
|
import { AddressSet } from "../onchain/utils/AddressSet.js";
|
|
5
5
|
import { AssetsMap } from "../onchain/utils/AssetsMap.js";
|
package/dist/esm/dev/index.js
CHANGED
|
@@ -17,6 +17,7 @@ import { discoverMidasCreditSuites, discoverMidasGateways, discoverMidasMTokens,
|
|
|
17
17
|
import { DEFAULT_MIDAS_ADMIN, getSecuritizeAdmin, greenlistMidasGateway, registerMidasInvestor, registerRWAInvestor, registerSecuritizeInvestor } from "./kycUtils.js";
|
|
18
18
|
import { isRangeError, logSplitterTransport } from "./logSplitterTransport.js";
|
|
19
19
|
import { setLTZero, setLTs } from "./ltUtils.js";
|
|
20
|
+
import { lowerHealthFactor } from "./lowerHealthFactor.js";
|
|
20
21
|
import { migrateFaucet } from "./migrateFaucet.js";
|
|
21
22
|
import { SUPPORTED_RPC_PROVIDERS, getAlchemyUrl, getAnkrUrl, getDrpcUrl, getErpcKey, getRpcProviderUrl, getThirdWebUrl, rpcProvidersSchema } from "./providers.js";
|
|
22
23
|
import { replaceStorage } from "./replaceStorage.js";
|
|
@@ -25,4 +26,4 @@ import { claimDSToken, claimDSTokens, enableDSTokenBackDating } from "./securiti
|
|
|
25
26
|
import "./types.js";
|
|
26
27
|
import { ONCHAIN_EXECUTION_ID_ADDRESS, verifyTestnet } from "./verifyTestnet.js";
|
|
27
28
|
import { makePendingWithdrawalsClaimable } from "./withdrawalUtils.js";
|
|
28
|
-
export { AccountOpener, Create2Deployer, DEFAULT_CREATE2_SALT, DEFAULT_MIDAS_ADMIN, EthCallSpy, NoAvailableTransportsError, ONCHAIN_EXECUTION_ID_ADDRESS, OpenTxRevertedError, PUBLIC_CREATE2_FACTORY, RevolverTransport, SUPPORTED_RPC_PROVIDERS, SelectionStrategy, anvilNodeInfo, calcLiquidatableLTs, claimDSToken, claimDSTokens, claimFromFaucet, createAnvilClient, createMinter, deployUsingPublicCreate2, detectChain, discoverMidasCreditSuites, discoverMidasGateways, discoverMidasMTokens, enableDSTokenBackDating, evmMineDetailed, extendAnvilClient, getAlchemyUrl, getAnkrUrl, getDrpcUrl, getErpcKey, getPublicCreate2Address, getRpcProviderUrl, getSecuritizeAdmin, getThirdWebUrl, greenlistMidasGateway, httpTransportOptionsSchema, iDegenNftv2Abi, iFaucetAbi, iOnchainExecutionIdAbi, iOwnableAbi, iaclTraitAbi, isAnvil, isDeployedUsingPublicCreate2, isOutOfSyncError, isRangeError, isRateLimitError, isTransientError, logSplitterTransport, makePendingWithdrawalsClaimable, migrateFaucet, providerConfigSchema, rateLimitOptionsSchema, registerMidasInvestor, registerRWAInvestor, registerSecuritizeInvestor, replaceStorage, resilientTransport, resilientTransportOptionsSchema, revolverTransportConfigBaseSchema, revolverTransportConfigSchema, rpcProvidersSchema, setLTZero, setLTs, unpauseMidasIssuanceVault, verifyTestnet, writeContractSync };
|
|
29
|
+
export { AccountOpener, Create2Deployer, DEFAULT_CREATE2_SALT, DEFAULT_MIDAS_ADMIN, EthCallSpy, NoAvailableTransportsError, ONCHAIN_EXECUTION_ID_ADDRESS, OpenTxRevertedError, PUBLIC_CREATE2_FACTORY, RevolverTransport, SUPPORTED_RPC_PROVIDERS, SelectionStrategy, anvilNodeInfo, calcLiquidatableLTs, claimDSToken, claimDSTokens, claimFromFaucet, createAnvilClient, createMinter, deployUsingPublicCreate2, detectChain, discoverMidasCreditSuites, discoverMidasGateways, discoverMidasMTokens, enableDSTokenBackDating, evmMineDetailed, extendAnvilClient, getAlchemyUrl, getAnkrUrl, getDrpcUrl, getErpcKey, getPublicCreate2Address, getRpcProviderUrl, getSecuritizeAdmin, getThirdWebUrl, greenlistMidasGateway, httpTransportOptionsSchema, iDegenNftv2Abi, iFaucetAbi, iOnchainExecutionIdAbi, iOwnableAbi, iaclTraitAbi, isAnvil, isDeployedUsingPublicCreate2, isOutOfSyncError, isRangeError, isRateLimitError, isTransientError, logSplitterTransport, lowerHealthFactor, makePendingWithdrawalsClaimable, migrateFaucet, providerConfigSchema, rateLimitOptionsSchema, registerMidasInvestor, registerRWAInvestor, registerSecuritizeInvestor, replaceStorage, resilientTransport, resilientTransportOptionsSchema, revolverTransportConfigBaseSchema, revolverTransportConfigSchema, rpcProvidersSchema, setLTZero, setLTs, unpauseMidasIssuanceVault, verifyTestnet, writeContractSync };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { TypedObjectUtils } from "../onchain/utils/mappers.js";
|
|
2
|
+
import "../onchain/index.js";
|
|
3
|
+
import { calcLiquidatableLTs } from "./calcLiquidatableLTs.js";
|
|
4
|
+
import { setLTs } from "./ltUtils.js";
|
|
5
|
+
//#region src/dev/lowerHealthFactor.ts
|
|
6
|
+
/**
|
|
7
|
+
* Lowers liquidation thresholds of credit account's credit manager on anvil, so that account's health factor drops to `hf`.
|
|
8
|
+
* Does not update LTs held in sdk's cached credit manager state.
|
|
9
|
+
*/
|
|
10
|
+
async function lowerHealthFactor(anvil, sdk, ca, options = {}) {
|
|
11
|
+
const { hf, logger } = options;
|
|
12
|
+
if (ca.debt === 0n) throw new Error("warning: zero-debt account");
|
|
13
|
+
const cm = sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
14
|
+
const newLTs = await calcLiquidatableLTs(sdk, ca, hf, logger);
|
|
15
|
+
const oldLTs = {};
|
|
16
|
+
for (const t of TypedObjectUtils.keys(newLTs)) oldLTs[t] = cm.creditManager.liquidationThresholds.mustGet(t);
|
|
17
|
+
await setLTs(anvil, cm.state, newLTs, logger);
|
|
18
|
+
const account = await sdk.accounts.getCreditAccountData(ca.creditAccount);
|
|
19
|
+
if (!account) throw new Error(`cannot find credit account ${ca.creditAccount}`);
|
|
20
|
+
logger?.debug({
|
|
21
|
+
hfNew: account.healthFactor.toString(),
|
|
22
|
+
hfOld: ca.healthFactor.toString()
|
|
23
|
+
});
|
|
24
|
+
return {
|
|
25
|
+
account,
|
|
26
|
+
oldLTs,
|
|
27
|
+
newLTs
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { lowerHealthFactor };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { iWithdrawalCompressorV313Abi } from "../abi/IWithdrawalCompressorV313.js";
|
|
2
1
|
import { getNetworkType } from "../onchain/chain/chains.js";
|
|
3
2
|
import { getWithdrawalCompressorAddress } from "../onchain/accounts/withdrawal-compressor/addresses.js";
|
|
3
|
+
import { iWithdrawalCompressorV313Abi } from "../abi/IWithdrawalCompressorV313.js";
|
|
4
4
|
import "../onchain/index.js";
|
|
5
5
|
import { iMidasDataFeedAbi, iMidasRedemptionVaultAbi, midasGatewayAbi, midasRedeemerAbi, midasRedemptionVaultPhantomTokenAbi, securitizeRedeemerAbi, securitizeRedemptionGatewayAbi, securitizeRedemptionPhantomTokenAbi } from "./withdrawalAbi.js";
|
|
6
6
|
import { erc20Abi, hexToString, parseAbi, parseEther } from "viem";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ierc20Abi } from "../../abi/iERC20.js";
|
|
2
1
|
import { iCreditFacadeV310Abi } from "../../abi/310/generated.js";
|
|
2
|
+
import { ierc20Abi } from "../../abi/iERC20.js";
|
|
3
3
|
import { AddressMap } from "../../onchain/utils/AddressMap.js";
|
|
4
4
|
import "../../onchain/index.js";
|
|
5
5
|
import { UnexpectedFacadeEventOrderError } from "./errors.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ZodAddress } from "../onchain/utils/zod.js";
|
|
2
|
-
import { assetTypeSchema, chainIdSchema, tokenSchema } from "./primitives.schema.js";
|
|
2
|
+
import { assetTypeSchema, chainIdSchema, tokenSchema, underlyingTokenSchema } from "./primitives.schema.js";
|
|
3
3
|
import { chartRangeSchema, protocolChartMetricSchema } from "./charts.schema.js";
|
|
4
|
-
import { curatorNameSchema } from "./curators.schema.js";
|
|
4
|
+
import { curatorNameSchema, curatorSchema } from "./curators.schema.js";
|
|
5
5
|
import { isFilterSet } from "./filters.js";
|
|
6
6
|
import { encodeFlag, filterable } from "./filters.schema.js";
|
|
7
7
|
import { liquidationPositionSchema } from "./liquidations.schema.js";
|
|
@@ -151,14 +151,21 @@ const analyticsPositionPageSchema = z.object({
|
|
|
151
151
|
const analyticsContractOptionSchema = z.object({
|
|
152
152
|
chainId: chainIdSchema,
|
|
153
153
|
address: ZodAddress(),
|
|
154
|
-
name: z.string()
|
|
154
|
+
name: z.string(),
|
|
155
|
+
underlyingToken: underlyingTokenSchema,
|
|
156
|
+
curator: curatorSchema
|
|
157
|
+
});
|
|
158
|
+
/** {@link AnalyticsCuratorOption} */
|
|
159
|
+
const analyticsCuratorOptionSchema = z.object({
|
|
160
|
+
name: curatorNameSchema,
|
|
161
|
+
url: z.string().nullable()
|
|
155
162
|
});
|
|
156
163
|
/** {@link AnalyticsPositionFilterOptions} */
|
|
157
164
|
const analyticsPositionFilterOptionsSchema = z.object({
|
|
158
165
|
pools: z.array(analyticsContractOptionSchema),
|
|
159
166
|
creditManagers: z.array(analyticsContractOptionSchema),
|
|
160
167
|
assets: z.array(tokenSchema),
|
|
161
|
-
curators: z.array(
|
|
168
|
+
curators: z.array(analyticsCuratorOptionSchema)
|
|
162
169
|
});
|
|
163
170
|
/** Chain scope of a filter-options read, shared by the client and backend. */
|
|
164
171
|
const analyticsPositionFilterOptionsQuerySchema = z.codec(analyticsPositionListQueryParamsSchema.pick({ chainIds: true }), analyticsPositionListOptionsSchema.pick({ chainIds: true }), {
|
|
@@ -205,4 +212,4 @@ const analyticsChartQuerySchema = z.codec(analyticsChartQueryParamsSchema, analy
|
|
|
205
212
|
})
|
|
206
213
|
});
|
|
207
214
|
//#endregion
|
|
208
|
-
export { ANALYTICS_POSITIONS_DEFAULT_LIMIT, ANALYTICS_POSITIONS_MAX_LIMIT, analyticsChartQueryOptionsSchema, analyticsChartQueryParamsSchema, analyticsChartQuerySchema, analyticsContractOptionSchema, analyticsContractRefSchema, analyticsPositionFilterOptionsQuerySchema, analyticsPositionFilterOptionsSchema, analyticsPositionListOptionsSchema, analyticsPositionListQueryParamsSchema, analyticsPositionListQuerySchema, analyticsPositionPageSchema, analyticsPositionSchema, analyticsPositionSortFieldSchema, analyticsSortDirectionSchema };
|
|
215
|
+
export { ANALYTICS_POSITIONS_DEFAULT_LIMIT, ANALYTICS_POSITIONS_MAX_LIMIT, analyticsChartQueryOptionsSchema, analyticsChartQueryParamsSchema, analyticsChartQuerySchema, analyticsContractOptionSchema, analyticsContractRefSchema, analyticsCuratorOptionSchema, analyticsPositionFilterOptionsQuerySchema, analyticsPositionFilterOptionsSchema, analyticsPositionListOptionsSchema, analyticsPositionListQueryParamsSchema, analyticsPositionListQuerySchema, analyticsPositionPageSchema, analyticsPositionSchema, analyticsPositionSortFieldSchema, analyticsSortDirectionSchema };
|
package/dist/esm/model/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import { KYC_REGISTRATION_LINKS, RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, RWA_
|
|
|
11
11
|
import { kycRequirementSchema, rwaProtocolSchema } from "./rwa.schema.js";
|
|
12
12
|
import { apyBreakdownSchema, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterQueryParamsSchema, opportunityFilterQuerySchema, opportunityFilterSchema, opportunityKeySchema, opportunityKindSchema, opportunitySchema, opportunityTotalsSchema, pointRewardsSchema, pointsProgramSchema, poolOpportunityDetailSchema, poolOpportunityKeySchema, poolOpportunitySchema, priceFeedDataSchema, priceFeedSummarySchema, quotaAssetSchema, rateCurvePointSchema, rateCurveSchema, rewardsSchema, strategyOpportunityDetailSchema, strategyOpportunityKeySchema, strategyOpportunitySchema, tokenRewardsSchema } from "./opportunities.schema.js";
|
|
13
13
|
import { borrowRateBreakdownSchema, pnlBreakdownSchema, pointsProgramPnLSchema, pointsRewardsPnLSchema, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionKeySchema, positionKindSchema, positionSchema, positionTransactionKindSchema, positionTransactionSchema, positionsTotalsSchema, rewardsPnLSchema, strategyPositionKeySchema, strategyPositionSchema, tokenQuotaRateSchema, tokenRewardsPnLSchema } from "./positions.schema.js";
|
|
14
|
-
import { ANALYTICS_POSITIONS_DEFAULT_LIMIT, ANALYTICS_POSITIONS_MAX_LIMIT, analyticsChartQueryOptionsSchema, analyticsChartQueryParamsSchema, analyticsChartQuerySchema, analyticsContractOptionSchema, analyticsContractRefSchema, analyticsPositionFilterOptionsQuerySchema, analyticsPositionFilterOptionsSchema, analyticsPositionListOptionsSchema, analyticsPositionListQueryParamsSchema, analyticsPositionListQuerySchema, analyticsPositionPageSchema, analyticsPositionSchema, analyticsPositionSortFieldSchema, analyticsSortDirectionSchema } from "./analytics.schema.js";
|
|
14
|
+
import { ANALYTICS_POSITIONS_DEFAULT_LIMIT, ANALYTICS_POSITIONS_MAX_LIMIT, analyticsChartQueryOptionsSchema, analyticsChartQueryParamsSchema, analyticsChartQuerySchema, analyticsContractOptionSchema, analyticsContractRefSchema, analyticsCuratorOptionSchema, analyticsPositionFilterOptionsQuerySchema, analyticsPositionFilterOptionsSchema, analyticsPositionListOptionsSchema, analyticsPositionListQueryParamsSchema, analyticsPositionListQuerySchema, analyticsPositionPageSchema, analyticsPositionSchema, analyticsPositionSortFieldSchema, analyticsSortDirectionSchema } from "./analytics.schema.js";
|
|
15
15
|
import "./curators.js";
|
|
16
16
|
import "./delayed-intents.js";
|
|
17
17
|
import { creditAccountFrozen, liquidatorNotEligible, notEmergencyLiquidator, partialLiquidationImpossible } from "./errors/liquidation-errors.js";
|
|
@@ -33,4 +33,4 @@ import { safeValue, sdkErr, sdkOk } from "./result.js";
|
|
|
33
33
|
import "./rewards.js";
|
|
34
34
|
import "./withdrawals.js";
|
|
35
35
|
import { positionClaimableWithdrawalSchema, positionPendingWithdrawalSchema, positionWithdrawalsSchema, withdrawalOutputAmountSchema } from "./withdrawals.schema.js";
|
|
36
|
-
export { ANALYTICS_POSITIONS_DEFAULT_LIMIT, ANALYTICS_POSITIONS_MAX_LIMIT, CHART_METRIC_UNITS, CHART_RANGES, CHART_UNAVAILABLE_CODES, FILTER_ALL, KYC_REGISTRATION_LINKS, POOL_OPPORTUNITY_CHART_METRICS, POOL_POSITION_CHART_METRICS, PROTOCOL_CHART_METRICS, RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, RWA_PROTOCOLS, SECURITIZE_REGISTER_VAULT_TYPES, STRATEGY_OPPORTUNITY_CHART_METRICS, STRATEGY_POSITION_CHART_METRICS, STRATEGY_POSITION_COLLATERAL_ERROR, accountNotMidasGreenlisted, amountSchema, analyticsChartQueryOptionsSchema, analyticsChartQueryParamsSchema, analyticsChartQuerySchema, analyticsContractOptionSchema, analyticsContractRefSchema, analyticsPositionFilterOptionsQuerySchema, analyticsPositionFilterOptionsSchema, analyticsPositionListOptionsSchema, analyticsPositionListQueryParamsSchema, analyticsPositionListQuerySchema, analyticsPositionPageSchema, analyticsPositionSchema, analyticsPositionSortFieldSchema, analyticsSortDirectionSchema, apyBreakdownSchema, asEstimated, assetTypeSchema, backendPreferred, booleanParamSchema, borrowRateBreakdownSchema, bpsSchema, chainFailedSchema, chainIdSchema, chainMetadataSchema, chainSucceededSchema, chartBundleSchemaFor, chartDenominationSchema, chartMetricSchema, chartQueryCodec, chartQueryParamsSchema, chartQuerySchema, chartRangeSchema, chartSeriesSchema, chartValueSchema, chartWindowSchema, compareTagOf, creditAccountFrozen, creditAccountNotEmpty, creditAccountNotFound, creditManagerPaused, curatorNameSchema, curatorSchema, dataSourceSchema, debtOutOfRange, delayedReceivedAssetSchema, encodeFlag, filterAllSchema, filterable, forbiddenToken, instantReceivedAssetSchema, insufficientAllowance, insufficientBalance, insufficientCollateral, insufficientPoolLiquidity, isFilterSet, kycRequirementSchema, leverageOutOfRange, leverageSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionId, liquidationPositionSchema, liquidatorNotEligible, malformedTransaction, marketExpired, matchesLiquidatableAccountFilter, matchesOpportunityFilter, matchesPositionFilter, multipleDelayedWithdrawals, noDelayedRoute, noRecordedIntent, noStrategyTargetCollateral, notEmergencyLiquidator, noticeKindSchema, noticeSchema, offchainOnly, onchainOnly, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterQueryParamsSchema, opportunityFilterQuerySchema, opportunityFilterSchema, opportunityId, opportunityKeySchema, opportunityKindSchema, opportunitySchema, opportunityTotalsSchema, partialLiquidationImpossible, pnlBreakdownSchema, pointRewardsSchema, pointsProgramPnLSchema, pointsProgramSchema, pointsRewardsPnLSchema, poolOpportunityChartMetricSchema, poolOpportunityDetailSchema, poolOpportunityId, poolOpportunityKeySchema, poolOpportunitySchema, poolPaused, poolPositionChartMetricSchema, poolPositionId, poolPositionKeySchema, poolPositionSchema, poolSunset, positionClaimableWithdrawalSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionId, positionKeySchema, positionKindSchema, positionPendingWithdrawalSchema, positionSchema, positionTransactionKindSchema, positionTransactionSchema, positionWithdrawalsSchema, positionsTotalsSchema, priceFeedDataSchema, priceFeedSummarySchema, protocolChartMetricSchema, quotaAboveMax, quotaAssetSchema, quotaCountExceeded, quotaInactive, quotaLimitReached, quotaUnchanged, rateCurvePointSchema, rateCurveSchema, receivedAssetSchema, reservePriceLimited, responseMetadataSchema, responseSchema, rewardsPnLSchema, rewardsSchema, rwaOpenRequirementsNotMet, rwaProtocolSchema, safeValue, sdkErr, sdkOk, strategyOpportunityChartMetricSchema, strategyOpportunityDetailSchema, strategyOpportunityId, strategyOpportunityKeySchema, strategyOpportunitySchema, strategyPositionChartMetricSchema, strategyPositionId, strategyPositionKeySchema, strategyPositionSchema, timestampSchema, tokenAmountSchema, tokenQuotaRateSchema, tokenRewardsPnLSchema, tokenRewardsSchema, tokenSchema, tolerance, txCallSchema, underlyingTokenSchema, unexpectedFailure, unpriceableTokenError, unsupportedCollateralToken, unsupportedTokenPair, withdrawalInProgress, withdrawalOutputAmountSchema };
|
|
36
|
+
export { ANALYTICS_POSITIONS_DEFAULT_LIMIT, ANALYTICS_POSITIONS_MAX_LIMIT, CHART_METRIC_UNITS, CHART_RANGES, CHART_UNAVAILABLE_CODES, FILTER_ALL, KYC_REGISTRATION_LINKS, POOL_OPPORTUNITY_CHART_METRICS, POOL_POSITION_CHART_METRICS, PROTOCOL_CHART_METRICS, RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, RWA_PROTOCOLS, SECURITIZE_REGISTER_VAULT_TYPES, STRATEGY_OPPORTUNITY_CHART_METRICS, STRATEGY_POSITION_CHART_METRICS, STRATEGY_POSITION_COLLATERAL_ERROR, accountNotMidasGreenlisted, amountSchema, analyticsChartQueryOptionsSchema, analyticsChartQueryParamsSchema, analyticsChartQuerySchema, analyticsContractOptionSchema, analyticsContractRefSchema, analyticsCuratorOptionSchema, analyticsPositionFilterOptionsQuerySchema, analyticsPositionFilterOptionsSchema, analyticsPositionListOptionsSchema, analyticsPositionListQueryParamsSchema, analyticsPositionListQuerySchema, analyticsPositionPageSchema, analyticsPositionSchema, analyticsPositionSortFieldSchema, analyticsSortDirectionSchema, apyBreakdownSchema, asEstimated, assetTypeSchema, backendPreferred, booleanParamSchema, borrowRateBreakdownSchema, bpsSchema, chainFailedSchema, chainIdSchema, chainMetadataSchema, chainSucceededSchema, chartBundleSchemaFor, chartDenominationSchema, chartMetricSchema, chartQueryCodec, chartQueryParamsSchema, chartQuerySchema, chartRangeSchema, chartSeriesSchema, chartValueSchema, chartWindowSchema, compareTagOf, creditAccountFrozen, creditAccountNotEmpty, creditAccountNotFound, creditManagerPaused, curatorNameSchema, curatorSchema, dataSourceSchema, debtOutOfRange, delayedReceivedAssetSchema, encodeFlag, filterAllSchema, filterable, forbiddenToken, instantReceivedAssetSchema, insufficientAllowance, insufficientBalance, insufficientCollateral, insufficientPoolLiquidity, isFilterSet, kycRequirementSchema, leverageOutOfRange, leverageSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionId, liquidationPositionSchema, liquidatorNotEligible, malformedTransaction, marketExpired, matchesLiquidatableAccountFilter, matchesOpportunityFilter, matchesPositionFilter, multipleDelayedWithdrawals, noDelayedRoute, noRecordedIntent, noStrategyTargetCollateral, notEmergencyLiquidator, noticeKindSchema, noticeSchema, offchainOnly, onchainOnly, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterQueryParamsSchema, opportunityFilterQuerySchema, opportunityFilterSchema, opportunityId, opportunityKeySchema, opportunityKindSchema, opportunitySchema, opportunityTotalsSchema, partialLiquidationImpossible, pnlBreakdownSchema, pointRewardsSchema, pointsProgramPnLSchema, pointsProgramSchema, pointsRewardsPnLSchema, poolOpportunityChartMetricSchema, poolOpportunityDetailSchema, poolOpportunityId, poolOpportunityKeySchema, poolOpportunitySchema, poolPaused, poolPositionChartMetricSchema, poolPositionId, poolPositionKeySchema, poolPositionSchema, poolSunset, positionClaimableWithdrawalSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionId, positionKeySchema, positionKindSchema, positionPendingWithdrawalSchema, positionSchema, positionTransactionKindSchema, positionTransactionSchema, positionWithdrawalsSchema, positionsTotalsSchema, priceFeedDataSchema, priceFeedSummarySchema, protocolChartMetricSchema, quotaAboveMax, quotaAssetSchema, quotaCountExceeded, quotaInactive, quotaLimitReached, quotaUnchanged, rateCurvePointSchema, rateCurveSchema, receivedAssetSchema, reservePriceLimited, responseMetadataSchema, responseSchema, rewardsPnLSchema, rewardsSchema, rwaOpenRequirementsNotMet, rwaProtocolSchema, safeValue, sdkErr, sdkOk, strategyOpportunityChartMetricSchema, strategyOpportunityDetailSchema, strategyOpportunityId, strategyOpportunityKeySchema, strategyOpportunitySchema, strategyPositionChartMetricSchema, strategyPositionId, strategyPositionKeySchema, strategyPositionSchema, timestampSchema, tokenAmountSchema, tokenQuotaRateSchema, tokenRewardsPnLSchema, tokenRewardsSchema, tokenSchema, tolerance, txCallSchema, underlyingTokenSchema, unexpectedFailure, unpriceableTokenError, unsupportedCollateralToken, unsupportedTokenPair, withdrawalInProgress, withdrawalOutputAmountSchema };
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { iBaseRewardPoolAbi } from "../../abi/iBaseRewardPool.js";
|
|
2
|
-
import { ierc4626AdapterAbi } from "../../abi/ierc4626Adapter.js";
|
|
3
1
|
import { AP_REWARDS_COMPRESSOR } from "../constants/address-provider.js";
|
|
4
2
|
import { ADDRESS_0X0 } from "../constants/addresses.js";
|
|
5
3
|
import { MAX_UINT256 } from "../constants/math.js";
|
|
@@ -10,6 +8,8 @@ import "../base/index.js";
|
|
|
10
8
|
import { AccountBotsService } from "./bots/AccountBotsService.js";
|
|
11
9
|
import "./bots/index.js";
|
|
12
10
|
import { rewardsCompressorAbi } from "../../abi/compressors/rewardsCompressor.js";
|
|
11
|
+
import { iBaseRewardPoolAbi } from "../../abi/iBaseRewardPool.js";
|
|
12
|
+
import { ierc4626AdapterAbi } from "../../abi/ierc4626Adapter.js";
|
|
13
13
|
import { expectedBalanceDeltas } from "../market/credit/expectedBalanceDeltas.js";
|
|
14
14
|
import "../market/index.js";
|
|
15
15
|
import { CreditAccountCompressor } from "./credit-account-compressor/CreditAccountCompressor.js";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { iLiquidationCompressorV313Abi } from "../../../abi/ILiquidationCompressorV313.js";
|
|
2
1
|
import { AddressSet } from "../../utils/AddressSet.js";
|
|
3
2
|
import { bytes32ToString } from "../../utils/bytes32ToString.js";
|
|
4
3
|
import { ADDRESS_0X0 } from "../../constants/addresses.js";
|
|
@@ -20,8 +19,10 @@ import { SecuritizeLiquidatorContract } from "../../market/rwa/securitize/Securi
|
|
|
20
19
|
import "../../market/rwa/securitize/index.js";
|
|
21
20
|
import "../../market/index.js";
|
|
22
21
|
import { LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS } from "./constants.js";
|
|
22
|
+
import { iLiquidationCompressorV313Abi } from "../../../abi/ILiquidationCompressorV313.js";
|
|
23
23
|
import { optimalPartialLiquidation, partialLiquidationParams } from "./partialLiquidation.js";
|
|
24
24
|
import { skipLiquidatableAccount } from "./skipLiquidatableAccount.js";
|
|
25
|
+
import { isAddressEqual } from "viem";
|
|
25
26
|
//#region src/onchain/accounts/liquidations/LiquidationsService.ts
|
|
26
27
|
/**
|
|
27
28
|
* Service for discovering liquidatable credit accounts and previewing manual
|
|
@@ -120,14 +121,15 @@ var LiquidationsService = class extends SDKConstruct {
|
|
|
120
121
|
* full one: what the liquidator pays, what it receives and what it must
|
|
121
122
|
* approve, plus {@link LiquidationDetails.isPartiallyLiquidatable}.
|
|
122
123
|
*
|
|
123
|
-
* A local estimate
|
|
124
|
-
*
|
|
124
|
+
* A local estimate, not onchain read: no price feed updates are applied, so
|
|
125
|
+
* `ignoreReservePrices` has no effect here.
|
|
126
|
+
* Parameters left out of `props` are derived from current state.
|
|
125
127
|
*
|
|
126
|
-
* @throws For
|
|
127
|
-
* `tokenOut` can be picked.
|
|
128
|
+
* @throws For markets with a wrapped RWA underlying (Securitize), for a
|
|
129
|
+
* `tokenOut` that cannot be seized, and when no `tokenOut` can be picked.
|
|
128
130
|
**/
|
|
129
131
|
async getPartialLiquidationDetails(props) {
|
|
130
|
-
const { creditAccount, blockNumber } = props;
|
|
132
|
+
const { creditAccount, liquidator, blockNumber } = props;
|
|
131
133
|
const ca = await this.#getCreditAccountData(creditAccount, blockNumber);
|
|
132
134
|
const suite = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
133
135
|
const { priceOracle } = suite.market;
|
|
@@ -136,6 +138,13 @@ var LiquidationsService = class extends SDKConstruct {
|
|
|
136
138
|
const { liquidationDiscount } = suite.liquidationFees();
|
|
137
139
|
const seizedValue = repaidAmount * PERCENTAGE_FACTOR / BigInt(liquidationDiscount);
|
|
138
140
|
const seizedAmount = priceOracle.convert(underlying, tokenOut, repaidAmount) * PERCENTAGE_FACTOR / BigInt(liquidationDiscount);
|
|
141
|
+
const nft = await suite.degenNFT();
|
|
142
|
+
let isLiquidatorEligible = !nft;
|
|
143
|
+
if (nft && liquidator) {
|
|
144
|
+
const requirements = await nft.getOpenAccountRequirements(liquidator, { tokenOutAddress: tokenOut });
|
|
145
|
+
isLiquidatorEligible = nft.isRegistered(requirements);
|
|
146
|
+
}
|
|
147
|
+
const [kycToken] = nft && !isLiquidatorEligible ? await nft.getTokens() : [];
|
|
139
148
|
return {
|
|
140
149
|
...this.#buildAccount(ca, suite),
|
|
141
150
|
repaymentAmount: priceOracle.toTokenAmount(underlying, repaidAmount),
|
|
@@ -146,7 +155,9 @@ var LiquidationsService = class extends SDKConstruct {
|
|
|
146
155
|
...priceOracle.toTokenAmount(tokenOut, seizedAmount),
|
|
147
156
|
token: this.sdk.tokensMeta.mustGetToken(this.sdk.tokensMeta.depositedToken(tokenOut))
|
|
148
157
|
}],
|
|
149
|
-
isLiquidatorEligible
|
|
158
|
+
isLiquidatorEligible,
|
|
159
|
+
kycProtocol: isLiquidatorEligible ? void 0 : nft?.protocol,
|
|
160
|
+
kycToken: kycToken ? this.sdk.tokensMeta.getToken(kycToken) : void 0,
|
|
150
161
|
isCreditAccountFrozen: false,
|
|
151
162
|
approve: repaidAmount === 0n ? void 0 : {
|
|
152
163
|
spender: suite.creditManager.address,
|
|
@@ -162,17 +173,18 @@ var LiquidationsService = class extends SDKConstruct {
|
|
|
162
173
|
* discounted collateral sent to the liquidator. Parameters left out of
|
|
163
174
|
* `props` are derived from current state.
|
|
164
175
|
*
|
|
165
|
-
* @throws For
|
|
166
|
-
* `tokenOut`
|
|
167
|
-
* liquidated, see
|
|
176
|
+
* @throws For markets with a wrapped RWA underlying (Securitize), for a
|
|
177
|
+
* `tokenOut` that cannot be seized, when no `tokenOut` can be picked, and
|
|
178
|
+
* when the account cannot be partially liquidated, see
|
|
179
|
+
* {@link LiquidationDetails.isPartiallyLiquidatable}.
|
|
168
180
|
**/
|
|
169
181
|
async buildPartialLiquidationTx(props) {
|
|
170
|
-
const { creditAccount, liquidator, blockNumber } = props;
|
|
182
|
+
const { creditAccount, liquidator, ignoreReservePrices, blockNumber } = props;
|
|
171
183
|
const ca = await this.#getCreditAccountData(creditAccount, blockNumber);
|
|
172
184
|
const suite = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
173
185
|
const params = this.#getPartialLiquidationParams(ca, suite, props);
|
|
174
186
|
if (!params.isPartiallyLiquidatable) throw new Error(`credit account ${this.labelAddress(creditAccount)} cannot be partially liquidated`);
|
|
175
|
-
const updates = await this.sdk.accounts.getOnDemandPriceUpdates(ca,
|
|
187
|
+
const updates = await this.sdk.accounts.getOnDemandPriceUpdates(ca, ignoreReservePrices);
|
|
176
188
|
const tx = suite.creditFacade.partiallyLiquidateCreditAccount(ca.creditAccount, params.tokenOut, params.repaidAmount, params.minSeizedAmount, liquidator, updates);
|
|
177
189
|
this.logger?.debug(`built tx to partially liquidate credit account ${this.labelAddress(creditAccount)} to ${this.labelAddress(liquidator)}`);
|
|
178
190
|
return {
|
|
@@ -184,9 +196,6 @@ var LiquidationsService = class extends SDKConstruct {
|
|
|
184
196
|
* Optimal partial liquidation of a credit account: the collateral to seize
|
|
185
197
|
* and the amounts that bring its health factor close to `optimalHF`.
|
|
186
198
|
*
|
|
187
|
-
* Prices come from the last synced oracle state and `ca`, not from fresh
|
|
188
|
-
* price updates. Withdrawal phantom tokens are never seized.
|
|
189
|
-
*
|
|
190
199
|
* @param ca - Credit account to partially liquidate.
|
|
191
200
|
* @param optimalHF - Health factor to aim for, in basis points. Defaults to
|
|
192
201
|
* {@link CreditSuite.optimalHFForPartialLiquidation}.
|
|
@@ -195,11 +204,12 @@ var LiquidationsService = class extends SDKConstruct {
|
|
|
195
204
|
* @throws If no `tokenOut` can be picked.
|
|
196
205
|
**/
|
|
197
206
|
getOptimalPartialLiquidation(ca, optimalHF, liquidationThresholds) {
|
|
207
|
+
const suite = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
198
208
|
return optimalPartialLiquidation({
|
|
199
|
-
suite
|
|
209
|
+
suite,
|
|
200
210
|
account: ca,
|
|
201
211
|
optimalHF,
|
|
202
|
-
exclude: (token) => this.#
|
|
212
|
+
exclude: (token) => this.#isUnseizable(suite, token),
|
|
203
213
|
liquidationThresholds
|
|
204
214
|
});
|
|
205
215
|
}
|
|
@@ -335,24 +345,32 @@ var LiquidationsService = class extends SDKConstruct {
|
|
|
335
345
|
/**
|
|
336
346
|
* Everything a partial liquidation of a credit account needs, with any
|
|
337
347
|
* parameter the caller pinned down taken as given and the rest derived from
|
|
338
|
-
* current state. A derived `tokenOut` is never a
|
|
348
|
+
* current state. A derived `tokenOut` is never a token that cannot be seized.
|
|
339
349
|
*
|
|
340
|
-
* @throws For
|
|
341
|
-
* the
|
|
342
|
-
* which does not redeem instantly,
|
|
343
|
-
*
|
|
350
|
+
* @throws For markets with a wrapped RWA underlying (Securitize), whose
|
|
351
|
+
* repayment the liquidator cannot fund, for a `tokenOut` that cannot be
|
|
352
|
+
* seized (a withdrawal phantom token, which does not redeem instantly, or a
|
|
353
|
+
* phantom token that unwraps to the underlying), if a derived `tokenOut`
|
|
354
|
+
* cannot be picked, and if the seized token is not a collateral token of the
|
|
355
|
+
* credit manager.
|
|
344
356
|
**/
|
|
345
357
|
#getPartialLiquidationParams(ca, suite, overrides) {
|
|
346
358
|
const label = this.labelAddress(ca.creditAccount);
|
|
347
|
-
if (suite.
|
|
348
|
-
if (overrides.tokenOut && this.#
|
|
359
|
+
if (this.sdk.tokensMeta.isRWAUnderlying(this.sdk.tokensMeta.mustGet(suite.underlying))) throw new Error(`cannot partially liquidate ${label}: markets with a wrapped RWA underlying are not supported`);
|
|
360
|
+
if (overrides.tokenOut && this.#isUnseizable(suite, overrides.tokenOut)) throw new Error(`cannot partially liquidate ${label}: ${this.labelAddress(overrides.tokenOut)} cannot be seized`);
|
|
349
361
|
return partialLiquidationParams({
|
|
350
362
|
suite,
|
|
351
363
|
account: ca,
|
|
352
364
|
overrides,
|
|
353
|
-
exclude: (token) => this.#
|
|
365
|
+
exclude: (token) => this.#isUnseizable(suite, token)
|
|
354
366
|
});
|
|
355
367
|
}
|
|
368
|
+
/**
|
|
369
|
+
* The facade reverts when a phantom tokenOut unwraps to the underlying
|
|
370
|
+
**/
|
|
371
|
+
#isUnseizable(suite, token) {
|
|
372
|
+
return this.#isWithdrawalPhantom(token) || isAddressEqual(this.sdk.tokensMeta.depositedToken(token), suite.underlying);
|
|
373
|
+
}
|
|
356
374
|
async #getCreditAccountData(creditAccount, blockNumber) {
|
|
357
375
|
const ca = await this.sdk.accounts.getCreditAccountData(creditAccount, blockNumber);
|
|
358
376
|
if (!ca) throw new Error(`credit account ${creditAccount} not found`);
|
|
@@ -425,7 +443,6 @@ var LiquidationsService = class extends SDKConstruct {
|
|
|
425
443
|
};
|
|
426
444
|
}
|
|
427
445
|
#isPartiallyLiquidatable(ca, suite) {
|
|
428
|
-
if (suite.market.rwa) return false;
|
|
429
446
|
try {
|
|
430
447
|
return this.#getPartialLiquidationParams(ca, suite, {}).isPartiallyLiquidatable;
|
|
431
448
|
} catch (e) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { iRedemptionLoggerV310Abi } from "../../../abi/iRedemptionLoggerV310.js";
|
|
2
1
|
import { BaseContract } from "../../base/BaseContract.js";
|
|
3
2
|
import "../../base/index.js";
|
|
4
3
|
import { sdkErr, sdkOk } from "../../../model/result.js";
|
|
5
4
|
import "../../../model/index.js";
|
|
6
5
|
import { decodeDelayedIntent } from "./intent-codec.js";
|
|
6
|
+
import { iRedemptionLoggerV310Abi } from "../../../abi/iRedemptionLoggerV310.js";
|
|
7
7
|
//#region src/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.ts
|
|
8
8
|
const abi = iRedemptionLoggerV310Abi;
|
|
9
9
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { iWithdrawalCompressorV310Abi } from "../../../abi/IWithdrawalCompressorV310.js";
|
|
2
1
|
import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
|
|
2
|
+
import { iWithdrawalCompressorV310Abi } from "../../../abi/IWithdrawalCompressorV310.js";
|
|
3
3
|
//#region src/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.ts
|
|
4
4
|
const abi = iWithdrawalCompressorV310Abi;
|
|
5
5
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { iWithdrawalCompressorV311Abi } from "../../../abi/IWithdrawalCompressorV311.js";
|
|
2
1
|
import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
|
|
2
|
+
import { iWithdrawalCompressorV311Abi } from "../../../abi/IWithdrawalCompressorV311.js";
|
|
3
3
|
//#region src/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.ts
|
|
4
4
|
const abi = iWithdrawalCompressorV311Abi;
|
|
5
5
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { iWithdrawalCompressorV313Abi } from "../../../abi/IWithdrawalCompressorV313.js";
|
|
2
1
|
import { encodeDelayedIntent } from "./intent-codec.js";
|
|
3
2
|
import { AbstractWithdrawalCompressorContract, iCreditAccountAbi, toClaimableWithdrawal, toPendingWithdrawal, toRequestableWithdrawal } from "./AbstractWithdrawalCompressorContract.js";
|
|
3
|
+
import { iWithdrawalCompressorV313Abi } from "../../../abi/IWithdrawalCompressorV313.js";
|
|
4
4
|
import { toWithdrawalStatus } from "./types.js";
|
|
5
5
|
//#region src/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.ts
|
|
6
6
|
const abi = iWithdrawalCompressorV313Abi;
|