freecoding.school100% FREE · NO SIGNUP
Yield OceanISSUE #13 of 34

makerdao · dai · the peg stability module

Liquidity LuVSThe Sandwich Bot
Liquidity Lu saysMakerDAO’s Peg Stability Module lets anyone swap USDC for DAI at 1:1 (minus a tiny fee) — pinning DAI to the dollar via instant arbitrage.

Algorithmic stables are hard; MakerDAO's Peg Stability Module uses a different trick. The PSM holds USDC as collateral and lets anyone swap USDC ↔ DAI at 1:1 minus a tiny fee (typically 0.1%). If DAI trades above $1.005 on the open market, arbs mint DAI from the PSM at $1.001 and sell, pushing the price down. If DAI trades below $0.995, arbs buy cheap DAI on market and redeem for USDC at $0.999.

The peg holds tightly as a result, at the cost of growing USDC reliance. The demo runs a swap each way through the PSM.

Power-ups you unlock

The Sandwich Bot attacks — common mistakes

Boss battleRun a $1000 swap through the PSM each way and compute the fee on each.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre id="o"></pre>
<script>
const FEE = 0.001;
function psm(asset, amount){
  const fee = amount * FEE;
  return { received: amount - fee, fee };
}
const usdcToDai = psm('USDC→DAI', 1000);
const daiToUsdc = psm('DAI→USDC', 1000);
document.getElementById('o').textContent = [
  'PSM (fee = ' + (FEE*100) + '%):',
  '',
  '  swap $1000 USDC → DAI:  receive ' + usdcToDai.received + ' DAI   (fee ' + usdcToDai.fee + ')',
  '  swap $1000 DAI → USDC: receive ' + daiToUsdc.received + ' USDC  (fee ' + daiToUsdc.fee + ')',
  '',
  'arb keeps DAI near $1:',
  '  DAI > $1.005 → mint via PSM, sell → price falls',
  '  DAI < $0.995 → buy cheap, redeem via PSM → price rises'
].join('\n');
</script></body></html>
▶ Open the interactive comic issue
‹ Flash Loans · Atomic Uncollateralized CreditPerps · Funding Rates · Gmx · Synthetix ›