DApp是指基于区块练技术的去中心化应用程序,它的特点是去中心化、透明、安全、不可篡改等特点。
DApp和APP的最大不同在于,DApp是基于区块练技术的去中心化应用程序,而APP是基于中心化服务器的应用程序,DApp的数据存储和处理都是分布式的,There is no centralized server,therefore it has higher security and reliability.
function mint(MintParams calldata params)
external
payable
override
checkDeadline(params.deadline)
returns(
uint256 tokenId,
uint256 amount0,
uint256 amount1
)
{
IUniswapV3Pool pool;
//这里是添加流动性,并完成x token和y token的发送
(amount0,amount1,pool)=addLiquidity(
AddLiquidityParams({
token0:params.token0,
token1:params.token1,
fee:params.fee,
recipient:address(this),
tickLower:params.tickLower,
tickUpper:params.tickUpper,
amount:params.amount,
amount0Max:params.amount0Max,
amount1Max:params.amount1Max
})
);
//铸造ERC721 token给用户,用来代表用户所持有的流动性
_mint(params.recipient,(tokenId=_nextId++));
bytes32 positionKey=PositionKey.compute(address(this),params.tickLower,params.tickUpper);
(,uint256 feeGrowthInside0LastX128,uint256 feeGrowthInside1LastX128,,)=pool.positions(positionKey);
//idempotent set
uint80 poolId=
cachePoolKey(
address(pool),
PoolAddress.PoolKey({token0:params.token0,token1:params.token1,fee:params.fee})
);
//用ERC721的token
_positions[tokenId]=Position({
nonce:0,
operator:address(0),
poolId:poolId,
tickLower:params.tickLower,
tickUpper:params.tickUpper,
liquidity:params.amount,
feeGrowthInside0LastX128:feeGrowthInside0LastX128,
feeGrowthInside1LastX128:feeGrowthInside1LastX128,
tokensOwed0:0,
tokensOwed1:0
});
}