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 Dec 7, 2023
1 parent f3b62d6 commit f8a9a4f
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 6 deletions.
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]: {

Check failure on line 822 in src/constants/index.tsx

View workflow job for this annotation

GitHub Actions / ⬡・Typecheck

Property 'SWAPR_V3' does not exist on type 'typeof RoutablePlatform'.
logo: SwaprV3Logo,
alt: RoutablePlatform.SWAPR_V3.name,

Check failure on line 824 in src/constants/index.tsx

View workflow job for this annotation

GitHub Actions / ⬡・Typecheck

Property 'SWAPR_V3' does not exist on type 'typeof RoutablePlatform'.
gradientColor: '#9185F7',
name: RoutablePlatform.SWAPR_V3.name,

Check failure on line 826 in src/constants/index.tsx

View workflow job for this annotation

GitHub Actions / ⬡・Typecheck

Property 'SWAPR_V3' does not exist on type 'typeof RoutablePlatform'.
},
}

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" />,

Check failure on line 849 in src/constants/index.tsx

View workflow job for this annotation

GitHub Actions / ⬡・Typecheck

Property 'SWAPR_V3' does not exist on type 'typeof RoutablePlatform'.
}

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,

Check failure on line 14 in src/hooks/useSwapCallback.ts

View workflow job for this annotation

GitHub Actions / ⬡・Typecheck

Module '"@swapr/sdk"' has no exported member '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 }),

Check failure on line 95 in src/hooks/useSwapCallback.ts

View workflow job for this annotation

GitHub Actions / ⬡・Typecheck

Property 'swapTransaction' does not exist on type 'Trade'.
Expand Down
29 changes: 29 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,

Check failure on line 18 in src/lib/eco-router/api.ts

View workflow job for this annotation

GitHub Actions / ⬡・Typecheck

Module '"@swapr/sdk"' has no exported member 'SwaprV3Trade'.
} from '@swapr/sdk'

// Low-level API for Uniswap V2
Expand Down Expand Up @@ -114,6 +115,20 @@ export async function getExactIn(
tradeType: TradeType.EXACT_INPUT,
})
}
// Swapr v3
if (platform.name === RoutablePlatform.SWAPR_V3.name) {

Check failure on line 119 in src/lib/eco-router/api.ts

View workflow job for this annotation

GitHub Actions / ⬡・Typecheck

Property 'SWAPR_V3' does not exist on type 'typeof RoutablePlatform'.
// console.log('--- Exact input ---')
// console.log('currencyOut-quoteCurrency:', currencyOut)
// console.log('currencyAmountIn-amount:', currencyAmountIn)

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 +162,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 +280,19 @@ export async function getExactOut(
tradeType: TradeType.EXACT_OUTPUT,
})
}
if (platform.name === RoutablePlatform.SWAPR_V3.name) {

Check failure on line 283 in src/lib/eco-router/api.ts

View workflow job for this annotation

GitHub Actions / ⬡・Typecheck

Property 'SWAPR_V3' does not exist on type 'typeof RoutablePlatform'.
// console.log('--- EXACT_OUTPUT ---')
// console.log('currencyIn-quoteCurrency:', currencyIn)
// console.log('currencyAmountOut-amount:', currencyAmountOut)

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,

Check failure on line 40 in src/lib/eco-router/platforms.ts

View workflow job for this annotation

GitHub Actions / ⬡・Typecheck

Property 'SWAPR_V3' does not exist on type 'typeof RoutablePlatform'.
].filter(platform => platform.supportsChain(chainId))
}
1 change: 1 addition & 0 deletions src/pages/Swap/Components/TradeDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export function TradeDetails({
const [showAddRecipient, setShowAddRecipient] = useState<boolean>(false)
// errors
const [showInverted, setShowInverted] = useState<boolean>(false)
console.log('trade details:', trade)

if (loading) {
return (
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

0 comments on commit f8a9a4f

Please sign in to comment.