@@ -83,10 +83,7 @@ export interface SettlementContractType {
83
83
// Some random prefix for the sequencer signature
84
84
export const BATCH_SIGNATURE_PREFIX = prefixToField ( "pk-batchSignature" ) ;
85
85
86
- export class SettlementSmartContract
87
- extends TokenContract
88
- implements SettlementContractType
89
- {
86
+ export abstract class SettlementSmartContractBase extends TokenContract {
90
87
// This pattern of injecting args into a smartcontract is currently the only
91
88
// viable solution that works given the inheritance issues of o1js
92
89
public static args : {
@@ -96,23 +93,18 @@ export class SettlementSmartContract
96
93
escapeHatchSlotsInterval : number ;
97
94
} ;
98
95
99
- @state ( Field ) public sequencerKey = State < Field > ( ) ;
100
- @state ( UInt32 ) public lastSettlementL1BlockHeight = State < UInt32 > ( ) ;
101
-
102
- @state ( Field ) public stateRoot = State < Field > ( ) ;
103
- @state ( Field ) public networkStateHash = State < Field > ( ) ;
104
- @state ( Field ) public blockHashRoot = State < Field > ( ) ;
105
-
106
- @state ( Field ) public dispatchContractAddressX = State < Field > ( ) ;
107
-
108
- @state ( Field ) public outgoingMessageCursor = State < Field > ( ) ;
96
+ abstract sequencerKey : State < Field > ;
97
+ abstract lastSettlementL1BlockHeight : State < UInt32 > ;
98
+ abstract stateRoot : State < Field > ;
99
+ abstract networkStateHash : State < Field > ;
100
+ abstract blockHashRoot : State < Field > ;
101
+ abstract dispatchContractAddressX : State < Field > ;
102
+ abstract outgoingMessageCursor : State < Field > ;
109
103
110
- @method async approveBase ( forest : AccountUpdateForest ) {
111
- this . checkZeroBalanceChange ( forest ) ;
112
- }
113
-
114
- @method
115
- public async initialize ( sequencer : PublicKey , dispatchContract : PublicKey ) {
104
+ protected async initializeBase (
105
+ sequencer : PublicKey ,
106
+ dispatchContract : PublicKey
107
+ ) {
116
108
this . sequencerKey . getAndRequireEquals ( ) . assertEquals ( Field ( 0 ) ) ;
117
109
this . stateRoot . getAndRequireEquals ( ) . assertEquals ( Field ( 0 ) ) ;
118
110
this . blockHashRoot . getAndRequireEquals ( ) . assertEquals ( Field ( 0 ) ) ;
@@ -125,13 +117,12 @@ export class SettlementSmartContract
125
117
this . networkStateHash . set ( NetworkState . empty ( ) . hash ( ) ) ;
126
118
this . dispatchContractAddressX . set ( dispatchContract . x ) ;
127
119
128
- const { DispatchContract } = SettlementSmartContract . args ;
120
+ const { DispatchContract } = SettlementSmartContractBase . args ;
129
121
const contractInstance = new DispatchContract ( dispatchContract ) ;
130
122
await contractInstance . initialize ( this . address ) ;
131
123
}
132
124
133
- @method
134
- public async settle (
125
+ protected async settleBase (
135
126
blockProof : LazyBlockProof ,
136
127
signature : Signature ,
137
128
dispatchContractAddress : PublicKey ,
@@ -159,7 +150,7 @@ export class SettlementSmartContract
159
150
) ;
160
151
161
152
const { DispatchContract, escapeHatchSlotsInterval, hooks } =
162
- SettlementSmartContract . args ;
153
+ SettlementSmartContractBase . args ;
163
154
164
155
// Get dispatch contract values
165
156
// These values are witnesses but will be checked later on the AU
@@ -265,14 +256,60 @@ export class SettlementSmartContract
265
256
266
257
this . lastSettlementL1BlockHeight . set ( minBlockHeightIncluded ) ;
267
258
}
259
+ }
260
+
261
+ export class SettlementSmartContract
262
+ extends SettlementSmartContractBase
263
+ implements SettlementContractType
264
+ {
265
+ @state ( Field ) public sequencerKey = State < Field > ( ) ;
266
+ @state ( UInt32 ) public lastSettlementL1BlockHeight = State < UInt32 > ( ) ;
267
+
268
+ @state ( Field ) public stateRoot = State < Field > ( ) ;
269
+ @state ( Field ) public networkStateHash = State < Field > ( ) ;
270
+ @state ( Field ) public blockHashRoot = State < Field > ( ) ;
271
+
272
+ @state ( Field ) public dispatchContractAddressX = State < Field > ( ) ;
273
+
274
+ @state ( Field ) public outgoingMessageCursor = State < Field > ( ) ;
275
+
276
+ @method async approveBase ( forest : AccountUpdateForest ) {
277
+ this . checkZeroBalanceChange ( forest ) ;
278
+ }
279
+
280
+ @method
281
+ public async initialize ( sequencer : PublicKey , dispatchContract : PublicKey ) {
282
+ return await this . initializeBase ( sequencer , dispatchContract ) ;
283
+ }
284
+
285
+ @method
286
+ public async settle (
287
+ blockProof : LazyBlockProof ,
288
+ signature : Signature ,
289
+ dispatchContractAddress : PublicKey ,
290
+ publicKey : PublicKey ,
291
+ inputNetworkState : NetworkState ,
292
+ outputNetworkState : NetworkState ,
293
+ newPromisedMessagesHash : Field
294
+ ) {
295
+ return await this . settleBase (
296
+ blockProof ,
297
+ signature ,
298
+ dispatchContractAddress ,
299
+ publicKey ,
300
+ inputNetworkState ,
301
+ outputNetworkState ,
302
+ newPromisedMessagesHash
303
+ ) ;
304
+ }
268
305
269
306
@method
270
307
public async rollupOutgoingMessages ( batch : OutgoingMessageArgumentBatch ) {
271
308
let counter = this . outgoingMessageCursor . getAndRequireEquals ( ) ;
272
309
const stateRoot = this . stateRoot . getAndRequireEquals ( ) ;
273
310
274
311
const [ withdrawalModule , withdrawalStateName ] =
275
- SettlementSmartContract . args . withdrawalStatePath ;
312
+ SettlementSmartContractBase . args . withdrawalStatePath ;
276
313
const mapPath = Path . fromProperty ( withdrawalModule , withdrawalStateName ) ;
277
314
278
315
let accountCreationFeePaid = Field ( 0 ) ;
0 commit comments