@gearbox-protocol/sdk 13.3.2 → 13.3.4

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 (92) hide show
  1. package/dist/cjs/rewards/rewards/api.js +4 -124
  2. package/dist/cjs/rewards/rewards/extra-apy.js +5 -7
  3. package/dist/cjs/rewards/rewards/index.js +1 -5
  4. package/dist/cjs/sdk/GearboxSDK.js +135 -20
  5. package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +40 -141
  6. package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +5 -5
  7. package/dist/cjs/sdk/base/BaseContract.js +26 -6
  8. package/dist/cjs/sdk/base/ChainContractsRegister.js +39 -2
  9. package/dist/cjs/sdk/base/Construct.js +15 -3
  10. package/dist/cjs/sdk/base/TokensMeta.js +23 -0
  11. package/dist/cjs/sdk/constants/address-provider.js +0 -22
  12. package/dist/cjs/sdk/core/AbstractAddressProviderContract.js +15 -0
  13. package/dist/cjs/sdk/market/MarketRegister.js +74 -3
  14. package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +31 -50
  15. package/dist/cjs/sdk/market/pricefeeds/PriceFeedRef.js +16 -0
  16. package/dist/cjs/sdk/market/pricefeeds/PriceFeedsRegister.js +55 -12
  17. package/dist/cjs/sdk/options.js +30 -24
  18. package/dist/cjs/sdk/plugins/BasePlugin.js +24 -0
  19. package/dist/cjs/sdk/pools/AbstractPoolService.js +6 -0
  20. package/dist/cjs/sdk/router/AbstractRouterContract.js +4 -1
  21. package/dist/cjs/sdk/router/RouterV310Contract.js +20 -15
  22. package/dist/cjs/sdk/utils/AddressMap.js +53 -17
  23. package/dist/cjs/sdk/utils/AddressSet.js +9 -0
  24. package/dist/cjs/sdk/utils/viem/sendRawTx.js +16 -0
  25. package/dist/esm/rewards/rewards/api.js +4 -124
  26. package/dist/esm/rewards/rewards/extra-apy.js +4 -6
  27. package/dist/esm/rewards/rewards/index.js +0 -2
  28. package/dist/esm/sdk/GearboxSDK.js +135 -20
  29. package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +40 -141
  30. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +5 -5
  31. package/dist/esm/sdk/base/BaseContract.js +26 -6
  32. package/dist/esm/sdk/base/ChainContractsRegister.js +39 -2
  33. package/dist/esm/sdk/base/Construct.js +15 -3
  34. package/dist/esm/sdk/base/TokensMeta.js +23 -0
  35. package/dist/esm/sdk/constants/address-provider.js +0 -21
  36. package/dist/esm/sdk/core/AbstractAddressProviderContract.js +15 -0
  37. package/dist/esm/sdk/market/MarketRegister.js +74 -3
  38. package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +31 -50
  39. package/dist/esm/sdk/market/pricefeeds/PriceFeedRef.js +16 -0
  40. package/dist/esm/sdk/market/pricefeeds/PriceFeedsRegister.js +55 -12
  41. package/dist/esm/sdk/options.js +30 -24
  42. package/dist/esm/sdk/plugins/BasePlugin.js +24 -0
  43. package/dist/esm/sdk/pools/AbstractPoolService.js +6 -0
  44. package/dist/esm/sdk/router/AbstractRouterContract.js +4 -1
  45. package/dist/esm/sdk/router/RouterV310Contract.js +20 -15
  46. package/dist/esm/sdk/utils/AddressMap.js +53 -17
  47. package/dist/esm/sdk/utils/AddressSet.js +9 -0
  48. package/dist/esm/sdk/utils/viem/sendRawTx.js +19 -1
  49. package/dist/types/rewards/rewards/api.d.ts +5 -28
  50. package/dist/types/rewards/rewards/extra-apy.d.ts +1 -1
  51. package/dist/types/rewards/rewards/index.d.ts +0 -2
  52. package/dist/types/sdk/GearboxSDK.d.ts +236 -34
  53. package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +55 -141
  54. package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +14 -5
  55. package/dist/types/sdk/accounts/types.d.ts +219 -17
  56. package/dist/types/sdk/base/BaseContract.d.ts +67 -6
  57. package/dist/types/sdk/base/ChainContractsRegister.d.ts +51 -2
  58. package/dist/types/sdk/base/Construct.d.ts +31 -0
  59. package/dist/types/sdk/base/PlaceholderContract.d.ts +3 -0
  60. package/dist/types/sdk/base/SDKConstruct.d.ts +10 -0
  61. package/dist/types/sdk/base/TokensMeta.d.ts +59 -2
  62. package/dist/types/sdk/base/types.d.ts +185 -25
  63. package/dist/types/sdk/chain/chains.d.ts +78 -18
  64. package/dist/types/sdk/chain/detectNetwork.d.ts +7 -0
  65. package/dist/types/sdk/constants/address-provider.d.ts +4 -3
  66. package/dist/types/sdk/core/AbstractAddressProviderContract.d.ts +23 -0
  67. package/dist/types/sdk/core/types.d.ts +46 -0
  68. package/dist/types/sdk/market/MarketRegister.d.ts +81 -0
  69. package/dist/types/sdk/market/adapters/PlaceholderAdapterContracts.d.ts +3 -0
  70. package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +40 -50
  71. package/dist/types/sdk/market/oracle/types.d.ts +76 -57
  72. package/dist/types/sdk/market/pricefeeds/AbstractLPPriceFeed.d.ts +3 -0
  73. package/dist/types/sdk/market/pricefeeds/AbstractPriceFeed.d.ts +3 -0
  74. package/dist/types/sdk/market/pricefeeds/PriceFeedRef.d.ts +22 -2
  75. package/dist/types/sdk/market/pricefeeds/PriceFeedsRegister.d.ts +77 -13
  76. package/dist/types/sdk/market/pricefeeds/types.d.ts +70 -10
  77. package/dist/types/sdk/options.d.ts +13 -4
  78. package/dist/types/sdk/plugins/BasePlugin.d.ts +39 -0
  79. package/dist/types/sdk/plugins/types.d.ts +73 -43
  80. package/dist/types/sdk/pools/AbstractPoolService.d.ts +12 -0
  81. package/dist/types/sdk/pools/types.d.ts +75 -6
  82. package/dist/types/sdk/router/AbstractRouterContract.d.ts +21 -2
  83. package/dist/types/sdk/router/RouterV310Contract.d.ts +27 -15
  84. package/dist/types/sdk/router/types.d.ts +51 -69
  85. package/dist/types/sdk/types/state.d.ts +32 -3
  86. package/dist/types/sdk/utils/AddressMap.d.ts +61 -17
  87. package/dist/types/sdk/utils/AddressSet.d.ts +15 -0
  88. package/dist/types/sdk/utils/viem/sendRawTx.d.ts +5 -1
  89. package/package.json +4 -2
  90. package/dist/cjs/rewards/rewards/apy.js +0 -177
  91. package/dist/esm/rewards/rewards/apy.js +0 -160
  92. package/dist/types/rewards/rewards/apy.d.ts +0 -44
