5 使用Vyper无法调用Uniswap添加流动性

我使用Vyper调用Uniswap添加流动性功能的合约,在Rinkeby上部署后发现的addLP这个功能没办法用,提示: image.png

我已经将gaslimit调到了最高也没用,不知道哪里有问题,有没有大佬帮忙看下,修改下代码哪里有问题,感激不尽

from vyper.interfaces import ERC20

interface UniswapV2Router02:
def factory() -> address: nonpayable
def addLiquidityETH(
token: address,
amountTokenDesired: uint256,
amountTokenMin: uint256,
amountETHMin: uint256,
to: address,
deadline: uint256
) -> uint256[3]: nonpayable

WETHAddress: address
Factory: address

UNISWAP: constant(address) = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D
SUSD: constant(address) = 0x970C963166351B901c642B8CB49920536C3127e6
WETH: constant(address) = 0xc778417E063141139Fce010982780140Aa0cD5Ab

@external
def __init__():
self.Factory = UniswapV2Router02(UNISWAP).factory()

@external
@view
def getFactoryAddress() -> address:
return self.Factory

@external
@payable
def addLP(tokenIn: address, amountTokenDes: uint256):
ERC20(SUSD).transferFrom(msg.sender, self, amountTokenDes)
ERC20(SUSD).approve(UNISWAP, amountTokenDes)

res: Bytes[128] = raw_call(
UNISWAP,
concat(
method_id("addLiquidityETH(address,uint256,uint256,uint256,address,uint256)"),
convert(tokenIn, bytes32),
convert(amountTokenDes, bytes32),
convert(amountTokenDes * 995 / 1000, bytes32),
convert(msg.value * 995 / 1000, bytes32),
convert(self, bytes32),
convert(block.timestamp, bytes32),
),
gas=msg.gas,
max_outsize=128,
)
请先 登录 后评论

1 个回答

Deep Defi - Solidity engineer
请先 登录 后评论
  • 1 关注
  • 0 收藏,2398 浏览
  • 0x77 提出于 2022-03-22 11:59