diff --git a/src/GMXAutomationBase.sol b/src/GMXAutomationBase.sol index 1dc702a..deb10f5 100644 --- a/src/GMXAutomationBase.sol +++ b/src/GMXAutomationBase.sol @@ -19,6 +19,9 @@ contract GMXAutomationBase is Ownable2Step { // ERRORS error GMXAutomationBase_OnlyForwarder(); + error GMXAutomationBase_ZeroIndexTokenFeedId(); + error GMXAutomationBase_ZeroLongTokenFeedId(); + error GMXAutomationBase_ZeroShortTokenFeedId(); // IMMUTABLES DataStore public immutable i_dataStore; @@ -79,21 +82,24 @@ contract GMXAutomationBase is Ownable2Step { function _addPropsToMapping(Market.Props memory marketProps) internal { if (marketProps.indexToken != address(0)) { uint256 indexTokenFeedId = uint256(i_dataStore.getBytes32(Keys.realtimeFeedIdKey(marketProps.indexToken))); - if (indexTokenFeedId != 0 && !s_feedIdToMarketTokenMap.contains(indexTokenFeedId)) { + if (indexTokenFeedId == 0) revert GMXAutomationBase_ZeroIndexTokenFeedId(); + if (!s_feedIdToMarketTokenMap.contains(indexTokenFeedId)) { s_feedIdToMarketTokenMap.set(indexTokenFeedId, marketProps.indexToken); } } if (marketProps.longToken != address(0)) { uint256 longTokenFeedId = uint256(i_dataStore.getBytes32(Keys.realtimeFeedIdKey(marketProps.longToken))); - if (longTokenFeedId != 0 && !s_feedIdToMarketTokenMap.contains(longTokenFeedId)) { + if (longTokenFeedId == 0) revert GMXAutomationBase_ZeroLongTokenFeedId(); + if (!s_feedIdToMarketTokenMap.contains(longTokenFeedId)) { s_feedIdToMarketTokenMap.set(longTokenFeedId, marketProps.longToken); } } if (marketProps.shortToken != address(0)) { uint256 shortTokenFeedId = uint256(i_dataStore.getBytes32(Keys.realtimeFeedIdKey(marketProps.shortToken))); - if (shortTokenFeedId != 0 && !s_feedIdToMarketTokenMap.contains(shortTokenFeedId)) { + if (shortTokenFeedId == 0) revert GMXAutomationBase_ZeroShortTokenFeedId(); + if (!s_feedIdToMarketTokenMap.contains(shortTokenFeedId)) { s_feedIdToMarketTokenMap.set(shortTokenFeedId, marketProps.shortToken); } } diff --git a/test/GMXAutomationBase.t.sol b/test/GMXAutomationBase.t.sol index 64e8f81..55c253d 100644 --- a/test/GMXAutomationBase.t.sol +++ b/test/GMXAutomationBase.t.sol @@ -126,6 +126,90 @@ contract GMXAutomationBaseTest__addPropsToMapping is Test { assertEq(s_gmxAutomation.feedIdToMarketTokenMapGet(uint256(longTokenFeedId)), marketProps.longToken); assertEq(s_gmxAutomation.feedIdToMarketTokenMapGet(uint256(shortTokenFeedId)), marketProps.shortToken); } + + function test__addPropsToMapping_ZeroIndexTokenFeedId_reverts() public { + Market.Props memory marketProps; + marketProps.indexToken = address(1); + marketProps.longToken = address(2); + marketProps.shortToken = address(3); + + bytes32 indexTokenFeedId; + bytes32 longTokenFeedId = bytes32("100"); + bytes32 shortTokenFeedId = bytes32("101"); + vm.mockCall( + DATA_STORE_ADDRESS, + abi.encodeWithSelector(DataStore.getBytes32.selector, Keys.realtimeFeedIdKey(marketProps.indexToken)), + abi.encode(indexTokenFeedId) + ); + vm.mockCall( + DATA_STORE_ADDRESS, + abi.encodeWithSelector(DataStore.getBytes32.selector, Keys.realtimeFeedIdKey(marketProps.longToken)), + abi.encode(longTokenFeedId) + ); + vm.mockCall( + DATA_STORE_ADDRESS, + abi.encodeWithSelector(DataStore.getBytes32.selector, Keys.realtimeFeedIdKey(marketProps.shortToken)), + abi.encode(shortTokenFeedId) + ); + vm.expectRevert(GMXAutomationBase.GMXAutomationBase_ZeroIndexTokenFeedId.selector); + s_gmxAutomation.addPropsToMapping(marketProps); + } + + function test__addPropsToMapping_ZeroLongTokenFeedId_reverts() public { + Market.Props memory marketProps; + marketProps.indexToken = address(1); + marketProps.longToken = address(2); + marketProps.shortToken = address(3); + + bytes32 indexTokenFeedId = bytes32("99"); + bytes32 longTokenFeedId; + bytes32 shortTokenFeedId = bytes32("101"); + vm.mockCall( + DATA_STORE_ADDRESS, + abi.encodeWithSelector(DataStore.getBytes32.selector, Keys.realtimeFeedIdKey(marketProps.indexToken)), + abi.encode(indexTokenFeedId) + ); + vm.mockCall( + DATA_STORE_ADDRESS, + abi.encodeWithSelector(DataStore.getBytes32.selector, Keys.realtimeFeedIdKey(marketProps.longToken)), + abi.encode(longTokenFeedId) + ); + vm.mockCall( + DATA_STORE_ADDRESS, + abi.encodeWithSelector(DataStore.getBytes32.selector, Keys.realtimeFeedIdKey(marketProps.shortToken)), + abi.encode(shortTokenFeedId) + ); + vm.expectRevert(GMXAutomationBase.GMXAutomationBase_ZeroLongTokenFeedId.selector); + s_gmxAutomation.addPropsToMapping(marketProps); + } + + function test__addPropsToMapping_ZeroShortTokenFeedId_reverts() public { + Market.Props memory marketProps; + marketProps.indexToken = address(1); + marketProps.longToken = address(2); + marketProps.shortToken = address(3); + + bytes32 indexTokenFeedId = bytes32("99"); + bytes32 longTokenFeedId = bytes32("100"); + bytes32 shortTokenFeedId; + vm.mockCall( + DATA_STORE_ADDRESS, + abi.encodeWithSelector(DataStore.getBytes32.selector, Keys.realtimeFeedIdKey(marketProps.indexToken)), + abi.encode(indexTokenFeedId) + ); + vm.mockCall( + DATA_STORE_ADDRESS, + abi.encodeWithSelector(DataStore.getBytes32.selector, Keys.realtimeFeedIdKey(marketProps.longToken)), + abi.encode(longTokenFeedId) + ); + vm.mockCall( + DATA_STORE_ADDRESS, + abi.encodeWithSelector(DataStore.getBytes32.selector, Keys.realtimeFeedIdKey(marketProps.shortToken)), + abi.encode(shortTokenFeedId) + ); + vm.expectRevert(GMXAutomationBase.GMXAutomationBase_ZeroShortTokenFeedId.selector); + s_gmxAutomation.addPropsToMapping(marketProps); + } } contract GMXAutomationBaseTest__flushMapping is Test {