Cloning two contracts in the same function doesn't work

Hi everyone,
I'm a Solidity developer currently studying OpenZeppelin. I'm trying to clone the same implementation contract twice within the same function, but when I try to do so only the first clone I'm trying to make actually is "usable": the other one has some sort of error that doesn't allow me to interact with it using ABI.
Please find attached the code I've written:

// SPDX-License-Identifier: UNLICENSE
// Author: Stilgar

pragma solidity ^0.8.0;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts/proxy/Clones.sol";

import "./CaladanToken.sol";

contract CaladanPool is OwnableUpgradeable {
    string public poolName;

    uint public earnedReward = 0;
    uint public strikePrice;

    address public rewardToken;
    address public shortTokenAddress;
    address public longTokenAddress;

    function initialize(string memory _poolName, uint _strikePrice, address tokenImplementation) virtual initializer public {
        // initilaize PoolName and tracked Strike Price
        poolName = _poolName;
        strikePrice = _strikePrice;

        // clone and create a LONG pool token
        longTokenAddress = Clones.clone(tokenImplementation);
        CaladanToken longToken = CaladanToken(longTokenAddress);
        string memory longName = string(abi.encodePacked("LONG-",_poolName));
        longToken.initialize(longName, longName);

        // clone and create a SHORT pool token
        shortTokenAddress = Clones.clone(tokenImplementation);
        CaladanToken shortToken = CaladanToken(shortTokenAddress);
        string memory nameSymbol = string(abi.encodePacked("SHORT-",_poolName));
        shortToken.initialize(nameSymbol, nameSymbol);

        __Ownable_init();
    }
}```

Hey @valerio-mc,
can you provide the error you get?

Hi @FreezyEx , thanks for your interest.
It doesn't get me a proper error but I can't properly interface with shortToken address using either Remix or Hardhat. However, it works with the longToken address. Do you have any idea of why it doesn't work as expected?

Edit: it seems as if I can have only clone per contract and shortToken and longToken can't coexist.

These are the testing codes I'm using and the error I get from HardHat. The reported error is triggered every time I try to interface with ShortToken contract, while if I try to interact with LongToken contract everything works fine. It seems to me that is not possible to have more than 1 clone per contract, but this doesn't sound right....


Hello @valerio-mc

The code you provide has a dependency on CaladanToken.sol and contains code that is unrelated to the issue. Could you please provide a minimal reproducible example?