0

I am trying to override the _update function in an ERC1155 contract. However I get the following compiler error on my code:

Member "_update" not found or not visible after argument-dependent lookup in type(contract super MyContract).(9582)

But super._update works in the override function, but not my secondary function. Why is this? I have the error on the line in adjustSftBalances() marked in **, no issues on the _update override.

function _update(address from, address to, uint256[] memory ids, uint256[] memory values) internal override virtual {
    // check that batch update is valid.
    if (ids.length != values.length) revert ERC1155InvalidArrayLength(ids.length, values.length);

    // users can only own 1 SFT ID so can only send SFT and token and ERC20 token, should not be transferring more than 2.
    if (values.length > 2) revert ERC1155InvalidArrayLength(ids.length, values.length);
    
    uint256[] memory newIds = new uint256[](1);
    uint256[] memory newValues = new uint256[](1);

    newIds[0] = ERC20_ID;

    if (from != address(0)) {

    }
    for (uint8 i; i < ids.length; i++) {
        if (ids[i] == ERC20_ID) {
            newValues[0] = values[i];
        }
        if (ids[i] > ERC20_ID) {
            newValues[0] = balanceFromRarity(balanceOf(from));
        }
    }
    super._update(from, to, newIds, newValues);

    adjustSftBalances(from);
    adjustSftBalances(to);

}

function adjustSftBalances(address owner) internal virtual {
    if (owner != address(0)) {
        if (_totalSupply[owner] < tokenRarity(owner)) {
            **super._update(address(0), owner, uint160(owner), tokenRarity(owner) - _totalSupply[owner]);**
            // super._mint(owner, uint160(owner), tokenRarity(owner) - _totalSupply[owner], "");
        }
        if (_totalSupply[owner] > tokenRarity(owner)) {
            super._burn(owner, uint160(owner), _totalSupply[owner] - tokenRarity(owner));
        }
        // using your idea of SFTs.
        _totalSupply[owner] = tokenRarity(owner); // if you add the following code they become NFTs > 0 ? 1 : 0;
    }
}

Actually, come to think of it, my first problem seems to be that super._mint was calling my overriden _update function instead of the super._update, but I'm not sure if that was how it should work, I could manually do the super_update but I was hoping super._mint would work using the default functions.

1 Answer 1

0

This was just me being dumb. I was trying to pass in uint256 instead of uint256[]. Here's the correct code but another issue (that I'm not sure is a real issue) is that super._burn and super._mint didn't use super._update. Should it?

The fixed code is here:

function adjustSftBalances(address owner) public {
    if (owner != address(0)) {
        uint256[] memory ids = new uint256[](1);
        ids[0] = uint160(owner);
        uint256[] memory values = new uint256[](1);
        if (_totalSupply[owner] < tokenRarity(owner)) {
            values[0] = tokenRarity(owner) - _totalSupply[owner];
            super._update(address(0), owner, ids, values);
            // super._mint(owner, uint160(owner), tokenRarity(owner) - _totalSupply[owner], "");
        }
        if (_totalSupply[owner] > tokenRarity(owner)) {
            values[0] = _totalSupply[owner] - tokenRarity(owner);
            super._update(owner, address(0), ids, values);
            // super._burn(owner, uint160(owner), _totalSupply[owner] - tokenRarity(owner));
        }
        // using your idea of SFTs.
        _totalSupply[owner] = tokenRarity(owner); // if you add the following code they become NFTs > 0 ? 1 : 0;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.