Lending Morpho EVM API Reference
API Reference for @morpho-org/wdk-protocol-lending-morpho-evm
API Reference
Class: MorphoProtocolEvm
Main class for Morpho Vault V2 and Morpho Blue lending on EVM.
Constructor
new MorphoProtocolEvm(account, options)Parameters:
account:WalletAccountEvm | WalletAccountReadOnlyEvm | WalletAccountEvmErc4337 | WalletAccountReadOnlyEvmErc4337options:MorphoProtocolOptions
Example:
const morpho = new MorphoProtocolEvm(account, {
presets: {
earn: 'sky-money-usdt-savings',
borrow: 'wsteth'
}
})Methods
| Method | Description | Returns |
|---|---|---|
supply(options, config?) | Deposit assets into the configured vault | Promise<SupplyResult> |
getSupplyRequirements(options, requirementOptions?) | Return approval or signature requirements for vault deposit | Promise<ApprovalOrSignatureRequirement[]> |
quoteSupply(options, config?) | Quote vault deposit | Promise<Omit<SupplyResult, "hash">> |
withdraw(options, config?) | Withdraw assets from the configured vault | Promise<WithdrawResult> |
quoteWithdraw(options, config?) | Quote vault withdrawal | Promise<Omit<WithdrawResult, "hash">> |
supplyCollateral(options, config?) | Supply collateral to the configured market | Promise<SupplyResult> |
getSupplyCollateralRequirements(options, requirementOptions?) | Return approval or signature requirements for collateral supply | Promise<ApprovalOrSignatureRequirement[]> |
quoteSupplyCollateral(options, config?) | Quote collateral supply | Promise<Omit<SupplyResult, "hash">> |
borrow(options, config?) | Borrow from the configured market | Promise<BorrowResult> |
getBorrowRequirements(options) | Return Morpho authorization requirements for borrow | Promise<RequirementAuthorization[]> |
quoteBorrow(options, config?) | Quote borrow | Promise<Omit<BorrowResult, "hash">> |
repay(options, config?) | Repay the configured market | Promise<RepayResult> |
getRepayRequirements(options, requirementOptions?) | Return approval or signature requirements for repay | Promise<ApprovalOrSignatureRequirement[]> |
quoteRepay(options, config?) | Quote repay | Promise<Omit<RepayResult, "hash">> |
withdrawCollateral(options, config?) | Withdraw collateral from the configured market | Promise<WithdrawResult> |
quoteWithdrawCollateral(options, config?) | Quote collateral withdrawal | Promise<Omit<WithdrawResult, "hash">> |
getVaultPosition(account?) | Read configured vault position | Promise<VaultPosition> |
getMarketPosition(account?) | Read configured market position | Promise<MarketPosition> |
getAccountData(account?) | Read combined configured vault and market position | Promise<AccountData> |
getVaultAddress() | Return the configured vault address | Address |
getBorrowMarketId() | Return the configured borrow market id | string |
Requirements and Results
ApprovalOrSignatureRequirement: returned by supply, collateral supply, and repay requirement helpers. Each item is either a Morpho SDK approval transaction withto,value, anddata, or a signature requirement withsign(client, userAddress).RequirementAuthorization: returned bygetBorrowRequirements(). These are Morpho authorization transactions withto,value, anddata.RequirementSignature: returned by a signature requirement'ssign(client, userAddress)helper. Pass it tosupply(),supplyCollateral(), orrepay()asrequirementSignature.- Write methods return the WDK wallet transaction result, including
hashandfee. Quote methods return the same protocol result withouthash.
supply(options, config?)
Deposit assets into the configured Morpho vault.
Options:
token(string): configured vault assetamount(number | bigint, optional whennativeAmountis set): ERC-20 amount in base unitsnativeAmount(number | bigint, optional): native amount to wrap and supplyonBehalfOf(string, optional): must equal the connected wallet address when setrequirementSignature(RequirementSignature, optional): signature returned by a Morpho SDK requirementslippageTolerance(bigint, optional): per-call Morpho SDK slippage tolerance
const tx = await morpho.supply({
token: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
amount: 1000000n
})getSupplyRequirements(options, requirementOptions?)
Return Morpho SDK approval or signature requirements for a vault deposit. Use it before supply() when the account has not approved the required spender or when signature support is enabled.
const requirements = await morpho.getSupplyRequirements({
token: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
amount: 1000000n
})quoteSupply(options, config?)
Quote the fee for a vault deposit transaction.
const quote = await morpho.quoteSupply({
token: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
amount: 1000000n
})withdraw(options, config?)
Withdraw assets from the configured Morpho vault.
Options:
token(string): configured vault assetamount(number | bigint): amount in base unitsto(string, optional): must equal the connected wallet address when set
const tx = await morpho.withdraw({
token: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
amount: 1000000n
})quoteWithdraw(options, config?)
Quote the fee for a vault withdrawal transaction.
const quote = await morpho.quoteWithdraw({
token: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
amount: 1000000n
})supplyCollateral(options, config?)
Supply collateral to the configured Morpho Blue market.
Options:
token(string): configured market collateral tokenamount(number | bigint, optional whennativeAmountis set): ERC-20 amount in base unitsnativeAmount(number | bigint, optional): native amount to wrap and supplyonBehalfOf(string, optional): must equal the connected wallet address when setrequirementSignature(RequirementSignature, optional): signature returned by a Morpho SDK requirement
const tx = await morpho.supplyCollateral({
token: 'COLLATERAL_TOKEN_ADDRESS',
amount: 1000000000000000000n
})getSupplyCollateralRequirements(options, requirementOptions?)
Return Morpho SDK approval or signature requirements for collateral supply.
const requirements = await morpho.getSupplyCollateralRequirements({
token: 'COLLATERAL_TOKEN_ADDRESS',
amount: 1000000000000000000n
})quoteSupplyCollateral(options, config?)
Quote the fee for supplying collateral.
const quote = await morpho.quoteSupplyCollateral({
token: 'COLLATERAL_TOKEN_ADDRESS',
amount: 1000000000000000000n
})borrow(options, config?)
Borrow assets from the configured Morpho Blue market.
Options:
token(string): configured market loan tokenamount(number | bigint): amount in base unitsonBehalfOf(string, optional): must equal the connected wallet address when setreallocations(readonly VaultReallocation[], optional): Morpho Vault V2 reallocationsslippageTolerance(bigint, optional): per-call Morpho SDK slippage tolerance
const tx = await morpho.borrow({
token: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
amount: 1000000n
})getBorrowRequirements(options)
Return Morpho authorization requirements for borrow flows.
const requirements = await morpho.getBorrowRequirements({
token: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
amount: 1000000n
})quoteBorrow(options, config?)
Quote the fee for borrowing.
const quote = await morpho.quoteBorrow({
token: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
amount: 1000000n
})repay(options, config?)
Repay assets to the configured Morpho Blue market.
Options:
token(string): configured market loan tokenamount(number | bigint | "max"): amount in base units, or"max"to repay current borrow sharesonBehalfOf(string, optional): must equal the connected wallet address when setrequirementSignature(RequirementSignature, optional): signature returned by a Morpho SDK requirementslippageTolerance(bigint, optional): per-call Morpho SDK slippage tolerance
const tx = await morpho.repay({
token: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
amount: 'max'
})When amount is "max", Morpho repays borrow shares. Re-run getRepayRequirements({ amount: "max" }) immediately before sending repay() so the approval or permit reflects current market state, or approve getChainAddresses(chainId).bundler3.generalAdapter1 with a small buffer above current debt and pass a non-zero slippageTolerance. slippageTolerance caps the repay share price or transfer amount; it is not approval slippage.
getRepayRequirements(options, requirementOptions?)
Return Morpho SDK approval or signature requirements for repayment.
const requirements = await morpho.getRepayRequirements({
token: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
amount: 'max'
})quoteRepay(options, config?)
Quote the fee for repayment.
const quote = await morpho.quoteRepay({
token: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
amount: 'max'
})withdrawCollateral(options, config?)
Withdraw collateral from the configured Morpho Blue market.
Options:
token(string): configured market collateral tokenamount(number | bigint): amount in base unitsto(string, optional): must equal the connected wallet address when set
const tx = await morpho.withdrawCollateral({
token: 'COLLATERAL_TOKEN_ADDRESS',
amount: 1000000000000000000n
})quoteWithdrawCollateral(options, config?)
Quote the fee for withdrawing collateral.
const quote = await morpho.quoteWithdrawCollateral({
token: 'COLLATERAL_TOKEN_ADDRESS',
amount: 1000000000000000000n
})Position Reads
getVaultPosition(account?)
Read this or another account's configured vault position.
Returns:
{
shares: bigint,
assets: bigint,
vaultAddress: Address
}getMarketPosition(account?)
Read this or another account's configured market position.
Returns:
{
supplyShares: bigint,
borrowShares: bigint,
borrowAssets: bigint,
collateral: bigint,
marketId: string
}getAccountData(account?)
Read combined configured vault and market position data.
Returns:
{
vaultShares: bigint,
vaultAssets: bigint,
marketSupplyShares: bigint,
marketBorrowShares: bigint,
marketBorrowAssets: bigint,
collateral: bigint,
vaultAddress: Address,
marketId: string
}Rules & Notes
- The wallet account must include a provider.
- Write methods require a writable EVM account.
token,onBehalfOf,to, andaccountaddresses must be valid when provided.- For vault supply and collateral supply, pass
amount,nativeAmount, or both, and make sure the combined supplied amount is greater than zero. - Withdraw, borrow, and collateral-withdraw amounts must be greater than zero.
repay()also acceptsamount: "max". - Vault operations require the token to match the configured vault asset.
- Market borrow and repay operations require the token to match the configured market loan token.
- Collateral operations require the token to match the configured market collateral token.
onBehalfOfand vault or collateral withdrawaltomust equal the connected wallet address when set.slippageToleranceapplies to vault supply, borrow, and repay calls in the published adapter. Collateral supply uses the Morpho SDK collateral-supply action defaults.- Use
get*Requirementsmethods before final actions when the Morpho SDK reports approval, signature, or authorization requirements.
WDK Lending Morpho EVM Configuration
Presets, explicit targets, and Morpho SDK options
WDK Lending Morpho EVM Usage
Get started with Morpho lending operations