單雙幣/子母幣/多幣質(zhì)押挖礦系統(tǒng)開發(fā)(開發(fā)規(guī)則)及詳細源碼
Metaverse is a virtual world constructed by humans using digital technology,mapped or transcended by the real world,and can interact with the real world.It is a digital living space with a new social system.
The"meta universe"itself is not a new technology,but rather integrates a large number of existing technologies,including 5G,cloud computing,artificial intelligence,virtual reality,blockchain,the Internet of Things,human-computer interaction,and so on.
For users,it is mainly about experiencing various meta universe application scenarios,such as meta universe e-commerce,meta universe social networking,meta universe entertainment,and meta universe office.All real-world scenarios can be presented in the meta universe through digital technology,so it can also be understood as a digital city,and more importantly,a digital earth.
swap是普通用戶進行代幣交易的操作。普通用戶通過swap操作實現(xiàn)兩種token之間的交易。
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[]calldata path,
開發(fā)案例I59源碼2OO7詳細3O69
address to,
uint deadline
)external virtual override ensure(deadline)returns(uint[]memory amounts){
關(guān)于區(qū)塊鏈項目技術(shù)開發(fā)唯:yy625019,代幣發(fā)行、dapp智能合約開發(fā)、鏈游開發(fā)、多鏈錢包開發(fā)
交易所開發(fā)、量化合約開發(fā)、互助游戲開發(fā)、Nft數(shù)字藏品開發(fā)、眾籌互助開發(fā)、元宇宙開發(fā)、swap開發(fā)、
鏈上合約開發(fā)、ido開發(fā)、商城開發(fā)等,開發(fā)過各種各樣的系統(tǒng)模式,更有多種模式、制度、案例、后臺等,成熟技術(shù)團隊,歡迎實體參考。
Uniswap支持多種代幣的交換。具體的含義是,Uniswap提供了多級交易池的路由功能。舉個例子,已有兩個交易對TokenA-TokenB,以及TokenB-TokenC,通過swap接口,可以實現(xiàn)TokenA-TokenC的交換,其中經(jīng)過的TokenA-TokenB,TokenB-TokenC,稱為路徑(path)。amountIn是路徑中的第一個代幣的數(shù)量,amountOutMin是期望的交換后的最少的數(shù)量。
amounts=UniswapV2Library.getAmountsOut(factory,amountIn,path);
require(amounts[amounts.length-1]>=amountOutMin,‘UniswapV2Router:INSUFFICIENT_OUTPUT_AMOUNT’);
amounts是每個路徑上的交換后的數(shù)量。amounts[amounts.length-1]也就是最后一條路徑的輸出數(shù)量。注意,UniswapV2Library.getAmountsOut的實現(xiàn)(在獲取每個交易對的reserve信息后,調(diào)用getAmountOut函數(shù)):
function getAmountOut(uint amountIn,uint reserveIn,uint reserveOut)internal pure returns(uint amountOut){
require(amountIn>0,'UniswapV2Library:INSUFFICIENT_INPUT_AMOUNT');
require(reserveIn>0&&reserveOut>0,'UniswapV2Library:INSUFFICIENT_LIQUIDITY');
uint amountInWithFee=amountIn.mul(997);
uint numerator=amountInWithFee.mul(reserveOut);
uint denominator=reserveIn.mul(1000).add(amountInWithFee);
amountOut=numerator/denominator;
}
注意,其中的997/1000的系數(shù)。在進入每個交易池之前,進入的金額先扣除了0.3%的本金。這個就是交易費。注意的是,路徑上的交易池,每個池子都收。有點像高速收費站,一段段的收。
TransferHelper.safeTransferFrom(
path[0],msg.sender,UniswapV2Library.pairFor(factory,path[0],path[1]),amounts[0]
);
將代幣path[0],轉(zhuǎn)入到交易對,數(shù)量為amounts[0]。轉(zhuǎn)入代幣后,進行真正的swap操作:
function _swap(uint[]memory amounts,address[]memory path,address _to)internal virtual{
for(uint i;i<path.length-1;i++){
(address input,address output)=(path<i>,path[i+1]);
(address token0,)=UniswapV2Library.sortTokens(input,output);
uint amountOut=amounts[i+1];
(uint amount0Out,uint amount1Out)=input==token0?(uint(0),amountOut):(amountOut,uint(0));
address to=i<path.length-2?UniswapV2Library.pairFor(factory,output,path[i+2]):_to;
IUniswapV2Pair(UniswapV2Library.pairFor(factory,input,output)).swap(
amount0Out,amount1Out,to,new bytes(0)
);
}
}