Lending
Let your users earn interest on deposits, borrow against them like a secured loan, repay and withdraw, from one quote endpoint.
Your users can deposit a currency to earn interest, and borrow another currency against that deposit, like a secured loan. Every lending action starts with a quote from Create Lending Quote, which the user approves and you submit like any other operation. The deposit stays in the user's name; only the user can move their money, and Notus never holds it.
Your users can deposit tokens on Aave to earn interest, and borrow other tokens against that deposit. Every lending action is one quote from Create Lending Quote, signed and executed like any other operation. The deposit stays in the user's wallet's name on Aave; Notus never holds it.
Deposit to earn interest
const USDC_BASE = '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913'
const quote = await notus.lending.createLendingQuote({
walletAddress,
provider: 'AAVE',
supply: { tokenAddress: USDC_BASE, amount: '100', chainId: 8453 },
gas: { tokenAddress: USDC_BASE, paymentMethod: 'DEDUCT_FROM_AMOUNT' },
})
const operation = quote.signData.find((item) => item.type === 'USER_OPERATION')
if (!operation?.hash) throw new Error(JSON.stringify(quote.revertReason))
await notus.userOperations.executeUserOperation({
userOperationHash: operation.hash,
signature: await signer.signMessage({ message: { raw: operation.hash } }),
})This example deposits 100 digital dollars (USDC) on the Base network (chainId: 8453). Money lives on a network, like a bank system; tokenAddress is the currency's id on that network, walletAddress is the user's account address, and amount is how much to deposit, as text. Setting gas with DEDUCT_FROM_AMOUNT pays the network fee from the dollars being deposited.
A lending quote lists what the user needs to approve in signData instead of a top-level userOperationHash. Have the user approve the USER_OPERATION entry with their key, then send the approval to executeUserOperation.
A lending quote lists what to sign in signData instead of a top-level userOperationHash. Sign the USER_OPERATION hash and execute.
What each request does
The legs you send decide the operation:
| Send | The user |
|---|---|
supply | deposits and starts earning |
supply + borrow | deposits and borrows against it in one step |
borrow | borrows against what they already deposited |
repay | pays back a loan |
withdraw | takes a deposit back |
repay + withdraw | repays and withdraws in one step |
Each leg takes { tokenAddress, amount, chainId }: the currency's id, the amount as text, and the network's id. Legs sent together must be on the same network.
Each leg is { tokenAddress, amount, chainId }. Legs sent together must be on the same chain.
Show deposits and loans
The user's portfolio with includeLendingPositions=true lists each deposit and loan (positionType: 'supply' | 'borrow') with its value in dollars.
The wallet's portfolio with includeLendingPositions=true lists each deposit and loan (positionType: 'supply' | 'borrow') with its value in dollars.
Networks
Available on Ethereum, OP Mainnet, BNB Smart Chain, Gnosis, Polygon, Base, Arbitrum, Avalanche and X Layer.
Aave V3 on Ethereum, OP Mainnet, BNB Smart Chain, Gnosis, Polygon, Base, Arbitrum, Avalanche and X Layer.
Morpho, risk and errors
- Morpho.
provider: 'MORPHO'uses Morpho markets on Polygon. Every leg then needs the market'smarketId. - Signing.
signDataholds aUSER_OPERATIONentry, and anAUTHORIZATIONentry on an EIP-7702 wallet's first operation on that chain: sign its hash and send it asauthorizationon execute. - Borrow risk. Notus watches open loans and sends a
lending.riskwebhook when a position gets close to liquidation, andlending.liquidationwhen one is liquidated. The history type for that isLENDING_LIQUIDATION. - Gas.
DEDUCT_FROM_AMOUNTtakes the network fee from the leg whose token matchesgas.tokenAddress;ADD_TO_AMOUNTcharges it separately. - Errors.
MARKET_NOT_FOUND(token or chain without a market),AMOUNT_TOO_LOW,INSUFFICIENT_BALANCE,UNSUPPORTED_LENDING_OPERATION_EXCEPTION(for examplesupplywithrepay).