11// SPDX-License-Identifier: MIT
22pragma solidity 0.8.18 ;
33
4- import { ERC20Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol " ;
5- import { ERC20BurnableUpgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20BurnableUpgradeable.sol " ;
6- import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol " ;
7- import { Strings } from "@openzeppelin/contracts/utils/Strings.sol " ;
8- import { Base64 } from "@openzeppelin/contracts/utils/Base64.sol " ;
9- import { Tokenizer, MustControlIpnft } from "./Tokenizer.sol " ;
104import { IControlIPTs } from "./IControlIPTs.sol " ;
115import { IIPToken, Metadata } from "./IIPToken.sol " ;
6+ import { MustControlIpnft, Tokenizer } from "./Tokenizer.sol " ;
7+ import { IPTokenUtils } from "./libraries/IPTokenUtils.sol " ;
8+ import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol " ;
9+ import { ERC20Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol " ;
10+ import { ERC20BurnableUpgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20BurnableUpgradeable.sol " ;
1211
1312error TokenCapped ();
1413
@@ -51,32 +50,53 @@ contract IPToken is IIPToken, ERC20Upgradeable, ERC20BurnableUpgradeable, Ownabl
5150 _;
5251 }
5352
54- function metadata () external view returns (Metadata memory ) {
53+ function metadata () external view override returns (Metadata memory ) {
5554 return _metadata;
5655 }
5756
58- function balanceOf (address account ) public view override (ERC20Upgradeable , IIPToken) returns (uint256 ) {
57+ // Override ERC20 functions to resolve diamond inheritance
58+ function totalSupply () public view override returns (uint256 ) {
59+ return ERC20Upgradeable .totalSupply ();
60+ }
61+
62+ function balanceOf (address account ) public view override returns (uint256 ) {
5963 return ERC20Upgradeable .balanceOf (account);
6064 }
6165
62- function name () public view override (ERC20Upgradeable , IIPToken) returns (string memory ) {
66+ function transfer (address to , uint256 amount ) public override returns (bool ) {
67+ return ERC20Upgradeable .transfer (to, amount);
68+ }
69+
70+ function allowance (address owner , address spender ) public view override returns (uint256 ) {
71+ return ERC20Upgradeable .allowance (owner, spender);
72+ }
73+
74+ function approve (address spender , uint256 amount ) public override returns (bool ) {
75+ return ERC20Upgradeable .approve (spender, amount);
76+ }
77+
78+ function transferFrom (address from , address to , uint256 amount ) public override returns (bool ) {
79+ return ERC20Upgradeable .transferFrom (from, to, amount);
80+ }
81+
82+ function name () public view override returns (string memory ) {
6383 return ERC20Upgradeable .name ();
6484 }
6585
66- function symbol () public view override ( ERC20Upgradeable , IIPToken) returns (string memory ) {
86+ function symbol () public view override returns (string memory ) {
6787 return ERC20Upgradeable .symbol ();
6888 }
6989
70- function decimals () public view override ( ERC20Upgradeable , IIPToken) returns (uint8 ) {
90+ function decimals () public view override returns (uint8 ) {
7191 return ERC20Upgradeable .decimals ();
7292 }
93+
7394 /**
7495 * @notice the supply of IP Tokens is controlled by the tokenizer contract.
7596 * @param receiver address
7697 * @param amount uint256
7798 */
78-
79- function issue (address receiver , uint256 amount ) external onlyTokenizerOrIPNFTController {
99+ function issue (address receiver , uint256 amount ) external override onlyTokenizerOrIPNFTController {
80100 if (capped) {
81101 revert TokenCapped ();
82102 }
@@ -87,7 +107,7 @@ contract IPToken is IIPToken, ERC20Upgradeable, ERC20BurnableUpgradeable, Ownabl
87107 /**
88108 * @notice mark this token as capped. After calling this, no new tokens can be `issue`d
89109 */
90- function cap () external onlyTokenizerOrIPNFTController {
110+ function cap () external override onlyTokenizerOrIPNFTController {
91111 capped = true ;
92112 emit Capped (totalIssued);
93113 }
@@ -96,37 +116,7 @@ contract IPToken is IIPToken, ERC20Upgradeable, ERC20BurnableUpgradeable, Ownabl
96116 * @notice contract metadata, compatible to ERC1155
97117 * @return string base64 encoded data url
98118 */
99- function uri () external view returns (string memory ) {
100- string memory tokenId = Strings.toString (_metadata.ipnftId);
101-
102- string memory props = string .concat (
103- '"properties": { ' ,
104- '"ipnft_id": ' ,
105- tokenId,
106- ',"agreement_content": "ipfs:// ' ,
107- _metadata.agreementCid,
108- '","original_owner": " ' ,
109- Strings.toHexString (_metadata.originalOwner),
110- '","erc20_contract": " ' ,
111- Strings.toHexString (address (this )),
112- '","supply": " ' ,
113- Strings.toString (totalIssued),
114- '"} '
115- );
116-
117- return string .concat (
118- "data:application/json;base64, " ,
119- Base64.encode (
120- bytes (
121- string .concat (
122- '{"name": "IP Tokens of IPNFT # ' ,
123- tokenId,
124- '","description": "IP Tokens, derived from IP-NFTs, are ERC-20 tokens governing IP pools.","decimals": 18,"external_url": "https://molecule.xyz","image": "", ' ,
125- props,
126- "} "
127- )
128- )
129- )
130- );
119+ function uri () external view override returns (string memory ) {
120+ return IPTokenUtils.generateURI (_metadata, address (this ), totalIssued);
131121 }
132122}
0 commit comments