@gearbox-protocol/sdk 14.12.0-next.78 → 14.12.0-next.79
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/model/filters.js +20 -0
- package/dist/cjs/model/filters.schema.js +21 -0
- package/dist/cjs/model/index.js +6 -0
- package/dist/cjs/model/liquidations.js +10 -8
- package/dist/cjs/model/liquidations.schema.js +6 -5
- package/dist/cjs/model/opportunities.js +11 -9
- package/dist/cjs/model/opportunities.schema.js +7 -6
- package/dist/cjs/model/positions.js +10 -8
- package/dist/cjs/model/positions.schema.js +5 -4
- package/dist/cjs/sdk/market/MarketSuite.js +5 -3
- package/dist/cjs/sdk/opportunities/MultichainOpportunitiesService.js +5 -2
- package/dist/cjs/sdk/opportunities/OpportunitiesService.js +4 -1
- package/dist/cjs/sdk/positions/MultichainPositionsService.js +5 -2
- package/dist/cjs/sdk/positions/PositionsService.js +8 -4
- package/dist/esm/dev/AccountOpener.js +1 -1
- package/dist/esm/dev/withdrawalUtils.js +1 -1
- package/dist/esm/model/filters.js +18 -0
- package/dist/esm/model/filters.schema.js +19 -0
- package/dist/esm/model/index.js +3 -1
- package/dist/esm/model/liquidations.js +10 -8
- package/dist/esm/model/liquidations.schema.js +6 -5
- package/dist/esm/model/opportunities.js +11 -9
- package/dist/esm/model/opportunities.schema.js +7 -6
- package/dist/esm/model/positions.js +10 -8
- package/dist/esm/model/positions.schema.js +5 -4
- package/dist/esm/plugins/adapters/contracts/ERC4626AdapterContract.js +1 -1
- package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
- package/dist/esm/preview/trace/extractTransfers.js +1 -1
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +2 -2
- package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +1 -1
- 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/TokensMeta.js +2 -2
- package/dist/esm/sdk/chain/detectNetwork.js +1 -1
- package/dist/esm/sdk/core/createAddressProvider.js +1 -1
- package/dist/esm/sdk/market/MarketSuite.js +5 -3
- package/dist/esm/sdk/market/credit/CreditFacadeV310BaseContract.js +1 -1
- package/dist/esm/sdk/market/pool/PoolV310Contract.js +1 -1
- 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 +5 -2
- package/dist/esm/sdk/opportunities/OpportunitiesService.js +4 -1
- package/dist/esm/sdk/pools/PoolService.js +1 -1
- package/dist/esm/sdk/positions/MultichainPositionsService.js +5 -2
- package/dist/esm/sdk/positions/PositionsService.js +8 -4
- package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +1 -1
- package/dist/types/model/filters.d.ts +30 -0
- package/dist/types/model/filters.schema.d.ts +16 -0
- package/dist/types/model/index.d.ts +3 -1
- package/dist/types/model/liquidations.d.ts +14 -10
- package/dist/types/model/liquidations.schema.d.ts +5 -5
- package/dist/types/model/opportunities.d.ts +15 -11
- package/dist/types/model/opportunities.schema.d.ts +6 -6
- package/dist/types/model/positions.d.ts +14 -10
- package/dist/types/model/positions.schema.d.ts +4 -4
- package/dist/types/sdk/accounts/credit-account-compressor/types.d.ts +3 -3
- package/dist/types/sdk/accounts/liquidations/types.d.ts +1 -1
- package/dist/types/sdk/base/types.d.ts +1 -1
- package/dist/types/sdk/market/MarketSuite.d.ts +1 -1
- package/dist/types/sdk/positions/PositionsService.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isFilterSet } from "./filters.js";
|
|
1
2
|
//#region src/model/positions.ts
|
|
2
3
|
/**
|
|
3
4
|
* Builds the canonical id of a pool position.
|
|
@@ -45,26 +46,27 @@ function positionId(position) {
|
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
48
|
/**
|
|
48
|
-
* Whether a position satisfies every
|
|
49
|
+
* Whether a position satisfies every condition of a filter.
|
|
49
50
|
*
|
|
50
|
-
* This is the single definition of what each
|
|
51
|
+
* This is the single definition of what each condition means: every source
|
|
51
52
|
* builds its rows first and runs them through here, so the chain and the
|
|
52
53
|
* backend cannot disagree on what a filter selects.
|
|
53
54
|
*
|
|
54
|
-
* A
|
|
55
|
+
* A condition that does not apply to a position's kind keeps the row rather
|
|
55
56
|
* than dropping it: `isZeroDebt` says nothing about a pool position, and
|
|
56
57
|
* `underlyingType` says nothing about a liquidation position, which is
|
|
57
58
|
* denominated in whatever its withdrawal pays out.
|
|
58
59
|
*
|
|
59
60
|
* @param position - Row to test.
|
|
60
|
-
* @param filter -
|
|
61
|
+
* @param filter - Conditions to test against. An absent filter matches
|
|
62
|
+
* anything.
|
|
61
63
|
**/
|
|
62
64
|
function matchesPositionFilter(position, filter) {
|
|
63
65
|
if (!filter) return true;
|
|
64
|
-
if (filter.kind && position.kind !== filter.kind) return false;
|
|
65
|
-
if (filter.chainIds && !filter.chainIds.includes(position.chainId)) return false;
|
|
66
|
-
if (filter.isZeroDebt
|
|
67
|
-
if (filter.underlyingType) {
|
|
66
|
+
if (isFilterSet(filter.kind) && position.kind !== filter.kind) return false;
|
|
67
|
+
if (isFilterSet(filter.chainIds) && !filter.chainIds.includes(position.chainId)) return false;
|
|
68
|
+
if (isFilterSet(filter.isZeroDebt) && position.kind === "strategy" && position.totalDebt.value === 0n !== filter.isZeroDebt) return false;
|
|
69
|
+
if (isFilterSet(filter.underlyingType)) {
|
|
68
70
|
const underlying = positionUnderlying(position);
|
|
69
71
|
if (underlying && underlying.assetType !== filter.underlyingType) return false;
|
|
70
72
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ZodAddress } from "../sdk/utils/zod.js";
|
|
2
|
+
import { filterable } from "./filters.schema.js";
|
|
2
3
|
import { assetTypeSchema, bpsSchema, chainIdSchema, leverageSchema, tokenAmountSchema, tokenSchema } from "./primitives.schema.js";
|
|
3
4
|
import { apyBreakdownSchema, pointsProgramSchema } from "./opportunities.schema.js";
|
|
4
5
|
import { delayedReceivedAssetSchema, liquidationPositionSchema } from "./liquidations.schema.js";
|
|
@@ -100,10 +101,10 @@ const positionSchema = z.discriminatedUnion("kind", [
|
|
|
100
101
|
* {@link PositionFilter}
|
|
101
102
|
**/
|
|
102
103
|
const positionFilterSchema = z.object({
|
|
103
|
-
kind: positionKindSchema.optional(),
|
|
104
|
-
isZeroDebt: z.boolean().optional(),
|
|
105
|
-
chainIds: z.array(chainIdSchema).optional(),
|
|
106
|
-
underlyingType: assetTypeSchema.optional()
|
|
104
|
+
kind: filterable(positionKindSchema).optional(),
|
|
105
|
+
isZeroDebt: filterable(z.boolean()).optional(),
|
|
106
|
+
chainIds: filterable(z.array(chainIdSchema)).optional(),
|
|
107
|
+
underlyingType: filterable(assetTypeSchema).optional()
|
|
107
108
|
});
|
|
108
109
|
/**
|
|
109
110
|
* {@link PoolPositionKey}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ierc4626AdapterAbi } from "../../../abi/ierc4626Adapter.js";
|
|
2
1
|
import { MissingSerializedParamsError } from "../../../sdk/base/errors.js";
|
|
2
|
+
import { ierc4626AdapterAbi } from "../../../abi/ierc4626Adapter.js";
|
|
3
3
|
import "../../../sdk/index.js";
|
|
4
4
|
import { fnSigToName, swapFromTransfers } from "../transferHelpers.js";
|
|
5
5
|
import { AbstractAdapterContract } from "./AbstractAdapter.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { iZapperAbi } from "../../abi/iZapper.js";
|
|
2
1
|
import { iPoolV310Abi } from "../../abi/310/generated.js";
|
|
2
|
+
import { iZapperAbi } from "../../abi/iZapper.js";
|
|
3
3
|
import { asPreviewSimulationError } from "./errors.js";
|
|
4
4
|
//#region src/preview/simulate/simulatePoolOperation.ts
|
|
5
5
|
function previewRead(operation) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ierc20Abi } from "../../abi/iERC20.js";
|
|
2
1
|
import { iCreditFacadeV310Abi } from "../../abi/310/generated.js";
|
|
3
2
|
import { AddressMap } from "../../sdk/utils/AddressMap.js";
|
|
3
|
+
import { ierc20Abi } from "../../abi/iERC20.js";
|
|
4
4
|
import "../../sdk/index.js";
|
|
5
5
|
import { UnexpectedFacadeEventOrderError } from "./errors.js";
|
|
6
6
|
import { getAddress, isAddressEqual, parseEventLogs } from "viem";
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { iBaseRewardPoolAbi } from "../../abi/iBaseRewardPool.js";
|
|
2
|
-
import { ierc4626AdapterAbi } from "../../abi/ierc4626Adapter.js";
|
|
3
1
|
import { AP_REWARDS_COMPRESSOR } from "../constants/address-provider.js";
|
|
4
2
|
import { ADDRESS_0X0 } from "../constants/addresses.js";
|
|
5
3
|
import { MAX_UINT256 } from "../constants/math.js";
|
|
@@ -10,6 +8,8 @@ import "../base/index.js";
|
|
|
10
8
|
import { AccountBotsService } from "./bots/AccountBotsService.js";
|
|
11
9
|
import "./bots/index.js";
|
|
12
10
|
import { rewardsCompressorAbi } from "../../abi/compressors/rewardsCompressor.js";
|
|
11
|
+
import { iBaseRewardPoolAbi } from "../../abi/iBaseRewardPool.js";
|
|
12
|
+
import { ierc4626AdapterAbi } from "../../abi/ierc4626Adapter.js";
|
|
13
13
|
import { expectedBalanceDeltas } from "../market/credit/expectedBalanceDeltas.js";
|
|
14
14
|
import "../market/index.js";
|
|
15
15
|
import { CreditAccountCompressor } from "./credit-account-compressor/CreditAccountCompressor.js";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { iLiquidationCompressorV313Abi } from "../../../abi/ILiquidationCompressorV313.js";
|
|
2
1
|
import { AddressSet } from "../../utils/AddressSet.js";
|
|
3
2
|
import { bytes32ToString } from "../../utils/bytes32ToString.js";
|
|
4
3
|
import { ADDRESS_0X0 } from "../../constants/addresses.js";
|
|
@@ -20,6 +19,7 @@ import { SecuritizeLiquidatorContract } from "../../market/rwa/securitize/Securi
|
|
|
20
19
|
import "../../market/rwa/securitize/index.js";
|
|
21
20
|
import "../../market/index.js";
|
|
22
21
|
import { LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS } from "./constants.js";
|
|
22
|
+
import { iLiquidationCompressorV313Abi } from "../../../abi/ILiquidationCompressorV313.js";
|
|
23
23
|
//#region src/sdk/accounts/liquidations/LiquidationsService.ts
|
|
24
24
|
/**
|
|
25
25
|
* Service for discovering liquidatable credit accounts and previewing manual
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { iRedemptionLoggerV310Abi } from "../../../abi/iRedemptionLoggerV310.js";
|
|
2
1
|
import { BaseContract } from "../../base/BaseContract.js";
|
|
3
2
|
import "../../base/index.js";
|
|
4
3
|
import { decodeDelayedIntent } from "./intent-codec.js";
|
|
4
|
+
import { iRedemptionLoggerV310Abi } from "../../../abi/iRedemptionLoggerV310.js";
|
|
5
5
|
import { InvalidDelayedIntentError } from "./errors.js";
|
|
6
6
|
//#region src/sdk/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.ts
|
|
7
7
|
const abi = iRedemptionLoggerV310Abi;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { iWithdrawalCompressorV310Abi } from "../../../abi/IWithdrawalCompressorV310.js";
|
|
2
1
|
import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
|
|
2
|
+
import { iWithdrawalCompressorV310Abi } from "../../../abi/IWithdrawalCompressorV310.js";
|
|
3
3
|
//#region src/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.ts
|
|
4
4
|
const abi = iWithdrawalCompressorV310Abi;
|
|
5
5
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { iWithdrawalCompressorV311Abi } from "../../../abi/IWithdrawalCompressorV311.js";
|
|
2
1
|
import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
|
|
2
|
+
import { iWithdrawalCompressorV311Abi } from "../../../abi/IWithdrawalCompressorV311.js";
|
|
3
3
|
//#region src/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.ts
|
|
4
4
|
const abi = iWithdrawalCompressorV311Abi;
|
|
5
5
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { iWithdrawalCompressorV313Abi } from "../../../abi/IWithdrawalCompressorV313.js";
|
|
2
1
|
import { encodeDelayedIntent } from "./intent-codec.js";
|
|
3
2
|
import { AbstractWithdrawalCompressorContract, iCreditAccountAbi, toClaimableWithdrawal, toPendingWithdrawal, toRequestableWithdrawal } from "./AbstractWithdrawalCompressorContract.js";
|
|
3
|
+
import { iWithdrawalCompressorV313Abi } from "../../../abi/IWithdrawalCompressorV313.js";
|
|
4
4
|
import { toWithdrawalStatus } from "./types.js";
|
|
5
5
|
//#region src/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.ts
|
|
6
6
|
const abi = iWithdrawalCompressorV313Abi;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { iStateSerializerAbi } from "../../abi/iStateSerializer.js";
|
|
2
|
-
import { iVersionAbi } from "../../abi/iVersion.js";
|
|
3
1
|
import { AddressMap } from "../utils/AddressMap.js";
|
|
4
2
|
import { AddressSet } from "../utils/AddressSet.js";
|
|
5
3
|
import { bytes32ToString } from "../utils/bytes32ToString.js";
|
|
6
4
|
import { getAssetType } from "../chain/chains.js";
|
|
7
5
|
import { formatBN } from "../utils/formatter.js";
|
|
8
6
|
import "../utils/index.js";
|
|
7
|
+
import { iStateSerializerAbi } from "../../abi/iStateSerializer.js";
|
|
8
|
+
import { iVersionAbi } from "../../abi/iVersion.js";
|
|
9
9
|
//#region src/sdk/base/TokensMeta.ts
|
|
10
10
|
/**
|
|
11
11
|
* Registry of token metadata (symbol, decimals, phantom type) keyed by address.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { iVersionAbi } from "../../abi/iVersion.js";
|
|
2
1
|
import { AP_MARKET_COMPRESSOR, AP_PRICE_FEED_COMPRESSOR } from "../constants/address-provider.js";
|
|
3
2
|
import { isV310 } from "../constants/versions.js";
|
|
4
3
|
import "../constants/index.js";
|
|
5
4
|
import { hexEq } from "../utils/hex.js";
|
|
5
|
+
import { iVersionAbi } from "../../abi/iVersion.js";
|
|
6
6
|
import { AddressProviderV310Contract } from "./AddressProviderV310Contract.js";
|
|
7
7
|
//#region src/sdk/core/createAddressProvider.ts
|
|
8
8
|
const OVERRIDE_ADDRESSES = { Mainnet: {
|
|
@@ -7,6 +7,7 @@ import { rayToBps } from "./math.js";
|
|
|
7
7
|
import { CreditSuite } from "./credit/CreditSuite.js";
|
|
8
8
|
import "./credit/index.js";
|
|
9
9
|
import { MarketConfiguratorContract } from "./MarketConfiguratorContract.js";
|
|
10
|
+
import { isFilterSet } from "../../model/filters.js";
|
|
10
11
|
import { matchesOpportunityFilter } from "../../model/opportunities.js";
|
|
11
12
|
import "../../model/index.js";
|
|
12
13
|
import { createLossPolicy } from "./loss-policy/createLossPolicy.js";
|
|
@@ -199,12 +200,13 @@ var MarketSuite = class extends SDKConstruct {
|
|
|
199
200
|
* @param filter - Optional narrowing. A filter naming a kind skips building
|
|
200
201
|
* the other kind entirely; every built row is then checked in full by
|
|
201
202
|
* {@link matchesOpportunityFilter}, so there is one definition of what each
|
|
202
|
-
*
|
|
203
|
+
* condition means.
|
|
203
204
|
*/
|
|
204
205
|
opportunities(filter) {
|
|
205
206
|
const rows = [];
|
|
206
|
-
|
|
207
|
-
if (
|
|
207
|
+
const kind = filter?.kind;
|
|
208
|
+
if (!isFilterSet(kind) || kind === "pool") rows.push(this.poolOpportunity());
|
|
209
|
+
if (!isFilterSet(kind) || kind === "strategy") for (const { suite, collateral } of this.strategies) rows.push(suite.strategyOpportunity(collateral));
|
|
208
210
|
return rows.filter((row) => matchesOpportunityFilter(row, filter));
|
|
209
211
|
}
|
|
210
212
|
/**
|
|
@@ -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,4 +1,3 @@
|
|
|
1
|
-
import { iPausableAbi } from "../../../abi/iPausable.js";
|
|
2
1
|
import { iPoolV310Abi } from "../../../abi/310/generated.js";
|
|
3
2
|
import { AddressMap } from "../../utils/AddressMap.js";
|
|
4
3
|
import { RAY } from "../../constants/math.js";
|
|
@@ -7,6 +6,7 @@ import { formatBN, formatBNvalue, percentFmt } from "../../utils/formatter.js";
|
|
|
7
6
|
import "../../utils/index.js";
|
|
8
7
|
import { BaseContract } from "../../base/BaseContract.js";
|
|
9
8
|
import "../../base/index.js";
|
|
9
|
+
import { iPausableAbi } from "../../../abi/iPausable.js";
|
|
10
10
|
import { utilizationBps } from "../math.js";
|
|
11
11
|
//#region src/sdk/market/pool/PoolV310Contract.ts
|
|
12
12
|
const abi = [...iPoolV310Abi, ...iPausableAbi];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { iethZapperAbi } from "../../../abi/iETHZapper.js";
|
|
2
1
|
import { ZapperContract } from "./ZapperContract.js";
|
|
2
|
+
import { iethZapperAbi } from "../../../abi/iETHZapper.js";
|
|
3
3
|
//#region src/sdk/market/zapper/IETHZapperContract.ts
|
|
4
4
|
const abi = iethZapperAbi;
|
|
5
5
|
var IETHZapperContract = class extends ZapperContract {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { iZapperAbi } from "../../../abi/iZapper.js";
|
|
2
1
|
import { BaseContract } from "../../base/BaseContract.js";
|
|
3
2
|
import "../../base/index.js";
|
|
3
|
+
import { iZapperAbi } from "../../../abi/iZapper.js";
|
|
4
4
|
import { UnsupportedZapperFunctionError } from "./errors.js";
|
|
5
5
|
//#region src/sdk/market/zapper/ZapperContract.ts
|
|
6
6
|
/**
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { getNetworkType } from "../chain/chains.js";
|
|
2
2
|
import { MultichainConstruct } from "../base/MultichainConstruct.js";
|
|
3
3
|
import "../base/index.js";
|
|
4
|
+
import { isFilterSet } from "../../model/filters.js";
|
|
5
|
+
import "../../model/index.js";
|
|
4
6
|
//#region src/sdk/opportunities/MultichainOpportunitiesService.ts
|
|
5
7
|
/**
|
|
6
8
|
* Cross-chain counterpart of {@link OpportunitiesService}.
|
|
@@ -45,9 +47,10 @@ var MultichainOpportunitiesService = class extends MultichainConstruct {
|
|
|
45
47
|
* a filter naming them is a narrowing, not a request.
|
|
46
48
|
**/
|
|
47
49
|
#networksOf(filter) {
|
|
48
|
-
|
|
50
|
+
const chainIds = filter?.chainIds;
|
|
51
|
+
if (!isFilterSet(chainIds)) return;
|
|
49
52
|
const networks = [];
|
|
50
|
-
for (const chainId of
|
|
53
|
+
for (const chainId of chainIds) try {
|
|
51
54
|
networks.push(getNetworkType(chainId));
|
|
52
55
|
} catch {
|
|
53
56
|
this.sdk.logger?.debug(`ignoring unsupported chain ${chainId} in opportunities filter`);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { SDKConstruct } from "../base/SDKConstruct.js";
|
|
2
2
|
import "../base/index.js";
|
|
3
|
+
import { isFilterSet } from "../../model/filters.js";
|
|
4
|
+
import "../../model/index.js";
|
|
3
5
|
//#region src/sdk/opportunities/OpportunitiesService.ts
|
|
4
6
|
/**
|
|
5
7
|
* Builds the `opportunities` read model from the chain.
|
|
@@ -21,7 +23,8 @@ var OpportunitiesService = class extends SDKConstruct {
|
|
|
21
23
|
* @param filter - Optional narrowing, applied to the built rows.
|
|
22
24
|
**/
|
|
23
25
|
async list(filter) {
|
|
24
|
-
|
|
26
|
+
const chainIds = filter?.chainIds;
|
|
27
|
+
if (isFilterSet(chainIds) && !chainIds.includes(this.chainId)) return [];
|
|
25
28
|
return this.sdk.marketRegister.markets.flatMap((market) => market.opportunities(filter));
|
|
26
29
|
}
|
|
27
30
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ierc20Abi } from "../../abi/iERC20.js";
|
|
2
1
|
import { AddressSet } from "../utils/AddressSet.js";
|
|
2
|
+
import { ierc20Abi } from "../../abi/iERC20.js";
|
|
3
3
|
import "../constants/addresses.js";
|
|
4
4
|
import { RAY } from "../constants/math.js";
|
|
5
5
|
import "../constants/index.js";
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { getNetworkType } from "../chain/chains.js";
|
|
2
2
|
import { MultichainConstruct } from "../base/MultichainConstruct.js";
|
|
3
3
|
import "../base/index.js";
|
|
4
|
+
import { isFilterSet } from "../../model/filters.js";
|
|
5
|
+
import "../../model/index.js";
|
|
4
6
|
//#region src/sdk/positions/MultichainPositionsService.ts
|
|
5
7
|
/**
|
|
6
8
|
* Cross-chain counterpart of {@link PositionsService}.
|
|
@@ -33,9 +35,10 @@ var MultichainPositionsService = class extends MultichainConstruct {
|
|
|
33
35
|
* a filter naming them is a narrowing, not a request.
|
|
34
36
|
**/
|
|
35
37
|
#networksOf(filter) {
|
|
36
|
-
|
|
38
|
+
const chainIds = filter?.chainIds;
|
|
39
|
+
if (!isFilterSet(chainIds)) return;
|
|
37
40
|
const networks = [];
|
|
38
|
-
for (const chainId of
|
|
41
|
+
for (const chainId of chainIds) try {
|
|
39
42
|
networks.push(getNetworkType(chainId));
|
|
40
43
|
} catch {
|
|
41
44
|
this.sdk.logger?.debug(`ignoring unsupported chain ${chainId} in positions filter`);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SDKConstruct } from "../base/SDKConstruct.js";
|
|
2
2
|
import "../base/index.js";
|
|
3
|
+
import { isFilterSet } from "../../model/filters.js";
|
|
3
4
|
import { matchesPositionFilter } from "../../model/positions.js";
|
|
4
5
|
import "../../model/index.js";
|
|
5
6
|
//#region src/sdk/positions/PositionsService.ts
|
|
@@ -12,18 +13,21 @@ var PositionsService = class extends SDKConstruct {
|
|
|
12
13
|
/**
|
|
13
14
|
* Every position of a wallet on this chain, optionally narrowed by
|
|
14
15
|
* {@link PositionFilter} (see {@link matchesPositionFilter} for what each
|
|
15
|
-
*
|
|
16
|
+
* condition selects). Reads live chain state, so rows reflect the moment of
|
|
16
17
|
* the call rather than the SDK's loaded snapshot.
|
|
17
18
|
**/
|
|
18
19
|
async list(props) {
|
|
19
20
|
const { wallet, filter } = props;
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
const chainIds = filter?.chainIds;
|
|
22
|
+
if (isFilterSet(chainIds) && !chainIds.includes(this.chainId)) return [];
|
|
23
|
+
const wantedKind = filter?.kind;
|
|
24
|
+
const wanted = (kind) => !isFilterSet(wantedKind) || wantedKind === kind;
|
|
25
|
+
const isZeroDebt = filter?.isZeroDebt;
|
|
22
26
|
const [pool, strategy, liquidation] = await Promise.all([
|
|
23
27
|
wanted("pool") ? this.sdk.pools.listPositions({ wallet }) : Promise.resolve([]),
|
|
24
28
|
wanted("strategy") ? this.sdk.accounts.listPositions({
|
|
25
29
|
owner: wallet,
|
|
26
|
-
includeZeroDebt:
|
|
30
|
+
includeZeroDebt: !isFilterSet(isZeroDebt) || isZeroDebt
|
|
27
31
|
}) : Promise.resolve([]),
|
|
28
32
|
wanted("liquidation") ? this.sdk.liquidations.getLiquidationPositions({ liquidator: wallet }) : Promise.resolve([])
|
|
29
33
|
]);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { errorAbis } from "../../../abi/errors.js";
|
|
2
|
-
import { iUpdatablePriceFeedAbi } from "../../../abi/iUpdatablePriceFeed.js";
|
|
3
2
|
import { generateCastTraceCall } from "./cast.js";
|
|
3
|
+
import { iUpdatablePriceFeedAbi } from "../../../abi/iUpdatablePriceFeed.js";
|
|
4
4
|
import { simulateMulticall } from "./simulateMulticall.js";
|
|
5
5
|
import { BaseError, CallExecutionError, ContractFunctionRevertedError, decodeFunctionData, decodeFunctionResult, encodeFunctionData, parseAbi } from "viem";
|
|
6
6
|
import { getAction, parseAccount } from "viem/utils";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/model/filters.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The vocabulary every read-model filter is written in: how a single condition
|
|
4
|
+
* says "do not narrow", and how a predicate asks whether it narrows at all.
|
|
5
|
+
**/
|
|
6
|
+
/**
|
|
7
|
+
* Sentinel a filter condition can be set to instead of being omitted.
|
|
8
|
+
**/
|
|
9
|
+
declare const FILTER_ALL = "all";
|
|
10
|
+
/**
|
|
11
|
+
* Type of {@link FILTER_ALL}.
|
|
12
|
+
**/
|
|
13
|
+
type FilterAll = typeof FILTER_ALL;
|
|
14
|
+
/**
|
|
15
|
+
* A filter condition: a value, the {@link FILTER_ALL} sentinel, or omitted.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const kind: Filterable<OpportunityKind> = "pool"; // only pools
|
|
20
|
+
* const anyKind: Filterable<OpportunityKind> = "all"; // pools and strategies
|
|
21
|
+
* ```
|
|
22
|
+
**/
|
|
23
|
+
type Filterable<T> = T | FilterAll;
|
|
24
|
+
/**
|
|
25
|
+
* Whether a condition narrows anything. An omitted condition and one set to
|
|
26
|
+
* {@link FILTER_ALL} both do not, so this is the only check a predicate needs.
|
|
27
|
+
**/
|
|
28
|
+
declare function isFilterSet<T>(condition: Filterable<T> | undefined): condition is T;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { FILTER_ALL, FilterAll, Filterable, isFilterSet };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
//#region src/model/filters.schema.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Runtime schemas for {@link ./filters.js}, see the note in
|
|
5
|
+
* `primitives.schema.ts` on why they are written by hand.
|
|
6
|
+
**/
|
|
7
|
+
/**
|
|
8
|
+
* {@link FilterAll}
|
|
9
|
+
**/
|
|
10
|
+
declare const filterAllSchema: z.ZodLiteral<"all">;
|
|
11
|
+
/**
|
|
12
|
+
* {@link Filterable}
|
|
13
|
+
**/
|
|
14
|
+
declare function filterable<T extends z.ZodType>(schema: T): z.ZodUnion<[T, typeof filterAllSchema]>;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { filterAllSchema, filterable };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Curator, CuratorName } from "./curators.js";
|
|
2
2
|
import { Amount, AssetType, Bps, ChainId, Leverage, Timestamp, Token, TokenAmount, TxCall } from "./primitives.js";
|
|
3
3
|
import { curatorNameSchema, curatorSchema } from "./curators.schema.js";
|
|
4
|
+
import { FILTER_ALL, FilterAll, Filterable, isFilterSet } from "./filters.js";
|
|
5
|
+
import { filterAllSchema, filterable } from "./filters.schema.js";
|
|
4
6
|
import { ApyBreakdown, Opportunity, OpportunityBase, OpportunityDetail, OpportunityFilter, OpportunityId, OpportunityKey, OpportunityKind, PointRewards, PointsProgram, PoolOpportunity, PoolOpportunityDetail, PoolOpportunityKey, PoolOpportunityRef, PriceFeedData, PriceFeedSummary, QuotaAsset, RateCurve, RateCurvePoint, Rewards, StrategyOpportunity, StrategyOpportunityDetail, StrategyOpportunityKey, StrategyOpportunityRef, TokenRewards, matchesOpportunityFilter, opportunityId, poolOpportunityId, strategyOpportunityId } from "./opportunities.js";
|
|
5
7
|
import { DelayedReceivedAsset, InstantReceivedAsset, LiquidatableAccount, LiquidatableAccountFilter, LiquidationApproval, LiquidationDetails, LiquidationPosition, ReceivedAsset, matchesLiquidatableAccountFilter } from "./liquidations.js";
|
|
6
8
|
import { PnlBreakdown, PointsProgramPnL, PointsRewardsPnL, PoolPosition, PoolPositionKey, PoolPositionRef, Position, PositionCollateral, PositionFilter, PositionId, PositionKey, PositionKind, RewardsPnL, StrategyPosition, StrategyPositionKey, StrategyPositionRef, TokenRewardsPnL, liquidationPositionId, matchesPositionFilter, poolPositionId, positionId, strategyPositionId } from "./positions.js";
|
|
@@ -10,4 +12,4 @@ import { delayedReceivedAssetSchema, instantReceivedAssetSchema, liquidatableAcc
|
|
|
10
12
|
import { apyBreakdownSchema, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterSchema, opportunityKeySchema, opportunityKindSchema, opportunitySchema, pointRewardsSchema, pointsProgramSchema, poolOpportunityDetailSchema, poolOpportunityKeySchema, poolOpportunitySchema, priceFeedDataSchema, priceFeedSummarySchema, quotaAssetSchema, rateCurvePointSchema, rateCurveSchema, rewardsSchema, strategyOpportunityDetailSchema, strategyOpportunityKeySchema, strategyOpportunitySchema, tokenRewardsSchema } from "./opportunities.schema.js";
|
|
11
13
|
import { pnlBreakdownSchema, pointsProgramPnLSchema, pointsRewardsPnLSchema, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterSchema, positionKeySchema, positionKindSchema, positionSchema, rewardsPnLSchema, strategyPositionKeySchema, strategyPositionSchema, tokenRewardsPnLSchema } from "./positions.schema.js";
|
|
12
14
|
import { amountSchema, assetTypeSchema, bpsSchema, chainIdSchema, leverageSchema, timestampSchema, tokenAmountSchema, tokenSchema, txCallSchema } from "./primitives.schema.js";
|
|
13
|
-
export { Amount, ApyBreakdown, AssetType, Bps, ChainId, Curator, CuratorName, DelayedReceivedAsset, HistoryChartMetadata, HistoryMetric, HistoryPoint, HistoryRange, HistorySeries, InstantReceivedAsset, Leverage, LiquidatableAccount, LiquidatableAccountFilter, LiquidationApproval, LiquidationDetails, LiquidationPosition, Opportunity, OpportunityBase, OpportunityDetail, OpportunityFilter, OpportunityHistoryQuery, OpportunityId, OpportunityKey, OpportunityKind, POOL_HISTORY_METRICS, POOL_POSITION_HISTORY_METRICS, PnlBreakdown, PointRewards, PointsProgram, PointsProgramPnL, PointsRewardsPnL, PoolHistoryMetric, PoolOpportunity, PoolOpportunityDetail, PoolOpportunityKey, PoolOpportunityRef, PoolPosition, PoolPositionHistoryMetric, PoolPositionKey, PoolPositionRef, Position, PositionCollateral, PositionFilter, PositionHistoryMetric, PositionHistoryQuery, PositionId, PositionKey, PositionKind, PriceFeedData, PriceFeedSummary, QuotaAsset, RateCurve, RateCurvePoint, ReceivedAsset, Rewards, RewardsPnL, STRATEGY_HISTORY_METRICS, STRATEGY_POSITION_HISTORY_METRICS, StrategyHistoryMetric, StrategyOpportunity, StrategyOpportunityDetail, StrategyOpportunityKey, StrategyOpportunityRef, StrategyPosition, StrategyPositionHistoryMetric, StrategyPositionKey, StrategyPositionRef, Timestamp, Token, TokenAmount, TokenRewards, TokenRewardsPnL, TxCall, amountSchema, apyBreakdownSchema, assetTypeSchema, bpsSchema, chainIdSchema, curatorNameSchema, curatorSchema, delayedReceivedAssetSchema, historyChartMetadataSchema, historyMetricSchema, historyPointSchema, historyRangeSchema, historySeriesSchema, instantReceivedAssetSchema, leverageSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionId, liquidationPositionSchema, matchesLiquidatableAccountFilter, matchesOpportunityFilter, matchesPositionFilter, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterSchema, opportunityHistoryQuerySchema, opportunityId, opportunityKeySchema, opportunityKindSchema, opportunitySchema, pnlBreakdownSchema, pointRewardsSchema, pointsProgramPnLSchema, pointsProgramSchema, pointsRewardsPnLSchema, poolHistoryMetricSchema, poolOpportunityDetailSchema, poolOpportunityId, poolOpportunityKeySchema, poolOpportunitySchema, poolPositionHistoryMetricSchema, poolPositionId, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterSchema, positionHistoryMetricSchema, positionHistoryQuerySchema, positionId, positionKeySchema, positionKindSchema, positionSchema, priceFeedDataSchema, priceFeedSummarySchema, quotaAssetSchema, rateCurvePointSchema, rateCurveSchema, receivedAssetSchema, rewardsPnLSchema, rewardsSchema, strategyHistoryMetricSchema, strategyOpportunityDetailSchema, strategyOpportunityId, strategyOpportunityKeySchema, strategyOpportunitySchema, strategyPositionHistoryMetricSchema, strategyPositionId, strategyPositionKeySchema, strategyPositionSchema, timestampSchema, tokenAmountSchema, tokenRewardsPnLSchema, tokenRewardsSchema, tokenSchema, txCallSchema };
|
|
15
|
+
export { Amount, ApyBreakdown, AssetType, Bps, ChainId, Curator, CuratorName, DelayedReceivedAsset, FILTER_ALL, FilterAll, Filterable, HistoryChartMetadata, HistoryMetric, HistoryPoint, HistoryRange, HistorySeries, InstantReceivedAsset, Leverage, LiquidatableAccount, LiquidatableAccountFilter, LiquidationApproval, LiquidationDetails, LiquidationPosition, Opportunity, OpportunityBase, OpportunityDetail, OpportunityFilter, OpportunityHistoryQuery, OpportunityId, OpportunityKey, OpportunityKind, POOL_HISTORY_METRICS, POOL_POSITION_HISTORY_METRICS, PnlBreakdown, PointRewards, PointsProgram, PointsProgramPnL, PointsRewardsPnL, PoolHistoryMetric, PoolOpportunity, PoolOpportunityDetail, PoolOpportunityKey, PoolOpportunityRef, PoolPosition, PoolPositionHistoryMetric, PoolPositionKey, PoolPositionRef, Position, PositionCollateral, PositionFilter, PositionHistoryMetric, PositionHistoryQuery, PositionId, PositionKey, PositionKind, PriceFeedData, PriceFeedSummary, QuotaAsset, RateCurve, RateCurvePoint, ReceivedAsset, Rewards, RewardsPnL, STRATEGY_HISTORY_METRICS, STRATEGY_POSITION_HISTORY_METRICS, StrategyHistoryMetric, StrategyOpportunity, StrategyOpportunityDetail, StrategyOpportunityKey, StrategyOpportunityRef, StrategyPosition, StrategyPositionHistoryMetric, StrategyPositionKey, StrategyPositionRef, Timestamp, Token, TokenAmount, TokenRewards, TokenRewardsPnL, TxCall, amountSchema, apyBreakdownSchema, assetTypeSchema, bpsSchema, chainIdSchema, curatorNameSchema, curatorSchema, delayedReceivedAssetSchema, filterAllSchema, filterable, historyChartMetadataSchema, historyMetricSchema, historyPointSchema, historyRangeSchema, historySeriesSchema, instantReceivedAssetSchema, isFilterSet, leverageSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionId, liquidationPositionSchema, matchesLiquidatableAccountFilter, matchesOpportunityFilter, matchesPositionFilter, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterSchema, opportunityHistoryQuerySchema, opportunityId, opportunityKeySchema, opportunityKindSchema, opportunitySchema, pnlBreakdownSchema, pointRewardsSchema, pointsProgramPnLSchema, pointsProgramSchema, pointsRewardsPnLSchema, poolHistoryMetricSchema, poolOpportunityDetailSchema, poolOpportunityId, poolOpportunityKeySchema, poolOpportunitySchema, poolPositionHistoryMetricSchema, poolPositionId, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterSchema, positionHistoryMetricSchema, positionHistoryQuerySchema, positionId, positionKeySchema, positionKindSchema, positionSchema, priceFeedDataSchema, priceFeedSummarySchema, quotaAssetSchema, rateCurvePointSchema, rateCurveSchema, receivedAssetSchema, rewardsPnLSchema, rewardsSchema, strategyHistoryMetricSchema, strategyOpportunityDetailSchema, strategyOpportunityId, strategyOpportunityKeySchema, strategyOpportunitySchema, strategyPositionHistoryMetricSchema, strategyPositionId, strategyPositionKeySchema, strategyPositionSchema, timestampSchema, tokenAmountSchema, tokenRewardsPnLSchema, tokenRewardsSchema, tokenSchema, txCallSchema };
|
|
@@ -1,36 +1,39 @@
|
|
|
1
1
|
import { AssetType, ChainId, Timestamp, Token, TokenAmount, TxCall } from "./primitives.js";
|
|
2
|
+
import { Filterable } from "./filters.js";
|
|
2
3
|
import { Address } from "viem";
|
|
3
4
|
//#region src/model/liquidations.d.ts
|
|
4
5
|
/**
|
|
5
6
|
* Optional narrowing of a liquidatable accounts list.
|
|
6
7
|
*
|
|
7
|
-
* Every
|
|
8
|
-
* filter is the same as no filter at all.
|
|
8
|
+
* Every condition is optional and an omitted one matches any value, so an
|
|
9
|
+
* empty filter is the same as no filter at all. A condition can also be set to
|
|
10
|
+
* `"all"` to say the same thing explicitly, which is what a UI whose state has
|
|
11
|
+
* an "any" option holds, see {@link Filterable}. Conditions combine with AND.
|
|
9
12
|
**/
|
|
10
13
|
interface LiquidatableAccountFilter {
|
|
11
14
|
/**
|
|
12
15
|
* Keep only accounts on these chains.
|
|
13
16
|
**/
|
|
14
|
-
chainIds?: ChainId[]
|
|
17
|
+
chainIds?: Filterable<ChainId[]>;
|
|
15
18
|
/**
|
|
16
19
|
* Keep only accounts whose underlying — the token of
|
|
17
20
|
* {@link LiquidatableAccount.totalValue} — is of this class.
|
|
18
21
|
**/
|
|
19
|
-
underlyingType?: AssetType
|
|
22
|
+
underlyingType?: Filterable<AssetType>;
|
|
20
23
|
/**
|
|
21
24
|
* Keep only accounts of paused credit facades, or only of unpaused ones.
|
|
22
25
|
**/
|
|
23
|
-
paused?: boolean
|
|
26
|
+
paused?: Filterable<boolean>;
|
|
24
27
|
/**
|
|
25
28
|
* Keep only accounts in markets that accept RWA collateral, or only the ones
|
|
26
29
|
* outside them.
|
|
27
30
|
**/
|
|
28
|
-
rwa?: boolean
|
|
31
|
+
rwa?: Filterable<boolean>;
|
|
29
32
|
/**
|
|
30
33
|
* Keep only accounts with (`true`) or without (`false`) delayed
|
|
31
34
|
* (phantom-token) withdrawals.
|
|
32
35
|
**/
|
|
33
|
-
delayed?: boolean
|
|
36
|
+
delayed?: Filterable<boolean>;
|
|
34
37
|
}
|
|
35
38
|
/**
|
|
36
39
|
* A credit account that can be liquidated, with amounts precomputed for
|
|
@@ -90,14 +93,15 @@ interface LiquidatableAccount {
|
|
|
90
93
|
rwa: boolean;
|
|
91
94
|
}
|
|
92
95
|
/**
|
|
93
|
-
* Whether a liquidatable account satisfies every
|
|
96
|
+
* Whether a liquidatable account satisfies every condition of a filter.
|
|
94
97
|
*
|
|
95
|
-
* This is the single definition of what each
|
|
98
|
+
* This is the single definition of what each condition means: every source
|
|
96
99
|
* builds its rows first and runs them through here, so the chain and the
|
|
97
100
|
* backend cannot disagree on what a filter selects.
|
|
98
101
|
*
|
|
99
102
|
* @param account - Row to test.
|
|
100
|
-
* @param filter -
|
|
103
|
+
* @param filter - Conditions to test against. An absent filter matches
|
|
104
|
+
* anything.
|
|
101
105
|
**/
|
|
102
106
|
declare function matchesLiquidatableAccountFilter(account: LiquidatableAccount, filter?: LiquidatableAccountFilter): boolean;
|
|
103
107
|
/**
|
|
@@ -8,11 +8,11 @@ import { z } from "zod/v4";
|
|
|
8
8
|
* {@link LiquidatableAccountFilter}
|
|
9
9
|
**/
|
|
10
10
|
declare const liquidatableAccountFilterSchema: z.ZodObject<{
|
|
11
|
-
chainIds: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
12
|
-
underlyingType: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>>;
|
|
13
|
-
paused: z.ZodOptional<z.ZodBoolean
|
|
14
|
-
rwa: z.ZodOptional<z.ZodBoolean
|
|
15
|
-
delayed: z.ZodOptional<z.ZodBoolean
|
|
11
|
+
chainIds: z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodNumber>, z.ZodLiteral<"all">]>>;
|
|
12
|
+
underlyingType: z.ZodOptional<z.ZodUnion<[z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>, z.ZodLiteral<"all">]>>;
|
|
13
|
+
paused: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodLiteral<"all">]>>;
|
|
14
|
+
rwa: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodLiteral<"all">]>>;
|
|
15
|
+
delayed: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodLiteral<"all">]>>;
|
|
16
16
|
}, z.core.$strip>;
|
|
17
17
|
/**
|
|
18
18
|
* {@link LiquidatableAccount}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Curator } from "./curators.js";
|
|
2
2
|
import { Amount, AssetType, Bps, ChainId, Leverage, Timestamp, Token } from "./primitives.js";
|
|
3
|
+
import { Filterable } from "./filters.js";
|
|
3
4
|
import { Address } from "viem";
|
|
4
5
|
//#region src/model/opportunities.d.ts
|
|
5
6
|
/**
|
|
@@ -350,48 +351,51 @@ declare function opportunityId(opportunity: Opportunity): OpportunityId;
|
|
|
350
351
|
* The list is filtered in memory over final values, so there is no paging and
|
|
351
352
|
* no sorting: a screen sorts what it got.
|
|
352
353
|
*
|
|
353
|
-
* Every
|
|
354
|
-
* filter is the same as no filter at all.
|
|
354
|
+
* Every condition is optional and an omitted one matches any value, so an
|
|
355
|
+
* empty filter is the same as no filter at all. A condition can also be set to
|
|
356
|
+
* `"all"` to say the same thing explicitly, which is what a UI whose state has
|
|
357
|
+
* an "any" option holds, see {@link Filterable}. Conditions combine with AND.
|
|
355
358
|
**/
|
|
356
359
|
interface OpportunityFilter {
|
|
357
360
|
/**
|
|
358
361
|
* Keep only pools or only strategies.
|
|
359
362
|
**/
|
|
360
|
-
kind?: OpportunityKind
|
|
363
|
+
kind?: Filterable<OpportunityKind>;
|
|
361
364
|
/**
|
|
362
365
|
* Keep only opportunities on these chains.
|
|
363
366
|
**/
|
|
364
|
-
chainIds?: ChainId[]
|
|
367
|
+
chainIds?: Filterable<ChainId[]>;
|
|
365
368
|
/**
|
|
366
369
|
* Keep only opportunities whose {@link OpportunityBase.underlyingToken} is of
|
|
367
370
|
* this class, which for an RWA market means the class of the token its
|
|
368
371
|
* wrapper holds. An underlying that is not in the hardcoded table never
|
|
369
372
|
* matches, so a set filter also drops unclassified rows.
|
|
370
373
|
**/
|
|
371
|
-
underlyingType?: AssetType
|
|
374
|
+
underlyingType?: Filterable<AssetType>;
|
|
372
375
|
/**
|
|
373
376
|
* Keep only paused opportunities, or only unpaused ones.
|
|
374
377
|
**/
|
|
375
|
-
paused?: boolean
|
|
378
|
+
paused?: Filterable<boolean>;
|
|
376
379
|
/**
|
|
377
380
|
* Keep only opportunities being wound down, or only the ones that are not.
|
|
378
381
|
**/
|
|
379
|
-
sunset?: boolean
|
|
382
|
+
sunset?: Filterable<boolean>;
|
|
380
383
|
/**
|
|
381
384
|
* Keep only opportunities that accept RWA collateral, or only the ones that
|
|
382
385
|
* do not.
|
|
383
386
|
**/
|
|
384
|
-
rwa?: boolean
|
|
387
|
+
rwa?: Filterable<boolean>;
|
|
385
388
|
}
|
|
386
389
|
/**
|
|
387
|
-
* Whether an opportunity satisfies every
|
|
390
|
+
* Whether an opportunity satisfies every condition of a filter.
|
|
388
391
|
*
|
|
389
|
-
* This is the single definition of what each
|
|
392
|
+
* This is the single definition of what each condition means: every source
|
|
390
393
|
* builds its rows first and runs them through here, so the chain and the
|
|
391
394
|
* backend cannot disagree on what a filter selects.
|
|
392
395
|
*
|
|
393
396
|
* @param opportunity - Row to test.
|
|
394
|
-
* @param filter -
|
|
397
|
+
* @param filter - Conditions to test against. An absent filter matches
|
|
398
|
+
* anything.
|
|
395
399
|
**/
|
|
396
400
|
declare function matchesOpportunityFilter(opportunity: Opportunity, filter?: OpportunityFilter): boolean;
|
|
397
401
|
/**
|