Skip to content

Commit

Permalink
fallback on other collateral before V1 and format
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0Louis committed Jan 12, 2023
1 parent 84c471f commit 1ee9581
Show file tree
Hide file tree
Showing 10 changed files with 607 additions and 496 deletions.
791 changes: 417 additions & 374 deletions src/JoeDexLens.sol

Large diffs are not rendered by default.

18 changes: 0 additions & 18 deletions src/JoeDexLensErrors.sol

This file was deleted.

16 changes: 2 additions & 14 deletions src/interfaces/AggregatorV3Interface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,10 @@ interface AggregatorV3Interface {
function getRoundData(uint80 _roundId)
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);

function latestRoundData()
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
}
35 changes: 22 additions & 13 deletions src/interfaces/IJoeDexLens.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,28 @@ pragma solidity ^0.8.0;

import "joe-v2/interfaces/ILBRouter.sol";
import "joe-v2/interfaces/IJoeFactory.sol";
import "joe-v2/interfaces/IPendingOwnable.sol";
import "solrary/access/ISafeAccessControlEnumerable.sol";

import "../JoeDexLensErrors.sol";
import "../interfaces/AggregatorV3Interface.sol";
import "joe-v2/LBErrors.sol";

/// @title Interface of the Joe Dex Lens contract
/// @author Trader Joe
/// @notice The interface needed to interract with the Joe Dex Lens contract
interface IJoeDexLens is IPendingOwnable {
interface IJoeDexLens is ISafeAccessControlEnumerable {
error JoeDexLens__PairsNotCreated();
error JoeDexLens__UnknownDataFeedType();
error JoeDexLens__CollateralNotInPair(address pair, address collateral);
error JoeDexLens__TokenNotInPair(address pair, address token);
error JoeDexLens__SameTokens();
error JoeDexLens__DataFeedAlreadyAdded(address colateral, address token, address dataFeed);
error JoeDexLens__DataFeedNotInSet(address colateral, address token, address dataFeed);
error JoeDexLens__LengthsMismatch();
error JoeDexLens__NullWeight();
error JoeDexLens__WrongPair();
error JoeDexLens__InvalidChainLinkPrice();
error JoeDexLens__NotEnoughLiquidity();

/// @notice Enumerators of the different data feed types
enum dfType {
V1,
Expand Down Expand Up @@ -43,6 +56,10 @@ interface IJoeDexLens is IPendingOwnable {

event DataFeedRemoved(address collateral, address token, address dfAddress);

function getWNative() external view returns (address wNative);

function getUSDStableCoin() external view returns (address usd);

function getRouterV2() external view returns (ILBRouter routerV2);

function getFactoryV1() external view returns (IJoeFactory factoryV1);
Expand All @@ -63,17 +80,9 @@ interface IJoeDexLens is IPendingOwnable {

function addNativeDataFeed(address token, DataFeed calldata dataFeed) external;

function setUSDDataFeedWeight(
address token,
address dfAddress,
uint88 newWeight
) external;
function setUSDDataFeedWeight(address token, address dfAddress, uint88 newWeight) external;

function setNativeDataFeedWeight(
address token,
address dfAddress,
uint88 newWeight
) external;
function setNativeDataFeedWeight(address token, address dfAddress, uint88 newWeight) external;

function removeUSDDataFeed(address token, address dfAddress) external;

Expand Down
96 changes: 84 additions & 12 deletions test/JoeDexLens.Access.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,44 +34,116 @@ contract TestJoeDexLens is TestHelper {
uint88 weight1 = 1;
IJoeDexLens.DataFeed memory df = IJoeDexLens.DataFeed(address1, weight1, IJoeDexLens.dfType.V1);

vm.expectRevert(PendingOwnable__NotOwner.selector);
vm.expectRevert(
abi.encodeWithSelector(
ISafeAccessControlEnumerable.SafeAccessControlEnumerable__OnlyOwnerOrRole.selector,
ALICE,
joeDexLens.DATA_FEED_MANAGER_ROLE()
)
);
joeDexLens.addUSDDataFeed(address1, df);

vm.expectRevert(PendingOwnable__NotOwner.selector);
vm.expectRevert(
abi.encodeWithSelector(
ISafeAccessControlEnumerable.SafeAccessControlEnumerable__OnlyOwnerOrRole.selector,
ALICE,
joeDexLens.DATA_FEED_MANAGER_ROLE()
)
);
joeDexLens.addNativeDataFeed(address1, df);

vm.expectRevert(PendingOwnable__NotOwner.selector);
vm.expectRevert(
abi.encodeWithSelector(
ISafeAccessControlEnumerable.SafeAccessControlEnumerable__OnlyOwnerOrRole.selector,
ALICE,
joeDexLens.DATA_FEED_MANAGER_ROLE()
)
);
joeDexLens.setUSDDataFeedWeight(address1, address1, weight1);

vm.expectRevert(PendingOwnable__NotOwner.selector);
vm.expectRevert(
abi.encodeWithSelector(
ISafeAccessControlEnumerable.SafeAccessControlEnumerable__OnlyOwnerOrRole.selector,
ALICE,
joeDexLens.DATA_FEED_MANAGER_ROLE()
)
);
joeDexLens.setNativeDataFeedWeight(address1, address1, weight1);

vm.expectRevert(PendingOwnable__NotOwner.selector);
vm.expectRevert(
abi.encodeWithSelector(
ISafeAccessControlEnumerable.SafeAccessControlEnumerable__OnlyOwnerOrRole.selector,
ALICE,
joeDexLens.DATA_FEED_MANAGER_ROLE()
)
);
joeDexLens.removeUSDDataFeed(address1, address1);

vm.expectRevert(PendingOwnable__NotOwner.selector);
vm.expectRevert(
abi.encodeWithSelector(
ISafeAccessControlEnumerable.SafeAccessControlEnumerable__OnlyOwnerOrRole.selector,
ALICE,
joeDexLens.DATA_FEED_MANAGER_ROLE()
)
);
joeDexLens.removeNativeDataFeed(address1, address1);

IJoeDexLens.DataFeed[] memory dfSingleton = getDataFeedSingleton(df);

vm.expectRevert(PendingOwnable__NotOwner.selector);
vm.expectRevert(
abi.encodeWithSelector(
ISafeAccessControlEnumerable.SafeAccessControlEnumerable__OnlyOwnerOrRole.selector,
ALICE,
joeDexLens.DATA_FEED_MANAGER_ROLE()
)
);
joeDexLens.addUSDDataFeeds(usdcSingleton, dfSingleton);

vm.expectRevert(PendingOwnable__NotOwner.selector);
vm.expectRevert(
abi.encodeWithSelector(
ISafeAccessControlEnumerable.SafeAccessControlEnumerable__OnlyOwnerOrRole.selector,
ALICE,
joeDexLens.DATA_FEED_MANAGER_ROLE()
)
);
joeDexLens.addNativeDataFeeds(wNativeSingleton, dfSingleton);

uint88[] memory uint8Singleton = getUint88Singleton(1);

vm.expectRevert(PendingOwnable__NotOwner.selector);
vm.expectRevert(
abi.encodeWithSelector(
ISafeAccessControlEnumerable.SafeAccessControlEnumerable__OnlyOwnerOrRole.selector,
ALICE,
joeDexLens.DATA_FEED_MANAGER_ROLE()
)
);
joeDexLens.setUSDDataFeedsWeights(usdcSingleton, usdcSingleton, uint8Singleton);

vm.expectRevert(PendingOwnable__NotOwner.selector);
vm.expectRevert(
abi.encodeWithSelector(
ISafeAccessControlEnumerable.SafeAccessControlEnumerable__OnlyOwnerOrRole.selector,
ALICE,
joeDexLens.DATA_FEED_MANAGER_ROLE()
)
);
joeDexLens.setNativeDataFeedsWeights(wNativeSingleton, wNativeSingleton, uint8Singleton);

vm.expectRevert(PendingOwnable__NotOwner.selector);
vm.expectRevert(
abi.encodeWithSelector(
ISafeAccessControlEnumerable.SafeAccessControlEnumerable__OnlyOwnerOrRole.selector,
ALICE,
joeDexLens.DATA_FEED_MANAGER_ROLE()
)
);
joeDexLens.removeUSDDataFeeds(usdcSingleton, usdcSingleton);

vm.expectRevert(PendingOwnable__NotOwner.selector);
vm.expectRevert(
abi.encodeWithSelector(
ISafeAccessControlEnumerable.SafeAccessControlEnumerable__OnlyOwnerOrRole.selector,
ALICE,
joeDexLens.DATA_FEED_MANAGER_ROLE()
)
);
joeDexLens.removeNativeDataFeeds(wNativeSingleton, wNativeSingleton);

vm.stopPrank();
Expand Down
35 changes: 17 additions & 18 deletions test/JoeDexLens.DataFeed.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ contract TestJoeDexLens is TestHelper {
IJoeDexLens.DataFeed memory df = IJoeDexLens.DataFeed(address(1), 1, IJoeDexLens.dfType.CHAINLINK);
joeDexLens.addUSDDataFeed(wNative, df);

vm.expectRevert(abi.encodeWithSelector(JoeDexLens__NullWeight.selector));
vm.expectRevert(abi.encodeWithSelector(IJoeDexLens.JoeDexLens__NullWeight.selector));
joeDexLens.setUSDDataFeedWeight(wNative, df.dfAddress, 0);

joeDexLens.setUSDDataFeedWeight(wNative, df.dfAddress, 1e18);
Expand All @@ -70,7 +70,7 @@ contract TestJoeDexLens is TestHelper {
IJoeDexLens.DataFeed memory df = IJoeDexLens.DataFeed(address(1), 1, IJoeDexLens.dfType.CHAINLINK);
joeDexLens.addNativeDataFeed(USDC, df);

vm.expectRevert(abi.encodeWithSelector(JoeDexLens__NullWeight.selector));
vm.expectRevert(abi.encodeWithSelector(IJoeDexLens.JoeDexLens__NullWeight.selector));
joeDexLens.setNativeDataFeedWeight(USDC, df.dfAddress, 0);

joeDexLens.setNativeDataFeedWeight(USDC, df.dfAddress, 1e18);
Expand All @@ -94,17 +94,23 @@ contract TestJoeDexLens is TestHelper {
joeDexLens.addUSDDataFeeds(tokens, dataFeeds);

vm.expectRevert(
abi.encodeWithSelector(JoeDexLens__DataFeedAlreadyAdded.selector, USDC, tokens[0], dataFeeds[0].dfAddress)
abi.encodeWithSelector(
IJoeDexLens.JoeDexLens__DataFeedAlreadyAdded.selector, USDC, tokens[0], dataFeeds[0].dfAddress
)
);
joeDexLens.addUSDDataFeeds(tokens, dataFeeds);

vm.expectRevert(
abi.encodeWithSelector(JoeDexLens__DataFeedAlreadyAdded.selector, USDC, tokens[0], dataFeeds[0].dfAddress)
abi.encodeWithSelector(
IJoeDexLens.JoeDexLens__DataFeedAlreadyAdded.selector, USDC, tokens[0], dataFeeds[0].dfAddress
)
);
joeDexLens.addUSDDataFeed(tokens[0], dataFeeds[0]);

vm.expectRevert(
abi.encodeWithSelector(JoeDexLens__DataFeedAlreadyAdded.selector, USDC, tokens[1], dataFeeds[1].dfAddress)
abi.encodeWithSelector(
IJoeDexLens.JoeDexLens__DataFeedAlreadyAdded.selector, USDC, tokens[1], dataFeeds[1].dfAddress
)
);
joeDexLens.addUSDDataFeed(tokens[1], dataFeeds[1]);

Expand All @@ -124,7 +130,9 @@ contract TestJoeDexLens is TestHelper {
joeDexLens.removeUSDDataFeed(tokens[0], dataFeeds[0].dfAddress);

vm.expectRevert(
abi.encodeWithSelector(JoeDexLens__DataFeedNotInSet.selector, USDC, tokens[0], dataFeeds[0].dfAddress)
abi.encodeWithSelector(
IJoeDexLens.JoeDexLens__DataFeedNotInSet.selector, USDC, tokens[0], dataFeeds[0].dfAddress
)
);
joeDexLens.removeUSDDataFeed(tokens[0], dataFeeds[0].dfAddress);
USDTDataFeeds = joeDexLens.getUSDDataFeeds(USDT);
Expand Down Expand Up @@ -189,30 +197,21 @@ contract TestJoeDexLens is TestHelper {

vm.expectRevert(
abi.encodeWithSelector(
JoeDexLens__DataFeedAlreadyAdded.selector,
wNative,
tokens[0],
dataFeeds[0].dfAddress
IJoeDexLens.JoeDexLens__DataFeedAlreadyAdded.selector, wNative, tokens[0], dataFeeds[0].dfAddress
)
);
joeDexLens.addNativeDataFeeds(tokens, dataFeeds);

vm.expectRevert(
abi.encodeWithSelector(
JoeDexLens__DataFeedAlreadyAdded.selector,
wNative,
tokens[0],
dataFeeds[0].dfAddress
IJoeDexLens.JoeDexLens__DataFeedAlreadyAdded.selector, wNative, tokens[0], dataFeeds[0].dfAddress
)
);
joeDexLens.addNativeDataFeed(tokens[0], dataFeeds[0]);

vm.expectRevert(
abi.encodeWithSelector(
JoeDexLens__DataFeedAlreadyAdded.selector,
wNative,
tokens[1],
dataFeeds[1].dfAddress
IJoeDexLens.JoeDexLens__DataFeedAlreadyAdded.selector, wNative, tokens[1], dataFeeds[1].dfAddress
)
);
joeDexLens.addNativeDataFeed(tokens[1], dataFeeds[1]);
Expand Down
Loading

0 comments on commit 1ee9581

Please sign in to comment.