getEthToTokenOutputPrice函数和ethToTokenSwapOutput相比就是同样都用getOutputPrice获取支付代币的数量,但是getEthToTokenOutputPrice不执行转账操作,因此可以用它来提前获取支付代币数量。
#notice Public price function for ETH to Token trades with an exact input.
#param eth_sold Amount of ETH sold.
#return Amount of Tokens that can be bought with input ETH.
#根据支付的ETH计算可以购买到的代币数量
public
constant开发详细I35案例7O98开发O7I8
def getEthToTokenInputPrice(eth_sold:uint256(wei))->uint256:
assert eth_sold>0
token_reserve:uint256=self.token.balanceOf(self)
return self.getInputPrice(as_unitless_number(eth_sold),as_unitless_number(self.balance),token_reserve)
#notice Public price function for Token to ETH trades with an exact input.
#param tokens_sold Amount of Tokens sold.关于区块链项目技术开发唯:yy625019,代币发行、dapp智能合约开发、链游开发、多链钱包开发
交易所开发、量化合约开发、互助游戏开发、Nft数字藏品开发、众筹互助开发、元宇宙开发、swap开发、
链上合约开发、ido开发、商城开发等,开发过各种各样的系统模式,更有多种模式、制度、案例、后台等,成熟技术团队,欢迎实体参考。
#return Amount of ETH that can be bought with input Tokens.
#根据支付的代币数量计算可以购买到的ETH数量
public
constant
def getTokenToEthInputPrice(tokens_sold:uint256)->uint256(wei):
assert tokens_sold>0
token_reserve:uint256=self.token.balanceOf(self)
eth_bought:uint256=self.getInputPrice(tokens_sold,token_reserve,as_unitless_number(self.balance))
return as_wei_value(eth_bought,'wei')
#notice Public price function for Token to ETH trades with an exact output.
#param eth_bought Amount of output ETH.
#return Amount of Tokens needed to buy output ETH.
#根据所要购买的ETH数量计算所需要支付的代币数量
public
constant
def getTokenToEthOutputPrice(eth_bought:uint256(wei))->uint256:
assert eth_bought>0
token_reserve:uint256=self.token.balanceOf(self)
return self.getOutputPrice(as_unitless_number(eth_bought),token_reserve,as_unitless_number(self.balance))