Skip to content

Commit

Permalink
Feat: Paraswap partner switch (#1817)
Browse files Browse the repository at this point in the history
* feat: added dao partner address to paraswap rates

* feat: changed to take surplus

* feat: added partner to paraswap get rates

* feat: added exclude dexes
  • Loading branch information
JoaquinBattilana authored Oct 23, 2023
1 parent e6cae50 commit 0a38051
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@lingui/react": "^3.14.0",
"@mui/icons-material": "^5.10.14",
"@mui/material": "^5.10.9",
"@paraswap/sdk": "6.2.2",
"@paraswap/sdk": "6.2.4",
"@tanstack/react-query": "^4.28.0",
"@visx/axis": "^2.14.0",
"@visx/curve": "^2.1.0",
Expand Down
1 change: 1 addition & 0 deletions src/components/transactions/Switch/SwitchActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export const SwitchActions = ({
maxSlippage: Number(slippage) * 10000,
permit: signatureParams && signatureParams.signature,
deadline: signatureParams && signatureParams.deadline,
partner: 'aave-widget',
});
tx.chainId = chainId;
const txWithGasEstimation = await estimateGasLimit(tx, chainId);
Expand Down
3 changes: 3 additions & 0 deletions src/components/transactions/Switch/SwitchModalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ export const SwitchModalContent = ({
destToken: selectedOutputReserve.underlyingAsset,
destDecimals: selectedOutputReserve.decimals,
user,
options: {
partner: 'aave-widget',
},
});

if (sellRates && switchTxState.success) {
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/paraswap/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const getParaswap = (chainId: ChainId) => {
throw new Error('chain not supported');
};

const getFeeClaimerAddress = (chainId: ChainId) => {
export const getFeeClaimerAddress = (chainId: ChainId) => {
if (ChainId.base === chainId) return MiscBase.PARASWAP_FEE_CLAIMER;

return MiscEthereum.PARASWAP_FEE_CLAIMER;
Expand Down Expand Up @@ -350,7 +350,7 @@ export const ExactInSwapper = (chainId: ChainId) => {
priceRoute: route,
userAddress: user,
partnerAddress: FEE_CLAIMER_ADDRESS,
positiveSlippageToUser: false,
takeSurplus: true,
},
{ ignoreChecks: true }
);
Expand Down Expand Up @@ -423,7 +423,7 @@ const ExactOutSwapper = (chainId: ChainId) => {
priceRoute: route,
userAddress: user,
partnerAddress: FEE_CLAIMER_ADDRESS,
positiveSlippageToUser: false,
takeSurplus: true,
srcDecimals,
destDecimals,
},
Expand Down
16 changes: 14 additions & 2 deletions src/hooks/paraswap/useParaswapRates.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { OptimalRate, SwapSide } from '@paraswap/sdk';
import { RateOptions } from '@paraswap/sdk/dist/methods/swap/rates';
import { useMutation, useQuery } from '@tanstack/react-query';
import { BigNumber, constants, PopulatedTransaction } from 'ethers';
import { QueryKeys } from 'src/ui-config/queries';

import { getParaswap } from './common';
import { getFeeClaimerAddress, getParaswap } from './common';

type ParaSwapSellRatesParams = {
amount: string;
Expand All @@ -13,6 +14,7 @@ type ParaSwapSellRatesParams = {
destDecimals: number;
chainId: number;
user: string;
options?: RateOptions;
};

export const useParaswapSellRates = ({
Expand All @@ -23,6 +25,7 @@ export const useParaswapSellRates = ({
destToken,
destDecimals,
user,
options = {},
}: ParaSwapSellRatesParams) => {
return useQuery<OptimalRate | undefined>({
queryFn: () => {
Expand All @@ -35,6 +38,10 @@ export const useParaswapSellRates = ({
destDecimals,
userAddress: user ? user : constants.AddressZero,
side: SwapSide.SELL,
options: {
...options,
excludeDEXS: ['ParaSwapPool', 'ParaSwapLimitOrders'],
},
});
},
queryKey: [QueryKeys.PARASWAP_RATES, chainId, amount, srcToken, destToken, user],
Expand All @@ -54,9 +61,11 @@ type UseParaswapSellTxParams = {
maxSlippage: number;
permit?: string;
deadline?: string;
partner?: string;
};

export const useParaswapSellTxParams = (chainId: number) => {
const FEE_CLAIMER_ADDRESS = getFeeClaimerAddress(chainId);
return useMutation<PopulatedTransaction, unknown, UseParaswapSellTxParams>({
mutationFn: async ({
srcToken,
Expand All @@ -68,6 +77,7 @@ export const useParaswapSellTxParams = (chainId: number) => {
maxSlippage,
permit,
deadline,
partner,
}: UseParaswapSellTxParams) => {
const paraswap = getParaswap(chainId);
const response = await paraswap.buildTx(
Expand All @@ -80,7 +90,9 @@ export const useParaswapSellTxParams = (chainId: number) => {
userAddress: user,
priceRoute: route,
slippage: maxSlippage,
positiveSlippageToUser: true,
takeSurplus: true,
partner,
partnerAddress: FEE_CLAIMER_ADDRESS,
permit,
deadline,
},
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2799,10 +2799,10 @@
resolved "https://registry.yarnpkg.com/@paraswap/core/-/core-1.1.0.tgz#5ec7415be69dc657a9d82b0fde4e20f632cca1b6"
integrity sha512-ecnX8ezlhYWFwolZxYEz+K+RfLr8xaxQqiJKlxJ8Yf00tXTGxDGn6/Acy00t4+9Kv0apewd7++J33eJt9yNfwg==

"@paraswap/[email protected].2":
version "6.2.2"
resolved "https://registry.yarnpkg.com/@paraswap/sdk/-/sdk-6.2.2.tgz#c34eef61ab4cb8e0ad284f2259a25b9a61b4bb9a"
integrity sha512-W0sAIf/T4zAmI7Yp4TcAuQr68NtaopeuYOWop20piAGoko4K9eLY4DYwWgkXf9fw9bAeeGofwP+GYJJC8Q24xg==
"@paraswap/[email protected].4":
version "6.2.4"
resolved "https://registry.yarnpkg.com/@paraswap/sdk/-/sdk-6.2.4.tgz#df6cf7c6acf04b40c4efd678d1aa7326e5e8d219"
integrity sha512-Ow7MArOXYeE0xrAYclCxPUyBCsPlk+Jm3k1+jsxXF0jUQgucSXZ4yfFzA/nxlRd6xjpoljX5V05Nir1nOAINsQ==
dependencies:
"@paraswap/core" "1.1.0"
bignumber.js "^9.0.2"
Expand Down

1 comment on commit 0a38051

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit was deployed on ipfs

Please sign in to comment.