Skip to main content

Introduction

Mewler is a modular lending protocol that developers can integrate into their applications. This guide covers the essential concepts and tools needed to build on Mewler.

Architecture Overview

Mewler consists of several key components:

Core Contracts

  • Vault Factory: Deploys new isolated vaults
  • Vault Implementation: The vault contract template
  • EVC: Ethereum Vault Connector for advanced features
  • Protocol Config: Global protocol parameters

Periphery Contracts

  • Earn Factory: Deploys yield strategy vaults
  • Lens Contracts: Read-only data aggregation
  • Swap Contracts: DEX integration for multiply positions

Key Concepts for Developers

Vault Interface

Each vault implements a standard interface for:
  • Depositing and withdrawing assets
  • Borrowing and repaying debt
  • Querying balances and rates

Share Accounting

Vaults use share-based accounting (ERC-4626 compatible):
  • Deposits mint shares
  • Withdrawals burn shares
  • Share price increases with interest

Interest Accrual

Interest accrues continuously:
  • No per-block updates required
  • Calculated on-demand during operations
  • Gas-efficient implementation

Getting Started

1. Install Dependencies

npm install ethers
# or
npm install viem

2. Import ABIs

Get contract ABIs from:

3. Connect to Contracts

import { ethers } from 'ethers';

const provider = new ethers.JsonRpcProvider('YOUR_RPC_URL');
const vaultAddress = '0x...'; // Your vault address
const vaultABI = [...]; // Vault ABI

const vault = new ethers.Contract(vaultAddress, vaultABI, provider);

Common Operations

Depositing Assets

async function deposit(amount: bigint) {
  const signer = await provider.getSigner();
  const vault = new ethers.Contract(vaultAddress, vaultABI, signer);
  
  // Approve if needed
  const token = new ethers.Contract(assetAddress, erc20ABI, signer);
  await token.approve(vaultAddress, amount);
  
  // Deposit
  const tx = await vault.deposit(amount, signer.address);
  await tx.wait();
}

Borrowing Assets

async function borrow(amount: bigint) {
  const signer = await provider.getSigner();
  const vault = new ethers.Contract(vaultAddress, vaultABI, signer);
  
  const tx = await vault.borrow(amount, signer.address);
  await tx.wait();
}

Querying Balances

async function getBalance(userAddress: string) {
  const vault = new ethers.Contract(vaultAddress, vaultABI, provider);
  
  const [shares, assets] = await vault.balanceOf(userAddress);
  return { shares, assets };
}

Using the EVC

Batching Operations

const evc = new ethers.Contract(EVC_ADDRESS, evcABI, signer);

const calls = [
  vault.interface.encodeFunctionData('deposit', [amount1, userAddress]),
  vault.interface.encodeFunctionData('borrow', [amount2, userAddress]),
];

await evc.batch(calls);

Sub-Accounts

// Operations on sub-account 1
const subAccountId = 1;
await vault.deposit(amount, `${userAddress}:${subAccountId}`);

Integration Patterns

Lending Integration

Integrate Mewler vaults as a yield source:
  1. Deposit user funds into vault
  2. Track user shares
  3. Allow withdrawals based on share value

Borrowing Integration

Enable borrowing in your application:
  1. Check user collateral across vaults
  2. Calculate borrowing capacity
  3. Execute borrow transactions
  4. Monitor health scores

Liquidation Bots

Build automated liquidation systems:
  1. Monitor positions for health score < 1.0
  2. Calculate liquidation profitability
  3. Execute liquidations
  4. Handle partial vs full liquidations

Testing

Local Development

  1. Fork mainnet state
  2. Deploy test vaults
  3. Use test tokens
  4. Simulate operations

Testnet

Use testnet deployments for integration testing:
  • Test all user flows
  • Verify gas costs
  • Test edge cases

Security Considerations

Input Validation

  • Validate all user inputs
  • Check return values from contract calls
  • Handle revert cases gracefully

Access Control

  • Verify contract addresses
  • Check permissions before operations
  • Use multi-sig for admin functions

Error Handling

  • Handle all possible revert reasons
  • Provide clear error messages
  • Log important events

Resources

Support