@gearbox-protocol/sdk 14.12.0-next.65 → 14.12.0-next.67
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/common-utils/index.js +2 -2
- package/dist/cjs/common-utils/utils/apy/calculate-safe-borrow-rate.js +3 -3
- package/dist/cjs/common-utils/utils/assets-math.js +7 -7
- package/dist/cjs/common-utils/utils/creditAccount/calc-health-factor.js +2 -2
- package/dist/cjs/common-utils/utils/creditAccount/debt.js +2 -2
- package/dist/cjs/common-utils/utils/creditAccount/quota-utils.js +5 -5
- package/dist/cjs/common-utils/utils/index.js +2 -2
- package/dist/cjs/common-utils/utils/strategies/leverage/calculate-max-leverage-factor.js +2 -2
- package/dist/cjs/common-utils/utils/strategies/leverage/calculate-max-strategy-debt.js +5 -5
- package/dist/cjs/common-utils/utils/strategies/strategy-info/calculate-total-points.js +2 -2
- package/dist/cjs/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.js +2 -2
- package/dist/cjs/common-utils/utils/validation/validate-open-account-pool-status.js +4 -4
- package/dist/cjs/dev/index.js +2 -1
- package/dist/cjs/dev/kycUtils.js +1 -1
- package/dist/cjs/dev/midasUtils.js +104 -0
- package/dist/cjs/model/history.js +28 -0
- package/dist/cjs/model/history.schema.js +84 -0
- package/dist/cjs/model/index.js +64 -0
- package/dist/cjs/model/liquidations.js +23 -0
- package/dist/cjs/model/liquidations.schema.js +91 -0
- package/dist/cjs/model/opportunities.js +55 -0
- package/dist/cjs/model/opportunities.schema.js +220 -0
- package/dist/cjs/model/package.json +1 -0
- package/dist/cjs/model/positions.js +1 -0
- package/dist/cjs/model/primitives.js +1 -0
- package/dist/cjs/model/primitives.schema.js +85 -0
- package/dist/cjs/new-sdk/AbstractNamespace.js +158 -0
- package/dist/cjs/new-sdk/GearboxSDK.js +122 -0
- package/dist/cjs/new-sdk/index.js +11 -0
- package/dist/cjs/new-sdk/opportunities/OpportunitiesNamespace.js +122 -0
- package/dist/cjs/new-sdk/opportunities/index.js +4 -0
- package/dist/cjs/new-sdk/opportunities/types.js +1 -0
- package/dist/cjs/new-sdk/package.json +1 -0
- package/dist/cjs/new-sdk/types.js +22 -0
- package/dist/cjs/new-sdk/utils/history.js +1 -0
- package/dist/cjs/new-sdk/utils/index.js +2 -0
- package/dist/cjs/offchain/GearboxAPI.js +33 -0
- package/dist/cjs/offchain/index.js +8 -0
- package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +97 -0
- package/dist/cjs/offchain/opportunities/index.js +4 -0
- package/dist/cjs/offchain/package.json +1 -0
- package/dist/cjs/offchain/types.js +1 -0
- package/dist/cjs/preview/preview/buildDelayedPreview.js +5 -5
- package/dist/cjs/rewards/rewards/api.js +2 -2
- package/dist/cjs/rewards/rewards/extra-apy.js +2 -2
- package/dist/cjs/sdk/MultichainSDK.js +18 -2
- package/dist/cjs/sdk/OnchainSDK.js +8 -1
- package/dist/cjs/sdk/accounts/index.js +2 -0
- package/dist/cjs/sdk/accounts/liquidations/LiquidationsService.js +150 -106
- package/dist/cjs/sdk/accounts/liquidations/MultichainLiquidationsService.js +32 -38
- package/dist/cjs/sdk/accounts/liquidations/constants.js +13 -0
- package/dist/cjs/sdk/accounts/liquidations/index.js +2 -0
- package/dist/cjs/sdk/base/MultichainConstruct.js +80 -0
- package/dist/cjs/sdk/base/TokensMeta.js +51 -0
- package/dist/cjs/sdk/base/index.js +2 -0
- package/dist/cjs/sdk/chain/chains.js +76 -0
- package/dist/cjs/sdk/chain/index.js +4 -0
- package/dist/cjs/sdk/core/errors.js +13 -0
- package/dist/cjs/sdk/core/index.js +2 -1
- package/dist/cjs/sdk/index.js +25 -1
- package/dist/cjs/sdk/market/MarketConfiguratorContract.js +14 -0
- package/dist/cjs/sdk/market/MarketSuite.js +163 -0
- package/dist/cjs/sdk/market/credit/CreditManagerV310Contract.js +26 -0
- package/dist/cjs/sdk/market/credit/CreditSuite.js +102 -0
- package/dist/cjs/sdk/market/math.js +104 -0
- package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +52 -0
- package/dist/cjs/sdk/market/pool/LinearInterestRateModelContract.js +30 -0
- package/dist/cjs/sdk/market/pool/PoolQuotaKeeperV310Contract.js +26 -0
- package/dist/cjs/sdk/market/pool/PoolSuite.js +28 -0
- package/dist/cjs/sdk/market/pool/PoolV310Contract.js +27 -0
- package/dist/cjs/sdk/market/pool/math.js +44 -0
- package/dist/cjs/sdk/market/pricefeeds/AbstractPriceFeed.js +17 -0
- package/dist/cjs/sdk/opportunities/MultichainOpportunitiesService.js +60 -0
- package/dist/cjs/sdk/opportunities/OpportunitiesService.js +103 -0
- package/dist/cjs/sdk/opportunities/index.js +12 -0
- package/dist/cjs/sdk/types/multichain.js +1 -0
- package/dist/cjs/{common-utils → sdk}/utils/bigint-math.js +11 -11
- package/dist/cjs/sdk/utils/index.js +3 -0
- package/dist/cjs/sdk/utils/zod.js +12 -0
- package/dist/esm/common-utils/index.js +1 -1
- package/dist/esm/common-utils/utils/apy/calculate-safe-borrow-rate.js +1 -1
- package/dist/esm/common-utils/utils/assets-math.js +1 -1
- package/dist/esm/common-utils/utils/creditAccount/calc-health-factor.js +1 -1
- package/dist/esm/common-utils/utils/creditAccount/debt.js +1 -1
- package/dist/esm/common-utils/utils/creditAccount/quota-utils.js +1 -1
- package/dist/esm/common-utils/utils/index.js +1 -1
- package/dist/esm/common-utils/utils/strategies/leverage/calculate-max-leverage-factor.js +1 -1
- package/dist/esm/common-utils/utils/strategies/leverage/calculate-max-strategy-debt.js +1 -1
- package/dist/esm/common-utils/utils/strategies/strategy-info/calculate-total-points.js +1 -1
- package/dist/esm/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.js +1 -1
- package/dist/esm/common-utils/utils/validation/validate-open-account-pool-status.js +1 -1
- package/dist/esm/dev/AccountOpener.js +1 -1
- package/dist/esm/dev/index.js +3 -3
- package/dist/esm/dev/kycUtils.js +1 -1
- package/dist/esm/dev/midasUtils.js +105 -2
- package/dist/esm/dev/withdrawalUtils.js +1 -1
- package/dist/esm/model/history.js +26 -0
- package/dist/esm/model/history.schema.js +76 -0
- package/dist/esm/model/index.js +9 -0
- package/dist/esm/model/liquidations.js +22 -0
- package/dist/esm/model/liquidations.schema.js +83 -0
- package/dist/esm/model/opportunities.js +51 -0
- package/dist/esm/model/opportunities.schema.js +198 -0
- package/dist/esm/model/package.json +1 -0
- package/dist/esm/model/positions.js +1 -0
- package/dist/esm/model/primitives.js +1 -0
- package/dist/esm/model/primitives.schema.js +75 -0
- package/dist/esm/new-sdk/AbstractNamespace.js +157 -0
- package/dist/esm/new-sdk/GearboxSDK.js +121 -0
- package/dist/esm/new-sdk/index.js +7 -0
- package/dist/esm/new-sdk/opportunities/OpportunitiesNamespace.js +121 -0
- package/dist/esm/new-sdk/opportunities/index.js +3 -0
- package/dist/esm/new-sdk/opportunities/types.js +1 -0
- package/dist/esm/new-sdk/package.json +1 -0
- package/dist/esm/new-sdk/types.js +21 -0
- package/dist/esm/new-sdk/utils/history.js +1 -0
- package/dist/esm/new-sdk/utils/index.js +2 -0
- package/dist/esm/offchain/GearboxAPI.js +32 -0
- package/dist/esm/offchain/index.js +5 -0
- package/dist/esm/offchain/opportunities/OffchainOpportunities.js +95 -0
- package/dist/esm/offchain/opportunities/index.js +2 -0
- package/dist/esm/offchain/package.json +1 -0
- package/dist/esm/offchain/types.js +1 -0
- package/dist/esm/preview/preview/buildDelayedPreview.js +1 -1
- package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
- package/dist/esm/preview/trace/extractTransfers.js +1 -1
- package/dist/esm/rewards/rewards/api.js +1 -1
- package/dist/esm/rewards/rewards/extra-apy.js +1 -1
- package/dist/esm/sdk/MultichainSDK.js +18 -2
- package/dist/esm/sdk/OnchainSDK.js +8 -1
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +2 -2
- package/dist/esm/sdk/accounts/index.js +2 -2
- package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +153 -109
- package/dist/esm/sdk/accounts/liquidations/MultichainLiquidationsService.js +32 -38
- package/dist/esm/sdk/accounts/liquidations/constants.js +12 -1
- package/dist/esm/sdk/accounts/liquidations/index.js +2 -2
- package/dist/esm/sdk/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
- package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
- package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
- package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
- package/dist/esm/sdk/base/MultichainConstruct.js +79 -0
- package/dist/esm/sdk/base/TokensMeta.js +53 -2
- package/dist/esm/sdk/base/index.js +2 -1
- package/dist/esm/sdk/chain/chains.js +74 -2
- package/dist/esm/sdk/chain/detectNetwork.js +1 -1
- package/dist/esm/sdk/chain/index.js +2 -2
- package/dist/esm/sdk/core/createAddressProvider.js +1 -1
- package/dist/esm/sdk/core/errors.js +13 -1
- package/dist/esm/sdk/core/index.js +2 -2
- package/dist/esm/sdk/index.js +11 -5
- package/dist/esm/sdk/market/MarketConfiguratorContract.js +14 -0
- package/dist/esm/sdk/market/MarketSuite.js +163 -0
- package/dist/esm/sdk/market/credit/CreditFacadeV310BaseContract.js +1 -1
- package/dist/esm/sdk/market/credit/CreditManagerV310Contract.js +26 -0
- package/dist/esm/sdk/market/credit/CreditSuite.js +102 -0
- package/dist/esm/sdk/market/math.js +98 -0
- package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +52 -0
- package/dist/esm/sdk/market/pool/LinearInterestRateModelContract.js +30 -0
- package/dist/esm/sdk/market/pool/PoolQuotaKeeperV310Contract.js +26 -0
- package/dist/esm/sdk/market/pool/PoolSuite.js +28 -0
- package/dist/esm/sdk/market/pool/PoolV310Contract.js +28 -1
- package/dist/esm/sdk/market/pool/math.js +41 -0
- package/dist/esm/sdk/market/pricefeeds/AbstractPriceFeed.js +17 -0
- package/dist/esm/sdk/market/zapper/IETHZapperContract.js +1 -1
- package/dist/esm/sdk/market/zapper/ZapperContract.js +1 -1
- package/dist/esm/sdk/opportunities/MultichainOpportunitiesService.js +59 -0
- package/dist/esm/sdk/opportunities/OpportunitiesService.js +102 -0
- package/dist/esm/sdk/opportunities/index.js +4 -0
- package/dist/esm/sdk/pools/PoolService.js +1 -1
- package/dist/esm/sdk/types/multichain.js +1 -0
- package/dist/esm/{common-utils → sdk}/utils/bigint-math.js +11 -11
- package/dist/esm/sdk/utils/index.js +3 -2
- package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +1 -1
- package/dist/esm/sdk/utils/zod.js +13 -2
- package/dist/types/common-utils/index.d.ts +1 -1
- package/dist/types/common-utils/utils/index.d.ts +1 -1
- package/dist/types/dev/index.d.ts +2 -2
- package/dist/types/dev/midasUtils.d.ts +31 -2
- package/dist/types/model/history.d.ts +105 -0
- package/dist/types/model/history.schema.d.ts +66 -0
- package/dist/types/model/index.d.ts +9 -0
- package/dist/types/model/liquidations.d.ts +230 -0
- package/dist/types/model/liquidations.schema.d.ts +292 -0
- package/dist/types/model/opportunities.d.ts +543 -0
- package/dist/types/model/opportunities.schema.d.ts +1066 -0
- package/dist/types/model/positions.d.ts +11 -0
- package/dist/types/model/primitives.d.ts +193 -0
- package/dist/types/model/primitives.schema.d.ts +81 -0
- package/dist/types/new-sdk/AbstractNamespace.d.ts +119 -0
- package/dist/types/new-sdk/GearboxSDK.d.ts +78 -0
- package/dist/types/new-sdk/index.d.ts +9 -0
- package/dist/types/new-sdk/opportunities/OpportunitiesNamespace.d.ts +69 -0
- package/dist/types/new-sdk/opportunities/index.d.ts +3 -0
- package/dist/types/new-sdk/opportunities/types.d.ts +66 -0
- package/dist/types/new-sdk/types.d.ts +149 -0
- package/dist/types/new-sdk/utils/history.d.ts +44 -0
- package/dist/types/new-sdk/utils/index.d.ts +2 -0
- package/dist/types/offchain/GearboxAPI.d.ts +31 -0
- package/dist/types/offchain/index.d.ts +5 -0
- package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +69 -0
- package/dist/types/offchain/opportunities/index.d.ts +2 -0
- package/dist/types/offchain/types.d.ts +50 -0
- package/dist/types/sdk/MultichainSDK.d.ts +15 -2
- package/dist/types/sdk/OnchainSDK.d.ts +9 -3
- package/dist/types/sdk/accounts/index.d.ts +3 -3
- package/dist/types/sdk/accounts/liquidations/LiquidationsService.d.ts +24 -16
- package/dist/types/sdk/accounts/liquidations/MultichainLiquidationsService.d.ts +26 -20
- package/dist/types/sdk/accounts/liquidations/constants.d.ts +12 -1
- package/dist/types/sdk/accounts/liquidations/index.d.ts +3 -3
- package/dist/types/sdk/accounts/liquidations/types.d.ts +34 -309
- package/dist/types/sdk/base/MultichainConstruct.d.ts +57 -0
- package/dist/types/sdk/base/TokensMeta.d.ts +26 -0
- package/dist/types/sdk/base/index.d.ts +2 -1
- package/dist/types/sdk/chain/chains.d.ts +68 -1
- package/dist/types/sdk/chain/index.d.ts +2 -2
- package/dist/types/sdk/core/errors.d.ts +10 -1
- package/dist/types/sdk/core/index.d.ts +2 -2
- package/dist/types/sdk/index.d.ts +15 -8
- package/dist/types/sdk/market/MarketConfiguratorContract.d.ts +9 -0
- package/dist/types/sdk/market/MarketSuite.d.ts +109 -1
- package/dist/types/sdk/market/credit/CreditManagerV310Contract.d.ts +14 -0
- package/dist/types/sdk/market/credit/CreditSuite.d.ts +47 -0
- package/dist/types/sdk/market/credit/types.d.ts +22 -0
- package/dist/types/sdk/market/index.d.ts +2 -2
- package/dist/types/sdk/market/math.d.ts +74 -0
- package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +23 -0
- package/dist/types/sdk/market/oracle/types.d.ts +46 -0
- package/dist/types/sdk/market/pool/LinearInterestRateModelContract.d.ts +12 -0
- package/dist/types/sdk/market/pool/PoolQuotaKeeperV310Contract.d.ts +22 -1
- package/dist/types/sdk/market/pool/PoolSuite.d.ts +23 -0
- package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +18 -0
- package/dist/types/sdk/market/pool/math.d.ts +57 -0
- package/dist/types/sdk/market/pool/types.d.ts +23 -0
- package/dist/types/sdk/market/pricefeeds/AbstractPriceFeed.d.ts +6 -0
- package/dist/types/sdk/market/pricefeeds/types.d.ts +10 -0
- package/dist/types/sdk/opportunities/MultichainOpportunitiesService.d.ts +40 -0
- package/dist/types/sdk/opportunities/OpportunitiesService.d.ts +47 -0
- package/dist/types/sdk/opportunities/index.d.ts +4 -0
- package/dist/types/sdk/types/index.d.ts +2 -1
- package/dist/types/sdk/types/multichain.d.ts +65 -0
- package/dist/types/sdk/types/state.d.ts +1 -1
- package/dist/types/sdk/types/transactions.d.ts +3 -0
- package/dist/types/{common-utils → sdk}/utils/bigint-math.d.ts +7 -11
- package/dist/types/sdk/utils/index.d.ts +3 -2
- package/dist/types/sdk/utils/zod.d.ts +6 -2
- package/package.json +16 -1
- package/dist/cjs/sdk/accounts/liquidations/helpers.js +0 -201
- package/dist/esm/sdk/accounts/liquidations/helpers.js +0 -192
- package/dist/types/sdk/accounts/liquidations/helpers.d.ts +0 -140
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_runtime = require("../../_virtual/_rolldown/runtime.js");
|
|
3
|
+
const require_sdk_utils_bigint_math = require("../../sdk/utils/bigint-math.js");
|
|
3
4
|
const require_sdk_chain_chains = require("../../sdk/chain/chains.js");
|
|
4
5
|
const require_sdk_constants_math = require("../../sdk/constants/math.js");
|
|
5
6
|
const require_sdk_utils_formatter = require("../../sdk/utils/formatter.js");
|
|
6
7
|
require("../../sdk/index.js");
|
|
7
|
-
const require_common_utils_utils_bigint_math = require("../../common-utils/utils/bigint-math.js");
|
|
8
8
|
require("../../common-utils/index.js");
|
|
9
9
|
let axios = require("axios");
|
|
10
10
|
axios = require_runtime.__toESM(axios);
|
|
@@ -64,7 +64,7 @@ var PoolPointsAPI = class PoolPointsAPI {
|
|
|
64
64
|
const { decimals: underlyingDecimals = 18 } = tokensList.get(pool.pool.pool.underlying) || {};
|
|
65
65
|
const underlyingFactor = 10n ** BigInt(underlyingDecimals);
|
|
66
66
|
const points = (tokenBalanceInPool?.balance || 0n) * defaultPoints / (pool.pool.pool.expectedLiquidity * targetFactor / underlyingFactor);
|
|
67
|
-
return
|
|
67
|
+
return require_sdk_utils_bigint_math.BigIntMath.min(points, defaultPoints);
|
|
68
68
|
}
|
|
69
69
|
};
|
|
70
70
|
//#endregion
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_sdk_chain_chains = require("./chain/chains.js");
|
|
3
|
+
const require_sdk_core_errors = require("./core/errors.js");
|
|
3
4
|
const require_sdk_market_pricefeeds_updates_PriceUpdatesCache = require("./market/pricefeeds/updates/PriceUpdatesCache.js");
|
|
4
5
|
require("./market/pricefeeds/updates/index.js");
|
|
5
6
|
const require_sdk_accounts_liquidations_MultichainLiquidationsService = require("./accounts/liquidations/MultichainLiquidationsService.js");
|
|
6
7
|
require("./accounts/index.js");
|
|
7
|
-
const require_sdk_core_errors = require("./core/errors.js");
|
|
8
8
|
require("./core/index.js");
|
|
9
|
+
const require_sdk_opportunities_MultichainOpportunitiesService = require("./opportunities/MultichainOpportunitiesService.js");
|
|
10
|
+
require("./opportunities/index.js");
|
|
9
11
|
const require_sdk_OnchainSDK = require("./OnchainSDK.js");
|
|
10
12
|
//#region src/sdk/MultichainSDK.ts
|
|
11
13
|
/**
|
|
@@ -23,6 +25,11 @@ var MultichainSDK = class {
|
|
|
23
25
|
* configured chains.
|
|
24
26
|
*/
|
|
25
27
|
liquidations;
|
|
28
|
+
/**
|
|
29
|
+
* Namespace for the pool and strategy opportunities of all configured
|
|
30
|
+
* chains.
|
|
31
|
+
*/
|
|
32
|
+
opportunities;
|
|
26
33
|
constructor(options) {
|
|
27
34
|
this.#chains = /* @__PURE__ */ new Map();
|
|
28
35
|
this.#logger = options.logger;
|
|
@@ -40,6 +47,7 @@ var MultichainSDK = class {
|
|
|
40
47
|
this.#chains.set(network, sdk);
|
|
41
48
|
}
|
|
42
49
|
this.liquidations = new require_sdk_accounts_liquidations_MultichainLiquidationsService.MultichainLiquidationsService(this);
|
|
50
|
+
this.opportunities = new require_sdk_opportunities_MultichainOpportunitiesService.MultichainOpportunitiesService(this);
|
|
43
51
|
}
|
|
44
52
|
/**
|
|
45
53
|
* Attach all configured chains in parallel.
|
|
@@ -128,7 +136,7 @@ var MultichainSDK = class {
|
|
|
128
136
|
if (typeof networkOrChainId === "number") network = require_sdk_chain_chains.getNetworkType(networkOrChainId);
|
|
129
137
|
else network = networkOrChainId;
|
|
130
138
|
const sdk = this.#chains.get(network);
|
|
131
|
-
if (!sdk) throw new
|
|
139
|
+
if (!sdk) throw new require_sdk_core_errors.ChainNotConfiguredError(networkOrChainId);
|
|
132
140
|
return sdk;
|
|
133
141
|
}
|
|
134
142
|
/**
|
|
@@ -138,6 +146,14 @@ var MultichainSDK = class {
|
|
|
138
146
|
return this.#chains;
|
|
139
147
|
}
|
|
140
148
|
/**
|
|
149
|
+
* Shared logger, used for messages that are not attributable to a single
|
|
150
|
+
* chain. Per-chain messages should use the logger of the corresponding
|
|
151
|
+
* {@link OnchainSDK}.
|
|
152
|
+
**/
|
|
153
|
+
get logger() {
|
|
154
|
+
return this.#logger;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
141
157
|
* Sync state for all chains in parallel.
|
|
142
158
|
*
|
|
143
159
|
* @param opts - Sync options.
|
|
@@ -9,6 +9,7 @@ const require_sdk_utils_formatter = require("./utils/formatter.js");
|
|
|
9
9
|
const require_sdk_utils_toAddress = require("./utils/toAddress.js");
|
|
10
10
|
require("./utils/index.js");
|
|
11
11
|
const require_sdk_base_ChainContractsRegister = require("./base/ChainContractsRegister.js");
|
|
12
|
+
const require_sdk_core_errors = require("./core/errors.js");
|
|
12
13
|
require("./base/index.js");
|
|
13
14
|
const require_sdk_utils_viem_executeDelegatedMulticalls = require("./utils/viem/executeDelegatedMulticalls.js");
|
|
14
15
|
require("./utils/viem/index.js");
|
|
@@ -23,8 +24,9 @@ const require_sdk_accounts_withdrawal_compressor_createRedemptionLogger = requir
|
|
|
23
24
|
const require_sdk_accounts_withdrawal_compressor_createWithdrawalCompressor = require("./accounts/withdrawal-compressor/createWithdrawalCompressor.js");
|
|
24
25
|
require("./accounts/index.js");
|
|
25
26
|
const require_sdk_core_createAddressProvider = require("./core/createAddressProvider.js");
|
|
26
|
-
const require_sdk_core_errors = require("./core/errors.js");
|
|
27
27
|
require("./core/index.js");
|
|
28
|
+
const require_sdk_opportunities_OpportunitiesService = require("./opportunities/OpportunitiesService.js");
|
|
29
|
+
require("./opportunities/index.js");
|
|
28
30
|
const require_sdk_plugins_errors = require("./plugins/errors.js");
|
|
29
31
|
require("./plugins/index.js");
|
|
30
32
|
const require_sdk_pools_PoolService = require("./pools/PoolService.js");
|
|
@@ -107,6 +109,10 @@ var OnchainSDK = class extends require_sdk_base_ChainContractsRegister.ChainCont
|
|
|
107
109
|
*/
|
|
108
110
|
liquidations;
|
|
109
111
|
/**
|
|
112
|
+
* Namespace for the pool and strategy opportunities of this chain.
|
|
113
|
+
*/
|
|
114
|
+
opportunities;
|
|
115
|
+
/**
|
|
110
116
|
* @param network - Gearbox network type (e.g. `"Mainnet"`, `"Monad"`).
|
|
111
117
|
* @param clientOptions - Connection options (RPC URLs, transport, or client).
|
|
112
118
|
* @param options - SDK configuration options.
|
|
@@ -127,6 +133,7 @@ var OnchainSDK = class extends require_sdk_base_ChainContractsRegister.ChainCont
|
|
|
127
133
|
this.accounts = new require_sdk_accounts_CreditAccountsServiceV310.CreditAccountsServiceV310(this);
|
|
128
134
|
this.pools = new require_sdk_pools_PoolService.PoolService(this);
|
|
129
135
|
this.liquidations = new require_sdk_accounts_liquidations_LiquidationsService.LiquidationsService(this);
|
|
136
|
+
this.opportunities = new require_sdk_opportunities_OpportunitiesService.OpportunitiesService(this);
|
|
130
137
|
this.#withdrawalCompressor = require_sdk_accounts_withdrawal_compressor_createWithdrawalCompressor.createWithdrawalCompressor(this);
|
|
131
138
|
}
|
|
132
139
|
/**
|
|
@@ -21,7 +21,9 @@ exports.AbstractWithdrawalCompressorContract = require_sdk_accounts_withdrawal_c
|
|
|
21
21
|
exports.CreditAccountsServiceV310 = require_sdk_accounts_CreditAccountsServiceV310.CreditAccountsServiceV310;
|
|
22
22
|
exports.DELAYED_INTENT_TYPES = require_sdk_accounts_withdrawal_compressor_intent_codec.DELAYED_INTENT_TYPES;
|
|
23
23
|
exports.DELAYED_INTENT_VERSION = require_sdk_accounts_withdrawal_compressor_intent_codec.DELAYED_INTENT_VERSION;
|
|
24
|
+
exports.DUST_THRESHOLD = require_sdk_accounts_liquidations_constants.DUST_THRESHOLD;
|
|
24
25
|
exports.InvalidDelayedIntentError = require_sdk_accounts_withdrawal_compressor_errors.InvalidDelayedIntentError;
|
|
26
|
+
exports.LIQUIDATION_APPROVAL_BUFFER = require_sdk_accounts_liquidations_constants.LIQUIDATION_APPROVAL_BUFFER;
|
|
25
27
|
exports.LIQUIDATION_COMPRESSOR_V313_ADDRESS = require_sdk_accounts_liquidations_constants.LIQUIDATION_COMPRESSOR_V313_ADDRESS;
|
|
26
28
|
exports.LiquidationsService = require_sdk_accounts_liquidations_LiquidationsService.LiquidationsService;
|
|
27
29
|
exports.MultichainLiquidationsService = require_sdk_accounts_liquidations_MultichainLiquidationsService.MultichainLiquidationsService;
|
|
@@ -9,6 +9,9 @@ const require_sdk_utils_hex = require("../../utils/hex.js");
|
|
|
9
9
|
require("../../utils/index.js");
|
|
10
10
|
const require_sdk_base_SDKConstruct = require("../../base/SDKConstruct.js");
|
|
11
11
|
require("../../base/index.js");
|
|
12
|
+
const require_sdk_market_math = require("../../market/math.js");
|
|
13
|
+
const require_model_liquidations = require("../../../model/liquidations.js");
|
|
14
|
+
require("../../../model/index.js");
|
|
12
15
|
const require_sdk_market_rwa_midas_constants = require("../../market/rwa/midas/constants.js");
|
|
13
16
|
const require_sdk_market_rwa_midas_MidasLiquidatorContract = require("../../market/rwa/midas/MidasLiquidatorContract.js");
|
|
14
17
|
require("../../market/rwa/midas/index.js");
|
|
@@ -16,95 +19,104 @@ const require_sdk_market_rwa_securitize_constants = require("../../market/rwa/se
|
|
|
16
19
|
const require_sdk_market_rwa_securitize_SecuritizeLiquidatorContract = require("../../market/rwa/securitize/SecuritizeLiquidatorContract.js");
|
|
17
20
|
require("../../market/rwa/securitize/index.js");
|
|
18
21
|
const require_sdk_accounts_liquidations_constants = require("./constants.js");
|
|
19
|
-
const require_sdk_accounts_liquidations_helpers = require("./helpers.js");
|
|
20
22
|
//#region src/sdk/accounts/liquidations/LiquidationsService.ts
|
|
21
23
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* Discovers liquidatable credit accounts (health factor below 1 plus accounts
|
|
25
|
-
* of expired credit managers with outstanding debt) and previews what a
|
|
26
|
-
* manual liquidation pays and receives.
|
|
24
|
+
* Service for discovering liquidatable credit accounts and previewing manual
|
|
25
|
+
* liquidations.
|
|
27
26
|
**/
|
|
28
27
|
var LiquidationsService = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
29
28
|
/**
|
|
30
|
-
*
|
|
29
|
+
* Returns all liquidatable credit accounts: accounts with health factor
|
|
30
|
+
* below 1 plus accounts of expired credit managers with outstanding debt.
|
|
31
|
+
* Accounts whose collateral computation failed are excluded.
|
|
31
32
|
**/
|
|
32
33
|
async getLiquidatableAccounts(props) {
|
|
33
34
|
await this.sdk.withdrawalCompressor?.loadWithdrawableAssets();
|
|
34
|
-
const
|
|
35
|
+
const unhealthy = await this.sdk.accounts.getCreditAccounts({
|
|
35
36
|
maxHealthFactor: require_sdk_constants_math.WAD - 1n,
|
|
36
37
|
includeZeroDebt: false
|
|
37
38
|
});
|
|
38
|
-
const seen = new require_sdk_utils_AddressSet.AddressSet(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
const allowedAssets = props?.assets?.length ? new require_sdk_utils_AddressSet.AddressSet(props.assets) : void 0;
|
|
49
|
-
return rows.filter((row) => {
|
|
50
|
-
if (props?.delayed !== void 0 && row.isDelayed !== props.delayed) return false;
|
|
51
|
-
if (allowedAssets && !allowedAssets.has(row.asset)) return false;
|
|
52
|
-
return true;
|
|
53
|
-
});
|
|
39
|
+
const seen = new require_sdk_utils_AddressSet.AddressSet(unhealthy.map((ca) => ca.creditAccount));
|
|
40
|
+
let expired = await this.#getExpiredCreditAccounts();
|
|
41
|
+
expired = expired.filter((ca) => !seen.has(ca.creditAccount));
|
|
42
|
+
return [...unhealthy, ...expired].flatMap((ca) => {
|
|
43
|
+
if (!ca.success) {
|
|
44
|
+
this.logger?.warn(`cannot compute liquidation details for ${ca.creditAccount}: collateral computation failed`);
|
|
45
|
+
return [];
|
|
46
|
+
}
|
|
47
|
+
return [this.#buildAccount(ca)];
|
|
48
|
+
}).filter((row) => require_model_liquidations.matchesLiquidatableAccountFilter(row, props));
|
|
54
49
|
}
|
|
55
50
|
/**
|
|
56
|
-
*
|
|
51
|
+
* Returns detailed information about a liquidatable credit account,
|
|
52
|
+
* including the full list of assets the liquidator receives.
|
|
53
|
+
*
|
|
54
|
+
* @throws When the account is not found or its collateral computation fails.
|
|
57
55
|
**/
|
|
58
56
|
async getLiquidationDetails(props) {
|
|
59
57
|
const { creditAccount, liquidator, ignoreReservePrices } = props;
|
|
60
58
|
const ca = await this.#getCreditAccountData(creditAccount);
|
|
59
|
+
const suite = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
60
|
+
const { priceOracle } = suite.market;
|
|
61
61
|
await this.sdk.withdrawalCompressor?.loadWithdrawableAssets();
|
|
62
|
-
const account = this.#buildAccount(ca);
|
|
62
|
+
const account = this.#buildAccount(ca, suite);
|
|
63
63
|
const data = await this.#getLiquidationData(ca, liquidator, ignoreReservePrices);
|
|
64
|
-
const suite = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
65
64
|
return {
|
|
66
65
|
...account,
|
|
67
|
-
repaymentAmount:
|
|
68
|
-
token: require_sdk_utils_hex.hexEq(data.requiredToken, "0x0000000000000000000000000000000000000000") ? account.totalValue.token : data.requiredToken,
|
|
69
|
-
balance: data.requiredAmount
|
|
70
|
-
},
|
|
66
|
+
repaymentAmount: priceOracle.toTokenAmount(require_sdk_utils_hex.hexEq(data.requiredToken, "0x0000000000000000000000000000000000000000") ? account.totalValue.token.address : data.requiredToken, data.requiredAmount),
|
|
71
67
|
isDelayed: data.expectedOutputs.some((o) => o.delayed),
|
|
72
|
-
receivedAssets:
|
|
68
|
+
receivedAssets: this.#receivedAssets(data.expectedOutputs, priceOracle),
|
|
73
69
|
isLiquidatorEligible: data.isLiquidatorEligible,
|
|
74
70
|
isCreditAccountFrozen: data.isCreditAccountFrozen,
|
|
75
71
|
kycProtocol: data.kycProtocol || void 0,
|
|
76
|
-
kycToken: require_sdk_utils_hex.hexEq(data.kycToken, "0x0000000000000000000000000000000000000000") ? void 0 : data.kycToken,
|
|
77
|
-
approve:
|
|
78
|
-
target: data.liquidationCall.target,
|
|
79
|
-
creditFacade: suite.creditFacade.address,
|
|
80
|
-
creditManager: ca.creditManager,
|
|
81
|
-
token: data.requiredToken,
|
|
82
|
-
amount: data.requiredAmount
|
|
83
|
-
})
|
|
72
|
+
kycToken: require_sdk_utils_hex.hexEq(data.kycToken, "0x0000000000000000000000000000000000000000") ? void 0 : this.sdk.tokensMeta.getToken(data.kycToken),
|
|
73
|
+
approve: this.#liquidationApproval(data, suite, priceOracle)
|
|
84
74
|
};
|
|
85
75
|
}
|
|
86
76
|
/**
|
|
87
|
-
*
|
|
77
|
+
* Builds the transaction that fully liquidates a credit account, repaying
|
|
78
|
+
* the debt from own funds and receiving the collateral from the credit account.
|
|
88
79
|
**/
|
|
89
80
|
async buildLiquidationTx(props) {
|
|
90
81
|
const { creditAccount, liquidator, ignoreReservePrices } = props;
|
|
91
82
|
const ca = await this.#getCreditAccountData(creditAccount);
|
|
92
|
-
const
|
|
93
|
-
|
|
83
|
+
const { liquidationCall } = await this.#getLiquidationData(ca, liquidator, ignoreReservePrices);
|
|
84
|
+
this.logger?.debug(`built tx to liquidate credit account ${this.labelAddress(creditAccount)} to ${this.labelAddress(liquidator)}`);
|
|
85
|
+
return {
|
|
86
|
+
to: liquidationCall.target,
|
|
87
|
+
callData: liquidationCall.callData
|
|
88
|
+
};
|
|
94
89
|
}
|
|
95
90
|
/**
|
|
96
|
-
*
|
|
91
|
+
* Returns the status of delayed-withdrawal positions (redemption receipts)
|
|
92
|
+
* owned by a liquidator wallet: what is receivable, how much, and when it
|
|
93
|
+
* becomes claimable.
|
|
97
94
|
**/
|
|
98
|
-
async
|
|
95
|
+
async getLiquidationPositions(props) {
|
|
99
96
|
const compressor = this.sdk.withdrawalCompressor;
|
|
100
97
|
if (!compressor) return [];
|
|
101
98
|
await compressor.loadWithdrawableAssets();
|
|
102
99
|
const phantomTokens = new require_sdk_utils_AddressSet.AddressSet(compressor.getWithdrawableAssets().map((a) => a.withdrawalPhantomToken));
|
|
103
|
-
const
|
|
104
|
-
|
|
100
|
+
const { claimable, pending } = await compressor.getExternalAccountCurrentWithdrawals(props.liquidator, ...phantomTokens.asArray());
|
|
101
|
+
const chainId = this.sdk.chainId;
|
|
102
|
+
return [...claimable.map((w) => ({
|
|
103
|
+
chainId,
|
|
104
|
+
sourceToken: this.sdk.tokensMeta.mustGetToken(w.token),
|
|
105
|
+
output: this.#withdrawalOutput(w.outputs, w.token),
|
|
106
|
+
claimTx: this.#claimTx(w.claimCalls, w.token),
|
|
107
|
+
redeemer: w.redeemer
|
|
108
|
+
})), ...pending.map((w) => ({
|
|
109
|
+
chainId,
|
|
110
|
+
sourceToken: this.sdk.tokensMeta.mustGetToken(w.token),
|
|
111
|
+
output: this.#withdrawalOutput(w.expectedOutputs, w.token),
|
|
112
|
+
claimableAt: Number(w.claimableAt),
|
|
113
|
+
redeemer: w.redeemer
|
|
114
|
+
}))];
|
|
105
115
|
}
|
|
106
116
|
/**
|
|
107
|
-
*
|
|
117
|
+
* Discovers the dedicated RWA liquidator contracts (Securitize, Midas)
|
|
118
|
+
* deployed for the markets of the chain and registers them in the SDK
|
|
119
|
+
* contracts register.
|
|
108
120
|
**/
|
|
109
121
|
async loadRWALiquidators() {
|
|
110
122
|
const configurators = this.sdk.marketRegister.marketConfigurators;
|
|
@@ -121,14 +133,6 @@ var LiquidationsService = class extends require_sdk_base_SDKConstruct.SDKConstru
|
|
|
121
133
|
});
|
|
122
134
|
for (const info of resp.flat()) this.#createRWALiquidator(info);
|
|
123
135
|
}
|
|
124
|
-
/**
|
|
125
|
-
* Instantiates the liquidator contract, which registers it and labels its
|
|
126
|
-
* address (see `BaseContract`).
|
|
127
|
-
*
|
|
128
|
-
* @param info - Liquidator discovered by the compressor. The same gateway
|
|
129
|
-
* can be configured in several credit managers, so duplicates are expected
|
|
130
|
-
* and skipped.
|
|
131
|
-
**/
|
|
132
136
|
#createRWALiquidator(info) {
|
|
133
137
|
const liquidator = info.liquidatorAddress;
|
|
134
138
|
if (this.sdk.getContract(liquidator)) return;
|
|
@@ -143,20 +147,64 @@ var LiquidationsService = class extends require_sdk_base_SDKConstruct.SDKConstru
|
|
|
143
147
|
return;
|
|
144
148
|
}
|
|
145
149
|
}
|
|
150
|
+
#anyMarketTokenAmount(token, value) {
|
|
151
|
+
const meta = this.sdk.tokensMeta.mustGetToken(token);
|
|
152
|
+
for (const market of this.sdk.marketRegister.markets) {
|
|
153
|
+
const valueUsd = market.priceOracle.safeUsdValue(token, value);
|
|
154
|
+
if (valueUsd !== null) return {
|
|
155
|
+
token: meta,
|
|
156
|
+
value,
|
|
157
|
+
valueUsd
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
return {
|
|
161
|
+
token: meta,
|
|
162
|
+
value,
|
|
163
|
+
valueUsd: null
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
#withdrawalOutput(outputs, sourceToken) {
|
|
167
|
+
const [output] = outputs;
|
|
168
|
+
if (outputs.length !== 1 || !output) throw new Error(`expected exactly one output for withdrawal of ${sourceToken}, got ${outputs.length}`);
|
|
169
|
+
return this.#anyMarketTokenAmount(output.token, output.amount);
|
|
170
|
+
}
|
|
171
|
+
#claimTx(claimCalls, sourceToken) {
|
|
172
|
+
if (claimCalls.length > 1) throw new Error(`expected at most one claim call for withdrawal of ${sourceToken}, got ${claimCalls.length}`);
|
|
173
|
+
const [call] = claimCalls;
|
|
174
|
+
return call ? {
|
|
175
|
+
to: call.target,
|
|
176
|
+
callData: call.callData
|
|
177
|
+
} : void 0;
|
|
178
|
+
}
|
|
179
|
+
#receivedAssets(outputs, priceOracle) {
|
|
180
|
+
return outputs.map((o) => {
|
|
181
|
+
const amount = priceOracle.toTokenAmount(o.token, o.amount);
|
|
182
|
+
if (!o.delayed) return {
|
|
183
|
+
isDelayed: false,
|
|
184
|
+
...amount
|
|
185
|
+
};
|
|
186
|
+
return {
|
|
187
|
+
isDelayed: true,
|
|
188
|
+
...amount,
|
|
189
|
+
redeemerAddress: require_sdk_utils_hex.hexEq(o.redeemerAddress, "0x0000000000000000000000000000000000000000") ? void 0 : o.redeemerAddress,
|
|
190
|
+
claimableAt: o.claimableAt === 0n ? void 0 : Number(o.claimableAt)
|
|
191
|
+
};
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
#liquidationApproval(data, suite, priceOracle) {
|
|
195
|
+
const { requiredToken, requiredAmount, liquidationCall } = data;
|
|
196
|
+
if (requiredAmount === 0n) return;
|
|
197
|
+
return {
|
|
198
|
+
spender: require_sdk_utils_hex.hexEq(liquidationCall.target, suite.creditFacade.address) ? suite.creditManager.address : liquidationCall.target,
|
|
199
|
+
...priceOracle.toTokenAmount(requiredToken, requiredAmount * (require_sdk_constants_math.PERCENTAGE_FACTOR + require_sdk_accounts_liquidations_constants.LIQUIDATION_APPROVAL_BUFFER) / require_sdk_constants_math.PERCENTAGE_FACTOR)
|
|
200
|
+
};
|
|
201
|
+
}
|
|
146
202
|
async #getCreditAccountData(creditAccount) {
|
|
147
203
|
const ca = await this.sdk.accounts.getCreditAccountData(creditAccount);
|
|
148
204
|
if (!ca) throw new Error(`credit account ${creditAccount} not found`);
|
|
149
205
|
if (!ca.success) throw new Error(`cannot compute liquidation details for ${creditAccount}: collateral computation failed`);
|
|
150
206
|
return ca;
|
|
151
207
|
}
|
|
152
|
-
/**
|
|
153
|
-
* Previews the liquidation via the liquidation compressor.
|
|
154
|
-
*
|
|
155
|
-
* @param ca - Credit account to liquidate
|
|
156
|
-
* @param liquidator - Liquidator wallet, zero address when not known: it only
|
|
157
|
-
* affects the KYC eligibility fields and the receiver encoded into the calls
|
|
158
|
-
* @param ignoreReservePrices - Exclude reserve price feeds from the updates
|
|
159
|
-
**/
|
|
160
208
|
async #getLiquidationData(ca, liquidator = require_sdk_constants_addresses.ADDRESS_0X0, ignoreReservePrices) {
|
|
161
209
|
const priceUpdates = await this.sdk.accounts.getOnDemandPriceUpdates(ca, ignoreReservePrices);
|
|
162
210
|
const { result } = await this.client.simulateContract({
|
|
@@ -171,10 +219,6 @@ var LiquidationsService = class extends require_sdk_base_SDKConstruct.SDKConstru
|
|
|
171
219
|
});
|
|
172
220
|
return result;
|
|
173
221
|
}
|
|
174
|
-
/**
|
|
175
|
-
* Accounts of expired credit managers with outstanding debt are liquidatable
|
|
176
|
-
* regardless of their health factor.
|
|
177
|
-
**/
|
|
178
222
|
async #getExpiredCreditAccounts() {
|
|
179
223
|
const expiredCMs = [];
|
|
180
224
|
for (const market of this.sdk.marketRegister.markets) {
|
|
@@ -186,58 +230,58 @@ var LiquidationsService = class extends require_sdk_base_SDKConstruct.SDKConstru
|
|
|
186
230
|
}
|
|
187
231
|
if (expiredCMs.length === 0) return [];
|
|
188
232
|
this.logger?.debug(`getting credit accounts of ${expiredCMs.length} expired credit managers`);
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
includeZeroDebt: false
|
|
194
|
-
});
|
|
195
|
-
result.push(...accounts);
|
|
196
|
-
}
|
|
197
|
-
return result;
|
|
233
|
+
return (await Promise.all(expiredCMs.map((creditManager) => this.sdk.accounts.getCreditAccounts({
|
|
234
|
+
creditManager,
|
|
235
|
+
includeZeroDebt: false
|
|
236
|
+
})))).flat();
|
|
198
237
|
}
|
|
199
|
-
|
|
200
|
-
* Requires the compressor's withdrawable assets cache to be loaded
|
|
201
|
-
* (see `loadWithdrawableAssets`) so that phantom token lookups are sync.
|
|
202
|
-
**/
|
|
203
|
-
#buildAccount(ca) {
|
|
204
|
-
const compressor = this.sdk.withdrawalCompressor;
|
|
205
|
-
const suite = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
238
|
+
#buildAccount(ca, suite = this.sdk.marketRegister.findCreditManager(ca.creditManager)) {
|
|
206
239
|
const market = suite.market;
|
|
207
|
-
const
|
|
208
|
-
const unwrappedUnderlying = meta && this.sdk.tokensMeta.isRWAUnderlying(meta) ? meta.asset : suite.underlying;
|
|
240
|
+
const unwrappedUnderlying = this.sdk.tokensMeta.unwrapRWA(suite.underlying);
|
|
209
241
|
const liquidationDiscount = suite.isExpired ? suite.creditManager.liquidationDiscountExpired : suite.creditManager.liquidationDiscount;
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
return 0n;
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
if (asset) asset = compressor?.getWithdrawalSourceToken(asset) ?? asset;
|
|
218
|
-
else asset = unwrappedUnderlying;
|
|
242
|
+
const repaymentAmount = ca.totalValue * BigInt(liquidationDiscount) / require_sdk_constants_math.PERCENTAGE_FACTOR;
|
|
243
|
+
const estimatedProfit = ca.totalValue - repaymentAmount;
|
|
244
|
+
const token = this.sdk.tokensMeta.mustGetToken(unwrappedUnderlying);
|
|
245
|
+
const usd = (part) => ca.totalValue > 0n ? require_sdk_market_math.usdToNumber(ca.totalValueUSD * part / ca.totalValue) : 0;
|
|
219
246
|
return {
|
|
247
|
+
chainId: this.sdk.chainId,
|
|
220
248
|
creditAccount: ca.creditAccount,
|
|
221
249
|
creditManager: ca.creditManager,
|
|
222
|
-
|
|
223
|
-
asset,
|
|
250
|
+
asset: this.sdk.tokensMeta.mustGetToken(this.#mainAsset(ca, market, unwrappedUnderlying)),
|
|
224
251
|
totalValue: {
|
|
225
|
-
token
|
|
226
|
-
|
|
252
|
+
token,
|
|
253
|
+
value: ca.totalValue,
|
|
254
|
+
valueUsd: require_sdk_market_math.usdToNumber(ca.totalValueUSD)
|
|
227
255
|
},
|
|
228
|
-
totalValueUSD: ca.totalValueUSD,
|
|
229
256
|
repaymentAmount: {
|
|
230
|
-
token
|
|
231
|
-
|
|
257
|
+
token,
|
|
258
|
+
value: repaymentAmount,
|
|
259
|
+
valueUsd: usd(repaymentAmount)
|
|
232
260
|
},
|
|
233
261
|
estimatedProfit: {
|
|
234
|
-
token
|
|
235
|
-
|
|
262
|
+
token,
|
|
263
|
+
value: estimatedProfit,
|
|
264
|
+
valueUsd: usd(estimatedProfit)
|
|
236
265
|
},
|
|
237
|
-
isDelayed: ca.tokens.some((t) => t.balance > 10n && !!
|
|
238
|
-
paused: suite.creditFacade.isPaused
|
|
266
|
+
isDelayed: ca.tokens.some((t) => t.balance > 10n && !!this.sdk.withdrawalCompressor?.getWithdrawalSourceToken(t.token)),
|
|
267
|
+
paused: suite.creditFacade.isPaused,
|
|
268
|
+
rwa: market.rwa
|
|
239
269
|
};
|
|
240
270
|
}
|
|
271
|
+
#mainAsset(ca, market, fallback) {
|
|
272
|
+
let bestValue = 0;
|
|
273
|
+
let asset;
|
|
274
|
+
for (const t of ca.tokens) {
|
|
275
|
+
if (require_sdk_utils_hex.hexEq(t.token, ca.underlying) || (t.mask & ca.enabledTokensMask) === 0n || t.balance <= 10n) continue;
|
|
276
|
+
const value = market.priceOracle.safeUsdValue(t.token, t.balance) ?? 0;
|
|
277
|
+
if (value > bestValue) {
|
|
278
|
+
bestValue = value;
|
|
279
|
+
asset = t.token;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
if (!asset) return fallback;
|
|
283
|
+
return this.sdk.withdrawalCompressor?.getWithdrawalSourceToken(asset) ?? asset;
|
|
284
|
+
}
|
|
241
285
|
};
|
|
242
286
|
//#endregion
|
|
243
287
|
exports.LiquidationsService = LiquidationsService;
|
|
@@ -1,66 +1,60 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sdk_base_MultichainConstruct = require("../../base/MultichainConstruct.js");
|
|
3
|
+
require("../../base/index.js");
|
|
2
4
|
//#region src/sdk/accounts/liquidations/MultichainLiquidationsService.ts
|
|
3
5
|
/**
|
|
4
|
-
* Cross-chain
|
|
6
|
+
* Cross-chain counterpart of {@link LiquidationsService}.
|
|
5
7
|
*
|
|
6
|
-
*
|
|
7
|
-
* {@link
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* Fans out over all chains configured in {@link MultichainSDK} (optionally
|
|
9
|
+
* restricted via {@link MultichainNetworksProps.networks}). A failed chain is
|
|
10
|
+
* logged as a warning and skipped, so one dead RPC does not empty the whole
|
|
11
|
+
* list; its failure is reported in {@link MultichainResult.meta}. Networks that
|
|
12
|
+
* are not configured in the SDK are reported there the same way.
|
|
10
13
|
**/
|
|
11
|
-
var MultichainLiquidationsService = class {
|
|
12
|
-
#sdk;
|
|
13
|
-
constructor(sdk) {
|
|
14
|
-
this.#sdk = sdk;
|
|
15
|
-
}
|
|
14
|
+
var MultichainLiquidationsService = class extends require_sdk_base_MultichainConstruct.MultichainConstruct {
|
|
16
15
|
/**
|
|
17
|
-
*
|
|
16
|
+
* Accounts of all queried chains, see
|
|
17
|
+
* {@link LiquidationsService.getLiquidatableAccounts}.
|
|
18
18
|
**/
|
|
19
19
|
async getLiquidatableAccounts(props) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const [network, chainSdk] = chains[i];
|
|
25
|
-
if (result.status === "fulfilled") accounts.push(...result.value);
|
|
26
|
-
else chainSdk.logger?.warn(result.reason, `failed to get liquidatable accounts on ${network}`);
|
|
20
|
+
return this.queryChains({
|
|
21
|
+
networks: props?.networks,
|
|
22
|
+
label: "get liquidatable accounts",
|
|
23
|
+
run: (sdk) => sdk.liquidations.getLiquidatableAccounts(props)
|
|
27
24
|
});
|
|
28
|
-
return accounts;
|
|
29
25
|
}
|
|
30
26
|
/**
|
|
31
|
-
* {@inheritDoc
|
|
27
|
+
* {@inheritDoc LiquidationsService.getLiquidationDetails}
|
|
32
28
|
**/
|
|
33
29
|
async getLiquidationDetails(props) {
|
|
34
|
-
return this
|
|
30
|
+
return this.sdk.chain(props.network).liquidations.getLiquidationDetails(props);
|
|
35
31
|
}
|
|
36
32
|
/**
|
|
37
|
-
* {@inheritDoc
|
|
33
|
+
* {@inheritDoc LiquidationsService.buildLiquidationTx}
|
|
38
34
|
**/
|
|
39
35
|
async buildLiquidationTx(props) {
|
|
40
|
-
return this
|
|
36
|
+
return this.sdk.chain(props.network).liquidations.buildLiquidationTx(props);
|
|
41
37
|
}
|
|
42
38
|
/**
|
|
43
|
-
*
|
|
39
|
+
* Liquidation positions of all queried chains, see
|
|
40
|
+
* {@link LiquidationsService.getLiquidationPositions}.
|
|
44
41
|
**/
|
|
45
|
-
async
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const [network, chainSdk] = chains[i];
|
|
51
|
-
if (result.status === "fulfilled") withdrawals.push(...result.value);
|
|
52
|
-
else chainSdk.logger?.warn(result.reason, `failed to get liquidator withdrawals on ${network}`);
|
|
42
|
+
async getLiquidationPositions(props) {
|
|
43
|
+
return this.queryChains({
|
|
44
|
+
networks: props.networks,
|
|
45
|
+
label: "get liquidation positions",
|
|
46
|
+
run: (sdk) => sdk.liquidations.getLiquidationPositions(props)
|
|
53
47
|
});
|
|
54
|
-
return withdrawals;
|
|
55
48
|
}
|
|
56
49
|
/**
|
|
57
|
-
*
|
|
50
|
+
* Loads the liquidators of all queried chains, see
|
|
51
|
+
* {@link LiquidationsService.loadRWALiquidators}.
|
|
58
52
|
**/
|
|
59
53
|
async loadRWALiquidators(props) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
54
|
+
return this.runChains({
|
|
55
|
+
networks: props?.networks,
|
|
56
|
+
label: "load RWA liquidators",
|
|
57
|
+
run: (sdk) => sdk.liquidations.loadRWALiquidators()
|
|
64
58
|
});
|
|
65
59
|
}
|
|
66
60
|
};
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
//#region src/sdk/accounts/liquidations/constants.ts
|
|
3
3
|
const LIQUIDATION_COMPRESSOR_V313_ADDRESS = "0xB70C4500a0afF02107eB983a348F22492fB6dC94";
|
|
4
|
+
/**
|
|
5
|
+
* Token balances at or below this threshold are treated as dust and ignored,
|
|
6
|
+
* consistent with the rest of the SDK (see `filterDust`).
|
|
7
|
+
**/
|
|
8
|
+
const DUST_THRESHOLD = 10n;
|
|
9
|
+
/**
|
|
10
|
+
* Headroom (in bps) added on top of the amount the liquidation pulls when
|
|
11
|
+
* building the liquidator's approval, so that the transaction does not revert
|
|
12
|
+
* when prices move between the preview and the execution.
|
|
13
|
+
**/
|
|
14
|
+
const LIQUIDATION_APPROVAL_BUFFER = 50n;
|
|
4
15
|
//#endregion
|
|
16
|
+
exports.DUST_THRESHOLD = DUST_THRESHOLD;
|
|
17
|
+
exports.LIQUIDATION_APPROVAL_BUFFER = LIQUIDATION_APPROVAL_BUFFER;
|
|
5
18
|
exports.LIQUIDATION_COMPRESSOR_V313_ADDRESS = LIQUIDATION_COMPRESSOR_V313_ADDRESS;
|
|
@@ -3,6 +3,8 @@ const require_sdk_accounts_liquidations_constants = require("./constants.js");
|
|
|
3
3
|
const require_sdk_accounts_liquidations_LiquidationsService = require("./LiquidationsService.js");
|
|
4
4
|
const require_sdk_accounts_liquidations_MultichainLiquidationsService = require("./MultichainLiquidationsService.js");
|
|
5
5
|
require("./types.js");
|
|
6
|
+
exports.DUST_THRESHOLD = require_sdk_accounts_liquidations_constants.DUST_THRESHOLD;
|
|
7
|
+
exports.LIQUIDATION_APPROVAL_BUFFER = require_sdk_accounts_liquidations_constants.LIQUIDATION_APPROVAL_BUFFER;
|
|
6
8
|
exports.LIQUIDATION_COMPRESSOR_V313_ADDRESS = require_sdk_accounts_liquidations_constants.LIQUIDATION_COMPRESSOR_V313_ADDRESS;
|
|
7
9
|
exports.LiquidationsService = require_sdk_accounts_liquidations_LiquidationsService.LiquidationsService;
|
|
8
10
|
exports.MultichainLiquidationsService = require_sdk_accounts_liquidations_MultichainLiquidationsService.MultichainLiquidationsService;
|