3. TOTAL VALUE LOCKED IN DEFI
Total Value Locked in DeFi protocols (TVL) now
stands above $25B, an incredible 2500% growth Y/Y.
Similarly, the number of DeFi users has surpassed 1.2M
Protocols like Uniswap and Compound claim 200-500K
users, with most other DeFi apps between 25-50K users.
5. UNISWAP
Most popular decentralized exchange
August 30 surpassed major cryptocurrency exchange Coinbase in volume
after its users traded $426 million worth of cryptocurrencies in a single day
16. UNISWAP ROUTER CONTRACT
interface IUniswapV2Router01 {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidity()
function addLiquidityETH()
function removeLiquidity()
function removeLiquidityETH()
function removeLiquidityWithPermit()
function removeLiquidityETHWithPermit()
function swapExactTokensForTokens()
function swapTokensForExactTokens()
function swapExactETHForTokens()
function swapTokensForExactETH()
function swapExactTokensForETH()
function swapETHForExactTokens()
function quote(uint amountA, uint reserveA, uint reserveB)
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut)
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut)
function getAmountsOut(uint amountIn, address[] calldata path)
function getAmountsIn(uint amountOut, address[] calldata path)
}
25. CALL FROM A SMART CONTRACT –
GET PRICE
IUniswapV2Router02 private uniswapV2router;
uniswapV2router =
IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
function getEstimatedEthForToken(address token, uint256 tokenAmount) public
view returns (uint256) {
if (token!=address(0) && tokenAmount>0) {
address[] memory path = getPathToETH(token);
uint[] memory r = uniswapV2router.getAmountsOut(tokenAmount, path);
return r[1];
} else {
return 0;
}
}
26. SWAP TOKEN TO ETH
// amountOutMin must be retrieved from an oracle of some kind
address[] memory path = new address[](2);
path[0] = address(DAI);
path[1] = UniswapV2Router02.WETH();
UniswapV2Router02.swapExactTokensForETH(amountIn, amountOutMin, path,
msg.sender, block.timestamp)
27. CALL FROM A SMART CONTRACT -
SELL
event SellToken(address token, uint256 tokenAmount);
function convertTokenToEth(address token, uint256 tokenAmount) public onlyOwner {
IERC20 erc20Token = IERC20(token);
emit SellToken(token, tokenAmount);
require(getTokenBalance(token)>=tokenAmount && token!=address(0), "Token balance");
require(erc20Token.approve(address(uniswapV2router), 0), "Approve failed");
require(erc20Token.approve(address(uniswapV2router), tokenAmount), "Approve failed");
uint256 deadline = block.timestamp + 300; // transaction expires in 300 seconds (5 minutes)
uint256 minETHAmountToReceieve = (getEstimatedEthForToken(token, tokenAmount)*8)/10; //20%
sleepage is OK
uniswapV2router.swapExactTokensForETH(tokenAmount, minETHAmountToReceieve,
getPathToETH(token), address(this), deadline);
}
https://www.theblockcrypto.com/linked/91539/januarys-decentralized-exchange-volumes-are-on-track-to-reach-record-highs
Uniswap currently makes up 44.85% of January’s trading volume, with SushiSwap (22.19%) and Curve (12.98%) in second and third place, respectively.
Note: routers are stateless and do not hold token balances, they can be replaced
https://uniswap.org/docs/v2/smart-contracts/router02/#weth
https://github.com/Uniswap/uniswap-v2-periphery/blob/master/contracts/UniswapV2Router02.sol