Skip to main content

Morpho Blue

Operations → Lending → Morpho Blue (Composer)

Morpho Blue uses a market-based system where each market is defined by specific parameters. All operations require the full market specification.

Market Parameters​

Each Morpho operation requires the complete market definition:

OffsetLength (bytes)Description
020MarketParams.loanToken
2020MarketParams.collateralToken
4020MarketParams.oracle
6020MarketParams.irm (Interest Rate Model)
8016MarketParams.lltv (Liquidation Loan-To-Value)

Deposit Collateral​

Deposit collateral tokens to a Morpho Blue market.

If amount=0, we use the contract balance via collateralToken.balanceOf(address(this)). This is recommended when executing this operation after a swap.

OffsetLength (bytes)Description
020MarketParams.loanToken
2020MarketParams.collateralToken
4020MarketParams.oracle
6020MarketParams.irm
8016amount uint128
9620receiver address
11620morpho address

Withdraw Collateral​

Withdraw collateral tokens from a Morpho Blue market.

If amount=0xffffffffffffffffffffffffffff, we read the user's full collateral balance and withdraw without leaving dust.

OffsetLength (bytes)Description
020MarketParams.loanToken
2020MarketParams.collateralToken
4020MarketParams.oracle
6020MarketParams.irm
8016amount uint128
9620receiver address
11620morpho address

Deposit Lending Token​

Deposit loan tokens (lending tokens) to a Morpho Blue market. This operation supports both assets and shares.

Use the flag at offset 96 to specify whether to deposit by assets (0) or shares (1). If amount=0, we use the contract balance.

OffsetLength (bytes)Description
020MarketParams.loanToken
2020MarketParams.collateralToken
4020MarketParams.oracle
6020MarketParams.irm
8016MarketParams.lltv
961flags (0=assets, 1=shares)
9715amount uint112
11220receiver address
13220morpho address
1522callbackLength uint16
154callbackLengthcallbackData

Withdraw Lending Token​

Withdraw loan tokens from a Morpho Blue market. This operation supports both assets and shares.

Use the flag at offset 96 to specify whether to withdraw by assets (0) or shares (1). If amount=0xffffffffffffffffffffffffffff, we withdraw the user's full balance.

OffsetLength (bytes)Description
020MarketParams.loanToken
2020MarketParams.collateralToken
4020MarketParams.oracle
6020MarketParams.irm
8016MarketParams.lltv
961flags (0=assets, 1=shares)
9715amount uint112
11220receiver address
13220morpho address

Borrow​

Borrow loan tokens from a Morpho Blue market. This operation supports both assets and shares.

Use the flag at offset 96 to specify whether to borrow by assets (0) or shares (1).

OffsetLength (bytes)Description
020MarketParams.loanToken
2020MarketParams.collateralToken
4020MarketParams.oracle
6020MarketParams.irm
8016MarketParams.lltv
961flags (0=assets, 1=shares)
9715amount uint112
11220receiver address
13220morpho address

Repay​

Repay borrowed loan tokens to a Morpho Blue market. This operation supports both assets and shares.

Use the flag at offset 96 to specify whether to repay by assets (0) or shares (1).

Special amount values:

  • amount=0: repay contract balance
  • amount=0xffffffffffffffffffffffffffff: repay maximum safe amount (prevents dust)
OffsetLength (bytes)Description
020MarketParams.loanToken
2020MarketParams.collateralToken
4020MarketParams.oracle
6020MarketParams.irm
8016MarketParams.lltv
961flags (0=assets, 1=shares)
9715amount uint112
11220receiver address
13220morpho address
1522callbackLength uint16
154callbackLengthcallbackData