@gearbox-protocol/sdk 18.1.0 → 18.2.0-next.10

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.
Files changed (98) hide show
  1. package/dist/cjs/abi/compressors/subcompressors/liquidation/treehouseLiquidationSubcompressor.js +179 -0
  2. package/dist/cjs/abi/compressors/subcompressors/withdrawal/treehouseWithdrawalSubcompressor.js +534 -0
  3. package/dist/cjs/abi/router/treehouseWorker.js +885 -0
  4. package/dist/cjs/onchain/market/adapters/abi/actionAbi.js +1 -0
  5. package/dist/cjs/onchain/market/adapters/abi/conctructorAbi.js +3 -0
  6. package/dist/cjs/onchain/market/adapters/types.js +3 -0
  7. package/dist/cjs/permissionless/api/GearboxPermissionless.js +12 -5
  8. package/dist/cjs/permissionless/api/analytics/PermissionlessAnalytics.js +50 -0
  9. package/dist/cjs/permissionless/api/analytics/index.js +4 -0
  10. package/dist/cjs/permissionless/api/analytics/schemas.js +27 -0
  11. package/dist/cjs/permissionless/api/analytics/types.js +1 -0
  12. package/dist/cjs/permissionless/api/index.js +3 -0
  13. package/dist/cjs/permissionless/api/oracles/PermissionlessOracles.js +444 -28
  14. package/dist/cjs/permissionless/api/oracles/enrich.js +99 -0
  15. package/dist/cjs/permissionless/api/oracles/schemas.js +102 -16
  16. package/dist/cjs/permissionless/api/schemas.js +0 -3
  17. package/dist/cjs/permissionless/bindings/index.js +1 -1
  18. package/dist/cjs/permissionless/index.js +4 -1
  19. package/dist/cjs/permissionless/utils/index.js +1 -0
  20. package/dist/cjs/permissionless/utils/price-update/get-prices.js +25 -0
  21. package/dist/cjs/permissionless/utils/price-update/index.js +1 -0
  22. package/dist/cjs/testnets/TestnetsAPI.js +179 -0
  23. package/dist/cjs/testnets/errors/TestnetNotFoundError.js +15 -0
  24. package/dist/cjs/testnets/errors/TestnetRequestFailedError.js +24 -0
  25. package/dist/cjs/testnets/errors/TestnetStatusError.js +19 -0
  26. package/dist/cjs/testnets/errors/TestnetValidationError.js +24 -0
  27. package/dist/cjs/testnets/errors/TestnetWaitTimeoutError.js +30 -0
  28. package/dist/cjs/testnets/errors/TestnetsError.js +34 -0
  29. package/dist/cjs/testnets/errors/index.js +13 -0
  30. package/dist/cjs/testnets/index.js +32 -0
  31. package/dist/cjs/testnets/package.json +1 -0
  32. package/dist/cjs/testnets/schemas.js +242 -0
  33. package/dist/cjs/testnets/types.js +1 -0
  34. package/dist/esm/abi/compressors/subcompressors/liquidation/treehouseLiquidationSubcompressor.js +178 -0
  35. package/dist/esm/abi/compressors/subcompressors/withdrawal/treehouseWithdrawalSubcompressor.js +533 -0
  36. package/dist/esm/abi/router/treehouseWorker.js +884 -0
  37. package/dist/esm/onchain/market/adapters/abi/actionAbi.js +1 -0
  38. package/dist/esm/onchain/market/adapters/abi/conctructorAbi.js +3 -0
  39. package/dist/esm/onchain/market/adapters/types.js +3 -0
  40. package/dist/esm/permissionless/api/GearboxPermissionless.js +12 -5
  41. package/dist/esm/permissionless/api/analytics/PermissionlessAnalytics.js +49 -0
  42. package/dist/esm/permissionless/api/analytics/index.js +2 -0
  43. package/dist/esm/permissionless/api/analytics/schemas.js +25 -0
  44. package/dist/esm/permissionless/api/analytics/types.js +1 -0
  45. package/dist/esm/permissionless/api/index.js +3 -1
  46. package/dist/esm/permissionless/api/oracles/PermissionlessOracles.js +446 -30
  47. package/dist/esm/permissionless/api/oracles/enrich.js +94 -0
  48. package/dist/esm/permissionless/api/oracles/schemas.js +94 -17
  49. package/dist/esm/permissionless/api/schemas.js +2 -4
  50. package/dist/esm/permissionless/bindings/index.js +1 -1
  51. package/dist/esm/permissionless/index.js +4 -3
  52. package/dist/esm/permissionless/utils/index.js +2 -2
  53. package/dist/esm/permissionless/utils/price-update/get-prices.js +25 -1
  54. package/dist/esm/permissionless/utils/price-update/index.js +2 -2
  55. package/dist/esm/testnets/TestnetsAPI.js +178 -0
  56. package/dist/esm/testnets/errors/TestnetNotFoundError.js +14 -0
  57. package/dist/esm/testnets/errors/TestnetRequestFailedError.js +23 -0
  58. package/dist/esm/testnets/errors/TestnetStatusError.js +18 -0
  59. package/dist/esm/testnets/errors/TestnetValidationError.js +23 -0
  60. package/dist/esm/testnets/errors/TestnetWaitTimeoutError.js +29 -0
  61. package/dist/esm/testnets/errors/TestnetsError.js +33 -0
  62. package/dist/esm/testnets/errors/index.js +7 -0
  63. package/dist/esm/testnets/index.js +11 -0
  64. package/dist/esm/testnets/package.json +1 -0
  65. package/dist/esm/testnets/schemas.js +228 -0
  66. package/dist/esm/testnets/types.js +1 -0
  67. package/dist/types/abi/compressors/subcompressors/liquidation/treehouseLiquidationSubcompressor.d.ts +148 -0
  68. package/dist/types/abi/compressors/subcompressors/withdrawal/treehouseWithdrawalSubcompressor.d.ts +440 -0
  69. package/dist/types/abi/router/treehouseWorker.d.ts +728 -0
  70. package/dist/types/onchain/market/adapters/types.d.ts +4 -1
  71. package/dist/types/permissionless/api/GearboxPermissionless.d.ts +11 -5
  72. package/dist/types/permissionless/api/analytics/PermissionlessAnalytics.d.ts +38 -0
  73. package/dist/types/permissionless/api/analytics/index.d.ts +3 -0
  74. package/dist/types/permissionless/api/analytics/schemas.d.ts +32 -0
  75. package/dist/types/permissionless/api/analytics/types.d.ts +38 -0
  76. package/dist/types/permissionless/api/index.d.ts +5 -2
  77. package/dist/types/permissionless/api/oracles/PermissionlessOracles.d.ts +159 -22
  78. package/dist/types/permissionless/api/oracles/enrich.d.ts +59 -0
  79. package/dist/types/permissionless/api/oracles/index.d.ts +2 -2
  80. package/dist/types/permissionless/api/oracles/schemas.d.ts +202 -7
  81. package/dist/types/permissionless/api/oracles/types.d.ts +401 -22
  82. package/dist/types/permissionless/api/schemas.d.ts +0 -2
  83. package/dist/types/permissionless/index.d.ts +5 -3
  84. package/dist/types/permissionless/utils/index.d.ts +2 -2
  85. package/dist/types/permissionless/utils/price-update/get-prices.d.ts +17 -0
  86. package/dist/types/permissionless/utils/price-update/index.d.ts +2 -2
  87. package/dist/types/testnets/TestnetsAPI.d.ts +108 -0
  88. package/dist/types/testnets/errors/TestnetNotFoundError.d.ts +12 -0
  89. package/dist/types/testnets/errors/TestnetRequestFailedError.d.ts +11 -0
  90. package/dist/types/testnets/errors/TestnetStatusError.d.ts +15 -0
  91. package/dist/types/testnets/errors/TestnetValidationError.d.ts +16 -0
  92. package/dist/types/testnets/errors/TestnetWaitTimeoutError.d.ts +21 -0
  93. package/dist/types/testnets/errors/TestnetsError.d.ts +47 -0
  94. package/dist/types/testnets/errors/index.d.ts +7 -0
  95. package/dist/types/testnets/index.d.ts +11 -0
  96. package/dist/types/testnets/schemas.d.ts +554 -0
  97. package/dist/types/testnets/types.d.ts +717 -0
  98. package/package.json +9 -3
