import type { Abi, Address, ContractFunctionArgs, ContractFunctionName } from "viem"; import type { ZapperData } from "../market/index.js"; import type { Asset } from "../router/index.js"; interface PermitResult { r: Address; s: Address; v: number; token: Address; owner: Address; spender: Address; value: bigint; deadline: bigint; nonce: bigint; } export type PoolServiceCall = ContractFunctionName, args extends ContractFunctionArgs = ContractFunctionArgs> = { abi: abi; functionName: functionName; args: args; target: Address; value?: bigint; }; export interface AddLiquidityProps { /** * Token and amount to deposit. **/ collateral: Asset; /** * Address of the Gearbox lending pool. **/ pool: Address; wallet: Address; meta: DepositMetadata; permit?: PermitResult; referralCode?: bigint; } /** * Parameters for withdrawing liquidity from a Gearbox lending pool. * * Withdrawals are routed through a zapper that redeems pool shares * (diesel tokens) for the underlying asset. **/ export interface RemoveLiquidityProps { /** * Address of the Gearbox lending pool. **/ pool: Address; /** * Amount of pool shares (diesel tokens) to redeem. **/ amount: bigint; wallet: Address; permit: PermitResult | undefined; meta: WithdrawalMetadata; } export type MarketType = "rwa-on-demand" | "rwa-default" | "classic"; export interface DepositMetadata { /** * Zapper that will perform the deposit, undefined in case of direct pool underlying deposit */ zapper?: ZapperData; /** * Before deposit user will nedd to call approve method on token that he wants to deposit, * this is the spender address that will be used to call approve method. */ approveTarget: Address; /** * If true, user can avoid approval step and deposit with permit */ permissible: boolean; /** * Type of deposit * @default "classic" */ type?: MarketType; } export interface WithdrawalMetadata { /** * Zapper that will perform the withdrawal, undefined in case of direct pool underlying withdrawal */ zapper?: ZapperData; /** * Before withdrawal user will need to call approve method on token that he wants to withdraw (diesel token), * this is the spender address that will be used to call approve method. */ approveTarget?: Address; /** * If true, user can avoid approval step and withdrawal with permit */ permissible: boolean; /** * Type of withdrawal * @default "classic" */ type?: MarketType; } /** * Service interface for pool liquidity operations. **/ export interface IPoolsService { /** * Returns list of tokens that can be deposited to a pool * @param pool */ getDepositTokensIn(pool: Address): Address[]; /** * Returns list of tokens that user can receive after depositing to a pool, * depends on the pool type and the token being deposited (one of returned by {@link getDepositTokensIn}). * * Can return empty array if no tokens can be received (e.g. for RWA underlying on demand) * * @param pool * @param tokenIn */ getDepositTokensOut(pool: Address, tokenIn: Address): Address[]; /** * After user chooses tokenIn from {@link getDepositTokensIn} and tokenOut from {@link getDepositTokensOut}, * this method returns metadata that will be used to perform the deposit. * * @param pool * @param tokenIn * @param tokenOut can be undefined if deposit is not resulting in a token out (e.g. for RWA underlying on demand) */ getDepositMetadata(pool: Address, tokenIn: Address, tokenOut?: Address): DepositMetadata; /** * Returns a list of tokens that can be redeemed from a pool * @param pool */ getWithdrawalTokensIn(pool: Address): Address[]; /** * Returns a list of tokens that can be received after redeeming from a pool * @param pool * @param tokenIn token that will be redeemed from the pool */ getWithdrawalTokensOut(pool: Address, tokenIn: Address): Address[]; /** * After user chooses tokenIn from {@link getWithdrawalTokensIn} and tokenOut from {@link getWithdrawalTokensOut}, * this method returns metadata that will be used to perform the withdrawal. * @param pool * @param tokenIn * @param tokenOut */ getWithdrawalMetadata(pool: Address, tokenIn: Address, tokenOut?: Address): WithdrawalMetadata; /** * Returns contract call parameters for adding liquidity to a pool * Or undefined if no deposit action is required (e.g. for RWA underlying on demand) * @param props - {@link AddLiquidityProps} * @returns - {@link AddLiquidityCall} */ addLiquidity(props: AddLiquidityProps): PoolServiceCall | undefined; /** * Construct a call to remove liquidity from a Gearbox lending pool. * * @param props - {@link RemoveLiquidityProps} * @returns - {@link RemoveLiquidityCall} */ removeLiquidity(props: RemoveLiquidityProps): PoolServiceCall; } export {};