Skip to content

Commit d880ad2

Browse files
fix: error in curve integration of ExchangeIssuanceLeveraged (#133)
* Add double check on returned dy * Remove calculator call and just swap all of maxAmountIn * Fix wrong value in weth deposit * chore(CI): pin node-version to 16. as a temporary fix to our hardhat dep version not supporting node 18. --------- Co-authored-by: SnakePoison <[email protected]>
1 parent 4f98409 commit d880ad2

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

.github/workflows/publish.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v3
15+
- uses: actions/setup-node@v3
16+
with:
17+
node-version: 16
1518
- name: copy env
1619
run: cp .env.default .env
1720
- name: install

contracts/exchangeIssuance/DEXAdapter.sol

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -420,27 +420,27 @@ library DEXAdapter {
420420
require(_path.length == 2, "ExchangeIssuance: CURVE_WRONG_PATH_LENGTH");
421421
(int128 i, int128 j) = _getCoinIndices(_pool, _path[0], _path[1], ICurveAddressProvider(_addresses.curveAddressProvider));
422422

423-
uint256 amountIn = _getAmountInCurve(
424-
_pool,
425-
i,
426-
j,
427-
_amountOut,
428-
_addresses
429-
);
430-
require(amountIn <= _maxAmountIn, "ExchangeIssuance: CURVE_OVERSPENT");
431423

432424
if(_path[0] == ETH_ADDRESS){
433-
IWETH(_addresses.weth).withdraw(amountIn);
425+
IWETH(_addresses.weth).withdraw(_maxAmountIn);
434426
}
435427

436-
uint256 returnedAmountOut = _exchangeCurve(i, j, _pool, amountIn, _amountOut, _path[0]);
428+
uint256 returnedAmountOut = _exchangeCurve(i, j, _pool, _maxAmountIn, _amountOut, _path[0]);
437429
require(_amountOut <= returnedAmountOut, "ExchangeIssuance: CURVE_UNDERBOUGHT");
438430

431+
uint256 swappedBackAmountIn;
432+
if(returnedAmountOut > _amountOut){
433+
swappedBackAmountIn = _exchangeCurve(j, i, _pool, returnedAmountOut.sub(_amountOut), 0, _path[1]);
434+
if(_path[0] == ETH_ADDRESS){
435+
IWETH(_addresses.weth).deposit{ value: swappedBackAmountIn }();
436+
}
437+
}
438+
439439
if(_path[_path.length-1] == ETH_ADDRESS){
440-
IWETH(_addresses.weth).deposit{ value: returnedAmountOut }();
440+
IWETH(_addresses.weth).deposit{ value: _amountOut }();
441441
}
442442

443-
return amountIn;
443+
return _maxAmountIn.sub(swappedBackAmountIn);
444444
}
445445

446446
function _exchangeCurve(

0 commit comments

Comments
 (0)