@@ -2,40 +2,100 @@ import type { Address, Hex, UnionOmit } from "viem";
2
2
  import type { IBaseContract, PriceFeedAnswer } from "../../base/index.js";
3
3
  import type { IPriceUpdateTx, PriceFeedStateHuman, RawTx } from "../../types/index.js";
4
4
  import type { PriceFeedRef } from "./PriceFeedRef.js";
5
+ /**
6
+ * @internal
7
+ * Indicates whether a price feed is used as the primary ("Main") or
8
+ * fallback ("Reserve") oracle for a token. Gearbox uses dual-oracle
9
+ * pricing to protect against oracle manipulation.
10
+ **/
5
11
  export type PriceFeedUsageType = "Main" | "Reserve";
12
+ /**
13
+ * Discriminator for the various on-chain price feed contract implementations
14
+ * (e.g. Curve LP, Balancer, Pyth, Redstone).
15
+ **/
6
16
  export type PriceFeedContractType = "PRICE_FEED::BALANCER_STABLE" | "PRICE_FEED::BALANCER_WEIGHTED" | "PRICE_FEED::BOUNDED" | "PRICE_FEED::COMPOSITE" | "PRICE_FEED::CONSTANT" | "PRICE_FEED::CURVE_CRYPTO" | "PRICE_FEED::CURVE_STABLE" | "PRICE_FEED::CURVE_USD" | "PRICE_FEED::ERC4626" | "PRICE_FEED::EXTERNAL" | "PRICE_FEED::MELLOW_LRT" | "PRICE_FEED::PENDLE_PT_TWAP" | "PRICE_FEED::PYTH" | "PRICE_FEED::REDSTONE" | "PRICE_FEED::WSTETH" | "PRICE_FEED::YEARN" | "PRICE_FEED::ZERO";
