Skip to content

Commit c252fa2

Browse files
committed
refactor(rebalancer): extract getOverrideExecutionType helper to reduce duplication
1 parent b7e36dd commit c252fa2

2 files changed

Lines changed: 18 additions & 24 deletions

File tree

typescript/rebalancer/src/config/types.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,20 @@ export function getChainExecutionType(
512512
return chainConfig?.executionType ?? ExecutionType.MovableCollateral;
513513
}
514514

515+
/**
516+
* Extract the executionType from an override config object.
517+
* Returns undefined if the override config doesn't have an executionType field.
518+
*/
519+
export function getOverrideExecutionType(
520+
overrideConfig: unknown,
521+
): ExecutionType | undefined {
522+
return typeof overrideConfig === 'object' &&
523+
overrideConfig !== null &&
524+
'executionType' in overrideConfig
525+
? (overrideConfig as { executionType?: ExecutionType }).executionType
526+
: undefined;
527+
}
528+
515529
/**
516530
* Get the names of all chains that use inventory execution type.
517531
* Includes both top-level inventory chains and override destination chains
@@ -540,15 +554,7 @@ export function getInventoryChainNames(strategies: StrategyConfig[]): string[] {
540554
return overrideEntries
541555
.filter(([, overrideConfig]) => {
542556
const overrideExecutionType =
543-
typeof overrideConfig === 'object' &&
544-
overrideConfig !== null &&
545-
'executionType' in overrideConfig
546-
? (
547-
overrideConfig as {
548-
executionType?: ExecutionType;
549-
}
550-
).executionType
551-
: undefined;
557+
getOverrideExecutionType(overrideConfig);
552558

553559
return (
554560
(overrideExecutionType ??
@@ -582,15 +588,7 @@ export function getInventoryOriginChainNames(
582588
chainConfig.override,
583589
).some((overrideConfig) => {
584590
const overrideExecutionType =
585-
typeof overrideConfig === 'object' &&
586-
overrideConfig !== null &&
587-
'executionType' in overrideConfig
588-
? (
589-
overrideConfig as {
590-
executionType?: ExecutionType;
591-
}
592-
).executionType
593-
: undefined;
591+
getOverrideExecutionType(overrideConfig);
594592

595593
return (
596594
(overrideExecutionType ??

typescript/rebalancer/src/factories/RebalancerContextFactory.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
getAllBridges,
2828
getInventoryChainNames,
2929
getInventoryOriginChainNames,
30+
getOverrideExecutionType,
3031
getStrategyChainConfig,
3132
getStrategyChainNames,
3233
} from '../config/types.js';
@@ -702,12 +703,7 @@ export class RebalancerContextFactory {
702703

703704
return Object.values(chainConfig.override).some((overrideConfig) => {
704705
const overrideExecutionType =
705-
typeof overrideConfig === 'object' &&
706-
overrideConfig !== null &&
707-
'executionType' in overrideConfig
708-
? (overrideConfig as { executionType?: ExecutionType })
709-
.executionType
710-
: undefined;
706+
getOverrideExecutionType(overrideConfig);
711707

712708
return (
713709
(overrideExecutionType ??

0 commit comments

Comments
 (0)