Skip to content

Commit a607e7a

Browse files
ckoopmannChristian KoopmannFlattestWhiteSnakePoison
authored
feat: FixedRebalanceExtension
* Skeleton contract and integration test stub * Adjust getShortfall method * Add codes to handle exchange rate between asset and underlying token * Fix rebalance method * Clean up tests * Comment out rebalance test * Change shortfall function to be based on current value * Fix tests * Break apart selling of surplus positions and buying shortfall positions * Clean up tests * Rename to FixedRebalanceExtension * Rename shorfall/surplus to underweight/overweight and other refactoring * More refactoring and documentation * Add methods to adjust allocations and valid maturities * Add additional test when changing allocation * Add todo comment regarding trading via underlying token * Fix wrong year in license * Allow configuration wether to trade via underlying or asset token * Parameterize tests to run both for trading via asset or underlying token * Reenable optimizer * Add slippage protection * Add test that simulates reaching maturity * Fix maturity expiration test * Fix typos etc in test titles Co-authored-by: Richard Guan <[email protected]> * Fix typo on docstring Co-authored-by: Richard Guan <[email protected]> * Remove unneeded CallArguments struct * Improve test names and add test for getting total fcash position when trading via underlying * Remove unused internal methods * Make some state variables public Co-authored-by: SnakePoison <[email protected]> * Add integration test step in coverage workflow * Add test for wrong minPositions length * Add test for trading only partial share * Fix coverage integration tests * Add test checking operator transfer * Remove validMaturities * Remove validMaturities state variable * Additional tests * Remove coverage step for integration tests since it overwrote the report from unit tests * Remove unused event. Co-authored-by: SnakePoison <[email protected]> * Make setToken immutable variable public Co-authored-by: Christian Koopmann <[email protected]> Co-authored-by: Richard Guan <[email protected]> Co-authored-by: SnakePoison <[email protected]>
1 parent c00d171 commit a607e7a

File tree

12 files changed

+1145
-6
lines changed

12 files changed

+1145
-6
lines changed

contracts/adapters/FixedRebalanceExtension.sol

Lines changed: 400 additions & 0 deletions
Large diffs are not rendered by default.

contracts/interfaces/INotionalProxy.sol

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,62 @@ interface INotionalProxy {
6464

6565
function settleAccount(address account) external;
6666

67+
function getfCashLendFromDeposit(
68+
uint16 currencyId,
69+
uint256 depositAmountExternal,
70+
uint256 maturity,
71+
uint32 minLendRate,
72+
uint256 blockTime,
73+
bool useUnderlying
74+
) external view returns (
75+
uint88 fCashAmount,
76+
uint8 marketIndex,
77+
bytes32 encodedTrade
78+
);
79+
80+
function getDepositFromfCashLend(
81+
uint16 currencyId,
82+
uint256 fCashAmount,
83+
uint256 maturity,
84+
uint32 minLendRate,
85+
uint256 blockTime
86+
) external view returns (
87+
uint256 depositAmountUnderlying,
88+
uint256 depositAmountAsset,
89+
uint8 marketIndex,
90+
bytes32 encodedTrade
91+
);
92+
93+
function getPrincipalFromfCashBorrow(
94+
uint16 currencyId,
95+
uint256 fCashBorrow,
96+
uint256 maturity,
97+
uint32 maxBorrowRate,
98+
uint256 blockTime
99+
) external view returns (
100+
uint256 borrowAmountUnderlying,
101+
uint256 borrowAmountAsset,
102+
uint8 marketIndex,
103+
bytes32 encodedTrade
104+
);
105+
106+
function getfCashBorrowFromPrincipal(
107+
uint16 currencyId,
108+
uint256 borrowedAmountExternal,
109+
uint256 maturity,
110+
uint32 maxBorrowRate,
111+
uint256 blockTime,
112+
bool useUnderlying
113+
) external view returns (
114+
uint88 fCashDebt,
115+
uint8 marketIndex,
116+
bytes32 encodedTrade
117+
);
118+
119+
function initializeMarkets(
120+
uint16 currencyId,
121+
bool flag
122+
) external;
123+
124+
67125
}

