Skip to content

Commit f4cbed0

Browse files
committed
changed logic in claim function
1 parent 424babf commit f4cbed0

File tree

6 files changed

+284
-30
lines changed

6 files changed

+284
-30
lines changed

broadcast/DeployV2.s.sol/11155111/run-1753815054.json

Lines changed: 72 additions & 0 deletions
Large diffs are not rendered by default.

broadcast/DeployV2.s.sol/11155111/run-1753816864.json

Lines changed: 72 additions & 0 deletions
Large diffs are not rendered by default.

broadcast/DeployV2.s.sol/11155111/run-latest.json

Lines changed: 72 additions & 0 deletions
Large diffs are not rendered by default.

src/Core/BetManager.sol

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -256,24 +256,42 @@ contract BetManager is IBetManager, Ownable, Pausable, ReentrancyGuardTransient
256256

257257
// Round valid, claim rewards
258258
if (rounds[_roundIds[i]].priceUpdated) {
259-
require(claimable(_roundIds[i], msg.sender), "Not eligible for claim");
260-
Round memory round = rounds[_roundIds[i]];
261-
if (ledger[_roundIds[i]][msg.sender].isPromoBet) {
262-
addedReward = (ledger[_roundIds[i]][msg.sender].amount * round.rewardAmount)
263-
/ round.rewardBaseAmount
264-
+ (
265-
(ledger[_roundIds[i]][msg.sender].amount * round.rewardAmount) / round.rewardBaseAmount
266-
- ledger[_roundIds[i]][msg.sender].amount
267-
) * PROMO_AMOUNT / 10000;
259+
if (claimable(_roundIds[i], msg.sender)) {
260+
Round memory round = rounds[_roundIds[i]];
261+
if (ledger[_roundIds[i]][msg.sender].isPromoBet) {
262+
addedReward = (ledger[_roundIds[i]][msg.sender].amount * round.rewardAmount)
263+
/ round.rewardBaseAmount
264+
+ (
265+
(ledger[_roundIds[i]][msg.sender].amount * round.rewardAmount) / round.rewardBaseAmount
266+
- ledger[_roundIds[i]][msg.sender].amount
267+
) * PROMO_AMOUNT / 10000;
268+
} else {
269+
addedReward =
270+
(ledger[_roundIds[i]][msg.sender].amount * round.rewardAmount) / round.rewardBaseAmount;
271+
}
268272
} else {
269-
addedReward =
270-
(ledger[_roundIds[i]][msg.sender].amount * round.rewardAmount) / round.rewardBaseAmount;
273+
unchecked {
274+
if(roundIdsLength > ++i) {
275+
return;
276+
} else {
277+
continue;
278+
}
279+
}
271280
}
272281
}
273282
// Round invalid, refund bet amount
274283
else {
275-
require(refundable(_roundIds[i], msg.sender), "Not eligible for refund");
276-
addedReward = ledger[_roundIds[i]][msg.sender].amount;
284+
if (refundable(_roundIds[i], msg.sender)) {
285+
addedReward = ledger[_roundIds[i]][msg.sender].amount;
286+
} else {
287+
unchecked {
288+
if(roundIdsLength > ++i) {
289+
return;
290+
} else {
291+
continue;
292+
}
293+
}
294+
}
277295
}
278296

279297
ledger[_roundIds[i]][msg.sender].claimed = true;

src/Core/BetManagerV2.sol

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -235,24 +235,42 @@ contract BetManagerV2 is IBetManagerV2, Ownable, Pausable, ReentrancyGuardTransi
235235

236236
// Round valid, claim rewards
237237
if (rounds[_roundIds[i]].priceUpdated) {
238-
require(claimable(_roundIds[i], msg.sender), "Not eligible for claim");
239-
Round memory round = rounds[_roundIds[i]];
240-
if (ledger[_roundIds[i]][msg.sender].isPromoBet) {
241-
addedReward = (ledger[_roundIds[i]][msg.sender].amount * round.rewardAmount)
242-
/ round.rewardBaseAmount
243-
+ (
244-
(ledger[_roundIds[i]][msg.sender].amount * round.rewardAmount) / round.rewardBaseAmount
245-
- ledger[_roundIds[i]][msg.sender].amount
246-
) * PROMO_AMOUNT / 10000;
238+
if (claimable(_roundIds[i], msg.sender)) {
239+
Round memory round = rounds[_roundIds[i]];
240+
if (ledger[_roundIds[i]][msg.sender].isPromoBet) {
241+
addedReward = (ledger[_roundIds[i]][msg.sender].amount * round.rewardAmount)
242+
/ round.rewardBaseAmount
243+
+ (
244+
(ledger[_roundIds[i]][msg.sender].amount * round.rewardAmount) / round.rewardBaseAmount
245+
- ledger[_roundIds[i]][msg.sender].amount
246+
) * PROMO_AMOUNT / 10000;
247+
} else {
248+
addedReward =
249+
(ledger[_roundIds[i]][msg.sender].amount * round.rewardAmount) / round.rewardBaseAmount;
250+
}
247251
} else {
248-
addedReward =
249-
(ledger[_roundIds[i]][msg.sender].amount * round.rewardAmount) / round.rewardBaseAmount;
252+
unchecked {
253+
if(roundIdsLength > ++i) {
254+
return;
255+
} else {
256+
continue;
257+
}
258+
}
250259
}
251260
}
252261
// Round invalid, refund bet amount
253262
else {
254-
require(refundable(_roundIds[i], msg.sender), "Not eligible for refund");
255-
addedReward = ledger[_roundIds[i]][msg.sender].amount;
263+
if (refundable(_roundIds[i], msg.sender)) {
264+
addedReward = ledger[_roundIds[i]][msg.sender].amount;
265+
} else {
266+
unchecked {
267+
if(roundIdsLength > ++i) {
268+
return;
269+
} else {
270+
continue;
271+
}
272+
}
273+
}
256274
}
257275

258276
ledger[_roundIds[i]][msg.sender].claimed = true;
@@ -404,7 +422,7 @@ contract BetManagerV2 is IBetManagerV2, Ownable, Pausable, ReentrancyGuardTransi
404422
_startRound(currentRoundId);
405423
initialLock = true;
406424
}
407-
425+
408426
/**
409427
* @notice Update price using CEXes prices
410428
* @dev Callable by round manager

test/BetManagerTest.t.sol

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ contract BetManagerTest is Test {
183183
bet.claim(ids);
184184

185185
vm.prank(upBettor, upBettor);
186-
vm.expectRevert("Not eligible for claim");
186+
// vm.expectRevert("Not eligible for claim");
187187
bet.claim(ids);
188188

189189
// Round memory round = bet.rounds(currentRoundId);
@@ -306,9 +306,11 @@ contract BetManagerTest is Test {
306306

307307
vm.prank(upBettorSecond, upBettorSecond);
308308

309-
uint32[] memory ids = new uint32[](1);
310-
309+
uint32[] memory ids = new uint32[](5);
311310
ids[0] = cr;
311+
ids[1] = cr-1;
312+
ids[2] = cr-2;
313+
ids[3] = cr-3;
312314
bet.claim(ids);
313315

314316
uint256 balanceAfter = wUSDT.balanceOf(upBettorSecond);

0 commit comments

Comments
 (0)