首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SushiSwap Fork在createPair()

SushiSwap Fork在createPair()
EN

Ethereum用户
提问于 2021-01-11 16:28:26
回答 1查看 648关注 0票数 2

我最近从存储库那里得到了分叉。在我的部署过程中从createPair()调用UniswapV2Factory.sol时,我得到了以下错误,代码没有被触及,我不知道我哪里出错了。

错误:Error: Returned error: VM Exception while processing transaction: revert

部署:

代码语言:javascript
复制
// Uniswap
const Factory = artifacts.require('Uniswapv2/UniswapV2Factory.sol');

// WETH
const WETH = artifacts.require('WETH.sol');

// Testing
const MockERC20 = artifacts.require('MockERC20.sol');

module.exports = async function(deployer, network, accounts) {
    const [admin, _] = accounts;

    // Test Tokens
    const tokenA = await MockERC20.new('TokenA', 'TKA', web3.utils.toWei('100000'));
    const tokenB = await MockERC20.new('TokenB', 'TKB', web3.utils.toWei('100000'));

    // Uniswap factory
    await deployer.deploy(Factory, admin);
    const factory = await Factory.deployed();

    await factory.createPair(tokenA.address, tokenB.address);

};

CreatePair函数:

代码语言:javascript
复制
function createPair(address tokenA, address tokenB) external override returns (address pair) {
        require(tokenA != tokenB, 'UniswapV2: IDENTICAL_ADDRESSES');
        (address token0, address token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
        require(token0 != address(0), 'UniswapV2: ZERO_ADDRESS');
        require(getPair[token0][token1] == address(0), 'UniswapV2: PAIR_EXISTS'); // single check is sufficient
        bytes memory bytecode = type(UniswapV2Pair).creationCode;
        bytes32 salt = keccak256(abi.encodePacked(token0, token1));
        assembly {
            pair := create2(0, add(bytecode, 32), mload(bytecode), salt)
        }
        UniswapV2Pair(pair).initialize(token0, token1); //<-- this is causing the error
        getPair[token0][token1] = pair;
        getPair[token1][token0] = pair; // populate mapping in the reverse direction
        allPairs.push(pair);
        emit PairCreated(token0, token1, pair, allPairs.length);
    }

我推断错误发生在这里,UniswapV2Pair(pair).initialize(token0, token1);,但是为什么我不知道。

任何见解都将不胜感激!詹姆斯

EN

回答 1

Ethereum用户

发布于 2021-01-19 05:21:58

检查您的松露配置。如果要部署到testnet或本地,请添加标志

skipDryRun: true

我使用此标志将契约部署到ropsten和mainnet(注意:这是mainnet上的默认设置)

票数 1
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/92156

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档