@@ -17,6 +17,7 @@ import { commify } from "../../../utils/units"
1717import { Field } from "../../Claim/Field"
1818import { ErrorModal } from "../../../pages/ContestDetails/ErrorModal"
1919import { useAdminTwitterAccount } from "../../../hooks/api/admin/useTwitterAccount"
20+ import { useAdminContestVariables } from "../../../hooks/api/admin/useAdminContestVariables"
2021
2122type Props = ModalProps & { }
2223
@@ -43,18 +44,14 @@ export const CreateContestModal: React.FC<Props> = ({ onClose }) => {
4344 const [ contestTitle , setContestTitle ] = useState ( "" )
4445 const [ contestShortDescription , setShortDescription ] = useState ( "" )
4546 const [ contestNSLOC , setContestNSLOC ] = useState ( "" )
47+ const [ debouncedContestNSLOC ] = useDebounce ( contestNSLOC , 300 )
4648 const [ contestStartDate , setContestStartDate ] = useState ( "" )
4749 const [ contestAuditLength , setContestAuditLength ] = useState ( "" )
48- const [ contestAuditPrizePool , setContestAuditPrizePool ] = useState < BigNumber | undefined > ( BigNumber . from ( 0 ) )
49- const [ contestLeadSeniorWatsonFixedPay , setContestLeadSeniorWatsonFixedPay ] = useState < BigNumber | undefined > (
50- BigNumber . from ( 0 )
51- )
50+ const [ contestAuditRewards , setContestAuditRewards ] = useState < BigNumber | undefined > ( BigNumber . from ( 0 ) )
5251 const [ contestJudgingPrizePool , setContestJudgingPrizePool ] = useState < BigNumber | undefined > ( BigNumber . from ( 0 ) )
5352 const [ contestLeadJudgeFixedPay , setContestLeadJudgeFixedPay ] = useState < BigNumber | undefined > ( BigNumber . from ( 0 ) )
5453 const [ contestTotalCost , setContestTotalCost ] = useState < BigNumber | undefined > ( BigNumber . from ( 0 ) )
55- const [ initialLeadSeniorWatsonFixedPay , setInitialLeadSeniorWatsonFixedPay ] = useState < BigNumber | undefined > (
56- BigNumber . from ( 0 )
57- )
54+ const [ initialAuditContestRewards , setInitialAuditContestRewards ] = useState < BigNumber | undefined > ( BigNumber . from ( 0 ) )
5855 const [ initialJudgingPrizePool , setInitialJudgingPrizePool ] = useState < BigNumber | undefined > ( BigNumber . from ( 0 ) )
5956 const [ initialLeadJudgeFixedPay , setInitialLeadJudgeFixedPay ] = useState < BigNumber | undefined > ( BigNumber . from ( 0 ) )
6057 const [ initialTotalCost , setInitialTotalCost ] = useState < BigNumber | undefined > ( BigNumber . from ( 0 ) )
@@ -66,6 +63,27 @@ export const CreateContestModal: React.FC<Props> = ({ onClose }) => {
6663
6764 const displayProtocolInfo = ! ! protocol || protocolNotFound || protocolLoading
6865
66+ const { data : contestVariables , isSuccess : contestVariablesSuccess } = useAdminContestVariables (
67+ parseInt ( debouncedContestNSLOC )
68+ )
69+
70+ useEffect ( ( ) => {
71+ if ( contestVariablesSuccess ) {
72+ setContestAuditLength ( `${ contestVariables . length } ` )
73+
74+ setInitialAuditContestRewards ( ethers . utils . parseUnits ( `${ contestVariables . auditContestRewards } ` , 6 ) )
75+ setInitialJudgingPrizePool ( ethers . utils . parseUnits ( `${ contestVariables . judgingPrizePool } ` , 6 ) )
76+ setInitialLeadJudgeFixedPay ( ethers . utils . parseUnits ( `${ contestVariables . leadJudgeFixedPay } ` , 6 ) )
77+ setInitialTotalCost ( ethers . utils . parseUnits ( `${ contestVariables . fullPayment } ` , 6 ) )
78+ } else {
79+ setContestAuditLength ( "" )
80+ setInitialAuditContestRewards ( BigNumber . from ( 0 ) )
81+ setInitialJudgingPrizePool ( BigNumber . from ( 0 ) )
82+ setInitialLeadJudgeFixedPay ( BigNumber . from ( 0 ) )
83+ setInitialTotalCost ( BigNumber . from ( 0 ) )
84+ }
85+ } , [ contestVariablesSuccess , setContestAuditLength , contestVariables ] )
86+
6987 useEffect ( ( ) => {
7088 if ( isSuccess ) onClose ?.( )
7189 } , [ isSuccess , onClose ] )
@@ -105,46 +123,14 @@ export const CreateContestModal: React.FC<Props> = ({ onClose }) => {
105123 setStartDateError ( undefined )
106124 } , [ contestStartDate , contestAuditLength ] )
107125
108- useEffect ( ( ) => {
109- if ( ! contestAuditPrizePool ) return
110-
111- const fixedPay = contestAuditPrizePool . div ( 10 ) . mul ( 4 )
112- const judgingPool = contestAuditPrizePool . div ( 100 ) . mul ( 5 )
113-
114- setInitialLeadSeniorWatsonFixedPay ( fixedPay )
115- setInitialJudgingPrizePool ( judgingPool )
116- setInitialLeadJudgeFixedPay ( judgingPool )
117- } , [ contestAuditPrizePool , setInitialLeadSeniorWatsonFixedPay , setInitialJudgingPrizePool , setInitialTotalCost ] )
118-
119- useEffect ( ( ) => {
120- if ( ! contestJudgingPrizePool ) return
121- setInitialLeadJudgeFixedPay ( contestJudgingPrizePool )
122- } , [ contestJudgingPrizePool ] )
123-
124- useEffect ( ( ) => {
125- const total = contestAuditPrizePool
126- ?. add ( contestLeadSeniorWatsonFixedPay ?? 0 )
127- . add ( contestJudgingPrizePool ?? 0 )
128- . add ( contestLeadJudgeFixedPay ?? 0 )
129- . add ( contestAuditPrizePool . div ( 100 ) . mul ( 5 ) )
130- setInitialTotalCost ( total )
131- } , [ contestAuditPrizePool , contestLeadSeniorWatsonFixedPay , contestJudgingPrizePool , contestLeadJudgeFixedPay ] )
132-
133126 const sherlockFee = useMemo ( ( ) => {
134127 const fee = contestTotalCost
135- ?. sub ( contestAuditPrizePool ?? 0 )
136- . sub ( contestLeadSeniorWatsonFixedPay ?? 0 )
128+ ?. sub ( contestAuditRewards ?? 0 )
137129 . sub ( contestJudgingPrizePool ?? 0 )
138130 . sub ( contestLeadJudgeFixedPay ?? 0 )
139131
140132 return commify ( parseInt ( ethers . utils . formatUnits ( fee ?? 0 , 6 ) ) )
141- } , [
142- contestAuditPrizePool ,
143- contestLeadSeniorWatsonFixedPay ,
144- contestJudgingPrizePool ,
145- contestTotalCost ,
146- contestLeadJudgeFixedPay ,
147- ] )
133+ } , [ contestTotalCost , contestAuditRewards , contestJudgingPrizePool , contestLeadJudgeFixedPay ] )
148134
149135 const canCreateContest = useMemo ( ( ) => {
150136 if ( protocolName === "" ) return false
@@ -163,15 +149,13 @@ export const CreateContestModal: React.FC<Props> = ({ onClose }) => {
163149 if ( ! startDate . isValid ) return false
164150 if ( startDate < DateTime . now ( ) ) return false
165151
166- if ( contestAuditPrizePool ?. eq ( BigNumber . from ( 0 ) ) ) return false
167- if ( contestLeadSeniorWatsonFixedPay ?. eq ( BigNumber . from ( 0 ) ) ) return false
152+ if ( contestAuditRewards ?. eq ( BigNumber . from ( 0 ) ) ) return false
168153 if ( contestTotalCost ?. eq ( BigNumber . from ( 0 ) ) ) return false
169154
170155 return true
171156 } , [
172157 contestAuditLength ,
173- contestAuditPrizePool ,
174- contestLeadSeniorWatsonFixedPay ,
158+ contestAuditRewards ,
175159 contestShortDescription . length ,
176160 contestStartDate ,
177161 contestTitle ,
@@ -227,18 +211,16 @@ export const CreateContestModal: React.FC<Props> = ({ onClose }) => {
227211 nSLOC : contestNSLOC ,
228212 startDate,
229213 endDate,
230- auditPrizePool : parseInt ( ethers . utils . formatUnits ( contestAuditPrizePool ?? 0 , 6 ) ) ,
214+ auditRewards : parseInt ( ethers . utils . formatUnits ( contestAuditRewards ?? 0 , 6 ) ) ,
231215 judgingPrizePool : parseInt ( ethers . utils . formatUnits ( contestJudgingPrizePool ?? 0 , 6 ) ) ,
232- leadSeniorAuditorFixedPay : parseInt ( ethers . utils . formatUnits ( contestLeadSeniorWatsonFixedPay ?? 0 , 6 ) ) ,
233216 leadJudgeFixedPay : parseInt ( ethers . utils . formatUnits ( contestLeadJudgeFixedPay ?? 0 , 6 ) ) ,
234217 fullPayment : parseInt ( ethers . utils . formatUnits ( contestTotalCost ?? 0 , 6 ) ) ,
235218 } ,
236219 } )
237220 } , [
238221 contestAuditLength ,
239- contestAuditPrizePool ,
222+ contestAuditRewards ,
240223 contestJudgingPrizePool ,
241- contestLeadSeniorWatsonFixedPay ,
242224 contestLeadJudgeFixedPay ,
243225 contestNSLOC ,
244226 contestShortDescription ,
@@ -262,16 +244,14 @@ export const CreateContestModal: React.FC<Props> = ({ onClose }) => {
262244 contestNSLOC !== "" ||
263245 contestStartDate !== "" ||
264246 contestAuditLength !== "" ||
265- contestAuditPrizePool ?. gt ( BigNumber . from ( 0 ) ) ||
266- contestLeadSeniorWatsonFixedPay ?. gt ( BigNumber . from ( 0 ) ) ||
247+ contestAuditRewards ?. gt ( BigNumber . from ( 0 ) ) ||
267248 contestJudgingPrizePool ?. gt ( BigNumber . from ( 0 ) ) ||
268249 contestLeadJudgeFixedPay ?. gt ( BigNumber . from ( 0 ) ) ||
269250 contestTotalCost ?. gt ( BigNumber . from ( 0 ) ) ,
270251 [
271252 contestAuditLength ,
272- contestAuditPrizePool ,
253+ contestAuditRewards ,
273254 contestJudgingPrizePool ,
274- contestLeadSeniorWatsonFixedPay ,
275255 contestLeadJudgeFixedPay ,
276256 contestNSLOC ,
277257 contestShortDescription ,
@@ -400,6 +380,9 @@ export const CreateContestModal: React.FC<Props> = ({ onClose }) => {
400380 < Field label = "Short Description" error = { ! ! shortDescriptionError } errorMessage = { shortDescriptionError ?? "" } >
401381 < Input value = { contestShortDescription } onChange = { handleUpdateShortDescription } />
402382 </ Field >
383+ < Field label = "Start Date" error = { ! ! startDateError } errorMessage = { startDateError ?? "" } >
384+ < Input value = { contestStartDate } onChange = { setContestStartDate } />
385+ </ Field >
403386 < Field
404387 label = "nSLOC"
405388 detail = {
@@ -410,31 +393,22 @@ export const CreateContestModal: React.FC<Props> = ({ onClose }) => {
410393 >
411394 < Input value = { contestNSLOC } onChange = { setContestNSLOC } />
412395 </ Field >
413- < Field label = "Start Date" error = { ! ! startDateError } errorMessage = { startDateError ?? "" } >
414- < Input value = { contestStartDate } onChange = { setContestStartDate } />
415- </ Field >
416396 < Field label = "Audit Length" >
417397 < Input type = "number" value = { contestAuditLength } onChange = { setContestAuditLength } />
418398 </ Field >
419- < Field label = "Audit Contest Prize Pool" >
420- < TokenInput token = "USDC" onChange = { setContestAuditPrizePool } />
421- </ Field >
422- < Field label = "Lead Senior Watson Fixed Pay" >
423- < TokenInput
424- token = "USDC"
425- initialValue = { initialLeadSeniorWatsonFixedPay }
426- onChange = { setContestLeadSeniorWatsonFixedPay }
427- />
399+ < Field label = "Audit Contest Rewards" sublabel = "Contest Pool + Lead fixed pay" >
400+ < TokenInput token = "USDC" initialValue = { initialAuditContestRewards } onChange = { setContestAuditRewards } />
428401 </ Field >
429402 < Field label = "Judging Contest Prize Pool" >
430403 < TokenInput token = "USDC" initialValue = { initialJudgingPrizePool } onChange = { setContestJudgingPrizePool } />
431404 </ Field >
432405 < Field label = "Lead Judge Fixed Pay" >
433406 < TokenInput token = "USDC" initialValue = { initialLeadJudgeFixedPay } onChange = { setContestLeadJudgeFixedPay } />
434407 </ Field >
435- < Field label = "Total Cost" detail = { `Sherlock fee will be ${ sherlockFee } USDC` } >
408+ < Field label = "Total Cost" >
436409 < TokenInput token = "USDC" initialValue = { initialTotalCost } onChange = { setContestTotalCost } />
437410 </ Field >
411+ < Text size = "small" > { `Admin Fee: ${ sherlockFee } USDC` } </ Text >
438412 </ Column >
439413 < hr />
440414 < Button disabled = { ! canCreateContest } onClick = { handleCreateContest } >
0 commit comments