5 使用Vyper调用PancakeSwap合约时报错,无法部署

以下是我的代码,我将合约换成Uniswap和WETH时可以正常部署,但是Pancake不行,请教大佬们

# @version ^0.2

from vyper.interfaces import ERC20

interface PancakeRouter:
    def swapExactTokensForTokens(
        amountIn: uint256,
        amountOutMin: uint256,
        path: address[3],
        to: address,
        deadline: uint256
    ) -> uint256[3]: nonpayable

PANCAKESWAP: constant(address) = 0x10ED43C718714eb63d5aA57B78B54704E256024E
WBNB: constant(address) = 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c

@external
def swap(tokenIn: address, tokenOut: address, amountIn: uint256):
    ERC20(tokenIn).transferFrom(msg.sender, self, amountIn)
    ERC20(tokenIn).approve(PANCAKESWAP, amountIn)

    res: Bytes[128] = raw_call(
        PANCAKESWAP,
        concat(
            method_id("swapExactTokensForTokens(uint256, uint256, address[], address, uint256)"),
            convert(amountIn, bytes32),
            convert(0, bytes32),
            convert(160, bytes32),
            convert(self, bytes32),
            convert(block.timestamp, bytes32),
            convert(3, bytes32),
            convert(tokenIn, bytes32),
            convert(WBNB, bytes32),
            convert(tokenOut, bytes32),
        ),
        max_outsize=128,
    )
请先 登录 后评论

2 个回答

Tiny熊
  擅长:智能合约,以太坊
请先 登录 后评论
Deep Defi - Solidity engineer
请先 登录 后评论
  • 2 关注
  • 0 收藏,2367 浏览
  • 0x77 提出于 2022-03-18 13:51