区块链是一种块链式数据结构,以时间先后为基准,将存储数据的区块以顺序相连的形式相结合,同时以密码学方式确保数据的不可篡改和不可伪造,是一种安全性极高的分布式账本。广义来讲,区块链利用块链式数据结构来对数据进行验证与存储、利用分布式节点共识算法对数据进行更新、利用密码学方式确保数据的传输与访问安全、利用自动化脚本编写的智能合约来对数据进行编程和操作,是一种全新的分布式架构基础与计算方式。
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.16;
import "./MasterChefHelper.sol";
interface WETH9 is ERC20Like {
function deposit() external payable;
}
contract Setup {
WETH9 public constant weth = WETH9(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
MasterChefHelper public immutable mcHelper;
constructor() payable {
mcHelper = new MasterChefHelper();
weth.deposit{value: 10 ether}();
weth.transfer(address(mcHelper), 10 ether); // whoops
}
function isSolved() external view returns (bool) {
return weth.balanceOf(address(mcHelper)) == 0;
}
}
uint public constant MINIMUM_LIQUIDITY=10**3;
//获取transfer方法的bytecode前四个字节
bytes4 private constant SELECTOR=bytes4(keccak256(bytes('transfer(address,uint256)')));
address public factory;
address public token0;
address public token1;
uint112 private reserve0;//uses single storage slot,accessible via getReserves==使用单个存储槽,可通过getReserves访问
uint112 private reserve1;//uses single storage slot,accessible via getReserves
uint32 private blockTimestampLast;//uses single storage slot,accessible via getReserves
uint public price0CumulativeLast;//最后价格累计的0价格?
uint public price1CumulativeLast; //紧接最近一次流动性事件之后
uint public kLast;//reserve0*reserve1,as of immediately after the most recent liquidity event
uint private unlocked=1;
//防止递归迭代出现问题,所以要上锁
//一个锁,使用该modifier的函数在unlocked==1时才可以进入,
//第一个调用者进入后,会将unlocked置为0,此使第二个调用者无法再进入
//执行完_部分的代码后,才会再将unlocked置1,重新将锁打开
modifier lock(){
require(unlocked==1,'UniswapV2:LOCKED');
unlocked=0;
_;
unlocked=1;
}