什么是MSG乌托邦理想国NFT系统
MSG乌托邦理想国NFT系统是专为数字艺术家和数字货币爱好者打造的一个去中心化的NFT交易系统。
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";import "@openzeppelin/contracts/utils/math/SafeMath.sol";
contract IDOStakingContract {
using SafeMath for uint256; IERC20 public token1; IERC20 public token2;
struct User {
uint256 amount1;
uint256 amount2;
uint256 rewardDebt;
}
mapping (address => User) public users;
uint256 public totalAmount1;
uint256 public totalAmount2;
uint256 public rewardPerToken;
constructor(IERC20 _token1, IERC20 _token2) {
token1 = _token1;
token2 = _token2;
}
function stake(uint256 _amount1, uint256 _amount2) external {
require(_amount1 > 0 && _amount2 > 0, "Amounts must be greater than 0");
token1.transferFrom(msg.sender, address(this), _amount1);
token2.transferFrom(msg.sender, address(this), _amount2);
users[msg.sender].amount1 = _amount1;
users[msg.sender].amount2 = _amount2;
totalAmount1 = totalAmount1.add(_amount1);
totalAmount2 = totalAmount2.add(_amount2);
if (totalAmount1 > 0 && totalAmount2 > 0) {
uint256 reward = token1.balanceOf(address(this));
rewardPerToken = reward.div(totalAmount1).div(totalAmount2);
}
users[msg.sender].rewardDebt = rewardPerToken;
}
function withdraw() external {
require(users[msg.sender].amount1 > 0 && users[msg.sender].amount2 > 0,
"Nothing staked");
uint256 amount1 = users[msg.sender].amount1;
uint256 amount2 = users[msg.sender].amount2;
token