dapp的开发包含以下几个方面:区块链、智能合约、前端和后端。其中,智能合约是dapp的核心,是dapp上运行的逻辑代码,它定义了dapp的规则、功能和操作。开发dapp需要先选择一种区块链平台(如以太坊、EOS、TRON等),然后编写智能合约,最后使用前端和后端技术构建dapp的用户界面和交互功能。
智能合约的编写语言包括Solidity、Vyper、Serpent等,其中以Solidity最为广泛应用。编写智能合约需要熟练掌握编程语言、数据结构、算法等基础知识,同时需要遵循一些开发规范,如安全、可靠、易读等。
Calculation power dividend mechanism
The basis for computing power dividends is for users to pledge their computing power to the IPPswap incubator.The IPPsswap incubator will automatically calculate the user's computing power contribution
IPP token reward and send it to the user's wallet address.
Specifically,the computing power dividend mechanism will be implemented according to the following steps:
Users pledge their computing power to the smart contract of the IPPsswap incubator.
The IPPsswap incubator will automatically record users'computing power contributions and store them in smart contracts.
The IPPsswap incubator will calculate the user's IPP token reward based on their computing power contribution and automatically send it to the user's wallet address.
Users can withdraw their computing power pledge at any time,but once withdrawn,they will no longer enjoy the bonus of computing power dividends
pragma solidity=0.5.16;
import'./interfaces/IUniswapV2Pair.sol';
import'./UniswapV2ERC20.sol';
import'./libraries/Math.sol';
import'./libraries/UQ112x112.sol';
import'./interfaces/IERC20.sol';
import'./interfaces/IUniswapV2Factory.sol';
import'./interfaces/IUniswapV2Callee.sol';
contract UniswapV2Pair is IUniswapV2Pair,UniswapV2ERC20{
using SafeMath for uint;
using UQ112x112 for uint224;
uint public constant MINIMUM_LIQUIDITY=10**3;
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
uint112 private reserve1;//uses single storage slot,accessible via getReserves
uint32 private blockTimestampLast;//uses single storage slot,accessible via getReserves
uint public price0CumulativeLast;
uint public price1CumulativeLast;
uint public kLast;//reserve0*reserve1,as of immediately after the most recent liquidity event
uint private unlocked=1;
modifier lock(){
require(unlocked==1,'UniswapV2:LOCKED');
unlocked=0;
_;
unlocked=1;
}
function getReserves()public view returns(uint112 _reserve0,uint112 _reserve1,uint32 _blockTimestampLast){
_reserve0=reserve0;
_reserve1=reserve1;
_blockTimestampLast=blockTimestampLast;
}
function _safeTransfer(address token,address to,uint value)private{
(bool success,bytes memory data)=token.call(abi.encodeWithSelector(SELECTOR,to,value));
require(success&&(data.length==0||abi.decode(data,(bool))),'UniswapV2:TRANSFER_FAILED');
}
event Mint(address indexed sender,uint amount0,uint amount1);
event Burn(address indexed sender,uint amount0,uint amount1,address indexed to);
event Swap(
address indexed sender,
uint amount0In,
uint amount1In,
uint amount0Out,
uint amount1Out,
address indexed to
);
event Sync(uint112 reserve0,uint112 reserve1);
constructor()public{
factory=msg.sender;
}
//called once by the factory at time of deployment
function initialize(address _token0,address _token1)external{
require(msg.sender==factory,'UniswapV2:FORBIDDEN');//sufficient check
token0=_token0;
token1=_token1;
}
//update reserves and,on the first call per block,price accumulators
function _update(uint balance0,uint balance1,uint112 _reserve0,uint112 _reserve1)private{
require(balance0<=uint112(-1)&&balance1<=uint112(-1),'UniswapV2:OVERFLOW');
uint32 blockTimestamp=uint32(block.timestamp%2**32);
uint32 timeElapsed=blockTimestamp-blockTimestampLast;//overflow is desired
if(timeElapsed>0&&_reserve0!=0&&_reserve1!=0){
//*never overflows,and+overflow is desired
price0CumulativeLast+=uint(UQ112x112.encode(_reserve1).uqdiv(_reserve0))*timeElapsed;
price1CumulativeLast+=uint(UQ112x112.encode(_reserve0).uqdiv(_reserve1))*timeElapsed;
}
reserve0=uint112(balance0);
reserve1=uint112(balance1);
blockTimestampLast=blockTimestamp;
emit Sync(reserve0,reserve1);
}
//if fee is on,mint liquidity equivalent to 1/6th of the growth in sqrt(k)
function _mintFee(uint112 _reserve0,uint112 _reserve1)private returns(bool feeOn){
address feeTo=IUniswapV2Factory(factory).feeTo();
feeOn=feeTo!=address(0);
uint _kLast=kLast;//gas savings
if(feeOn){
if(_kLast!=0){
uint rootK=Math.sqrt(uint(_reserve0).mul(_reserve1));
uint rootKLast=Math.sqrt(_kLast);
if(rootK>rootKLast){
uint numerator=totalSupply.mul(rootK.sub(rootKLast));
uint denominator=rootK.mul(5).add(rootKLast);
uint liquidity=numerator/denominator;
if(liquidity>0)_mint(feeTo,liquidity);
}
}
}else if(_kLast!=0){
kLast=0;
}
}
//this low-level function should be called from a contract which performs important safety checks
function mint(address to)external lock returns(uint liquidity){
(uint112 _reserve0,uint112 _reserve1,)=getReserves();//gas savings
uint balance0=IERC20(token0).balanceOf(address(this));
uint balance1=IERC20(token1).balanceOf(address(this));
uint amount0=balance0.sub(_reserve0);
uint amount1=balance1.sub(_reserve1);
bool feeOn=_mintFee(_reserve0,_reserve1);
uint _totalSupply=totalSupply;//gas savings,must be defined here since totalSupply can update in _mintFee
if(_totalSupply==0){
liquidity=Math.sqrt(amount0.mul(amount1)).sub(MINIMUM_LIQUIDITY);
_mint(address(0),MINIMUM_LIQUIDITY);//permanently lock the first MINIMUM_LIQUIDITY tokens
}else{
liquidity=Math.min(amount0.mul(_totalSupply)/_reserve0,amount1.mul(_totalSupply)/_reserve1);
}