By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
A stablecoin is a cryptocurrency that aims to keep its price pegged to a stable asset—most often a fiat currency like USD. By anchoring value, stablecoins let users enjoy the speed and programmability of crypto while avoiding the wild price swings of Bitcoin or ETH. In a decentralized finance (DeFi) stack, a stablecoin is the “cash” you use to swap on Uniswap, lend on Aave, or pay for gas on a Layer‑2 roll‑up.
decimals
solidity uint8 public constant decimals = 6; // USDC‑style
mint
burn
solidity function mint(address to, uint256 amount) external onlyMinter { _mint(to, amount); } function burn(address from, uint256 amount) external onlyMinter { _burn(from, amount); }
priceOracle
solidity interface IPriceOracle { function latestAnswer() external view returns (int256); }
collateralRatio
CR = totalCollateralValue / totalSupply
liquidation
solidity function liquidate(address vault) external { // 1️⃣ check CR, 2️⃣ seize collateral, 3️⃣ mint stablecoins to liquidator }
rebase
solidity function rebase(int256 supplyDelta) external onlyRebaser { totalSupply = totalSupply + supplyDelta; // balances are scaled via a global index }
ERC‑4626
EIP‑2612 permit
solidity function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external;
ERC20PresetMinterPauser
bash npx hardhat compile npx hardhat test test/Stablecoin.t.sol
js const Stablecoin = await ethers.getContractFactory("MyStablecoin"); const stable = await Stablecoin.deploy(oracle.address); await stable.deployed();
js await stable.mint(userAddress, amount);
CR < 150%
liquidate(vaultId)
Mistake: Using tx.origin for access control (e.g., only the “owner” can mint). Correction: Use msg.sender with onlyOwner modifiers; tx.origin can be spoofed through a malicious contract, breaking the peg security.
tx.origin
msg.sender
onlyOwner
Mistake: Hard‑coding the oracle address and forgetting to update it after a feed upgrade. Correction: Store the oracle in a mutable address public priceOracle; and provide an onlyOwner setOracle() function. This keeps the system flexible and audit‑friendly.
address public priceOracle;
setOracle()
Mistake: Forgetting to round down when converting from 18‑decimal collateral to a 6‑decimal stablecoin, leading to “dust” loss. Correction: Use SafeMath (or Solidity 0.8+ built‑in checks) and explicit scaling: amount * 1e6 / 1e18.
SafeMath
amount * 1e6 / 1e18
Mistake: Allowing unlimited mint calls from any address (no role restriction). Correction: Leverage OpenZeppelin’s AccessControl and grant the MINTER_ROLE only to the collateral manager contract.
AccessControl
MINTER_ROLE
Mistake: Ignoring slippage when performing a rebase; the market price may overshoot the peg. Correction: Implement a bounded rebase (e.g., max ±5 % per epoch) and combine with a secondary stabilization pool.
“Explain the difference between fiat‑collateralized and over‑collateralized stablecoins.” Interviewers look for understanding of risk profiles: FC relies on trust in custodial banks; OC relies on smart‑contract‑enforced collateral ratios and liquidation mechanisms.
“How would you protect a liquidation function from front‑running?” Expect answers like using a commit‑reveal scheme, adding a minimum profit margin, or leveraging EIP‑1559 base‑fee to make the transaction cost‑predictable.
“What are the gas‑implications of an ERC‑4626 vault vs a naïve ERC‑20 mint/burn?” Auditors check that vaults batch accounting (single totalAssets update) to save gas, whereas per‑user mint/burn can be expensive at scale.
totalAssets
“Why might an algorithmic stablecoin still need a collateral buffer?” Because pure supply‑adjustment can’t react instantly to market shocks; a small collateral reserve (e.g., FRAX’s 10 % USDC) provides a safety net and is a red flag for auditors.
Scenario: A DApp calls stablecoin.transferFrom(msg.sender, address(this), amount) without first approving the contract. Answer: The transaction will revert with “ERC20: transfer amount exceeds allowance.” Users must approve the contract (or use permit) before transferFrom.
stablecoin.transferFrom(msg.sender, address(this), amount)
approve
permit
transferFrom
Scenario: Your OC stablecoin’s collateralRatio drops to 120 % while the minimum is 150 %. A keeper calls liquidate() but the transaction runs out of gas. Answer: The liquidation fails, leaving the system under‑collateralized; design the function to be gas‑efficient (use unchecked loops, limit batch size) and consider a fallback emergency shutdown.
liquidate()
unchecked
Scenario: You see a contract that mints new stablecoins whenever priceOracle.latestAnswer() < 0.99 * peg. Answer: This is a price‑oracle‑driven mint that can be gamed if the oracle is compromised; a robust design adds a time‑weighted average price (TWAP) and a governance delay before minting.
priceOracle.latestAnswer() < 0.99 * peg
index
* 1e10
call
.call{gas: 100_000}
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.