@@ -15,7 +15,7 @@ export interface IAdapterContract extends IBaseContract {
15
15
  openingCalls(): Promise<MultiCall[]>;
16
16
  }
17
17
  export type VersionedAbi = Record<number, readonly AbiParameter[]>;
18
- export type AdapterContractType = "ADAPTER::ACCOUNT_MIGRATOR" | "ADAPTER::BALANCER_V3_ROUTER" | "ADAPTER::BALANCER_V3_WRAPPER" | "ADAPTER::CAMELOT_V3_ROUTER" | "ADAPTER::CURVE_STABLE_NG" | "ADAPTER::CURVE_V1_2ASSETS" | "ADAPTER::CURVE_V1_3ASSETS" | "ADAPTER::CURVE_V1_4ASSETS" | "ADAPTER::CURVE_V1_STECRV_POOL" | "ADAPTER::CVX_V1_BASE_REWARD_POOL" | "ADAPTER::CVX_V1_BOOSTER" | "ADAPTER::DAI_USDS_EXCHANGE" | "ADAPTER::ERC4626_VAULT" | "ADAPTER::ERC4626_VAULT_REFERRAL" | "ADAPTER::FLUID_DEX" | "ADAPTER::INFINIFI_GATEWAY" | "ADAPTER::INFINIFI_UNWINDING" | "ADAPTER::KELP_DEPOSIT_POOL" | "ADAPTER::KELP_WITHDRAWAL" | "ADAPTER::LIDO_V1" | "ADAPTER::LIDO_WSTETH_V1" | "ADAPTER::MELLOW_CLAIMER" | "ADAPTER::MELLOW_DVV" | "ADAPTER::MELLOW_ERC4626_VAULT" | "ADAPTER::MELLOW_WRAPPER" | "ADAPTER::MIDAS_GATEWAY" | "ADAPTER::MIDAS_ISSUANCE_VAULT" | "ADAPTER::MIDAS_REDEMPTION_VAULT" | "ADAPTER::PENDLE_ROUTER" | "ADAPTER::SECURITIZE_ONRAMP" | "ADAPTER::SECURITIZE_REDEMPTION" | "ADAPTER::STAKING_REWARDS" | "ADAPTER::TRADERJOE_ROUTER" | "ADAPTER::UNISWAP_V2_ROUTER" | "ADAPTER::UNISWAP_V3_ROUTER" | "ADAPTER::UNISWAP_V4_GATEWAY" | "ADAPTER::UPSHIFT_VAULT" | "ADAPTER::VELODROME_V2_ROUTER";
18
+ export type AdapterContractType = "ADAPTER::ACCOUNT_MIGRATOR" | "ADAPTER::BALANCER_V3_ROUTER" | "ADAPTER::BALANCER_V3_WRAPPER" | "ADAPTER::CAMELOT_V3_ROUTER" | "ADAPTER::CURVE_STABLE_NG" | "ADAPTER::CURVE_V1_2ASSETS" | "ADAPTER::CURVE_V1_3ASSETS" | "ADAPTER::CURVE_V1_4ASSETS" | "ADAPTER::CURVE_V1_STECRV_POOL" | "ADAPTER::CVX_V1_BASE_REWARD_POOL" | "ADAPTER::CVX_V1_BOOSTER" | "ADAPTER::DAI_USDS_EXCHANGE" | "ADAPTER::ERC4626_VAULT" | "ADAPTER::ERC4626_VAULT_REFERRAL" | "ADAPTER::FLUID_DEX" | "ADAPTER::INFINIFI_GATEWAY" | "ADAPTER::INFINIFI_UNWINDING" | "ADAPTER::KELP_DEPOSIT_POOL" | "ADAPTER::KELP_WITHDRAWAL" | "ADAPTER::LIDO_V1" | "ADAPTER::LIDO_WSTETH_V1" | "ADAPTER::MELLOW_CLAIMER" | "ADAPTER::MELLOW_DVV" | "ADAPTER::MELLOW_ERC4626_VAULT" | "ADAPTER::MELLOW_WRAPPER" | "ADAPTER::MIDAS_GATEWAY" | "ADAPTER::MIDAS_ISSUANCE_VAULT" | "ADAPTER::MIDAS_REDEMPTION_VAULT" | "ADAPTER::PENDLE_ROUTER" | "ADAPTER::SECURITIZE_ONRAMP" | "ADAPTER::SECURITIZE_REDEMPTION" | "ADAPTER::STAKING_REWARDS" | "ADAPTER::TRADERJOE_ROUTER" | "ADAPTER::TREEHOUSE_FASTLANE" | "ADAPTER::TREEHOUSE_GATEWAY" | "ADAPTER::TREEHOUSE_ROUTER" | "ADAPTER::UNISWAP_V2_ROUTER" | "ADAPTER::UNISWAP_V3_ROUTER" | "ADAPTER::UNISWAP_V4_GATEWAY" | "ADAPTER::UPSHIFT_VAULT" | "ADAPTER::VELODROME_V2_ROUTER";
19
19
  export declare enum AdapterType {
20
20
  ACCOUNT_MIGRATOR = "ACCOUNT_MIGRATOR",
21
21
  BALANCER_V3_ROUTER = "BALANCER_V3_ROUTER",
@@ -50,6 +50,9 @@ export declare enum AdapterType {
50
50
  SECURITIZE_REDEMPTION = "SECURITIZE_REDEMPTION",
51
51
  STAKING_REWARDS = "STAKING_REWARDS",
52
52
  TRADERJOE_ROUTER = "TRADERJOE_ROUTER",
53
+ TREEHOUSE_FASTLANE = "TREEHOUSE_FASTLANE",
54
+ TREEHOUSE_GATEWAY = "TREEHOUSE_GATEWAY",
55
+ TREEHOUSE_ROUTER = "TREEHOUSE_ROUTER",
53
56
  UNISWAP_V2_ROUTER = "UNISWAP_V2_ROUTER",
54
57
  UNISWAP_V3_ROUTER = "UNISWAP_V3_ROUTER",
55
58
  UNISWAP_V4_GATEWAY = "UNISWAP_V4_GATEWAY",
@@ -1,4 +1,5 @@
1
1
  import { GearboxPermissionlessOptions } from "./types.js";
2
+ import { PermissionlessAnalytics } from "./analytics/PermissionlessAnalytics.js";
2
3
  import { AttachChainsArgs } from "./chains/types.js";
3
4
  import { ChainsNamespace } from "./chains/ChainsNamespace.js";
4
5
  import { PermissionlessDeploy } from "./deploy/PermissionlessDeploy.js";
@@ -26,11 +27,11 @@ import { InstanceOwnerTransactions } from "./transactions/InstanceOwnerTransacti
26
27
  * const store = await permissionless.oracles.store({ chainId: chain.chainId });
27
28
  * ```
28
29
  *
29
- * Only what needs a server goes to one. {@link chains} and {@link oracles}
30
- * are the backend's reads; {@link deploy} and {@link transactions} read the
31
- * target chain directly, because everything they answer is derived from there
32
- * and a round trip would only move the derivation further from the wallet
33
- * that has to sign for it.
30
+ * Only what needs a server goes to one. {@link chains}, {@link oracles} and
31
+ * {@link analytics} are the backend's reads; {@link deploy} and
32
+ * {@link transactions} read the target chain directly, because everything
33
+ * they answer is derived from there and a round trip would only move the
34
+ * derivation further from the wallet that has to sign for it.
34
35
  **/
35
36
  export declare class GearboxPermissionless {
36
37
  /**
@@ -42,6 +43,11 @@ export declare class GearboxPermissionless {
42
43
  * Namespace for price feeds: the store and its prices.
43
44
  **/
44
45
  readonly oracles: PermissionlessOracles;
46
+ /**
47
+ * Namespace for history: what a feed's price did over a window, see
48
+ * {@link PermissionlessAnalytics}.
49
+ **/
50
+ readonly analytics: PermissionlessAnalytics;
45
51
  /**
46
52
  * Namespace for the Safe batches an instance owner executes. Backend-free,
47
53
  * see {@link InstanceOwnerTransactions}.
@@ -0,0 +1,38 @@
1
+ import { AbstractOffchainNamespace } from "../../../offchain/AbstractOffchainNamespace.js";
2
+ import { GearboxPermissionlessOptions } from "../types.js";
3
+ import { PriceChartArgs, PriceFeedPriceChart } from "./types.js";
4
+ //#region src/permissionless/api/analytics/PermissionlessAnalytics.d.ts
5
+ /**
6
+ * History of the permissionless stack: what a thing did, rather than what it
7
+ * is.
8
+ *
9
+ * Separate from {@link PermissionlessOracles} because the two are read on
10
+ * different clocks. A feed's identity settles when a curator uploads it and
11
+ * is read once per page; its price moves every block and is re-read whenever
12
+ * a window changes. Folding the series into the feed would make every range
13
+ * switch re-fetch the identity, and every identity read carry a series the
14
+ * caller may never draw.
15
+ *
16
+ * ```ts
17
+ * const chart = await permissionless.analytics.priceChart({
18
+ * chainId: 1,
19
+ * address: feed,
20
+ * range: "1w",
21
+ * });
22
+ * ```
23
+ **/
24
+ export declare class PermissionlessAnalytics extends AbstractOffchainNamespace {
25
+ constructor(options: GearboxPermissionlessOptions);
26
+ /**
27
+ * The price one feed reported over a window.
28
+ *
29
+ * Backend-only by construction: the chain serves the present, and
30
+ * reconstructing a series from it would mean an archive read per point.
31
+ *
32
+ * @throws When the PriceFeedStore does not carry the feed. An address the
33
+ * store never held has no indexed history, and answering an empty series
34
+ * would read as "no price yet" rather than as the mistake it is.
35
+ **/
36
+ priceChart({ chainId, address, range }: PriceChartArgs): Promise<PriceFeedPriceChart>;
37
+ }
38
+ //#endregion
@@ -0,0 +1,3 @@
1
+ import { PriceChartArgs, PriceFeedChartPoint, PriceFeedPriceChart } from "./types.js";
2
+ import { PermissionlessAnalytics } from "./PermissionlessAnalytics.js";
3
+ export { PermissionlessAnalytics, PriceChartArgs, PriceFeedChartPoint, PriceFeedPriceChart };
@@ -0,0 +1,32 @@
1
+ import { z } from "zod/v4";
2
+ //#region src/permissionless/api/analytics/schemas.d.ts
3
+ /**
4
+ * Runtime schemas for {@link ./types.js}.
5
+ *
6
+ * Loose for the same reason the oracles schemas are: the backend assembles
7
+ * these rows from its own indexes and may report more about a window than the
8
+ * hand-written types declare.
9
+ **/
10
+ /** {@link PriceFeedChartPoint} */
11
+ export declare const priceFeedChartPointSchema: z.ZodObject<{
12
+ timestamp: z.ZodNumber;
13
+ value: z.ZodNumber;
14
+ }, z.core.$loose>;
15
+ /** {@link PriceFeedPriceChart} */
16
+ export declare const priceFeedChartSchema: z.ZodObject<{
17
+ range: z.ZodEnum<{
18
+ "1d": "1d";
19
+ "1m": "1m";
20
+ "1w": "1w";
21
+ "1y": "1y";
22
+ max: "max";
23
+ }>;
24
+ from: z.ZodNumber;
25
+ to: z.ZodNumber;
26
+ intervalSeconds: z.ZodNumber;
27
+ points: z.ZodArray<z.ZodObject<{
28
+ timestamp: z.ZodNumber;
29
+ value: z.ZodNumber;
30
+ }, z.core.$loose>>;
31
+ }, z.core.$loose>;
32
+ //#endregion
@@ -0,0 +1,38 @@
1
+ import { Timestamp } from "../../../model/primitives.js";
2
+ import { ChartRange } from "../../../model/charts.js";
3
+ import { Address } from "viem";
4
+ //#region src/permissionless/api/analytics/types.d.ts
5
+ /** One sampled price, in whole US dollars. */
6
+ export interface PriceFeedChartPoint {
7
+ timestamp: Timestamp;
8
+ value: number;
9
+ }
10
+ /**
11
+ * A feed's price over one window, sampled onto an epoch-aligned grid.
12
+ *
13
+ * Only the buckets with an observation are present: a gap is an absent point,
14
+ * never a zero and never a value carried over from a neighbour. The window is
15
+ * echoed back because `max` resolves against the feed's own first observation
16
+ * and is therefore not derivable from the range alone.
17
+ *
18
+ * Deliberately not a {@link ChartBundle}. A bundle carries one series per
19
+ * {@link ChartMetric}, and that union is closed over what the read model
20
+ * charts — a price feed's own price is not one of them, and widening it would
21
+ * reach every chart the protocol serves to add a series only this page draws.
22
+ **/
23
+ export interface PriceFeedPriceChart {
24
+ range: ChartRange;
25
+ from: Timestamp;
26
+ to: Timestamp;
27
+ /** Distance between two consecutive buckets. */
28
+ intervalSeconds: number;
29
+ points: PriceFeedChartPoint[];
30
+ }
31
+ /** Args of {@link PermissionlessAnalytics.priceChart}. */
32
+ export interface PriceChartArgs {
33
+ chainId: number;
34
+ address: Address;
35
+ /** Window to cover. The same set every other Gearbox chart offers. */
36
+ range: ChartRange;
37
+ }
38
+ //#endregion
@@ -1,17 +1,20 @@
1
1
  import { GearboxPermissionlessOptions } from "./types.js";
2
+ import { PriceChartArgs, PriceFeedChartPoint, PriceFeedPriceChart } from "./analytics/types.js";
3
+ import { PermissionlessAnalytics } from "./analytics/PermissionlessAnalytics.js";
2
4
  import { AttachChainsArgs, ChainScope, ChainSummaryArgs, PermissionlessChain, PermissionlessChainSummary } from "./chains/types.js";
3
5
  import { ChainsNamespace } from "./chains/ChainsNamespace.js";
4
6
  import { DeployArgs, DeployContractArgs, DeployPriceFeedArgs, PreparedDeployment, PreparedPriceFeedDeployment } from "./deploy/types.js";
5
7
  import { DEFAULT_DEPLOY_SALT, PermissionlessDeploy, priceFeedSalt } from "./deploy/PermissionlessDeploy.js";
6
- import { GetPricesArgs, PermissionlessAsset, PermissionlessPriceFeedStore, PermissionlessPrices } from "./oracles/types.js";
8
+ import { AssetArgs, AssetCap, AssetsArgs, FeedCap, MarketCap, PermissionlessAsset, PermissionlessAssetDetails, PermissionlessAssetMarket, PermissionlessAssetMarketFeed, PermissionlessAssetQuota, PermissionlessAssetSummary, PermissionlessIndexedAssetDetails, PermissionlessIndexedAssetSummary, PermissionlessIndexedPriceFeedDetails, PermissionlessIndexedPriceFeedMarket, PermissionlessMarket, PermissionlessPriceFeedAsset, PermissionlessPriceFeedDetails, PermissionlessPriceFeedMarket, PermissionlessPriceFeedStore, PermissionlessQuotaTotals, PriceFeedArgs, PriceFeedPrice, PriceFeedRef } from "./oracles/types.js";
7
9
  import { GET_PRICES_CHUNK_SIZE, GET_PRICES_GAS_LIMIT_BY_CHAIN_ID, PermissionlessOracles } from "./oracles/PermissionlessOracles.js";
8
10
  import { AddFeedsArgs, ChangeNamesArgs, ChangeStalenessPeriodsArgs, ForbidFeedsArgs, InstanceTxsArgs, PriceFeedPair } from "./transactions/types.js";
9
11
  import { InstanceOwnerTransactions } from "./transactions/InstanceOwnerTransactions.js";
10
12
  import { GearboxPermissionless } from "./GearboxPermissionless.js";
13
+ import "./analytics/index.js";
11
14
  import "./chains/index.js";
12
15
  import { deriveEffectiveStalenessPeriod } from "./deploy/effective-staleness.js";
13
16
  import "./deploy/index.js";
14
17
  import { PermissionlessChainUnreachableError, PermissionlessNotAttachedError, PriceFeedNotInStoreError, PriceFeedSaltMissingError, PriceFeedStalenessUnknownError } from "./errors.js";
15
18
  import "./oracles/index.js";
16
19
  import "./transactions/index.js";
17
- export { AddFeedsArgs, AttachChainsArgs, ChainScope, ChainSummaryArgs, ChainsNamespace, ChangeNamesArgs, ChangeStalenessPeriodsArgs, DEFAULT_DEPLOY_SALT, DeployArgs, DeployContractArgs, DeployPriceFeedArgs, ForbidFeedsArgs, GET_PRICES_CHUNK_SIZE, GET_PRICES_GAS_LIMIT_BY_CHAIN_ID, GearboxPermissionless, GearboxPermissionlessOptions, GetPricesArgs, InstanceOwnerTransactions, InstanceTxsArgs, PermissionlessAsset, PermissionlessChain, PermissionlessChainSummary, PermissionlessChainUnreachableError, PermissionlessDeploy, PermissionlessNotAttachedError, PermissionlessOracles, PermissionlessPriceFeedStore, PermissionlessPrices, PreparedDeployment, PreparedPriceFeedDeployment, PriceFeedNotInStoreError, PriceFeedPair, PriceFeedSaltMissingError, PriceFeedStalenessUnknownError, deriveEffectiveStalenessPeriod, priceFeedSalt };
20
+ export { AddFeedsArgs, AssetArgs, AssetCap, AssetsArgs, AttachChainsArgs, ChainScope, ChainSummaryArgs, ChainsNamespace, ChangeNamesArgs, ChangeStalenessPeriodsArgs, DEFAULT_DEPLOY_SALT, DeployArgs, DeployContractArgs, DeployPriceFeedArgs, FeedCap, ForbidFeedsArgs, GET_PRICES_CHUNK_SIZE, GET_PRICES_GAS_LIMIT_BY_CHAIN_ID, GearboxPermissionless, GearboxPermissionlessOptions, InstanceOwnerTransactions, InstanceTxsArgs, MarketCap, PermissionlessAnalytics, PermissionlessAsset, PermissionlessAssetDetails, PermissionlessAssetMarket, PermissionlessAssetMarketFeed, PermissionlessAssetQuota, PermissionlessAssetSummary, PermissionlessChain, PermissionlessChainSummary, PermissionlessChainUnreachableError, PermissionlessDeploy, PermissionlessIndexedAssetDetails, PermissionlessIndexedAssetSummary, PermissionlessIndexedPriceFeedDetails, PermissionlessIndexedPriceFeedMarket, PermissionlessMarket, PermissionlessNotAttachedError, PermissionlessOracles, PermissionlessPriceFeedAsset, PermissionlessPriceFeedDetails, PermissionlessPriceFeedMarket, PermissionlessPriceFeedStore, PermissionlessQuotaTotals, PreparedDeployment, PreparedPriceFeedDeployment, PriceChartArgs, PriceFeedArgs, PriceFeedChartPoint, PriceFeedNotInStoreError, PriceFeedPair, PriceFeedPrice, PriceFeedPriceChart, PriceFeedRef, PriceFeedSaltMissingError, PriceFeedStalenessUnknownError, deriveEffectiveStalenessPeriod, priceFeedSalt };
@@ -1,8 +1,8 @@
1
+ import { PriceFeedData } from "../../../model/opportunities.js";
1
2
  import { AbstractOffchainNamespace } from "../../../offchain/AbstractOffchainNamespace.js";
2
3
  import { GearboxPermissionlessOptions } from "../types.js";
3
4
  import { ChainsNamespace } from "../chains/ChainsNamespace.js";
4
- import { GetPricesArgs, PermissionlessPriceFeedStore, PermissionlessPrices } from "./types.js";
5
- import { Address } from "viem";
5
+ import { AssetArgs, AssetCap, AssetsArgs, FeedCap, MarketCap, PermissionlessAssetDetails, PermissionlessAssetSummary, PermissionlessPriceFeedDetails, PermissionlessPriceFeedStore, PriceFeedArgs, PriceFeedPrice, PriceFeedRef } from "./types.js";
6
6
  //#region src/permissionless/api/oracles/PermissionlessOracles.d.ts
7
7
  export declare const GET_PRICES_GAS_LIMIT_BY_CHAIN_ID: Record<number, bigint>;
8
8
  export declare const GET_PRICES_CHUNK_SIZE = 200;
@@ -12,9 +12,17 @@ export declare const GET_PRICES_CHUNK_SIZE = 200;
12
12
  *
13
13
  * ```ts
14
14
  * const store = await permissionless.oracles.store({ chainId: 1 });
15
- * const { prices } = await permissionless.oracles.prices({ chainId: 1 });
15
+ * const prices = await permissionless.oracles.getPrices(
16
+ * store.priceFeeds.map(({ address }) => ({ chainId: 1, address })),
17
+ * );
16
18
  * ```
17
19
  *
20
+ * The backend answers what it has indexed; anything that is only true at a
21
+ * block — a price, a market cap, a quota in one currency, the period an
22
+ * oracle holds for a slot — is read here, off the chain, and folded into what
23
+ * it answered. That is why these reads mix a request with a multicall rather
24
+ * than being either one.
25
+ *
18
26
  * Read-only. What the store carries is decided on chain, so putting a feed
19
27
  * there is a batch the instance owner executes — see
20
28
  * {@link InstanceOwnerTransactions} — not a row a client writes here.
@@ -24,40 +32,169 @@ export declare class PermissionlessOracles extends AbstractOffchainNamespace {
24
32
  constructor(options: GearboxPermissionlessOptions, chains: ChainsNamespace);
25
33
  /**
26
34
  * The store with the assets and feeds of one chain.
35
+ *
36
+ * {@link stores} narrowed to one and unwrapped, which is the whole of it:
37
+ * there is one route either way, and a chain the backend does not serve has
38
+ * no store to answer with rather than an empty one.
39
+ *
40
+ * @throws When the backend serves no store for the chain.
27
41
  **/
28
42
  store({ chainId }: {
29
43
  chainId: number;
30
44
  }): Promise<PermissionlessPriceFeedStore>;
31
45
  /**
32
- * A price per feed, and a market cap per feed and asset. The feeds the
33
- * indexer has not seen are read off the chain by the backend, so the store
34
- * is priced whole.
46
+ * The same stores for every chain the backend serves.
47
+ *
48
+ * One request rather than {@link store} per chain, which is what a page
49
+ * showing all of them would otherwise do: the backend assembles them in the
50
+ * same few queries it assembles one in, so the chains cost little more than
51
+ * the largest of them.
52
+ *
53
+ * Each entry names its own chain, so a store is never attributed by
54
+ * position. `chainId` narrows it to one, for a caller that wants the list
55
+ * shape either way.
56
+ *
57
+ * ```ts
58
+ * const stores = await permissionless.oracles.stores();
59
+ * ```
35
60
  **/
36
- prices({ chainId }: {
37
- chainId: number;
38
- }): Promise<PermissionlessPrices>;
61
+ stores({ chainId }?: AssetsArgs): Promise<PermissionlessPriceFeedStore[]>;
39
62
  /**
40
- * The price each of the named feeds reports, read off the chain.
63
+ * One feed of the store: what it is, which assets it may price, and which
64
+ * market slots it currently fills.
65
+ *
66
+ * Singular where {@link store} is plural, and not a filter over it: the
67
+ * store answers what a list renders, while this answers what a feed is used
68
+ * for, which the store does not carry at all.
69
+ *
70
+ * ```ts
71
+ * const { priceFeed, markets } = await permissionless.oracles.feed({
72
+ * chainId: 1,
73
+ * address: feed,
74
+ * });
75
+ * ```
41
76
  *
42
- * Where {@link prices} answers for the store as a whole and at whatever
43
- * moment the backend priced it, this prices exactly the feeds asked for, at
44
- * the current block. A feed the store does not carry prices the same way,
45
- * which is what makes this the call to reach for after a deploy, or while a
46
- * form is still choosing between candidates.
77
+ * Each market row also carries the staleness period that market's own
78
+ * oracle holds for the slot, read off the chain here — see
79
+ * {@link PermissionlessPriceFeedMarket.marketStalenessPeriod}.
47
80
  *
48
- * Feeds needing a fresh answer before they can be read are updated inside
49
- * the same simulation, so a push-based feed prices as readily as a
50
- * pull-based one. `null` is a feed whose read reverted, not a zero.
81
+ * @throws When the store does not carry the feed. A private draft is not
82
+ * here — it lives in whichever app wrote it.
83
+ **/
84
+ feed({ chainId, address }: PriceFeedArgs): Promise<PermissionlessPriceFeedDetails>;
85
+ /**
86
+ * One asset of the store: the feeds allowed for it, and the markets that
87
+ * take it as collateral.
88
+ *
89
+ * The mirror of {@link feed}, and the call to reach for when the question is
90
+ * "what prices this token and what is it backing" rather than "where is this
91
+ * feed used". Both read the same market slots; which end they are indexed
92
+ * from is the difference.
51
93
  *
52
94
  * ```ts
53
- * const prices = await permissionless.oracles.getPrices({
95
+ * const { priceFeeds, markets, quotaUsedUsd } =
96
+ * await permissionless.oracles.asset({ chainId: 1, address: token });
97
+ * ```
98
+ *
99
+ * The quota totals are worked out here, over the very market rows this
100
+ * answers with — see {@link PermissionlessQuotaTotals}.
101
+ *
102
+ * @throws When the chain has no metadata for the address. An asset nothing
103
+ * was indexed for has no symbol or decimals, so there is no row to answer.
104
+ **/
105
+ asset({ chainId, address }: AssetArgs): Promise<PermissionlessAssetDetails>;
106
+ /**
107
+ * Every asset the store carries, with what its markets make of it.
108
+ *
109
+ * Enough on its own to render a list of assets: the alternative is the
110
+ * store's whole read for the names plus a call per row for the quotas, and
111
+ * this is one request either way you scope it.
112
+ *
113
+ * Ordered by how central each asset is — the markets it underlies first,
114
+ * then what is quoted against it, then what it is allowed — so a consumer
115
+ * renders the rows as they arrive. Omit `chainId` for every chain the
116
+ * backend serves, ordered the same way across all of them.
117
+ *
118
+ * Each row also carries its quota totals and what this SDK's tables say the
119
+ * asset is, neither of which is served — see
120
+ * {@link PermissionlessAssetSummary}. The totals are what the last two terms
121
+ * of the order are over, so this waits for them rather than handing back a
122
+ * list that would reshuffle a moment later.
123
+ *
124
+ * ```ts
125
+ * const assets = await permissionless.oracles.assets({ chainId: 1 });
126
+ * const everywhere = await permissionless.oracles.assets();
127
+ * ```
128
+ **/
129
+ assets({ chainId }?: AssetsArgs): Promise<PermissionlessAssetSummary[]>;
130
+ /**
131
+ * The feeds one feed reads from, recursively.
132
+ *
133
+ * Answers for any feed the chain has indexed, store member or not: a
134
+ * composite feed's children are rarely in the store themselves, and a tree
135
+ * that stopped at the first of them would not be one.
136
+ *
137
+ * ```ts
138
+ * const tree = await permissionless.oracles.dependencies({
54
139
  * chainId: 1,
55
- * priceFeeds: [feed],
140
+ * address: feed,
56
141
  * });
57
142
  * ```
143
+ **/
144
+ dependencies({ chainId, address }: PriceFeedArgs): Promise<PriceFeedData>;
145
+ /**
146
+ * What the named feeds price, read off the chain.
147
+ *
148
+ * Prices exactly what is asked for, at the current block, across as many
149
+ * chains as the list names — one read per chain, so a screen listing every
150
+ * chain's feeds pays per chain and not per row. A feed the store does not
151
+ * carry prices the same way, which is what makes this the call to reach for
152
+ * after a deploy, or while a form is still choosing between candidates.
153
+ *
154
+ * Read in two passes. The first asks every feed what it reports as it
155
+ * stands, which is one multicall per chain; a feed that will not answer
156
+ * until it has been given a fresh one is then priced inside a simulation
157
+ * that updates it first, so a push-based feed prices as readily as a
158
+ * pull-based one. The second pass costs an `OnchainSDK` to attach, hence
159
+ * only the feeds that need it rather than all of them.
160
+ *
161
+ * `null` is a feed neither pass could read, and a chain with no client
162
+ * configured is every one of its feeds reading `null` rather than a failed
163
+ * call — the figures built on them are floors either way.
58
164
  *
59
- * @returns A price per feed, in the 8 decimals every Gearbox feed reports.
165
+ * ```ts
166
+ * const [{ price }] = await permissionless.oracles.getPrices([
167
+ * { chainId: 1, address: feed },
168
+ * ]);
169
+ * ```
170
+ *
171
+ * @returns One entry per feed asked for, in the order asked, each price in
172
+ * the 8 decimals every Gearbox feed reports.
173
+ **/
174
+ getPrices(feeds: PriceFeedRef[]): Promise<PriceFeedPrice[]>;
175
+ /**
176
+ * What one chain's feeds value one chain's assets at: `price × totalSupply`
177
+ * per pair.
178
+ *
179
+ * Asked from whichever side the caller is looking at — one asset through
180
+ * each of its feeds, or one feed over each of the assets it prices — because
181
+ * a screen shows one row per feed or one row per asset, never the full
182
+ * cross product. Both answer the same pairs in the same shape.
183
+ *
184
+ * Two reads per chain: the prices, and one multicall for the assets'
185
+ * supplies and decimals. Several scopes can be asked at once, which is how a
186
+ * table of every asset's feeds pays per chain rather than per row; the pairs
187
+ * come back in the order the scopes named them. A pair neither read could
188
+ * resolve has a `null` cap, which is not a zero.
189
+ *
190
+ * ```ts
191
+ * const caps = await permissionless.oracles.getMarketCap({
192
+ * chainId: 1,
193
+ * asset: token,
194
+ * priceFeeds: [main, reserve],
195
+ * });
196
+ * ```
60
197
  **/
61
- getPrices({ chainId, priceFeeds }: GetPricesArgs): Promise<Record<Address, bigint | null>>;
198
+ getMarketCap(scope: AssetCap | FeedCap | Array<AssetCap | FeedCap>): Promise<MarketCap[]>;
62
199
  }
63
200
  //#endregion
@@ -0,0 +1,59 @@
1
+ import { PermissionlessAssetQuota, PermissionlessIndexedAssetSummary, PermissionlessQuotaTotals, PriceFeedPrice } from "./types.js";
2
+ import { Address } from "viem";
3
+ //#region src/permissionless/api/oracles/enrich.d.ts
4
+ /**
5
+ * What the oracles namespace works out for itself once the backend has
6
+ * answered.
7
+ *
8
+ * All of it used to be the backend's, and all of it needs the chain: a quota
9
+ * is denominated in its market's own underlying and a market cap is a supply
10
+ * times a price, so none of these can be indexed — they can only be read at
11
+ * the block the reader is on. Keeping them here means one description of each
12
+ * rule rather than one per service that wants it, and a backend that holds no
13
+ * viem client at all.
14
+ **/
15
+ /** Identifies a feed across chains, since an address alone does not. */
16
+ export declare function feedKey(chainId: number, address: Address): string;
17
+ /** Prices looked up the way {@link totalQuotas} and the caps need them. */
18
+ export declare function pricesByFeed(prices: PriceFeedPrice[]): Map<string, bigint | null>;
19
+ /**
20
+ * The asset's quota across its markets, totalled in USD.
21
+ *
22
+ * Each market's figures are converted at the price that market's own oracle
23
+ * holds for its underlying, which is the same number that market's accounting
24
+ * uses.
25
+ *
26
+ * Limits count only the markets still running, because a shut down market's
27
+ * limit is not borrowable; what is already quoted counts everywhere, because
28
+ * debt outstanding is exposure either way. A market whose underlying could not
29
+ * be priced is skipped, which makes both figures floors, and `null` is nothing
30
+ * to total rather than a zero.
31
+ *
32
+ * @param priceOf - The price each underlying feed reports, in the 8 decimals
33
+ * every Gearbox feed uses.
34
+ */
35
+ export declare function totalQuotas(quotas: PermissionlessAssetQuota[], priceOf: (feed: Address) => bigint | null | undefined): PermissionlessQuotaTotals;
36
+ /**
37
+ * What one feed values one asset's supply at: `price × totalSupply`.
38
+ *
39
+ * Multiplied as integers and formatted once, rather than through two floats:
40
+ * an 8-decimal price times an 18-decimal supply loses its small end to a JS
41
+ * number long before it loses the large one, and the figure is a total rather
42
+ * than an estimate.
43
+ *
44
+ * `null` if either side could not be read — an asset nobody could price is
45
+ * not an asset worth nothing.
46
+ */
47
+ export declare function toCap(price: bigint | null | undefined, totalSupply: bigint | null | undefined, decimals: number): string | null;
48
+ /**
49
+ * Assets ordered the way a reader scans them: what the protocol is built on
50
+ * first, then what is actually borrowed against it, then what it is merely
51
+ * allowed to be borrowed against.
52
+ *
53
+ * Applied here and not by the backend because the two middle terms are the
54
+ * converted quotas, which only exist once the chain has been read. The
55
+ * backend orders by the first term and the tie-breakers, so a caller reading
56
+ * the route directly still gets a stable order; this refines it.
57
+ */
58
+ export declare function byCentrality<T extends PermissionlessIndexedAssetSummary & PermissionlessQuotaTotals>(a: T, b: T): number;
59
+ //#endregion
@@ -1,3 +1,3 @@
1
- import { GetPricesArgs, PermissionlessAsset, PermissionlessPriceFeedStore, PermissionlessPrices } from "./types.js";
1
+ import { AssetArgs, AssetCap, AssetsArgs, FeedCap, MarketCap, PermissionlessAsset, PermissionlessAssetDetails, PermissionlessAssetMarket, PermissionlessAssetMarketFeed, PermissionlessAssetQuota, PermissionlessAssetSummary, PermissionlessIndexedAssetDetails, PermissionlessIndexedAssetSummary, PermissionlessIndexedPriceFeedDetails, PermissionlessIndexedPriceFeedMarket, PermissionlessMarket, PermissionlessPriceFeedAsset, PermissionlessPriceFeedDetails, PermissionlessPriceFeedMarket, PermissionlessPriceFeedStore, PermissionlessQuotaTotals, PriceFeedArgs, PriceFeedPrice, PriceFeedRef } from "./types.js";
2
2
  import { GET_PRICES_CHUNK_SIZE, GET_PRICES_GAS_LIMIT_BY_CHAIN_ID, PermissionlessOracles } from "./PermissionlessOracles.js";
3
- export { GET_PRICES_CHUNK_SIZE, GET_PRICES_GAS_LIMIT_BY_CHAIN_ID, GetPricesArgs, PermissionlessAsset, PermissionlessOracles, PermissionlessPriceFeedStore, PermissionlessPrices };
3
+ export { AssetArgs, AssetCap, AssetsArgs, FeedCap, GET_PRICES_CHUNK_SIZE, GET_PRICES_GAS_LIMIT_BY_CHAIN_ID, MarketCap, PermissionlessAsset, PermissionlessAssetDetails, PermissionlessAssetMarket, PermissionlessAssetMarketFeed, PermissionlessAssetQuota, PermissionlessAssetSummary, PermissionlessIndexedAssetDetails, PermissionlessIndexedAssetSummary, PermissionlessIndexedPriceFeedDetails, PermissionlessIndexedPriceFeedMarket, PermissionlessMarket, PermissionlessOracles, PermissionlessPriceFeedAsset, PermissionlessPriceFeedDetails, PermissionlessPriceFeedMarket, PermissionlessPriceFeedStore, PermissionlessQuotaTotals, PriceFeedArgs, PriceFeedPrice, PriceFeedRef };