import { type MarketParams } from "@morpho-org/blue-sdk"; import { type Address } from "viem"; import type { BlueRepayAction, Metadata, PermitRequirementSignature, RepayActionAmountArgs, Transaction } from "../../types/index.js"; /** Parameters for {@link blueRepay}. */ export interface BlueRepayParams { market: { readonly chainId: number; readonly marketParams: MarketParams; }; args: RepayActionAmountArgs & { /** Address whose debt is being repaid. */ onBehalf: Address; /** Receives residual loan tokens in shares mode. */ receiver: Address; /** Maximum repay share price (in ray). Protects against share price manipulation. */ maxSharePrice: bigint; /** Optional pre-signed permit/permit2 approval for the loan-token transfer. */ requirementSignature?: PermitRequirementSignature; }; metadata?: Metadata; } /** * Prepares a repay transaction for a Morpho Blue market. * * Routed through bundler3 via `GeneralAdapter1`. All amount arithmetic is done upstream (see * `MorphoBlue.repay`); this builder just assembles the bundle from the pre-resolved * {@link RepayActionAmountArgs}. The mode is discriminated on `shares`, plus optional native wrapping * (when `nativeAmount > 0`, native ETH is wrapped via `GeneralAdapter1.wrapNative()` before the * repay; the loan token must be the chain's wNative): * * - **assets mode** (`shares` unset/`0n`): repays `transferAmount` assets (`= amount + nativeAmount`, * additive like `blueSupply`), pulling `amount` ERC-20 and wrapping `nativeAmount`. No residual. * - **shares mode** (`shares > 0n`): repays exact shares (full repay), pulling `transferAmount` * ERC-20 (already net of native) and wrapping `nativeAmount`. Residual loan tokens are skimmed * back to `receiver` after the call. * * Uses `maxSharePrice` to protect against share price manipulation between construction and execution. * * @param params.market.chainId - The chain the market lives on. * @param params.market.marketParams - Market params (loanToken, collateralToken, oracle, irm, lltv). * @param params.args.amount - (assets mode) ERC-20 loan tokens pulled from the payer. Defaults to `0n`. * @param params.args.shares - (shares mode) Repay amount in borrow shares. Discriminates the mode. * @param params.args.transferAmount - Loan tokens routed into `GeneralAdapter1`: assets mode = the * total repaid (`amount + nativeAmount`); shares mode = the ERC-20 pulled (net of native). * @param params.args.nativeAmount - Optional native token to wrap into wNative to fund the repay. * Requires the loan token to be the chain's wNative. * @param params.args.onBehalf - Address whose Morpho debt is being repaid. * @param params.args.receiver - Address that receives residual loan tokens in shares mode. * @param params.args.maxSharePrice - Maximum acceptable repay share price (in ray). Slippage * protection. * @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval for the * loan-token transfer. * @param params.metadata - Optional analytics metadata attached to the bundle. * @returns A deep-frozen `Transaction` with `to`, `value` (= `nativeAmount`), * `data`, and the typed `action` discriminator the simulation layer consumes. * @throws {NonPositiveInputError} when `maxSharePrice <= 0n` or the total funding is zero. * @throws {NegativeInputError} when `amount`, `shares`, `nativeAmount`, or `transferAmount` is negative. * @throws {MutuallyExclusiveRepayAmountsError} when both `amount` and `shares` are `> 0n`. * @throws {TransferAmountNotEqualToAssetsError} when in assets mode and * `transferAmount !== amount + nativeAmount`. * @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative. * @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the loan token is not * the chain's wNative. * @throws {DepositAssetMismatchError} from `getTokenRequirementActions` when `requirementSignature` * is provided and the signed asset differs from `marketParams.loanToken`. * @throws {DepositAmountMismatchError} from `getTokenRequirementActions` when `requirementSignature` * is provided and the signed amount differs from the ERC-20 amount pulled. * @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement * signature is missing its expiration. * @example * ```ts * import { blueRepay } from "@morpho-org/morpho-sdk"; * * // Repay 0.5 loan-asset units, 0.2 of them funded by wrapping native ETH. * const tx = blueRepay({ * market: { chainId: 1, marketParams }, // marketParams.loanToken === wNative * args: { * amount: 300_000_000_000_000_000n, // ERC-20 part * nativeAmount: 200_000_000_000_000_000n, // wrapped ETH part * transferAmount: 500_000_000_000_000_000n, // total repaid = amount + nativeAmount * onBehalf: borrower, * receiver: borrower, * maxSharePrice: 1_010_000_000_000_000_000_000_000_000n, // RAY-scaled, 1.01x * }, * }); * // tx.value === 200_000_000_000_000_000n * ``` */ export declare const blueRepay: ({ market: { chainId, marketParams }, args, metadata, }: BlueRepayParams) => Readonly>;