Skip to content

Commit

Permalink
feat: paraswap v6 (#2216)
Browse files Browse the repository at this point in the history
Co-authored-by: Mark Hinschberger <[email protected]>
  • Loading branch information
grothem and foodaka authored Oct 24, 2024
1 parent a00dccd commit 68fec1e
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 50 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { configEnvHarmony } from '../../../support/steps/configuration.steps';
import { dashboardAssetValuesVerification } from '../../../support/steps/verification.steps';
import constants from '../../../fixtures/constans.json';
import assets from '../../../fixtures/assets.json';
import constants from '../../../fixtures/constans.json';
import { skipState } from '../../../support/steps/common';
import { configEnvHarmony } from '../../../support/steps/configuration.steps';
import { dashboardAssetValuesVerification } from '../../../support/steps/verification.steps';

const testData = {
dashboard: [
Expand Down Expand Up @@ -32,7 +32,7 @@ const testData = {
],
};

describe('HARMONY GENERAL SPEC', () => {
describe.skip('HARMONY GENERAL SPEC', () => {
const skipTestState = skipState(false);
configEnvHarmony('0xE4217040c894e8873EE19d675b6d0EeC992c2c0D');
dashboardAssetValuesVerification(testData.dashboard, skipTestState);
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"test:coverage": "jest --coverage"
},
"dependencies": {
"@aave/contract-helpers": "1.30.3",
"@aave/math-utils": "1.30.3",
"@aave/contract-helpers": "1.30.4",
"@aave/math-utils": "1.30.4",
"@bgd-labs/aave-address-book": "3.7.0",
"@emotion/cache": "11.10.3",
"@emotion/react": "11.10.4",
Expand All @@ -45,7 +45,7 @@
"@mui/icons-material": "^5.10.14",
"@mui/lab": "5.0.0-alpha.103",
"@mui/material": "^5.10.9",
"@paraswap/sdk": "6.2.4",
"@paraswap/sdk": "6.10.0",
"@tanstack/react-query": "^4.28.0",
"@visx/annotation": "^3.3.0",
"@visx/axis": "^2.14.0",
Expand Down
49 changes: 26 additions & 23 deletions src/hooks/paraswap/common.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { ChainId, valueToWei } from '@aave/contract-helpers';
import { normalize, normalizeBN, valueToBigNumber } from '@aave/math-utils';
import {
MiscArbitrum,
MiscAvalanche,
MiscBase,
MiscBNB,
MiscEthereum,
MiscFantom,
MiscOptimism,
MiscPolygon,
AaveV3Arbitrum,
AaveV3Avalanche,
AaveV3Base,
AaveV3BNB,
AaveV3Ethereum,
AaveV3Fantom,
AaveV3Optimism,
AaveV3Polygon,
} from '@bgd-labs/aave-address-book';
import {
BuildTxFunctions,
Expand Down Expand Up @@ -62,43 +62,44 @@ const ParaSwap = (chainId: number) => {
{
chainId,
fetcher,
version: '6.2',
},
constructBuildTx,
constructGetRate
);
};

type ParaswapChainMap = {
[key in ChainId]?: { paraswap: BuildTxFunctions & GetRateFunctions; feeClaimer: string };
[key in ChainId]?: { paraswap: BuildTxFunctions & GetRateFunctions; feeTarget: string };
};

const paraswapNetworks: ParaswapChainMap = {
[ChainId.mainnet]: {
paraswap: ParaSwap(ChainId.mainnet),
feeClaimer: MiscEthereum.PARASWAP_FEE_CLAIMER,
feeTarget: AaveV3Ethereum.COLLECTOR,
},
[ChainId.polygon]: {
paraswap: ParaSwap(ChainId.polygon),
feeClaimer: MiscPolygon.PARASWAP_FEE_CLAIMER,
feeTarget: AaveV3Polygon.COLLECTOR,
},
[ChainId.avalanche]: {
paraswap: ParaSwap(ChainId.avalanche),
feeClaimer: MiscAvalanche.PARASWAP_FEE_CLAIMER,
feeTarget: AaveV3Avalanche.COLLECTOR,
},
[ChainId.fantom]: {
paraswap: ParaSwap(ChainId.fantom),
feeClaimer: MiscFantom.PARASWAP_FEE_CLAIMER,
feeTarget: AaveV3Fantom.COLLECTOR,
},
[ChainId.arbitrum_one]: {
paraswap: ParaSwap(ChainId.arbitrum_one),
feeClaimer: MiscArbitrum.PARASWAP_FEE_CLAIMER,
feeTarget: AaveV3Arbitrum.COLLECTOR,
},
[ChainId.optimism]: {
paraswap: ParaSwap(ChainId.optimism),
feeClaimer: MiscOptimism.PARASWAP_FEE_CLAIMER,
feeTarget: AaveV3Optimism.COLLECTOR,
},
[ChainId.base]: { paraswap: ParaSwap(ChainId.base), feeClaimer: MiscBase.PARASWAP_FEE_CLAIMER },
[ChainId.bnb]: { paraswap: ParaSwap(ChainId.bnb), feeClaimer: MiscBNB.PARASWAP_FEE_CLAIMER },
[ChainId.base]: { paraswap: ParaSwap(ChainId.base), feeTarget: AaveV3Base.COLLECTOR },
[ChainId.bnb]: { paraswap: ParaSwap(ChainId.bnb), feeTarget: AaveV3BNB.COLLECTOR },
};

export const getParaswap = (chainId: ChainId) => {
Expand Down Expand Up @@ -210,7 +211,7 @@ export async function fetchExactInRate(
};

if (max) {
options.includeContractMethods = [ContractMethod.multiSwap, ContractMethod.megaSwap];
options.includeContractMethods = [ContractMethod.swapExactAmountIn];
}

const swapper = ExactInSwapper(chainId);
Expand Down Expand Up @@ -291,7 +292,7 @@ export async function fetchExactOutRate(
};

if (max) {
options.includeContractMethods = [ContractMethod.buy];
options.includeContractMethods = [ContractMethod.swapExactAmountOut];
}

const swapper = ExactOutSwapper(chainId);
Expand All @@ -308,7 +309,7 @@ export async function fetchExactOutRate(
}

export const ExactInSwapper = (chainId: ChainId) => {
const { paraswap, feeClaimer } = getParaswap(chainId);
const { paraswap, feeTarget } = getParaswap(chainId);

const getRate = async (
amount: string,
Expand Down Expand Up @@ -353,8 +354,9 @@ export const ExactInSwapper = (chainId: ChainId) => {
slippage: maxSlippage * 100,
priceRoute: route,
userAddress: user,
partnerAddress: feeClaimer,
partnerAddress: feeTarget,
takeSurplus: true,
isDirectFeeTransfer: true,
},
{ ignoreChecks: true }
);
Expand All @@ -376,7 +378,7 @@ export const ExactInSwapper = (chainId: ChainId) => {
};

const ExactOutSwapper = (chainId: ChainId) => {
const { paraswap, feeClaimer } = getParaswap(chainId);
const { paraswap, feeTarget } = getParaswap(chainId);

const getRate = async (
amount: string,
Expand Down Expand Up @@ -419,10 +421,11 @@ const ExactOutSwapper = (chainId: ChainId) => {
slippage: maxSlippage * 100,
priceRoute: route,
userAddress: user,
partnerAddress: feeClaimer,
partnerAddress: feeTarget,
takeSurplus: true,
srcDecimals,
destDecimals,
isDirectFeeTransfer: true,
},
{ ignoreChecks: true }
);
Expand Down
7 changes: 4 additions & 3 deletions src/hooks/paraswap/useParaswapRates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const useParaswapSellRates = ({
side: SwapSide.SELL,
options: {
...options,
excludeDEXS: ['ParaSwapPool', 'ParaSwapLimitOrders'],
excludeDEXS: ['ParaSwapPool', 'ParaSwapLimitOrders', 'SwaapV2', 'Hashflow', 'Dexalot'],
},
});
},
Expand Down Expand Up @@ -78,7 +78,7 @@ export const useParaswapSellTxParams = (chainId: number) => {
deadline,
partner,
}: UseParaswapSellTxParams) => {
const { paraswap, feeClaimer } = getParaswap(chainId);
const { paraswap, feeTarget } = getParaswap(chainId);
const response = await paraswap.buildTx(
{
srcToken,
Expand All @@ -91,9 +91,10 @@ export const useParaswapSellTxParams = (chainId: number) => {
slippage: maxSlippage,
takeSurplus: true,
partner,
partnerAddress: feeClaimer,
partnerAddress: feeTarget,
permit,
deadline,
isDirectFeeTransfer: true,
},
{ ignoreChecks: true }
);
Expand Down
8 changes: 8 additions & 0 deletions src/ui-config/TokenList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12716,6 +12716,14 @@ export const TOKEN_LIST: TokenList = {
chainId: 1,
logoURI: 'https://assets.coingecko.com/coins/images/39926/standard/usds.webp?1726666683',
},
{
name: 'Savings Dai',
address: '0x83f20f44975d03b1b09e64809b757c47f942beea',
symbol: 'SDAI',
decimals: 18,
chainId: 1,
logoURI: 'https://assets.coingecko.com/coins/images/32254/standard/sdai.png?1697015278',
},
],
};

Expand Down
34 changes: 17 additions & 17 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
# yarn lockfile v1


"@aave/[email protected].3":
version "1.30.3"
resolved "https://registry.yarnpkg.com/@aave/contract-helpers/-/contract-helpers-1.30.3.tgz#f91f68c6f318db2ace9101c0012cfbeaacbc902b"
integrity sha512-xONje75WW371PQ/m2TZxswJMVJpN/l5RRi11CqH349EFqauR+6LdhoOC/wo3+qGdmoWKhLoEKKdceRktezVLKA==
"@aave/[email protected].4":
version "1.30.4"
resolved "https://registry.yarnpkg.com/@aave/contract-helpers/-/contract-helpers-1.30.4.tgz#409d9a6a19af471e7fa31a97ade19ebdae3f70dd"
integrity sha512-UrstVWMgHIJxEPgf7PHokiuJLeyNEF8179Xe1vYjPAY0rXpvD6jVIMmVCyypD0h9BlhwRhPnSCXn0TYgtJQ5jg==
dependencies:
isomorphic-unfetch "^3.1.0"

"@aave/[email protected].3":
version "1.30.3"
resolved "https://registry.yarnpkg.com/@aave/math-utils/-/math-utils-1.30.3.tgz#c9c96bcbadb3d5e056aac074bd221481555a1f84"
integrity sha512-L8Utyvon6gAHzwB/KQrSSdrHEQ9FNtGcZhQHEHkDk/tfcQidXHItwywM1taNmC5ZwFLJ10PL9c14OZh5fZNvLg==
"@aave/[email protected].4":
version "1.30.4"
resolved "https://registry.yarnpkg.com/@aave/math-utils/-/math-utils-1.30.4.tgz#6794c708ab68d0447ff78ee6aeb3e3f8da914865"
integrity sha512-nJWblQo5WBdIBitJtNTFKoIQhVrQ9aKCDNgukb2vGTW9n7NEdNYXK+yrU78VSTHW/eZ1kDaE4oBPdcN86eEpAg==

"@adobe/css-tools@^4.0.1":
version "4.0.1"
Expand Down Expand Up @@ -3174,17 +3174,17 @@
"@nodelib/fs.scandir" "2.1.5"
fastq "^1.6.0"

"@paraswap/core@1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@paraswap/core/-/core-1.1.0.tgz#5ec7415be69dc657a9d82b0fde4e20f632cca1b6"
integrity sha512-ecnX8ezlhYWFwolZxYEz+K+RfLr8xaxQqiJKlxJ8Yf00tXTGxDGn6/Acy00t4+9Kv0apewd7++J33eJt9yNfwg==
"@paraswap/core@2.2.0":
version "2.2.0"
resolved "https://registry.yarnpkg.com/@paraswap/core/-/core-2.2.0.tgz#848175c7729f1064e715019269b1c193a23a5be8"
integrity sha512-aENl5zjS0y4ag7PLEq/hHgaAH4XpN5M4Zc7Igt/03D+W6t6tgScG9on2gXKkEUErcgnZ79qnvzKhaU6QgzoBAQ==

"@paraswap/sdk@6.2.4":
version "6.2.4"
resolved "https://registry.yarnpkg.com/@paraswap/sdk/-/sdk-6.2.4.tgz#df6cf7c6acf04b40c4efd678d1aa7326e5e8d219"
integrity sha512-Ow7MArOXYeE0xrAYclCxPUyBCsPlk+Jm3k1+jsxXF0jUQgucSXZ4yfFzA/nxlRd6xjpoljX5V05Nir1nOAINsQ==
"@paraswap/sdk@6.10.0":
version "6.10.0"
resolved "https://registry.yarnpkg.com/@paraswap/sdk/-/sdk-6.10.0.tgz#fffba05a8ecc0bda91cc2ee07c0f5a4a79ff53f2"
integrity sha512-FhzJs1HYTGDnjYOxJmZ0+Qk0WHnshTgHpP2QdhiJYIkIF/2zYzI1OLTseO3XXhkQfmg4ZmZbTm6ZuutTg6c3zg==
dependencies:
"@paraswap/core" "1.1.0"
"@paraswap/core" "2.2.0"
bignumber.js "^9.0.2"
ts-essentials "^9.1.2"

Expand Down

2 comments on commit 68fec1e

@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

@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.