@@ -283,66 +283,44 @@ export class AllocationPriorityQueue {
283
283
private calculatePriority ( decision : AllocationDecision ) : number {
284
284
let priority = 0
285
285
286
- // Critical factors (1000+ points)
287
- if ( decision . urgent ) {
288
- priority += 10000 // Urgent allocations get top priority
289
- }
290
-
291
- if ( decision . toAllocate && ! decision . deployment . activeAllocations ) {
292
- priority += 5000 // New allocations for unallocated deployments
293
- }
294
-
295
286
// High priority factors (100-999 points)
296
287
if ( decision . toAllocate ) {
297
288
priority += 500 // Creating allocations is generally high priority
298
289
}
299
290
300
- // Signal-based priority (up to 1000 points)
301
- if ( decision . deployment . signalledTokens . gt ( this . signalThreshold ) ) {
302
- const signalScore = Math . min (
303
- 1000 ,
304
- decision . deployment . signalledTokens
305
- . div ( this . signalThreshold )
306
- . toNumber ( ) * 10
307
- )
308
- priority += signalScore
309
- }
310
-
311
- // Stake-based priority (up to 500 points)
312
- if ( decision . deployment . stakedTokens . gt ( this . stakeThreshold ) ) {
313
- const stakeScore = Math . min (
314
- 500 ,
315
- decision . deployment . stakedTokens
316
- . div ( this . stakeThreshold )
317
- . toNumber ( ) * 5
318
- )
319
- priority += stakeScore
320
- }
321
-
322
- // Query fees priority (up to 300 points)
323
- if ( decision . deployment . queryFeesAmount . gt ( 0 ) ) {
324
- const feeScore = Math . min (
325
- 300 ,
326
- Math . log10 ( decision . deployment . queryFeesAmount . toNumber ( ) ) * 30
327
- )
328
- priority += feeScore
329
- }
330
-
331
- // Profitability-based priority (up to 200 points)
332
- if ( decision . profitability && decision . profitability > 0 ) {
333
- priority += Math . min ( 200 , decision . profitability * 100 )
334
- }
335
-
336
291
// Lower priority for closing allocations (-100 points)
337
292
if ( ! decision . toAllocate ) {
338
293
priority -= 100
339
294
}
340
295
341
- // Safety check failures get deprioritized (-500 points)
342
- if ( decision . deployment . deniedAt && decision . deployment . deniedAt > 0 ) {
343
- priority -= 500
296
+ // Rule-based priority
297
+ if ( decision . ruleMatch . rule ) {
298
+ const rule = decision . ruleMatch . rule
299
+
300
+ // Higher allocation amount suggests higher importance
301
+ if ( rule . allocationAmount ) {
302
+ const amount = parseFloat ( rule . allocationAmount )
303
+ priority += Math . min ( 200 , Math . log10 ( amount + 1 ) * 20 )
304
+ }
305
+
306
+ // Priority based on decision basis
307
+ if ( rule . decisionBasis === 'always' ) {
308
+ priority += 100
309
+ } else if ( rule . decisionBasis === 'rules' ) {
310
+ priority += 50
311
+ }
312
+
313
+ // Safety considerations
314
+ if ( rule . safety === false ) {
315
+ priority -= 200 // Deprioritize unsafe deployments
316
+ }
344
317
}
345
318
319
+ // Deployment ID based priority (for consistent ordering)
320
+ const deploymentHash = decision . deployment . ipfsHash
321
+ const hashPriority = parseInt ( deploymentHash . slice ( - 4 ) , 16 ) / 65535 * 10
322
+ priority += hashPriority
323
+
346
324
return Math . max ( 0 , priority ) // Ensure non-negative priority
347
325
}
348
326
0 commit comments