Skip to main content

Swap

  • Swap - 货币互换
  • Deposit - 货币质押 - 增加流动性
  • Liquite - 流动性
    • A 币+B 币
  • Borrow - 借
  • Loan - 贷
  • Flash Loan
  • Payback - 偿还
  • Stake - 持有货币,增加稳定性
  • 跨链互换
  • Native <-> ERC20 互换 - 早期的 Native Currency 不是 ERC20 不方便交易
  • Reward fee
  • Sliperage
  • liquidation - 清算
  • 滑点
    • 预设成交价位与真实成交价位的偏差
    • 交易额越大,滑点越大,交易者的损失就越大
  • 无常损失
  • CPMMM - Constant Product Market Maker Model - 恒定乘积做市商模型
  • CFMMs - Constant function market makers
  • Marginal exchange rate - 边际汇率
  • DEX
  • AMM
  • MM - Market Maker - 做市商
  • TWAPs - time-weighted average prices
  • EMAs
  • SMAs
  • arbitrage - 套利

  • LP/Liquidity Provider -Deposit-> Pool
    • +token0, +token1 -> share
    • reserve0, reserve1
    • liquidity shares
  • Trader -Swap-> Pool
    • token0/token1 + fee -> token1/token0

  • dx -> dy
{xy=k(x+dx)(ydy)=k\begin{cases} xy=k \\ (x+dx)(y-dy)=k \end{cases} dy=ydxx+dxdy = \frac {y \cdot dx} {x+dx} dx/dy=x+dxydx/dy = \frac {x+dx} y SlippageyPrice=dx/dyx/y=dxySlippage_{yPrice} = dx/dy - x/y = \frac {dx} y
  • dx 滑点就越大,偏离实际价位就越大
  • 池中的资金储备越多、交易深度越大,则能尽量减少滑点的溢价,使用户的交易损耗降低
  • Uniswap/sdk-core computePriceImpact
PriceImpact=midPricedxdymidPricedxPriceImpact = \frac {midPrice \cdot dx - dy} {midPrice \cdot dx}
  • midPrice - x->y = y/x
PriceImpact=dxx+dxPriceImpact = \frac {dx} {x + dx}

Dev

bytes memory bytecode = type(UniswapV2Pair).creationCode;
bytes32 salt = keccak256(abi.encodePacked(token0, token1));
assembly {
pair := create2(0, add(bytecode, 32), mload(bytecode), salt)
}

参考