DeFi is smart-contract lending, swaps, and liquidity
DeFi is a way to trade, lend, and borrow crypto through self-executing programs and pooled funds on a blockchain. A wallet submits instructions to smart contracts, which hold collateral, calculate balances, route swaps, and settle results without opening a conventional brokerage account.
The short version: It is an on-chain financial system where smart contracts automate collateralized lending, token swaps, and liquidity pools, letting users borrow and trade from self-custodied wallets.
A DeFi position moves from approval to settlement
A DeFi position begins with the correct chain, a funded wallet, and a contract call the wallet can sign.
First, select the network carrying both the asset and protocol deployment. Ethereum Mainnet uses chain ID 1, OP Mainnet uses 10, Arbitrum One uses 42161, and Base uses 8453. Each network uses ETH for transaction fees, but balances remain separate across chains. After funding the wallet, connect MetaMask or Rabby to the protocol interface. Read the selected chain, token contract, amount, recipient contract, and maximum gas fee before signing.
An ERC-20 token action commonly requires an approval transaction followed by the protocol transaction. The approval gives a specified contract permission to move tokens up to a ceiling. A Uniswap router then executes a swap, while an Aave pool contract records a supply or borrowing position. After block inclusion, the transaction receipt shows whether execution succeeded and which events changed the on-chain state. Exiting reverses the relevant operation: withdraw supplied assets, repay debt before reclaiming collateral, or swap tokens back through a pool. Keep the transaction hash as the durable record.
Smart contracts turn shared block space into financial state
Smart contracts maintain balances and enforce financial rules from identical inputs, producing state every network participant can inspect (see also DeFi eligibility breakdown ).
Ethereum orders those state changes through 12-second slots. An epoch contains 32 slots and lasts 6.4 minutes; finality normally follows after two epochs, or about 13 minutes. Inclusion happens earlier, when a validator places the transaction in a block. Amounts use integer units beneath wallet formatting: 1 ETH equals 10 18 wei, and 1 gwei equals 10 9 wei. Token contracts choose their own display precision, with USDC using 6 decimal places and DAI using 18.
Different contracts turn this shared ledger into distinct services. Uniswap v2 applies the constant-product formula x × y = k to reserve balances, while Curve uses its StableSwap design for assets expected to trade near one another. Aave and Compound match supplied liquidity with overcollateralized borrowing. Maker contracts create DAI against approved collateral. Liquidity providers accept pool exposure and receive trading fees; lenders supply reserves and receive borrower-funded interest. Every balance remains composable, so another contract can use a receipt token or pool position as an input.
DEXs, exchanges, and banks answer different needs
The right venue follows from custody, settlement, credit requirements, and the protections attached to the account.
Uniswap and Curve settle trades directly to a wallet, expose pool rules on-chain, and let other contracts compose with the resulting assets. Uniswap v2 embeds a 0.30% liquidity-provider fee in each swap. Coinbase and Kraken maintain customer account ledgers, manage asset custody until withdrawal, and support familiar order types and account recovery processes. Banks add identity-based underwriting, payment reversals, and jurisdiction-specific deposit protections. They also issue loans against income or credit history. Aave and Compound instead secure ordinary borrowing with on-chain collateral, so they serve asset-backed liquidity rather than a conventional unsecured personal loan.
Pool fees and collateral determine transaction economics
Transaction economics combine protocol charges, price impact, network computation, interest, and the collateral committed to an open position.
Uniswap v3 defines four standard fee tiers: 0.01%, 0.05%, 0.30%, and 1%. The pool chosen by the route determines the applicable tier, while trade size relative to active liquidity determines price impact. Ethereum charges gas separately. A plain ETH transfer consumes 21,000 gas, whereas swaps and lending calls execute more instructions. Under EIP-1559, the base fee moves by at most 12.5% from one block to the next, and block capacity expands to 2 times its target during heavy demand.
Worked example: Every changing input in this paragraph is hypothetical. A trader swaps 5,000 USDC through a Uniswap v3 pool charging 0.05%, with quoted price impact of 0.20% excluding that pool fee. Estimated gas costs 0.003 ETH, and ETH carries a conversion value of $2,000. The pool fee is $2.50, price impact represents $10, and gas represents $6. Combined execution cost is $18.50, leaving an expected output value of $4,981.50 before any separate interface charge.
Borrowing replaces swap price impact with a utilization-based interest rate and collateral constraints. The quoted rate changes as borrowers consume liquidity and suppliers replenish it. A complete cost view includes opening and closing gas, accrued interest, and the collateral exposed to liquidation. Those inputs belong to the specific Aave or Compound market, not to DeFi as one universal rate.
Liquidation, oracle, and contract design define the risk
Major DeFi risks arise from automatic position rules, external price data, contract dependencies, and governance-controlled parameters.
Position mechanics
Borrowing and liquidity positions respond differently when market prices move. Each position therefore requires its own solvency or range metric.
Borrowing positions
Aave calculates health factor from collateral value, weighted liquidation thresholds, and total debt. A position becomes eligible for liquidation below a health factor of 1. Supplying collateral or repaying debt raises that ratio. Compound III uses separate borrow and liquidation collateral factors to create a buffer between opening capacity and liquidation. Both systems rely on price feeds, including Chainlink data feeds in supported markets, to translate token amounts into comparable values.
Liquidity positions
Uniswap v3 liquidity occupies a chosen price range. When the market moves outside that range, the position holds only one side of the pair and stops earning swap fees until price returns. Even inside the range, reserve rebalancing produces impermanent loss relative to holding the two tokens separately. Curve pools reduce price impact for closely priced assets through StableSwap, but the pool still inherits the economic behavior of every included asset.
Protocol dependencies
This is revisited in detail. Contract logic, upgrade permissions, governance decisions, and connected protocols shape the remaining exposure. An audit examines a defined code state; it does not make later parameter changes or external dependencies infallible. A bridge adds its own contracts and message-validation system before assets reach another chain. Stablecoins also differ materially: USDC follows an issuer-backed reserve and redemption model, while DAI follows an on-chain collateral and governance model. Read those mechanisms separately from the lending pool using the token.
Self-custody fits users who manage the full position
DeFi suits users prepared to manage signing authority, network fees, collateral buffers, approvals, and the final exit transaction. The follow-on topic is treated in DeFi wallets rundown.
Its practical benefits are direct settlement, transparent contract state, permissionless composition, and control of assets between transactions. Start with one established protocol on one chain, retain enough ETH to close the position, and reconcile wallet balances with protocol records. An EVM address contains 20 bytes and displays 40 hexadecimal characters after its 0x prefix, so chain identity still needs a separate check. ERC-20 interfaces should set an allowance to 0 before replacing an existing nonzero allowance. Larger shared treasuries can separate signing authority through a multi-owner wallet such as Safe.
What readers ask about DeFi
-
What happens if a DeFi transaction runs out of gas?
- An Ethereum transaction that runs out of gas reverts its state changes, while the sender still pays for computation already performed. The wallet's gas limit caps the units available, and the gas price determines cost per unit. A limit below the contract's execution needs causes failure even when the wallet holds enough ETH. A transaction rejected before block inclusion consumes no gas, whereas an execution-time revert consumes the gas used.
-
Why does my wallet show a new token after I supply assets?
- A new token balance commonly represents the claim created by a lending or liquidity contract. Aave supplies aTokens when assets enter a reserve; the aToken balance tracks the holder's supplied position and accrued interest. Other protocols record claims through vault shares, pool tokens, or internal accounting. The representation is not an unrelated reward. It provides the contract with a transferable or composable record of the underlying assets owed to the wallet.
-
When should an ERC-20 allowance be reduced to zero?
- An ERC-20 allowance should return to zero when the spender no longer needs access or before replacing a nonzero allowance through an interface following EIP-20 guidance. Approval establishes a spending ceiling rather than transferring tokens immediately. The allowance remains recorded until spending consumes it, the owner changes it, or the token contract applies another rule. Reducing an unused allowance narrows the authority available to future calls from that spender contract.
-
What creates the interest paid to DeFi lenders?
- Borrowers create most lending interest by paying a variable rate on assets drawn from a protocol's liquidity pool. Aave and Compound set rates through utilization curves: borrowing a larger share of available liquidity raises the rate, while repayment and new supply reduce utilization. Suppliers receive their portion after protocol reserve allocations and other configured deductions. Token incentives, when present, are separate emissions and should not be confused with borrower-funded interest.
-
Who changes a DeFi protocol after its contracts are deployed?
- Protocol governance and designated administrative mechanisms change upgradeable DeFi systems. Token holders or delegates submit and vote on proposals, while timelock and execution contracts apply approved actions under the protocol's configured process. Aave governance adjusts supported assets and risk parameters; Uniswap governance handles protocol-level decisions. Fully immutable contracts retain their original code, although developers can deploy a separate version and liquidity providers can migrate voluntarily.