@gearbox-protocol/sdk 14.12.0-next.80 → 14.12.0-next.82
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 +0 -4
- package/dist/cjs/model/filters.schema.js +10 -1
- package/dist/cjs/model/index.js +11 -0
- package/dist/cjs/model/liquidations.js +1 -1
- package/dist/cjs/model/liquidations.schema.js +1 -1
- package/dist/cjs/model/opportunities.js +1 -1
- package/dist/cjs/model/opportunities.schema.js +6 -13
- package/dist/cjs/model/positions.js +1 -1
- package/dist/cjs/model/positions.schema.js +33 -1
- package/dist/cjs/model/response.js +1 -0
- package/dist/cjs/model/response.schema.js +64 -0
- package/dist/cjs/new-sdk/AbstractNamespace.js +46 -128
- package/dist/cjs/new-sdk/GearboxSDK.js +55 -42
- package/dist/cjs/new-sdk/errors/AllSourcesFailedError.js +20 -0
- package/dist/cjs/new-sdk/errors/MissingSourceError.js +25 -0
- package/dist/cjs/new-sdk/errors/NoSourceServedError.js +20 -0
- package/dist/cjs/new-sdk/errors/SourceChainMismatchError.js +34 -0
- package/dist/cjs/new-sdk/errors/SourceUnavailableError.js +25 -0
- package/dist/cjs/new-sdk/errors/assertSameChains.js +12 -0
- package/dist/cjs/new-sdk/errors/everyChainFailed.js +11 -0
- package/dist/cjs/new-sdk/errors/index.js +15 -0
- package/dist/cjs/new-sdk/index.js +23 -3
- package/dist/cjs/new-sdk/opportunities/OpportunitiesNamespace.js +37 -89
- package/dist/cjs/new-sdk/positions/PositionsNamespace.js +27 -94
- package/dist/cjs/new-sdk/types.js +0 -21
- package/dist/cjs/new-sdk/utils/filterResponse.js +21 -0
- package/dist/cjs/new-sdk/utils/index.js +6 -0
- package/dist/cjs/new-sdk/utils/mergeChains.js +81 -0
- package/dist/cjs/new-sdk/utils/types.js +1 -0
- package/dist/cjs/offchain/AbstractOffchainNamespace.js +42 -65
- package/dist/cjs/offchain/GearboxAPI.js +12 -8
- package/dist/cjs/offchain/errors/OffchainInvalidJsonError.js +19 -0
- package/dist/cjs/offchain/errors/OffchainNotConfiguredError.js +20 -0
- package/dist/cjs/offchain/errors/OffchainNotImplementedError.js +19 -0
- package/dist/cjs/offchain/errors/OffchainRequestFailedError.js +24 -0
- package/dist/cjs/offchain/errors/OffchainStatusError.js +20 -0
- package/dist/cjs/offchain/errors/OffchainTransportError.js +31 -0
- package/dist/cjs/offchain/errors/OffchainValidationError.js +26 -0
- package/dist/cjs/offchain/errors/backendMessage.js +28 -0
- package/dist/cjs/offchain/errors/errorCause.js +12 -0
- package/dist/cjs/offchain/errors/index.js +21 -0
- package/dist/cjs/offchain/errors/readResponseBody.js +15 -0
- package/dist/cjs/offchain/index.js +22 -5
- package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +6 -3
- package/dist/cjs/offchain/positions/OffchainPositions.js +15 -21
- package/dist/cjs/offchain/types.js +0 -75
- package/dist/cjs/sdk/MultichainSDK.js +1 -1
- package/dist/cjs/sdk/OnchainSDK.js +1 -1
- package/dist/cjs/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +6 -6
- package/dist/cjs/sdk/accounts/liquidations/LiquidationsService.js +26 -20
- package/dist/cjs/sdk/accounts/liquidations/MultichainLiquidationsService.js +38 -14
- package/dist/cjs/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.js +7 -5
- package/dist/cjs/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +3 -2
- package/dist/cjs/sdk/base/MultichainConstruct.js +73 -34
- package/dist/cjs/sdk/chain/chains.js +11 -0
- package/dist/cjs/sdk/chain/index.js +1 -0
- package/dist/cjs/sdk/core/index.js +1 -1
- package/dist/cjs/sdk/index.js +2 -1
- package/dist/cjs/sdk/market/rwa/RWARegistry.js +4 -2
- package/dist/cjs/sdk/opportunities/MultichainOpportunitiesService.js +18 -32
- package/dist/cjs/sdk/opportunities/OpportunitiesService.js +1 -4
- package/dist/cjs/sdk/pools/PoolService.js +2 -1
- package/dist/cjs/sdk/positions/MultichainPositionsService.js +6 -29
- package/dist/cjs/sdk/positions/PositionsService.js +12 -6
- package/dist/esm/dev/AccountOpener.js +1 -1
- package/dist/esm/dev/withdrawalUtils.js +1 -1
- package/dist/esm/model/filters.js +0 -4
- package/dist/esm/model/filters.schema.js +10 -2
- package/dist/esm/model/index.js +5 -3
- package/dist/esm/model/liquidations.js +1 -1
- package/dist/esm/model/liquidations.schema.js +1 -1
- package/dist/esm/model/opportunities.js +1 -1
- package/dist/esm/model/opportunities.schema.js +4 -11
- package/dist/esm/model/positions.js +1 -1
- package/dist/esm/model/positions.schema.js +33 -3
- package/dist/esm/model/response.js +1 -0
- package/dist/esm/model/response.schema.js +58 -0
- package/dist/esm/new-sdk/AbstractNamespace.js +46 -128
- package/dist/esm/new-sdk/GearboxSDK.js +55 -42
- package/dist/esm/new-sdk/errors/AllSourcesFailedError.js +19 -0
- package/dist/esm/new-sdk/errors/MissingSourceError.js +24 -0
- package/dist/esm/new-sdk/errors/NoSourceServedError.js +19 -0
- package/dist/esm/new-sdk/errors/SourceChainMismatchError.js +33 -0
- package/dist/esm/new-sdk/errors/SourceUnavailableError.js +24 -0
- package/dist/esm/new-sdk/errors/assertSameChains.js +11 -0
- package/dist/esm/new-sdk/errors/everyChainFailed.js +10 -0
- package/dist/esm/new-sdk/errors/index.js +8 -0
- package/dist/esm/new-sdk/index.js +13 -3
- package/dist/esm/new-sdk/opportunities/OpportunitiesNamespace.js +38 -90
- package/dist/esm/new-sdk/positions/PositionsNamespace.js +28 -95
- package/dist/esm/new-sdk/types.js +1 -21
- package/dist/esm/new-sdk/utils/filterResponse.js +20 -0
- package/dist/esm/new-sdk/utils/index.js +3 -1
- package/dist/esm/new-sdk/utils/mergeChains.js +78 -0
- package/dist/esm/new-sdk/utils/types.js +1 -0
- package/dist/esm/offchain/AbstractOffchainNamespace.js +41 -64
- package/dist/esm/offchain/GearboxAPI.js +12 -8
- package/dist/esm/offchain/errors/OffchainInvalidJsonError.js +18 -0
- package/dist/esm/offchain/errors/OffchainNotConfiguredError.js +19 -0
- package/dist/esm/offchain/errors/OffchainNotImplementedError.js +18 -0
- package/dist/esm/offchain/errors/OffchainRequestFailedError.js +23 -0
- package/dist/esm/offchain/errors/OffchainStatusError.js +19 -0
- package/dist/esm/offchain/errors/OffchainTransportError.js +30 -0
- package/dist/esm/offchain/errors/OffchainValidationError.js +25 -0
- package/dist/esm/offchain/errors/backendMessage.js +27 -0
- package/dist/esm/offchain/errors/errorCause.js +11 -0
- package/dist/esm/offchain/errors/index.js +11 -0
- package/dist/esm/offchain/errors/readResponseBody.js +14 -0
- package/dist/esm/offchain/index.js +13 -2
- package/dist/esm/offchain/opportunities/OffchainOpportunities.js +6 -3
- package/dist/esm/offchain/positions/OffchainPositions.js +15 -21
- package/dist/esm/offchain/types.js +1 -72
- 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/MultichainSDK.js +1 -1
- package/dist/esm/sdk/OnchainSDK.js +1 -1
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +2 -2
- package/dist/esm/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +6 -6
- package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +27 -21
- package/dist/esm/sdk/accounts/liquidations/MultichainLiquidationsService.js +38 -14
- package/dist/esm/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.js +7 -5
- 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 +4 -3
- package/dist/esm/sdk/base/MultichainConstruct.js +73 -34
- package/dist/esm/sdk/base/TokensMeta.js +2 -2
- package/dist/esm/sdk/chain/chains.js +11 -1
- 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/index.js +1 -1
- package/dist/esm/sdk/index.js +3 -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/rwa/RWARegistry.js +4 -2
- 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 +18 -32
- package/dist/esm/sdk/opportunities/OpportunitiesService.js +1 -4
- package/dist/esm/sdk/pools/PoolService.js +3 -2
- package/dist/esm/sdk/positions/MultichainPositionsService.js +6 -29
- package/dist/esm/sdk/positions/PositionsService.js +12 -6
- package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +1 -1
- package/dist/types/model/filters.d.ts +9 -3
- package/dist/types/model/filters.schema.d.ts +7 -1
- package/dist/types/model/index.d.ts +7 -5
- package/dist/types/model/liquidations.d.ts +2 -6
- package/dist/types/model/liquidations.schema.d.ts +1 -1
- package/dist/types/model/opportunities.d.ts +3 -7
- package/dist/types/model/opportunities.schema.d.ts +2 -2
- package/dist/types/model/positions.d.ts +2 -6
- package/dist/types/model/positions.schema.d.ts +32 -2
- package/dist/types/model/response.d.ts +105 -0
- package/dist/types/model/response.schema.d.ts +98 -0
- package/dist/types/new-sdk/AbstractNamespace.d.ts +33 -98
- package/dist/types/new-sdk/GearboxSDK.d.ts +10 -25
- package/dist/types/new-sdk/errors/AllSourcesFailedError.d.ts +11 -0
- package/dist/types/new-sdk/errors/MissingSourceError.d.ts +23 -0
- package/dist/types/new-sdk/errors/NoSourceServedError.d.ts +17 -0
- package/dist/types/new-sdk/errors/SourceChainMismatchError.d.ts +35 -0
- package/dist/types/new-sdk/errors/SourceUnavailableError.d.ts +22 -0
- package/dist/types/new-sdk/errors/assertSameChains.d.ts +11 -0
- package/dist/types/new-sdk/errors/everyChainFailed.d.ts +10 -0
- package/dist/types/new-sdk/errors/index.d.ts +8 -0
- package/dist/types/new-sdk/index.d.ts +17 -6
- package/dist/types/new-sdk/opportunities/OpportunitiesNamespace.d.ts +19 -40
- package/dist/types/new-sdk/opportunities/index.d.ts +2 -2
- package/dist/types/new-sdk/opportunities/types.d.ts +80 -26
- package/dist/types/new-sdk/positions/PositionsNamespace.d.ts +17 -38
- package/dist/types/new-sdk/positions/index.d.ts +2 -2
- package/dist/types/new-sdk/positions/types.d.ts +74 -24
- package/dist/types/new-sdk/types.d.ts +24 -77
- package/dist/types/new-sdk/utils/filterResponse.d.ts +16 -0
- package/dist/types/new-sdk/utils/history.d.ts +6 -36
- package/dist/types/new-sdk/utils/index.d.ts +5 -2
- package/dist/types/new-sdk/utils/mergeChains.d.ts +20 -0
- package/dist/types/new-sdk/utils/types.d.ts +11 -0
- package/dist/types/offchain/AbstractOffchainNamespace.d.ts +21 -28
- package/dist/types/offchain/GearboxAPI.d.ts +13 -9
- package/dist/types/offchain/errors/OffchainInvalidJsonError.d.ts +16 -0
- package/dist/types/offchain/errors/OffchainNotConfiguredError.d.ts +16 -0
- package/dist/types/offchain/errors/OffchainNotImplementedError.d.ts +15 -0
- package/dist/types/offchain/errors/OffchainRequestFailedError.d.ts +12 -0
- package/dist/types/offchain/errors/OffchainStatusError.d.ts +16 -0
- package/dist/types/offchain/errors/OffchainTransportError.d.ts +43 -0
- package/dist/types/offchain/errors/OffchainValidationError.d.ts +21 -0
- package/dist/types/offchain/errors/backendMessage.d.ts +9 -0
- package/dist/types/offchain/errors/errorCause.d.ts +22 -0
- package/dist/types/offchain/errors/index.d.ts +11 -0
- package/dist/types/offchain/errors/readResponseBody.d.ts +8 -0
- package/dist/types/offchain/index.d.ts +13 -2
- package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +9 -8
- package/dist/types/offchain/positions/OffchainPositions.d.ts +9 -15
- package/dist/types/offchain/types.d.ts +7 -88
- package/dist/types/sdk/accounts/credit-account-compressor/types.d.ts +4 -0
- package/dist/types/sdk/accounts/index.d.ts +3 -3
- package/dist/types/sdk/accounts/liquidations/LiquidationsService.d.ts +2 -2
- package/dist/types/sdk/accounts/liquidations/MultichainLiquidationsService.d.ts +15 -14
- package/dist/types/sdk/accounts/liquidations/index.d.ts +2 -2
- package/dist/types/sdk/accounts/liquidations/types.d.ts +32 -16
- package/dist/types/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.d.ts +4 -4
- package/dist/types/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.d.ts +2 -2
- package/dist/types/sdk/accounts/withdrawal-compressor/index.d.ts +2 -2
- package/dist/types/sdk/accounts/withdrawal-compressor/types.d.ts +26 -4
- package/dist/types/sdk/base/MultichainConstruct.d.ts +63 -14
- package/dist/types/sdk/base/index.d.ts +2 -2
- package/dist/types/sdk/chain/chains.d.ts +10 -2
- package/dist/types/sdk/chain/index.d.ts +2 -2
- package/dist/types/sdk/index.d.ts +7 -7
- package/dist/types/sdk/market/MarketSuite.d.ts +1 -1
- package/dist/types/sdk/market/rwa/RWARegistry.d.ts +2 -1
- package/dist/types/sdk/opportunities/MultichainOpportunitiesService.d.ts +13 -16
- package/dist/types/sdk/pools/types.d.ts +4 -0
- package/dist/types/sdk/positions/MultichainPositionsService.d.ts +2 -12
- package/dist/types/sdk/positions/index.d.ts +2 -2
- package/dist/types/sdk/positions/types.d.ts +14 -5
- package/dist/types/sdk/types/index.d.ts +2 -2
- package/dist/types/sdk/types/multichain.d.ts +16 -36
- package/package.json +1 -1
|
@@ -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";
|
|
@@ -188,7 +188,8 @@ var PoolService = class extends SDKConstruct {
|
|
|
188
188
|
args: [props.wallet]
|
|
189
189
|
})),
|
|
190
190
|
allowFailure: false,
|
|
191
|
-
batchSize: 0
|
|
191
|
+
batchSize: 0,
|
|
192
|
+
blockNumber: props.blockNumber
|
|
192
193
|
});
|
|
193
194
|
return markets.flatMap((market, i) => {
|
|
194
195
|
const shares = balances[i] ?? 0n;
|
|
@@ -1,50 +1,27 @@
|
|
|
1
|
-
import { getNetworkType } from "../chain/chains.js";
|
|
2
1
|
import { MultichainConstruct } from "../base/MultichainConstruct.js";
|
|
3
2
|
import "../base/index.js";
|
|
4
|
-
import { isFilterSet } from "../../model/filters.js";
|
|
5
|
-
import "../../model/index.js";
|
|
6
3
|
//#region src/sdk/positions/MultichainPositionsService.ts
|
|
7
4
|
/**
|
|
8
5
|
* Cross-chain counterpart of {@link PositionsService}.
|
|
9
6
|
*
|
|
10
|
-
* Fans out over every chain configured in {@link MultichainSDK}. A chain that
|
|
11
|
-
* fails is logged and skipped so one dead RPC does not hide the positions a
|
|
12
|
-
* wallet holds elsewhere; its failure is reported in
|
|
13
|
-
* {@link MultichainResult.meta}.
|
|
14
|
-
*
|
|
15
7
|
* @typeParam Plugins - Map of attached plugin types.
|
|
16
8
|
**/
|
|
17
9
|
var MultichainPositionsService = class extends MultichainConstruct {
|
|
18
10
|
/**
|
|
19
11
|
* Positions of a wallet on all queried chains, see
|
|
20
12
|
* {@link PositionsService.list}.
|
|
21
|
-
*
|
|
22
|
-
* A filter that names chains narrows the fan-out itself, so chains whose rows
|
|
23
|
-
* would be discarded are never queried and never appear in the meta.
|
|
24
13
|
**/
|
|
25
14
|
async list(props) {
|
|
26
15
|
return this.queryChains({
|
|
27
|
-
|
|
16
|
+
chainIds: props.filter?.chainIds,
|
|
28
17
|
label: "list positions",
|
|
29
|
-
|
|
18
|
+
block: "latest",
|
|
19
|
+
run: (sdk, block) => sdk.positions.list({
|
|
20
|
+
...props,
|
|
21
|
+
blockNumber: block.blockNumber
|
|
22
|
+
})
|
|
30
23
|
});
|
|
31
24
|
}
|
|
32
|
-
/**
|
|
33
|
-
* Chains named by the filter, or `undefined` to query all of them. Chain ids
|
|
34
|
-
* the SDK does not support are dropped here rather than reported as failures:
|
|
35
|
-
* a filter naming them is a narrowing, not a request.
|
|
36
|
-
**/
|
|
37
|
-
#networksOf(filter) {
|
|
38
|
-
const chainIds = filter?.chainIds;
|
|
39
|
-
if (!isFilterSet(chainIds)) return;
|
|
40
|
-
const networks = [];
|
|
41
|
-
for (const chainId of chainIds) try {
|
|
42
|
-
networks.push(getNetworkType(chainId));
|
|
43
|
-
} catch {
|
|
44
|
-
this.sdk.logger?.debug(`ignoring unsupported chain ${chainId} in positions filter`);
|
|
45
|
-
}
|
|
46
|
-
return networks;
|
|
47
|
-
}
|
|
48
25
|
};
|
|
49
26
|
//#endregion
|
|
50
27
|
export { MultichainPositionsService };
|
|
@@ -17,19 +17,25 @@ var PositionsService = class extends SDKConstruct {
|
|
|
17
17
|
* the call rather than the SDK's loaded snapshot.
|
|
18
18
|
**/
|
|
19
19
|
async list(props) {
|
|
20
|
-
const { wallet, filter } = props;
|
|
21
|
-
|
|
22
|
-
if (isFilterSet(chainIds) && !chainIds.includes(this.chainId)) return [];
|
|
20
|
+
const { wallet, filter, blockNumber } = props;
|
|
21
|
+
if (filter?.chainIds && !filter.chainIds.includes(this.chainId)) return [];
|
|
23
22
|
const wantedKind = filter?.kind;
|
|
24
23
|
const wanted = (kind) => !isFilterSet(wantedKind) || wantedKind === kind;
|
|
25
24
|
const isZeroDebt = filter?.isZeroDebt;
|
|
26
25
|
const [pool, strategy, liquidation] = await Promise.all([
|
|
27
|
-
wanted("pool") ? this.sdk.pools.listPositions({
|
|
26
|
+
wanted("pool") ? this.sdk.pools.listPositions({
|
|
27
|
+
wallet,
|
|
28
|
+
blockNumber
|
|
29
|
+
}) : Promise.resolve([]),
|
|
28
30
|
wanted("strategy") ? this.sdk.accounts.listPositions({
|
|
29
31
|
owner: wallet,
|
|
30
|
-
includeZeroDebt: !isFilterSet(isZeroDebt) || isZeroDebt
|
|
32
|
+
includeZeroDebt: !isFilterSet(isZeroDebt) || isZeroDebt,
|
|
33
|
+
blockNumber
|
|
31
34
|
}) : Promise.resolve([]),
|
|
32
|
-
wanted("liquidation") ? this.sdk.liquidations.getLiquidationPositions({
|
|
35
|
+
wanted("liquidation") ? this.sdk.liquidations.getLiquidationPositions({
|
|
36
|
+
liquidator: wallet,
|
|
37
|
+
blockNumber
|
|
38
|
+
}) : Promise.resolve([])
|
|
33
39
|
]);
|
|
34
40
|
return [
|
|
35
41
|
...pool,
|
|
@@ -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";
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
import { ChainId } from "./primitives.js";
|
|
1
2
|
//#region src/model/filters.d.ts
|
|
2
3
|
/**
|
|
3
|
-
* The
|
|
4
|
-
* says "do not narrow", and how a predicate asks whether it narrows at all.
|
|
4
|
+
* The part of a filter that scopes it to chains, which every list filter has.
|
|
5
5
|
**/
|
|
6
|
+
interface ChainScopedFilter {
|
|
7
|
+
/**
|
|
8
|
+
* Keep only entities from these chains.
|
|
9
|
+
**/
|
|
10
|
+
chainIds?: ChainId[];
|
|
11
|
+
}
|
|
6
12
|
/**
|
|
7
13
|
* Sentinel a filter condition can be set to instead of being omitted.
|
|
8
14
|
**/
|
|
@@ -27,4 +33,4 @@ type Filterable<T> = T | FilterAll;
|
|
|
27
33
|
**/
|
|
28
34
|
declare function isFilterSet<T>(condition: Filterable<T> | undefined): condition is T;
|
|
29
35
|
//#endregion
|
|
30
|
-
export { FILTER_ALL, FilterAll, Filterable, isFilterSet };
|
|
36
|
+
export { ChainScopedFilter, FILTER_ALL, FilterAll, Filterable, isFilterSet };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Filterable } from "./filters.js";
|
|
1
2
|
import { z } from "zod/v4";
|
|
2
3
|
//#region src/model/filters.schema.d.ts
|
|
3
4
|
/**
|
|
@@ -16,5 +17,10 @@ declare const booleanParamSchema: z.ZodEnum<{
|
|
|
16
17
|
false: "false";
|
|
17
18
|
true: "true";
|
|
18
19
|
}>;
|
|
20
|
+
/**
|
|
21
|
+
* A boolean condition as a URL can carry it: a condition that does not narrow
|
|
22
|
+
* is absent rather than spelled out, see {@link booleanParamSchema}.
|
|
23
|
+
**/
|
|
24
|
+
declare function encodeFlag(condition: Filterable<boolean> | undefined): "true" | "false" | undefined;
|
|
19
25
|
//#endregion
|
|
20
|
-
export { booleanParamSchema, filterAllSchema, filterable };
|
|
26
|
+
export { booleanParamSchema, encodeFlag, filterAllSchema, filterable };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Curator, CuratorName } from "./curators.js";
|
|
2
1
|
import { Amount, AssetType, Bps, ChainId, Leverage, Timestamp, Token, TokenAmount, TxCall } from "./primitives.js";
|
|
2
|
+
import { Curator, CuratorName } from "./curators.js";
|
|
3
3
|
import { curatorNameSchema, curatorSchema } from "./curators.schema.js";
|
|
4
|
-
import { FILTER_ALL, FilterAll, Filterable, isFilterSet } from "./filters.js";
|
|
5
|
-
import { booleanParamSchema, filterAllSchema, filterable } from "./filters.schema.js";
|
|
4
|
+
import { ChainScopedFilter, FILTER_ALL, FilterAll, Filterable, isFilterSet } from "./filters.js";
|
|
5
|
+
import { booleanParamSchema, encodeFlag, filterAllSchema, filterable } from "./filters.schema.js";
|
|
6
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";
|
|
7
7
|
import { DelayedReceivedAsset, InstantReceivedAsset, LiquidatableAccount, LiquidatableAccountFilter, LiquidationApproval, LiquidationDetails, LiquidationPosition, ReceivedAsset, matchesLiquidatableAccountFilter } from "./liquidations.js";
|
|
8
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,6 +10,8 @@ import { HistoryChartMetadata, HistoryMetric, HistoryPoint, HistoryRange, Histor
|
|
|
10
10
|
import { historyChartMetadataSchema, historyMetricSchema, historyPointSchema, historyRangeSchema, historySeriesSchema, opportunityHistoryQuerySchema, poolHistoryMetricSchema, poolPositionHistoryMetricSchema, positionHistoryMetricSchema, positionHistoryQuerySchema, strategyHistoryMetricSchema, strategyPositionHistoryMetricSchema } from "./history.schema.js";
|
|
11
11
|
import { delayedReceivedAssetSchema, instantReceivedAssetSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionSchema, receivedAssetSchema } from "./liquidations.schema.js";
|
|
12
12
|
import { apyBreakdownSchema, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterQueryParamsSchema, opportunityFilterQuerySchema, opportunityFilterSchema, opportunityKeySchema, opportunityKindSchema, opportunitySchema, pointRewardsSchema, pointsProgramSchema, poolOpportunityDetailSchema, poolOpportunityKeySchema, poolOpportunitySchema, priceFeedDataSchema, priceFeedSummarySchema, quotaAssetSchema, rateCurvePointSchema, rateCurveSchema, rewardsSchema, strategyOpportunityDetailSchema, strategyOpportunityKeySchema, strategyOpportunitySchema, tokenRewardsSchema } from "./opportunities.schema.js";
|
|
13
|
-
import { pnlBreakdownSchema, pointsProgramPnLSchema, pointsRewardsPnLSchema, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterSchema, positionKeySchema, positionKindSchema, positionSchema, rewardsPnLSchema, strategyPositionKeySchema, strategyPositionSchema, tokenRewardsPnLSchema } from "./positions.schema.js";
|
|
13
|
+
import { pnlBreakdownSchema, pointsProgramPnLSchema, pointsRewardsPnLSchema, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionKeySchema, positionKindSchema, positionSchema, rewardsPnLSchema, strategyPositionKeySchema, strategyPositionSchema, tokenRewardsPnLSchema } from "./positions.schema.js";
|
|
14
14
|
import { amountSchema, assetTypeSchema, bpsSchema, chainIdSchema, leverageSchema, timestampSchema, tokenAmountSchema, tokenSchema, txCallSchema } from "./primitives.schema.js";
|
|
15
|
-
|
|
15
|
+
import { ChainFailed, ChainMetadata, ChainScoped, ChainSucceeded, DataResponse, DataSource, ResponseMetadata } from "./response.js";
|
|
16
|
+
import { chainFailedSchema, chainMetadataSchema, chainSucceededSchema, dataSourceSchema, responseMetadataSchema, responseSchema } from "./response.schema.js";
|
|
17
|
+
export { Amount, ApyBreakdown, AssetType, Bps, ChainFailed, ChainId, ChainMetadata, ChainScoped, ChainScopedFilter, ChainSucceeded, Curator, CuratorName, DataResponse, DataSource, 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, ResponseMetadata, 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, booleanParamSchema, bpsSchema, chainFailedSchema, chainIdSchema, chainMetadataSchema, chainSucceededSchema, curatorNameSchema, curatorSchema, dataSourceSchema, delayedReceivedAssetSchema, encodeFlag, filterAllSchema, filterable, historyChartMetadataSchema, historyMetricSchema, historyPointSchema, historyRangeSchema, historySeriesSchema, instantReceivedAssetSchema, isFilterSet, leverageSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionId, liquidationPositionSchema, matchesLiquidatableAccountFilter, matchesOpportunityFilter, matchesPositionFilter, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterQueryParamsSchema, opportunityFilterQuerySchema, opportunityFilterSchema, opportunityHistoryQuerySchema, opportunityId, opportunityKeySchema, opportunityKindSchema, opportunitySchema, pnlBreakdownSchema, pointRewardsSchema, pointsProgramPnLSchema, pointsProgramSchema, pointsRewardsPnLSchema, poolHistoryMetricSchema, poolOpportunityDetailSchema, poolOpportunityId, poolOpportunityKeySchema, poolOpportunitySchema, poolPositionHistoryMetricSchema, poolPositionId, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionHistoryMetricSchema, positionHistoryQuerySchema, positionId, positionKeySchema, positionKindSchema, positionSchema, priceFeedDataSchema, priceFeedSummarySchema, quotaAssetSchema, rateCurvePointSchema, rateCurveSchema, receivedAssetSchema, responseMetadataSchema, responseSchema, rewardsPnLSchema, rewardsSchema, strategyHistoryMetricSchema, strategyOpportunityDetailSchema, strategyOpportunityId, strategyOpportunityKeySchema, strategyOpportunitySchema, strategyPositionHistoryMetricSchema, strategyPositionId, strategyPositionKeySchema, strategyPositionSchema, timestampSchema, tokenAmountSchema, tokenRewardsPnLSchema, tokenRewardsSchema, tokenSchema, txCallSchema };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AssetType, ChainId, Timestamp, Token, TokenAmount, TxCall } from "./primitives.js";
|
|
2
|
-
import { Filterable } from "./filters.js";
|
|
2
|
+
import { ChainScopedFilter, Filterable } from "./filters.js";
|
|
3
3
|
import { Address } from "viem";
|
|
4
4
|
//#region src/model/liquidations.d.ts
|
|
5
5
|
/**
|
|
@@ -10,11 +10,7 @@ import { Address } from "viem";
|
|
|
10
10
|
* `"all"` to say the same thing explicitly, which is what a UI whose state has
|
|
11
11
|
* an "any" option holds, see {@link Filterable}. Conditions combine with AND.
|
|
12
12
|
**/
|
|
13
|
-
interface LiquidatableAccountFilter {
|
|
14
|
-
/**
|
|
15
|
-
* Keep only accounts on these chains.
|
|
16
|
-
**/
|
|
17
|
-
chainIds?: Filterable<ChainId[]>;
|
|
13
|
+
interface LiquidatableAccountFilter extends ChainScopedFilter {
|
|
18
14
|
/**
|
|
19
15
|
* Keep only accounts whose underlying — the token of
|
|
20
16
|
* {@link LiquidatableAccount.totalValue} — is of this class.
|
|
@@ -8,7 +8,7 @@ import { z } from "zod/v4";
|
|
|
8
8
|
* {@link LiquidatableAccountFilter}
|
|
9
9
|
**/
|
|
10
10
|
declare const liquidatableAccountFilterSchema: z.ZodObject<{
|
|
11
|
-
chainIds: z.ZodOptional<z.
|
|
11
|
+
chainIds: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
12
12
|
underlyingType: z.ZodOptional<z.ZodUnion<[z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>, z.ZodLiteral<"all">]>>;
|
|
13
13
|
paused: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodLiteral<"all">]>>;
|
|
14
14
|
rwa: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodLiteral<"all">]>>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Curator } from "./curators.js";
|
|
2
1
|
import { Amount, AssetType, Bps, ChainId, Leverage, Timestamp, Token } from "./primitives.js";
|
|
3
|
-
import {
|
|
2
|
+
import { Curator } from "./curators.js";
|
|
3
|
+
import { ChainScopedFilter, Filterable } from "./filters.js";
|
|
4
4
|
import { Address } from "viem";
|
|
5
5
|
//#region src/model/opportunities.d.ts
|
|
6
6
|
/**
|
|
@@ -356,15 +356,11 @@ declare function opportunityId(opportunity: Opportunity): OpportunityId;
|
|
|
356
356
|
* `"all"` to say the same thing explicitly, which is what a UI whose state has
|
|
357
357
|
* an "any" option holds, see {@link Filterable}. Conditions combine with AND.
|
|
358
358
|
**/
|
|
359
|
-
interface OpportunityFilter {
|
|
359
|
+
interface OpportunityFilter extends ChainScopedFilter {
|
|
360
360
|
/**
|
|
361
361
|
* Keep only pools or only strategies.
|
|
362
362
|
**/
|
|
363
363
|
kind?: Filterable<OpportunityKind>;
|
|
364
|
-
/**
|
|
365
|
-
* Keep only opportunities on these chains.
|
|
366
|
-
**/
|
|
367
|
-
chainIds?: Filterable<ChainId[]>;
|
|
368
364
|
/**
|
|
369
365
|
* Keep only opportunities whose {@link OpportunityBase.underlyingToken} is of
|
|
370
366
|
* this class, which for an RWA market means the class of the token its
|
|
@@ -562,7 +562,7 @@ declare const opportunitySchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
562
562
|
**/
|
|
563
563
|
declare const opportunityFilterSchema: z.ZodObject<{
|
|
564
564
|
kind: z.ZodOptional<z.ZodUnion<[z.ZodUnion<readonly [z.ZodLiteral<"pool">, z.ZodLiteral<"strategy">]>, z.ZodLiteral<"all">]>>;
|
|
565
|
-
chainIds: z.ZodOptional<z.
|
|
565
|
+
chainIds: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
566
566
|
underlyingType: z.ZodOptional<z.ZodUnion<[z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>, z.ZodLiteral<"all">]>>;
|
|
567
567
|
paused: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodLiteral<"all">]>>;
|
|
568
568
|
sunset: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodLiteral<"all">]>>;
|
|
@@ -610,7 +610,7 @@ declare const opportunityFilterQuerySchema: z.ZodCodec<z.ZodObject<{
|
|
|
610
610
|
}>>;
|
|
611
611
|
}, z.core.$strip>, z.ZodObject<{
|
|
612
612
|
kind: z.ZodOptional<z.ZodUnion<[z.ZodUnion<readonly [z.ZodLiteral<"pool">, z.ZodLiteral<"strategy">]>, z.ZodLiteral<"all">]>>;
|
|
613
|
-
chainIds: z.ZodOptional<z.
|
|
613
|
+
chainIds: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
614
614
|
underlyingType: z.ZodOptional<z.ZodUnion<[z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>, z.ZodLiteral<"all">]>>;
|
|
615
615
|
paused: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodLiteral<"all">]>>;
|
|
616
616
|
sunset: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodLiteral<"all">]>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AssetType, Bps, ChainId, Leverage, Token, TokenAmount } from "./primitives.js";
|
|
2
|
-
import { Filterable } from "./filters.js";
|
|
2
|
+
import { ChainScopedFilter, Filterable } from "./filters.js";
|
|
3
3
|
import { ApyBreakdown, PointsProgram } from "./opportunities.js";
|
|
4
4
|
import { DelayedReceivedAsset, LiquidationPosition } from "./liquidations.js";
|
|
5
5
|
import { Address } from "viem";
|
|
@@ -264,7 +264,7 @@ declare function positionId(position: Position): PositionId;
|
|
|
264
264
|
* `"all"` to say the same thing explicitly, which is what a UI whose state has
|
|
265
265
|
* an "any" option holds, see {@link Filterable}. Conditions combine with AND.
|
|
266
266
|
**/
|
|
267
|
-
interface PositionFilter {
|
|
267
|
+
interface PositionFilter extends ChainScopedFilter {
|
|
268
268
|
/**
|
|
269
269
|
* Keep only positions of this kind.
|
|
270
270
|
**/
|
|
@@ -274,10 +274,6 @@ interface PositionFilter {
|
|
|
274
274
|
* Applicable only to {@link StrategyPosition}
|
|
275
275
|
**/
|
|
276
276
|
isZeroDebt?: Filterable<boolean>;
|
|
277
|
-
/**
|
|
278
|
-
* Keep only positions on these chains.
|
|
279
|
-
**/
|
|
280
|
-
chainIds?: Filterable<ChainId[]>;
|
|
281
277
|
/**
|
|
282
278
|
* Keep only positions whose underlying is of this class, which for an RWA
|
|
283
279
|
* market means the class of the token its wrapper holds.
|
|
@@ -694,9 +694,39 @@ declare const positionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
694
694
|
declare const positionFilterSchema: z.ZodObject<{
|
|
695
695
|
kind: z.ZodOptional<z.ZodUnion<[z.ZodUnion<readonly [z.ZodLiteral<"pool">, z.ZodLiteral<"strategy">, z.ZodLiteral<"liquidation">]>, z.ZodLiteral<"all">]>>;
|
|
696
696
|
isZeroDebt: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodLiteral<"all">]>>;
|
|
697
|
-
chainIds: z.ZodOptional<z.
|
|
697
|
+
chainIds: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
698
698
|
underlyingType: z.ZodOptional<z.ZodUnion<[z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>, z.ZodLiteral<"all">]>>;
|
|
699
699
|
}, z.core.$strip>;
|
|
700
|
+
/**
|
|
701
|
+
* {@link PositionFilter} as a URL can carry it: every condition is a string,
|
|
702
|
+
* and a condition that does not narrow is absent rather than empty.
|
|
703
|
+
**/
|
|
704
|
+
declare const positionFilterQueryParamsSchema: z.ZodObject<{
|
|
705
|
+
kind: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"pool">, z.ZodLiteral<"strategy">, z.ZodLiteral<"liquidation">]>>;
|
|
706
|
+
isZeroDebt: z.ZodOptional<z.ZodEnum<{
|
|
707
|
+
false: "false";
|
|
708
|
+
true: "true";
|
|
709
|
+
}>>;
|
|
710
|
+
chainIds: z.ZodOptional<z.ZodString>;
|
|
711
|
+
underlyingType: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>>;
|
|
712
|
+
}, z.core.$strip>;
|
|
713
|
+
/**
|
|
714
|
+
* Code for {@link PositionFilter} to encode/decode to/from url query parameters.
|
|
715
|
+
**/
|
|
716
|
+
declare const positionFilterQuerySchema: z.ZodCodec<z.ZodObject<{
|
|
717
|
+
kind: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"pool">, z.ZodLiteral<"strategy">, z.ZodLiteral<"liquidation">]>>;
|
|
718
|
+
isZeroDebt: z.ZodOptional<z.ZodEnum<{
|
|
719
|
+
false: "false";
|
|
720
|
+
true: "true";
|
|
721
|
+
}>>;
|
|
722
|
+
chainIds: z.ZodOptional<z.ZodString>;
|
|
723
|
+
underlyingType: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>>;
|
|
724
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
725
|
+
kind: z.ZodOptional<z.ZodUnion<[z.ZodUnion<readonly [z.ZodLiteral<"pool">, z.ZodLiteral<"strategy">, z.ZodLiteral<"liquidation">]>, z.ZodLiteral<"all">]>>;
|
|
726
|
+
isZeroDebt: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodLiteral<"all">]>>;
|
|
727
|
+
chainIds: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
728
|
+
underlyingType: z.ZodOptional<z.ZodUnion<[z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>, z.ZodLiteral<"all">]>>;
|
|
729
|
+
}, z.core.$strip>>;
|
|
700
730
|
/**
|
|
701
731
|
* {@link PoolPositionKey}
|
|
702
732
|
**/
|
|
@@ -726,4 +756,4 @@ declare const positionKeySchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
726
756
|
kind: z.ZodLiteral<"strategy">;
|
|
727
757
|
}, z.core.$strip>], "kind">;
|
|
728
758
|
//#endregion
|
|
729
|
-
export { pnlBreakdownSchema, pointsProgramPnLSchema, pointsRewardsPnLSchema, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterSchema, positionKeySchema, positionKindSchema, positionSchema, rewardsPnLSchema, strategyPositionKeySchema, strategyPositionSchema, tokenRewardsPnLSchema };
|
|
759
|
+
export { pnlBreakdownSchema, pointsProgramPnLSchema, pointsRewardsPnLSchema, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionKeySchema, positionKindSchema, positionSchema, rewardsPnLSchema, strategyPositionKeySchema, strategyPositionSchema, tokenRewardsPnLSchema };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { ChainId, Timestamp } from "./primitives.js";
|
|
2
|
+
//#region src/model/response.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Shared response envelope: the payload plus per-chain metadata naming which
|
|
5
|
+
* source served each chain.
|
|
6
|
+
*
|
|
7
|
+
* The backend sends this on HTTP success only. Transport failures, timeouts,
|
|
8
|
+
* and backend error bodies are not an envelope — the offchain client wraps
|
|
9
|
+
* those, because the request may never have reached the backend.
|
|
10
|
+
*
|
|
11
|
+
* @typeParam T - Payload type
|
|
12
|
+
**/
|
|
13
|
+
interface DataResponse<T> {
|
|
14
|
+
/**
|
|
15
|
+
* Response payload.
|
|
16
|
+
**/
|
|
17
|
+
data: T;
|
|
18
|
+
/**
|
|
19
|
+
* Per-chain outcome of the read, see {@link ResponseMetadata}.
|
|
20
|
+
**/
|
|
21
|
+
meta: ResponseMetadata;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Per-chain outcomes attached to every {@link DataResponse}.
|
|
25
|
+
**/
|
|
26
|
+
interface ResponseMetadata {
|
|
27
|
+
/**
|
|
28
|
+
* One entry per chain the read asked. After a merge, each success names the
|
|
29
|
+
* side that won it in {@link ChainSucceeded.source}, so a consumer can tell
|
|
30
|
+
* a chain served live from a chain served by the backend without per-row
|
|
31
|
+
* provenance.
|
|
32
|
+
**/
|
|
33
|
+
chains: ChainMetadata[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Which side produced a chain's data.
|
|
37
|
+
**/
|
|
38
|
+
type DataSource = "onchain" | "offchain";
|
|
39
|
+
/**
|
|
40
|
+
* Chain that answered, which source served it, and the block it answered from.
|
|
41
|
+
*
|
|
42
|
+
* Discriminated from {@link ChainFailed} on {@link status}, so a success
|
|
43
|
+
* without a source, or without the block it reflects, is unrepresentable.
|
|
44
|
+
**/
|
|
45
|
+
interface ChainSucceeded {
|
|
46
|
+
/**
|
|
47
|
+
* Chain the entry describes.
|
|
48
|
+
**/
|
|
49
|
+
chainId: ChainId;
|
|
50
|
+
status: "success";
|
|
51
|
+
/**
|
|
52
|
+
* Source that produced this chain's data. Never absent on success: some
|
|
53
|
+
* source produced it.
|
|
54
|
+
**/
|
|
55
|
+
source: DataSource;
|
|
56
|
+
/**
|
|
57
|
+
* Block the data reflects. A `number` here (model convention), converted
|
|
58
|
+
* from `bigint` at the onchain boundary. A chain that cannot say which block
|
|
59
|
+
* it answered from is a {@link ChainFailed}.
|
|
60
|
+
**/
|
|
61
|
+
blockNumber: number;
|
|
62
|
+
/**
|
|
63
|
+
* Unix seconds of {@link blockNumber}.
|
|
64
|
+
**/
|
|
65
|
+
timestamp: Timestamp;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Chain that did not answer.
|
|
69
|
+
**/
|
|
70
|
+
interface ChainFailed {
|
|
71
|
+
/**
|
|
72
|
+
* Chain the entry describes.
|
|
73
|
+
**/
|
|
74
|
+
chainId: ChainId;
|
|
75
|
+
status: "error";
|
|
76
|
+
/**
|
|
77
|
+
* Source that failed this chain. Absent when every source failed for it, so
|
|
78
|
+
* no side won it.
|
|
79
|
+
**/
|
|
80
|
+
source?: DataSource;
|
|
81
|
+
/**
|
|
82
|
+
* Rejection reason. A `string` in a JSON response, an `Error` (or an
|
|
83
|
+
* `AggregateError` when both sources failed) when produced locally.
|
|
84
|
+
*
|
|
85
|
+
* Serialises to `{}` if an envelope carrying a real `Error` is put into
|
|
86
|
+
* Redux or a log as-is.
|
|
87
|
+
**/
|
|
88
|
+
error?: unknown;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Per-chain outcome, discriminated on {@link ChainSucceeded.status} /
|
|
92
|
+
* {@link ChainFailed.status}.
|
|
93
|
+
**/
|
|
94
|
+
type ChainMetadata = ChainSucceeded | ChainFailed;
|
|
95
|
+
/**
|
|
96
|
+
* Anything the read model scopes to one chain, i.e. every list row.
|
|
97
|
+
**/
|
|
98
|
+
interface ChainScoped {
|
|
99
|
+
/**
|
|
100
|
+
* Chain the row lives on.
|
|
101
|
+
**/
|
|
102
|
+
chainId: ChainId;
|
|
103
|
+
}
|
|
104
|
+
//#endregion
|
|
105
|
+
export { ChainFailed, ChainMetadata, ChainScoped, ChainSucceeded, DataResponse, DataSource, ResponseMetadata };
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { DataResponse } from "./response.js";
|
|
2
|
+
import { z } from "zod/v4";
|
|
3
|
+
//#region src/model/response.schema.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Runtime schemas for {@link ./response.js}, see the note in
|
|
6
|
+
* `primitives.schema.ts` on why they are written by hand.
|
|
7
|
+
*
|
|
8
|
+
* `responseSchema(payloadSchema)` validates a successful backend 2xx body.
|
|
9
|
+
* HTTP and transport errors never pass through it.
|
|
10
|
+
**/
|
|
11
|
+
/**
|
|
12
|
+
* {@link DataSource}
|
|
13
|
+
**/
|
|
14
|
+
declare const dataSourceSchema: z.ZodEnum<{
|
|
15
|
+
offchain: "offchain";
|
|
16
|
+
onchain: "onchain";
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* {@link ChainSucceeded}
|
|
20
|
+
*
|
|
21
|
+
* `source` may be omitted by the backend and decodes to `"offchain"`. The block
|
|
22
|
+
* has no such default: a success that omits it fails validation.
|
|
23
|
+
**/
|
|
24
|
+
declare const chainSucceededSchema: z.ZodObject<{
|
|
25
|
+
chainId: z.ZodNumber;
|
|
26
|
+
status: z.ZodLiteral<"success">;
|
|
27
|
+
source: z.ZodDefault<z.ZodEnum<{
|
|
28
|
+
offchain: "offchain";
|
|
29
|
+
onchain: "onchain";
|
|
30
|
+
}>>;
|
|
31
|
+
blockNumber: z.ZodNumber;
|
|
32
|
+
timestamp: z.ZodNumber;
|
|
33
|
+
}, z.core.$strip>;
|
|
34
|
+
/**
|
|
35
|
+
* {@link ChainFailed}
|
|
36
|
+
*
|
|
37
|
+
* `error` is a `string` in a JSON body. The schema accepts `unknown` so the
|
|
38
|
+
* same codec also validates a locally produced envelope carrying an `Error`.
|
|
39
|
+
**/
|
|
40
|
+
declare const chainFailedSchema: z.ZodObject<{
|
|
41
|
+
chainId: z.ZodNumber;
|
|
42
|
+
status: z.ZodLiteral<"error">;
|
|
43
|
+
source: z.ZodOptional<z.ZodEnum<{
|
|
44
|
+
offchain: "offchain";
|
|
45
|
+
onchain: "onchain";
|
|
46
|
+
}>>;
|
|
47
|
+
error: z.ZodOptional<z.ZodUnknown>;
|
|
48
|
+
}, z.core.$strip>;
|
|
49
|
+
/**
|
|
50
|
+
* {@link ChainMetadata}
|
|
51
|
+
**/
|
|
52
|
+
declare const chainMetadataSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
53
|
+
chainId: z.ZodNumber;
|
|
54
|
+
status: z.ZodLiteral<"success">;
|
|
55
|
+
source: z.ZodDefault<z.ZodEnum<{
|
|
56
|
+
offchain: "offchain";
|
|
57
|
+
onchain: "onchain";
|
|
58
|
+
}>>;
|
|
59
|
+
blockNumber: z.ZodNumber;
|
|
60
|
+
timestamp: z.ZodNumber;
|
|
61
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
62
|
+
chainId: z.ZodNumber;
|
|
63
|
+
status: z.ZodLiteral<"error">;
|
|
64
|
+
source: z.ZodOptional<z.ZodEnum<{
|
|
65
|
+
offchain: "offchain";
|
|
66
|
+
onchain: "onchain";
|
|
67
|
+
}>>;
|
|
68
|
+
error: z.ZodOptional<z.ZodUnknown>;
|
|
69
|
+
}, z.core.$strip>], "status">;
|
|
70
|
+
/**
|
|
71
|
+
* {@link ResponseMetadata}
|
|
72
|
+
**/
|
|
73
|
+
declare const responseMetadataSchema: z.ZodObject<{
|
|
74
|
+
chains: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
75
|
+
chainId: z.ZodNumber;
|
|
76
|
+
status: z.ZodLiteral<"success">;
|
|
77
|
+
source: z.ZodDefault<z.ZodEnum<{
|
|
78
|
+
offchain: "offchain";
|
|
79
|
+
onchain: "onchain";
|
|
80
|
+
}>>;
|
|
81
|
+
blockNumber: z.ZodNumber;
|
|
82
|
+
timestamp: z.ZodNumber;
|
|
83
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
84
|
+
chainId: z.ZodNumber;
|
|
85
|
+
status: z.ZodLiteral<"error">;
|
|
86
|
+
source: z.ZodOptional<z.ZodEnum<{
|
|
87
|
+
offchain: "offchain";
|
|
88
|
+
onchain: "onchain";
|
|
89
|
+
}>>;
|
|
90
|
+
error: z.ZodOptional<z.ZodUnknown>;
|
|
91
|
+
}, z.core.$strip>], "status">>;
|
|
92
|
+
}, z.core.$strip>;
|
|
93
|
+
/**
|
|
94
|
+
* {@link DataResponse} parameterized by the payload schema.
|
|
95
|
+
**/
|
|
96
|
+
declare function responseSchema<S extends z.ZodType>(payloadSchema: S): z.ZodType<DataResponse<z.output<S>>>;
|
|
97
|
+
//#endregion
|
|
98
|
+
export { chainFailedSchema, chainMetadataSchema, chainSucceededSchema, dataSourceSchema, responseMetadataSchema, responseSchema };
|