Skip to content

Commit 2845261

Browse files
ckoopmannChristian KoopmannChristian KoopmannChristian Koopmann
authored
feat: Exchange Issuance for Leveraged Tokens (#97)
* Starting point for new Exchange Issuance Contract by combining EIv2 with flashloan interface * Copy EIv2 test suite as starting point for test suite * Addd failing test tryinga flashloan * Test failing due to 0 Balance of AToken * Add function retrieving long / short token addresses and amounts * Copy fli setup from fli strategy extension test * Log out issuance / redemption units in fli strategy integration test * Add engage fliExtension call to test * Fix getLeveraged Token Data * Add method borrowing short token * Delete most of the test setup and start form aaveFLI setup * Engagement of aave token working * Test for skeleton issueExactSetFromLongToken passing * Switch to flashloaning long token * Deposit long token in smart contract * Contract issuing set with borrowed long tokens * Contract swapping short for long token passing * Obtaining shortfall from user passing * Remove unneeded methods copied from original exchange issuance contract * Add some docstring comments * Move param decoding into helper functions to avoid stack too deep error * Add check against max amount input * Add test checking unimplemented method reverting * Emit ExchangeIssue event * remove logs * Cleanup unintended changes * Cleanup log statements * let user pass exchange to use * Approve lending pool once when approving the set token * Reset lending pool allowance to zero before approving maxUint * Updating comment / docstrings * Limit executeOperation to only be called by the lending pool * Finish fist implementation of redemption workflow * Add minAmountOutput check * Add docstring comment * Add function to redeem for custom ERC20 * Issue from erc20 * Redemption to ETH * Full test pipeline green for issuance / redemption * Refactor obtainLongTokens method * Refactor _liquidateLongTokens method * More docstrings * Add separate address for intermediat token * Use intermediate token in trades * Factor out collateralToken into separate variable * Update hardhat and add skeleton integration test * Remove uniswapV2 from exchanges * Deploy exchange issuance contract in integration test * Test issuing ETH2x for Matic passing * Add integration test for redeeming to ETH * Add test issuing / redeeming for long token * Add buffer amount to short token to avoid debt issuance module reverting on redemption * Extend integration test * Relative instead of absolute tolerance on debt amount for redemption * Sync aave leverage module before every issuance / redemption * Pin block in integration tests * Integration test for issuance via erc20 * Remove console logs * Revert "Remove uniswapV2 from exchanges" This reverts commit 7be0c38. * Adjust expected revert messages and remove gasPrice: 0 * Fix broken unittests * Rename Uniswap references to quickswap * Run polygon integration tests in circleci * Add polygon integration test to workflow * Change maxAmountIn when swapping tokens for exact tokens * Various minor changes based on PR feedback * Remove factory variables from the contract and add constructor param documentation * Use struct to contain decoded param values and avoid having decode multiple times * Various minor refactorings and nits from PR review * Factor out implementation of various public helper functions into one internal and one external function to save gas * Remove LongToken from Payment options and instead check inputToken parameter to decide wether or not swap is necessary * Remove LongToken versions of issue/redeem functions * Minor nits / refactorings based on second round of PR comments * Remove paymentParams encoding/decoding * Add check to prevent attacks by initiating a flashloan on behalf of the EI contract * Move max/minAmount checks to the top level of the executeOperation function * Move issuance / redemption workflows into separate helper functions to reduce complexity of executeOperation * Rename long / short to collateral / debt for consistency with naming in existing contracts * Generate leveraged token data only one and add it to the DecodedParams object * Add missing javadocs and rename _amountSetToken to _setAmount for consistency * Add missing parameter in javadoc * Fix misaligned javadoc * Move exchange interaction to separate contract * Add UniV3 integration * Factor out uniV2/V3 versions of swap methods into separate methods * Add method to encode uniV3 path * First try generating uni V3 path from token addresses / fees. Currently failing * fix wrong array indices * Remove unneeded newPath variable * Allow user to pass in swap parameters * Remove generatePath method * Adjust integration test to new interface * Test and fix uniV3 multihops * Add javadocs to new DEXAdapter methods * remove intermediate token address * Adjust integration test to use different fee levels * Minor changes based on PR feedback * Add minAmountOutput parameter for exactInput swap * More refactoring based on pr feedback * More cosmetic refactoring / changes and extensions of the javadocs * More adjustments based on compiler warnings Co-authored-by: Christian Koopmann <[email protected]> Co-authored-by: Christian Koopmann <[email protected]> Co-authored-by: Christian Koopmann <[email protected]>
1 parent 8b7c580 commit 2845261

19 files changed

+3642
-15
lines changed

.circleci/config.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,29 @@ jobs:
8080
name: Hardhat Test
8181
command: yarn test:fork
8282

83+
test_integration_polygon:
84+
docker:
85+
- image: cimg/node:lts
86+
working_directory: ~/index-coop-smart-contracts
87+
steps:
88+
- setup_remote_docker:
89+
docker_layer_caching: false
90+
- run:
91+
name: Fetch solc version
92+
command: docker pull ethereum/solc:0.6.10
93+
- restore_cache:
94+
key: compiled-env-{{ .Environment.CIRCLE_SHA1 }}
95+
- run:
96+
name: Set Up Environment Variables
97+
command: cp .env.default .env
98+
- run:
99+
name: Test RPC
100+
command: yarn chain:fork:polygon
101+
background: true
102+
- run:
103+
name: Hardhat Test
104+
command: yarn test:integration:polygon
105+
83106
coverage:
84107
docker:
85108
- image: cimg/node:lts
@@ -179,6 +202,9 @@ workflows:
179202
- test_forked_network:
180203
requires:
181204
- checkout_and_compile
205+
- test_integration_polygon:
206+
requires:
207+
- checkout_and_compile
182208
- coverage:
183209
requires:
184210
- checkout_and_compile

0 commit comments

Comments
 (0)