Skip to content

Commit b703822

Browse files
committed
adds general erc20 metadata fields to shared IPT interface
wrapping test case Signed-off-by: Stefan Adolf <[email protected]>
1 parent 5547642 commit b703822

File tree

5 files changed

+35
-11
lines changed

5 files changed

+35
-11
lines changed

src/IIPToken.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ interface IIPToken {
1515
function issue(address, uint256) external;
1616
function cap() external;
1717
function uri() external view returns (string memory);
18+
function name() external view returns (string memory);
19+
function symbol() external view returns (string memory);
20+
function decimals() external view returns (uint8);
1821
}

src/IPToken.sol

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ contract IPToken is IIPToken, ERC20Upgradeable, ERC20BurnableUpgradeable, Ownabl
3131

3232
Metadata internal _metadata;
3333

34-
function initialize(uint256 ipnftId, string calldata name, string calldata symbol, address originalOwner, string memory agreementCid)
34+
function initialize(uint256 ipnftId, string calldata name_, string calldata symbol_, address originalOwner, string memory agreementCid)
3535
external
3636
initializer
3737
{
3838
__Ownable_init();
39-
__ERC20_init(name, symbol);
39+
__ERC20_init(name_, symbol_);
4040
_metadata = Metadata({ ipnftId: ipnftId, originalOwner: originalOwner, agreementCid: agreementCid });
4141
}
4242

@@ -59,6 +59,17 @@ contract IPToken is IIPToken, ERC20Upgradeable, ERC20BurnableUpgradeable, Ownabl
5959
return ERC20Upgradeable.balanceOf(account);
6060
}
6161

62+
function name() public view override(ERC20Upgradeable, IIPToken) returns (string memory) {
63+
return ERC20Upgradeable.name();
64+
}
65+
66+
function symbol() public view override(ERC20Upgradeable, IIPToken) returns (string memory) {
67+
return ERC20Upgradeable.symbol();
68+
}
69+
70+
function decimals() public view override(ERC20Upgradeable, IIPToken) returns (uint8) {
71+
return ERC20Upgradeable.decimals();
72+
}
6273
/**
6374
* @notice the supply of IP Tokens is controlled by the tokenizer contract.
6475
* @param receiver address
@@ -109,7 +120,7 @@ contract IPToken is IIPToken, ERC20Upgradeable, ERC20BurnableUpgradeable, Ownabl
109120
string.concat(
110121
'{"name": "IP Tokens of IPNFT #',
111122
tokenId,
112-
'","description": "IP Tokens, derived from IP-NFTs, are ERC-20 tokens governing IP pools.","decimals": 18,"external_url": "https://molecule.to","image": "",',
123+
'","description": "IP Tokens, derived from IP-NFTs, are ERC-20 tokens governing IP pools.","decimals": 18,"external_url": "https://molecule.xyz","image": "",',
113124
props,
114125
"}"
115126
)

src/Tokenizer.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@ contract Tokenizer is UUPSUpgradeable, OwnableUpgradeable, IControlIPTs {
109109
/**
110110
* @dev sets legacy IPTs on the tokenized mapping
111111
*/
112-
function reinit(WrappedIPToken _wrappedIpTokenImplementation) public onlyOwner reinitializer(6) {
112+
function reinit(WrappedIPToken _wrappedIpTokenImplementation, IPToken _ipTokenImplementation) public onlyOwner reinitializer(6) {
113113
wrappedTokenImplementation = _wrappedIpTokenImplementation;
114+
setIPTokenImplementation(_ipTokenImplementation);
114115
}
115116

116117
/**

src/WrappedIPToken.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ contract WrappedIPToken is IIPToken, Initializable {
7575
'","original_owner": "',
7676
Strings.toHexString(_metadata.originalOwner),
7777
'","erc20_contract": "',
78-
Strings.toHexString(address(this)),
78+
Strings.toHexString(address(wrappedToken)),
7979
'","supply": "',
8080
Strings.toString(wrappedToken.totalSupply()),
8181
'"}'

test/TokenizerWrapped.t.sol

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { AcceptAllAuthorizer } from "./helpers/AcceptAllAuthorizer.sol";
1414

1515
import { FakeERC20 } from "../src/helpers/FakeERC20.sol";
1616
import { MustControlIpnft, AlreadyTokenized, Tokenizer, ZeroAddress, IPTNotControlledByTokenizer } from "../src/Tokenizer.sol";
17-
import { Metadata as TokenMetadata } from "../src/IIPToken.sol";
17+
import { IIPToken, Metadata as TokenMetadata } from "../src/IIPToken.sol";
1818
import { IPToken, TokenCapped } from "../src/IPToken.sol";
1919
import { WrappedIPToken } from "../src/WrappedIPToken.sol";
2020
import { IPermissioner, BlindPermissioner } from "../src/Permissioner.sol";
@@ -57,6 +57,9 @@ contract TokenizerWrappedTest is Test {
5757
tokenizer.initialize(ipnft, blindPermissioner);
5858
tokenizer.setIPTokenImplementation(new IPToken());
5959

60+
WrappedIPToken wrappedTokenImplementation = new WrappedIPToken();
61+
tokenizer.reinit(wrappedTokenImplementation, tokenizer.ipTokenImplementation());
62+
6063
vm.stopPrank();
6164

6265
vm.deal(originalOwner, MINTING_FEE);
@@ -65,10 +68,16 @@ contract TokenizerWrappedTest is Test {
6568
ipnft.mintReservation{ value: MINTING_FEE }(originalOwner, reservationId, ipfsUri, DEFAULT_SYMBOL, "");
6669
}
6770

68-
function testInitWrappedIPTokenImplementation() public {
69-
vm.startPrank(deployer);
70-
WrappedIPToken wrappedTokenImplementation = new WrappedIPToken();
71-
tokenizer.reinit(wrappedTokenImplementation);
72-
assertEq(address(tokenizer.wrappedTokenImplementation()), address(wrappedTokenImplementation));
71+
function testAdoptERC20AsWrappedIPToken() public {
72+
vm.startPrank(originalOwner);
73+
erc20 = new FakeERC20("URORiif", "UROR");
74+
erc20.mint(originalOwner, 1_000_000 ether);
75+
76+
IIPToken tokenContract = tokenizer.attachIpt(1, agreementCid, "", erc20);
77+
78+
assertEq(tokenContract.balanceOf(originalOwner), 1_000_000 ether);
79+
assertNotEq(address(tokenizer.synthesized(1)), address(erc20)); // the synthesized member tracks the wrapped ipt
80+
assertEq(tokenContract.totalIssued(), 1_000_000 ether);
81+
assertEq(tokenContract.name(), "URORiif");
7382
}
7483
}

0 commit comments

Comments
 (0)