17
+ /**
18
+ * Public interface for a single price feed contract.
19
+ *
20
+ * A price feed converts an on-chain or off-chain data source into a
21
+ * USD-denominated price with 8 decimals. Feeds are organized into trees:
22
+ * composite feeds may depend on several underlying feeds.
23
+ **/
7
24
  export interface IPriceFeedContract extends IBaseContract {
25
+ /**
26
+ * Whether this price feed enforces a lower-bound cap on its answer.
27
+ **/
8
28
  readonly hasLowerBoundCap: boolean;
29
+ /**
30
+ * Discriminator identifying gearbox price feed type
31
+ **/
9
32
  readonly priceFeedType: PriceFeedContractType;
33
+ /**
34
+ * Number of decimals in the price answer (typically 8).
35
+ **/
10
36
  readonly decimals: number;
11
37
  /**
12
- * True if the contract deployed at this address implements IUpdatablePriceFeed interface
13
- */
38
+ * `true` if the on-chain contract implements `IUpdatablePriceFeed`,
39
+ * meaning its price can be refreshed via an off-chain data push.
40
+ **/
14
41
  readonly updatable: boolean;
15
42
  /**
16
- * It's possible to create PriceFeed with base params only.
17
- * This flag idicates that all the price feed data (decimals, skip check, dependencies...) has been loaded from compressor
18
- */
43
+ * @internal
44
+ * `true` once the full feed configuration (decimals, skip-check flag,
45
+ * dependencies, etc.) has been loaded. A feed created from base params
46
+ * alone will have `loaded === false`.
47
+ **/
19
48
  readonly loaded: boolean;
20
49
  /**
21
- * Latest answer for this price feed
22
- */
50
+ * Latest price answer for this feed.
51
+ **/
23
52
  readonly answer: PriceFeedAnswer;
53
+ /**
54
+ * Whether price feed implements its own safety and staleness checks
55
+ **/
24
56
  readonly skipCheck: boolean;
57
+ /**
58
+ * Immediate child feeds that this composite feed depends on.
59
+ **/
25
60
  readonly underlyingPriceFeeds: readonly PriceFeedRef[];
61
+ /**
62
+ * Replaces the cached answer with a new value.
63
+ * @param answer - New price answer to store.
64
+ **/
26
65
  updateAnswer: (answer: PriceFeedAnswer) => void;
66
+ /**
67
+ * Returns a human-readable snapshot of this feed's state.
68
+ * @param raw - When `true`, includes raw/unformatted values.
69
+ **/
27
70
  stateHuman: (raw?: boolean) => UnionOmit<PriceFeedStateHuman, "stalenessPeriod">;
28
71
  /**
29
- * Returns all updatable depenedencies (uderlying price feeds) of this price feed, including price feed itself, if it's updatable
30
- * @returns
31
- */
72
+ * Collects all updatable feeds in this feed's dependency tree,
73
+ * including this feed itself when it is updatable.
74
+ **/
32
75
  updatableDependencies: () => IUpdatablePriceFeedContract[];
33
76
  }
77
+ /**
78
+ * Extended price feed interface for feeds whose price can be refreshed
79
+ * via an off-chain data push (e.g. Pyth or Redstone feeds).
80
+ **/
34
81
  export interface IUpdatablePriceFeedContract extends IPriceFeedContract {
82
+ /**
83
+ * Builds a raw transaction that pushes new price data to the on-chain feed.
84
+ * @param data - ABI-encoded update payload.
85
+ **/
35
86
  createPriceUpdateTx: (data: `0x${string}`) => RawTx;
36
87
  }
88
+ /**
89
+ * Result of generating price-feed update transactions.
90
+ **/
37
91
  export interface UpdatePriceFeedsResult {
92
+ /**
93
+ * Transactions that push fresh prices to updatable feeds.
94
+ **/
38
95
  txs: IPriceUpdateTx[];
96
+ /**
97
+ * Latest timestamp among all fetched price updates (unix seconds).
98
+ **/
39
99
  timestamp: number;
40
100
  }
