区块链的部分价值,早以“互联网+数据库”的形式发展了很多年。在“互联网+数据库”的模式下,“+”到一定程度,就到私有链的水平了。然后每一个私链进行合并,当私链具备了更多共通性和可交换性之后,就变成了公链。
区块链作为一种新型的技术组合,综合了P2P网络、共识算法、非对称加密、智能合约等新型技术,是一种在对等网络(也称分布式网络、点对点网络)环境下,通过透明和可信的规则,构建可追溯的块链式数据结构,具有分布式对等、链式数据块、防伪造和防篡改、可追溯、透明可信和高可靠性的典型特征。
DAPP是去中心化应用程序/分布式的应用程序,是底层区块链平台生态上衍生的各种分布式应用,也是区块链世界中的基础服务提供方。将应用程序分布在不同节点上,通过共识机制和区块链平台来完成任务的应用程序,它本身就是去中心化,不依赖于任何中心化服务器,促使用户交易更加安全。
//SPDX-License-Identifier:BUSL-1.1
pragma solidity=0.7.6;
import'./interfaces/IUniswapV3Factory.sol';
import'./UniswapV3PoolDeployer.sol';
import'./NoDelegateCall.sol';
import'./UniswapV3Pool.sol';
/// title Canonical Uniswap V3 factory
/// notice Deploys Uniswap V3 pools and manages ownership and control over pool protocol fees
contract UniswapV3Factory is IUniswapV3Factory,UniswapV3PoolDeployer,NoDelegateCall{
/// inheritdoc IUniswapV3Factory
address public override owner;
/// inheritdoc IUniswapV3Factory
mapping(uint24=>int24)public override feeAmountTickSpacing;
/// inheritdoc IUniswapV3Factory
mapping(address=>mapping(address=>mapping(uint24=>address)))public override getPool;
constructor(){
owner=msg.sender;
emit OwnerChanged(address(0),msg.sender);
feeAmountTickSpacing[500]=10;
emit FeeAmountEnabled(500,10);
feeAmountTickSpacing[3000]=60;
emit FeeAmountEnabled(3000,60);
feeAmountTickSpacing[10000]=200;
emit FeeAmountEnabled(10000,200);
}
/// inheritdoc IUniswapV3Factory
function createPool(
address tokenA,
address tokenB,
uint24 fee
)external override noDelegateCall returns(address pool){
require(tokenA!=tokenB);
(address token0,address token1)=tokenA<tokenB?(tokenA,tokenB):(tokenB,tokenA);
require(token0!=address(0));
int24 tickSpacing=feeAmountTickSpacing[fee];
require(tickSpacing!=0);
require(getPooltoken0[fee]==address(0));
pool=deploy(address(this),token0,token1,fee,tickSpacing);
getPooltoken0[fee]=pool;
//populate mapping in the reverse direction,deliberate choice to avoid the cost of comparing addresses
getPooltoken1[fee]=pool;
emit PoolCreated(token0,token1,fee,tickSpacing,pool);
}
/// inheritdoc IUniswapV3Factory
function setOwner(address _owner)external override{
require(msg.sender==owner);
emit OwnerChanged(owner,_owner);
owner=_owner;
}
/// inheritdoc IUniswapV3Factory
function enableFeeAmount(uint24 fee,int24 tickSpacing)public override{
require(msg.sender==owner);
require(fee<1000000);
//tick spacing is capped at 16384 to prevent the situation where tickSpacing is so large that
//TickBitmap#nextInitializedTickWithinOneWord overflows int24 container from a valid tick
//16384 ticks represents a>5x price change with ticks of 1 bips
require(tickSpacing>0&&tickSpacing<16384);
require(feeAmountTickSpacing[fee]==0);
feeAmountTickSpacing[fee]=tickSpacing;
emit FeeAmountEnabled(fee,tickSpacing);
}
}