Skip to content

Commit

Permalink
Switch to Uniswap SwapRouter02 from SwapRouter (#70)
Browse files Browse the repository at this point in the history
We switch to Uniswap's `SwapRouter02` from `SwapRouter` because
`SwapRouter` isn't supported on chains like Base. The routers are mostly
the same, with `SwapRouter02` being newer and having support for Uniswap
v2. However, their interfaces do differ slightly as the swap params for
`SwapRouter02` no longer take a `deadline`. This is fine since a)
recurring swaps don't need a deadline anyways and b) we can use the
QuarkOperation's `expiry` to set the deadline for one-time swaps.

We have to manually import parts of `ISwapRouter02` because one of its
dependencies [locks the compiler
version](Uniswap/swap-router-contracts#72) to
`=0.7.6`, so the library cannot be directly used for higher Solidity
versions without modifications.
  • Loading branch information
kevincheng96 committed Sep 9, 2024
1 parent 09d67e9 commit 4d433bd
Show file tree
Hide file tree
Showing 24 changed files with 335 additions and 138 deletions.
174 changes: 144 additions & 30 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
ApproveAndSwapTest:testSwap() (gas: 285500)
ApproveAndSwapTest:testSwapFailsIfWeExpectedTooMuch() (gas: 364666)
ApproveAndSwapTest:testSwapFailsWithNoApproval() (gas: 122231)
ApproveAndSwapTest:testSwap() (gas: 285492)
ApproveAndSwapTest:testSwapFailsIfWeExpectedTooMuch() (gas: 364765)
ApproveAndSwapTest:testSwapFailsWithNoApproval() (gas: 122254)
CCTPBridge:testBridgeToBase() (gas: 146874)
CometClaimRewardsTest:testClaimComp() (gas: 131265)
CometRepayAndWithdrawMultipleAssetsTest:testInvalidInput() (gas: 68171)
CometRepayAndWithdrawMultipleAssetsTest:testInvalidInput() (gas: 68180)
CometRepayAndWithdrawMultipleAssetsTest:testRepayAndWithdrawMultipleAssets() (gas: 153860)
CometSupplyMultipleAssetsAndBorrowTest:testInvalidInput() (gas: 68114)
CometSupplyMultipleAssetsAndBorrowTest:testInvalidInput() (gas: 68123)
CometSupplyMultipleAssetsAndBorrowTest:testSupplyMultipleAssetsAndBorrow() (gas: 295260)
ConditionalMulticallTest:testConditionalRunEmptyInputIsValid() (gas: 51386)
ConditionalMulticallTest:testConditionalRunInvalidInput() (gas: 68840)
Expand All @@ -19,8 +19,15 @@ EthcallTest:testEthcallShouldReturnCallResult() (gas: 52545)
EthcallTest:testEthcallSupplyUSDCToComet() (gas: 171965)
EthcallTest:testEthcallWithdrawUSDCFromComet() (gas: 296115)
GetDripTest:testDrip() (gas: 120591)
MorphoActionsTest:testRepayAndWithdrawCollateral() (gas: 130575)
MorphoActionsTest:testRepayMaxAndWithdrawCollateral() (gas: 118293)
MorphoActionsTest:testSupplyCollateralAndBorrow() (gas: 250037)
MorphoRewardsActionsTest:testClaim() (gas: 112124)
MorphoRewardsActionsTest:testClaimAll() (gas: 186069)
MorphoVaultActionsTest:testDeposit() (gas: 762206)
MorphoVaultActionsTest:testWithdraw() (gas: 570979)
MulticallTest:testCallcodeToMulticallSucceedsWhenUninitialized() (gas: 83316)
MulticallTest:testCreateSubWalletAndExecute() (gas: 608534)
MulticallTest:testCreateSubWalletAndExecute() (gas: 619226)
MulticallTest:testEmptyInputIsValid() (gas: 50892)
MulticallTest:testExecutorCanMulticallAcrossSubwallets() (gas: 303309)
MulticallTest:testInvalidInput() (gas: 68358)
Expand All @@ -29,23 +36,126 @@ MulticallTest:testMulticallError() (gas: 309667)
MulticallTest:testMulticallShouldReturnCallResults() (gas: 86409)
MulticallTest:testRevertsForInvalidCallContext() (gas: 11574)
MulticallTest:testSupplyWETHWithdrawUSDCOnComet() (gas: 259628)
PaycallTest:testInitializeProperlyFromConstructor() (gas: 6425)
PaycallTest:testPaycallForPayWithUSDT() (gas: 121389)
PaycallTest:testPaycallForPayWithWBTC() (gas: 115864)
PaycallTest:testReturnCallResult() (gas: 89981)
PaycallTest:testRevertsForInvalidCallContext() (gas: 16521)
PaycallTest:testRevertsWhenCostIsMoreThanMaxPaymentCost() (gas: 119258)
PaycallTest:testSimpleCounterAndPayWithUSDC() (gas: 143929)
PaycallTest:testSimpleTransferTokenAndPayWithUSDC() (gas: 139569)
PaycallTest:testSupplyWETHWithdrawUSDCOnCometAndPayWithUSDC() (gas: 300142)
ReplayableTransactionsTest:testCancelRecurringPurchase() (gas: 267995)
ReplayableTransactionsTest:testRecurringPurchaseHappyPath() (gas: 210285)
ReplayableTransactionsTest:testRecurringPurchaseMultiplePurchases() (gas: 365698)
ReplayableTransactionsTest:testRecurringPurchaseWithDifferentCalldata() (gas: 590229)
ReplayableTransactionsTest:testRevertsForExpiredQuarkOperation() (gas: 11893)
ReplayableTransactionsTest:testRevertsForExpiredUniswapParams() (gas: 118215)
ReplayableTransactionsTest:testRevertsForPurchaseBeforeNextPurchasePeriod() (gas: 283863)
ReplayableTransactionsTest:testRevertsForPurchasingOverTheLimit() (gas: 284305)
PaycallTest:testInitializeProperlyFromConstructor() (gas: 6430)
PaycallTest:testPaycallForPayWithUSDT() (gas: 125307)
PaycallTest:testPaycallForPayWithWBTC() (gas: 119793)
PaycallTest:testPaycallRevertsWhenCallReverts() (gas: 72350)
PaycallTest:testReturnCallResult() (gas: 92209)
PaycallTest:testRevertWhenCostIsMoreThanMaxPaymentCost() (gas: 119383)
PaycallTest:testRevertsForInvalidCallContext() (gas: 16562)
PaycallTest:testSimpleCounterAndPayWithUSDC() (gas: 148804)
PaycallTest:testSimpleTransferTokenAndPayWithUSDC() (gas: 144444)
PaycallTest:testSupplyWETHWithdrawUSDCOnCometAndPayWithUSDC() (gas: 305017)
PaycallWrapperTest:testSimpleTransferAndWrapForPaycall() (gas: 1342091)
PriceFeedsTest:testFindPriceFeedPathDirectMatch() (gas: 210653)
PriceFeedsTest:testFindPriceFeedPathDirectMatchWithReverse() (gas: 215730)
PriceFeedsTest:testFindPriceFeedPathNoMatch() (gas: 221293)
PriceFeedsTest:testFindPriceFeedPathOneHopMatch() (gas: 271926)
PriceFeedsTest:testFindPriceFeeds() (gas: 100690)
QuarkBuilderCometBorrowTest:testBorrow() (gas: 19750324)
QuarkBuilderCometBorrowTest:testBorrowFundsUnavailable() (gas: 18786452)
QuarkBuilderCometBorrowTest:testBorrowInvalidInput() (gas: 18586022)
QuarkBuilderCometBorrowTest:testBorrowPayFromBorrow() (gas: 20781060)
QuarkBuilderCometBorrowTest:testBorrowWithAutoWrapper() (gas: 21124862)
QuarkBuilderCometBorrowTest:testBorrowWithBridgedPaymentToken() (gas: 22260790)
QuarkBuilderCometBorrowTest:testBorrowWithBridgedcollateralAsset() (gas: 22323602)
QuarkBuilderCometBorrowTest:testBorrowWithPaycall() (gas: 20721101)
QuarkBuilderCometRepayTest:testCometRepay() (gas: 19692940)
QuarkBuilderCometRepayTest:testCometRepayFundsUnavailable() (gas: 18723824)
QuarkBuilderCometRepayTest:testCometRepayInvalidInput() (gas: 18586338)
QuarkBuilderCometRepayTest:testCometRepayMax() (gas: 20498265)
QuarkBuilderCometRepayTest:testCometRepayMaxCostTooHigh() (gas: 19142820)
QuarkBuilderCometRepayTest:testCometRepayMaxWithBridge() (gas: 22229297)
QuarkBuilderCometRepayTest:testCometRepayPayFromWithdraw() (gas: 20970376)
QuarkBuilderCometRepayTest:testCometRepayWithAutoWrapper() (gas: 21113470)
QuarkBuilderCometRepayTest:testCometRepayWithBridge() (gas: 22309913)
QuarkBuilderCometRepayTest:testCometRepayWithPaycall() (gas: 20612154)
QuarkBuilderCometSupplyTest:testCometSupplyMaxWithBridge() (gas: 19806359)
QuarkBuilderCometSupplyTest:testCometSupplyMaxWithBridgeAndQuotecall() (gas: 20092356)
QuarkBuilderCometSupplyTest:testCometSupplyWithBridge() (gas: 19609730)
QuarkBuilderCometSupplyTest:testCometSupplyWithBridgeAndPaycall() (gas: 19933817)
QuarkBuilderCometSupplyTest:testCometSupplyWithPaycall() (gas: 19156407)
QuarkBuilderCometSupplyTest:testFundsUnavailable() (gas: 18703862)
QuarkBuilderCometSupplyTest:testInsufficientFunds() (gas: 18722355)
QuarkBuilderCometSupplyTest:testMaxCostTooHigh() (gas: 18702511)
QuarkBuilderCometSupplyTest:testSimpleCometSupply() (gas: 18985338)
QuarkBuilderCometSupplyTest:testSimpleCometSupplyMax() (gas: 19006508)
QuarkBuilderCometSupplyTest:testSimpleCometSupplyWithAutoWrapper() (gas: 19613872)
QuarkBuilderCometWithdrawTest:testCometWithdraw() (gas: 18847756)
QuarkBuilderCometWithdrawTest:testCometWithdrawMax() (gas: 19160292)
QuarkBuilderCometWithdrawTest:testCometWithdrawMaxRevertsMaxCostTooHigh() (gas: 18854170)
QuarkBuilderCometWithdrawTest:testCometWithdrawPayFromWithdraw() (gas: 19164988)
QuarkBuilderCometWithdrawTest:testCometWithdrawWithBridge() (gas: 19696713)
QuarkBuilderCometWithdrawTest:testCometWithdrawWithPaycall() (gas: 19125617)
QuarkBuilderCometWithdrawTest:testWithdrawNotEnoughFundsToBridge() (gas: 18771151)
QuarkBuilderHelperTest:testAddBufferToPaymentCost() (gas: 413026)
QuarkBuilderHelperTest:testCanBridgeUSDCOnSupportedChains() (gas: 423046)
QuarkBuilderHelperTest:testCannotBridgeUSDCOnUnsupportedChains() (gas: 420966)
QuarkBuilderHelperTest:testCannotBridgeUnsupportedAssets() (gas: 419619)
QuarkBuilderRecurringSwapTest:testFundsUnavailableErrorGivesSuggestionForAvailableFunds() (gas: 18706546)
QuarkBuilderRecurringSwapTest:testInsufficientFunds() (gas: 18692219)
QuarkBuilderRecurringSwapTest:testMaxCostTooHigh() (gas: 18706365)
QuarkBuilderRecurringSwapTest:testNotEnoughFundsOnTargetChain() (gas: 18691754)
QuarkBuilderRecurringSwapTest:testRecurringExactInSwapSucceeds() (gas: 19757953)
QuarkBuilderRecurringSwapTest:testRecurringExactOutSwapSucceeds() (gas: 19757841)
QuarkBuilderRecurringSwapTest:testRecurringSwapWithPaycallSucceeds() (gas: 20044818)
QuarkBuilderSwapTest:testBridgeSwapBridgesPaymentToken() (gas: 20023763)
QuarkBuilderSwapTest:testBridgeSwapMaxWithQuotecallSucceeds() (gas: 20263384)
QuarkBuilderSwapTest:testBridgeSwapSucceeds() (gas: 19771808)
QuarkBuilderSwapTest:testBridgeSwapWithPaycallSucceeds() (gas: 20104014)
QuarkBuilderSwapTest:testFundsOnUnbridgeableChains() (gas: 18710246)
QuarkBuilderSwapTest:testFundsUnavailableErrorGivesSuggestionForAvailableFunds() (gas: 18708049)
QuarkBuilderSwapTest:testIgnoresChainIfMaxCostIsNotSpecified() (gas: 18707930)
QuarkBuilderSwapTest:testInsufficientFunds() (gas: 18727769)
QuarkBuilderSwapTest:testLocalSwapSucceeds() (gas: 19146905)
QuarkBuilderSwapTest:testLocalSwapWithAutoWrapperSucceeds() (gas: 19775323)
QuarkBuilderSwapTest:testLocalSwapWithPaycallSucceeds() (gas: 19325351)
QuarkBuilderSwapTest:testMaxCostTooHigh() (gas: 18707872)
QuarkBuilderSwapTest:testRevertsIfNotEnoughFundsToBridge() (gas: 18907157)
QuarkBuilderSwapTest:testSwapMaxSucceeds() (gas: 19393623)
QuarkBuilderTransferTest:testBridgeTransferBridgesPaymentToken() (gas: 19846281)
QuarkBuilderTransferTest:testBridgeTransferMaxFundUnavailableError() (gas: 18920988)
QuarkBuilderTransferTest:testFundsOnUnbridgeableChains() (gas: 18704432)
QuarkBuilderTransferTest:testFundsUnavailableErrorGivesSuggestionForAvailableFunds() (gas: 18703025)
QuarkBuilderTransferTest:testIgnoresChainIfMaxCostIsNotSpecified() (gas: 18702967)
QuarkBuilderTransferTest:testInsufficientFunds() (gas: 18722742)
QuarkBuilderTransferTest:testMaxCostTooHigh() (gas: 18702895)
QuarkBuilderTransferTest:testRevertsIfNotEnoughFundsToBridge() (gas: 18901147)
QuarkBuilderTransferTest:testSimpleBridgeTransferMax() (gas: 20060891)
QuarkBuilderTransferTest:testSimpleBridgeTransferSucceeds() (gas: 19562564)
QuarkBuilderTransferTest:testSimpleBridgeTransferWithPaycallSucceeds() (gas: 19925119)
QuarkBuilderTransferTest:testSimpleLocalTransferMax() (gas: 19184362)
QuarkBuilderTransferTest:testSimpleLocalTransferSucceeds() (gas: 18945497)
QuarkBuilderTransferTest:testSimpleLocalTransferWithPaycallSucceeds() (gas: 19156154)
QuarkBuilderTransferTest:testTransferMaxWithAutoUnwrapping() (gas: 20222055)
QuarkBuilderTransferTest:testTransferWithAutoUnwrapping() (gas: 19547064)
QuarkBuilderTransferTest:testTransferWithAutoUnwrappingWithPaycallSucceeds() (gas: 20048567)
QuarkBuilderTransferTest:testTransferWithAutoWrapping() (gas: 19607562)
QuotecallTest:testInitializeProperlyFromConstructor() (gas: 7036)
QuotecallTest:testQuotecallForPayWithUSDT() (gas: 125408)
QuotecallTest:testQuotecallForPayWithWBTC() (gas: 119962)
QuotecallTest:testQuotecallRevertsWhenCallReverts() (gas: 108579)
QuotecallTest:testReturnCallResult() (gas: 112319)
QuotecallTest:testRevertsForInvalidCallContext() (gas: 16537)
QuotecallTest:testRevertsWhenQuoteTooHigh() (gas: 155229)
QuotecallTest:testRevertsWhenQuoteTooLow() (gas: 155071)
QuotecallTest:testSimpleCounterAndPayWithUSDC() (gas: 148952)
QuotecallTest:testSimpleTransferTokenAndPayWithUSDC() (gas: 144596)
QuotecallWrapperTest:testSimpleTransferAndWrapForQuotecall() (gas: 1407584)
RecurringSwapTest:testCancelRecurringSwap() (gas: 293567)
RecurringSwapTest:testRecurringSwapCanSwapMultipleTimes() (gas: 425136)
RecurringSwapTest:testRecurringSwapExactInAlternateSwap() (gas: 229791)
RecurringSwapTest:testRecurringSwapExactInSwap() (gas: 237508)
RecurringSwapTest:testRecurringSwapExactOutAlternateSwap() (gas: 233113)
RecurringSwapTest:testRecurringSwapExactOutSwap() (gas: 239457)
RecurringSwapTest:testRecurringSwapWithDifferentCalldata() (gas: 724141)
RecurringSwapTest:testRecurringSwapWithMultiplePriceFeeds() (gas: 254663)
RecurringSwapTest:testRevertsForExpiredQuarkOperation() (gas: 12817)
RecurringSwapTest:testRevertsForInvalidInput() (gas: 143492)
RecurringSwapTest:testRevertsForSwapBeforeNextSwapWindow() (gas: 307929)
RecurringSwapTest:testRevertsForSwapBeforeStartTime() (gas: 9223372036854754743)
RecurringSwapTest:testRevertsWhenSlippageParamsConfiguredWrong() (gas: 260596)
RecurringSwapTest:testRevertsWhenSlippageTooHigh() (gas: 260796)
SupplyActionsTest:testInvalidInput() (gas: 67616)
SupplyActionsTest:testRepayBorrow() (gas: 89628)
SupplyActionsTest:testSupply() (gas: 131927)
Expand All @@ -57,7 +167,7 @@ TransferActionsTest:testRevertsForTransferReentrancyAttackWithReentrancyGuard()
TransferActionsTest:testRevertsForTransferReentrancyAttackWithoutCallbackEnabled() (gas: 99351)
TransferActionsTest:testRevertsForTransferReentrantAttackWithStolenSignature() (gas: 110234)
TransferActionsTest:testTransferERC20TokenToEOA() (gas: 70280)
TransferActionsTest:testTransferERC20TokenToQuarkWallet() (gas: 71600)
TransferActionsTest:testTransferERC20TokenToQuarkWallet() (gas: 71604)
TransferActionsTest:testTransferERC777SuccessWithEvilReceiverWithoutAttackAttempt() (gas: 106630)
TransferActionsTest:testTransferERC777TokenReentrancyAttackSuccessWithCallbackEnabled() (gas: 144402)
TransferActionsTest:testTransferNativeTokenToEOA() (gas: 79394)
Expand All @@ -73,14 +183,18 @@ UniswapFlashSwapExactOutTest:testInvalidCallerFlashSwap() (gas: 70209)
UniswapFlashSwapExactOutTest:testNotEnoughToPayFlashSwap() (gas: 293339)
UniswapFlashSwapExactOutTest:testRevertsIfCalledDirectly() (gas: 10724)
UniswapFlashSwapExactOutTest:testUniswapFlashSwapExactOutLeverageComet() (gas: 353254)
UniswapSwapActionsTest:testApprovalRefund() (gas: 163571)
UniswapSwapActionsTest:testBuyAssetOneStop() (gas: 251129)
UniswapSwapActionsTest:testBuyAssetTwoStops() (gas: 357689)
UniswapSwapActionsTest:testSellAssetOneStop() (gas: 248467)
UniswapSwapActionsTest:testSellAssetTwoStops() (gas: 361614)
UniswapSwapActionsTest:testApprovalRefund() (gas: 163410)
UniswapSwapActionsTest:testBuyAssetOneStop() (gas: 250917)
UniswapSwapActionsTest:testBuyAssetTwoStops() (gas: 357575)
UniswapSwapActionsTest:testSellAssetOneStop() (gas: 248255)
UniswapSwapActionsTest:testSellAssetTwoStops() (gas: 361500)
WithdrawActionsTest:testBorrow() (gas: 153735)
WithdrawActionsTest:testInvalidInput() (gas: 67488)
WithdrawActionsTest:testWithdraw() (gas: 83594)
WithdrawActionsTest:testWithdrawFrom() (gas: 83108)
WithdrawActionsTest:testWithdrawMultipleAssets() (gas: 159195)
WithdrawActionsTest:testWithdrawTo() (gas: 83573)
WithdrawActionsTest:testWithdrawTo() (gas: 83573)
WrapperScriptsTest:testUnwrapWETH() (gas: 57751)
WrapperScriptsTest:testUnwrapWstETH() (gas: 100520)
WrapperScriptsTest:testWrapETH() (gas: 76834)
WrapperScriptsTest:testWrapStETH() (gas: 124640)
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
[submodule "lib/quark"]
path = lib/quark
url = git@github.com:compound-finance/quark
[submodule "lib/swap-router-contracts"]
path = lib/swap-router-contracts
url = https://github.com/Uniswap/swap-router-contracts
3 changes: 3 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ via_ir = true
optimizer = true
optimizer_runs = 100000000

[fmt]
ignore = ["src/vendor/**/*"]

bytecode_hash = "none"
cbor_metadata = false
1 change: 1 addition & 0 deletions lib/swap-router-contracts
Submodule swap-router-contracts added at c696aa
1 change: 1 addition & 0 deletions remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ openzeppelin-contracts/=lib/openzeppelin-contracts/
openzeppelin/=lib/openzeppelin-contracts/contracts/
v3-core/=lib/v3-core/
v3-periphery/=lib/v3-periphery/contracts/
swap-router-contracts/=lib/swap-router-contracts/contracts/
codejar/=lib/quark/src/codejar/
quark-core/=lib/quark/src/quark-core/
quark-factory/=lib/quark/src/quark-factory/
Expand Down
14 changes: 5 additions & 9 deletions src/DeFiScripts.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.8.23;

import {IERC20} from "openzeppelin/token/ERC20/IERC20.sol";
import {SafeERC20} from "openzeppelin/token/ERC20/utils/SafeERC20.sol";
import {ISwapRouter} from "v3-periphery/interfaces/ISwapRouter.sol";
import {ISwapRouter02, IV3SwapRouter} from "src/vendor/uniswap-swap-router-contracts/ISwapRouter02.sol";

import {QuarkScript} from "quark-core/src/QuarkScript.sol";

Expand Down Expand Up @@ -136,7 +136,6 @@ contract UniswapSwapActions {
uint256 amount;
// Minimum amount of target token to receive (revert if return amount is less than this)
uint256 amountOutMinimum;
uint256 deadline;
// Path of the swap
bytes path;
}
Expand All @@ -148,7 +147,6 @@ contract UniswapSwapActions {
uint256 amount;
// Maximum amount of input token to spend (revert if input amount is greater than this)
uint256 amountInMaximum;
uint256 deadline;
// Path of the swap
bytes path;
}
Expand All @@ -159,11 +157,10 @@ contract UniswapSwapActions {
*/
function swapAssetExactIn(SwapParamsExactIn calldata params) external {
IERC20(params.tokenFrom).forceApprove(params.uniswapRouter, params.amount);
ISwapRouter(params.uniswapRouter).exactInput(
ISwapRouter.ExactInputParams({
ISwapRouter02(params.uniswapRouter).exactInput(
IV3SwapRouter.ExactInputParams({
path: params.path,
recipient: params.recipient,
deadline: params.deadline,
amountIn: params.amount,
amountOutMinimum: params.amountOutMinimum
})
Expand All @@ -176,11 +173,10 @@ contract UniswapSwapActions {
*/
function swapAssetExactOut(SwapParamsExactOut calldata params) external {
IERC20(params.tokenFrom).forceApprove(params.uniswapRouter, params.amountInMaximum);
uint256 amountIn = ISwapRouter(params.uniswapRouter).exactOutput(
ISwapRouter.ExactOutputParams({
uint256 amountIn = ISwapRouter02(params.uniswapRouter).exactOutput(
IV3SwapRouter.ExactOutputParams({
path: params.path,
recipient: params.recipient,
deadline: params.deadline,
amountOut: params.amount,
amountInMaximum: params.amountInMaximum
})
Expand Down
14 changes: 5 additions & 9 deletions src/RecurringSwap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {SafeERC20} from "openzeppelin/token/ERC20/utils/SafeERC20.sol";
import {IERC20Metadata} from "openzeppelin/token/ERC20/extensions/IERC20Metadata.sol";

import {AggregatorV3Interface} from "src/vendor/chainlink/AggregatorV3Interface.sol";
import {ISwapRouter} from "v3-periphery/interfaces/ISwapRouter.sol";
import {ISwapRouter02, IV3SwapRouter} from "src/vendor/uniswap-swap-router-contracts/ISwapRouter02.sol";

import {QuarkWallet} from "quark-core/src/QuarkWallet.sol";
import {QuarkScript} from "quark-core/src/QuarkScript.sol";
Expand Down Expand Up @@ -65,7 +65,6 @@ contract RecurringSwap is QuarkScript {
uint256 amount;
/// @dev False for exact in; true for exact out
bool isExactOut;
uint256 deadline;
bytes path;
}

Expand Down Expand Up @@ -210,23 +209,21 @@ contract RecurringSwap is QuarkScript {

if (swapParams.isExactOut) {
// Exact out swap
actualAmountIn = ISwapRouter(swapParams.uniswapRouter).exactOutput(
ISwapRouter.ExactOutputParams({
actualAmountIn = ISwapRouter02(swapParams.uniswapRouter).exactOutput(
IV3SwapRouter.ExactOutputParams({
path: swapParams.path,
recipient: swapParams.recipient,
deadline: swapParams.deadline,
amountOut: amountOut,
amountInMaximum: amountIn
})
);
actualAmountOut = amountOut;
} else {
// Exact in swap
actualAmountOut = ISwapRouter(swapParams.uniswapRouter).exactInput(
ISwapRouter.ExactInputParams({
actualAmountOut = ISwapRouter02(swapParams.uniswapRouter).exactInput(
IV3SwapRouter.ExactInputParams({
path: swapParams.path,
recipient: swapParams.recipient,
deadline: swapParams.deadline,
amountIn: amountIn,
amountOutMinimum: amountOut
})
Expand Down Expand Up @@ -268,7 +265,6 @@ contract RecurringSwap is QuarkScript {
config.swapParams.tokenOut,
config.swapParams.amount,
config.swapParams.isExactOut,
config.swapParams.deadline,
config.swapParams.path
),
abi.encodePacked(
Expand Down
Loading

0 comments on commit 4d433bd

Please sign in to comment.