@@ -11,49 +11,34 @@ import {
11
11
ChangeWinnerMultiplierCall ,
12
12
ChangeWithdrawTimeoutCall ,
13
13
ExecuteSubmissionsCall ,
14
+ FundAppealCall ,
14
15
Governor ,
15
16
SetMetaEvidenceCall ,
16
17
SubmitListCall ,
17
18
WithdrawTransactionListCall ,
18
19
} from "../generated/Governor/Governor" ;
19
20
import {
20
21
Contract ,
22
+ Contribution ,
21
23
MetaEvidence ,
22
24
Round ,
23
25
Session ,
24
26
Submission ,
25
27
Transaction ,
26
28
} from "../generated/schema" ;
27
29
28
- function getStatus ( status : number ) : string {
29
- if ( status == 0 ) return "NoDispute" ;
30
- if ( status == 1 ) return "DisputeCreated" ;
31
- if ( status == 2 ) return "Resolved" ;
32
- return "Error" ;
33
- }
34
-
35
30
function concatByteArrays ( a : ByteArray , b : ByteArray ) : ByteArray {
36
31
let out = new Uint8Array ( a . length + b . length ) ;
37
32
for ( let i = 0 ; i < a . length ; i ++ ) out [ i ] = a [ i ] ;
38
33
for ( let j = 0 ; j < b . length ; j ++ ) out [ a . length + j ] = b [ j ] ;
39
34
return out as ByteArray ;
40
35
}
41
36
42
- function newSession ( contract : Contract , creationTime : BigInt ) : Session {
43
- let session = new Session ( contract . sessionsLength . toHexString ( ) ) ;
44
- session . creationTime = creationTime ;
45
- session . sumDeposit = BigInt . fromI32 ( 0 ) ;
46
- session . status = getStatus ( 0 ) ;
47
- session . durationOffset = BigInt . fromI32 ( 0 ) ;
48
- session . submissionsLength = BigInt . fromI32 ( 0 ) ;
49
- session . roundsLength = BigInt . fromI32 ( 0 ) ;
50
- session . save ( ) ;
51
-
52
- contract . sessionsLength . plus ( BigInt . fromI32 ( 1 ) ) ;
53
- contract . save ( ) ;
54
-
55
- // Something is broken with The Graph's null type guards so we need these explicit casts in some places.
56
- return session as Session ;
37
+ function getStatus ( status : number ) : string {
38
+ if ( status == 0 ) return "NoDispute" ;
39
+ if ( status == 1 ) return "DisputeCreated" ;
40
+ if ( status == 2 ) return "Resolved" ;
41
+ return "Error" ;
57
42
}
58
43
59
44
function initializeContract (
@@ -89,12 +74,29 @@ function initializeContract(
89
74
return contract as Contract ;
90
75
}
91
76
77
+ function newSession ( contract : Contract , creationTime : BigInt ) : Session {
78
+ let session = new Session ( contract . sessionsLength . toHexString ( ) ) ;
79
+ session . creationTime = creationTime ;
80
+ session . sumDeposit = BigInt . fromI32 ( 0 ) ;
81
+ session . status = getStatus ( 0 ) ;
82
+ session . durationOffset = BigInt . fromI32 ( 0 ) ;
83
+ session . submissionsLength = BigInt . fromI32 ( 0 ) ;
84
+ session . roundsLength = BigInt . fromI32 ( 0 ) ;
85
+ session . save ( ) ;
86
+
87
+ contract . sessionsLength . plus ( BigInt . fromI32 ( 1 ) ) ;
88
+ contract . save ( ) ;
89
+
90
+ // Something is broken with The Graph's null type guards so we need these explicit casts in some places.
91
+ return session as Session ;
92
+ }
93
+
92
94
function newRound ( session : Session , creationTime : BigInt ) : Round {
93
95
let round = new Round (
94
96
crypto
95
97
. keccak256 (
96
98
concatByteArrays (
97
- ByteArray . fromUTF8 ( session . id ) ,
99
+ ByteArray . fromHexString ( session . id ) ,
98
100
ByteArray . fromUTF8 ( session . roundsLength . toString ( ) )
99
101
)
100
102
)
@@ -115,6 +117,49 @@ function newRound(session: Session, creationTime: BigInt): Round {
115
117
return round as Round ;
116
118
}
117
119
120
+ function updateContribution (
121
+ governor : Governor ,
122
+ sessionID : BigInt ,
123
+ roundIndex : BigInt ,
124
+ contributor : Address ,
125
+ time : BigInt
126
+ ) : Contribution {
127
+ let roundInfo = governor . getRoundInfo ( sessionID , roundIndex ) ;
128
+ let contributions = governor . getContributions (
129
+ sessionID ,
130
+ roundIndex ,
131
+ contributor
132
+ ) ;
133
+
134
+ let roundID = crypto . keccak256 (
135
+ concatByteArrays (
136
+ ByteArray . fromUTF8 ( sessionID . toString ( ) ) ,
137
+ ByteArray . fromUTF8 ( roundIndex . toString ( ) )
138
+ )
139
+ ) ;
140
+ let round = Round . load ( roundID . toHexString ( ) ) ;
141
+ round . paidFees = roundInfo . value0 ;
142
+ round . hasPaid = roundInfo . value1 ;
143
+ round . feeRewards = roundInfo . value2 ;
144
+ round . successfullyPaid = roundInfo . value3 ;
145
+ round . save ( ) ;
146
+
147
+ let contributionID = crypto
148
+ . keccak256 ( concatByteArrays ( roundID , contributor ) )
149
+ . toHexString ( ) ;
150
+ let contribution = Contribution . load ( contributionID ) ;
151
+ if ( contribution == null ) {
152
+ contribution = new Contribution ( contributionID ) ;
153
+ contribution . creationTime = time ;
154
+ contribution . round = round . id ;
155
+ contribution . contributor = contributor ;
156
+ }
157
+ contribution . values = contributions ;
158
+ contribution . save ( ) ;
159
+
160
+ return contribution as Contribution ;
161
+ }
162
+
118
163
export function setMetaEvidence ( call : SetMetaEvidenceCall ) : void {
119
164
let contract = initializeContract ( call . to , call . from , call . block . timestamp ) ;
120
165
@@ -215,7 +260,7 @@ export function submitList(call: SubmitListCall): void {
215
260
for ( let i = 0 ; i < call . inputs . _target . length ; i ++ ) {
216
261
let transaction = new Transaction (
217
262
concatByteArrays (
218
- crypto . keccak256 ( ByteArray . fromUTF8 ( submission . id ) ) ,
263
+ crypto . keccak256 ( ByteArray . fromHexString ( submission . id ) ) ,
219
264
ByteArray . fromUTF8 ( i . toString ( ) )
220
265
) . toHexString ( )
221
266
) ;
@@ -309,3 +354,26 @@ export function executeSubmissions(call: ExecuteSubmissionsCall): void {
309
354
newRound ( session as Session , call . block . timestamp ) ;
310
355
}
311
356
}
357
+
358
+ export function fundAppeal ( call : FundAppealCall ) : void {
359
+ let governor = Governor . bind ( call . to ) ;
360
+ let contract = initializeContract ( call . to , call . from , call . block . timestamp ) ;
361
+
362
+ let sessionID = contract . sessionsLength . minus ( BigInt . fromI32 ( 1 ) ) ;
363
+ let session = Session . load ( sessionID . toHexString ( ) ) ;
364
+ updateContribution (
365
+ governor ,
366
+ sessionID ,
367
+ session . roundsLength . minus ( BigInt . fromI32 ( 1 ) ) ,
368
+ call . from ,
369
+ call . block . timestamp
370
+ ) ;
371
+
372
+ contract . reservedETH = governor . reservedETH ( ) ;
373
+ contract . shadowWinner = governor . shadowWinner ( ) . toHexString ( ) ;
374
+ contract . save ( ) ;
375
+
376
+ let sessionRoundsNumber = governor . getSessionRoundsNumber ( sessionID ) ;
377
+ if ( sessionRoundsNumber . gt ( session . roundsLength ) )
378
+ newRound ( session as Session , call . block . timestamp ) ;
379
+ }
0 commit comments