I have just encountered some very strange bug/issue? While playing with NonfungiblePositionManager contract. I have wrote solidity code that creates new ERC20 contract and then calling function dexCoin() from another my contract that takes this newly created ERC20 contract address and calls below:
I have then wrote some simple test using foundry to check if everything works and indeed it was until I ran same code on forked Ethereum Mainnet. So the problem occurs on every single forked mainnet I tested (Ethereum Mainnet, Polygon, Avalanche), there is no issue on testnets like Sepolia.
This is contract code I'm using to start calls chain:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {Coin} from "./Coin.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {ICoinDexer} from "./Interfaces/ICoinDexer.sol";
import {ICoinMinter} from "./Interfaces/ICoinMinter.sol";
contract CoinMinter is ICoinMinter, Ownable {
/// @dev Constructor
/// @notice Owner of this contract is DFM contract
constructor() Ownable(msg.sender) {}
/////////////////////// @notice MCM External Functions (Callable only by DFM contract) ///////////////////////
/// @notice Deploys new ERC20 Token
/// @param params ICoinMinter
function mintCoinAndRequestDex(MintParams calldata params) external onlyOwner {
/// @dev BUG HERE:
Coin newCoin = new Coin(params);
emit CoinMinted(address(newCoin), params.name, params.symbol);
ICoinDexer(params.mcd).dex(address(newCoin), params.totalFunds, params.totalCoins);
emit ICoinDexer.DexRequestReceived(address(newCoin));
}
}
If i run my test on forked mainnet I'm getting those logs:
So to sum up the only thing that changed is that ERC20 contract address. I have noticed that createAndInitializePoolIfNecessary has problem with some certain addresses and only while testing on mainnets. I have even reproduced this error using different private key and creating additional unnecessary coin as above but it didnt solve issue, so i guess address generated was incorrect for some reason. Solution I showed works only for some private keys and if it pass on ethereum mainnet it will also pass on any other mainnet and testnet. Am I missing some additional requirements to create and initialize pool? Maybe it is just foundry bug and it is creating some corrupted addresses (I highly doubt)? Or it just needs some specific ERC20 address format.
If anyone has any idea how this can be fixed or can explain to me where is the problem I will be very grateful!
Hello,
I have just encountered some very strange bug/issue? While playing with NonfungiblePositionManager contract. I have wrote solidity code that creates new ERC20 contract and then calling function
dexCoin()
from another my contract that takes this newly created ERC20 contract address and calls below:I have then wrote some simple test using
foundry
to check if everything works and indeed it was until I ran same code on forked Ethereum Mainnet. So the problem occurs on every single forked mainnet I tested (Ethereum Mainnet, Polygon, Avalanche), there is no issue on testnets like Sepolia.This is contract code I'm using to start calls chain:
If i run my test on forked mainnet I'm getting those logs:
But if i do this in contract above:
so i just added this line
new Coin(params);
and i run same test without changing anything else in code it works perfectly fine:So to sum up the only thing that changed is that ERC20 contract address. I have noticed that
createAndInitializePoolIfNecessary
has problem with some certain addresses and only while testing on mainnets. I have even reproduced this error using different private key and creating additional unnecessary coin as above but it didnt solve issue, so i guess address generated was incorrect for some reason. Solution I showed works only for some private keys and if it pass on ethereum mainnet it will also pass on any other mainnet and testnet. Am I missing some additional requirements to create and initialize pool? Maybe it is justfoundry
bug and it is creating some corrupted addresses (I highly doubt)? Or it just needs some specific ERC20 address format.If anyone has any idea how this can be fixed or can explain to me where is the problem I will be very grateful!