Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add SwaprV3 liquidity integration #1892

Merged
merged 3 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@reduxjs/toolkit": "^1.9.5",
"@swapr/core": "^0.3.19",
"@swapr/periphery": "^0.3.22",
"@swapr/sdk": "1.9.4",
"@swapr/sdk": "1.10.2",
"@tanstack/react-query": "4.24.6",
"@uniswap/token-lists": "^1.0.0-beta.27",
"@uniswap/v3-periphery": "1.4.1",
Expand Down
4 changes: 4 additions & 0 deletions src/assets/images/swapr-v3-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions src/constants/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import ZeroXLogo from '../assets/images/logos/ZeroX.svg'
import Metamask from '../assets/images/metamask.png'
import QuickswapLogo from '../assets/images/quickswap-logo.png'
import SushiswapNewLogo from '../assets/images/sushiswap-new-logo.svg'
import SwaprV3Logo from '../assets/images/swapr-v3-logo.svg'
import UniswapLogo from '../assets/images/uniswap-logo.svg'
import VelodromeLogo from '../assets/images/velodrome-logo.svg'
import WalletConnect from '../assets/images/wallet-connect.svg'
Expand Down Expand Up @@ -818,6 +819,12 @@ export const ROUTABLE_PLATFORM_STYLE: {
gradientColor: '#FB52A1',
name: RoutablePlatform.VELODROME.name,
},
[RoutablePlatform.SWAPR_V3.name]: {
logo: SwaprV3Logo,
alt: RoutablePlatform.SWAPR_V3.name,
gradientColor: '#9185F7',
name: RoutablePlatform.SWAPR_V3.name,
},
}

