Overview
The most comprehensive template. Includes a Uniswap-style AMM (Factory, Pair, Router), a collateralized lending vault, Synthetix-style staking rewards, and a price oracle. Comes with IPFS, a subgraph indexer, Blockscout explorer, and Chainlink mock oracle as services.Quick Start
Generated Files
my-defi
dokrypt.yaml
foundry.toml
README.md
contracts
token
DeFiToken.sol
amm
Factory.sol
Pair.sol
Router.sol
lending
LendingVault.sol
InterestModel.sol
staking
StakingRewards.sol
oracle
PriceOracle.sol
test
amm
Factory.t.sol
Router.t.sol
lending
LendingVault.t.sol
staking
StakingRewards.t.sol
scripts
deploy-amm.js
deploy-lending.js
deploy-staking.js
Contracts
DeFiToken.sol
ERC-20 with governance delegation, minting, and burning. Constructor:AMM Module
A Uniswap V2-style automated market maker with three contracts.Factory.sol
Creates and tracks liquidity pairs using CREATE2 for deterministic addresses.
Uses CREATE2 with salt
keccak256(abi.encodePacked(token0, token1)).
Pair.sol
Liquidity pool implementing thex * y = k constant product invariant.
Key Constants:
MINIMUM_LIQUIDITY = 1000— Permanently locked on first mintSWAP_FEE = 3— 0.3% swap fee (3/1000)
Features:
- ERC-20 LP tokens for liquidity providers
- TWAP (Time-Weighted Average Price) oracle via
price0CumulativeLastandprice1CumulativeLast - Flash swap support
Mint, Burn, Swap, Sync
Router.sol
High-level interface with deadline protection and slippage guards.
All functions have
deadline parameter — reverts if block.timestamp > deadline.
Events: LiquidityAdded, LiquidityRemoved, SwapExecuted
LendingVault.sol
Collateralized lending with liquidation mechanics. Constants:
Functions:
Liquidation Flow:
- Borrower’s health factor drops below threshold (collateral value / debt > 80%)
- Liquidator calls
liquidate()with the debt amount to repay - Liquidator receives collateral worth 105% of repaid debt (5% bonus)
- Borrower’s debt and collateral are reduced accordingly
CollateralDeposited, CollateralWithdrawn, Borrowed, Repaid, Liquidated, InterestAccrued
InterestModel.sol
Kinked linear interest rate model. Rates increase slowly at low utilization and steeply at high utilization.StakingRewards.sol
Same Synthetix-style staking as theevm-token template. See evm-token StakeRewards for full details.