@gearbox-protocol/sdk 16.0.0-next.29 → 16.0.0-next.30
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/model/liquidations.schema.js +5 -1
- package/dist/cjs/onchain/accounts/intents/index.js +5 -5
- package/dist/cjs/onchain/accounts/intents/open-strategy.js +4 -3
- package/dist/cjs/onchain/accounts/intents/testing/sdk-mock.js +13 -4
- package/dist/cjs/onchain/accounts/liquidations/LiquidationsService.js +6 -5
- package/dist/cjs/onchain/accounts/liquidations/skipLiquidatableAccount.js +12 -0
- package/dist/cjs/onchain/market/credit/creditOperationMarket.js +7 -3
- package/dist/cjs/sdk/execute/ExecuteApi.js +6 -6
- package/dist/cjs/sdk/prepare/PrepareApi.js +8 -8
- package/dist/esm/dev/AccountOpener.js +1 -1
- package/dist/esm/dev/withdrawalUtils.js +1 -1
- package/dist/esm/model/liquidations.schema.js +6 -2
- package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +2 -2
- package/dist/esm/onchain/accounts/intents/index.js +6 -6
- package/dist/esm/onchain/accounts/intents/open-strategy.js +4 -3
- package/dist/esm/onchain/accounts/intents/testing/sdk-mock.js +13 -4
- package/dist/esm/onchain/accounts/liquidations/LiquidationsService.js +7 -6
- package/dist/esm/onchain/accounts/liquidations/skipLiquidatableAccount.js +11 -0
- 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/credit/creditOperationMarket.js +7 -3
- package/dist/esm/onchain/market/pool/PoolV310Contract.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/utils/viem/simulateWithPriceUpdates.js +1 -1
- package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
- package/dist/esm/preview/trace/extractTransfers.js +1 -1
- package/dist/esm/sdk/execute/ExecuteApi.js +6 -6
- package/dist/esm/sdk/prepare/PrepareApi.js +8 -8
- package/dist/types/model/index.d.ts +3 -3
- package/dist/types/model/liquidations.d.ts +14 -8
- package/dist/types/model/liquidations.schema.d.ts +46 -2
- package/dist/types/model/positions.d.ts +1 -1
- package/dist/types/model/previews.d.ts +9 -7
- package/dist/types/onchain/accounts/index.d.ts +2 -2
- package/dist/types/onchain/accounts/intents/index.d.ts +3 -3
- package/dist/types/onchain/accounts/intents/open-strategy.d.ts +6 -19
- package/dist/types/onchain/accounts/intents/testing/sdk-mock.d.ts +8 -2
- package/dist/types/onchain/accounts/intents/types.d.ts +24 -17
- package/dist/types/onchain/accounts/liquidations/LiquidationsService.d.ts +0 -1
- package/dist/types/onchain/accounts/liquidations/skipLiquidatableAccount.d.ts +11 -0
- package/dist/types/onchain/index.d.ts +2 -2
- package/dist/types/onchain/market/credit/creditOperationMarket.d.ts +6 -2
- package/dist/types/sdk/execute/types.d.ts +4 -4
- package/dist/types/sdk/prepare/types.d.ts +8 -8
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_onchain_utils_zod = require("../onchain/utils/zod.js");
|
|
3
3
|
const require_model_primitives_schema = require("./primitives.schema.js");
|
|
4
|
+
const require_model_curators_schema = require("./curators.schema.js");
|
|
4
5
|
const require_model_filters_schema = require("./filters.schema.js");
|
|
5
6
|
let zod_v4 = require("zod/v4");
|
|
6
7
|
//#region src/model/liquidations.schema.ts
|
|
@@ -22,9 +23,12 @@ const liquidatableAccountFilterSchema = zod_v4.z.object({
|
|
|
22
23
|
* {@link LiquidatableAccount}
|
|
23
24
|
**/
|
|
24
25
|
const liquidatableAccountSchema = zod_v4.z.object({
|
|
26
|
+
creditManager: require_onchain_utils_zod.ZodAddress(),
|
|
27
|
+
name: zod_v4.z.string(),
|
|
28
|
+
curator: require_model_curators_schema.curatorSchema,
|
|
29
|
+
liquidationDiscount: require_model_primitives_schema.bpsSchema,
|
|
25
30
|
chainId: require_model_primitives_schema.chainIdSchema,
|
|
26
31
|
creditAccount: require_onchain_utils_zod.ZodAddress(),
|
|
27
|
-
creditManager: require_onchain_utils_zod.ZodAddress(),
|
|
28
32
|
asset: require_model_primitives_schema.tokenSchema,
|
|
29
33
|
totalValue: require_model_primitives_schema.tokenAmountSchema,
|
|
30
34
|
repaymentAmount: require_model_primitives_schema.tokenAmountSchema,
|
|
@@ -170,7 +170,7 @@ var CreditAccountOperationsService = class extends require_onchain_base_SDKConst
|
|
|
170
170
|
});
|
|
171
171
|
return {
|
|
172
172
|
...result,
|
|
173
|
-
|
|
173
|
+
state: tail.state,
|
|
174
174
|
delayed
|
|
175
175
|
};
|
|
176
176
|
} catch (e) {
|
|
@@ -258,7 +258,7 @@ var CreditAccountOperationsService = class extends require_onchain_base_SDKConst
|
|
|
258
258
|
try {
|
|
259
259
|
return {
|
|
260
260
|
ok: true,
|
|
261
|
-
|
|
261
|
+
state: await require_onchain_accounts_intents_open_strategy.buildOpenStrategyState(props)
|
|
262
262
|
};
|
|
263
263
|
} catch (e) {
|
|
264
264
|
return asFailure(e);
|
|
@@ -277,7 +277,7 @@ var CreditAccountOperationsService = class extends require_onchain_base_SDKConst
|
|
|
277
277
|
return {
|
|
278
278
|
ok: true,
|
|
279
279
|
operations,
|
|
280
|
-
|
|
280
|
+
state,
|
|
281
281
|
calls,
|
|
282
282
|
delayed
|
|
283
283
|
};
|
|
@@ -289,11 +289,11 @@ var CreditAccountOperationsService = class extends require_onchain_base_SDKConst
|
|
|
289
289
|
/** Drops the delayed half for the flows that cannot produce one. */
|
|
290
290
|
function plain(result) {
|
|
291
291
|
if (!result.ok) return result;
|
|
292
|
-
const { operations,
|
|
292
|
+
const { operations, state, calls } = result;
|
|
293
293
|
return {
|
|
294
294
|
ok: true,
|
|
295
295
|
operations,
|
|
296
|
-
|
|
296
|
+
state,
|
|
297
297
|
calls
|
|
298
298
|
};
|
|
299
299
|
}
|
|
@@ -10,7 +10,8 @@ require("./utils/index.js");
|
|
|
10
10
|
/** Stand-in account address: nothing exists on chain until the tx lands. */
|
|
11
11
|
const NO_ACCOUNT = "0x0000000000000000000000000000000000000000";
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Builds the state opening a leveraged position out of wallet collateral would
|
|
14
|
+
* land in.
|
|
14
15
|
*
|
|
15
16
|
* Debt follows from the target leverage against the supplied margin
|
|
16
17
|
* (`debt = margin * (L - 1)`, `totalValue = margin * L`); the collateral and the
|
|
@@ -20,7 +21,7 @@ const NO_ACCOUNT = "0x0000000000000000000000000000000000000000";
|
|
|
20
21
|
* no operation list — the caller passes the numbers and calls straight to
|
|
21
22
|
* `sdk.accounts.openCA`.
|
|
22
23
|
*/
|
|
23
|
-
async function
|
|
24
|
+
async function buildOpenStrategyState(props) {
|
|
24
25
|
const { sdk, creditManager, collateral, targetToken, leverage, slippage = 0, quotaReserve, leftoverBalances = [] } = props;
|
|
25
26
|
require_onchain_accounts_intents_math.assertLeverageAtLeastOne(leverage);
|
|
26
27
|
const suite = sdk.marketRegister.findCreditManager(creditManager);
|
|
@@ -130,4 +131,4 @@ function toAssets(balances) {
|
|
|
130
131
|
}));
|
|
131
132
|
}
|
|
132
133
|
//#endregion
|
|
133
|
-
exports.
|
|
134
|
+
exports.buildOpenStrategyState = buildOpenStrategyState;
|
|
@@ -13,8 +13,16 @@ let vitest = require("vitest");
|
|
|
13
13
|
* from their inputs, so `result.calls` pins down which ops reached the
|
|
14
14
|
* assembler and in which order.
|
|
15
15
|
*/
|
|
16
|
-
/**
|
|
17
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Curator of the mock market: an unknown market configurator, so it carries no
|
|
18
|
+
* display name and no page — what the on-chain source answers for a
|
|
19
|
+
* configurator outside the curated table.
|
|
20
|
+
*/
|
|
21
|
+
const MOCK_CURATOR = {
|
|
22
|
+
address: "0x00000000000000000000000000000000000c0f16",
|
|
23
|
+
name: void 0,
|
|
24
|
+
url: null
|
|
25
|
+
};
|
|
18
26
|
/**
|
|
19
27
|
* Liquidation fees of the mock suite: a 3% premium (the manager reports its
|
|
20
28
|
* complement) on top of a 1.5% protocol fee, so the discount a screen shows is
|
|
@@ -166,6 +174,8 @@ function buildMockSdk(args) {
|
|
|
166
174
|
};
|
|
167
175
|
const market = {
|
|
168
176
|
toUnderlyingAmount,
|
|
177
|
+
/** {@inheritDoc MarketSuite.curator} */
|
|
178
|
+
curator: MOCK_CURATOR,
|
|
169
179
|
/** {@inheritDoc MarketSuite.underlying} */
|
|
170
180
|
underlying: args.underlying,
|
|
171
181
|
priceOracle: {
|
|
@@ -217,7 +227,6 @@ function buildMockSdk(args) {
|
|
|
217
227
|
const expirationDate = args.expirationDate ?? 0;
|
|
218
228
|
const creditManagerSuite = {
|
|
219
229
|
name: "TestCreditManager",
|
|
220
|
-
marketConfigurator: { address: MOCK_MARKET_CONFIGURATOR },
|
|
221
230
|
liquidationFees: () => MOCK_LIQUIDATION_FEES,
|
|
222
231
|
creditManager: {
|
|
223
232
|
address: args.creditManager,
|
|
@@ -404,8 +413,8 @@ function payloadOf(slice) {
|
|
|
404
413
|
exports.CA_OP_CALLS = CA_OP_CALLS;
|
|
405
414
|
exports.MOCK_CLAIM_CALL = MOCK_CLAIM_CALL;
|
|
406
415
|
exports.MOCK_CLOSE_CALL = MOCK_CLOSE_CALL;
|
|
416
|
+
exports.MOCK_CURATOR = MOCK_CURATOR;
|
|
407
417
|
exports.MOCK_LIQUIDATION_FEES = MOCK_LIQUIDATION_FEES;
|
|
408
|
-
exports.MOCK_MARKET_CONFIGURATOR = MOCK_MARKET_CONFIGURATOR;
|
|
409
418
|
exports.MOCK_REQUEST_CALL = MOCK_REQUEST_CALL;
|
|
410
419
|
exports.MOCK_ROUTER_CALL = MOCK_ROUTER_CALL;
|
|
411
420
|
exports.MOCK_RWA_UNWRAP_CALL = MOCK_RWA_UNWRAP_CALL;
|
|
@@ -11,6 +11,7 @@ const require_onchain_base_SDKConstruct = require("../../base/SDKConstruct.js");
|
|
|
11
11
|
require("../../base/index.js");
|
|
12
12
|
const require_onchain_market_math = require("../../market/math.js");
|
|
13
13
|
const require_onchain_market_credit_collateralUtils = require("../../market/credit/collateralUtils.js");
|
|
14
|
+
const require_onchain_market_credit_creditOperationMarket = require("../../market/credit/creditOperationMarket.js");
|
|
14
15
|
const require_model_liquidations = require("../../../model/liquidations.js");
|
|
15
16
|
require("../../../model/index.js");
|
|
16
17
|
const require_onchain_market_rwa_midas_constants = require("../../market/rwa/midas/constants.js");
|
|
@@ -21,6 +22,7 @@ const require_onchain_market_rwa_securitize_SecuritizeLiquidatorContract = requi
|
|
|
21
22
|
require("../../market/rwa/securitize/index.js");
|
|
22
23
|
require("../../market/index.js");
|
|
23
24
|
const require_onchain_accounts_liquidations_constants = require("./constants.js");
|
|
25
|
+
const require_onchain_accounts_liquidations_skipLiquidatableAccount = require("./skipLiquidatableAccount.js");
|
|
24
26
|
//#region src/onchain/accounts/liquidations/LiquidationsService.ts
|
|
25
27
|
/**
|
|
26
28
|
* Service for discovering liquidatable credit accounts and previewing manual
|
|
@@ -30,7 +32,6 @@ var LiquidationsService = class extends require_onchain_base_SDKConstruct.SDKCon
|
|
|
30
32
|
/**
|
|
31
33
|
* Returns all liquidatable credit accounts: accounts with health factor
|
|
32
34
|
* below 1 plus accounts of expired credit managers with outstanding debt.
|
|
33
|
-
* Accounts whose collateral computation failed are excluded.
|
|
34
35
|
**/
|
|
35
36
|
async getLiquidatableAccounts(props) {
|
|
36
37
|
const unhealthy = await this.sdk.accounts.getCreditAccounts({
|
|
@@ -41,8 +42,8 @@ var LiquidationsService = class extends require_onchain_base_SDKConstruct.SDKCon
|
|
|
41
42
|
let expired = await this.#getExpiredCreditAccounts(props?.blockNumber);
|
|
42
43
|
expired = expired.filter((ca) => !seen.has(ca.creditAccount));
|
|
43
44
|
return [...unhealthy, ...expired].flatMap((ca) => {
|
|
44
|
-
if (
|
|
45
|
-
this.logger?.warn(`
|
|
45
|
+
if (require_onchain_accounts_liquidations_skipLiquidatableAccount.skipLiquidatableAccount(ca, (token) => this.sdk.tokensMeta.get(token)?.contractType)) {
|
|
46
|
+
this.logger?.warn(`skipping liquidatable account ${ca.creditAccount}`);
|
|
46
47
|
return [];
|
|
47
48
|
}
|
|
48
49
|
return [this.#buildAccount(ca)];
|
|
@@ -254,15 +255,15 @@ var LiquidationsService = class extends require_onchain_base_SDKConstruct.SDKCon
|
|
|
254
255
|
#buildAccount(ca, suite = this.sdk.marketRegister.findCreditManager(ca.creditManager)) {
|
|
255
256
|
const market = suite.market;
|
|
256
257
|
const unwrappedUnderlying = this.sdk.tokensMeta.unwrapRWA(suite.underlying);
|
|
257
|
-
const liquidationDiscount = suite.
|
|
258
|
+
const { liquidationDiscount } = suite.liquidationFees();
|
|
258
259
|
const repaymentAmount = ca.totalValue * BigInt(liquidationDiscount) / require_onchain_constants_math.PERCENTAGE_FACTOR;
|
|
259
260
|
const estimatedProfit = ca.totalValue - repaymentAmount;
|
|
260
261
|
const token = this.sdk.tokensMeta.mustGetToken(unwrappedUnderlying);
|
|
261
262
|
const usd = (part) => ca.totalValue > 0n ? require_onchain_market_math.usdToNumber(ca.totalValueUSD * part / ca.totalValue) : 0;
|
|
262
263
|
return {
|
|
264
|
+
...require_onchain_market_credit_creditOperationMarket.creditOperationMarket(suite),
|
|
263
265
|
chainId: this.sdk.chainId,
|
|
264
266
|
creditAccount: ca.creditAccount,
|
|
265
|
-
creditManager: ca.creditManager,
|
|
266
267
|
asset: this.sdk.tokensMeta.mustGetToken(this.#mainAsset(ca, market, unwrappedUnderlying)),
|
|
267
268
|
totalValue: {
|
|
268
269
|
token,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/onchain/accounts/liquidations/skipLiquidatableAccount.ts
|
|
3
|
+
/**
|
|
4
|
+
* Whether a credit account should be dropped from the liquidatable list:
|
|
5
|
+
* collateral computation failed, or it holds a Mellow withdrawal phantom
|
|
6
|
+
* token above dust (no liquidation subcompressor for that type).
|
|
7
|
+
**/
|
|
8
|
+
function skipLiquidatableAccount(account, getContractType) {
|
|
9
|
+
return !account.success || account.tokens.some((t) => getContractType(t.token) === "PHANTOM_TOKEN::MELLOW_WITHDRAWAL");
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
exports.skipLiquidatableAccount = skipLiquidatableAccount;
|
|
@@ -16,14 +16,18 @@ function totalLiquidationDiscount(suite) {
|
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* The market half of every credit operation result, read off the suite that
|
|
19
|
-
* serves it
|
|
20
|
-
*
|
|
19
|
+
* serves it: a preview, a projection, the open-strategy walk and a
|
|
20
|
+
* liquidatable-account row all spread it, so the four fields are filled in one
|
|
21
|
+
* place and cannot drift apart between the halves of the SDK.
|
|
22
|
+
*
|
|
23
|
+
* The curator comes from the same getter {@link CreditSuite.strategyOpportunity}
|
|
24
|
+
* reads, so a result and the opportunity beside it name one entity.
|
|
21
25
|
**/
|
|
22
26
|
function creditOperationMarket(suite) {
|
|
23
27
|
return {
|
|
24
28
|
creditManager: suite.creditManager.address,
|
|
25
29
|
name: suite.name,
|
|
26
|
-
curator: suite.
|
|
30
|
+
curator: suite.market.curator,
|
|
27
31
|
liquidationDiscount: totalLiquidationDiscount(suite)
|
|
28
32
|
};
|
|
29
33
|
}
|
|
@@ -23,7 +23,7 @@ var ExecuteApi = class {
|
|
|
23
23
|
};
|
|
24
24
|
function poolTx(sdk, request) {
|
|
25
25
|
const { pool, wallet, sim } = request;
|
|
26
|
-
const { tokenIn, tokenOut } = sim.
|
|
26
|
+
const { tokenIn, tokenOut } = sim.state;
|
|
27
27
|
if (request.op === "deposit") {
|
|
28
28
|
const meta = sdk.pools.getDepositMetadata(pool, tokenIn.token.address, tokenOut.token.address);
|
|
29
29
|
const result = sdk.pools.addLiquidity({
|
|
@@ -50,16 +50,16 @@ function poolTx(sdk, request) {
|
|
|
50
50
|
}
|
|
51
51
|
async function openTx(sdk, request) {
|
|
52
52
|
const { creditManager, wallet, collateral, ethAmount, sim } = request;
|
|
53
|
-
const {
|
|
53
|
+
const { state } = sim;
|
|
54
54
|
return sdk.accounts.openCA({
|
|
55
55
|
creditManager,
|
|
56
56
|
to: wallet,
|
|
57
57
|
collateral,
|
|
58
58
|
ethAmount,
|
|
59
|
-
debt:
|
|
60
|
-
calls:
|
|
61
|
-
averageQuota:
|
|
62
|
-
minQuota:
|
|
59
|
+
debt: state.totalDebt.value,
|
|
60
|
+
calls: state.calls,
|
|
61
|
+
averageQuota: state.averageQuota,
|
|
62
|
+
minQuota: state.minQuota,
|
|
63
63
|
permits: {},
|
|
64
64
|
referralCode: 0n,
|
|
65
65
|
rwaOptions: await openRwaOptions(sdk, request)
|
|
@@ -60,7 +60,7 @@ var PrepareApi = class extends require_onchain_base_MultichainConstruct.Multicha
|
|
|
60
60
|
const tokenIn = params.tokenIn ?? marketRegister.findByPool(pool.pool).pool.underlying;
|
|
61
61
|
const tokenOut = lpRoute(params.tokenOut, () => pools.getDepositTokensOut(pool.pool, tokenIn));
|
|
62
62
|
if (!tokenOut) return unroutable(chain, tokenIn, void 0);
|
|
63
|
-
const
|
|
63
|
+
const state = pools.simulateDeposit({
|
|
64
64
|
pool: pool.pool,
|
|
65
65
|
amount: params.amount,
|
|
66
66
|
tokenIn,
|
|
@@ -68,8 +68,8 @@ var PrepareApi = class extends require_onchain_base_MultichainConstruct.Multicha
|
|
|
68
68
|
});
|
|
69
69
|
const call = pools.addLiquidity({
|
|
70
70
|
collateral: {
|
|
71
|
-
token:
|
|
72
|
-
balance:
|
|
71
|
+
token: state.tokenIn.token.address,
|
|
72
|
+
balance: state.tokenIn.value
|
|
73
73
|
},
|
|
74
74
|
pool: pool.pool,
|
|
75
75
|
wallet: params.wallet,
|
|
@@ -79,7 +79,7 @@ var PrepareApi = class extends require_onchain_base_MultichainConstruct.Multicha
|
|
|
79
79
|
return {
|
|
80
80
|
ok: true,
|
|
81
81
|
operations: [],
|
|
82
|
-
|
|
82
|
+
state,
|
|
83
83
|
calls: call.calls
|
|
84
84
|
};
|
|
85
85
|
}
|
|
@@ -92,7 +92,7 @@ var PrepareApi = class extends require_onchain_base_MultichainConstruct.Multicha
|
|
|
92
92
|
const tokenIn = params.tokenIn ?? pool.pool;
|
|
93
93
|
const tokenOut = lpRoute(params.tokenOut, () => pools.getWithdrawalTokensOut(pool.pool, tokenIn));
|
|
94
94
|
if (!tokenOut) return unroutable(chain, tokenIn, void 0);
|
|
95
|
-
const
|
|
95
|
+
const state = pools.simulateWithdraw({
|
|
96
96
|
pool: pool.pool,
|
|
97
97
|
amount: params.amount,
|
|
98
98
|
tokenIn,
|
|
@@ -109,7 +109,7 @@ var PrepareApi = class extends require_onchain_base_MultichainConstruct.Multicha
|
|
|
109
109
|
return {
|
|
110
110
|
ok: true,
|
|
111
111
|
operations: [],
|
|
112
|
-
|
|
112
|
+
state,
|
|
113
113
|
calls
|
|
114
114
|
};
|
|
115
115
|
}
|
|
@@ -122,7 +122,7 @@ var PrepareApi = class extends require_onchain_base_MultichainConstruct.Multicha
|
|
|
122
122
|
const tokenIn = params.tokenIn ?? pool.pool;
|
|
123
123
|
const tokenOut = lpRoute(params.tokenOut, () => pools.getWithdrawalTokensOut(pool.pool, tokenIn));
|
|
124
124
|
if (!tokenOut) return unroutable(chain, tokenIn, void 0);
|
|
125
|
-
const
|
|
125
|
+
const state = pools.simulateRedeem({
|
|
126
126
|
pool: pool.pool,
|
|
127
127
|
amount: params.amount,
|
|
128
128
|
tokenIn,
|
|
@@ -139,7 +139,7 @@ var PrepareApi = class extends require_onchain_base_MultichainConstruct.Multicha
|
|
|
139
139
|
return {
|
|
140
140
|
ok: true,
|
|
141
141
|
operations: [],
|
|
142
|
-
|
|
142
|
+
state,
|
|
143
143
|
calls
|
|
144
144
|
};
|
|
145
145
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { iCreditFacadeV310Abi } from "../abi/310/generated.js";
|
|
2
1
|
import { ierc20Abi } from "../abi/iERC20.js";
|
|
2
|
+
import { iCreditFacadeV310Abi } from "../abi/310/generated.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";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { iWithdrawalCompressorV313Abi } from "../abi/IWithdrawalCompressorV313.js";
|
|
1
2
|
import { getNetworkType } from "../onchain/chain/chains.js";
|
|
2
3
|
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,6 @@
|
|
|
1
1
|
import { ZodAddress } from "../onchain/utils/zod.js";
|
|
2
|
-
import { assetTypeSchema, chainIdSchema, timestampSchema, tokenAmountSchema, tokenSchema, txCallSchema } from "./primitives.schema.js";
|
|
2
|
+
import { assetTypeSchema, bpsSchema, chainIdSchema, timestampSchema, tokenAmountSchema, tokenSchema, txCallSchema } from "./primitives.schema.js";
|
|
3
|
+
import { curatorSchema } from "./curators.schema.js";
|
|
3
4
|
import { filterable } from "./filters.schema.js";
|
|
4
5
|
import { z } from "zod/v4";
|
|
5
6
|
//#region src/model/liquidations.schema.ts
|
|
@@ -21,9 +22,12 @@ const liquidatableAccountFilterSchema = z.object({
|
|
|
21
22
|
* {@link LiquidatableAccount}
|
|
22
23
|
**/
|
|
23
24
|
const liquidatableAccountSchema = z.object({
|
|
25
|
+
creditManager: ZodAddress(),
|
|
26
|
+
name: z.string(),
|
|
27
|
+
curator: curatorSchema,
|
|
28
|
+
liquidationDiscount: bpsSchema,
|
|
24
29
|
chainId: chainIdSchema,
|
|
25
30
|
creditAccount: ZodAddress(),
|
|
26
|
-
creditManager: ZodAddress(),
|
|
27
31
|
asset: tokenSchema,
|
|
28
32
|
totalValue: tokenAmountSchema,
|
|
29
33
|
repaymentAmount: tokenAmountSchema,
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { iBaseRewardPoolAbi } from "../../abi/iBaseRewardPool.js";
|
|
2
|
+
import { ierc4626AdapterAbi } from "../../abi/ierc4626Adapter.js";
|
|
1
3
|
import { AP_REWARDS_COMPRESSOR } from "../constants/address-provider.js";
|
|
2
4
|
import { ADDRESS_0X0 } from "../constants/addresses.js";
|
|
3
5
|
import { MAX_UINT256 } from "../constants/math.js";
|
|
@@ -8,8 +10,6 @@ import "../base/index.js";
|
|
|
8
10
|
import { AccountBotsService } from "./bots/AccountBotsService.js";
|
|
9
11
|
import "./bots/index.js";
|
|
10
12
|
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";
|
|
@@ -7,7 +7,7 @@ import { calcLeverageBand } from "./leverage-band.js";
|
|
|
7
7
|
import { maxProportionalWithdrawal } from "./math.js";
|
|
8
8
|
import { maxWithdrawCollateral } from "./maxWithdrawCollateral.js";
|
|
9
9
|
import { fetchCreditAccountSlice, toCreditAccountSlice } from "./utils/credit-account-slice.js";
|
|
10
|
-
import {
|
|
10
|
+
import { buildOpenStrategyState } from "./open-strategy.js";
|
|
11
11
|
import { planAddCollateral, planAdjustLeverage, planAdjustLeverageDelayed, planDeposit, planRepay, planWithdraw, planWithdrawAsset, planWithdrawDelayed } from "./plan.js";
|
|
12
12
|
import { realize } from "./realize.js";
|
|
13
13
|
import { accountView } from "./view.js";
|
|
@@ -169,7 +169,7 @@ var CreditAccountOperationsService = class extends SDKConstruct {
|
|
|
169
169
|
});
|
|
170
170
|
return {
|
|
171
171
|
...result,
|
|
172
|
-
|
|
172
|
+
state: tail.state,
|
|
173
173
|
delayed
|
|
174
174
|
};
|
|
175
175
|
} catch (e) {
|
|
@@ -257,7 +257,7 @@ var CreditAccountOperationsService = class extends SDKConstruct {
|
|
|
257
257
|
try {
|
|
258
258
|
return {
|
|
259
259
|
ok: true,
|
|
260
|
-
|
|
260
|
+
state: await buildOpenStrategyState(props)
|
|
261
261
|
};
|
|
262
262
|
} catch (e) {
|
|
263
263
|
return asFailure(e);
|
|
@@ -276,7 +276,7 @@ var CreditAccountOperationsService = class extends SDKConstruct {
|
|
|
276
276
|
return {
|
|
277
277
|
ok: true,
|
|
278
278
|
operations,
|
|
279
|
-
|
|
279
|
+
state,
|
|
280
280
|
calls,
|
|
281
281
|
delayed
|
|
282
282
|
};
|
|
@@ -288,11 +288,11 @@ var CreditAccountOperationsService = class extends SDKConstruct {
|
|
|
288
288
|
/** Drops the delayed half for the flows that cannot produce one. */
|
|
289
289
|
function plain(result) {
|
|
290
290
|
if (!result.ok) return result;
|
|
291
|
-
const { operations,
|
|
291
|
+
const { operations, state, calls } = result;
|
|
292
292
|
return {
|
|
293
293
|
ok: true,
|
|
294
294
|
operations,
|
|
295
|
-
|
|
295
|
+
state,
|
|
296
296
|
calls
|
|
297
297
|
};
|
|
298
298
|
}
|
|
@@ -9,7 +9,8 @@ import "./utils/index.js";
|
|
|
9
9
|
/** Stand-in account address: nothing exists on chain until the tx lands. */
|
|
10
10
|
const NO_ACCOUNT = "0x0000000000000000000000000000000000000000";
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Builds the state opening a leveraged position out of wallet collateral would
|
|
13
|
+
* land in.
|
|
13
14
|
*
|
|
14
15
|
* Debt follows from the target leverage against the supplied margin
|
|
15
16
|
* (`debt = margin * (L - 1)`, `totalValue = margin * L`); the collateral and the
|
|
@@ -19,7 +20,7 @@ const NO_ACCOUNT = "0x0000000000000000000000000000000000000000";
|
|
|
19
20
|
* no operation list — the caller passes the numbers and calls straight to
|
|
20
21
|
* `sdk.accounts.openCA`.
|
|
21
22
|
*/
|
|
22
|
-
async function
|
|
23
|
+
async function buildOpenStrategyState(props) {
|
|
23
24
|
const { sdk, creditManager, collateral, targetToken, leverage, slippage = 0, quotaReserve, leftoverBalances = [] } = props;
|
|
24
25
|
assertLeverageAtLeastOne(leverage);
|
|
25
26
|
const suite = sdk.marketRegister.findCreditManager(creditManager);
|
|
@@ -129,4 +130,4 @@ function toAssets(balances) {
|
|
|
129
130
|
}));
|
|
130
131
|
}
|
|
131
132
|
//#endregion
|
|
132
|
-
export {
|
|
133
|
+
export { buildOpenStrategyState };
|
|
@@ -13,8 +13,16 @@ import { vi } from "vitest";
|
|
|
13
13
|
* from their inputs, so `result.calls` pins down which ops reached the
|
|
14
14
|
* assembler and in which order.
|
|
15
15
|
*/
|
|
16
|
-
/**
|
|
17
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Curator of the mock market: an unknown market configurator, so it carries no
|
|
18
|
+
* display name and no page — what the on-chain source answers for a
|
|
19
|
+
* configurator outside the curated table.
|
|
20
|
+
*/
|
|
21
|
+
const MOCK_CURATOR = {
|
|
22
|
+
address: "0x00000000000000000000000000000000000c0f16",
|
|
23
|
+
name: void 0,
|
|
24
|
+
url: null
|
|
25
|
+
};
|
|
18
26
|
/**
|
|
19
27
|
* Liquidation fees of the mock suite: a 3% premium (the manager reports its
|
|
20
28
|
* complement) on top of a 1.5% protocol fee, so the discount a screen shows is
|
|
@@ -166,6 +174,8 @@ function buildMockSdk(args) {
|
|
|
166
174
|
};
|
|
167
175
|
const market = {
|
|
168
176
|
toUnderlyingAmount,
|
|
177
|
+
/** {@inheritDoc MarketSuite.curator} */
|
|
178
|
+
curator: MOCK_CURATOR,
|
|
169
179
|
/** {@inheritDoc MarketSuite.underlying} */
|
|
170
180
|
underlying: args.underlying,
|
|
171
181
|
priceOracle: {
|
|
@@ -217,7 +227,6 @@ function buildMockSdk(args) {
|
|
|
217
227
|
const expirationDate = args.expirationDate ?? 0;
|
|
218
228
|
const creditManagerSuite = {
|
|
219
229
|
name: "TestCreditManager",
|
|
220
|
-
marketConfigurator: { address: MOCK_MARKET_CONFIGURATOR },
|
|
221
230
|
liquidationFees: () => MOCK_LIQUIDATION_FEES,
|
|
222
231
|
creditManager: {
|
|
223
232
|
address: args.creditManager,
|
|
@@ -401,4 +410,4 @@ function payloadOf(slice) {
|
|
|
401
410
|
};
|
|
402
411
|
}
|
|
403
412
|
//#endregion
|
|
404
|
-
export { CA_OP_CALLS, MOCK_CLAIM_CALL, MOCK_CLOSE_CALL,
|
|
413
|
+
export { CA_OP_CALLS, MOCK_CLAIM_CALL, MOCK_CLOSE_CALL, MOCK_CURATOR, MOCK_LIQUIDATION_FEES, MOCK_REQUEST_CALL, MOCK_ROUTER_CALL, MOCK_RWA_UNWRAP_CALL, MOCK_RWA_WRAP_CALL, buildMockSdk };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { iLiquidationCompressorV313Abi } from "../../../abi/ILiquidationCompressorV313.js";
|
|
1
2
|
import { AddressSet } from "../../utils/AddressSet.js";
|
|
2
3
|
import { bytes32ToString } from "../../utils/bytes32ToString.js";
|
|
3
4
|
import { ADDRESS_0X0 } from "../../constants/addresses.js";
|
|
@@ -9,6 +10,7 @@ import { SDKConstruct } from "../../base/SDKConstruct.js";
|
|
|
9
10
|
import "../../base/index.js";
|
|
10
11
|
import { usdToNumber } from "../../market/math.js";
|
|
11
12
|
import { dominantCollateral } from "../../market/credit/collateralUtils.js";
|
|
13
|
+
import { creditOperationMarket } from "../../market/credit/creditOperationMarket.js";
|
|
12
14
|
import { matchesLiquidatableAccountFilter } from "../../../model/liquidations.js";
|
|
13
15
|
import "../../../model/index.js";
|
|
14
16
|
import { RWA_LIQUIDATOR_MIDAS } from "../../market/rwa/midas/constants.js";
|
|
@@ -19,7 +21,7 @@ import { SecuritizeLiquidatorContract } from "../../market/rwa/securitize/Securi
|
|
|
19
21
|
import "../../market/rwa/securitize/index.js";
|
|
20
22
|
import "../../market/index.js";
|
|
21
23
|
import { LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS } from "./constants.js";
|
|
22
|
-
import {
|
|
24
|
+
import { skipLiquidatableAccount } from "./skipLiquidatableAccount.js";
|
|
23
25
|
//#region src/onchain/accounts/liquidations/LiquidationsService.ts
|
|
24
26
|
/**
|
|
25
27
|
* Service for discovering liquidatable credit accounts and previewing manual
|
|
@@ -29,7 +31,6 @@ var LiquidationsService = class extends SDKConstruct {
|
|
|
29
31
|
/**
|
|
30
32
|
* Returns all liquidatable credit accounts: accounts with health factor
|
|
31
33
|
* below 1 plus accounts of expired credit managers with outstanding debt.
|
|
32
|
-
* Accounts whose collateral computation failed are excluded.
|
|
33
34
|
**/
|
|
34
35
|
async getLiquidatableAccounts(props) {
|
|
35
36
|
const unhealthy = await this.sdk.accounts.getCreditAccounts({
|
|
@@ -40,8 +41,8 @@ var LiquidationsService = class extends SDKConstruct {
|
|
|
40
41
|
let expired = await this.#getExpiredCreditAccounts(props?.blockNumber);
|
|
41
42
|
expired = expired.filter((ca) => !seen.has(ca.creditAccount));
|
|
42
43
|
return [...unhealthy, ...expired].flatMap((ca) => {
|
|
43
|
-
if (
|
|
44
|
-
this.logger?.warn(`
|
|
44
|
+
if (skipLiquidatableAccount(ca, (token) => this.sdk.tokensMeta.get(token)?.contractType)) {
|
|
45
|
+
this.logger?.warn(`skipping liquidatable account ${ca.creditAccount}`);
|
|
45
46
|
return [];
|
|
46
47
|
}
|
|
47
48
|
return [this.#buildAccount(ca)];
|
|
@@ -253,15 +254,15 @@ var LiquidationsService = class extends SDKConstruct {
|
|
|
253
254
|
#buildAccount(ca, suite = this.sdk.marketRegister.findCreditManager(ca.creditManager)) {
|
|
254
255
|
const market = suite.market;
|
|
255
256
|
const unwrappedUnderlying = this.sdk.tokensMeta.unwrapRWA(suite.underlying);
|
|
256
|
-
const liquidationDiscount = suite.
|
|
257
|
+
const { liquidationDiscount } = suite.liquidationFees();
|
|
257
258
|
const repaymentAmount = ca.totalValue * BigInt(liquidationDiscount) / PERCENTAGE_FACTOR;
|
|
258
259
|
const estimatedProfit = ca.totalValue - repaymentAmount;
|
|
259
260
|
const token = this.sdk.tokensMeta.mustGetToken(unwrappedUnderlying);
|
|
260
261
|
const usd = (part) => ca.totalValue > 0n ? usdToNumber(ca.totalValueUSD * part / ca.totalValue) : 0;
|
|
261
262
|
return {
|
|
263
|
+
...creditOperationMarket(suite),
|
|
262
264
|
chainId: this.sdk.chainId,
|
|
263
265
|
creditAccount: ca.creditAccount,
|
|
264
|
-
creditManager: ca.creditManager,
|
|
265
266
|
asset: this.sdk.tokensMeta.mustGetToken(this.#mainAsset(ca, market, unwrappedUnderlying)),
|
|
266
267
|
totalValue: {
|
|
267
268
|
token,
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/onchain/accounts/liquidations/skipLiquidatableAccount.ts
|
|
2
|
+
/**
|
|
3
|
+
* Whether a credit account should be dropped from the liquidatable list:
|
|
4
|
+
* collateral computation failed, or it holds a Mellow withdrawal phantom
|
|
5
|
+
* token above dust (no liquidation subcompressor for that type).
|
|
6
|
+
**/
|
|
7
|
+
function skipLiquidatableAccount(account, getContractType) {
|
|
8
|
+
return !account.success || account.tokens.some((t) => getContractType(t.token) === "PHANTOM_TOKEN::MELLOW_WITHDRAWAL");
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { skipLiquidatableAccount };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { iRedemptionLoggerV310Abi } from "../../../abi/iRedemptionLoggerV310.js";
|
|
1
2
|
import { BaseContract } from "../../base/BaseContract.js";
|
|
2
3
|
import "../../base/index.js";
|
|
3
4
|
import { decodeDelayedIntent } from "./intent-codec.js";
|
|
4
|
-
import { iRedemptionLoggerV310Abi } from "../../../abi/iRedemptionLoggerV310.js";
|
|
5
5
|
import { InvalidDelayedIntentError } from "./errors.js";
|
|
6
6
|
//#region src/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.ts
|
|
7
7
|
const abi = iRedemptionLoggerV310Abi;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
|
|
2
1
|
import { iWithdrawalCompressorV310Abi } from "../../../abi/IWithdrawalCompressorV310.js";
|
|
2
|
+
import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
|
|
3
3
|
//#region src/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.ts
|
|
4
4
|
const abi = iWithdrawalCompressorV310Abi;
|
|
5
5
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
|
|
2
1
|
import { iWithdrawalCompressorV311Abi } from "../../../abi/IWithdrawalCompressorV311.js";
|
|
2
|
+
import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.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";
|
|
1
2
|
import { encodeDelayedIntent } from "./intent-codec.js";
|
|
2
3
|
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;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { iExpirableAbi } from "../../abi/iExpirable.js";
|
|
2
|
+
import { iStateSerializerAbi } from "../../abi/iStateSerializer.js";
|
|
3
|
+
import { iVersionAbi } from "../../abi/iVersion.js";
|
|
1
4
|
import { AddressMap } from "../utils/AddressMap.js";
|
|
2
5
|
import { AddressSet } from "../utils/AddressSet.js";
|
|
3
6
|
import { bytes32ToString } from "../utils/bytes32ToString.js";
|
|
4
7
|
import { getAssetType } from "../chain/chains.js";
|
|
5
8
|
import { formatBN } from "../utils/formatter.js";
|
|
6
9
|
import "../utils/index.js";
|
|
7
|
-
import { iExpirableAbi } from "../../abi/iExpirable.js";
|
|
8
|
-
import { iStateSerializerAbi } from "../../abi/iStateSerializer.js";
|
|
9
|
-
import { iVersionAbi } from "../../abi/iVersion.js";
|
|
10
10
|
import { SdkRWADataNotLoadedError } from "../core/errors.js";
|
|
11
11
|
import { executeMulticallBatches } from "../utils/viem/executeMulticallBatches.js";
|
|
12
12
|
//#region src/onchain/base/TokensMeta.ts
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { iVersionAbi } from "../../abi/iVersion.js";
|
|
1
2
|
import { AP_MARKET_COMPRESSOR, AP_PRICE_FEED_COMPRESSOR } from "../constants/address-provider.js";
|
|
2
3
|
import { isV310 } from "../constants/versions.js";
|
|
3
4
|
import "../constants/index.js";
|
|
4
5
|
import { hexEq } from "../utils/hex.js";
|
|
5
|
-
import { iVersionAbi } from "../../abi/iVersion.js";
|
|
6
6
|
import { AddressProviderV310Contract } from "./AddressProviderV310Contract.js";
|
|
7
7
|
//#region src/onchain/core/createAddressProvider.ts
|
|
8
8
|
const OVERRIDE_ADDRESSES = { Mainnet: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AbstractAdapterContract } from "./AbstractAdapter.js";
|
|
2
1
|
import { accountMigratorAbi } from "../../../../abi/AccountMigrator.js";
|
|
2
|
+
import { AbstractAdapterContract } from "./AbstractAdapter.js";
|
|
3
3
|
//#region src/onchain/market/adapters/contracts/AccountMigratorAdapterContract.ts
|
|
4
4
|
const abi = accountMigratorAbi;
|
|
5
5
|
const protocolAbi = accountMigratorAbi;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { ierc4626AdapterAbi } from "../../../../abi/ierc4626Adapter.js";
|
|
1
2
|
import { MissingSerializedParamsError } from "../../../base/errors.js";
|
|
2
3
|
import "../../../base/index.js";
|
|
3
|
-
import { ierc4626AdapterAbi } from "../../../../abi/ierc4626Adapter.js";
|
|
4
4
|
import { iERC4626Abi } from "../abi/targetContractAbi.js";
|
|
5
5
|
import { fnSigToName, swapFromTransfers } from "../transferHelpers.js";
|
|
6
6
|
import { AbstractAdapterContract } from "./AbstractAdapter.js";
|