@@ -86,6 +86,9 @@ contract SwanDebate is Ownable, Pausable {
86
86
/// @notice Thrown when trying to use an unregistered agent
87
87
error AgentNotRegistered ();
88
88
89
+ /// @notice Thrown when an invalid number of proposals exist in a debate
90
+ error InvalidProposalCount (uint256 count );
91
+
89
92
/*//////////////////////////////////////////////////////////////
90
93
EVENTS
91
94
//////////////////////////////////////////////////////////////*/
@@ -134,6 +137,8 @@ contract SwanDebate is Ownable, Pausable {
134
137
struct Debate {
135
138
uint256 agent1Id;
136
139
uint256 agent2Id;
140
+ uint256 agent1ProposalId;
141
+ uint256 agent2ProposalId;
137
142
uint256 currentRound;
138
143
uint256 winnerId;
139
144
mapping (uint256 => RoundData) rounds;
@@ -239,8 +244,15 @@ contract SwanDebate is Ownable, Pausable {
239
244
revert ContestInvalidState (contest.state (), IJokeRaceContest.ContestState.Queued);
240
245
}
241
246
247
+ uint256 [] memory proposalIds = contest.getAllProposalIds ();
248
+ if (proposalIds.length != 2 ) {
249
+ revert InvalidProposalCount (proposalIds.length );
250
+ }
251
+
242
252
debate.agent1Id = _agent1Id;
243
253
debate.agent2Id = _agent2Id;
254
+ debate.agent1ProposalId = proposalIds[0 ];
255
+ debate.agent2ProposalId = proposalIds[1 ];
244
256
debate.currentRound = 1 ;
245
257
debate.winnerId = 0 ;
246
258
@@ -335,11 +347,9 @@ contract SwanDebate is Ownable, Pausable {
335
347
// The last proposal in the sorted array has the highest votes
336
348
uint256 winningProposal = sortedProposals[sortedProposals.length - 1 ];
337
349
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;
343
353
344
354
// Store the winner
345
355
debates[_contest].winnerId = winnerId;
0 commit comments