-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.sol
180 lines (146 loc) · 5.86 KB
/
user.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import { IDiamondCut } from "./interfaces/IDiamondCut.sol";
import { IDiamondLoupe } from "./interfaces/IDiamondLoupe.sol";
import { IOwnershipFacet } from "./interfaces/IOwnershipFacet.sol";
import { IRewardToken } from "./interfaces/IRewardToken.sol";
import { IUtils } from "./interfaces/IUtils.sol";
import { IFactory } from "./interfaces/IFactory.sol";
import { IGrowing } from "./interfaces/IGrowing.sol";
import { IRobotMarket } from "./interfaces/IRobotMarket.sol";
import { IFighting } from "./interfaces/IFighting.sol";
/**
* @title Example of a user
*/
contract User {
// The contract of the game (DiamondRobots)
address public immutable DR;
constructor(address _DR) {
DR = _DR;
}
/**
* @dev Returns the address of the owner of DR
*/
function owner() external view returns (address) {
return IOwnershipFacet(DR).owner();
}
/**
* @dev Try to transfer the ownership of the game
* @notice Should revert if EOA is not the owner of the game
*/
function tryToTransferOwnership(address _newOwner) external {
IOwnershipFacet(DR).transferOwnership(_newOwner);
}
/**
* @dev Returns the address of the facet,
* that has '_functionString' function
*/
function getFacet(string memory _functionString) external view returns (address) {
bytes4 functionSelector = bytes4(keccak256(bytes(_functionString)));
return IDiamondLoupe(DR).facetAddress(functionSelector);
}
/**
* @dev try to withdraw as a user
*/
function tryToWithdraw() external {
IUtils(DR).withdraw();
}
function getMintingFeeInEth() public view returns (uint128) {
return IUtils(DR).getMintingFeeInEth();
}
function getMintingFeeInToken() public view returns (uint128) {
return IUtils(DR).getMintingFeeInToken();
}
function getCombiningFee() external view returns (uint128) {
return IUtils(DR).getCombiningFee();
}
function getMarketTax() external view returns (uint8) {
return IUtils(DR).getMarketTax();
}
function getRewardToken() public view returns (address) {
return IUtils(DR).getRewardToken();
}
function getNFT() public view returns (address) {
return IUtils(DR).getNFT();
}
function transferNFT(address _to, uint256 _robotId) external {
IERC721(getNFT()).transferFrom(address(this), _to, _robotId);
}
/**
* @dev Try to set 'MintingFeeInEth' as a user
*/
function tryToSetMintingFeeInEth(uint128 _newFee) public {
IUtils(DR).setMintingFeeInEth(_newFee);
}
/**
* @dev Try to initialize the game again
*/
function tryToInitAgain(address diamondInit) external {
IDiamondCut.FacetCut[] memory cuts = new IDiamondCut.FacetCut[](0);
bytes memory callInit = abi.encodeWithSignature("init(address,address)", address(0), address(0));
IDiamondCut(DR).diamondCut(cuts, diamondInit, callInit);
}
function mintRobotWithEth() external payable returns (uint256) {
return IFactory(DR).mintRobotWithEth{value: msg.value}();
}
/**
* @dev Mint a robot by directly sending eth to the game
*/
function mintRobotBySendingEth() external payable {
(bool sent,) = DR.call{value: msg.value}("");
require(sent, "Couldn't mint!");
}
function approveRewardTokenToDR() external {
IRewardToken(getRewardToken()).approve(DR, type(uint256).max);
}
/**
* @dev Different functions to interact with the game
*/
function mintRobotWithToken() external returns (uint256) {
return IFactory(DR).mintRobotWithToken();
}
function combineRobots(uint256 _robotId1, uint256 _robotId2) external returns (uint256) {
IERC721(getNFT()).approve(DR, _robotId1);
IERC721(getNFT()).approve(DR, _robotId2);
return IGrowing(DR).combineRobots(_robotId1, _robotId2);
}
function multiplyRobots(uint256 _robotId1, uint256 _robotId2) external returns (uint256) {
return IGrowing(DR).multiplyRobots(_robotId1, _robotId2);
}
function putOnMarket(uint256 _robotId, uint256 _price) external {
IERC721(getNFT()).approve(DR, _robotId);
IRobotMarket(DR).putOnMarket(_robotId, _price);
}
function withdrawFromMarket(uint256 _robotId) external {
IRobotMarket(DR).withdrawFromMarket(_robotId);
}
function buyRobot(uint256 _robotId) external {
IRobotMarket(DR).buyRobot(_robotId);
}
function putOnAuction(uint256 _robotId, uint256 _startingPrice, uint32 _auctionTime) external {
IERC721(getNFT()).approve(DR, _robotId);
IRobotMarket(DR).putOnAuction(_robotId, _startingPrice, _auctionTime);
}
function withdrawFromAuction(uint256 _robotId) external {
IRobotMarket(DR).withdrawFromAuction(_robotId);
}
function bidOnAuction(uint256 _robotId, uint256 _bid) external {
IRobotMarket(DR).bidOnAuction(_robotId, _bid);
}
function endAuction(uint256 _robotId) external {
IRobotMarket(DR).endAuction(_robotId);
}
function getAuction(uint256 _robotId) external view returns (IRobotMarket.Auction memory) {
return IRobotMarket(DR).getAuction(_robotId);
}
function createArena(uint256 _robotId) external returns (uint128) {
return IFighting(DR).createArena(_robotId);
}
function removeArena(uint128 _arenaId) external {
IFighting(DR).removeArena(_arenaId);
}
function enterArena(uint128 _arenaId, uint256 _attackerRobotId) external {
IFighting(DR).enterArena(_arenaId, _attackerRobotId);
}
}