Skip to content

Commit

Permalink
feat(flashMint): Support for fixed input Issuance (#169)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ckoopmann committed Apr 22, 2024
1 parent f2907ac commit 2278397
Show file tree
Hide file tree
Showing 16 changed files with 2,243 additions and 749 deletions.
77 changes: 57 additions & 20 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2
jobs:
checkout_and_compile:
docker:
- image: cimg/node:16.18
- image: cimg/node:20.12.2
working_directory: ~/index-coop-smart-contracts
steps:
- checkout
Expand Down Expand Up @@ -33,7 +33,7 @@ jobs:
- ~/index-coop-smart-contracts
test:
docker:
- image: cimg/node:16.18
- image: cimg/node:20.12.2
working_directory: ~/index-coop-smart-contracts
parallelism: 2
steps:
Expand All @@ -60,7 +60,7 @@ jobs:
test_integration_polygon:
docker:
- image: cimg/node:16.18
- image: cimg/node:20.12.2
working_directory: ~/index-coop-smart-contracts
steps:
- setup_remote_docker:
Expand All @@ -83,7 +83,7 @@ jobs:

test_integration_optimism:
docker:
- image: cimg/node:16.18
- image: cimg/node:20.12.2
working_directory: ~/index-coop-smart-contracts
steps:
- setup_remote_docker:
Expand All @@ -106,7 +106,7 @@ jobs:

test_integration_ethereum:
docker:
- image: cimg/node:16.18
- image: cimg/node:20.12.2
working_directory: ~/index-coop-smart-contracts
steps:
- setup_remote_docker:
Expand All @@ -129,7 +129,7 @@ jobs:

coverage:
docker:
- image: cimg/node:16.18
- image: cimg/node:20.12.2
working_directory: ~/index-coop-smart-contracts
parallelism: 2
steps:
Expand Down Expand Up @@ -166,7 +166,7 @@ jobs:

report_coverage:
docker:
- image: cimg/node:16.18
- image: cimg/node:20.12.2
working_directory: ~/index-coop-smart-contracts
steps:
- attach_workspace:
Expand All @@ -184,26 +184,63 @@ jobs:
command: |
cat coverage/lcov.info | ./node_modules/.bin/coveralls
test_integration_arbitrum:
docker:
- image: cimg/node:20.12.2
working_directory: ~/index-coop-smart-contracts
steps:
- setup_remote_docker:
docker_layer_caching: false
- run:
name: Fetch solc version
command: docker pull ethereum/solc:0.6.10
- restore_cache:
key: compiled-env-{{ .Environment.CIRCLE_SHA1 }}
- run:
name: Set Up Environment Variables
command: cp .env.default .env
- run:
name: Test RPC
command: yarn chain:fork:arbitrum
environment:
ARBITRUM_RPC_URL: https://arb-mainnet.g.alchemy.com/v2/NpgutFt2TfCFgUsHixNBsyoIkdgfg6tH
NETWORK: arbitrum
FORK: TRUE
background: true
- run:
name: Hardhat Test
environment:
ARBITRUM_RPC_URL: https://arb-mainnet.g.alchemy.com/v2/NpgutFt2TfCFgUsHixNBsyoIkdgfg6tH
NETWORK: arbitrum
FORK: TRUE
command: yarn run test:integration:arbitrum

workflows:
version: 2
build-and-test:
jobs:
- checkout_and_compile
- test:
requires:
- checkout_and_compile
# TODO: Comment back in when adding a new non-integration test (and use .only() to avoid rerunning all the old tests)
# - test:
# requires:
# - checkout_and_compile
- test_integration_ethereum:
requires:
- checkout_and_compile
- test_integration_polygon:
requires:
- checkout_and_compile
- test_integration_optimism:
# TODO: Reactivate when developing new contract on polygon (and use .only() to avoid rerunning all the old tests)
# - test_integration_polygon:
# requires:
# - checkout_and_compile
# TODO: Reactivate when developing new contract on optimism (and use .only() to avoid rerunning all the old tests)
# - test_integration_optimism:
# requires:
# - checkout_and_compile
- test_integration_arbitrum:
requires:
- checkout_and_compile
- coverage:
requires:
- checkout_and_compile
- report_coverage:
requires:
- coverage
# - coverage:
# requires:
# - checkout_and_compile
# - report_coverage:
# requires:
# - coverage
8 changes: 2 additions & 6 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,13 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 20
- name: copy env
run: cp .env.default .env
- name: install
run: yarn
- name: build
run: yarn build
- name: test
run: |
yarn chain &
yarn test

publish:
runs-on: ubuntu-latest
Expand All @@ -34,7 +30,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 20
- name: copy env
run: cp .env.default .env
- name: install
Expand Down
4 changes: 2 additions & 2 deletions contracts/exchangeIssuance/DEXAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ library DEXAdapter {
external
returns (uint256)
{
if (_swapData.path[0] == _swapData.path[_swapData.path.length -1]) {
if (_swapData.path.length == 0 || _swapData.path[0] == _swapData.path[_swapData.path.length -1]) {
return _amountIn;
}

Expand Down Expand Up @@ -151,7 +151,7 @@ library DEXAdapter {
external
returns (uint256 amountIn)
{
if (_swapData.path[0] == _swapData.path[_swapData.path.length -1]) {
if (_swapData.path.length == 0 || _swapData.path[0] == _swapData.path[_swapData.path.length -1]) {
return _amountOut;
}

Expand Down
9 changes: 9 additions & 0 deletions contracts/exchangeIssuance/FlashMintLeveraged.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { DEXAdapter } from "./DEXAdapter.sol";
import {IVault, IFlashLoanRecipient} from "../interfaces/external/balancer-v2/IVault.sol";
import {IPool} from "../interfaces/IPool.sol";


/**
* @title FlashMintLeveraged
* @author Index Coop
Expand Down Expand Up @@ -284,6 +285,7 @@ contract FlashMintLeveraged is ReentrancyGuard, IFlashLoanRecipient{
DEXAdapter.SwapData memory _swapDataOutputToken
)
external
virtual
nonReentrant
{
_initiateRedemption(
Expand Down Expand Up @@ -315,6 +317,7 @@ contract FlashMintLeveraged is ReentrancyGuard, IFlashLoanRecipient{
DEXAdapter.SwapData memory _swapDataOutputToken
)
external
virtual
nonReentrant
{
_initiateRedemption(
Expand Down Expand Up @@ -346,6 +349,7 @@ contract FlashMintLeveraged is ReentrancyGuard, IFlashLoanRecipient{
DEXAdapter.SwapData memory _swapDataInputToken
)
external
virtual
nonReentrant
{
_initiateIssuance(
Expand Down Expand Up @@ -373,6 +377,7 @@ contract FlashMintLeveraged is ReentrancyGuard, IFlashLoanRecipient{
DEXAdapter.SwapData memory _swapDataInputToken
)
external
virtual
payable
nonReentrant
{
Expand Down Expand Up @@ -784,6 +789,7 @@ contract FlashMintLeveraged is ReentrancyGuard, IFlashLoanRecipient{
DEXAdapter.SwapData memory _swapData
)
internal
virtual
returns (uint256)
{
if(address(_outputToken) == _collateralToken){
Expand Down Expand Up @@ -820,6 +826,7 @@ contract FlashMintLeveraged is ReentrancyGuard, IFlashLoanRecipient{
DEXAdapter.SwapData memory _swapData
)
internal
virtual
isValidPath(_swapData.path, _collateralToken, addresses.weth)
returns(uint256)
{
Expand Down Expand Up @@ -958,6 +965,7 @@ contract FlashMintLeveraged is ReentrancyGuard, IFlashLoanRecipient{
DEXAdapter.SwapData memory _swapData
)
internal
virtual
returns (uint256)
{
if(address(_inputToken) == _collateralToken){
Expand Down Expand Up @@ -998,6 +1006,7 @@ contract FlashMintLeveraged is ReentrancyGuard, IFlashLoanRecipient{

)
internal
virtual
returns(uint256)
{
IWETH(addresses.weth).deposit{value: _maxAmountEth}();
Expand Down
Loading

0 comments on commit 2278397

Please sign in to comment.