Skip to content

Commit 2278397

Browse files
committed
feat(flashMint): Support for fixed input Issuance (#169)
* Copy paste FlashMintLeveraged as starting point * Fix tests * Remove debug logs * Correct wrong eth logic, still failing because eth is sent back prematurely * Fix lint failure * Fix eth issuance by adjusting handling of input token, only paying back at the end * Fix fixedSetAmount issuance method and add related tests * Add redemExactSet tests back in * Adjust redemption methods * First version of exact output redemption * Add redemSetForExactETH method * Fix fixedOutputRedeem methods * copy paste ethereum integration test to new arbitrum integration test folder * Adjust arbitrum integration test addresses * Fix arbitrum integration test setup * More test fixes * Arbitrum tests green * Add arbitrum integration tests to ci * Set Arbitrum rpc url in env variables * update solidity-coverage * Remove ethereum integration tests for flashmintextended * Return excess eth in issueSetFromExactETH * Swap Input Token to ETH * Add swap data to ETH for redeem method * Temporarily comment out non-integration tests * Contract fixes * Fix test * More contract changes * Return amount of set token obtained from fixed input / output methods * Add maxIterations check * Add docstring comments and fix maxIterations check * more docstrings * Test issuance / redemption from / to usdc * Temporarily comment out polygon tests * Add maxGasRebate to protect against misconfiguration * Fix contract bug regarding eth rebate opt out * Extend tests * Re-Trigger CI * Use node 20 in github actions * Bump hardhat version * Update circleci node version * fix tests * fix tests * Deactivate optimism tests * only run optimistic auction rebalance tests in eth integration pipeline * fix tests * Inline doc comment * Remove test step from publish workflow * Fix tests
1 parent f2907ac commit 2278397

16 files changed

+2243
-749
lines changed

.circleci/config.yml

Lines changed: 57 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version: 2
33
jobs:
44
checkout_and_compile:
55
docker:
6-
- image: cimg/node:16.18
6+
- image: cimg/node:20.12.2
77
working_directory: ~/index-coop-smart-contracts
88
steps:
99
- checkout
@@ -33,7 +33,7 @@ jobs:
3333
- ~/index-coop-smart-contracts
3434
test:
3535
docker:
36-
- image: cimg/node:16.18
36+
- image: cimg/node:20.12.2
3737
working_directory: ~/index-coop-smart-contracts
3838
parallelism: 2
3939
steps:
@@ -60,7 +60,7 @@ jobs:
6060
6161
test_integration_polygon:
6262
docker:
63-
- image: cimg/node:16.18
63+
- image: cimg/node:20.12.2
6464
working_directory: ~/index-coop-smart-contracts
6565
steps:
6666
- setup_remote_docker:
@@ -83,7 +83,7 @@ jobs:
8383

8484
test_integration_optimism:
8585
docker:
86-
- image: cimg/node:16.18
86+
- image: cimg/node:20.12.2
8787
working_directory: ~/index-coop-smart-contracts
8888
steps:
8989
- setup_remote_docker:
@@ -106,7 +106,7 @@ jobs:
106106

107107
test_integration_ethereum:
108108
docker:
109-
- image: cimg/node:16.18
109+
- image: cimg/node:20.12.2
110110
working_directory: ~/index-coop-smart-contracts
111111
steps:
112112
- setup_remote_docker:
@@ -129,7 +129,7 @@ jobs:
129129

130130
coverage:
131131
docker:
132-
- image: cimg/node:16.18
132+
- image: cimg/node:20.12.2
133133
working_directory: ~/index-coop-smart-contracts
134134
parallelism: 2
135135
steps:
@@ -166,7 +166,7 @@ jobs:
166166

167167
report_coverage:
168168
docker:
169-
- image: cimg/node:16.18
169+
- image: cimg/node:20.12.2
170170
working_directory: ~/index-coop-smart-contracts
171171
steps:
172172
- attach_workspace:
@@ -184,26 +184,63 @@ jobs:
184184
command: |
185185
cat coverage/lcov.info | ./node_modules/.bin/coveralls
186186
187+
test_integration_arbitrum:
188+
docker:
189+
- image: cimg/node:20.12.2
190+
working_directory: ~/index-coop-smart-contracts
191+
steps:
192+
- setup_remote_docker:
193+
docker_layer_caching: false
194+
- run:
195+
name: Fetch solc version
196+
command: docker pull ethereum/solc:0.6.10
197+
- restore_cache:
198+
key: compiled-env-{{ .Environment.CIRCLE_SHA1 }}
199+
- run:
200+
name: Set Up Environment Variables
201+
command: cp .env.default .env
202+
- run:
203+
name: Test RPC
204+
command: yarn chain:fork:arbitrum
205+
environment:
206+
ARBITRUM_RPC_URL: https://arb-mainnet.g.alchemy.com/v2/NpgutFt2TfCFgUsHixNBsyoIkdgfg6tH
207+
NETWORK: arbitrum
208+
FORK: TRUE
209+
background: true
210+
- run:
211+
name: Hardhat Test
212+
environment:
213+
ARBITRUM_RPC_URL: https://arb-mainnet.g.alchemy.com/v2/NpgutFt2TfCFgUsHixNBsyoIkdgfg6tH
214+
NETWORK: arbitrum
215+
FORK: TRUE
216+
command: yarn run test:integration:arbitrum
217+
187218
workflows:
188219
version: 2
189220
build-and-test:
190221
jobs:
191222
- checkout_and_compile
192-
- test:
193-
requires:
194-
- checkout_and_compile
223+
# TODO: Comment back in when adding a new non-integration test (and use .only() to avoid rerunning all the old tests)
224+
# - test:
225+
# requires:
226+
# - checkout_and_compile
195227
- test_integration_ethereum:
196228
requires:
197229
- checkout_and_compile
198-
- test_integration_polygon:
199-
requires:
200-
- checkout_and_compile
201-
- test_integration_optimism:
230+
# TODO: Reactivate when developing new contract on polygon (and use .only() to avoid rerunning all the old tests)
231+
# - test_integration_polygon:
232+
# requires:
233+
# - checkout_and_compile
234+
# TODO: Reactivate when developing new contract on optimism (and use .only() to avoid rerunning all the old tests)
235+
# - test_integration_optimism:
236+
# requires:
237+
# - checkout_and_compile
238+
- test_integration_arbitrum:
202239
requires:
203240
- checkout_and_compile
204-
- coverage:
205-
requires:
206-
- checkout_and_compile
207-
- report_coverage:
208-
requires:
209-
- coverage
241+
# - coverage:
242+
# requires:
243+
# - checkout_and_compile
244+
# - report_coverage:
245+
# requires:
246+
# - coverage

.github/workflows/publish.yaml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,13 @@ jobs:
1414
- uses: actions/checkout@v3
1515
- uses: actions/setup-node@v3
1616
with:
17-
node-version: 16
17+
node-version: 20
1818
- name: copy env
1919
run: cp .env.default .env
2020
- name: install
2121
run: yarn
2222
- name: build
2323
run: yarn build
24-
- name: test
25-
run: |
26-
yarn chain &
27-
yarn test
2824

2925
publish:
3026
runs-on: ubuntu-latest
@@ -34,7 +30,7 @@ jobs:
3430
- uses: actions/checkout@v2
3531
- uses: actions/setup-node@v3
3632
with:
37-
node-version: 16
33+
node-version: 20
3834
- name: copy env
3935
run: cp .env.default .env
4036
- name: install

contracts/exchangeIssuance/DEXAdapter.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ library DEXAdapter {
100100
external
101101
returns (uint256)
102102
{
103-
if (_swapData.path[0] == _swapData.path[_swapData.path.length -1]) {
103+
if (_swapData.path.length == 0 || _swapData.path[0] == _swapData.path[_swapData.path.length -1]) {
104104
return _amountIn;
105105
}
106106

@@ -151,7 +151,7 @@ library DEXAdapter {
151151
external
152152
returns (uint256 amountIn)
153153
{
154-
if (_swapData.path[0] == _swapData.path[_swapData.path.length -1]) {
154+
if (_swapData.path.length == 0 || _swapData.path[0] == _swapData.path[_swapData.path.length -1]) {
155155
return _amountOut;
156156
}
157157

contracts/exchangeIssuance/FlashMintLeveraged.sol

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { DEXAdapter } from "./DEXAdapter.sol";
3636
import {IVault, IFlashLoanRecipient} from "../interfaces/external/balancer-v2/IVault.sol";
3737
import {IPool} from "../interfaces/IPool.sol";
3838

39+
3940
/**
4041
* @title FlashMintLeveraged
4142
* @author Index Coop
@@ -284,6 +285,7 @@ contract FlashMintLeveraged is ReentrancyGuard, IFlashLoanRecipient{
284285
DEXAdapter.SwapData memory _swapDataOutputToken
285286
)
286287
external
288+
virtual
287289
nonReentrant
288290
{
289291
_initiateRedemption(
@@ -315,6 +317,7 @@ contract FlashMintLeveraged is ReentrancyGuard, IFlashLoanRecipient{
315317
DEXAdapter.SwapData memory _swapDataOutputToken
316318
)
317319
external
320+
virtual
318321
nonReentrant
319322
{
320323
_initiateRedemption(
@@ -346,6 +349,7 @@ contract FlashMintLeveraged is ReentrancyGuard, IFlashLoanRecipient{
346349
DEXAdapter.SwapData memory _swapDataInputToken
347350
)
348351
external
352+
virtual
349353
nonReentrant
350354
{
351355
_initiateIssuance(
@@ -373,6 +377,7 @@ contract FlashMintLeveraged is ReentrancyGuard, IFlashLoanRecipient{
373377
DEXAdapter.SwapData memory _swapDataInputToken
374378
)
375379
external
380+
virtual
376381
payable
377382
nonReentrant
378383
{
@@ -784,6 +789,7 @@ contract FlashMintLeveraged is ReentrancyGuard, IFlashLoanRecipient{
784789
DEXAdapter.SwapData memory _swapData
785790
)
786791
internal
792+
virtual
787793
returns (uint256)
788794
{
789795
if(address(_outputToken) == _collateralToken){
@@ -820,6 +826,7 @@ contract FlashMintLeveraged is ReentrancyGuard, IFlashLoanRecipient{
820826
DEXAdapter.SwapData memory _swapData
821827
)
822828
internal
829+
virtual
823830
isValidPath(_swapData.path, _collateralToken, addresses.weth)
824831
returns(uint256)
825832
{
@@ -958,6 +965,7 @@ contract FlashMintLeveraged is ReentrancyGuard, IFlashLoanRecipient{
958965
DEXAdapter.SwapData memory _swapData
959966
)
960967
internal
968+
virtual
961969
returns (uint256)
962970
{
963971
if(address(_inputToken) == _collateralToken){
@@ -998,6 +1006,7 @@ contract FlashMintLeveraged is ReentrancyGuard, IFlashLoanRecipient{
9981006

9991007
)
10001008
internal
1009+
virtual
10011010
returns(uint256)
10021011
{
10031012
IWETH(addresses.weth).deposit{value: _maxAmountEth}();

0 commit comments

Comments
 (0)