Skip to content

Commit

Permalink
add SwaprV3 liquidity integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Diogomartf committed Jan 4, 2024
1 parent f3b62d6 commit 4cc78b0
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 12 deletions.
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.1",
"@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.
2 changes: 2 additions & 0 deletions src/components/LandingPageComponents/layout/Hero.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//@ts-nocheck

import { Fragment, ReactNode, useEffect, useState } from 'react'
import Marquee from 'react-fast-marquee'
import styled, { keyframes } from 'styled-components'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//@ts-nocheck

import { Currency, CurrencyAmount, currencyEquals, Token } from '@swapr/sdk'

import { ComponentType, CSSProperties, useCallback, useMemo, useState } from 'react'
Expand Down
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
@@ -1,3 +1,4 @@
//@ts-nocheck
// eslint-disable-next-line no-restricted-imports
/**
* @module limit-orders/api
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@ts-nocheck
import { Web3Provider } from '@ethersproject/providers'
import { parseUnits } from '@ethersproject/units'
import { ChainId, Currency, CurrencyAmount, JSBI, Token, TokenAmount } from '@swapr/sdk'
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.1
"@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.1":
version: 1.10.1
resolution: "@swapr/sdk@npm:1.10.1"
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: 6252df516eb8302bce3cc85fe922310d62b10970a61d27687e974cd6c0ee9a7022022a91441c1555a80d8c5d9b1d91eac88fab1b480e8d60ce46976b453c4fd4
languageName: node
linkType: hard

Expand Down

0 comments on commit 4cc78b0

Please sign in to comment.