export const ROUTABLE_PLATFORM_LOGO: {
Expand All @@ -839,6 +846,7 @@ export const ROUTABLE_PLATFORM_LOGO: {
[RoutablePlatform.UNISWAP.name]: <img width={16} height={16} src={UniswapLogo} alt="Uniswap Unicorn" />,
[UniswapV2RoutablePlatform.UNISWAP.name]: <img width={16} height={16} src={UniswapLogo} alt="uniswap" />,
[RoutablePlatform.VELODROME.name]: <img width={16} height={16} src={VelodromeLogo} alt="Velodrome" />,
[RoutablePlatform.SWAPR_V3.name]: <img width={16} height={16} src={SwaprV3Logo} alt="Swapr v3" />,
}

export const ChainLabel: any = {
Expand Down
8 changes: 7 additions & 1 deletion src/hooks/useSwapCallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
UniswapV2RoutablePlatform,
UniswapV2Trade,
VelodromeTrade,
SwaprV3Trade,
ZeroXTrade,
} from '@swapr/sdk'

Expand Down Expand Up @@ -83,7 +84,12 @@ export function useSwapsCallArguments(

const swapMethods = []
// Curve, Uniswap v3, ZeroX
if (trade instanceof CurveTrade || trade instanceof UniswapTrade || trade instanceof ZeroXTrade) {
if (
trade instanceof CurveTrade ||
trade instanceof UniswapTrade ||
trade instanceof ZeroXTrade ||
trade instanceof SwaprV3Trade
) {
return [
{
transactionParameters: trade.swapTransaction({ recipient }),
Expand Down
21 changes: 21 additions & 0 deletions src/lib/eco-router/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
UniswapV2Trade,
VelodromeTrade,
ZeroXTrade,
SwaprV3Trade,
} from '@swapr/sdk'

// Low-level API for Uniswap V2
Expand Down Expand Up @@ -114,6 +115,16 @@ export async function getExactIn(
tradeType: TradeType.EXACT_INPUT,
})
}
// Swapr v3
if (platform.name === RoutablePlatform.SWAPR_V3.name) {
return SwaprV3Trade.getQuote({
quoteCurrency: currencyOut,
amount: currencyAmountIn,
maximumSlippage,
recipient: receiver,
tradeType: TradeType.EXACT_INPUT,
})
}
// Curve
if (platform.name === RoutablePlatform.CURVE.name) {
return CurveTrade.bestTradeExactIn({
Expand Down Expand Up @@ -147,6 +158,7 @@ export async function getExactIn(
tradeType: TradeType.EXACT_INPUT,
})
}

if (platform.name === RoutablePlatform.ONE_INCH.name) {
return OneInchTrade.getQuote({
quoteCurrency: currencyOut,
Expand Down Expand Up @@ -264,6 +276,15 @@ export async function getExactOut(
tradeType: TradeType.EXACT_OUTPUT,
})
}
if (platform.name === RoutablePlatform.SWAPR_V3.name) {
return SwaprV3Trade.getQuote({
quoteCurrency: currencyIn,
amount: currencyAmountOut,
maximumSlippage,
recipient: receiver,
tradeType: TradeType.EXACT_OUTPUT,
})
}
// Trade out doesn't yet work on OneInch
/* if (platform.name === RoutablePlatform.ONE_INCH.name) {
return OneInchTrade.getQuote({
Expand Down
9 changes: 5 additions & 4 deletions src/lib/eco-router/platforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,20 @@ export function getUniswapV2PlatformList(chainId: ChainId): UniswapV2RoutablePla
*/
export function getSupportedPlatformsByChainId(chainId: ChainId) {
return [
RoutablePlatform.ZEROX,
RoutablePlatform.ONE_INCH,
UniswapV2RoutablePlatform.BISWAP,
RoutablePlatform.COW,
RoutablePlatform.CURVE,
UniswapV2RoutablePlatform.DFYN,
UniswapV2RoutablePlatform.HONEYSWAP,
UniswapV2RoutablePlatform.LEVINSWAP,
UniswapV2RoutablePlatform.PANCAKESWAP,
UniswapV2RoutablePlatform.QUICKSWAP,
UniswapV2RoutablePlatform.SUSHISWAP,
UniswapV2RoutablePlatform.SWAPR,
RoutablePlatform.ZEROX,
RoutablePlatform.ONE_INCH,
RoutablePlatform.COW,
RoutablePlatform.CURVE,
RoutablePlatform.UNISWAP,
RoutablePlatform.VELODROME,
RoutablePlatform.SWAPR_V3,
].filter(platform => platform.supportsChain(chainId))
}
1 change: 1 addition & 0 deletions src/pages/Swap/LimitOrderBox/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export async function deleteOpenOrders(chainId: ChainId, uid: string, signer: Si
await cowSdk.cowApi.sendSignedOrderCancellation({
//@ts-ignore
chainId,
//@ts-ignore
cancellation: { orderUid: uid, signature, signingScheme: SigningScheme.EIP712 },
})
const response = await cowSdk.cowApi.getOrder(uid)
Expand Down
8 changes: 7 additions & 1 deletion src/utils/prices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
VelodromeTrade,
ZERO,
ZeroXTrade,
SwaprV3Trade,
} from '@swapr/sdk'

import _Decimal from 'decimal.js-light'
Expand Down Expand Up @@ -70,7 +71,12 @@ export function computeTradePriceBreakdown(trade?: Trade): TradePriceBreakdown {
ONE_HUNDRED_PERCENT
)
return ONE_HUNDRED_PERCENT.subtract(totalRoutesFee)
} else if (trade instanceof CoWTrade || trade instanceof UniswapTrade || trade instanceof ZeroXTrade) {
} else if (
trade instanceof CoWTrade ||
trade instanceof UniswapTrade ||
trade instanceof ZeroXTrade ||
trade instanceof SwaprV3Trade
) {
return trade.fee
} else if (trade instanceof CurveTrade || trade instanceof VelodromeTrade || trade instanceof OneInchTrade) {
return ONE_HUNDRED_PERCENT.subtract(ONE_HUNDRED_PERCENT.subtract(trade.fee))
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7745,7 +7745,7 @@ __metadata:
"@storybook/testing-library": 0.1.0
"@swapr/core": ^0.3.19
"@swapr/periphery": ^0.3.22
"@swapr/sdk": 1.9.4
"@swapr/sdk": 1.10.2
"@synthetixio/synpress": ^2.3.3
"@tanstack/react-query": 4.24.6
"@testing-library/cypress": ^9.0.0
Expand Down Expand Up @@ -7886,9 +7886,9 @@ __metadata:
languageName: node
linkType: hard

"@swapr/sdk@npm:1.9.4":
version: 1.9.4
resolution: "@swapr/sdk@npm:1.9.4"
"@swapr/sdk@npm:1.10.2":
version: 1.10.2
resolution: "@swapr/sdk@npm:1.10.2"
dependencies:
"@cowprotocol/cow-sdk": ^1.0.2-RC.0
"@ethersproject/abi": ^5.6.4
Expand Down Expand Up @@ -7919,7 +7919,7 @@ __metadata:
tslib: ^2.3.1
peerDependencies:
ethers: ^5.4.0
checksum: dc37bdc8f3f7b0c76ef044bf40fdeb48fe715919677acaae86c4cd663b5d845df875298531c01121dbcbb412d43a17f7d2f175ee2982677f14645191e29bb187
checksum: 1a3a7bf14ff805d4783431bb693454e4c1d58a8ac9d329a236371c485fb7e6f461054c4d7fd90bb422d21795a4ff8b8f60cf58df6ddbe45aad1a32a71ee2a66f
languageName: node
linkType: hard

Expand Down
Loading