Skip to content

Commit b44895e

Browse files
authored
Create CatCoinGenerator.sol
```solidity // SPDX-License-Identifier: MIT pragma solidity ^0.8.17; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; import "@openzeppelin/contracts/utils/math/SafeMath.sol"; /** * @title CatCoinGenerator * @dev Creates different types of CAT COIN variants with feline-themed properties */ contract CatCoinGenerator is Ownable, ReentrancyGuard { using SafeMath for uint256; // Cat breed types for variant characteristics enum CatBreed { PERSIAN, // Luxury variant with high value SIAMESE, // Fast transactions MAINE_COON, // Large block size SPHYNX, // Minimal/lightweight RAGDOLL, // Flexible/adaptable BENGAL, // High performance/aggressive mining MUNCHKIN // Small but mighty (micro transactions) } struct CatCoinVariant { address tokenAddress; string name; string symbol; uint256 maxSupply; uint256 blockReward; uint256 halvingInterval; uint256 difficulty; bool isPrivate; bool hasStaking; CatBreed breed; string catPowerFeature; // Special feature based on cat breed } CatCoinVariant[] public catCoins; mapping(address => CatCoinVariant[]) public creatorCoins; mapping(CatBreed => uint256) public breedMiningBonus; event CatCoinCreated( address indexed tokenAddress, string name, CatBreed breed, address indexed creator ); event CatPowerActivated( address indexed tokenAddress, string catPowerFeature, uint256 timestamp ); constructor() { // Initialize breed mining bonuses breedMiningBonus[CatBreed.PERSIAN] = 20; // 20% bonus breedMiningBonus[CatBreed.SIAMESE] = 15; // 15% bonus breedMiningBonus[CatBreed.MAINE_COON] = 25; // 25% bonus breedMiningBonus[CatBreed.SPHYNX] = 10; // 10% bonus breedMiningBonus[CatBreed.RAGDOLL] = 18; // 18% bonus breedMiningBonus[CatBreed.BENGAL] = 30; // 30% bonus breedMiningBonus[CatBreed.MUNCHKIN] = 12; // 12% bonus } contract CatCoinToken is ERC20, Ownable, ReentrancyGuard { using SafeMath for uint256; uint256 public maxSupply; uint256 public currentSupply; uint256 public blockReward; uint256 public halvingInterval; uint256 public difficulty; uint256 public lastHalvingBlock; bool public isPrivate; bool public hasStaking; CatBreed public breed; // Staking variables mapping(address => uint256) public stakedAmount; mapping(address => uint256) public stakingStart; uint256 public totalStaked; uint256 public stakingRewardRate = 5; // 5% annual return // Cat Power special features uint256 public catPowerCooldown; mapping(address => uint256) public lastCatPowerUse; constructor( string memory _name, string memory _symbol, uint256 _maxSupply, uint256 _blockReward, uint256 _halvingInterval, uint256 _difficulty, bool _isPrivate, bool _hasStaking, CatBreed _breed ) ERC20(_name, _symbol) { maxSupply = _maxSupply; blockReward = _blockReward; halvingInterval = _halvingInterval; difficulty = _difficulty; isPrivate = _isPrivate; hasStaking = _hasStaking; breed = _breed; lastHalvingBlock = block.number; // Set Cat Power cooldown based on breed if (breed == CatBreed.SIAMESE) { catPowerCooldown = 1 hours; } else if (breed == CatBreed.BENGAL) { catPowerCooldown = 4 hours; } else { catPowerCooldown = 12 hours; } } // Staking functions function stake(uint256 amount) external nonReentrant { require(hasStaking, "Staking not enabled"); require(amount > 0, "Cannot stake 0"); require(balanceOf(msg.sender) >= amount, "Insufficient balance"); if (stakedAmount[msg.sender] > 0) { claimStakingRewards(); } _transfer(msg.sender, address(this), amount); stakedAmount[msg.sender] = stakedAmount[msg.sender].add(amount); stakingStart[msg.sender] = block.timestamp; totalStaked = totalStaked.add(amount); } function unstake() external nonReentrant { require(stakedAmount[msg.sender] > 0, "No stakes found"); claimStakingRewards(); uint256 amount = stakedAmount[msg.sender]; stakedAmount[msg.sender] = 0; totalStaked = totalStaked.sub(amount); _transfer(address(this), msg.sender, amount); } function claimStakingRewards() public { require(stakedAmount[msg.sender] > 0, "No stakes found"); uint256 reward = calculateStakingReward(msg.sender); if (reward > 0) { _mint(msg.sender, reward); stakingStart[msg.sender] = block.timestamp; } } function calculateStakingReward(address staker) public view returns (uint256) { uint256 stakingDuration = block.timestamp.sub(stakingStart[staker]); return stakedAmount[staker] .mul(stakingRewardRate) .mul(stakingDuration) .div(365 days) .div(100); } // Cat Power special abilities based on breed function activateCatPower() external nonReentrant { require(block.timestamp >= lastCatPowerUse[msg.sender].add(catPowerCooldown), "Cat Power in cooldown"); if (breed == CatBreed.PERSIAN) { // Luxury bonus: Temporary increase in mining rewards blockReward = blockReward.mul(2); // Reset after 1 hour blockReward = blockReward.div(2); } else if (breed == CatBreed.BENGAL) { // Aggressive mining: Temporary difficulty reduction difficulty = difficulty.mul(7).div(10); // Reset after 30 minutes difficulty = difficulty.mul(10).div(7); } else if (breed == CatBreed.MAINE_COON) { // Large block bonus: Double transactions per block temporarily // Implementation would depend on specific requirements } lastCatPowerUse[msg.sender] = block.timestamp; } // Mining with breed bonus function mine(uint256 nonce) external nonReentrant { require(currentSupply < maxSupply, "Max supply reached"); require(verifyPoW(nonce), "Invalid proof of work"); uint256 reward = calculateReward(); // Apply breed bonus reward = reward.mul(100 + breedMiningBonus[breed]).div(100); require(currentSupply.add(reward) <= maxSupply, "Would exceed max supply"); _mint(msg.sender, reward); currentSupply = currentSupply.add(reward); adjustDifficulty(); } // Additional helper functions remain the same as in the previous implementation // ... (verifyPoW, calculateReward, adjustDifficulty) } function createCatCoin( string memory name, string memory symbol, uint256 maxSupply, uint256 blockReward, uint256 halvingInterval, uint256 initialDifficulty, bool isPrivate, bool hasStaking, CatBreed breed ) external nonReentrant returns (address) { string memory catPowerFeature = getCatPowerFeature(breed); CatCoinToken newToken = new CatCoinToken( name, symbol, maxSupply, blockReward, halvingInterval, initialDifficulty, isPrivate, hasStaking, breed ); CatCoinVariant memory variant = CatCoinVariant({ tokenAddress: address(newToken), name: name, symbol: symbol, maxSupply: maxSupply, blockReward: blockReward, halvingInterval: halvingInterval, difficulty: initialDifficulty, isPrivate: isPrivate, hasStaking: hasStaking, breed: breed, catPowerFeature: catPowerFeature }); catCoins.push(variant); creatorCoins[msg.sender].push(variant); emit CatCoinCreated(address(newToken), name, breed, msg.sender); return address(newToken); } // Predefined CAT COIN variants function createPersianCatCoin() external returns (address) { return createCatCoin( "Persian CAT COIN", "PCAT", 21000000 * 10**18, 100 * 10**18, 210000, 1, true, true, CatBreed.PERSIAN ); } function createBengalCatCoin() external returns (address) { return createCatCoin( "Bengal CAT COIN", "BCAT", 50000000 * 10**18, 200 * 10**18, 100000, 1, false, true, CatBreed.BENGAL ); } function createSiameseCatCoin() external returns (address) { return createCatCoin( "Siamese CAT COIN", "SCAT", 30000000 * 10**18, 150 * 10**18, 150000, 1, false, true, CatBreed.SIAMESE ); } function getCatPowerFeature(CatBreed breed) internal pure returns (string memory) { if (breed == CatBreed.PERSIAN) return "Luxury Mining Bonus"; if (breed == CatBreed.SIAMESE) return "Speed Boost"; if (breed == CatBreed.MAINE_COON) return "Block Size Increase"; if (breed == CatBreed.SPHYNX) return "Lightweight Transactions"; if (breed == CatBreed.RAGDOLL) return "Adaptive Difficulty"; if (breed == CatBreed.BENGAL) return "Aggressive Mining"; if (breed == CatBreed.MUNCHKIN) return "Micro Transaction Boost"; return "Standard Cat Power"; } // View functions function getTotalCatCoins() external view returns (uint256) { return catCoins.length; } function getCreatorCatCoins(address creator) external view returns (CatCoinVariant[] memory) { return creatorCoins[creator]; } } ```
1 parent 3052321 commit b44895e

