OneWiex壹維克斯質(zhì)押項目挖礦系統(tǒng)開發(fā)(方案項目)/案例設(shè)計/源碼功能
智能合約是在區(qū)塊鏈上運(yùn)行的計算機(jī)程序。程序包括函數(shù)和數(shù)據(jù)(也稱為變量或參數(shù)),這些函數(shù)操作數(shù)據(jù)。函數(shù)使用的數(shù)據(jù)需要存儲在計算機(jī)的內(nèi)存中。在這種情況下,計算機(jī)是EVM。
存儲內(nèi)存類型的概念是區(qū)塊鏈所特有的,因?yàn)樵谥悄芎霞s中工作時,通過區(qū)塊鏈的加密封存屬性,存儲的數(shù)據(jù)是無法篡改的。在其他編程環(huán)境中,如果我們想要長期存儲變量,通常會將這項工作轉(zhuǎn)移到文件系統(tǒng)或數(shù)據(jù)庫中。但在區(qū)塊鏈上,智能合約的代碼和數(shù)據(jù)都長期保留在區(qū)塊鏈上。
//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(getPool[token0][token1][fee]==address(0));
pool=deploy(address(this),token0,token1,fee,tickSpacing);
getPool[token0][token1][fee]=pool;
//populate mapping in the reverse direction,deliberate choice to avoid the cost of comparing addresses
getPool[token1][token0][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);
}
}