41
101
  export interface PriceUpdateV310 {
@@ -1,6 +1,9 @@
1
1
  import { z } from "zod/v4";
2
2
  import type { PluginsMap } from "./plugins/index.js";
3
3
  import type { ILogger } from "./types/index.js";
4
+ /**
5
+ * Zod schema for validating {@link SDKOptions} at runtime.
6
+ **/
4
7
  export declare const SDKOptions: z.ZodObject<{
5
8
  addressProvider: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>>;
6
9
  marketConfigurators: z.ZodOptional<z.ZodArray<z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>>>;
@@ -25,13 +28,19 @@ export declare const SDKOptions: z.ZodObject<{
25
28
  }, z.core.$strip>>;
26
29
  gasLimit: z.ZodOptional<z.ZodNullable<z.ZodBigInt>>;
27
30
  }, z.core.$strip>;
31
+ /**
32
+ * Configuration options accepted by {@link GearboxSDK.attach} and related
33
+ * factory methods.
34
+ *
35
+ * @typeParam Plugins - Map of plugin names to plugin instances.
36
+ **/
28
37
  export type SDKOptions<Plugins extends PluginsMap> = Omit<z.infer<typeof SDKOptions>, "logger" | "plugins"> & {
29
38
  /**
30
- * Plugins to extends SDK functionality
31
- */
39
+ * Plugins that extend SDK functionality.
40
+ **/
32
41
  plugins?: Plugins;
33
42
  /**
34
- * Bring your own logger
35
- */
43
+ * Custom logger implementation.
44
+ **/
36
45
  logger?: ILogger;
37
46
  };
@@ -2,18 +2,57 @@ import type { Address, PublicClient } from "viem";
2
2
  import type { NetworkType } from "../chain/index.js";
3
3
  import type { GearboxSDK } from "../GearboxSDK.js";
4
4
  import type { ILogger } from "../index.js";
5
+ /**
6
+ * Convenience base class for {@link IGearboxSDKPlugin} implementations.
7
+ *
8
+ * Handles the SDK attachment lifecycle, logger setup, and provides
9
+ * common accessors (`network`, `client`). Subclasses only need to
10
+ * implement {@link load} to supply their domain-specific state.
11
+ *
12
+ * @typeParam TState - Plugin-specific state shape.
13
+ **/
5
14
  export declare abstract class BasePlugin<TState extends Record<keyof TState, unknown> = {}> {
6
15
  #private;
7
16
  protected logger?: ILogger;
17
+ /**
18
+ * Plugin state version for hydration compatibility checks.
19
+ * @default 1
20
+ **/
8
21
  readonly version: number;
22
+ /**
23
+ * When `true`, state is fetched eagerly during the `attach` phase
24
+ * rather than waiting for an explicit `load` call.
25
+ **/
9
26
  readonly loadOnAttach: boolean;
10
27
  constructor(loadOnAttach?: boolean);
28
+ /**
29
+ * Reference to the parent SDK instance.
30
+ * @throws Error if the SDK has not been attached yet.
31
+ **/
11
32
  get sdk(): GearboxSDK<any>;
12
33
  set sdk(sdk: GearboxSDK<any>);
34
+ /**
35
+ * {@inheritDoc IGearboxSDKPlugin.attach}
36
+ **/
13
37
  attach(): Promise<void>;
38
+ /**
39
+ * {@inheritDoc IGearboxSDKPlugin.syncState}
40
+ **/
14
41
  syncState(): Promise<void>;
42
+ /**
43
+ * Loads or refreshes the plugin state.
44
+ *
45
+ * @param force - When `true`, re-fetch even if state is already loaded.
46
+ * @returns The loaded plugin state.
47
+ **/
15
48
  abstract load(force?: boolean): Promise<TState>;
49
+ /**
50
+ * Network type of the connected chain (e.g. `"Mainnet"`, `"Arbitrum"`).
51
+ **/
16
52
  get network(): NetworkType;
53
+ /**
54
+ * Viem public client for read-only chain interactions.
55
+ **/
17
56
  get client(): PublicClient;
18
57
  protected labelAddress(address: Address): string;
19
58
  }
@@ -1,5 +1,13 @@
1
1
  import type { BaseState, IBaseContract } from "../base/index.js";
2
2
  import type { GearboxSDK } from "../GearboxSDK.js";
3
+ /**
4
+ * Serialisable snapshot of a plugin's state, used for hydration.
5
+ *
6
+ * When `loaded` is `false` only the `version` field is present;
7
+ * when `loaded` is `true` the full `State` payload is included.
8
+ *
9
+ * @typeParam State - Plugin-specific state shape.
10
+ **/
3
11
  export type IPluginState<State extends Record<keyof State, unknown> = {}> = {
4
12
  version: number;
5
13
  } & ({
@@ -7,77 +15,99 @@ export type IPluginState<State extends Record<keyof State, unknown> = {}> = {
7
15
  } | ({
8
16
  loaded: true;
9
17
  } & State));
18
+ /**
19
+ * @internal
20
+ * Constructor signature that the SDK uses to instantiate a plugin.
21
+ *
22
+ * @typeParam TState - Plugin-specific state shape.
23
+ * @typeParam TPlugin - Concrete plugin type produced by the constructor.
24
+ **/
10
25
  export type IGearboxSDKPluginConstructor<TState extends Record<keyof TState, unknown>, TPlugin extends IGearboxSDKPlugin<TState>> = new (sdk: GearboxSDK<any>) => TPlugin;
26
+ /**
27
+ * Public contract every SDK plugin must satisfy.
28
+ *
29
+ * Plugins extend the SDK with domain-specific data and behaviour
30
+ * (e.g. farming rewards, zapper helpers). They participate in the
31
+ * SDK lifecycle: attach, hydrate, sync, and on-demand load.
32
+ *
33
+ * @typeParam TState - Plugin-specific state shape.
34
+ **/
11
35
  export interface IGearboxSDKPlugin<TState extends Record<keyof TState, unknown> = {}> {
12
36
  /**
13
- * Plugin's SDK. Is set by SDK itself in SDK constructor
14
- */
37
+ * Reference to the parent SDK instance.
38
+ * Set automatically by the SDK constructor.
39
+ **/
15
40
  sdk: GearboxSDK<any>;
16
41
  /**
17
- * Plugin version, used to check if the plugin state is compatible with the plugin during hydration
18
- */
42
+ * Plugin version, used to verify state compatibility during hydration.
43
+ **/
19
44
  version: number;
20
45
  /**
21
- * Indicates that plugins state is ready to use
22
- * It does not matter how this state was obtained, be it via attach, hydrate or on-demand load
23
- */
46
+ * Whether the plugin's state is ready to use.
47
+ * `true` regardless of how the state was obtained (attach, hydrate, or on-demand load).
48
+ **/
24
49
  loaded: boolean;
25
50
  /**
26
- * Plugin state, can be hydarted/dehydrated
27
- */
51
+ * Plugin state, can be hydrated later.
52
+ **/
28
53
  state: TState;
29
54
  /**
30
- * Loads state on demand
31
- * If it's already loaded, does nothing and returns the same state, unless force is set to true
32
- * @param force
33
- * @returns
34
- */
55
+ * Loads state on demand.
56
+ * If already loaded, returns the existing state unless `force` is `true`.
57
+ *
58
+ * @param force - Re-fetch even if state is already loaded.
59
+ * @returns The loaded plugin state.
60
+ **/
35
61
  load?: (force?: boolean) => Promise<TState>;
36
62
  /**
37
- * Called after SDK is attached
38
- * Plugins are not required to implement this. For example plugin can be stateless, or load state on demand only
39
- * @param sdk
40
- * @returns
41
- */
63
+ * Called after SDK is attached to the chain.
64
+ * Plugins are not required to implement this a plugin can be stateless
65
+ * or load state on demand only.
66
+ **/
42
67
  attach?: () => Promise<void>;
43
68
  /**
44
- * Loads plugin state from dehydrated state
45
- * @param state
46
- * @returns
47
- */
69
+ * Restores plugin state from a previously saved snapshot.
70
+ *
71
+ * @param state - state to restore from.
72
+ **/
48
73
  hydrate?: (state: TState) => void;
49
74
  /**
50
- * Called after SDK state is already synced, meaning that block number and timestamp are accessible from SDK
51
- *
52
- * @param sdk
53
- * @returns
54
- */
75
+ * Hook to sync plugin state after sdk state is synced.
76
+ * Called after SDK state is already synced, meaning that block number
77
+ * and timestamp are accessible from the SDK.
78
+ **/
55
79
  syncState?: () => Promise<void>;
56
80
  /**
57
- * Can be called by SDK to create some auxiliary contracts, such as zappers and adapters
58
- * Otherwise they are created as BaseContract instances by sdk
59
- * @param params
60
- * @returns
61
- */
81
+ * Factory hook called by the SDK to create auxiliary contracts
82
+ * (e.g. zappers, adapters). If not implemented, the SDK falls back to
83
+ * generic {@link BaseContract} instances.
84
+ *
85
+ * @param params - On-chain identification parameters for the contract.
86
+ * @returns A contract instance, or `undefined` to let the SDK use the default.
87
+ **/
62
88
  createContract?: (params: BaseState) => IBaseContract | undefined;
63
89
  /**
64
- * Human readable state for diagnostics
65
- * @param raw (print actual values in addition to human-friendly values, e.g. 1 ETH (1000000000000000000))
66
- * @returns
67
- */
90
+ * Human-readable state snapshot for diagnostics.
91
+ *
92
+ * @param raw - When `true`, include raw numeric values alongside formatted ones
93
+ * (e.g. `1 ETH (1000000000000000000)`).
94
+ * @returns An untyped object suitable for logging or inspection.
95
+ **/
68
96
  stateHuman?: (raw?: boolean) => unknown;
69
97
  }
70
98
  /**
71
- * Helper type that extracts the state type from a plugin instance
72
- */
99
+ * Helper type that extracts the state type from a plugin instance.
100
+ **/
73
101
  export type PluginState<T> = T extends IGearboxSDKPlugin<infer TState> ? IPluginState<TState> : never;
74
102
  /**
75
- * Mapping between plugin name and plugin instance
76
- */
103
+ * @internal
104
+ * Mapping between plugin name and plugin instance.
105
+ **/
77
106
  export type PluginsMap = Record<string, IGearboxSDKPlugin<any>>;
78
107
  /**
79
- * Mapping that infers plugin states map from plugin instances map
80
- */
108
+ * @internal
109
+ * Mapping that infers plugin states from plugin instances.
110
+ **/
81
111
  export type PluginStatesMap<T extends PluginsMap> = {
82
112
  [K in keyof T]: PluginState<T[K]>;
83
113
  };
@@ -1,9 +1,21 @@
1
1
  import { SDKConstruct } from "../base/index.js";
2
2
  import type { GearboxSDK } from "../GearboxSDK.js";
3
3
  import type { AddLiquidityCall, AddLiquidityProps, RemoveLiquidityCall, RemoveLiquidityProps } from "./types.js";
4
+ /**
5
+ * @internal
6
+ * Base implementation of {@link IPoolsService}.
7
+ *
8
+ * Used to generate data for write operations on LP side (deposit to/withdraw from pool)
9
+ **/
4
10
  export declare abstract class AbstractPoolService extends SDKConstruct {
5
11
  #private;
6
12
  constructor(sdk: GearboxSDK, version: number);
13
+ /**
14
+ * {@inheritDoc IPoolsService.addLiquidity}
15
+ **/
7
16
  addLiquidity({ collateral, pool, account, zapper, permit, nativeTokenAddress, referralCode, migrate, }: AddLiquidityProps): AddLiquidityCall;
17
+ /**
18
+ * {@inheritDoc IPoolsService.removeLiquidity}
19
+ **/
8
20
  removeLiquidity({ pool, amount, account, zapper, permit, }: RemoveLiquidityProps): RemoveLiquidityCall;
9
21
  }
@@ -20,16 +20,54 @@ interface PermitResult {
20
20
  deadline: bigint;
21
21
  nonce: bigint;
22
22
  }
23
+ /**
24
+ * Parameters for depositing liquidity into a Gearbox lending pool.
25
+ *
26
+ * When a `zapper` is provided, the deposit is routed through a zapper
27
+ * contract that handles token conversions (e.g. native ETH wrapping or
28
+ * ERC-20 permit-based approvals). Without a zapper, the deposit goes
29
+ * directly to the pool contract.
30
+ **/
23
31
  export interface AddLiquidityProps {
32
+ /**
33
+ * Token and amount to deposit.
34
+ **/
24
35
  collateral: Asset;
36
+ /**
37
+ * Address of the Gearbox lending pool.
38
+ **/
25
39
  pool: Address;
40
+ /**
41
+ * Recipient of the pool shares (diesel tokens).
42
+ **/
26
43
  account: Address;
44
+ /**
45
+ * Whether this deposit is part of a pool migration.
46
+ * When `true`, a zapper is required.
47
+ **/
27
48
  migrate: boolean;
49
+ /**
50
+ * Optional zapper to route the deposit through.
51
+ **/
28
52
  zapper: IZapper | undefined;
53
+ /**
54
+ * Optional ERC-2612 permit for gasless token approval.
55
+ **/
29
56
  permit: PermitResult | undefined;
57
+ /**
58
+ * Address of the chain's native-token wrapper (e.g. WETH).
59
+ **/
30
60
  nativeTokenAddress: Address;
61
+ /**
62
+ * Optional referral code for tracking the deposit source.
63
+ **/
31
64
  referralCode: bigint | undefined;
32
65
  }
66
+ /**
67
+ * Tuple describing a single contract call to execute an add-liquidity
68
+ * operation. The exact variant depends on whether a zapper and/or
69
+ * permit is used.
70
+ **/
33
71
  export type AddLiquidityCall = [
34
72
  {
35
73
  target: Address;
@@ -54,13 +92,39 @@ export type AddLiquidityCall = [
54
92
  args: [bigint, Address, bigint];
55
93
  }
56
94
  ];
95
+ /**
96
+ * Parameters for withdrawing liquidity from a Gearbox lending pool.
97
+ *
98
+ * Withdrawals are routed through a zapper that redeems pool shares
99
+ * (diesel tokens) for the underlying asset.
100
+ **/
57
101
  export interface RemoveLiquidityProps {
102
+ /**
103
+ * Address of the Gearbox lending pool.
104
+ **/
58
105
  pool: Address;
106
+ /**
107
+ * Amount of pool shares (diesel tokens) to redeem.
108
+ **/
59
109
  amount: bigint;
110
+ /**
111
+ * Recipient of the redeemed underlying tokens.
112
+ **/
60
113
  account: Address;
114
+ /**
115
+ * Optional ERC-2612 permit for gasless token approval.
116
+ **/
61
117
  permit: PermitResult | undefined;
118
+ /**
119
+ * Zapper to route the redemption through.
120
+ **/
62
121
  zapper: IZapper;
63
122
  }
123
+ /**
124
+ * Tuple describing a single contract call to execute a remove-liquidity
125
+ * operation. The exact variant depends on whether a permit is used and
126
+ * whether the withdrawal goes through a zapper or directly to the pool.
127
+ **/
64
128
  export type RemoveLiquidityCall = [
65
129
  {
66
130
  target: Address;
@@ -79,18 +143,23 @@ export type RemoveLiquidityCall = [
79
143
  args: [bigint, Address, Address];
80
144
  }
81
145
  ];
146
+ /**
147
+ * Service interface for pool liquidity operations.
148
+ **/
82
149
  export interface IPoolsService {
83
150
  /**
84
- * Add liquidity to a pool
151
+ * Construct a call to add liquidity to a Gearbox lending pool.
152
+ *
85
153
  * @param props - {@link AddLiquidityProps}
86
- * @returns - {@link AddLiquidityCall}
87
- */
154
+ * @returns A single-element tuple with the encoded contract call.
155
+ **/
88
156
  addLiquidity(props: AddLiquidityProps): AddLiquidityCall;
89
157
  /**
90
- * Remove liquidity from a pool
158
+ * Construct a call to remove liquidity from a Gearbox lending pool.
159
+ *
91
160
  * @param props - {@link RemoveLiquidityProps}
92
- * @returns - {@link RemoveLiquidityCall}
93
- */
161
+ * @returns A single-element tuple with the encoded contract call.
162
+ **/
94
163
  removeLiquidity(props: RemoveLiquidityProps): RemoveLiquidityCall;
95
164
  }
96
165
  export {};
@@ -3,19 +3,38 @@ import { BaseContract, type BaseContractArgs } from "../base/index.js";
3
3
  import type { GearboxSDK } from "../GearboxSDK.js";
4
4
  import type { IPriceOracleContract } from "../market/index.js";
5
5
  import { AddressMap, AddressSet } from "../utils/index.js";
6
- import type { Asset, ExpectedAndLeftoverOptions, RouterCASlice, RouterCMSlice } from "./types.js";
6
+ import type { Asset, RouterCASlice, RouterCMSlice } from "./types.js";
7
+ export interface ExpectedAndLeftoverOptions {
8
+ balances?: Leftovers;
9
+ keepAssets?: Address[];
10
+ debtOnly?: boolean;
11
+ }
7
12
  export interface Leftovers {
8
13
  expectedBalances: AddressMap<Asset>;
9
14
  leftoverBalances: AddressMap<Asset>;
10
15
  tokensToClaim: AddressMap<Asset>;
11
16
  }
17
+ /**
18
+ * @internal
19
+ * Base class for router contract wrappers.
20
+ *
21
+ * Provides helpers that classify credit-account token balances into
22
+ * "expected" (to be swapped) and "leftover" (to be kept) categories,
23
+ * which concrete router implementations use when building optimised
24
+ * multi-call swap paths.
25
+ *
26
+ * @typeParam abi - ABI type of the underlying router contract.
27
+ **/
12
28
  export declare abstract class AbstractRouterContract<abi extends Abi | readonly unknown[]> extends BaseContract<abi> {
29
+ /**
30
+ * Reference to the parent SDK instance.
31
+ **/
13
32
  readonly sdk: GearboxSDK;
14
33
  constructor(sdk: GearboxSDK, args: BaseContractArgs<abi>);
15
34
  protected getExpectedAndLeftover(ca: RouterCASlice, cm: RouterCMSlice, options?: ExpectedAndLeftoverOptions): Leftovers;
16
35
  protected getDefaultExpectedAndLeftover(ca: RouterCASlice, keepAssets?: Address[], debtOnly?: boolean): Leftovers;
17
36
  /**
18
- * Tries to sell just enought of most valuable token to cover debt
37
+ * Tries to sell just enough of the most valuable token to cover debt.
19
38
  * @param ca
20
39
  * @param keepAssets
21
40
  * @returns
@@ -884,35 +884,47 @@ declare const abi: readonly [{
884
884
  }];
885
885
  }];
886
886
  type abi = typeof abi;
887
+ /**
888
+ * V3.10 implementation of the {@link IRouterContract} interface.
889
+ *
890
+ * Uses the on-chain Gearbox router to find optimal multi-hop swap
891
+ * paths, splitting large positions across multiple routes to reduce
892
+ * price impact.
893
+ **/
887
894
  export declare class RouterV310Contract extends AbstractRouterContract<abi> implements IRouterContract {
888
895
  #private;
889
896
  constructor(sdk: GearboxSDK, address: Address, version: number);
890
897
  /**
891
- * Implements {@link IRouterContract.findOneTokenPath}
892
- */
898
+ * {@inheritDoc IRouterContract.findOneTokenPath}
899
+ **/
893
900
  findOneTokenPath(props: FindOneTokenPathProps): Promise<RouterResult>;
894
901
  /**
895
- * Implements {@link IRouterContract.findOpenStrategyPath}
896
- */
902
+ * {@inheritDoc IRouterContract.findOpenStrategyPath}
903
+ **/
897
904
  findOpenStrategyPath(props: FindOpenStrategyPathProps): Promise<OpenStrategyResult>;
898
905
  /**
899
- * Implements {@link IRouterContract.findClaimAllRewards}
900
- */
906
+ * {@inheritDoc IRouterContract.findClaimAllRewards}
907
+ **/
901
908
  findClaimAllRewards(props: FindClaimAllRewardsProps): Promise<RouterRewardsResult>;
902
909
  /**
903
- * Implements {@link IRouterContract.findBestClosePath}
904
- */
910
+ * {@inheritDoc IRouterContract.findBestClosePath}
911
+ **/
905
912
  findBestClosePath(props: FindBestClosePathProps): Promise<RouterCloseResult>;
906
913
  /**
907
- * v310-specific method to set explicitly number of splits for a token
908
- * @param token
909
- * @param numSplits
910
- */
914
+ * Override the number of route splits used when swapping a specific token.
915
+ *
916
+ * @param token - Token address to configure.
917
+ * @param numSplits - Number of parallel route splits.
918
+ * @internal
919
+ **/
911
920
  setNumSplits(token: Address, numSplits: bigint): void;
912
921
  /**
913
- * v310-specific method to set default number of splits for a token
914
- * @param numSplits
915
- */
922
+ * Set the default number of route splits applied to the highest-value
923
+ * token in each swap.
924
+ *
925
+ * @param numSplits - Default number of parallel route splits.
926
+ * @internal
927
+ **/
916
928
  setDefaultNumSplits(numSplits: bigint): void;
917
929
  }
918
930
  export {};