contracts/interfaces/INotionalTradeModule.sol

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,43 @@ interface INotionalTradeModule {
99
function owner() external view returns(address);
1010
function settleAccount(address) external;
1111
function setRedeemToUnderlying(ISetToken, bool) external;
12+
function getFCashComponents(ISetToken _setToken) external view returns(address[] memory fCashComponents);
13+
function mintFixedFCashForToken(
14+
ISetToken _setToken,
15+
uint16 _currencyId,
16+
uint40 _maturity,
17+
uint256 _mintAmount,
18+
address _sendToken,
19+
uint256 _maxSendAmount
20+
) external returns(uint256);
21+
function redeemFixedFCashForToken(
22+
ISetToken _setToken,
23+
uint16 _currencyId,
24+
uint40 _maturity,
25+
uint256 _redeemAmount,
26+
address _receiveToken,
27+
uint256 _minReceiveAmount
28+
) external returns(uint256);
29+
30+
function mintFCashForFixedToken(
31+
ISetToken _setToken,
32+
uint16 _currencyId,
33+
uint40 _maturity,
34+
uint256 _minMintAmount,
35+
address _sendToken,
36+
uint256 _sendAmount
37+
) external returns(uint256);
38+
39+
function redeemFCashForFixedToken(
40+
ISetToken _setToken,
41+
uint16 _currencyId,
42+
uint40 _maturity,
43+
uint256 _maxRedeemAmount,
44+
address _receiveToken,
45+
uint256 _receiveAmount,
46+
uint256 _maxReceiveAmountDeviation
47+
) external returns(uint256);
48+
1249

1350
}
1451

contracts/interfaces/IWrappedfCash.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,7 @@ interface IWrappedfCash {
6969
}
7070

7171

72-
interface IWrappedfCashComplete is IWrappedfCash, IERC20 {}
72+
interface IWrappedfCashComplete is IWrappedfCash, IERC20 {
73+
function getMaturity() external view returns (uint40);
74+
}
7375

contracts/lib/PreciseUnitMath.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,4 @@ library PreciseUnitMath {
187187

188188
return result;
189189
}
190-
}
190+
}

contracts/mocks/NotionalTradeModuleMock.sol

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,46 @@ contract NotionalTradeModuleMock is INotionalTradeModule{
4141
function settleAccount(address) external override {
4242
}
4343

44+
function getFCashComponents(ISetToken _setToken) external view override returns(address[] memory fCashComponents) {
45+
}
46+
47+
function mintFixedFCashForToken(
48+
ISetToken _setToken,
49+
uint16 _currencyId,
50+
uint40 _maturity,
51+
uint256 _mintAmount,
52+
address _sendToken,
53+
uint256 _maxSendAmount
54+
) external override returns(uint256 spentAmount) {
55+
}
56+
function redeemFixedFCashForToken(
57+
ISetToken _setToken,
58+
uint16 _currencyId,
59+
uint40 _maturity,
60+
uint256 _redeemAmount,
61+
address _receiveToken,
62+
uint256 _minReceiveAmount
63+
) external override returns(uint256 receivedAmount) {
64+
}
65+
66+
function mintFCashForFixedToken(
67+
ISetToken _setToken,
68+
uint16 _currencyId,
69+
uint40 _maturity,
70+
uint256 _minMintAmount,
71+
address _sendToken,
72+
uint256 _sendAmount
73+
) external override returns(uint256) {}
74+
75+
function redeemFCashForFixedToken(
76+
ISetToken _setToken,
77+
uint16 _currencyId,
78+
uint40 _maturity,
79+
uint256 _maxRedeemAmount,
80+
address _receiveToken,
81+
uint256 _receiveAmount,
82+
uint256 _maxReceiveAmountDeviation
83+
) external override returns(uint256) {}
84+
85+
4486
}

hardhat.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const optimismForkingConfig = {
2424

2525
const mainnetForkingConfig = {
2626
url: "https://eth-mainnet.alchemyapi.io/v2/" + process.env.ALCHEMY_TOKEN,
27-
blockNumber: process.env.LATESTBLOCK ? undefined : 15754500,
27+
blockNumber: process.env.LATESTBLOCK ? undefined : 15981100,
2828
};
2929

3030
const forkingConfig =
@@ -57,7 +57,7 @@ const config: HardhatUserConfig = {
5757
compilers: [
5858
{
5959
version: "0.6.10",
60-
settings: { optimizer: { enabled: true, runs: 200 } },
60+
settings: { optimizer: { enabled: true, runs: 200 } }
6161
},
6262
],
6363
},

test/adapters/airdropExtension.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,4 +374,4 @@ describe("AirdropExtension", () => {
374374
});
375375
});
376376
});
377-
});
377+
});

test/integration/ethereum/addresses.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const PRODUCTION_ADDRESSES = {
1212
USDC: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
1313
cUSDC: "0x39aa39c021dfbae8fac545936693ac917d5e7563",
1414
cDAI: "0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643",
15+
fixedDai: "0x015558c3aB97c9e5a9c8c437C71Bb498B2e5afB3",
1516
},
1617
whales: {
1718
stEth: "0xdc24316b9ae028f1497c275eb9192a3ea0f67022",

0 commit comments

Comments
 (0)