我最近从存储库那里得到了分叉。在我的部署过程中从createPair()调用UniswapV2Factory.sol时,我得到了以下错误,代码没有被触及,我不知道我哪里出错了。
错误:Error: Returned error: VM Exception while processing transaction: revert
部署:
// 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函数:
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);,但是为什么我不知道。
任何见解都将不胜感激!詹姆斯
发布于 2021-01-19 05:21:58
检查您的松露配置。如果要部署到testnet或本地,请添加标志
skipDryRun: true
我使用此标志将契约部署到ropsten和mainnet(注意:这是mainnet上的默认设置)
https://ethereum.stackexchange.com/questions/92156
复制相似问题