繁体   English   中英

如何在 sushiswap 上批准 Bentobox 中的转移?

[英]How to Approve transfer in Bentobox on sushiswap?

我有这个 solidity function 用于与 Sushiswap 交互:

function swapSingleParamswhitPool(
    uint256 amountIn,
    uint256 amountOutMinimum, 
    address pool, 
    address tokenIn, 
    bytes memory data) public payable {

    ITridentRouter.ExactInputSingleParams memory exactInputSingleParams = ITridentRouter.ExactInputSingleParams(amountIn, amountOutMinimum, pool, tokenIn, data);
    tridentRouter.exactInputSingle{ value: msg.value }(exactInputSingleParams);
}

如果我运行这个 function,我总是得到错误:

{ "code": 3, "message": "execution reverted: BentoBox: Transfer not approved", "data": "0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001f42656e746f426f783a205472616e73666572206e6f7420617070726f76656400" }

我将 BentoBox 上的 masterContract 设置为已批准,也尝试手动批准,但没有任何效果。 谁能帮我这个? 非常感谢。

我目前面临这个问题并以这种方式解决了它:

  1. 将 BentoBox 上的主合同设置为已批准
IBentoBoxMinimal(bentBox).setMasterContractApproval(
               address(this), //this needs to be the address of your contract or the user if you are not transferring the funds to your contract
               _sushiswapTridentRouterAddress,
               true,
               0,
               0,
               0
           );
  1. 将令牌从用户转移到您的合约(如上所述可选)

  2. 批准允许代币从合约/用户钱包转移到便当盒

        IERC20Upgradeable(pool).safeIncreaseAllowance(
            bentBox,
           amountIn
        );
  1. 在你可以从 TridentContract 调用你需要的任何方法之后

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM