Skip to content

Commit 11fe4d7

Browse files
committed
SwanDebate: add specific agent order
1 parent 62a1462 commit 11fe4d7

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/SwanDebate.sol

+15-5
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ contract SwanDebate is Ownable, Pausable {
8686
/// @notice Thrown when trying to use an unregistered agent
8787
error AgentNotRegistered();
8888

89+
/// @notice Thrown when an invalid number of proposals exist in a debate
90+
error InvalidProposalCount(uint256 count);
91+
8992
/*//////////////////////////////////////////////////////////////
9093
EVENTS
9194
//////////////////////////////////////////////////////////////*/
@@ -134,6 +137,8 @@ contract SwanDebate is Ownable, Pausable {
134137
struct Debate {
135138
uint256 agent1Id;
136139
uint256 agent2Id;
140+
uint256 agent1ProposalId;
141+
uint256 agent2ProposalId;
137142
uint256 currentRound;
138143
uint256 winnerId;
139144
mapping(uint256 => RoundData) rounds;
@@ -239,8 +244,15 @@ contract SwanDebate is Ownable, Pausable {
239244
revert ContestInvalidState(contest.state(), IJokeRaceContest.ContestState.Queued);
240245
}
241246

247+
uint256[] memory proposalIds = contest.getAllProposalIds();
248+
if (proposalIds.length != 2) {
249+
revert InvalidProposalCount(proposalIds.length);
250+
}
251+
242252
debate.agent1Id = _agent1Id;
243253
debate.agent2Id = _agent2Id;
254+
debate.agent1ProposalId = proposalIds[0];
255+
debate.agent2ProposalId = proposalIds[1];
244256
debate.currentRound = 1;
245257
debate.winnerId = 0;
246258

@@ -335,11 +347,9 @@ contract SwanDebate is Ownable, Pausable {
335347
// The last proposal in the sorted array has the highest votes
336348
uint256 winningProposal = sortedProposals[sortedProposals.length - 1];
337349

338-
// Get proposal IDs dynamically from JokeRace
339-
uint256[] memory proposalIds = contest.getAllProposalIds();
340-
341-
// Determine which agent corresponds to the winning proposal
342-
uint256 winnerId = (proposalIds[0] == winningProposal) ? debates[_contest].agent1Id : debates[_contest].agent2Id;
350+
uint256 winnerId = (debates[_contest].agent1ProposalId == winningProposal)
351+
? debates[_contest].agent1Id
352+
: debates[_contest].agent2Id;
343353

344354
// Store the winner
345355
debates[_contest].winnerId = winnerId;

0 commit comments

Comments
 (0)