Skip to content

Commit

Permalink
settable permissioners / revert reinit (#150)
Browse files Browse the repository at this point in the history
* adds a setter for the permissioner
* uses contracts instead of addresses
* adds a address(0) check to setters

Signed-off-by: stadolf <stefan@molecule.to>

---------

Signed-off-by: stadolf <stefan@molecule.to>
  • Loading branch information
elmariachi111 authored Jan 11, 2024
1 parent 5d4ffbb commit 6edce47
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
29 changes: 21 additions & 8 deletions src/Tokenizer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import { IPNFT } from "./IPNFT.sol";

error MustOwnIpnft();
error AlreadyTokenized();

error ZeroAddress();
/// @title Tokenizer 1.2
/// @author molecule.to
/// @notice tokenizes an IPNFT to an ERC20 token (called IPT) and controls its supply.

contract Tokenizer is UUPSUpgradeable, OwnableUpgradeable {
event TokensCreated(
uint256 indexed moleculesId,
Expand All @@ -27,7 +28,8 @@ contract Tokenizer is UUPSUpgradeable, OwnableUpgradeable {
string symbol
);

event IPTokenImplementationUpgraded(address indexed oldAddress, address indexed newAddress);
event IPTokenImplementationUpdated(IPToken indexed old, IPToken indexed _new);
event PermissionerUpdated(IPermissioner indexed old, IPermissioner indexed _new);

IPNFT internal ipnft;

Expand All @@ -42,7 +44,7 @@ contract Tokenizer is UUPSUpgradeable, OwnableUpgradeable {
/// @dev the permissioner checks if senders have agreed to legal requirements
IPermissioner permissioner;

address public ipTokenImplementation;
IPToken public ipTokenImplementation;
/**
* @param _ipnft the IPNFT contract
* @param _permissioner a permissioning contract that checks if callers have agreed to the tokenized token's legal agreements
Expand All @@ -66,20 +68,31 @@ contract Tokenizer is UUPSUpgradeable, OwnableUpgradeable {
* @notice sets the new implementation address of the IPToken
* @param _ipTokenImplementation address pointing to the new implementation
*/
function setIPTokenImplementation(address _ipTokenImplementation) public onlyOwner {
function setIPTokenImplementation(IPToken _ipTokenImplementation) external onlyOwner {
/*
could call some functions on old contract to make sure its tokenizer not another contract behind a proxy for safety
*/
address oldIpTokenImplementation = ipTokenImplementation;
if (address(_ipTokenImplementation) == address(0)) {
revert ZeroAddress();
}

emit IPTokenImplementationUpdated(ipTokenImplementation, _ipTokenImplementation);
ipTokenImplementation = _ipTokenImplementation;
emit IPTokenImplementationUpgraded(oldIpTokenImplementation, _ipTokenImplementation);
}

function setPermissioner(IPermissioner _permissioner) external onlyOwner {
if (address(_permissioner) == address(0)) {
revert ZeroAddress();
}
emit PermissionerUpdated(permissioner, _permissioner);
permissioner = _permissioner;
}

/**
* @dev called after an upgrade to reinitialize a new permissioner impl.
* @param _permissioner the new TermsPermissioner
*/
function reinit(IPermissioner _permissioner) public onlyOwner reinitializer(5) {
function reinit(IPermissioner _permissioner) public onlyOwner reinitializer(4) {
permissioner = _permissioner;
}

Expand All @@ -105,7 +118,7 @@ contract Tokenizer is UUPSUpgradeable, OwnableUpgradeable {
}

// https://github.com/OpenZeppelin/workshops/tree/master/02-contracts-clone
token = IPToken(Clones.clone(ipTokenImplementation));
token = IPToken(Clones.clone(address(ipTokenImplementation)));
string memory name = string.concat("IP Tokens of IPNFT #", Strings.toString(ipnftId));
token.initialize(name, tokenSymbol, TokenMetadata(ipnftId, _msgSender(), agreementCid));

Expand Down
6 changes: 3 additions & 3 deletions test/Forking/TokenizerFork.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ contract TokenizerTest is Test {
tokenizer11.upgradeToAndCall(address(newTokenizerImplementation), upgradeCallData);
Tokenizer upgradedTokenizer = Tokenizer(mainnetTokenizer);

assertEq(upgradedTokenizer.ipTokenImplementation(), address(newIPTokenImplementation));
assertEq(address(upgradedTokenizer.ipTokenImplementation()), address(newIPTokenImplementation));

upgradedTokenizer.setPermissioner(new BlindPermissioner());

IPermissioner _permissioner = new BlindPermissioner();
upgradedTokenizer.reinit(_permissioner);
vm.stopPrank();

assertEq(ipnftMainnetInstance.ownerOf(valleyDaoIpnftId), valleyDaoMultisig);
Expand Down
2 changes: 1 addition & 1 deletion test/SalesShareDistributor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ contract SalesShareDistributorTest is Test {
)
);
tokenizer.initialize(ipnft, blindPermissioner);
tokenizer.setIPTokenImplementation(address(ipTokenImplementation));
tokenizer.setIPTokenImplementation(ipTokenImplementation);

distributor = SalesShareDistributor(
address(
Expand Down
2 changes: 1 addition & 1 deletion test/Tokenizer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ contract TokenizerTest is Test {

tokenizer = Tokenizer(address(new ERC1967Proxy(address(new Tokenizer()), "")));
tokenizer.initialize(ipnft, blindPermissioner);
tokenizer.setIPTokenImplementation(address(new IPToken()));
tokenizer.setIPTokenImplementation(new IPToken());

vm.stopPrank();

Expand Down

0 comments on commit 6edce47

Please sign in to comment.