File tree

1 file changed

+321
-0
lines changed

1 file changed

+321
-0
lines changed

App/contracts/CatCoinGenerator.sol

Lines changed: 321 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,321 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.17;
3+
4+
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
5+
import "@openzeppelin/contracts/access/Ownable.sol";
6+
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
7+
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
8+
9+
/**
10+
* @title CatCoinGenerator
11+
* @dev Creates different types of CAT COIN variants with feline-themed properties
12+
*/
13+
contract CatCoinGenerator is Ownable, ReentrancyGuard {
14+
using SafeMath for uint256;
15+
16+
// Cat breed types for variant characteristics
17+
enum CatBreed {
18+
PERSIAN, // Luxury variant with high value
19+
SIAMESE, // Fast transactions
20+
MAINE_COON, // Large block size
21+
SPHYNX, // Minimal/lightweight
22+
RAGDOLL, // Flexible/adaptable
23+
BENGAL, // High performance/aggressive mining
24+
MUNCHKIN // Small but mighty (micro transactions)
25+
}
26+
27+
struct CatCoinVariant {
28+
address tokenAddress;
29+
string name;
30+
string symbol;
31+
uint256 maxSupply;
32+
uint256 blockReward;
33+
uint256 halvingInterval;
34+
uint256 difficulty;
35+
bool isPrivate;
36+
bool hasStaking;
37+
CatBreed breed;
38+
string catPowerFeature; // Special feature based on cat breed
39+
}
40+
41+
CatCoinVariant[] public catCoins;
42+
mapping(address => CatCoinVariant[]) public creatorCoins;
43+
mapping(CatBreed => uint256) public breedMiningBonus;
44+
45+
event CatCoinCreated(
46+
address indexed tokenAddress,
47+
string name,
48+
CatBreed breed,
49+
address indexed creator
50+
);
51+
52+
event CatPowerActivated(
53+
address indexed tokenAddress,
54+
string catPowerFeature,
55+
uint256 timestamp
56+
);
57+
58+
constructor() {
59+
// Initialize breed mining bonuses
60+
breedMiningBonus[CatBreed.PERSIAN] = 20; // 20% bonus
61+
breedMiningBonus[CatBreed.SIAMESE] = 15; // 15% bonus
62+
breedMiningBonus[CatBreed.MAINE_COON] = 25; // 25% bonus
63+
breedMiningBonus[CatBreed.SPHYNX] = 10; // 10% bonus
64+
breedMiningBonus[CatBreed.RAGDOLL] = 18; // 18% bonus
65+
breedMiningBonus[CatBreed.BENGAL] = 30; // 30% bonus
66+
breedMiningBonus[CatBreed.MUNCHKIN] = 12; // 12% bonus
67+
}
68+
69+
contract CatCoinToken is ERC20, Ownable, ReentrancyGuard {
70+
using SafeMath for uint256;
71+
72+
uint256 public maxSupply;
73+
uint256 public currentSupply;
74+
uint256 public blockReward;
75+
uint256 public halvingInterval;
76+
uint256 public difficulty;
77+
uint256 public lastHalvingBlock;
78+
bool public isPrivate;
79+
bool public hasStaking;
80+
CatBreed public breed;
81+
82+
// Staking variables
83+
mapping(address => uint256) public stakedAmount;
84+
mapping(address => uint256) public stakingStart;
85+
uint256 public totalStaked;
86+
uint256 public stakingRewardRate = 5; // 5% annual return
87+
88+
// Cat Power special features
89+
uint256 public catPowerCooldown;
90+
mapping(address => uint256) public lastCatPowerUse;
91+
92+
constructor(
93+
string memory _name,
94+
string memory _symbol,
95+
uint256 _maxSupply,
96+
uint256 _blockReward,
97+
uint256 _halvingInterval,
98+
uint256 _difficulty,
99+
bool _isPrivate,
100+
bool _hasStaking,
101+
CatBreed _breed
102+
) ERC20(_name, _symbol) {
103+
maxSupply = _maxSupply;
104+
blockReward = _blockReward;
105+
halvingInterval = _halvingInterval;
106+
difficulty = _difficulty;
107+
isPrivate = _isPrivate;
108+
hasStaking = _hasStaking;
109+
breed = _breed;
110+
lastHalvingBlock = block.number;
111+
112+
// Set Cat Power cooldown based on breed
113+
if (breed == CatBreed.SIAMESE) {
114+
catPowerCooldown = 1 hours;
115+
} else if (breed == CatBreed.BENGAL) {
116+
catPowerCooldown = 4 hours;
117+
} else {
118+
catPowerCooldown = 12 hours;
119+
}
120+
}
121+
122+
// Staking functions
123+
function stake(uint256 amount) external nonReentrant {
124+
require(hasStaking, "Staking not enabled");
125+
require(amount > 0, "Cannot stake 0");
126+
require(balanceOf(msg.sender) >= amount, "Insufficient balance");
127+
128+
if (stakedAmount[msg.sender] > 0) {
129+
claimStakingRewards();
130+
}
131+
132+
_transfer(msg.sender, address(this), amount);
133+
stakedAmount[msg.sender] = stakedAmount[msg.sender].add(amount);
134+
stakingStart[msg.sender] = block.timestamp;
135+
totalStaked = totalStaked.add(amount);
136+
}
137+
138+
function unstake() external nonReentrant {
139+
require(stakedAmount[msg.sender] > 0, "No stakes found");
140+
141+
claimStakingRewards();
142+
uint256 amount = stakedAmount[msg.sender];
143+
stakedAmount[msg.sender] = 0;
144+
totalStaked = totalStaked.sub(amount);
145+
_transfer(address(this), msg.sender, amount);
146+
}
147+
148+
function claimStakingRewards() public {
149+
require(stakedAmount[msg.sender] > 0, "No stakes found");
150+
151+
uint256 reward = calculateStakingReward(msg.sender);
152+
if (reward > 0) {
153+
_mint(msg.sender, reward);
154+
stakingStart[msg.sender] = block.timestamp;
155+
}
156+
}
157+
158+
function calculateStakingReward(address staker) public view returns (uint256) {
159+
uint256 stakingDuration = block.timestamp.sub(stakingStart[staker]);
160+
return stakedAmount[staker]
161+
.mul(stakingRewardRate)
162+
.mul(stakingDuration)
163+
.div(365 days)
164+
.div(100);
165+
}
166+
167+
// Cat Power special abilities based on breed
168+
function activateCatPower() external nonReentrant {
169+
require(block.timestamp >= lastCatPowerUse[msg.sender].add(catPowerCooldown),
170+
"Cat Power in cooldown");
171+
172+
if (breed == CatBreed.PERSIAN) {
173+
// Luxury bonus: Temporary increase in mining rewards
174+
blockReward = blockReward.mul(2);
175+
// Reset after 1 hour
176+
blockReward = blockReward.div(2);
177+
}
178+
else if (breed == CatBreed.BENGAL) {
179+
// Aggressive mining: Temporary difficulty reduction
180+
difficulty = difficulty.mul(7).div(10);
181+
// Reset after 30 minutes
182+
difficulty = difficulty.mul(10).div(7);
183+
}
184+
else if (breed == CatBreed.MAINE_COON) {
185+
// Large block bonus: Double transactions per block temporarily
186+
// Implementation would depend on specific requirements
187+
}
188+
189+
lastCatPowerUse[msg.sender] = block.timestamp;
190+
}
191+
192+
// Mining with breed bonus
193+
function mine(uint256 nonce) external nonReentrant {
194+
require(currentSupply < maxSupply, "Max supply reached");
195+
require(verifyPoW(nonce), "Invalid proof of work");
196+
197+
uint256 reward = calculateReward();
198+
199+
// Apply breed bonus
200+
reward = reward.mul(100 + breedMiningBonus[breed]).div(100);
201+
202+
require(currentSupply.add(reward) <= maxSupply, "Would exceed max supply");
203+
_mint(msg.sender, reward);
204+
currentSupply = currentSupply.add(reward);
205+
206+
adjustDifficulty();
207+
}
208+
209+
// Additional helper functions remain the same as in the previous implementation
210+
// ... (verifyPoW, calculateReward, adjustDifficulty)
211+
}
212+
213+
function createCatCoin(
214+
string memory name,
215+
string memory symbol,
216+
uint256 maxSupply,
217+
uint256 blockReward,
218+
uint256 halvingInterval,
219+
uint256 initialDifficulty,
220+
bool isPrivate,
221+
bool hasStaking,
222+
CatBreed breed
223+
) external nonReentrant returns (address) {
224+
string memory catPowerFeature = getCatPowerFeature(breed);
225+
226+
CatCoinToken newToken = new CatCoinToken(
227+
name,
228+
symbol,
229+
maxSupply,
230+
blockReward,
231+
halvingInterval,
232+
initialDifficulty,
233+
isPrivate,
234+
hasStaking,
235+
breed
236+
);
237+
238+
CatCoinVariant memory variant = CatCoinVariant({
239+
tokenAddress: address(newToken),
240+
name: name,
241+
symbol: symbol,
242+
maxSupply: maxSupply,
243+
blockReward: blockReward,
244+
halvingInterval: halvingInterval,
245+
difficulty: initialDifficulty,
246+
isPrivate: isPrivate,
247+
hasStaking: hasStaking,
248+
breed: breed,
249+
catPowerFeature: catPowerFeature
250+
});
251+
252+
catCoins.push(variant);
253+
creatorCoins[msg.sender].push(variant);
254+
255+
emit CatCoinCreated(address(newToken), name, breed, msg.sender);
256+
return address(newToken);
257+
}
258+
259+
// Predefined CAT COIN variants
260+
function createPersianCatCoin() external returns (address) {
261+
return createCatCoin(
262+
"Persian CAT COIN",
263+
"PCAT",
264+
21000000 * 10**18,
265+
100 * 10**18,
266+
210000,
267+
1,
268+
true,
269+
true,
270+
CatBreed.PERSIAN
271+
);
272+
}
273+
274+
function createBengalCatCoin() external returns (address) {
275+
return createCatCoin(
276+
"Bengal CAT COIN",
277+
"BCAT",
278+
50000000 * 10**18,
279+
200 * 10**18,
280+
100000,
281+
1,
282+
false,
283+
true,
284+
CatBreed.BENGAL
285+
);
286+
}
287+
288+
function createSiameseCatCoin() external returns (address) {
289+
return createCatCoin(
290+
"Siamese CAT COIN",
291+
"SCAT",
292+
30000000 * 10**18,
293+
150 * 10**18,
294+
150000,
295+
1,
296+
false,
297+
true,
298+
CatBreed.SIAMESE
299+
);
300+
}
301+
302+
function getCatPowerFeature(CatBreed breed) internal pure returns (string memory) {
303+
if (breed == CatBreed.PERSIAN) return "Luxury Mining Bonus";
304+
if (breed == CatBreed.SIAMESE) return "Speed Boost";
305+
if (breed == CatBreed.MAINE_COON) return "Block Size Increase";
306+
if (breed == CatBreed.SPHYNX) return "Lightweight Transactions";
307+
if (breed == CatBreed.RAGDOLL) return "Adaptive Difficulty";
308+
if (breed == CatBreed.BENGAL) return "Aggressive Mining";
309+
if (breed == CatBreed.MUNCHKIN) return "Micro Transaction Boost";
310+
return "Standard Cat Power";
311+
}
312+
313+
// View functions
314+
function getTotalCatCoins() external view returns (uint256) {
315+
return catCoins.length;
316+
}
317+
318+
function getCreatorCatCoins(address creator) external view returns (CatCoinVariant[] memory) {
319+
return creatorCoins[creator];
320+
}
321+
}

0 commit comments

Comments
 (0)