Skip to content

Commit

Permalink
feat(SWA-146): add Openocean support (#1913)
Browse files Browse the repository at this point in the history
* feat(SWA-146): add Openocean logo
* feat(SWA-146): add OO as routable platform
---------

Co-authored-by: Berteotti <[email protected]>
  • Loading branch information
ElRodrigote and berteotti authored Mar 22, 2024
1 parent f914f90 commit 3e9860d
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 11 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.11.3",
"@swapr/sdk": "1.11.4",
"@tanstack/react-query": "4.24.6",
"@uniswap/token-lists": "^1.0.0-beta.27",
"@uniswap/v3-periphery": "1.4.1",
Expand Down
Binary file added src/assets/images/openocean-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 16 additions & 2 deletions src/constants/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import LevinswapLogo from '../assets/images/levinswap-logo.svg'
import SwaprLogo from '../assets/images/logo.svg'
import ZeroXLogo from '../assets/images/logos/ZeroX.svg'
import Metamask from '../assets/images/metamask.png'
import OpenoceanLogo from '../assets/images/openocean-logo.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'
Expand Down Expand Up @@ -683,6 +684,7 @@ export const RoutablePlatformKeysByNetwork = {
RoutablePlatform.UNISWAP.name,
UniswapV2RoutablePlatform.SUSHISWAP.name,
RoutablePlatform.ONE_INCH.name,
RoutablePlatform.OPENOCEAN.name,
],
[ChainId.ARBITRUM_RINKEBY]: [
UniswapV2RoutablePlatform.SWAPR.name,
Expand All @@ -698,6 +700,7 @@ export const RoutablePlatformKeysByNetwork = {
UniswapV2RoutablePlatform.SUSHISWAP.name,
UniswapV2RoutablePlatform.PANCAKESWAP.name,
RoutablePlatform.ONE_INCH.name,
RoutablePlatform.OPENOCEAN.name,
],
[ChainId.BSC_TESTNET]: [],
[ChainId.GOERLI]: [],
Expand All @@ -708,6 +711,7 @@ export const RoutablePlatformKeysByNetwork = {
RoutablePlatform.ZEROX.name,
RoutablePlatform.GNOSIS_PROTOCOL.name,
RoutablePlatform.ONE_INCH.name,
RoutablePlatform.OPENOCEAN.name,
],
[ChainId.OPTIMISM_GOERLI]: [],
[ChainId.OPTIMISM_MAINNET]: [
Expand All @@ -716,6 +720,7 @@ export const RoutablePlatformKeysByNetwork = {
RoutablePlatform.CURVE.name,
RoutablePlatform.VELODROME.name,
RoutablePlatform.ONE_INCH.name,
RoutablePlatform.OPENOCEAN.name,
],
[ChainId.POLYGON]: [
RoutablePlatform.UNISWAP.name,
Expand All @@ -724,6 +729,7 @@ export const RoutablePlatformKeysByNetwork = {
UniswapV2RoutablePlatform.DFYN.name,
RoutablePlatform.ZEROX.name,
RoutablePlatform.ONE_INCH.name,
RoutablePlatform.OPENOCEAN.name,
],
[ChainId.RINKEBY]: [
UniswapV2RoutablePlatform.SWAPR.name,
Expand All @@ -734,7 +740,7 @@ export const RoutablePlatformKeysByNetwork = {
UniswapV2RoutablePlatform.BAOSWAP.name,
RoutablePlatform.CURVE.name,
],
[ChainId.SCROLL_MAINNET]: [RoutablePlatform.SUSHISWAP.name],
[ChainId.SCROLL_MAINNET]: [RoutablePlatform.OPENOCEAN.name, RoutablePlatform.SUSHISWAP.name],
[ChainId.XDAI]: [
UniswapV2RoutablePlatform.SWAPR.name,
RoutablePlatform.UNISWAP.name,
Expand All @@ -745,8 +751,9 @@ export const RoutablePlatformKeysByNetwork = {
RoutablePlatform.CURVE.name,
RoutablePlatform.GNOSIS_PROTOCOL.name,
RoutablePlatform.ONE_INCH.name,
RoutablePlatform.OPENOCEAN.name,
],
[ChainId.ZK_SYNC_ERA_MAINNET]: [RoutablePlatform.ONE_INCH.name],
[ChainId.ZK_SYNC_ERA_MAINNET]: [RoutablePlatform.ONE_INCH.name, RoutablePlatform.OPENOCEAN.name],
[ChainId.ZK_SYNC_ERA_TESTNET]: [],
}

Expand Down Expand Up @@ -869,6 +876,12 @@ export const ROUTABLE_PLATFORM_STYLE: {
gradientColor: '#FB52A1',
name: RoutablePlatform.SUSHISWAP.name,
},
[RoutablePlatform.OPENOCEAN.name]: {
logo: OpenoceanLogo,
alt: RoutablePlatform.OPENOCEAN.name,
gradientColor: '#FB52A1',
name: RoutablePlatform.OPENOCEAN.name,
},
}

export const ROUTABLE_PLATFORM_LOGO: {
Expand All @@ -892,6 +905,7 @@ export const ROUTABLE_PLATFORM_LOGO: {
[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" />,
[RoutablePlatform.SUSHISWAP.name]: <img width={16} height={16} src={SushiswapNewLogo} alt="sushiswap" />,
[RoutablePlatform.OPENOCEAN.name]: <img width={16} height={16} src={OpenoceanLogo} alt="openocean" />,
}

export const ChainLabel: any = {
Expand Down
5 changes: 3 additions & 2 deletions src/hooks/useSwapCallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
CoWTrade,
CurveTrade,
OneInchTrade,
OpenoceanTrade,
Trade,
TradeType,
UniswapTrade,
Expand Down Expand Up @@ -84,13 +85,13 @@ export function useSwapsCallArguments(
}

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

// Low-level API for Uniswap V2
Expand Down Expand Up @@ -136,6 +137,16 @@ export async function getExactIn(
tradeType: TradeType.EXACT_INPUT,
})
}
// Openocean
if (platform.name === RoutablePlatform.OPENOCEAN.name) {
return OpenoceanTrade.getQuote({
quoteCurrency: currencyOut,
amount: currencyAmountIn,
maximumSlippage,
recipient: receiver,
tradeType: TradeType.EXACT_INPUT,
})
}
// Curve
if (platform.name === RoutablePlatform.CURVE.name) {
return CurveTrade.bestTradeExactIn({
Expand Down
1 change: 1 addition & 0 deletions src/lib/eco-router/platforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ export function getSupportedPlatformsByChainId(chainId: ChainId) {
RoutablePlatform.VELODROME,
RoutablePlatform.SWAPR_V3,
RoutablePlatform.SUSHISWAP,
RoutablePlatform.OPENOCEAN,
].filter(platform => platform.supportsChain(chainId))
}
4 changes: 3 additions & 1 deletion src/utils/prices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
ZeroXTrade,
SwaprV3Trade,
SushiswapTrade,
OpenoceanTrade,
} from '@swapr/sdk'

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

"@swapr/sdk@npm:1.11.3":
version: 1.11.3
resolution: "@swapr/sdk@npm:1.11.3"
"@swapr/sdk@npm:1.11.4":
version: 1.11.4
resolution: "@swapr/sdk@npm:1.11.4"
dependencies:
"@cowprotocol/cow-sdk": ^1.0.2-RC.0
"@ethersproject/abi": ^5.6.4
Expand Down Expand Up @@ -8603,7 +8603,7 @@ __metadata:
tslib: ^2.3.1
peerDependencies:
ethers: ^5.4.0
checksum: 14eae4662ce191d30e6749b6be6514545a9965e22b0c00a138821a265599791fce9055dbdbc8dd75eff8ffef6b04274eb1ad588ec66d89abee0b8db4ead23e10
checksum: 2ae6bb18dec24ad0ef91ab968335e288d76beb756d62b21e013a25210397cc4ee5006e17b20d4279291c4371f06f23e6baf9bbcd1ac7fc8b979b1eb88888b140
languageName: node
linkType: hard

Expand Down

0 comments on commit 3e9860d

Please sign in to comment.