Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
FlattestWhite committed Oct 1, 2023
1 parent 13aaa83 commit 0c328e2
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 24 deletions.
30 changes: 13 additions & 17 deletions contracts/exchangeIssuance/DEXAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { ICurveCalculator } from "../interfaces/external/ICurveCalculator.sol";
import { ICurveAddressProvider } from "../interfaces/external/ICurveAddressProvider.sol";
import { ICurvePoolRegistry } from "../interfaces/external/ICurvePoolRegistry.sol";
import { ICurvePool } from "../interfaces/external/ICurvePool.sol";
import { ISwapRouter} from "../interfaces/external/ISwapRouter.sol";
import { ISwapRouter02 } from "../interfaces/external/ISwapRouter02.sol";
import { IQuoter } from "../interfaces/IQuoter.sol";
import { IWETH } from "../interfaces/IWETH.sol";
import { PreciseUnitMath } from "../lib/PreciseUnitMath.sol";
Expand Down Expand Up @@ -119,7 +119,7 @@ library DEXAdapter {
_swapData.fees,
_amountIn,
_minAmountOut,
ISwapRouter(_addresses.uniV3Router)
ISwapRouter02(_addresses.uniV3Router)
);
} else {
return _swapExactTokensForTokensUniV2(
Expand Down Expand Up @@ -170,7 +170,7 @@ library DEXAdapter {
_swapData.fees,
_amountOut,
_maxAmountIn,
ISwapRouter(_addresses.uniV3Router)
ISwapRouter0202(_addresses.uniV3Router)
);
} else {
return _swapTokensForExactTokensUniV2(
Expand Down Expand Up @@ -326,7 +326,7 @@ library DEXAdapter {
uint24[] memory _fees,
uint256 _amountOut,
uint256 _maxAmountIn,
ISwapRouter _uniV3Router
ISwapRouter02 _uniV3Router
)
private
returns(uint256)
Expand All @@ -335,25 +335,23 @@ library DEXAdapter {
require(_path.length == _fees.length + 1, "ExchangeIssuance: PATHS_FEES_MISMATCH");
_safeApprove(IERC20(_path[0]), address(_uniV3Router), _maxAmountIn);
if(_path.length == 2){
ISwapRouter.ExactOutputSingleParams memory params =
ISwapRouter.ExactOutputSingleParams({
ISwapRouter02.ExactOutputSingleParams memory params =
ISwapRouter02.ExactOutputSingleParams({
tokenIn: _path[0],
tokenOut: _path[1],
fee: _fees[0],
recipient: address(this),
deadline: block.timestamp,
amountOut: _amountOut,
amountInMaximum: _maxAmountIn,
sqrtPriceLimitX96: 0
});
return _uniV3Router.exactOutputSingle(params);
} else {
bytes memory pathV3 = _encodePathV3(_path, _fees, true);
ISwapRouter.ExactOutputParams memory params =
ISwapRouter.ExactOutputParams({
ISwapRouter02.ExactOutputParams memory params =
ISwapRouter02.ExactOutputParams({
path: pathV3,
recipient: address(this),
deadline: block.timestamp,
amountOut: _amountOut,
amountInMaximum: _maxAmountIn
});
Expand Down Expand Up @@ -627,33 +625,31 @@ library DEXAdapter {
uint24[] memory _fees,
uint256 _amountIn,
uint256 _minAmountOut,
ISwapRouter _uniV3Router
ISwapRouter02 _uniV3Router
)
private
returns (uint256)
{
require(_path.length == _fees.length + 1, "ExchangeIssuance: PATHS_FEES_MISMATCH");
_safeApprove(IERC20(_path[0]), address(_uniV3Router), _amountIn);
if(_path.length == 2){
ISwapRouter.ExactInputSingleParams memory params =
ISwapRouter.ExactInputSingleParams({
ISwapRouter02.ExactInputSingleParams memory params =
ISwapRouter02.ExactInputSingleParams({
tokenIn: _path[0],
tokenOut: _path[1],
fee: _fees[0],
recipient: address(this),
deadline: block.timestamp,
amountIn: _amountIn,
amountOutMinimum: _minAmountOut,
sqrtPriceLimitX96: 0
});
return _uniV3Router.exactInputSingle(params);
} else {
bytes memory pathV3 = _encodePathV3(_path, _fees, false);
ISwapRouter.ExactInputParams memory params =
ISwapRouter.ExactInputParams({
ISwapRouter02.ExactInputParams memory params =
ISwapRouter02.ExactInputParams({
path: pathV3,
recipient: address(this),
deadline: block.timestamp,
amountIn: _amountIn,
amountOutMinimum: _minAmountOut
});
Expand Down
12 changes: 5 additions & 7 deletions contracts/exchangeIssuance/FlashMintPerp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pragma experimental ABIEncoderV2;

import { IQuoter } from "../interfaces/IQuoter.sol";
import { IUniswapV3SwapCallback } from "../interfaces/IUniswapV3SwapCallback.sol";
import { ISwapRouter} from "../interfaces/external/ISwapRouter.sol";
import { ISwapRouter02 } from "../interfaces/external/ISwapRouter02.sol";
import { Address } from "@openzeppelin/contracts/utils/Address.sol";
import { Context } from "@openzeppelin/contracts/GSN/Context.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
Expand Down Expand Up @@ -51,7 +51,7 @@ contract FlashMintPerp is Withdrawable {
////////////// State //////////////

ISlippageIssuanceModule public immutable slippageIssuanceModule;
ISwapRouter public immutable uniV3Router;
ISwapRouter02 public immutable uniV3Router;
IQuoter public immutable uniV3Quoter;
IERC20 public immutable usdc;
mapping (ISetToken => SetPoolInfo) public setPoolInfo;
Expand All @@ -67,7 +67,7 @@ contract FlashMintPerp is Withdrawable {
////////////// Constructor //////////////

constructor(
ISwapRouter _uniV3Router,
ISwapRouter02 _uniV3Router,
IQuoter _uniV3Quoter,
ISlippageIssuanceModule _slippageIssuanceModule,
IERC20 _usdc
Expand Down Expand Up @@ -255,10 +255,9 @@ contract FlashMintPerp is Withdrawable {
uint256 spotAssetQuantity = _spotAssetQuantity(_setToken, _amount);

// Trade USDC for exact spot token
ISwapRouter.ExactOutputParams memory spotTokenParams = ISwapRouter.ExactOutputParams(
ISwapRouter02.ExactOutputParams memory spotTokenParams = ISwapRouter02.ExactOutputParams(
setPoolInfo[_setToken].spotToUsdcRoute,
address(this),
block.timestamp,
spotAssetQuantity.add(1), // Add 1 wei
PreciseUnitMath.maxUint256() // No need for slippage check
);
Expand Down Expand Up @@ -316,10 +315,9 @@ contract FlashMintPerp is Withdrawable {
spotAssetQuantity = spotTokenBalance;
}

ISwapRouter.ExactInputParams memory spotTokenParams = ISwapRouter.ExactInputParams(
ISwapRouter02.ExactInputParams memory spotTokenParams = ISwapRouter02.ExactInputParams(
setPoolInfo[_setToken].spotToUsdcRoute,
address(this),
block.timestamp,
spotAssetQuantity.sub(1), // Leave 1 wei
0 // No need for slippage check
);
Expand Down
127 changes: 127 additions & 0 deletions contracts/interfaces/external/ISwapRouter02.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.6.10;
pragma experimental ABIEncoderV2;

interface ISwapRouter02 {
struct IncreaseLiquidityParams {
address token0;
address token1;
uint256 tokenId;
uint256 amount0Min;
uint256 amount1Min;
}

struct MintParams {
address token0;
address token1;
uint24 fee;
int24 tickLower;
int24 tickUpper;
uint256 amount0Min;
uint256 amount1Min;
address recipient;
}

struct ExactInputParams {
bytes path;
address recipient;
uint256 amountIn;
uint256 amountOutMinimum;
}

struct ExactInputSingleParams {
address tokenIn;
address tokenOut;
uint24 fee;
address recipient;
uint256 amountIn;
uint256 amountOutMinimum;
uint160 sqrtPriceLimitX96;
}

struct ExactOutputParams {
bytes path;
address recipient;
uint256 amountOut;
uint256 amountInMaximum;
}

struct ExactOutputSingleParams {
address tokenIn;
address tokenOut;
uint24 fee;
address recipient;
uint256 amountOut;
uint256 amountInMaximum;
uint160 sqrtPriceLimitX96;
}

function WETH9() external view returns (address);
function approveMax(address token) external payable;
function approveMaxMinusOne(address token) external payable;
function approveZeroThenMax(address token) external payable;
function approveZeroThenMaxMinusOne(address token) external payable;
function callPositionManager(bytes memory data) external payable returns (bytes memory result);
function checkOracleSlippage(
bytes[] memory paths,
uint128[] memory amounts,
uint24 maximumTickDivergence,
uint32 secondsAgo
) external view;
function checkOracleSlippage(bytes memory path, uint24 maximumTickDivergence, uint32 secondsAgo) external view;
function exactInput(ExactInputParams memory params) external payable returns (uint256 amountOut);
function exactInputSingle(ExactInputSingleParams memory params) external payable returns (uint256 amountOut);
function exactOutput(ExactOutputParams memory params) external payable returns (uint256 amountIn);
function exactOutputSingle(ExactOutputSingleParams memory params) external payable returns (uint256 amountIn);
function factory() external view returns (address);
function factoryV2() external view returns (address);
function getApprovalType(address token, uint256 amount) external returns (uint8);
function increaseLiquidity(IncreaseLiquidityParams memory params) external payable returns (bytes memory result);
function mint(MintParams memory params) external payable returns (bytes memory result);
function multicall(bytes32 previousBlockhash, bytes[] memory data) external payable returns (bytes[] memory);
function multicall(uint256 deadline, bytes[] memory data) external payable returns (bytes[] memory);
function multicall(bytes[] memory data) external payable returns (bytes[] memory results);
function positionManager() external view returns (address);
function pull(address token, uint256 value) external payable;
function refundETH() external payable;
function selfPermit(address token, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s)
external
payable;
function selfPermitAllowed(address token, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s)
external
payable;
function selfPermitAllowedIfNecessary(address token, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s)
external
payable;
function selfPermitIfNecessary(address token, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s)
external
payable;
function swapExactTokensForTokens(uint256 amountIn, uint256 amountOutMin, address[] memory path, address to)
external
payable
returns (uint256 amountOut);
function swapTokensForExactTokens(uint256 amountOut, uint256 amountInMax, address[] memory path, address to)
external
payable
returns (uint256 amountIn);
function sweepToken(address token, uint256 amountMinimum, address recipient) external payable;
function sweepToken(address token, uint256 amountMinimum) external payable;
function sweepTokenWithFee(address token, uint256 amountMinimum, uint256 feeBips, address feeRecipient)
external
payable;
function sweepTokenWithFee(
address token,
uint256 amountMinimum,
address recipient,
uint256 feeBips,
address feeRecipient
) external payable;
function uniswapV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes memory _data) external;
function unwrapWETH9(uint256 amountMinimum, address recipient) external payable;
function unwrapWETH9(uint256 amountMinimum) external payable;
function unwrapWETH9WithFee(uint256 amountMinimum, address recipient, uint256 feeBips, address feeRecipient)
external
payable;
function unwrapWETH9WithFee(uint256 amountMinimum, uint256 feeBips, address feeRecipient) external payable;
function wrapETH(uint256 value) external payable;
}

0 comments on commit 0c328e2

Please sign in to comment.