Skip to content

Commit f3d1c6c

Browse files
authored
Add FLIRebalanceViewer (#65)
* add basic layout * add basic contract logic and uniswap v3 contracts * add uniswap v3 fixture * fix deployment and constructor test * add needed functions to FLIExtensionMock * add tests * fix bugs and refactor * refactor * add javadocs * improve tests * basic refactoring * add ActionInfo struct to reduce duplication * remove unused code * add more info to ActionInfo * fix indexing of chunk send quantity * refactoring * improve test coverage * remove redundant exchangNames variable
1 parent cac41ca commit f3d1c6c

26 files changed

+1327
-5
lines changed

contracts/interfaces/IFLIStrategyExtension.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ interface IFLIStrategyExtension {
2424
function getMethodology() external view returns (FlexibleLeverageStrategyExtension.MethodologySettings memory);
2525
function getIncentive() external view returns (FlexibleLeverageStrategyExtension.IncentiveSettings memory);
2626
function getExecution() external view returns (FlexibleLeverageStrategyExtension.ExecutionSettings memory);
27+
function getExchangeSettings(string memory _exchangeName) external view returns (FlexibleLeverageStrategyExtension.ExchangeSettings memory);
28+
function getEnabledExchanges() external view returns (string[] memory);
2729

2830
function getCurrentLeverageRatio() external view returns (uint256);
2931

contracts/interfaces/IQuoter.sol

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
pragma solidity 0.6.10;
3+
pragma experimental ABIEncoderV2;
4+
5+
/// @title Quoter Interface
6+
/// @notice Supports quoting the calculated amounts from exact input or exact output swaps
7+
/// @dev These functions are not marked view because they rely on calling non-view functions and reverting
8+
/// to compute the result. They are also not gas efficient and should not be called on-chain.
9+
interface IQuoter {
10+
/// @notice Returns the amount out received for a given exact input swap without executing the swap
11+
/// @param path The path of the swap, i.e. each token pair and the pool fee
12+
/// @param amountIn The amount of the first token to swap
13+
/// @return amountOut The amount of the last token that would be received
14+
function quoteExactInput(bytes memory path, uint256 amountIn) external returns (uint256 amountOut);
15+
16+
/// @notice Returns the amount out received for a given exact input but for a swap of a single pool
17+
/// @param tokenIn The token being swapped in
18+
/// @param tokenOut The token being swapped out
19+
/// @param fee The fee of the token pool to consider for the pair
20+
/// @param amountIn The desired input amount
21+
/// @param sqrtPriceLimitX96 The price limit of the pool that cannot be exceeded by the swap
22+
/// @return amountOut The amount of `tokenOut` that would be received
23+
function quoteExactInputSingle(
24+
address tokenIn,
25+
address tokenOut,
26+
uint24 fee,
27+
uint256 amountIn,
28+
uint160 sqrtPriceLimitX96
29+
) external returns (uint256 amountOut);
30+
31+
/// @notice Returns the amount in required for a given exact output swap without executing the swap
32+
/// @param path The path of the swap, i.e. each token pair and the pool fee. Path must be provided in reverse order
33+
/// @param amountOut The amount of the last token to receive
34+
/// @return amountIn The amount of first token required to be paid
35+
function quoteExactOutput(bytes memory path, uint256 amountOut) external returns (uint256 amountIn);
36+
37+
/// @notice Returns the amount in required to receive the given exact output amount but for a swap of a single pool
38+
/// @param tokenIn The token being swapped in
39+
/// @param tokenOut The token being swapped out
40+
/// @param fee The fee of the token pool to consider for the pair
41+
/// @param amountOut The desired output amount
42+
/// @param sqrtPriceLimitX96 The price limit of the pool that cannot be exceeded by the swap
43+
/// @return amountIn The amount required as the input for the swap in order to receive `amountOut`
44+
function quoteExactOutputSingle(
45+
address tokenIn,
46+
address tokenOut,
47+
uint24 fee,
48+
uint256 amountOut,
49+
uint160 sqrtPriceLimitX96
50+
) external returns (uint256 amountIn);
51+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
pragma solidity 0.6.10;
2+
pragma experimental ABIEncoderV2;
3+
4+
import { FlexibleLeverageStrategyExtension } from "../adapters/FlexibleLeverageStrategyExtension.sol";
5+
6+
// Mock contract for FlexibleLeverageStrategyExtension used to test FLIRebalanceViewer
7+
contract FLIStrategyExtensionMock {
8+
9+
string[] internal shouldRebalanceNames;
10+
FlexibleLeverageStrategyExtension.ShouldRebalance[] internal shouldRebalancesEnums;
11+
12+
uint256[] internal chunkRebalanceSizes;
13+
address internal chunkRebalanceSellAsset;
14+
address internal chunkRebalanceBuyAsset;
15+
16+
FlexibleLeverageStrategyExtension.ContractSettings internal strategy;
17+
18+
mapping(string => FlexibleLeverageStrategyExtension.ExchangeSettings) internal exchangeSettings;
19+
20+
21+
function shouldRebalanceWithBounds(
22+
uint256 /* _customMinLeverageRatio */,
23+
uint256 /* _customMaxLeverageRatio */
24+
)
25+
external
26+
view
27+
returns(string[] memory, FlexibleLeverageStrategyExtension.ShouldRebalance[] memory)
28+
{
29+
return (shouldRebalanceNames, shouldRebalancesEnums);
30+
}
31+
32+
function getChunkRebalanceNotional(
33+
string[] calldata /* _exchangeNames */
34+
)
35+
external
36+
view
37+
returns(uint256[] memory sizes, address sellAsset, address buyAsset)
38+
{
39+
sizes = chunkRebalanceSizes;
40+
sellAsset = chunkRebalanceSellAsset;
41+
buyAsset = chunkRebalanceBuyAsset;
42+
}
43+
44+
function getStrategy() external view returns (FlexibleLeverageStrategyExtension.ContractSettings memory) {
45+
return strategy;
46+
}
47+
48+
function getExchangeSettings(string memory _exchangeName) external view returns (FlexibleLeverageStrategyExtension.ExchangeSettings memory) {
49+
return exchangeSettings[_exchangeName];
50+
}
51+
52+
function getEnabledExchanges() external view returns (string[] memory) {
53+
return shouldRebalanceNames;
54+
}
55+
56+
/* =========== Functions for setting mock state =========== */
57+
58+
function setShouldRebalanceWithBounds(
59+
string[] memory _shouldRebalanceNames,
60+
FlexibleLeverageStrategyExtension.ShouldRebalance[] memory _shouldRebalancesEnums
61+
)
62+
external
63+
{
64+
shouldRebalanceNames = _shouldRebalanceNames;
65+
shouldRebalancesEnums = _shouldRebalancesEnums;
66+
}
67+
68+
function setGetChunkRebalanceWithBounds(
69+
uint256[] memory _chunkRebalanceSizes,
70+
address _chunkRebalanceSellAsset,
71+
address _chunkRebalanceBuyAsset
72+
)
73+
external
74+
{
75+
chunkRebalanceSizes = _chunkRebalanceSizes;
76+
chunkRebalanceSellAsset = _chunkRebalanceSellAsset;
77+
chunkRebalanceBuyAsset = _chunkRebalanceBuyAsset;
78+
}
79+
80+
function setStrategy(FlexibleLeverageStrategyExtension.ContractSettings memory _strategy) external {
81+
strategy = _strategy;
82+
}
83+
84+
function setExchangeSettings(string memory _exchangeName, FlexibleLeverageStrategyExtension.ExchangeSettings memory _settings) external {
85+
exchangeSettings[_exchangeName] = _settings;
86+
}
87+
}

0 commit comments

Comments
 (0)