@gearbox-protocol/sdk 14.12.0-next.66 → 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/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/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/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/index.js +2 -2
- package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +152 -108
- 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/base/MultichainConstruct.js +79 -0
- package/dist/esm/sdk/base/TokensMeta.js +51 -0
- package/dist/esm/sdk/base/index.js +2 -1
- package/dist/esm/sdk/chain/chains.js +74 -2
- package/dist/esm/sdk/chain/index.js +2 -2
- 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/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 +27 -0
- package/dist/esm/sdk/market/pool/math.js +41 -0
- package/dist/esm/sdk/market/pricefeeds/AbstractPriceFeed.js +17 -0
- 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/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/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/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,5 +1,5 @@
|
|
|
1
1
|
import { TypedObjectUtils } from "../utils/mappers.js";
|
|
2
|
-
import { defineChain } from "viem";
|
|
2
|
+
import { defineChain, isAddressEqual } from "viem";
|
|
3
3
|
import { arbitrum, avalanche, base, berachain, bsc, etherlink, hemi, lisk, mainnet, megaeth, monad, optimism, plasma, somnia, sonic, worldchain } from "viem/chains";
|
|
4
4
|
import { z } from "zod/v4";
|
|
5
5
|
//#region src/sdk/chain/chains.ts
|
|
@@ -62,6 +62,19 @@ const chains = {
|
|
|
62
62
|
"0xa770ce584adb6491a2138da6eaec33243bdcd248": "Testnet Curator"
|
|
63
63
|
},
|
|
64
64
|
rwaFactories: [],
|
|
65
|
+
underlyingAssetTypes: {
|
|
66
|
+
"0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0": "ETH",
|
|
67
|
+
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2": "ETH",
|
|
68
|
+
"0x18084fbA666a33d37592fA2633fD49a74DD93a88": "BTC",
|
|
69
|
+
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48": "Stable",
|
|
70
|
+
"0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599": "BTC"
|
|
71
|
+
},
|
|
72
|
+
rwaTokens: [
|
|
73
|
+
"0x17418038ecF73BA4026c4f428547BF099706F27B",
|
|
74
|
+
"0x51C2d74017390CbBd30550179A16A1c28F7210fc",
|
|
75
|
+
"0x238a700eD6165261Cf8b2e544ba797BC11e466Ba",
|
|
76
|
+
"0x7433806912Eae67919e66aea853d46Fa0aef98A8"
|
|
77
|
+
],
|
|
65
78
|
isPublic: true,
|
|
66
79
|
wellKnownToken: {
|
|
67
80
|
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
@@ -152,6 +165,12 @@ const chains = {
|
|
|
152
165
|
"0x16956912813ab9a38d95730b52a8cf53e860a7c5": "Tulipa",
|
|
153
166
|
"0x7c6ee1bf9c1eb3ee55bdbdc1e8d0317aab718e0a": "UltraYield"
|
|
154
167
|
},
|
|
168
|
+
underlyingAssetTypes: {
|
|
169
|
+
"0x3bd359C1119dA7Da1D913D1C4D2B7c461115433A": "ETH",
|
|
170
|
+
"0x754704Bc059F8C67012fEd69BC8A327a5aafb603": "Stable",
|
|
171
|
+
"0xe7cd86e13AC4309349F30B3435a9d337750fC82D": "Stable",
|
|
172
|
+
"0x00000000eFE302BEAA2b3e6e1b18d08D69a9012a": "Stable"
|
|
173
|
+
},
|
|
155
174
|
rwaFactories: [],
|
|
156
175
|
isPublic: true,
|
|
157
176
|
wellKnownToken: {
|
|
@@ -223,6 +242,7 @@ const chains = {
|
|
|
223
242
|
...etherlink,
|
|
224
243
|
network: "Etherlink",
|
|
225
244
|
defaultMarketConfigurators: { "0x577424f0e6f50db668cc1bc76babb87e36732291": "Re7" },
|
|
245
|
+
underlyingAssetTypes: { "0x796Ea11Fa2dD751eD01b53C372fFDB4AAa8f00F9": "Stable" },
|
|
226
246
|
rwaFactories: [],
|
|
227
247
|
isPublic: true,
|
|
228
248
|
wellKnownToken: {
|
|
@@ -269,6 +289,10 @@ const chains = {
|
|
|
269
289
|
"0xce1cf71a28837daaa7b92d00ca4ef2fd649c2a67": "Hyperithm",
|
|
270
290
|
"0x9655f82b585b11cee8a05576ed8efcf755cec04b": "TelosC"
|
|
271
291
|
},
|
|
292
|
+
underlyingAssetTypes: {
|
|
293
|
+
"0xB8CE59FC3717ada4C02eaDF9682A9e934F625ebb": "Stable",
|
|
294
|
+
"0x5d3a1Ff2b6BAb83b63cd9AD0787074081a52ef34": "Stable"
|
|
295
|
+
},
|
|
272
296
|
rwaFactories: [],
|
|
273
297
|
isPublic: true,
|
|
274
298
|
wellKnownToken: {
|
|
@@ -288,6 +312,10 @@ const chains = {
|
|
|
288
312
|
blockTime: 200,
|
|
289
313
|
network: "Somnia",
|
|
290
314
|
defaultMarketConfigurators: { "0x1ca8b92aa7233a9f8f7ba031ac45c878141adff0": "Invariant Group" },
|
|
315
|
+
underlyingAssetTypes: {
|
|
316
|
+
"0x28BEc7E30E6faee657a03e19Bf1128AaD7632A00": "Stable",
|
|
317
|
+
"0x046EDe9564A72571df6F5e44d0405360c0f4dCab": "ETH"
|
|
318
|
+
},
|
|
291
319
|
rwaFactories: [],
|
|
292
320
|
isPublic: true,
|
|
293
321
|
wellKnownToken: {
|
|
@@ -378,5 +406,49 @@ function findCuratorMarketConfigurator(curator, network) {
|
|
|
378
406
|
};
|
|
379
407
|
for (const [a, c] of TypedObjectUtils.entries(all)) if (c === curator) return a;
|
|
380
408
|
}
|
|
409
|
+
/**
|
|
410
|
+
* Looks up the {@link AssetType} of a token in hardcoded classifier.
|
|
411
|
+
* Not all tokens are classified, only underlyings, so the default answer is `undefined`.
|
|
412
|
+
*
|
|
413
|
+
* @param token - Token address
|
|
414
|
+
* @param network - Network the token lives on.
|
|
415
|
+
* @returns The asset type, or `undefined` when the token is not classified
|
|
416
|
+
**/
|
|
417
|
+
function getAssetType(token, network) {
|
|
418
|
+
const table = chains[network].underlyingAssetTypes;
|
|
419
|
+
if (!table) return;
|
|
420
|
+
for (const [a, assetType] of TypedObjectUtils.entries(table)) if (isAddressEqual(a, token)) return assetType;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Checks whether a token represents a real-world asset, per the curated list of
|
|
424
|
+
* a network.
|
|
425
|
+
*
|
|
426
|
+
* @param token - Token address.
|
|
427
|
+
* @param network - Network the token lives on.
|
|
428
|
+
**/
|
|
429
|
+
function isRWAToken(token, network) {
|
|
430
|
+
return !!chains[network].rwaTokens?.some((t) => isAddressEqual(t, token));
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Checks whether a pool is on the sunset list of a network.
|
|
434
|
+
*
|
|
435
|
+
* @param pool - Pool address.
|
|
436
|
+
* @param network - Network the pool lives on.
|
|
437
|
+
**/
|
|
438
|
+
function isSunsetPool(pool, network) {
|
|
439
|
+
return !!chains[network].sunsetPools?.some((p) => isAddressEqual(p, pool));
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Checks whether a strategy is on the sunset list of a network. Both halves of
|
|
443
|
+
* the strategy key must match: a credit manager can wind down one collateral
|
|
444
|
+
* and keep the rest.
|
|
445
|
+
*
|
|
446
|
+
* @param creditManager - Credit manager address.
|
|
447
|
+
* @param collateral - Target collateral of the strategy.
|
|
448
|
+
* @param network - Network the strategy lives on.
|
|
449
|
+
**/
|
|
450
|
+
function isSunsetStrategy(creditManager, collateral, network) {
|
|
451
|
+
return !!chains[network].sunsetStrategies?.some((s) => isAddressEqual(s.creditManager, creditManager) && isAddressEqual(s.collateral, collateral));
|
|
452
|
+
}
|
|
381
453
|
//#endregion
|
|
382
|
-
export { NetworkType, SUPPORTED_NETWORKS, chains, findCuratorMarketConfigurator, getChain, getCuratorName, getNetworkType, isPublicNetwork, isSupportedNetwork };
|
|
454
|
+
export { NetworkType, SUPPORTED_NETWORKS, chains, findCuratorMarketConfigurator, getAssetType, getChain, getCuratorName, getNetworkType, isPublicNetwork, isRWAToken, isSunsetPool, isSunsetStrategy, isSupportedNetwork };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { NetworkType, SUPPORTED_NETWORKS, chains, findCuratorMarketConfigurator, getChain, getCuratorName, getNetworkType, isPublicNetwork, isSupportedNetwork } from "./chains.js";
|
|
1
|
+
import { NetworkType, SUPPORTED_NETWORKS, chains, findCuratorMarketConfigurator, getAssetType, getChain, getCuratorName, getNetworkType, isPublicNetwork, isRWAToken, isSunsetPool, isSunsetStrategy, isSupportedNetwork } from "./chains.js";
|
|
2
2
|
import { detectNetwork } from "./detectNetwork.js";
|
|
3
|
-
export { NetworkType, SUPPORTED_NETWORKS, chains, detectNetwork, findCuratorMarketConfigurator, getChain, getCuratorName, getNetworkType, isPublicNetwork, isSupportedNetwork };
|
|
3
|
+
export { NetworkType, SUPPORTED_NETWORKS, chains, detectNetwork, findCuratorMarketConfigurator, getAssetType, getChain, getCuratorName, getNetworkType, isPublicNetwork, isRWAToken, isSunsetPool, isSunsetStrategy, isSupportedNetwork };
|
|
@@ -51,6 +51,18 @@ var SdkMissingChainStateError = class extends BaseError {
|
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
53
|
/**
|
|
54
|
+
* Thrown when a chain that is not configured in {@link MultichainSDK} is
|
|
55
|
+
* requested.
|
|
56
|
+
*/
|
|
57
|
+
var ChainNotConfiguredError = class extends BaseError {
|
|
58
|
+
name = "ChainNotConfiguredError";
|
|
59
|
+
network;
|
|
60
|
+
constructor(network) {
|
|
61
|
+
super(`Chain ${String(network)} is not configured in this MultichainSDK`);
|
|
62
|
+
this.network = network;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
54
66
|
* Thrown by {@link MultichainSDK.syncState} when one or more per-chain syncs
|
|
55
67
|
* fail. Wraps the individual errors keyed by network.
|
|
56
68
|
*/
|
|
@@ -64,4 +76,4 @@ var SdkSyncFailedError = class extends BaseError {
|
|
|
64
76
|
}
|
|
65
77
|
};
|
|
66
78
|
//#endregion
|
|
67
|
-
export { SdkAlreadyAttachedError, SdkChainMismatchError, SdkMissingChainStateError, SdkNotAttachedError, SdkStateVersionMismatchError, SdkSyncFailedError };
|
|
79
|
+
export { ChainNotConfiguredError, SdkAlreadyAttachedError, SdkChainMismatchError, SdkMissingChainStateError, SdkNotAttachedError, SdkStateVersionMismatchError, SdkSyncFailedError };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { ChainNotConfiguredError, SdkAlreadyAttachedError, SdkChainMismatchError, SdkMissingChainStateError, SdkNotAttachedError, SdkStateVersionMismatchError, SdkSyncFailedError } from "./errors.js";
|
|
1
2
|
import { AddressProviderV310Contract } from "./AddressProviderV310Contract.js";
|
|
2
3
|
import { createAddressProvider, hydrateAddressProvider } from "./createAddressProvider.js";
|
|
3
|
-
import { SdkAlreadyAttachedError, SdkChainMismatchError, SdkMissingChainStateError, SdkNotAttachedError, SdkStateVersionMismatchError, SdkSyncFailedError } from "./errors.js";
|
|
4
4
|
import "./types.js";
|
|
5
|
-
export { AddressProviderV310Contract, SdkAlreadyAttachedError, SdkChainMismatchError, SdkMissingChainStateError, SdkNotAttachedError, SdkStateVersionMismatchError, SdkSyncFailedError, createAddressProvider, hydrateAddressProvider };
|
|
5
|
+
export { AddressProviderV310Contract, ChainNotConfiguredError, SdkAlreadyAttachedError, SdkChainMismatchError, SdkMissingChainStateError, SdkNotAttachedError, SdkStateVersionMismatchError, SdkSyncFailedError, createAddressProvider, hydrateAddressProvider };
|
package/dist/esm/sdk/index.js
CHANGED
|
@@ -3,11 +3,12 @@ import { AddressSet } from "./utils/AddressSet.js";
|
|
|
3
3
|
import { AssetsMap } from "./utils/AssetsMap.js";
|
|
4
4
|
import { json_parse, json_stringify } from "./utils/json.js";
|
|
5
5
|
import { functionArgsToMap, functionArgsToRecord, getFunctionSignature } from "./utils/abi-decode.js";
|
|
6
|
+
import { BigIntMath } from "./utils/bigint-math.js";
|
|
6
7
|
import { bytes32ToString } from "./utils/bytes32ToString.js";
|
|
7
8
|
import { childLogger } from "./utils/childLogger.js";
|
|
8
9
|
import { createRawTx } from "./utils/createRawTx.js";
|
|
9
10
|
import { TypedObjectUtils } from "./utils/mappers.js";
|
|
10
|
-
import { NetworkType, SUPPORTED_NETWORKS, chains, findCuratorMarketConfigurator, getChain, getCuratorName, getNetworkType, isPublicNetwork, isSupportedNetwork } from "./chain/chains.js";
|
|
11
|
+
import { NetworkType, SUPPORTED_NETWORKS, chains, findCuratorMarketConfigurator, getAssetType, getChain, getCuratorName, getNetworkType, isPublicNetwork, isRWAToken, isSunsetPool, isSunsetStrategy, isSupportedNetwork } from "./chain/chains.js";
|
|
11
12
|
import { detectNetwork } from "./chain/detectNetwork.js";
|
|
12
13
|
import "./chain/index.js";
|
|
13
14
|
import { etherscanApiUrl, etherscanUrl } from "./utils/etherscan.js";
|
|
@@ -25,7 +26,7 @@ import { fmtBinaryMask, formatBN, formatBNvalue, formatDuration, formatLeverage,
|
|
|
25
26
|
import { hexEq } from "./utils/hex.js";
|
|
26
27
|
import { retry } from "./utils/retry.js";
|
|
27
28
|
import { toAddress } from "./utils/toAddress.js";
|
|
28
|
-
import { ZodAddress } from "./utils/zod.js";
|
|
29
|
+
import { ZodAddress, ZodHex } from "./utils/zod.js";
|
|
29
30
|
import "./utils/index.js";
|
|
30
31
|
import { generateCastTraceCall, getCastTraceArgs } from "./utils/viem/cast.js";
|
|
31
32
|
import { SimulationError, simulateCall } from "./utils/viem/simulateCall.js";
|
|
@@ -34,6 +35,8 @@ import { ChainContractsRegister } from "./base/ChainContractsRegister.js";
|
|
|
34
35
|
import { Construct } from "./base/Construct.js";
|
|
35
36
|
import { BaseContract, ContractParseError } from "./base/BaseContract.js";
|
|
36
37
|
import { MissingSerializedParamsError } from "./base/errors.js";
|
|
38
|
+
import { ChainNotConfiguredError, SdkAlreadyAttachedError, SdkChainMismatchError, SdkMissingChainStateError, SdkNotAttachedError, SdkStateVersionMismatchError, SdkSyncFailedError } from "./core/errors.js";
|
|
39
|
+
import { MultichainConstruct } from "./base/MultichainConstruct.js";
|
|
37
40
|
import { PlaceholderContract } from "./base/PlaceholderContract.js";
|
|
38
41
|
import { SDKConstruct } from "./base/SDKConstruct.js";
|
|
39
42
|
import { PHANTOM_TOKEN_CONTRACT_TYPES, RWA_ON_DEMAND_LP_MONOPOLIZED, RWA_UNDERLYING_DEFAULT, RWA_UNDERLYING_ON_DEMAND } from "./base/token-types.js";
|
|
@@ -44,6 +47,7 @@ import { createAdapter } from "./market/adapters/createAdapter.js";
|
|
|
44
47
|
import { CreditConfiguratorV310Contract } from "./market/credit/CreditConfiguratorV310Contract.js";
|
|
45
48
|
import { CreditFacadeV310BaseContract, creditFacadeV310Abi as abi } from "./market/credit/CreditFacadeV310BaseContract.js";
|
|
46
49
|
import { CreditFacadeV310Contract } from "./market/credit/CreditFacadeV310Contract.js";
|
|
50
|
+
import { additionalBorrowApyBps, borrowApyBps, maxLeverage, rayToBps, usdToNumber, utilizationBps } from "./market/math.js";
|
|
47
51
|
import { CreditManagerV310Contract } from "./market/credit/CreditManagerV310Contract.js";
|
|
48
52
|
import { CreditSuite } from "./market/credit/CreditSuite.js";
|
|
49
53
|
import { simulateMulticall } from "./utils/viem/simulateMulticall.js";
|
|
@@ -99,7 +103,7 @@ import { RWARegistry } from "./market/rwa/RWARegistry.js";
|
|
|
99
103
|
import { RWA_FACTORY_TYPES, isRWAFactory } from "./market/rwa/types.js";
|
|
100
104
|
import "./market/index.js";
|
|
101
105
|
import { CreditAccountsServiceV310 } from "./accounts/CreditAccountsServiceV310.js";
|
|
102
|
-
import { LIQUIDATION_COMPRESSOR_V313_ADDRESS } from "./accounts/liquidations/constants.js";
|
|
106
|
+
import { DUST_THRESHOLD, LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS } from "./accounts/liquidations/constants.js";
|
|
103
107
|
import { LiquidationsService } from "./accounts/liquidations/LiquidationsService.js";
|
|
104
108
|
import { MultichainLiquidationsService } from "./accounts/liquidations/MultichainLiquidationsService.js";
|
|
105
109
|
import { DELAYED_INTENT_TYPES, DELAYED_INTENT_VERSION, decodeDelayedIntent, encodeDelayedIntent } from "./accounts/withdrawal-compressor/intent-codec.js";
|
|
@@ -116,8 +120,10 @@ import { createWithdrawalCompressor } from "./accounts/withdrawal-compressor/cre
|
|
|
116
120
|
import "./accounts/index.js";
|
|
117
121
|
import { AddressProviderV310Contract } from "./core/AddressProviderV310Contract.js";
|
|
118
122
|
import { createAddressProvider, hydrateAddressProvider } from "./core/createAddressProvider.js";
|
|
119
|
-
import { SdkAlreadyAttachedError, SdkChainMismatchError, SdkMissingChainStateError, SdkNotAttachedError, SdkStateVersionMismatchError, SdkSyncFailedError } from "./core/errors.js";
|
|
120
123
|
import "./core/index.js";
|
|
124
|
+
import { MultichainOpportunitiesService } from "./opportunities/MultichainOpportunitiesService.js";
|
|
125
|
+
import { OpportunitiesService } from "./opportunities/OpportunitiesService.js";
|
|
126
|
+
import "./opportunities/index.js";
|
|
121
127
|
import { BasePlugin } from "./plugins/BasePlugin.js";
|
|
122
128
|
import { PluginStateVersionError } from "./plugins/errors.js";
|
|
123
129
|
import "./plugins/index.js";
|
|
@@ -131,4 +137,4 @@ import { OnchainSDK, STATE_VERSION } from "./OnchainSDK.js";
|
|
|
131
137
|
import { MultichainSDK } from "./MultichainSDK.js";
|
|
132
138
|
import { attachOptionsSchema, onchainSDKOptionsSchema } from "./options.js";
|
|
133
139
|
import "./types/index.js";
|
|
134
|
-
export { ADDRESS_0X0, ADDRESS_PROVIDER_V310, AP_ACCOUNT_FACTORY, AP_ACL, AP_BOT_LIST, AP_BYTECODE_REPOSITORY, AP_CONTRACTS_REGISTER, AP_CONTROLLER_TIMELOCK, AP_CREDIT_ACCOUNT_COMPRESSOR, AP_CREDIT_SUITE_COMPRESSOR, AP_DATA_COMPRESSOR, AP_DELEVERAGE_BOT_HV, AP_DELEVERAGE_BOT_LV, AP_DELEVERAGE_BOT_PEGGED, AP_GAUGE_COMPRESSOR, AP_GEAR_STAKING, AP_GEAR_TOKEN, AP_INFLATION_ATTACK_BLOCKER, AP_INSOLVENCY_CHECKER, AP_MARKET_COMPRESSOR, AP_MARKET_CONFIGURATOR, AP_PARTIAL_LIQUIDATION_BOT, AP_PERIPHERY_COMPRESSOR, AP_PRICE_FEED_COMPRESSOR, AP_PRICE_FEED_STORE, AP_PRICE_ORACLE, AP_REDEMPTION_LOGGER, AP_REWARDS_COMPRESSOR, AP_ROUTER, AP_RWA_COMPRESSOR, AP_TOKEN_COMPRESSOR, AP_TREASURY, AP_WETH_GATEWAY, AP_WETH_TOKEN, AP_ZAPPER_REGISTER, AP_ZERO_PRICE_FEED, AbstractLPPriceFeedContract, AbstractPriceFeedContract, AbstractWithdrawalCompressorContract, AddressMap, AddressProviderV310Contract, AddressSet, AssetsMap, BLOCKS_PER_WEEK_BY_NETWORK, BalancerStablePriceFeedContract, BalancerWeightedPriceFeedContract, BaseContract, BasePlugin, BotPermissions, BoundedPriceFeedContract, ChainContractsRegister, CompositePriceFeedContract, Construct, ContractParseError, CreditAccountsServiceV310, CreditConfiguratorV310Contract, CreditFacadeV310BaseContract, CreditFacadeV310Contract, CreditManagerV310Contract, CreditSuite, CurveCryptoPriceFeedContract, CurveStablePriceFeedContract, CurveUSDPriceFeedContract, DELAYED_INTENT_TYPES, DELAYED_INTENT_VERSION, Erc4626PriceFeedContract, ExternalPriceFeedContract, GaugeContract, IERC20ZapperContract, IETHZapperContract, InvalidDelayedIntentError, LEVERAGE_DECIMALS, LIQUIDATION_COMPRESSOR_V313_ADDRESS, LinearInterestRateModelContract, LiquidationsService, MAX_INT, MAX_UINT16, MAX_UINT256, MIN_INT96, MULTICALL_ADDRESS, MarketRegister, MarketSuite, MellowLRTPriceFeedContract, MidasLiquidatorContract, MissingSerializedParamsError, MultichainLiquidationsService, MultichainSDK, NATIVE_ADDRESS, NOT_DEPLOYED, NO_VERSION, NetworkType, OnchainSDK, PERCENTAGE_DECIMALS, PERCENTAGE_FACTOR, PERCENTAGE_FACTOR_1KK, PERIPHERY_CONTRACTS, PHANTOM_TOKEN_CONTRACT_TYPES, PHANTOM_TOKEN_MIDAS_REDEMPTION, PHANTOM_TOKEN_SECURITIZE_REDEMPTION, PRICE_DECIMALS, PRICE_DECIMALS_POW, PartialPriceFeedInitError, PendleTWAPPTPriceFeed, PlaceholderAdapterContract, PlaceholderContract, PluginStateVersionError, PoolService, PoolSuite, PoolV310Contract, PriceFeedRef, PriceFeedRegister, PriceOracleV310Contract, PythPriceFeed, RAMP_DURATION_BY_NETWORK, RAY, RAY_DECIMALS_POW, RWARegistry, RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, RWA_LIQUIDATOR_MIDAS, RWA_LIQUIDATOR_SECURITIZE, RWA_ON_DEMAND_LP_MONOPOLIZED, RWA_UNDERLYING_DEFAULT, RWA_UNDERLYING_ON_DEMAND, RedemptionLoggerV310Contract, RedstonePriceFeedContract, RouterV310Contract, SDKConstruct, SECONDS_PER_YEAR, SECURITIZE_REGISTER_VAULT_TYPES, SLIPPAGE_DECIMALS, STATE_VERSION, SUPPORTED_NETWORKS, SdkAlreadyAttachedError, SdkChainMismatchError, SdkMissingChainStateError, SdkNotAttachedError, SdkStateVersionMismatchError, SdkSyncFailedError, SecuritizeLiquidatorContract, SecuritizeRWAFactory, SimulateWithPriceUpdatesError, SimulationError, TokensMeta, TypedObjectUtils, UnsupportedZapperFunctionError, VERSION_RANGE_310, VotingContractStatus, WAD, WAD_DECIMALS_POW, WithdrawalCompressorV310Contract, WithdrawalCompressorV311Contract, WithdrawalCompressorV313Contract, WstETHPriceFeedContract, YearnPriceFeedContract, ZapperContract, ZeroPriceFeedContract, ZodAddress, assetsMap, attachOptionsSchema, botPermissionsToString, bytes32ToString, chains, childLogger, createAdapter, createAddressProvider, createPriceOracle, createRawTx, createRedemptionLogger, createRouter, createWithdrawalCompressor, createZapper, abi as creditFacadeV310Abi, decodeDelayedIntent, detectNetwork, encodeDelayedIntent, estimateRawTxGas, etherscanApiUrl, etherscanUrl, executeDelegatedMulticalls, fetchPythPayloads, fetchRedstonePayloads, filterDust, filterDustUSD, findCuratorMarketConfigurator, fmtBinaryMask, formatBN, formatBNvalue, formatDuration, formatLeverage, formatNumberToString_, formatPercentage, formatTimestamp, functionArgsToMap, functionArgsToRecord, generateCastTraceCall, getCastTraceArgs, getChain, getCuratorName, getFunctionSignature, getNetworkType, getRawPriceUpdates, getSimulateWithPriceUpdatesError, getWithdrawalCompressorAddress, halfRAY, hexEq, hydrateAddressProvider, iCreditAccountAbi, isDust, isLPPriceFeed, isPublicNetwork, isRWAFactory, isSupportedNetwork, isUpdatablePriceFeed, isV310, isVersionRange, json_parse, json_stringify, numberWithCommas, onchainSDKOptionsSchema, percentFmt, rayToNumber, retry, sendRawTx, shortAddress, shortHash, simulateCall, simulateMulticall, simulateWithPriceUpdates, toAddress, toBN, toBigInt, toClaimableWithdrawal, toPendingWithdrawal, toRequestableWithdrawal, toSignificant, toWithdrawalStatus, watchBlocksAsync };
|
|
140
|
+
export { ADDRESS_0X0, ADDRESS_PROVIDER_V310, AP_ACCOUNT_FACTORY, AP_ACL, AP_BOT_LIST, AP_BYTECODE_REPOSITORY, AP_CONTRACTS_REGISTER, AP_CONTROLLER_TIMELOCK, AP_CREDIT_ACCOUNT_COMPRESSOR, AP_CREDIT_SUITE_COMPRESSOR, AP_DATA_COMPRESSOR, AP_DELEVERAGE_BOT_HV, AP_DELEVERAGE_BOT_LV, AP_DELEVERAGE_BOT_PEGGED, AP_GAUGE_COMPRESSOR, AP_GEAR_STAKING, AP_GEAR_TOKEN, AP_INFLATION_ATTACK_BLOCKER, AP_INSOLVENCY_CHECKER, AP_MARKET_COMPRESSOR, AP_MARKET_CONFIGURATOR, AP_PARTIAL_LIQUIDATION_BOT, AP_PERIPHERY_COMPRESSOR, AP_PRICE_FEED_COMPRESSOR, AP_PRICE_FEED_STORE, AP_PRICE_ORACLE, AP_REDEMPTION_LOGGER, AP_REWARDS_COMPRESSOR, AP_ROUTER, AP_RWA_COMPRESSOR, AP_TOKEN_COMPRESSOR, AP_TREASURY, AP_WETH_GATEWAY, AP_WETH_TOKEN, AP_ZAPPER_REGISTER, AP_ZERO_PRICE_FEED, AbstractLPPriceFeedContract, AbstractPriceFeedContract, AbstractWithdrawalCompressorContract, AddressMap, AddressProviderV310Contract, AddressSet, AssetsMap, BLOCKS_PER_WEEK_BY_NETWORK, BalancerStablePriceFeedContract, BalancerWeightedPriceFeedContract, BaseContract, BasePlugin, BigIntMath, BotPermissions, BoundedPriceFeedContract, ChainContractsRegister, ChainNotConfiguredError, CompositePriceFeedContract, Construct, ContractParseError, CreditAccountsServiceV310, CreditConfiguratorV310Contract, CreditFacadeV310BaseContract, CreditFacadeV310Contract, CreditManagerV310Contract, CreditSuite, CurveCryptoPriceFeedContract, CurveStablePriceFeedContract, CurveUSDPriceFeedContract, DELAYED_INTENT_TYPES, DELAYED_INTENT_VERSION, DUST_THRESHOLD, Erc4626PriceFeedContract, ExternalPriceFeedContract, GaugeContract, IERC20ZapperContract, IETHZapperContract, InvalidDelayedIntentError, LEVERAGE_DECIMALS, LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS, LinearInterestRateModelContract, LiquidationsService, MAX_INT, MAX_UINT16, MAX_UINT256, MIN_INT96, MULTICALL_ADDRESS, MarketRegister, MarketSuite, MellowLRTPriceFeedContract, MidasLiquidatorContract, MissingSerializedParamsError, MultichainConstruct, MultichainLiquidationsService, MultichainOpportunitiesService, MultichainSDK, NATIVE_ADDRESS, NOT_DEPLOYED, NO_VERSION, NetworkType, OnchainSDK, OpportunitiesService, PERCENTAGE_DECIMALS, PERCENTAGE_FACTOR, PERCENTAGE_FACTOR_1KK, PERIPHERY_CONTRACTS, PHANTOM_TOKEN_CONTRACT_TYPES, PHANTOM_TOKEN_MIDAS_REDEMPTION, PHANTOM_TOKEN_SECURITIZE_REDEMPTION, PRICE_DECIMALS, PRICE_DECIMALS_POW, PartialPriceFeedInitError, PendleTWAPPTPriceFeed, PlaceholderAdapterContract, PlaceholderContract, PluginStateVersionError, PoolService, PoolSuite, PoolV310Contract, PriceFeedRef, PriceFeedRegister, PriceOracleV310Contract, PythPriceFeed, RAMP_DURATION_BY_NETWORK, RAY, RAY_DECIMALS_POW, RWARegistry, RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, RWA_LIQUIDATOR_MIDAS, RWA_LIQUIDATOR_SECURITIZE, RWA_ON_DEMAND_LP_MONOPOLIZED, RWA_UNDERLYING_DEFAULT, RWA_UNDERLYING_ON_DEMAND, RedemptionLoggerV310Contract, RedstonePriceFeedContract, RouterV310Contract, SDKConstruct, SECONDS_PER_YEAR, SECURITIZE_REGISTER_VAULT_TYPES, SLIPPAGE_DECIMALS, STATE_VERSION, SUPPORTED_NETWORKS, SdkAlreadyAttachedError, SdkChainMismatchError, SdkMissingChainStateError, SdkNotAttachedError, SdkStateVersionMismatchError, SdkSyncFailedError, SecuritizeLiquidatorContract, SecuritizeRWAFactory, SimulateWithPriceUpdatesError, SimulationError, TokensMeta, TypedObjectUtils, UnsupportedZapperFunctionError, VERSION_RANGE_310, VotingContractStatus, WAD, WAD_DECIMALS_POW, WithdrawalCompressorV310Contract, WithdrawalCompressorV311Contract, WithdrawalCompressorV313Contract, WstETHPriceFeedContract, YearnPriceFeedContract, ZapperContract, ZeroPriceFeedContract, ZodAddress, ZodHex, additionalBorrowApyBps, assetsMap, attachOptionsSchema, borrowApyBps, botPermissionsToString, bytes32ToString, chains, childLogger, createAdapter, createAddressProvider, createPriceOracle, createRawTx, createRedemptionLogger, createRouter, createWithdrawalCompressor, createZapper, abi as creditFacadeV310Abi, decodeDelayedIntent, detectNetwork, encodeDelayedIntent, estimateRawTxGas, etherscanApiUrl, etherscanUrl, executeDelegatedMulticalls, fetchPythPayloads, fetchRedstonePayloads, filterDust, filterDustUSD, findCuratorMarketConfigurator, fmtBinaryMask, formatBN, formatBNvalue, formatDuration, formatLeverage, formatNumberToString_, formatPercentage, formatTimestamp, functionArgsToMap, functionArgsToRecord, generateCastTraceCall, getAssetType, getCastTraceArgs, getChain, getCuratorName, getFunctionSignature, getNetworkType, getRawPriceUpdates, getSimulateWithPriceUpdatesError, getWithdrawalCompressorAddress, halfRAY, hexEq, hydrateAddressProvider, iCreditAccountAbi, isDust, isLPPriceFeed, isPublicNetwork, isRWAFactory, isRWAToken, isSunsetPool, isSunsetStrategy, isSupportedNetwork, isUpdatablePriceFeed, isV310, isVersionRange, json_parse, json_stringify, maxLeverage, numberWithCommas, onchainSDKOptionsSchema, percentFmt, rayToBps, rayToNumber, retry, sendRawTx, shortAddress, shortHash, simulateCall, simulateMulticall, simulateWithPriceUpdates, toAddress, toBN, toBigInt, toClaimableWithdrawal, toPendingWithdrawal, toRequestableWithdrawal, toSignificant, toWithdrawalStatus, usdToNumber, utilizationBps, watchBlocksAsync };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { iMarketConfiguratorV310Abi } from "../../abi/310/generated.js";
|
|
2
|
+
import { getCuratorName } from "../chain/chains.js";
|
|
2
3
|
import { AP_MARKET_CONFIGURATOR } from "../constants/address-provider.js";
|
|
3
4
|
import "../constants/index.js";
|
|
4
5
|
import { BaseContract } from "../base/BaseContract.js";
|
|
@@ -24,6 +25,19 @@ var MarketConfiguratorContract = class extends BaseContract {
|
|
|
24
25
|
});
|
|
25
26
|
this.register.setAddressLabel(this.address, `Market configurator ${this.#curatorName}`);
|
|
26
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* The entity operating this configurator, as the shared read model describes
|
|
30
|
+
* it. The curated per-chain table wins over the name the contract reports,
|
|
31
|
+
* because the two sources must agree across services and only the table is
|
|
32
|
+
* shared with the backend.
|
|
33
|
+
*/
|
|
34
|
+
get curator() {
|
|
35
|
+
return {
|
|
36
|
+
address: this.address,
|
|
37
|
+
name: getCuratorName(this.address, this.networkType) ?? this.#curatorName ?? "Unknown",
|
|
38
|
+
url: null
|
|
39
|
+
};
|
|
40
|
+
}
|
|
27
41
|
static async getPeripheryContractBatch(configurators, client, contract, blockNumber) {
|
|
28
42
|
return await client.multicall({
|
|
29
43
|
allowFailure: true,
|
|
@@ -1,14 +1,20 @@
|
|
|
1
|
+
import { AddressMap } from "../utils/AddressMap.js";
|
|
2
|
+
import { isRWAToken, isSunsetPool } from "../chain/chains.js";
|
|
3
|
+
import "../utils/index.js";
|
|
1
4
|
import { SDKConstruct } from "../base/SDKConstruct.js";
|
|
2
5
|
import "../base/index.js";
|
|
3
6
|
import { CreditSuite } from "./credit/CreditSuite.js";
|
|
4
7
|
import "./credit/index.js";
|
|
5
8
|
import { MarketConfiguratorContract } from "./MarketConfiguratorContract.js";
|
|
9
|
+
import { matchesOpportunityFilter } from "../../model/opportunities.js";
|
|
10
|
+
import "../../model/index.js";
|
|
6
11
|
import { createLossPolicy } from "./loss-policy/createLossPolicy.js";
|
|
7
12
|
import "./loss-policy/index.js";
|
|
8
13
|
import { createPriceOracle } from "./oracle/createPriceOracle.js";
|
|
9
14
|
import "./oracle/index.js";
|
|
10
15
|
import { PoolSuite } from "./pool/PoolSuite.js";
|
|
11
16
|
import "./pool/index.js";
|
|
17
|
+
import { isAddressEqual } from "viem";
|
|
12
18
|
//#region src/sdk/market/MarketSuite.ts
|
|
13
19
|
/**
|
|
14
20
|
* Aggregates all SDK wrappers that make up one Gearbox market.
|
|
@@ -100,6 +106,163 @@ var MarketSuite = class extends SDKConstruct {
|
|
|
100
106
|
return this.pool.rwaFactory;
|
|
101
107
|
}
|
|
102
108
|
/**
|
|
109
|
+
* {@inheritDoc IPoolContract.unwrappedUnderlying}
|
|
110
|
+
*/
|
|
111
|
+
get unwrappedUnderlying() {
|
|
112
|
+
return this.pool.unwrappedUnderlying;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The market's underlying as the shared read model describes it.
|
|
116
|
+
*
|
|
117
|
+
* For an RWA market this is the token the underlying wraps rather than the
|
|
118
|
+
* wrapper itself, because only that token means anything to a reader. The
|
|
119
|
+
* wrapper converts one-for-one, so amounts denominated in it stay exact.
|
|
120
|
+
*/
|
|
121
|
+
get underlyingToken() {
|
|
122
|
+
return this.tokensMeta.mustGetToken(this.unwrappedUnderlying);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* {@inheritDoc MarketConfiguratorContract.curator}
|
|
126
|
+
*/
|
|
127
|
+
get curator() {
|
|
128
|
+
return this.configurator.curator;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Every `(credit suite, collateral)` pair of this market that qualifies as a
|
|
132
|
+
* leveraged position.
|
|
133
|
+
*/
|
|
134
|
+
get strategies() {
|
|
135
|
+
return this.creditManagers.flatMap((suite) => suite.strategyCollaterals.map((collateral) => ({
|
|
136
|
+
suite,
|
|
137
|
+
collateral
|
|
138
|
+
})));
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Tokens a position can actually be built on in this market, deduplicated
|
|
142
|
+
* across its credit suites.
|
|
143
|
+
*/
|
|
144
|
+
get collateralTokens() {
|
|
145
|
+
const seen = new AddressMap(void 0, "collateralTokens");
|
|
146
|
+
for (const { collateral } of this.strategies) seen.upsert(collateral, this.tokensMeta.mustGetToken(collateral));
|
|
147
|
+
return seen.values();
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Whether at least one of {@link collateralTokens} is a real-world-asset
|
|
151
|
+
* token. Read from a hardcoded per-chain list rather than from the chain.
|
|
152
|
+
*/
|
|
153
|
+
get rwa() {
|
|
154
|
+
return this.strategies.some(({ collateral }) => isRWAToken(collateral, this.sdk.networkType));
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Whether this market's pool is being wound down and should no longer be
|
|
158
|
+
* entered. Read from a hardcoded per-chain list.
|
|
159
|
+
*/
|
|
160
|
+
get sunset() {
|
|
161
|
+
return isSunsetPool(this.pool.pool.address, this.sdk.networkType);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Quota configuration of every token the market quotes: how much of it the
|
|
165
|
+
* market accepts in total, and what holding it costs.
|
|
166
|
+
*/
|
|
167
|
+
quotaAssets() {
|
|
168
|
+
const oracle = this.priceOracle;
|
|
169
|
+
const { underlying } = this;
|
|
170
|
+
return this.pool.pqk.quotas.entries().map(([token, quota]) => ({
|
|
171
|
+
token: this.tokensMeta.mustGetToken(token),
|
|
172
|
+
quotaRate: quota.rate,
|
|
173
|
+
limit: oracle.toAmount(underlying, quota.limit),
|
|
174
|
+
used: oracle.toAmount(underlying, quota.totalQuoted)
|
|
175
|
+
}));
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Prices and feeds of a collateral token and the market's underlying.
|
|
179
|
+
*
|
|
180
|
+
* Pricing goes through the wrapper for an RWA market, since that is what the
|
|
181
|
+
* market's oracle knows.
|
|
182
|
+
*
|
|
183
|
+
* @param collateral - Collateral token to price.
|
|
184
|
+
*/
|
|
185
|
+
priceFeedSummary(collateral) {
|
|
186
|
+
return this.priceOracle.priceFeedSummary(this.underlying, collateral);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Every opportunity this market offers: its pool, plus one row per
|
|
190
|
+
* `(credit manager, target collateral)` pair.
|
|
191
|
+
*
|
|
192
|
+
* @param totals - Resolves the summed worth of the credit accounts backing a
|
|
193
|
+
* strategy, which only a credit-account query can establish.
|
|
194
|
+
* @param filter - Optional narrowing. A filter naming a kind skips building
|
|
195
|
+
* the other kind entirely; every built row is then checked in full by
|
|
196
|
+
* {@link matchesOpportunityFilter}, so there is one definition of what each
|
|
197
|
+
* criterion means.
|
|
198
|
+
*/
|
|
199
|
+
opportunities(totals, filter) {
|
|
200
|
+
const rows = [];
|
|
201
|
+
if (filter?.kind !== "strategy") rows.push(this.poolOpportunity());
|
|
202
|
+
if (filter?.kind !== "pool") for (const { suite, collateral } of this.strategies) rows.push(suite.strategyOpportunity(collateral, totals(suite.creditManager.address, collateral)));
|
|
203
|
+
return rows.filter((row) => matchesOpportunityFilter(row, filter));
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Passive lending into this market's pool, as the shared read model
|
|
207
|
+
* describes it.
|
|
208
|
+
*/
|
|
209
|
+
poolOpportunity() {
|
|
210
|
+
const { pool } = this.pool;
|
|
211
|
+
const oracle = this.priceOracle;
|
|
212
|
+
return {
|
|
213
|
+
kind: "pool",
|
|
214
|
+
chainId: this.chainId,
|
|
215
|
+
pool: pool.address,
|
|
216
|
+
title: `${this.underlyingToken.symbol} Pool`,
|
|
217
|
+
curator: this.curator,
|
|
218
|
+
underlyingToken: this.underlyingToken,
|
|
219
|
+
totalSupply: {
|
|
220
|
+
value: pool.totalSupply,
|
|
221
|
+
valueUsd: oracle.safeUsdValue(pool.underlying, pool.totalAssets)
|
|
222
|
+
},
|
|
223
|
+
totalBorrow: oracle.toAmount(pool.underlying, pool.totalBorrowed),
|
|
224
|
+
utilization: pool.utilization,
|
|
225
|
+
collateralTokens: this.collateralTokens,
|
|
226
|
+
paused: pool.isPaused,
|
|
227
|
+
rwa: this.rwa,
|
|
228
|
+
sunset: this.sunset
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* {@link poolOpportunity} plus the data only its detail screen needs.
|
|
233
|
+
*/
|
|
234
|
+
poolOpportunityDetail() {
|
|
235
|
+
return {
|
|
236
|
+
...this.poolOpportunity(),
|
|
237
|
+
rateCurve: this.pool.rateCurve,
|
|
238
|
+
quotaAssets: this.quotaAssets()
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Resolves a strategy of this market by its two halves.
|
|
243
|
+
*
|
|
244
|
+
* @param creditManager - Credit manager the position is opened in.
|
|
245
|
+
* @param collateral - Target collateral of the position.
|
|
246
|
+
* @throws If this market has no such credit manager, or if that manager does
|
|
247
|
+
* not accept the collateral as a strategy.
|
|
248
|
+
*/
|
|
249
|
+
mustFindStrategy(creditManager, collateral) {
|
|
250
|
+
const strategy = this.strategies.find((s) => isAddressEqual(s.suite.creditManager.address, creditManager) && isAddressEqual(s.collateral, collateral));
|
|
251
|
+
if (!strategy) throw new Error(`${this.labelAddress(collateral)} is not a strategy collateral of credit manager ${this.labelAddress(creditManager)}`);
|
|
252
|
+
return strategy;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Detailed view of one leveraged position of this market.
|
|
256
|
+
*
|
|
257
|
+
* @param creditManager - Credit manager the position is opened in.
|
|
258
|
+
* @param collateral - Target collateral of the position.
|
|
259
|
+
* @param totalSupply - Summed worth of the credit accounts backing it.
|
|
260
|
+
* @throws If this market has no such strategy, see {@link mustFindStrategy}.
|
|
261
|
+
*/
|
|
262
|
+
strategyOpportunityDetail(creditManager, collateral, totalSupply) {
|
|
263
|
+
return this.mustFindStrategy(creditManager, collateral).suite.strategyOpportunityDetail(collateral, totalSupply);
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
103
266
|
* Whether any child contract wrapper has observed events that require a
|
|
104
267
|
* market resync.
|
|
105
268
|
*/
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { iCreditManagerV310Abi } from "../../../abi/310/generated.js";
|
|
2
2
|
import { AddressMap } from "../../utils/AddressMap.js";
|
|
3
|
+
import { PERCENTAGE_FACTOR } from "../../constants/math.js";
|
|
4
|
+
import "../../constants/index.js";
|
|
3
5
|
import { fmtBinaryMask, percentFmt } from "../../utils/formatter.js";
|
|
4
6
|
import "../../utils/index.js";
|
|
5
7
|
import { BaseContract } from "../../base/BaseContract.js";
|
|
6
8
|
import "../../base/index.js";
|
|
7
9
|
import { createAdapter } from "../adapters/createAdapter.js";
|
|
8
10
|
import "../adapters/index.js";
|
|
11
|
+
import { maxLeverage } from "../math.js";
|
|
12
|
+
import { isAddressEqual } from "viem";
|
|
9
13
|
//#region src/sdk/market/credit/CreditManagerV310Contract.ts
|
|
10
14
|
const abi = iCreditManagerV310Abi;
|
|
11
15
|
var CreditManagerV310Contract = class extends BaseContract {
|
|
@@ -59,6 +63,28 @@ var CreditManagerV310Contract = class extends BaseContract {
|
|
|
59
63
|
get collateralTokens() {
|
|
60
64
|
return this.liquidationThresholds.keys();
|
|
61
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* {@inheritDoc ICreditManagerContract.leverageableCollaterals}
|
|
68
|
+
*/
|
|
69
|
+
get leverageableCollaterals() {
|
|
70
|
+
return this.collateralTokens.filter((token) => {
|
|
71
|
+
if (isAddressEqual(token, this.underlying)) return false;
|
|
72
|
+
const lt = this.liquidationThresholds.get(token);
|
|
73
|
+
return !!lt && lt > 0 && lt < Number(10000n);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* {@inheritDoc ICreditManagerContract.maxLeverage}
|
|
78
|
+
*/
|
|
79
|
+
maxLeverage(collateral) {
|
|
80
|
+
return maxLeverage(this.liquidationThresholds.mustGet(collateral));
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* {@inheritDoc ICreditManagerContract.liquidationPremium}
|
|
84
|
+
*/
|
|
85
|
+
get liquidationPremium() {
|
|
86
|
+
return Number(PERCENTAGE_FACTOR) - this.liquidationDiscount;
|
|
87
|
+
}
|
|
62
88
|
processLog(log) {
|
|
63
89
|
switch (log.eventName) {
|
|
64
90
|
case "SetCreditConfigurator": this.dirty = true;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import { BigIntMath } from "../../utils/bigint-math.js";
|
|
2
|
+
import { isSunsetStrategy } from "../../chain/chains.js";
|
|
3
|
+
import "../../constants/math.js";
|
|
4
|
+
import "../../constants/index.js";
|
|
1
5
|
import { SDKConstruct } from "../../base/SDKConstruct.js";
|
|
2
6
|
import "../../base/index.js";
|
|
7
|
+
import { additionalBorrowApyBps, borrowApyBps, utilizationBps } from "../math.js";
|
|
3
8
|
import createCreditConfigurator from "./createCreditConfigurator.js";
|
|
4
9
|
import createCreditFacade from "./createCreditFacade.js";
|
|
5
10
|
import createCreditManager from "./createCreditManager.js";
|
|
@@ -98,6 +103,103 @@ var CreditSuite = class extends SDKConstruct {
|
|
|
98
103
|
return this.creditFacade.expirable && this.creditFacade.expirationDate > 0 && this.creditFacade.expirationDate < this.sdk.timestamp;
|
|
99
104
|
}
|
|
100
105
|
/**
|
|
106
|
+
* Moment the facade expires, after which positions can no longer be opened
|
|
107
|
+
* and open ones become liquidatable, or `null` when it is not expirable.
|
|
108
|
+
*
|
|
109
|
+
* @remarks
|
|
110
|
+
* The facade stores `0` for a non-expirable suite, which as a timestamp
|
|
111
|
+
* would read as 1970 rather than as "never".
|
|
112
|
+
*/
|
|
113
|
+
get expirationDate() {
|
|
114
|
+
const { expirationDate } = this.creditFacade;
|
|
115
|
+
return expirationDate > 0 ? expirationDate : null;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Whether this suite can be used right now. A paused pool blocks borrowing,
|
|
119
|
+
* so the suite is unusable even when its own facade is live.
|
|
120
|
+
*/
|
|
121
|
+
get isPaused() {
|
|
122
|
+
return this.creditFacade.isPaused || this.market.pool.isPaused;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Collateral tokens a leveraged position can be built around in this suite:
|
|
126
|
+
* the ones the credit manager can lever up, narrowed to those the market
|
|
127
|
+
* still accepts quota for.
|
|
128
|
+
*/
|
|
129
|
+
get strategyCollaterals() {
|
|
130
|
+
const { pqk } = this.market.pool;
|
|
131
|
+
return this.creditManager.leverageableCollaterals.filter((token) => pqk.hasActiveQuota(token));
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Largest debt a single new position can take on right now: the tightest of
|
|
135
|
+
* this manager's remaining debt limit, the pool's free liquidity and the
|
|
136
|
+
* facade's per-account maximum.
|
|
137
|
+
*/
|
|
138
|
+
get maxBorrowAmount() {
|
|
139
|
+
const { pool } = this.market.pool;
|
|
140
|
+
const debtParams = pool.creditManagerDebtParams.get(this.creditManager.address);
|
|
141
|
+
return BigIntMath.min(debtParams?.available ?? 115792089237316195423570985008687907853269984665640564039457584007913129639935n, pool.availableLiquidity, this.creditFacade.maxDebt);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Describes a leveraged position built on one collateral token as the shared
|
|
145
|
+
* read model does.
|
|
146
|
+
*
|
|
147
|
+
* @param collateral - Target collateral of the position.
|
|
148
|
+
* @param totalSupply - Summed worth of the credit accounts backing it, which
|
|
149
|
+
* only a credit-account query can establish. Defaults to zero, so a caller
|
|
150
|
+
* that does not care about size can omit it.
|
|
151
|
+
* @throws If the credit manager does not value the collateral.
|
|
152
|
+
*/
|
|
153
|
+
strategyOpportunity(collateral, totalSupply_) {
|
|
154
|
+
const totalSupply = totalSupply_ ?? {
|
|
155
|
+
value: 0n,
|
|
156
|
+
valueUsd: 0
|
|
157
|
+
};
|
|
158
|
+
const { market, creditManager: cm } = this;
|
|
159
|
+
const { pool } = market.pool;
|
|
160
|
+
const oracle = market.priceOracle;
|
|
161
|
+
const liquidationThreshold = cm.liquidationThresholds.mustGet(collateral);
|
|
162
|
+
const maxLeverage = cm.maxLeverage(collateral);
|
|
163
|
+
const borrowed = pool.creditManagerDebtParams.get(cm.address)?.borrowed ?? 0n;
|
|
164
|
+
return {
|
|
165
|
+
kind: "strategy",
|
|
166
|
+
chainId: this.chainId,
|
|
167
|
+
creditManager: cm.address,
|
|
168
|
+
targetCollateral: this.tokensMeta.mustGetToken(collateral),
|
|
169
|
+
title: `${this.tokensMeta.symbol(collateral)} / ${market.underlyingToken.symbol}`,
|
|
170
|
+
curator: market.curator,
|
|
171
|
+
underlyingToken: market.underlyingToken,
|
|
172
|
+
totalSupply,
|
|
173
|
+
totalBorrow: oracle.toAmount(pool.underlying, borrowed),
|
|
174
|
+
utilization: utilizationBps(borrowed, totalSupply.value),
|
|
175
|
+
collateralTokens: market.collateralTokens,
|
|
176
|
+
paused: this.isPaused,
|
|
177
|
+
rwa: market.rwa,
|
|
178
|
+
sunset: isSunsetStrategy(cm.address, collateral, this.sdk.networkType),
|
|
179
|
+
liquidationThreshold,
|
|
180
|
+
liquidationPremium: cm.liquidationPremium,
|
|
181
|
+
liquidationFee: cm.feeLiquidation,
|
|
182
|
+
expirationDate: this.expirationDate,
|
|
183
|
+
borrowApy: borrowApyBps(pool.baseInterestRate, cm.feeInterest),
|
|
184
|
+
additionalBorrowApy: additionalBorrowApyBps(market.pool.pqk.quotaRate(collateral), maxLeverage),
|
|
185
|
+
maxBorrowAmount: oracle.toAmount(pool.underlying, this.maxBorrowAmount),
|
|
186
|
+
maxLeverage
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* {@link strategyOpportunity} plus the data only its detail screen needs.
|
|
191
|
+
*
|
|
192
|
+
* @param collateral - Target collateral of the position.
|
|
193
|
+
* @param totalSupply - Summed worth of the credit accounts backing it.
|
|
194
|
+
*/
|
|
195
|
+
strategyOpportunityDetail(collateral, totalSupply) {
|
|
196
|
+
return {
|
|
197
|
+
...this.strategyOpportunity(collateral, totalSupply),
|
|
198
|
+
rateCurve: this.market.pool.rateCurve,
|
|
199
|
+
priceFeeds: this.market.priceFeedSummary(collateral)
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
101
203
|
* Whether the facade, manager, or configurator has observed logs that require
|
|
102
204
|
* a credit-suite resync.
|
|
103
205
|
*/
|