dapp的开发和运行基于智能合约,智能合约是一种运行在区块链上的自动执行合约,它可以实现自动化的交易和管理逻辑,And automatically supervise and execute according to the set rules.Dapp achieves decentralized data storage,business logic,and value exchange through smart contracts.
dapp是去中心化应用程序的简称。它是一种基于区块链技术构建的应用程序,具有去中心化、开放性、透明度、安全性和稳定性等特点。与传统的应用程序不同,dapp不需要采用传统的服务器和数据库,而是直接运行在区块链上。
The technical architecture of dapp mainly includes the following three levels:
Application layer:The application layer refers to the DAPP application that users directly come into contact with,including interface design,interaction methods,user experience,etc.,which needs to fully consider user needs and usage habits.
Protocol layer:The protocol layer refers to the protocols and rules of DAPP,including communication protocols,transaction rules,financial protocols,contract protocols,etc.,which need to ensure their security,stability,and transparency.
Blockchain layer:The blockchain layer is the underlying technical support for DAPP,including blockchain nodes,smart contracts,decentralized storage,consensus algorithms,etc.It requires algorithms and technical means to achieve decentralization,security,and scalability.
function _modifyPosition(ModifyPositionParams memory params)
private
noDelegateCall
returns(
Position.Info storage position,
int256 amount0,
int256 amount1
)
{
...
Slot0 memory _slot0=slot0;//SLOAD for gas optimization
position=_updatePosition(
...
);
...
}
function _modifyPosition(ModifyPositionParams memory params)
private
noDelegateCall
returns(
Position.Info storage position,
int256 amount0,
int256 amount1
)
{
...
if(params.liquidityDelta!=0){
//计算三种情况下amount0和amount1的值,即x token和y token的数量
if(_slot0.tick<params.tickLower){
amount0=SqrtPriceMath.getAmount0Delta(
//计算lower/upper tick对应的价格
TickMath.getSqrtRatioAtTick(params.tickLower),
TickMath.getSqrtRatioAtTick(params.tickUpper),
params.liquidityDelta
);
}else if(_slot0.tick<params.tickUpper){
//current tick is inside the passed range
uint128 liquidityBefore=liquidity;//SLOAD for gas optimization
...
amount0=SqrtPriceMath.getAmount0Delta(
_slot0.sqrtPriceX96,
TickMath.getSqrtRatioAtTick(params.tickUpper),
params.liquidityDelta
);
amount1=SqrtPriceMath.getAmount1Delta(
TickMath.getSqrtRatioAtTick(params.tickLower),
_slot0.sqrtPriceX96,
params.liquidityDelta
);
liquidity=LiquidityMath.addDelta(liquidityBefore,params.liquidityDelta);
}else{
amount1=SqrtPriceMath.getAmount1Delta(
TickMath.getSqrtRatioAtTick(params.tickLower),
TickMath.getSqrtRatioAtTick(params.tickUpper),
params.liquidityDelta
);
}
}
}