真正实现以大数据、云计算、人工智能、沉浸现实等诸多新技术实现联通,并且真正构建起一个完整的全新世界的,正是区块链技术。这便是区块链的功能。透过元宇宙,我们真正看到了区块链技术的这样一种联通、融合的角色与作用;透过元宇宙,我们看到了区块链技术的这样一种建构于生态之上的强大的能力。
//performs chained getAmountOut calculations on any number of pairs
//根据path,计算出每个交易对的输入/输出量(如果path>2,前一个交易对的输出量,就是下一个交易对交易的输入量)
//内部实际还是调用的上面getAmountOut方法,返回值amounts长度和path的长度一致,
function getAmountsOut(address factory,uint amountIn,address[]memory path)internal view returns(uint[]memory amounts){
require(path.length>=2,'UniswapV2Library:INVALID_PATH');
amounts=new uint[](path.length);//创建数组
amounts[0]=amountIn;//0位置是输入量
for(uint i;i<path.length-1;i++){//每两个token组成一个交易对,计算out
(uint reserveIn,uint reserveOut)=getReserves(factory,path<i>,path[i+1]);
amounts[i+1]=getAmountOut(amounts<i>,reserveIn,reserveOut);
}
}
//performs chained getAmountIn calculations on any number of pairs
//根据path,计算出每个交易对的输入/输出量(如果path>2,前一个交易对的输出量,就是下一个交易对交易的输入量)
//内部实际还是调用的上面getAmountIn方法,返回值amounts长度和path的长度一致,
function getAmountsIn(address factory,uint amountOut,address[]memory path)internal view returns(uint[]memory amounts){
require(path.length>=2,'UniswapV2Library:INVALID_PATH');
amounts=new uint[](path.length);
amounts[amounts.length-1]=amountOut;//最后一个是入参out,
for(uint i=path.length-1;i>0;i--){//倒序遍历计算
(uint reserveIn,uint reserveOut)=getReserves(factory,path[i-1],path<i>);
amounts[i-1]=getAmountIn(amounts<i>,reserveIn,reserveOut);
}
}
}
//helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false
//转账工具类
library TransferHelper{
function safeApprove(address token,address to,uint value)internal{
//bytes4(keccak256(bytes('approve(address,uint256)')));
(bool success,bytes memory data)=token.call(abi.encodeWithSelector(0x095ea7b3,to,value));
require(success&&(data.length==0||abi.decode(data,(bool))),'TransferHelper:A