@gearbox-protocol/sdk 14.12.0-next.66 → 14.12.0-next.68
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 +77 -0
- package/dist/cjs/model/liquidations.js +23 -0
- package/dist/cjs/model/liquidations.schema.js +93 -0
- package/dist/cjs/model/opportunities.js +55 -0
- package/dist/cjs/model/opportunities.schema.js +223 -0
- package/dist/cjs/model/package.json +1 -0
- package/dist/cjs/model/positions.js +1 -0
- package/dist/cjs/model/positions.schema.js +120 -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 +161 -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 +159 -0
- package/dist/cjs/sdk/market/credit/CreditManagerV310Contract.js +26 -0
- package/dist/cjs/sdk/market/credit/CreditSuite.js +92 -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 +48 -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/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 +11 -0
- package/dist/esm/model/liquidations.js +22 -0
- package/dist/esm/model/liquidations.schema.js +85 -0
- package/dist/esm/model/opportunities.js +51 -0
- package/dist/esm/model/opportunities.schema.js +201 -0
- package/dist/esm/model/package.json +1 -0
- package/dist/esm/model/positions.js +1 -0
- package/dist/esm/model/positions.schema.js +109 -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 +164 -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 +159 -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 +92 -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 +47 -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/model/history.d.ts +105 -0
- package/dist/types/model/history.schema.d.ts +66 -0
- package/dist/types/model/index.d.ts +11 -0
- package/dist/types/model/liquidations.d.ts +238 -0
- package/dist/types/model/liquidations.schema.d.ts +294 -0
- package/dist/types/model/opportunities.d.ts +584 -0
- package/dist/types/model/opportunities.schema.d.ts +1037 -0
- package/dist/types/model/positions.d.ts +247 -0
- package/dist/types/model/positions.schema.d.ts +701 -0
- package/dist/types/model/primitives.d.ts +194 -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 +98 -1
- package/dist/types/sdk/market/credit/CreditManagerV310Contract.d.ts +14 -0
- package/dist/types/sdk/market/credit/CreditSuite.d.ts +43 -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 +42 -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,14 +1,21 @@
|
|
|
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";
|
|
6
|
+
import { rayToBps } from "./math.js";
|
|
3
7
|
import { CreditSuite } from "./credit/CreditSuite.js";
|
|
4
8
|
import "./credit/index.js";
|
|
5
9
|
import { MarketConfiguratorContract } from "./MarketConfiguratorContract.js";
|
|
10
|
+
import { matchesOpportunityFilter } from "../../model/opportunities.js";
|
|
11
|
+
import "../../model/index.js";
|
|
6
12
|
import { createLossPolicy } from "./loss-policy/createLossPolicy.js";
|
|
7
13
|
import "./loss-policy/index.js";
|
|
8
14
|
import { createPriceOracle } from "./oracle/createPriceOracle.js";
|
|
9
15
|
import "./oracle/index.js";
|
|
10
16
|
import { PoolSuite } from "./pool/PoolSuite.js";
|
|
11
17
|
import "./pool/index.js";
|
|
18
|
+
import { isAddressEqual } from "viem";
|
|
12
19
|
//#region src/sdk/market/MarketSuite.ts
|
|
13
20
|
/**
|
|
14
21
|
* Aggregates all SDK wrappers that make up one Gearbox market.
|
|
@@ -100,6 +107,158 @@ var MarketSuite = class extends SDKConstruct {
|
|
|
100
107
|
return this.pool.rwaFactory;
|
|
101
108
|
}
|
|
102
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 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 }) => 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 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 filter - Optional narrowing. A filter naming a kind skips building
|
|
194
|
+
* the other kind entirely; every built row is then checked in full by
|
|
195
|
+
* {@link matchesOpportunityFilter}, so there is one definition of what each
|
|
196
|
+
* criterion means.
|
|
197
|
+
*/
|
|
198
|
+
opportunities(filter) {
|
|
199
|
+
const rows = [];
|
|
200
|
+
if (filter?.kind !== "strategy") rows.push(this.poolOpportunity());
|
|
201
|
+
if (filter?.kind !== "pool") for (const { suite, collateral } of this.strategies) rows.push(suite.strategyOpportunity(collateral));
|
|
202
|
+
return rows.filter((row) => matchesOpportunityFilter(row, filter));
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Passive lending into this market's pool, as the shared read model
|
|
206
|
+
* describes it.
|
|
207
|
+
*/
|
|
208
|
+
poolOpportunity() {
|
|
209
|
+
const { pool } = this.pool;
|
|
210
|
+
const oracle = this.priceOracle;
|
|
211
|
+
return {
|
|
212
|
+
kind: "pool",
|
|
213
|
+
chainId: this.chainId,
|
|
214
|
+
pool: pool.address,
|
|
215
|
+
name: `${this.underlyingToken.symbol} Pool`,
|
|
216
|
+
curator: this.curator,
|
|
217
|
+
underlyingToken: this.underlyingToken,
|
|
218
|
+
totalSupply: oracle.toAmount(pool.underlying, pool.totalAssets),
|
|
219
|
+
totalBorrow: oracle.toAmount(pool.underlying, pool.totalBorrowed),
|
|
220
|
+
utilization: pool.utilization,
|
|
221
|
+
supplyApy: { organicApy: rayToBps(pool.supplyRate) },
|
|
222
|
+
collateralTokens: this.collateralTokens,
|
|
223
|
+
paused: pool.isPaused,
|
|
224
|
+
rwa: this.rwa,
|
|
225
|
+
sunset: this.sunset
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* {@link poolOpportunity} plus the data only its detail screen needs.
|
|
230
|
+
*/
|
|
231
|
+
poolOpportunityDetail() {
|
|
232
|
+
return {
|
|
233
|
+
...this.poolOpportunity(),
|
|
234
|
+
rateCurve: this.pool.rateCurve,
|
|
235
|
+
quotaAssets: this.quotaAssets()
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Resolves a strategy of this market by its two halves.
|
|
240
|
+
*
|
|
241
|
+
* @param creditManager - Credit manager the position is opened in.
|
|
242
|
+
* @param collateral - Target collateral of the position.
|
|
243
|
+
* @throws If this market has no such credit manager, or if that manager does
|
|
244
|
+
* not accept the collateral as a strategy.
|
|
245
|
+
*/
|
|
246
|
+
mustFindStrategy(creditManager, collateral) {
|
|
247
|
+
const strategy = this.strategies.find((s) => isAddressEqual(s.suite.creditManager.address, creditManager) && isAddressEqual(s.collateral, collateral));
|
|
248
|
+
if (!strategy) throw new Error(`${this.labelAddress(collateral)} is not a strategy collateral of credit manager ${this.labelAddress(creditManager)}`);
|
|
249
|
+
return strategy;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Detailed view of one leveraged position of this market.
|
|
253
|
+
*
|
|
254
|
+
* @param creditManager - Credit manager the position is opened in.
|
|
255
|
+
* @param collateral - Target collateral of the position.
|
|
256
|
+
* @throws If this market has no such strategy, see {@link mustFindStrategy}.
|
|
257
|
+
*/
|
|
258
|
+
strategyOpportunityDetail(creditManager, collateral) {
|
|
259
|
+
return this.mustFindStrategy(creditManager, collateral).suite.strategyOpportunityDetail(collateral);
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
103
262
|
* Whether any child contract wrapper has observed events that require a
|
|
104
263
|
* market resync.
|
|
105
264
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { iPausableAbi } from "../../../abi/iPausable.js";
|
|
2
1
|
import { iCreditFacadeMulticallV310Abi, iCreditFacadeV310Abi } from "../../../abi/310/generated.js";
|
|
3
2
|
import { BaseContract } from "../../base/BaseContract.js";
|
|
4
3
|
import "../../base/index.js";
|
|
4
|
+
import { iPausableAbi } from "../../../abi/iPausable.js";
|
|
5
5
|
//#region src/sdk/market/credit/CreditFacadeV310BaseContract.ts
|
|
6
6
|
const abi = [
|
|
7
7
|
...iCreditFacadeV310Abi,
|
|
@@ -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 } 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,93 @@ 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
|
+
* @throws If the credit manager does not value the collateral.
|
|
149
|
+
*/
|
|
150
|
+
strategyOpportunity(collateral) {
|
|
151
|
+
const { market, creditManager: cm } = this;
|
|
152
|
+
const { pool } = market.pool;
|
|
153
|
+
const oracle = market.priceOracle;
|
|
154
|
+
const liquidationThreshold = cm.liquidationThresholds.mustGet(collateral);
|
|
155
|
+
const maxLeverage = cm.maxLeverage(collateral);
|
|
156
|
+
const borrowed = pool.creditManagerDebtParams.get(cm.address)?.borrowed ?? 0n;
|
|
157
|
+
return {
|
|
158
|
+
kind: "strategy",
|
|
159
|
+
chainId: this.chainId,
|
|
160
|
+
creditManager: cm.address,
|
|
161
|
+
targetCollateral: this.tokensMeta.mustGetToken(collateral),
|
|
162
|
+
name: `${this.tokensMeta.symbol(collateral)} / ${market.underlyingToken.symbol}`,
|
|
163
|
+
curator: market.curator,
|
|
164
|
+
underlyingToken: market.underlyingToken,
|
|
165
|
+
totalBorrow: oracle.toAmount(pool.underlying, borrowed),
|
|
166
|
+
collateralTokens: market.collateralTokens,
|
|
167
|
+
paused: this.isPaused,
|
|
168
|
+
rwa: market.rwa,
|
|
169
|
+
sunset: isSunsetStrategy(cm.address, collateral, this.sdk.networkType),
|
|
170
|
+
liquidationThreshold,
|
|
171
|
+
liquidationPremium: cm.liquidationPremium,
|
|
172
|
+
liquidationFee: cm.feeLiquidation,
|
|
173
|
+
expirationDate: this.expirationDate,
|
|
174
|
+
borrowApy: borrowApyBps(pool.baseInterestRate, cm.feeInterest),
|
|
175
|
+
additionalBorrowApy: additionalBorrowApyBps(market.pool.pqk.quotaRate(collateral), maxLeverage),
|
|
176
|
+
maxBorrowAmount: oracle.toAmount(pool.underlying, this.maxBorrowAmount),
|
|
177
|
+
maxLeverage
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* {@link strategyOpportunity} plus the data only its detail screen needs.
|
|
182
|
+
*
|
|
183
|
+
* @param collateral - Target collateral of the position.
|
|
184
|
+
*/
|
|
185
|
+
strategyOpportunityDetail(collateral) {
|
|
186
|
+
return {
|
|
187
|
+
...this.strategyOpportunity(collateral),
|
|
188
|
+
rateCurve: this.market.pool.rateCurve,
|
|
189
|
+
priceFeeds: this.market.priceFeedSummary(collateral)
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
101
193
|
* Whether the facade, manager, or configurator has observed logs that require
|
|
102
194
|
* a credit-suite resync.
|
|
103
195
|
*/
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { PERCENTAGE_FACTOR, PRICE_DECIMALS, RAY } from "../constants/math.js";
|
|
2
|
+
//#region src/sdk/market/math.ts
|
|
3
|
+
/**
|
|
4
|
+
* Conversions between the units the protocol stores and the basis points the
|
|
5
|
+
* read model exposes.
|
|
6
|
+
*
|
|
7
|
+
* These live here rather than inside the service so that the on-chain adapter,
|
|
8
|
+
* the merger and any future consumer of the read model share one definition of
|
|
9
|
+
* every derived value.
|
|
10
|
+
**/
|
|
11
|
+
const FULL = Number(PERCENTAGE_FACTOR);
|
|
12
|
+
/**
|
|
13
|
+
* Converts a ray-scaled rate (`10 ** 27` = 100%) to basis points, truncating
|
|
14
|
+
* towards zero.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* rayToBps(50_000_000_000_000_000_000_000_000n) // 500, i.e. 5%
|
|
19
|
+
* ```
|
|
20
|
+
**/
|
|
21
|
+
function rayToBps(ray) {
|
|
22
|
+
return Number(ray * PERCENTAGE_FACTOR / RAY);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Converts a USD value in the oracle's 8-decimal fixed point to a float.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* usdToNumber(150_050_000_000n) // 1500.5
|
|
30
|
+
* ```
|
|
31
|
+
**/
|
|
32
|
+
function usdToNumber(usd) {
|
|
33
|
+
return Number(usd) / Number(PRICE_DECIMALS);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Share of capital currently borrowed, in basis points. Returns `0` when there
|
|
37
|
+
* is nothing to borrow from, and never exceeds 100%.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* utilizationBps(750n, 1000n) // 7500, i.e. 75%
|
|
42
|
+
* ```
|
|
43
|
+
**/
|
|
44
|
+
function utilizationBps(borrowed, total) {
|
|
45
|
+
if (total <= 0n || borrowed <= 0n) return 0;
|
|
46
|
+
const utilization = Number(borrowed * PERCENTAGE_FACTOR / total);
|
|
47
|
+
return Math.min(utilization, FULL);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Annual cost of debt for a credit manager, in basis points: the pool's base
|
|
51
|
+
* rate plus the protocol's cut of the accrued interest.
|
|
52
|
+
*
|
|
53
|
+
* @param baseInterestRate - Pool base rate in ray.
|
|
54
|
+
* @param feeInterest - Credit manager interest fee in basis points.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* // 5% base rate, 50% interest fee
|
|
59
|
+
* borrowApyBps(50_000_000_000_000_000_000_000_000n, 5000) // 750, i.e. 7.5%
|
|
60
|
+
* ```
|
|
61
|
+
**/
|
|
62
|
+
function borrowApyBps(baseInterestRate, feeInterest) {
|
|
63
|
+
return rayToBps(baseInterestRate * (PERCENTAGE_FACTOR + BigInt(feeInterest)) / PERCENTAGE_FACTOR);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Highest leverage a liquidation threshold allows: `1 / (1 - lt)`.
|
|
67
|
+
*
|
|
68
|
+
* A threshold of 100% or more would allow unbounded leverage; such tokens are
|
|
69
|
+
* not strategies and are filtered out before this is called, so the guard here
|
|
70
|
+
* only exists to keep the function total.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* maxLeverage(9000) // 10
|
|
75
|
+
* maxLeverage(8000) // 5
|
|
76
|
+
* ```
|
|
77
|
+
**/
|
|
78
|
+
function maxLeverage(liquidationThreshold) {
|
|
79
|
+
const equity = FULL - liquidationThreshold;
|
|
80
|
+
return equity > 0 ? FULL / equity : Number.POSITIVE_INFINITY;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Annual quota cost scaled to the debt a maximally leveraged position carries,
|
|
84
|
+
* in basis points. Every unit of own capital carries `maxLeverage - 1` units of
|
|
85
|
+
* debt, and the quota is paid on the whole quoted position.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* // 2.5% quota rate at 5x leverage
|
|
90
|
+
* additionalBorrowApyBps(250, 5) // 1000, i.e. 10%
|
|
91
|
+
* ```
|
|
92
|
+
**/
|
|
93
|
+
function additionalBorrowApyBps(quotaRate, leverage) {
|
|
94
|
+
if (!Number.isFinite(leverage)) return 0;
|
|
95
|
+
return Math.round(quotaRate * Math.max(leverage - 1, 0));
|
|
96
|
+
}
|
|
97
|
+
//#endregion
|
|
98
|
+
export { additionalBorrowApyBps, borrowApyBps, maxLeverage, rayToBps, usdToNumber, utilizationBps };
|
|
@@ -6,6 +6,7 @@ import { formatBN } from "../../utils/formatter.js";
|
|
|
6
6
|
import "../../utils/index.js";
|
|
7
7
|
import { BaseContract } from "../../base/BaseContract.js";
|
|
8
8
|
import "../../base/index.js";
|
|
9
|
+
import { usdToNumber } from "../math.js";
|
|
9
10
|
import { PriceFeedRef } from "../pricefeeds/PriceFeedRef.js";
|
|
10
11
|
import { priceFeedCompressorAbi } from "../../../abi/compressors/priceFeedCompressor.js";
|
|
11
12
|
import "../pricefeeds/index.js";
|
|
@@ -103,6 +104,57 @@ var PriceOracleBaseContract = class extends BaseContract {
|
|
|
103
104
|
return amount * 10n ** BigInt(this.tokensMeta.decimals(to)) / price;
|
|
104
105
|
}
|
|
105
106
|
/**
|
|
107
|
+
* {@inheritDoc IPriceOracleContract.safeUsdValue}
|
|
108
|
+
**/
|
|
109
|
+
safeUsdValue(token, amount) {
|
|
110
|
+
try {
|
|
111
|
+
return usdToNumber(this.convertToUSD(token, amount));
|
|
112
|
+
} catch (e) {
|
|
113
|
+
this.logger?.debug(`cannot price ${this.labelAddress(token)}: ${e}`);
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* {@inheritDoc IPriceOracleContract.toAmount}
|
|
119
|
+
**/
|
|
120
|
+
toAmount = (token, value) => {
|
|
121
|
+
return {
|
|
122
|
+
value,
|
|
123
|
+
valueUsd: this.safeUsdValue(token, value)
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* {@inheritDoc IPriceOracleContract.toTokenAmount}
|
|
128
|
+
**/
|
|
129
|
+
toTokenAmount = (token, value) => {
|
|
130
|
+
return {
|
|
131
|
+
token: this.tokensMeta.mustGetToken(token),
|
|
132
|
+
...this.toAmount(token, value)
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* {@inheritDoc IPriceOracleContract.priceFeedData}
|
|
137
|
+
**/
|
|
138
|
+
priceFeedData(token) {
|
|
139
|
+
const ref = this.mainPriceFeeds.get(token);
|
|
140
|
+
if (!ref) throw new Error(`no main price feed for ${this.labelAddress(token)} in oracle ${this.labelAddress(this.address)}`);
|
|
141
|
+
return ref.priceFeed.describe();
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* {@inheritDoc IPriceOracleContract.priceFeedSummary}
|
|
145
|
+
**/
|
|
146
|
+
priceFeedSummary(underlying, collateral) {
|
|
147
|
+
const collateralUnit = 10n ** BigInt(this.tokensMeta.decimals(collateral));
|
|
148
|
+
const underlyingUnit = 10n ** BigInt(this.tokensMeta.decimals(underlying));
|
|
149
|
+
return {
|
|
150
|
+
underlyingPriceInUsd: usdToNumber(this.mainPrice(underlying)),
|
|
151
|
+
collateralPriceInUsd: usdToNumber(this.mainPrice(collateral)),
|
|
152
|
+
collateralPriceInUnderlying: Number(this.convert(collateral, underlying, collateralUnit)) / Number(underlyingUnit),
|
|
153
|
+
underlyingFeed: this.priceFeedData(underlying),
|
|
154
|
+
collateralFeed: this.priceFeedData(collateral)
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
106
158
|
* {@inheritDoc IPriceOracleContract.priceFeeds}
|
|
107
159
|
**/
|
|
108
160
|
get priceFeeds() {
|
|
@@ -3,6 +3,7 @@ import "../../utils/index.js";
|
|
|
3
3
|
import { BaseContract } from "../../base/BaseContract.js";
|
|
4
4
|
import "../../base/index.js";
|
|
5
5
|
import { iLinearInterestRateModelV310Abi } from "../../../abi/310/iLinearInterestRateModelV310.js";
|
|
6
|
+
import { borrowRateAtUtilization, rateCurveUtilizations, supplyRateAtUtilization } from "./math.js";
|
|
6
7
|
import { decodeAbiParameters } from "viem";
|
|
7
8
|
//#region src/sdk/market/pool/LinearInterestRateModelContract.ts
|
|
8
9
|
const abi = iLinearInterestRateModelV310Abi;
|
|
@@ -58,6 +59,35 @@ var LinearInterestRateModelContract = class extends BaseContract {
|
|
|
58
59
|
this.Rslope3 = Rslope3;
|
|
59
60
|
this.isBorrowingMoreU2Forbidden = isBorrowingMoreU2Forbidden;
|
|
60
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* The model's own parameters, gathered for the rate math.
|
|
64
|
+
*/
|
|
65
|
+
get params() {
|
|
66
|
+
return {
|
|
67
|
+
U1: this.U1,
|
|
68
|
+
U2: this.U2,
|
|
69
|
+
Rbase: this.Rbase,
|
|
70
|
+
Rslope1: this.Rslope1,
|
|
71
|
+
Rslope2: this.Rslope2,
|
|
72
|
+
Rslope3: this.Rslope3,
|
|
73
|
+
isBorrowingMoreU2Forbidden: this.isBorrowingMoreU2Forbidden
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The model evaluated into chart-ready points, so that no consumer has to
|
|
78
|
+
* reimplement it.
|
|
79
|
+
*/
|
|
80
|
+
rateCurve() {
|
|
81
|
+
const { params } = this;
|
|
82
|
+
return {
|
|
83
|
+
points: rateCurveUtilizations(params).map((utilization) => ({
|
|
84
|
+
utilization,
|
|
85
|
+
supplyApy: supplyRateAtUtilization(utilization, params),
|
|
86
|
+
borrowApy: borrowRateAtUtilization(utilization, params)
|
|
87
|
+
})),
|
|
88
|
+
borrowingLimitUtilization: params.isBorrowingMoreU2Forbidden ? params.U2 : null
|
|
89
|
+
};
|
|
90
|
+
}
|
|
61
91
|
stateHuman(raw) {
|
|
62
92
|
return {
|
|
63
93
|
...super.stateHuman(raw),
|
|
@@ -20,6 +20,32 @@ var PoolQuotaKeeperV310Contract = class extends BaseContract {
|
|
|
20
20
|
return [q.token, q];
|
|
21
21
|
}), "quotas");
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Whether the market still accepts quota for a token: a token whose quota is
|
|
25
|
+
* inactive or whose limit is exhausted can no longer back a new position.
|
|
26
|
+
*
|
|
27
|
+
* @param token - Token address.
|
|
28
|
+
*/
|
|
29
|
+
hasActiveQuota(token) {
|
|
30
|
+
const quota = this.quotas.get(token);
|
|
31
|
+
return !!quota?.isActive && quota.limit > 0n;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Every token the market still accepts quota for, see
|
|
35
|
+
* {@link hasActiveQuota}.
|
|
36
|
+
*/
|
|
37
|
+
get activeQuotaTokens() {
|
|
38
|
+
return this.quotas.keys().filter((token) => this.hasActiveQuota(token));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Annual quota rate paid on a quoted token, in basis points, or `0` when the
|
|
42
|
+
* market does not quote it.
|
|
43
|
+
*
|
|
44
|
+
* @param token - Quoted token address.
|
|
45
|
+
*/
|
|
46
|
+
quotaRate(token) {
|
|
47
|
+
return this.quotas.get(token)?.rate ?? 0;
|
|
48
|
+
}
|
|
23
49
|
stateHuman(raw = true) {
|
|
24
50
|
return {
|
|
25
51
|
...super.stateHuman(raw),
|
|
@@ -99,6 +99,34 @@ var PoolSuite = class extends SDKConstruct {
|
|
|
99
99
|
return this.pool.underlying;
|
|
100
100
|
}
|
|
101
101
|
/**
|
|
102
|
+
* {@inheritDoc IPoolContract.unwrappedUnderlying}
|
|
103
|
+
*/
|
|
104
|
+
get unwrappedUnderlying() {
|
|
105
|
+
return this.pool.unwrappedUnderlying;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* {@inheritDoc IPoolContract.utilization}
|
|
109
|
+
*/
|
|
110
|
+
get utilization() {
|
|
111
|
+
return this.pool.utilization;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Whether the pool is paused, which blocks borrowing across every connected
|
|
115
|
+
* credit suite.
|
|
116
|
+
*/
|
|
117
|
+
get isPaused() {
|
|
118
|
+
return this.pool.isPaused;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Interest rate curve of the pool's rate model.
|
|
122
|
+
*
|
|
123
|
+
* @throws If the market uses an interest-rate model that is not linear, and
|
|
124
|
+
* therefore has no curve the SDK can evaluate.
|
|
125
|
+
*/
|
|
126
|
+
get rateCurve() {
|
|
127
|
+
return this.linearModel.rateCurve();
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
102
130
|
* RWA factory associated with the pool's underlying, undefined for non-RWA markets.
|
|
103
131
|
*/
|
|
104
132
|
get rwaFactory() {
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { iPausableAbi } from "../../../abi/iPausable.js";
|
|
2
1
|
import { iPoolV310Abi } from "../../../abi/310/generated.js";
|
|
3
2
|
import { AddressMap } from "../../utils/AddressMap.js";
|
|
3
|
+
import { RAY } from "../../constants/math.js";
|
|
4
|
+
import "../../constants/index.js";
|
|
4
5
|
import { formatBN, formatBNvalue, percentFmt } from "../../utils/formatter.js";
|
|
5
6
|
import "../../utils/index.js";
|
|
6
7
|
import { BaseContract } from "../../base/BaseContract.js";
|
|
7
8
|
import "../../base/index.js";
|
|
9
|
+
import { iPausableAbi } from "../../../abi/iPausable.js";
|
|
10
|
+
import { utilizationBps } from "../math.js";
|
|
8
11
|
//#region src/sdk/market/pool/PoolV310Contract.ts
|
|
9
12
|
const abi = [...iPoolV310Abi, ...iPausableAbi];
|
|
10
13
|
var PoolV310Contract = class extends BaseContract {
|
|
@@ -31,6 +34,30 @@ var PoolV310Contract = class extends BaseContract {
|
|
|
31
34
|
const meta = this.#sdk.tokensMeta.mustGet(this.underlying);
|
|
32
35
|
if (this.#sdk.tokensMeta.isRWAUnderlying(meta)) return this.#sdk.mustGetContract(meta.rwaFactory);
|
|
33
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* {@inheritDoc IPoolContract.borrowed}
|
|
39
|
+
*/
|
|
40
|
+
get borrowed() {
|
|
41
|
+
return this.expectedLiquidity > this.availableLiquidity ? this.expectedLiquidity - this.availableLiquidity : 0n;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* {@inheritDoc IPoolContract.totalAssets}
|
|
45
|
+
*/
|
|
46
|
+
get totalAssets() {
|
|
47
|
+
return this.totalSupply * this.dieselRate / RAY;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* {@inheritDoc IPoolContract.utilization}
|
|
51
|
+
*/
|
|
52
|
+
get utilization() {
|
|
53
|
+
return utilizationBps(this.borrowed, this.expectedLiquidity);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* {@inheritDoc IPoolContract.unwrappedUnderlying}
|
|
57
|
+
*/
|
|
58
|
+
get unwrappedUnderlying() {
|
|
59
|
+
return this.tokensMeta.unwrapRWA(this.underlying);
|
|
60
|
+
}
|
|
34
61
|
stateHuman(raw = true) {
|
|
35
62
|
return {
|
|
36
63
|
...super.stateHuman(raw),
|