Skip to content

Commit 0af39d3

Browse files
committed
fix inventory bridge config validation
1 parent 3d662dc commit 0af39d3

2 files changed

Lines changed: 81 additions & 16 deletions

File tree

typescript/rebalancer/src/config/RebalancerConfig.test.ts

Lines changed: 81 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -786,8 +786,8 @@ describe('per-chain bridge configuration', () => {
786786
});
787787
});
788788

789-
it('should require externalBridges.lifi when executionType is inventory', () => {
790-
const data = {
789+
it('should accept externalBridges.layerzero for inventory execution', () => {
790+
const data: RebalancerConfigFileInput = {
791791
warpRouteId: 'test-route',
792792
strategy: [
793793
{
@@ -796,20 +796,26 @@ describe('per-chain bridge configuration', () => {
796796
ethereum: {
797797
weighted: { weight: 100, tolerance: 5 },
798798
executionType: ExecutionType.Inventory,
799+
externalBridge: ExternalBridgeType.LayerZero,
799800
},
800801
},
801802
},
802803
],
803804
inventorySigners: {
804805
ethereum: '0x1234567890123456789012345678901234567890',
805806
},
807+
externalBridges: {
808+
layerzero: {},
809+
},
806810
};
807811

808812
writeYamlOrJson(TEST_CONFIG_PATH_BRIDGE, data);
813+
const config = RebalancerConfig.load(TEST_CONFIG_PATH_BRIDGE);
809814

810-
expect(() => RebalancerConfig.load(TEST_CONFIG_PATH_BRIDGE)).to.throw(
811-
/externalBridges\.lifi.*required/i,
815+
expect(config.strategyConfig[0].chains.ethereum.externalBridge).to.equal(
816+
ExternalBridgeType.LayerZero,
812817
);
818+
expect(config.externalBridges?.layerzero).to.deep.equal({});
813819
});
814820

815821
it('should require externalBridges.lifi when externalBridge is lifi', () => {
@@ -839,7 +845,7 @@ describe('per-chain bridge configuration', () => {
839845
);
840846
});
841847

842-
it('should require externalBridge field when executionType is inventory', () => {
848+
it('should require externalBridges.layerzero when externalBridge is layerzero', () => {
843849
const data = {
844850
warpRouteId: 'test-route',
845851
strategy: [
@@ -849,6 +855,43 @@ describe('per-chain bridge configuration', () => {
849855
ethereum: {
850856
weighted: { weight: 100, tolerance: 5 },
851857
executionType: ExecutionType.Inventory,
858+
externalBridge: ExternalBridgeType.LayerZero,
859+
},
860+
},
861+
},
862+
],
863+
inventorySigners: {
864+
ethereum: '0x1234567890123456789012345678901234567890',
865+
},
866+
};
867+
868+
writeYamlOrJson(TEST_CONFIG_PATH_BRIDGE, data);
869+
870+
expect(() => RebalancerConfig.load(TEST_CONFIG_PATH_BRIDGE)).to.throw(
871+
/externalBridges\.layerzero.*required|layerzero.*not configured/i,
872+
);
873+
});
874+
875+
it('should accept override-only layerzero inventory config without lifi', () => {
876+
const data: RebalancerConfigFileInput = {
877+
warpRouteId: 'test-route',
878+
strategy: [
879+
{
880+
rebalanceStrategy: RebalancerStrategyOptions.Weighted,
881+
chains: {
882+
ethereum: {
883+
weighted: { weight: 50, tolerance: 5 },
884+
bridge: ethers.constants.AddressZero,
885+
override: {
886+
arbitrum: {
887+
executionType: ExecutionType.Inventory,
888+
externalBridge: ExternalBridgeType.LayerZero,
889+
},
890+
},
891+
},
892+
arbitrum: {
893+
weighted: { weight: 50, tolerance: 5 },
894+
bridge: ethers.constants.AddressZero,
852895
},
853896
},
854897
},
@@ -857,9 +900,40 @@ describe('per-chain bridge configuration', () => {
857900
ethereum: '0x1234567890123456789012345678901234567890',
858901
},
859902
externalBridges: {
860-
lifi: {
861-
integrator: 'test-app',
903+
layerzero: {},
904+
},
905+
};
906+
907+
writeYamlOrJson(TEST_CONFIG_PATH_BRIDGE, data);
908+
const config = RebalancerConfig.load(TEST_CONFIG_PATH_BRIDGE);
909+
910+
expect(
911+
config.strategyConfig[0].chains.ethereum.override?.arbitrum
912+
?.externalBridge,
913+
).to.equal(ExternalBridgeType.LayerZero);
914+
expect(config.externalBridges?.lifi).to.equal(undefined);
915+
expect(config.externalBridges?.layerzero).to.deep.equal({});
916+
});
917+
918+
it('should require externalBridge field when executionType is inventory', () => {
919+
const data = {
920+
warpRouteId: 'test-route',
921+
strategy: [
922+
{
923+
rebalanceStrategy: RebalancerStrategyOptions.Weighted,
924+
chains: {
925+
ethereum: {
926+
weighted: { weight: 100, tolerance: 5 },
927+
executionType: ExecutionType.Inventory,
928+
},
929+
},
862930
},
931+
],
932+
inventorySigners: {
933+
ethereum: '0x1234567890123456789012345678901234567890',
934+
},
935+
externalBridges: {
936+
layerzero: {},
863937
},
864938
};
865939

typescript/rebalancer/src/config/types.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -381,15 +381,6 @@ export const RebalancerConfigSchema = z
381381
// Other protocols: accept any non-empty string (future-proof)
382382
}
383383
}
384-
385-
if (!config.externalBridges?.lifi?.integrator) {
386-
ctx.addIssue({
387-
code: z.ZodIssueCode.custom,
388-
message:
389-
'externalBridges.lifi is required when using inventory execution',
390-
path: ['externalBridges', 'lifi'],
391-
});
392-
}
393384
}
394385

395386
for (

0 commit comments

Comments
 (0)