Artificial intelligence(AI)refers to the ability of computer systems to perform tasks similar to human intelligence.It is a complex technology,which constantly adjusts and improves its own algorithm by inputting a large amount of data into the algorithm for learning,so as to continuously optimize its performance.
AI can be divided into two categories:weak AI and strong AI.Weak AI(also known as narrow AI)refers to AI systems that can only show human intelligence in specific task areas.For example,voice recognition system,auto drive system,etc.Strong artificial intelligence(also known as generalized artificial intelligence)refers to an artificial intelligence system that can display human-like intelligence in various task fields like humans.
ERC20代币兑换ERC20代币的函数入口和ERC20代币兑换ETH的函数入口类似,不同的是ERC20代币兑换ERC20代币的函数入口在调用进行兑换的业务函数前会先用创建自身的工厂合约实现的getExchange函数来获取目标代币所在的兑换合约地址,然后再向目标兑换合约地址发送兑换请求,将在本合约兑换得到的ETH兑换成目标代币。
函数入口调用到的函数就两种,分别是根据输入代币计算输出代币的tokenToTokenInput,以及根据输出代币计算输入代币的tokenToTokenOutput。
下面先看tokenToTokenInput。
private
def tokenToTokenInput(tokens_sold:uint256,min_tokens_bought:uint256,min_eth_bought:uint256(wei),deadline:timestamp,buyer:address,recipient:address,exchange_addr:address)->uint256:
assert(deadline>=block.timestamp and tokens_sold>0)and(min_tokens_bought>0 and min_eth_bought>0)
assert exchange_addr!=self and exchange_addr!=ZERO_ADDRESS
token_reserve:uint256=self.token.balanceOf(self)#获得支付代币的储备量
#用getInputPrice计算所能兑换到的ETH
eth_bought:uint256=self.getInputPrice(tokens_sold,token_reserve,as_unitless_number(self.balance))
wei_bought:uint256(wei)=as_wei_value(eth_bought,'wei')#将单位转换成wei
assert wei_bought>=min_eth_bought