I have been trying to compile my smart contract but I keep on getting this error. I know this is related to ^0.8.0 version of solidity but I don’t really know how to fix it.
Here’s my code for the same:
contract BattleBetting {
using ABDKMath64x64 for int128;
using ABDKMath64x64 for uint256;
enum BattleType { Memecoin, CryptoInfluencer, Sports }
struct Battle {
address creator;
BattleType battleType;
uint256 minBet;
uint256 totalBetAmount;
uint256 startTime;
uint256 endTime;
bool isLive;
bool isFinalized;
uint256 opponent1Bets;
uint256 opponent2Bets;
uint256 opponent1StartValue;
uint256 opponent2StartValue;
mapping(address => uint8) opponentChoice;
string opponent1; // direct storage of names instead of addresses
string opponent2;
address[] bettors; // array to keep track of bettors
mapping(address => uint256) bets; // mapping to keep track of each user's bet
}
//.... some other logic
function finalizeBattle(
uint256 _battleId,
uint256 _opponent1EndValue,
uint256 _opponent2EndValue,
bool _sportsWinner
) public {
Battle storage battle = battles[_battleId];
require(block.timestamp >= battle.endTime, "Battle duration has not ended yet.");
require(!battle.isFinalized, "Battle is already finalized.");
require(battle.isLive, "Battle did not go live.");
uint256 winnerBetAmount;
uint256 loserBetAmount;
address winner;
if (battle.battleType == BattleType.Memecoin) {
// Determine winner by percentage change
uint256 opponent1Change = (_opponent1EndValue * 100) / battle.opponent1StartValue;
uint256 opponent2Change = (_opponent2EndValue * 100) / battle.opponent2StartValue;
if (opponent1Change > opponent2Change) {
winnerBetAmount = battle.opponent1Bets;
loserBetAmount = battle.opponent2Bets;
winner = battle.opponent1; // This line gives the error
} else {
winnerBetAmount = battle.opponent2Bets;
loserBetAmount = battle.opponent1Bets;
winner = battle.opponent2; // This line gives the error too
}
I was expecting this to be compiled but I don’t know how I can fix this code. Any suggestions would be helpful in this case. Thanking you all in advance.