Skip to content

Commit

Permalink
Merge pull request #29 from sushiswap/fix/improved-token-factory
Browse files Browse the repository at this point in the history
Fixes to make SocialToken more usable
  • Loading branch information
TheGreatHB committed Aug 24, 2021
2 parents d40802d + 73d4efc commit 40b63c9
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 8 deletions.
8 changes: 6 additions & 2 deletions contracts/SocialTokenV0.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ contract SocialTokenV0 is DividendPayingERC20, BaseExchange, OwnableInitializabl
address _owner,
string memory _name,
string memory _symbol,
address _dividendToken
address _dividendToken,
uint256 initialSupply
) external override initializer {
__Ownable_init(_owner);
__DividendPayingERC20_init(_name, _symbol, _dividendToken);
_factory = msg.sender;
_mint(_owner, initialSupply);

_CACHED_CHAIN_ID = block.chainid;
_DOMAIN_SEPARATOR = keccak256(
Expand Down Expand Up @@ -67,7 +69,9 @@ contract SocialTokenV0 is DividendPayingERC20, BaseExchange, OwnableInitializabl
_transfer(from, to, amount);
}

function mint(address account, uint256 value) external override onlyOwner {
function mint(address account, uint256 value) external override {
require(owner() == msg.sender || _factory == msg.sender, "SHOYU: FORBIDDEN");

_mint(account, value);
}

Expand Down
32 changes: 29 additions & 3 deletions contracts/TokenFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "@openzeppelin/contracts/access/Ownable.sol";
import "./interfaces/ITokenFactory.sol";
import "./interfaces/IBaseNFT721.sol";
import "./interfaces/IBaseNFT1155.sol";
import "./interfaces/ISocialToken.sol";
import "./base/ProxyFactory.sol";
import "./libraries/Signature.sol";

Expand All @@ -22,6 +23,9 @@ contract TokenFactory is ProxyFactory, Ownable, ITokenFactory {
// keccak256("MintBatch1155(address nft,address to,uint256[] tokenIds,uint256[] amounts,bytes data,uint256 nonce)");
bytes32 public constant override MINT_BATCH_1155_TYPEHASH =
0xb47ce0f6456fcc2f16b7d6e7b0255eb73822b401248e672a4543c2b3d7183043;
// keccak256("MintSocialToken(address token,address to,uint256 amount,uint256 nonce)");
bytes32 public constant override MINT_SOCIAL_TOKEN_TYPEHASH =
0x8f4bf92e5271f5ec2f59dc3fc74368af0064fb84b40a3de9150dd26c08cda104;
bytes32 internal immutable _DOMAIN_SEPARATOR;
uint256 internal immutable _CACHED_CHAIN_ID;

Expand Down Expand Up @@ -283,17 +287,25 @@ contract TokenFactory is ProxyFactory, Ownable, ITokenFactory {
address owner,
string memory name,
string memory symbol,
address dividendToken
address dividendToken,
uint256 initialSupply
) external override onlyDeployer returns (address proxy) {
require(bytes(name).length > 0, "SHOYU: INVALID_NAME");
require(bytes(symbol).length > 0, "SHOYU: INVALID_SYMBOL");
require(owner != address(0), "SHOYU: INVALID_ADDRESS");

bytes memory initData =
abi.encodeWithSignature("initialize(address,string,string,address)", owner, name, symbol, dividendToken);
abi.encodeWithSignature(
"initialize(address,string,string,address,uint256)",
owner,
name,
symbol,
dividendToken,
initialSupply
);
proxy = _createProxy(_targetsSocialToken[_targetsSocialToken.length - 1], initData);

emit DeploySocialToken(proxy, owner, name, symbol, dividendToken);
emit DeploySocialToken(proxy, owner, name, symbol, dividendToken, initialSupply);
}

function isSocialToken(address query) external view override returns (bool result) {
Expand Down Expand Up @@ -349,4 +361,18 @@ contract TokenFactory is ProxyFactory, Ownable, ITokenFactory {
Signature.verify(hash, owner, v, r, s, DOMAIN_SEPARATOR());
IBaseNFT1155(nft).mintBatch(to, tokenIds, amounts, data);
}

function mintSocialToken(
address token,
address to,
uint256 amount,
uint8 v,
bytes32 r,
bytes32 s
) external override {
address owner = ISocialToken(token).owner();
bytes32 hash = keccak256(abi.encode(MINT_SOCIAL_TOKEN_TYPEHASH, token, to, amount, nonces[owner]++));
Signature.verify(hash, owner, v, r, s, DOMAIN_SEPARATOR());
ISocialToken(token).mint(to, amount);
}
}
3 changes: 2 additions & 1 deletion contracts/interfaces/ISocialToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ interface ISocialToken is IDividendPayingERC20, IBaseExchange, IOwnable {
address owner,
string memory name,
string memory symbol,
address dividendToken
address dividendToken,
uint256 initialSupply
) external;

function mint(address account, uint256 value) external;
Expand Down
17 changes: 15 additions & 2 deletions contracts/interfaces/ITokenFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ interface ITokenFactory {
address indexed owner,
string name,
string symbol,
address indexed dividendToken
address indexed dividendToken,
uint256 initialSupply
);

function MAX_ROYALTY_FEE() external view returns (uint8);
Expand All @@ -52,6 +53,8 @@ interface ITokenFactory {

function MINT_BATCH_1155_TYPEHASH() external view returns (bytes32);

function MINT_SOCIAL_TOKEN_TYPEHASH() external view returns (bytes32);

function DOMAIN_SEPARATOR() external view returns (bytes32);

function nonces(address account) external view returns (uint256);
Expand Down Expand Up @@ -130,7 +133,8 @@ interface ITokenFactory {
address owner,
string memory name,
string memory symbol,
address dividendToken
address dividendToken,
uint256 initialSupply
) external returns (address proxy);

function isSocialToken(address query) external view returns (bool result);
Expand Down Expand Up @@ -163,4 +167,13 @@ interface ITokenFactory {
bytes32 r,
bytes32 s
) external;

function mintSocialToken(
address token,
address to,
uint256 amount,
uint8 v,
bytes32 r,
bytes32 s
) external;
}

0 comments on commit 40b63c9

Please sign in to comment.