@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,15 +1,21 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sdk_utils_AddressMap = require("../utils/AddressMap.js");
|
|
3
|
+
const require_sdk_chain_chains = require("../chain/chains.js");
|
|
4
|
+
require("../utils/index.js");
|
|
2
5
|
const require_sdk_base_SDKConstruct = require("../base/SDKConstruct.js");
|
|
3
6
|
require("../base/index.js");
|
|
4
7
|
const require_sdk_market_credit_CreditSuite = require("./credit/CreditSuite.js");
|
|
5
8
|
require("./credit/index.js");
|
|
6
9
|
const require_sdk_market_MarketConfiguratorContract = require("./MarketConfiguratorContract.js");
|
|
10
|
+
const require_model_opportunities = require("../../model/opportunities.js");
|
|
11
|
+
require("../../model/index.js");
|
|
7
12
|
const require_sdk_market_loss_policy_createLossPolicy = require("./loss-policy/createLossPolicy.js");
|
|
8
13
|
require("./loss-policy/index.js");
|
|
9
14
|
const require_sdk_market_oracle_createPriceOracle = require("./oracle/createPriceOracle.js");
|
|
10
15
|
require("./oracle/index.js");
|
|
11
16
|
const require_sdk_market_pool_PoolSuite = require("./pool/PoolSuite.js");
|
|
12
17
|
require("./pool/index.js");
|
|
18
|
+
let viem = require("viem");
|
|
13
19
|
//#region src/sdk/market/MarketSuite.ts
|
|
14
20
|
/**
|
|
15
21
|
* Aggregates all SDK wrappers that make up one Gearbox market.
|
|
@@ -101,6 +107,163 @@ var MarketSuite = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
|
101
107
|
return this.pool.rwaFactory;
|
|
102
108
|
}
|
|
103
109
|
/**
|
|
110
|
+
* {@inheritDoc IPoolContract.unwrappedUnderlying}
|
|
111
|
+
*/
|
|
112
|
+
get unwrappedUnderlying() {
|
|
113
|
+
return this.pool.unwrappedUnderlying;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The market's underlying as the shared read model describes it.
|
|
117
|
+
*
|
|
118
|
+
* For an RWA market this is the token the underlying wraps rather than the
|
|
119
|
+
* wrapper itself, because only that token means anything to a reader. The
|
|
120
|
+
* wrapper converts one-for-one, so amounts denominated in it stay exact.
|
|
121
|
+
*/
|
|
122
|
+
get underlyingToken() {
|
|
123
|
+
return this.tokensMeta.mustGetToken(this.unwrappedUnderlying);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* {@inheritDoc MarketConfiguratorContract.curator}
|
|
127
|
+
*/
|
|
128
|
+
get curator() {
|
|
129
|
+
return this.configurator.curator;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Every `(credit suite, collateral)` pair of this market that qualifies as a
|
|
133
|
+
* leveraged position.
|
|
134
|
+
*/
|
|
135
|
+
get strategies() {
|
|
136
|
+
return this.creditManagers.flatMap((suite) => suite.strategyCollaterals.map((collateral) => ({
|
|
137
|
+
suite,
|
|
138
|
+
collateral
|
|
139
|
+
})));
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Tokens a position can actually be built on in this market, deduplicated
|
|
143
|
+
* across its credit suites.
|
|
144
|
+
*/
|
|
145
|
+
get collateralTokens() {
|
|
146
|
+
const seen = new require_sdk_utils_AddressMap.AddressMap(void 0, "collateralTokens");
|
|
147
|
+
for (const { collateral } of this.strategies) seen.upsert(collateral, this.tokensMeta.mustGetToken(collateral));
|
|
148
|
+
return seen.values();
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Whether at least one of {@link collateralTokens} is a real-world-asset
|
|
152
|
+
* token. Read from a hardcoded per-chain list rather than from the chain.
|
|
153
|
+
*/
|
|
154
|
+
get rwa() {
|
|
155
|
+
return this.strategies.some(({ collateral }) => require_sdk_chain_chains.isRWAToken(collateral, this.sdk.networkType));
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Whether this market's pool is being wound down and should no longer be
|
|
159
|
+
* entered. Read from a hardcoded per-chain list.
|
|
160
|
+
*/
|
|
161
|
+
get sunset() {
|
|
162
|
+
return require_sdk_chain_chains.isSunsetPool(this.pool.pool.address, this.sdk.networkType);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Quota configuration of every token the market quotes: how much of it the
|
|
166
|
+
* market accepts in total, and what holding it costs.
|
|
167
|
+
*/
|
|
168
|
+
quotaAssets() {
|
|
169
|
+
const oracle = this.priceOracle;
|
|
170
|
+
const { underlying } = this;
|
|
171
|
+
return this.pool.pqk.quotas.entries().map(([token, quota]) => ({
|
|
172
|
+
token: this.tokensMeta.mustGetToken(token),
|
|
173
|
+
quotaRate: quota.rate,
|
|
174
|
+
limit: oracle.toAmount(underlying, quota.limit),
|
|
175
|
+
used: oracle.toAmount(underlying, quota.totalQuoted)
|
|
176
|
+
}));
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Prices and feeds of a collateral token and the market's underlying.
|
|
180
|
+
*
|
|
181
|
+
* Pricing goes through the wrapper for an RWA market, since that is what the
|
|
182
|
+
* market's oracle knows.
|
|
183
|
+
*
|
|
184
|
+
* @param collateral - Collateral token to price.
|
|
185
|
+
*/
|
|
186
|
+
priceFeedSummary(collateral) {
|
|
187
|
+
return this.priceOracle.priceFeedSummary(this.underlying, collateral);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Every opportunity this market offers: its pool, plus one row per
|
|
191
|
+
* `(credit manager, target collateral)` pair.
|
|
192
|
+
*
|
|
193
|
+
* @param totals - Resolves the summed worth of the credit accounts backing a
|
|
194
|
+
* strategy, which only a credit-account query can establish.
|
|
195
|
+
* @param filter - Optional narrowing. A filter naming a kind skips building
|
|
196
|
+
* the other kind entirely; every built row is then checked in full by
|
|
197
|
+
* {@link matchesOpportunityFilter}, so there is one definition of what each
|
|
198
|
+
* criterion means.
|
|
199
|
+
*/
|
|
200
|
+
opportunities(totals, filter) {
|
|
201
|
+
const rows = [];
|
|
202
|
+
if (filter?.kind !== "strategy") rows.push(this.poolOpportunity());
|
|
203
|
+
if (filter?.kind !== "pool") for (const { suite, collateral } of this.strategies) rows.push(suite.strategyOpportunity(collateral, totals(suite.creditManager.address, collateral)));
|
|
204
|
+
return rows.filter((row) => require_model_opportunities.matchesOpportunityFilter(row, filter));
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Passive lending into this market's pool, as the shared read model
|
|
208
|
+
* describes it.
|
|
209
|
+
*/
|
|
210
|
+
poolOpportunity() {
|
|
211
|
+
const { pool } = this.pool;
|
|
212
|
+
const oracle = this.priceOracle;
|
|
213
|
+
return {
|
|
214
|
+
kind: "pool",
|
|
215
|
+
chainId: this.chainId,
|
|
216
|
+
pool: pool.address,
|
|
217
|
+
title: `${this.underlyingToken.symbol} Pool`,
|
|
218
|
+
curator: this.curator,
|
|
219
|
+
underlyingToken: this.underlyingToken,
|
|
220
|
+
totalSupply: {
|
|
221
|
+
value: pool.totalSupply,
|
|
222
|
+
valueUsd: oracle.safeUsdValue(pool.underlying, pool.totalAssets)
|
|
223
|
+
},
|
|
224
|
+
totalBorrow: oracle.toAmount(pool.underlying, pool.totalBorrowed),
|
|
225
|
+
utilization: pool.utilization,
|
|
226
|
+
collateralTokens: this.collateralTokens,
|
|
227
|
+
paused: pool.isPaused,
|
|
228
|
+
rwa: this.rwa,
|
|
229
|
+
sunset: this.sunset
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* {@link poolOpportunity} plus the data only its detail screen needs.
|
|
234
|
+
*/
|
|
235
|
+
poolOpportunityDetail() {
|
|
236
|
+
return {
|
|
237
|
+
...this.poolOpportunity(),
|
|
238
|
+
rateCurve: this.pool.rateCurve,
|
|
239
|
+
quotaAssets: this.quotaAssets()
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Resolves a strategy of this market by its two halves.
|
|
244
|
+
*
|
|
245
|
+
* @param creditManager - Credit manager the position is opened in.
|
|
246
|
+
* @param collateral - Target collateral of the position.
|
|
247
|
+
* @throws If this market has no such credit manager, or if that manager does
|
|
248
|
+
* not accept the collateral as a strategy.
|
|
249
|
+
*/
|
|
250
|
+
mustFindStrategy(creditManager, collateral) {
|
|
251
|
+
const strategy = this.strategies.find((s) => (0, viem.isAddressEqual)(s.suite.creditManager.address, creditManager) && (0, viem.isAddressEqual)(s.collateral, collateral));
|
|
252
|
+
if (!strategy) throw new Error(`${this.labelAddress(collateral)} is not a strategy collateral of credit manager ${this.labelAddress(creditManager)}`);
|
|
253
|
+
return strategy;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Detailed view of one leveraged position of this market.
|
|
257
|
+
*
|
|
258
|
+
* @param creditManager - Credit manager the position is opened in.
|
|
259
|
+
* @param collateral - Target collateral of the position.
|
|
260
|
+
* @param totalSupply - Summed worth of the credit accounts backing it.
|
|
261
|
+
* @throws If this market has no such strategy, see {@link mustFindStrategy}.
|
|
262
|
+
*/
|
|
263
|
+
strategyOpportunityDetail(creditManager, collateral, totalSupply) {
|
|
264
|
+
return this.mustFindStrategy(creditManager, collateral).suite.strategyOpportunityDetail(collateral, totalSupply);
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
104
267
|
* Whether any child contract wrapper has observed events that require a
|
|
105
268
|
* market resync.
|
|
106
269
|
*/
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_abi_310_generated = require("../../../abi/310/generated.js");
|
|
3
3
|
const require_sdk_utils_AddressMap = require("../../utils/AddressMap.js");
|
|
4
|
+
const require_sdk_constants_math = require("../../constants/math.js");
|
|
5
|
+
require("../../constants/index.js");
|
|
4
6
|
const require_sdk_utils_formatter = require("../../utils/formatter.js");
|
|
5
7
|
require("../../utils/index.js");
|
|
6
8
|
const require_sdk_base_BaseContract = require("../../base/BaseContract.js");
|
|
7
9
|
require("../../base/index.js");
|
|
8
10
|
const require_sdk_market_adapters_createAdapter = require("../adapters/createAdapter.js");
|
|
9
11
|
require("../adapters/index.js");
|
|
12
|
+
const require_sdk_market_math = require("../math.js");
|
|
13
|
+
let viem = require("viem");
|
|
10
14
|
//#region src/sdk/market/credit/CreditManagerV310Contract.ts
|
|
11
15
|
const abi = require_abi_310_generated.iCreditManagerV310Abi;
|
|
12
16
|
var CreditManagerV310Contract = class extends require_sdk_base_BaseContract.BaseContract {
|
|
@@ -60,6 +64,28 @@ var CreditManagerV310Contract = class extends require_sdk_base_BaseContract.Base
|
|
|
60
64
|
get collateralTokens() {
|
|
61
65
|
return this.liquidationThresholds.keys();
|
|
62
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* {@inheritDoc ICreditManagerContract.leverageableCollaterals}
|
|
69
|
+
*/
|
|
70
|
+
get leverageableCollaterals() {
|
|
71
|
+
return this.collateralTokens.filter((token) => {
|
|
72
|
+
if ((0, viem.isAddressEqual)(token, this.underlying)) return false;
|
|
73
|
+
const lt = this.liquidationThresholds.get(token);
|
|
74
|
+
return !!lt && lt > 0 && lt < Number(10000n);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* {@inheritDoc ICreditManagerContract.maxLeverage}
|
|
79
|
+
*/
|
|
80
|
+
maxLeverage(collateral) {
|
|
81
|
+
return require_sdk_market_math.maxLeverage(this.liquidationThresholds.mustGet(collateral));
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* {@inheritDoc ICreditManagerContract.liquidationPremium}
|
|
85
|
+
*/
|
|
86
|
+
get liquidationPremium() {
|
|
87
|
+
return Number(require_sdk_constants_math.PERCENTAGE_FACTOR) - this.liquidationDiscount;
|
|
88
|
+
}
|
|
63
89
|
processLog(log) {
|
|
64
90
|
switch (log.eventName) {
|
|
65
91
|
case "SetCreditConfigurator": this.dirty = true;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sdk_utils_bigint_math = require("../../utils/bigint-math.js");
|
|
3
|
+
const require_sdk_chain_chains = require("../../chain/chains.js");
|
|
4
|
+
require("../../constants/math.js");
|
|
5
|
+
require("../../constants/index.js");
|
|
2
6
|
const require_sdk_base_SDKConstruct = require("../../base/SDKConstruct.js");
|
|
3
7
|
require("../../base/index.js");
|
|
8
|
+
const require_sdk_market_math = require("../math.js");
|
|
4
9
|
const require_sdk_market_credit_createCreditConfigurator = require("./createCreditConfigurator.js");
|
|
5
10
|
const require_sdk_market_credit_createCreditFacade = require("./createCreditFacade.js");
|
|
6
11
|
const require_sdk_market_credit_createCreditManager = require("./createCreditManager.js");
|
|
@@ -99,6 +104,103 @@ var CreditSuite = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
|
99
104
|
return this.creditFacade.expirable && this.creditFacade.expirationDate > 0 && this.creditFacade.expirationDate < this.sdk.timestamp;
|
|
100
105
|
}
|
|
101
106
|
/**
|
|
107
|
+
* Moment the facade expires, after which positions can no longer be opened
|
|
108
|
+
* and open ones become liquidatable, or `null` when it is not expirable.
|
|
109
|
+
*
|
|
110
|
+
* @remarks
|
|
111
|
+
* The facade stores `0` for a non-expirable suite, which as a timestamp
|
|
112
|
+
* would read as 1970 rather than as "never".
|
|
113
|
+
*/
|
|
114
|
+
get expirationDate() {
|
|
115
|
+
const { expirationDate } = this.creditFacade;
|
|
116
|
+
return expirationDate > 0 ? expirationDate : null;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Whether this suite can be used right now. A paused pool blocks borrowing,
|
|
120
|
+
* so the suite is unusable even when its own facade is live.
|
|
121
|
+
*/
|
|
122
|
+
get isPaused() {
|
|
123
|
+
return this.creditFacade.isPaused || this.market.pool.isPaused;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Collateral tokens a leveraged position can be built around in this suite:
|
|
127
|
+
* the ones the credit manager can lever up, narrowed to those the market
|
|
128
|
+
* still accepts quota for.
|
|
129
|
+
*/
|
|
130
|
+
get strategyCollaterals() {
|
|
131
|
+
const { pqk } = this.market.pool;
|
|
132
|
+
return this.creditManager.leverageableCollaterals.filter((token) => pqk.hasActiveQuota(token));
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Largest debt a single new position can take on right now: the tightest of
|
|
136
|
+
* this manager's remaining debt limit, the pool's free liquidity and the
|
|
137
|
+
* facade's per-account maximum.
|
|
138
|
+
*/
|
|
139
|
+
get maxBorrowAmount() {
|
|
140
|
+
const { pool } = this.market.pool;
|
|
141
|
+
const debtParams = pool.creditManagerDebtParams.get(this.creditManager.address);
|
|
142
|
+
return require_sdk_utils_bigint_math.BigIntMath.min(debtParams?.available ?? 115792089237316195423570985008687907853269984665640564039457584007913129639935n, pool.availableLiquidity, this.creditFacade.maxDebt);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Describes a leveraged position built on one collateral token as the shared
|
|
146
|
+
* read model does.
|
|
147
|
+
*
|
|
148
|
+
* @param collateral - Target collateral of the position.
|
|
149
|
+
* @param totalSupply - Summed worth of the credit accounts backing it, which
|
|
150
|
+
* only a credit-account query can establish. Defaults to zero, so a caller
|
|
151
|
+
* that does not care about size can omit it.
|
|
152
|
+
* @throws If the credit manager does not value the collateral.
|
|
153
|
+
*/
|
|
154
|
+
strategyOpportunity(collateral, totalSupply_) {
|
|
155
|
+
const totalSupply = totalSupply_ ?? {
|
|
156
|
+
value: 0n,
|
|
157
|
+
valueUsd: 0
|
|
158
|
+
};
|
|
159
|
+
const { market, creditManager: cm } = this;
|
|
160
|
+
const { pool } = market.pool;
|
|
161
|
+
const oracle = market.priceOracle;
|
|
162
|
+
const liquidationThreshold = cm.liquidationThresholds.mustGet(collateral);
|
|
163
|
+
const maxLeverage = cm.maxLeverage(collateral);
|
|
164
|
+
const borrowed = pool.creditManagerDebtParams.get(cm.address)?.borrowed ?? 0n;
|
|
165
|
+
return {
|
|
166
|
+
kind: "strategy",
|
|
167
|
+
chainId: this.chainId,
|
|
168
|
+
creditManager: cm.address,
|
|
169
|
+
targetCollateral: this.tokensMeta.mustGetToken(collateral),
|
|
170
|
+
title: `${this.tokensMeta.symbol(collateral)} / ${market.underlyingToken.symbol}`,
|
|
171
|
+
curator: market.curator,
|
|
172
|
+
underlyingToken: market.underlyingToken,
|
|
173
|
+
totalSupply,
|
|
174
|
+
totalBorrow: oracle.toAmount(pool.underlying, borrowed),
|
|
175
|
+
utilization: require_sdk_market_math.utilizationBps(borrowed, totalSupply.value),
|
|
176
|
+
collateralTokens: market.collateralTokens,
|
|
177
|
+
paused: this.isPaused,
|
|
178
|
+
rwa: market.rwa,
|
|
179
|
+
sunset: require_sdk_chain_chains.isSunsetStrategy(cm.address, collateral, this.sdk.networkType),
|
|
180
|
+
liquidationThreshold,
|
|
181
|
+
liquidationPremium: cm.liquidationPremium,
|
|
182
|
+
liquidationFee: cm.feeLiquidation,
|
|
183
|
+
expirationDate: this.expirationDate,
|
|
184
|
+
borrowApy: require_sdk_market_math.borrowApyBps(pool.baseInterestRate, cm.feeInterest),
|
|
185
|
+
additionalBorrowApy: require_sdk_market_math.additionalBorrowApyBps(market.pool.pqk.quotaRate(collateral), maxLeverage),
|
|
186
|
+
maxBorrowAmount: oracle.toAmount(pool.underlying, this.maxBorrowAmount),
|
|
187
|
+
maxLeverage
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* {@link strategyOpportunity} plus the data only its detail screen needs.
|
|
192
|
+
*
|
|
193
|
+
* @param collateral - Target collateral of the position.
|
|
194
|
+
* @param totalSupply - Summed worth of the credit accounts backing it.
|
|
195
|
+
*/
|
|
196
|
+
strategyOpportunityDetail(collateral, totalSupply) {
|
|
197
|
+
return {
|
|
198
|
+
...this.strategyOpportunity(collateral, totalSupply),
|
|
199
|
+
rateCurve: this.market.pool.rateCurve,
|
|
200
|
+
priceFeeds: this.market.priceFeedSummary(collateral)
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
102
204
|
* Whether the facade, manager, or configurator has observed logs that require
|
|
103
205
|
* a credit-suite resync.
|
|
104
206
|
*/
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sdk_constants_math = require("../constants/math.js");
|
|
3
|
+
//#region src/sdk/market/math.ts
|
|
4
|
+
/**
|
|
5
|
+
* Conversions between the units the protocol stores and the basis points the
|
|
6
|
+
* read model exposes.
|
|
7
|
+
*
|
|
8
|
+
* These live here rather than inside the service so that the on-chain adapter,
|
|
9
|
+
* the merger and any future consumer of the read model share one definition of
|
|
10
|
+
* every derived value.
|
|
11
|
+
**/
|
|
12
|
+
const FULL = Number(require_sdk_constants_math.PERCENTAGE_FACTOR);
|
|
13
|
+
/**
|
|
14
|
+
* Converts a ray-scaled rate (`10 ** 27` = 100%) to basis points, truncating
|
|
15
|
+
* towards zero.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* rayToBps(50_000_000_000_000_000_000_000_000n) // 500, i.e. 5%
|
|
20
|
+
* ```
|
|
21
|
+
**/
|
|
22
|
+
function rayToBps(ray) {
|
|
23
|
+
return Number(ray * require_sdk_constants_math.PERCENTAGE_FACTOR / require_sdk_constants_math.RAY);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Converts a USD value in the oracle's 8-decimal fixed point to a float.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* usdToNumber(150_050_000_000n) // 1500.5
|
|
31
|
+
* ```
|
|
32
|
+
**/
|
|
33
|
+
function usdToNumber(usd) {
|
|
34
|
+
return Number(usd) / Number(require_sdk_constants_math.PRICE_DECIMALS);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Share of capital currently borrowed, in basis points. Returns `0` when there
|
|
38
|
+
* is nothing to borrow from, and never exceeds 100%.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* utilizationBps(750n, 1000n) // 7500, i.e. 75%
|
|
43
|
+
* ```
|
|
44
|
+
**/
|
|
45
|
+
function utilizationBps(borrowed, total) {
|
|
46
|
+
if (total <= 0n || borrowed <= 0n) return 0;
|
|
47
|
+
const utilization = Number(borrowed * require_sdk_constants_math.PERCENTAGE_FACTOR / total);
|
|
48
|
+
return Math.min(utilization, FULL);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Annual cost of debt for a credit manager, in basis points: the pool's base
|
|
52
|
+
* rate plus the protocol's cut of the accrued interest.
|
|
53
|
+
*
|
|
54
|
+
* @param baseInterestRate - Pool base rate in ray.
|
|
55
|
+
* @param feeInterest - Credit manager interest fee in basis points.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* // 5% base rate, 50% interest fee
|
|
60
|
+
* borrowApyBps(50_000_000_000_000_000_000_000_000n, 5000) // 750, i.e. 7.5%
|
|
61
|
+
* ```
|
|
62
|
+
**/
|
|
63
|
+
function borrowApyBps(baseInterestRate, feeInterest) {
|
|
64
|
+
return rayToBps(baseInterestRate * (require_sdk_constants_math.PERCENTAGE_FACTOR + BigInt(feeInterest)) / require_sdk_constants_math.PERCENTAGE_FACTOR);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Highest leverage a liquidation threshold allows: `1 / (1 - lt)`.
|
|
68
|
+
*
|
|
69
|
+
* A threshold of 100% or more would allow unbounded leverage; such tokens are
|
|
70
|
+
* not strategies and are filtered out before this is called, so the guard here
|
|
71
|
+
* only exists to keep the function total.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* maxLeverage(9000) // 10
|
|
76
|
+
* maxLeverage(8000) // 5
|
|
77
|
+
* ```
|
|
78
|
+
**/
|
|
79
|
+
function maxLeverage(liquidationThreshold) {
|
|
80
|
+
const equity = FULL - liquidationThreshold;
|
|
81
|
+
return equity > 0 ? FULL / equity : Number.POSITIVE_INFINITY;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Annual quota cost scaled to the debt a maximally leveraged position carries,
|
|
85
|
+
* in basis points. Every unit of own capital carries `maxLeverage - 1` units of
|
|
86
|
+
* debt, and the quota is paid on the whole quoted position.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* // 2.5% quota rate at 5x leverage
|
|
91
|
+
* additionalBorrowApyBps(250, 5) // 1000, i.e. 10%
|
|
92
|
+
* ```
|
|
93
|
+
**/
|
|
94
|
+
function additionalBorrowApyBps(quotaRate, leverage) {
|
|
95
|
+
if (!Number.isFinite(leverage)) return 0;
|
|
96
|
+
return Math.round(quotaRate * Math.max(leverage - 1, 0));
|
|
97
|
+
}
|
|
98
|
+
//#endregion
|
|
99
|
+
exports.additionalBorrowApyBps = additionalBorrowApyBps;
|
|
100
|
+
exports.borrowApyBps = borrowApyBps;
|
|
101
|
+
exports.maxLeverage = maxLeverage;
|
|
102
|
+
exports.rayToBps = rayToBps;
|
|
103
|
+
exports.usdToNumber = usdToNumber;
|
|
104
|
+
exports.utilizationBps = utilizationBps;
|
|
@@ -7,6 +7,7 @@ const require_sdk_utils_formatter = require("../../utils/formatter.js");
|
|
|
7
7
|
require("../../utils/index.js");
|
|
8
8
|
const require_sdk_base_BaseContract = require("../../base/BaseContract.js");
|
|
9
9
|
require("../../base/index.js");
|
|
10
|
+
const require_sdk_market_math = require("../math.js");
|
|
10
11
|
const require_sdk_market_pricefeeds_PriceFeedRef = require("../pricefeeds/PriceFeedRef.js");
|
|
11
12
|
const require_abi_compressors_priceFeedCompressor = require("../../../abi/compressors/priceFeedCompressor.js");
|
|
12
13
|
require("../pricefeeds/index.js");
|
|
@@ -104,6 +105,57 @@ var PriceOracleBaseContract = class extends require_sdk_base_BaseContract.BaseCo
|
|
|
104
105
|
return amount * 10n ** BigInt(this.tokensMeta.decimals(to)) / price;
|
|
105
106
|
}
|
|
106
107
|
/**
|
|
108
|
+
* {@inheritDoc IPriceOracleContract.safeUsdValue}
|
|
109
|
+
**/
|
|
110
|
+
safeUsdValue(token, amount) {
|
|
111
|
+
try {
|
|
112
|
+
return require_sdk_market_math.usdToNumber(this.convertToUSD(token, amount));
|
|
113
|
+
} catch (e) {
|
|
114
|
+
this.logger?.debug(`cannot price ${this.labelAddress(token)}: ${e}`);
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* {@inheritDoc IPriceOracleContract.toAmount}
|
|
120
|
+
**/
|
|
121
|
+
toAmount = (token, value) => {
|
|
122
|
+
return {
|
|
123
|
+
value,
|
|
124
|
+
valueUsd: this.safeUsdValue(token, value)
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* {@inheritDoc IPriceOracleContract.toTokenAmount}
|
|
129
|
+
**/
|
|
130
|
+
toTokenAmount = (token, value) => {
|
|
131
|
+
return {
|
|
132
|
+
token: this.tokensMeta.mustGetToken(token),
|
|
133
|
+
...this.toAmount(token, value)
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* {@inheritDoc IPriceOracleContract.priceFeedData}
|
|
138
|
+
**/
|
|
139
|
+
priceFeedData(token) {
|
|
140
|
+
const ref = this.mainPriceFeeds.get(token);
|
|
141
|
+
if (!ref) throw new Error(`no main price feed for ${this.labelAddress(token)} in oracle ${this.labelAddress(this.address)}`);
|
|
142
|
+
return ref.priceFeed.describe();
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* {@inheritDoc IPriceOracleContract.priceFeedSummary}
|
|
146
|
+
**/
|
|
147
|
+
priceFeedSummary(underlying, collateral) {
|
|
148
|
+
const collateralUnit = 10n ** BigInt(this.tokensMeta.decimals(collateral));
|
|
149
|
+
const underlyingUnit = 10n ** BigInt(this.tokensMeta.decimals(underlying));
|
|
150
|
+
return {
|
|
151
|
+
underlyingPriceInUsd: require_sdk_market_math.usdToNumber(this.mainPrice(underlying)),
|
|
152
|
+
collateralPriceInUsd: require_sdk_market_math.usdToNumber(this.mainPrice(collateral)),
|
|
153
|
+
collateralPriceInUnderlying: Number(this.convert(collateral, underlying, collateralUnit)) / Number(underlyingUnit),
|
|
154
|
+
underlyingFeed: this.priceFeedData(underlying),
|
|
155
|
+
collateralFeed: this.priceFeedData(collateral)
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
107
159
|
* {@inheritDoc IPriceOracleContract.priceFeeds}
|
|
108
160
|
**/
|
|
109
161
|
get priceFeeds() {
|
|
@@ -4,6 +4,7 @@ require("../../utils/index.js");
|
|
|
4
4
|
const require_sdk_base_BaseContract = require("../../base/BaseContract.js");
|
|
5
5
|
require("../../base/index.js");
|
|
6
6
|
const require_abi_310_iLinearInterestRateModelV310 = require("../../../abi/310/iLinearInterestRateModelV310.js");
|
|
7
|
+
const require_sdk_market_pool_math = require("./math.js");
|
|
7
8
|
let viem = require("viem");
|
|
8
9
|
//#region src/sdk/market/pool/LinearInterestRateModelContract.ts
|
|
9
10
|
const abi = require_abi_310_iLinearInterestRateModelV310.iLinearInterestRateModelV310Abi;
|
|
@@ -59,6 +60,35 @@ var LinearInterestRateModelContract = class extends require_sdk_base_BaseContrac
|
|
|
59
60
|
this.Rslope3 = Rslope3;
|
|
60
61
|
this.isBorrowingMoreU2Forbidden = isBorrowingMoreU2Forbidden;
|
|
61
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* The model's own parameters, gathered for the rate math.
|
|
65
|
+
*/
|
|
66
|
+
get params() {
|
|
67
|
+
return {
|
|
68
|
+
U1: this.U1,
|
|
69
|
+
U2: this.U2,
|
|
70
|
+
Rbase: this.Rbase,
|
|
71
|
+
Rslope1: this.Rslope1,
|
|
72
|
+
Rslope2: this.Rslope2,
|
|
73
|
+
Rslope3: this.Rslope3,
|
|
74
|
+
isBorrowingMoreU2Forbidden: this.isBorrowingMoreU2Forbidden
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The model evaluated into chart-ready points, so that no consumer has to
|
|
79
|
+
* reimplement it.
|
|
80
|
+
*/
|
|
81
|
+
rateCurve() {
|
|
82
|
+
const { params } = this;
|
|
83
|
+
return {
|
|
84
|
+
points: require_sdk_market_pool_math.rateCurveUtilizations(params).map((utilization) => ({
|
|
85
|
+
utilization,
|
|
86
|
+
supplyApy: require_sdk_market_pool_math.supplyRateAtUtilization(utilization, params),
|
|
87
|
+
borrowApy: require_sdk_market_pool_math.borrowRateAtUtilization(utilization, params)
|
|
88
|
+
})),
|
|
89
|
+
borrowingLimitUtilization: params.isBorrowingMoreU2Forbidden ? params.U2 : null
|
|
90
|
+
};
|
|
91
|
+
}
|
|
62
92
|
stateHuman(raw) {
|
|
63
93
|
return {
|
|
64
94
|
...super.stateHuman(raw),
|
|
@@ -21,6 +21,32 @@ var PoolQuotaKeeperV310Contract = class extends require_sdk_base_BaseContract.Ba
|
|
|
21
21
|
return [q.token, q];
|
|
22
22
|
}), "quotas");
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Whether the market still accepts quota for a token: a token whose quota is
|
|
26
|
+
* inactive or whose limit is exhausted can no longer back a new position.
|
|
27
|
+
*
|
|
28
|
+
* @param token - Token address.
|
|
29
|
+
*/
|
|
30
|
+
hasActiveQuota(token) {
|
|
31
|
+
const quota = this.quotas.get(token);
|
|
32
|
+
return !!quota?.isActive && quota.limit > 0n;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Every token the market still accepts quota for, see
|
|
36
|
+
* {@link hasActiveQuota}.
|
|
37
|
+
*/
|
|
38
|
+
get activeQuotaTokens() {
|
|
39
|
+
return this.quotas.keys().filter((token) => this.hasActiveQuota(token));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Annual quota rate paid on a quoted token, in basis points, or `0` when the
|
|
43
|
+
* market does not quote it.
|
|
44
|
+
*
|
|
45
|
+
* @param token - Quoted token address.
|
|
46
|
+
*/
|
|
47
|
+
quotaRate(token) {
|
|
48
|
+
return this.quotas.get(token)?.rate ?? 0;
|
|
49
|
+
}
|
|
24
50
|
stateHuman(raw = true) {
|
|
25
51
|
return {
|
|
26
52
|
...super.stateHuman(raw),
|
|
@@ -100,6 +100,34 @@ var PoolSuite = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
|
100
100
|
return this.pool.underlying;
|
|
101
101
|
}
|
|
102
102
|
/**
|
|
103
|
+
* {@inheritDoc IPoolContract.unwrappedUnderlying}
|
|
104
|
+
*/
|
|
105
|
+
get unwrappedUnderlying() {
|
|
106
|
+
return this.pool.unwrappedUnderlying;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* {@inheritDoc IPoolContract.utilization}
|
|
110
|
+
*/
|
|
111
|
+
get utilization() {
|
|
112
|
+
return this.pool.utilization;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Whether the pool is paused, which blocks borrowing across every connected
|
|
116
|
+
* credit suite.
|
|
117
|
+
*/
|
|
118
|
+
get isPaused() {
|
|
119
|
+
return this.pool.isPaused;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Interest rate curve of the pool's rate model.
|
|
123
|
+
*
|
|
124
|
+
* @throws If the market uses an interest-rate model that is not linear, and
|
|
125
|
+
* therefore has no curve the SDK can evaluate.
|
|
126
|
+
*/
|
|
127
|
+
get rateCurve() {
|
|
128
|
+
return this.linearModel.rateCurve();
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
103
131
|
* RWA factory associated with the pool's underlying, undefined for non-RWA markets.
|
|
104
132
|
*/
|
|
105
133
|
get rwaFactory() {
|
|
@@ -2,10 +2,13 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_abi_iPausable = require("../../../abi/iPausable.js");
|
|
3
3
|
const require_abi_310_generated = require("../../../abi/310/generated.js");
|
|
4
4
|
const require_sdk_utils_AddressMap = require("../../utils/AddressMap.js");
|
|
5
|
+
const require_sdk_constants_math = require("../../constants/math.js");
|
|
6
|
+
require("../../constants/index.js");
|
|
5
7
|
const require_sdk_utils_formatter = require("../../utils/formatter.js");
|
|
6
8
|
require("../../utils/index.js");
|
|
7
9
|
const require_sdk_base_BaseContract = require("../../base/BaseContract.js");
|
|
8
10
|
require("../../base/index.js");
|
|
11
|
+
const require_sdk_market_math = require("../math.js");
|
|
9
12
|
//#region src/sdk/market/pool/PoolV310Contract.ts
|
|
10
13
|
const abi = [...require_abi_310_generated.iPoolV310Abi, ...require_abi_iPausable.iPausableAbi];
|
|
11
14
|
var PoolV310Contract = class extends require_sdk_base_BaseContract.BaseContract {
|
|
@@ -32,6 +35,30 @@ var PoolV310Contract = class extends require_sdk_base_BaseContract.BaseContract
|
|
|
32
35
|
const meta = this.#sdk.tokensMeta.mustGet(this.underlying);
|
|
33
36
|
if (this.#sdk.tokensMeta.isRWAUnderlying(meta)) return this.#sdk.mustGetContract(meta.rwaFactory);
|
|
34
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* {@inheritDoc IPoolContract.borrowed}
|
|
40
|
+
*/
|
|
41
|
+
get borrowed() {
|
|
42
|
+
return this.expectedLiquidity > this.availableLiquidity ? this.expectedLiquidity - this.availableLiquidity : 0n;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* {@inheritDoc IPoolContract.totalAssets}
|
|
46
|
+
*/
|
|
47
|
+
get totalAssets() {
|
|
48
|
+
return this.totalSupply * this.dieselRate / require_sdk_constants_math.RAY;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* {@inheritDoc IPoolContract.utilization}
|
|
52
|
+
*/
|
|
53
|
+
get utilization() {
|
|
54
|
+
return require_sdk_market_math.utilizationBps(this.borrowed, this.expectedLiquidity);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* {@inheritDoc IPoolContract.unwrappedUnderlying}
|
|
58
|
+
*/
|
|
59
|
+
get unwrappedUnderlying() {
|
|
60
|
+
return this.tokensMeta.unwrapRWA(this.underlying);
|
|
61
|
+
}
|
|
35
62
|
stateHuman(raw = true) {
|
|
36
63
|
return {
|
|
37
64
|
...super.stateHuman(raw),
|