Skip to content

Commit b15001a

Browse files
committed
feat: add deep liquidity flag
1 parent 9d8edcc commit b15001a

6 files changed

Lines changed: 42 additions & 6 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@reserve-protocol/react-zapper",
3-
"version": "1.5.8",
3+
"version": "1.5.9",
44
"type": "module",
55
"description": "React component for DTF minting with zap functionality",
66
"main": "dist/index.cjs.js",

src/components/zap-mint/zap-settings.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { ChainId } from '@/utils/chains'
22
import { broom } from '@lucide/lab'
33
import { useAtom, useAtomValue } from 'jotai'
4-
import { Anvil, Icon, Route, Zap } from 'lucide-react'
4+
import { Anvil, Icon, Route, Search, Zap } from 'lucide-react'
55
import {
66
chainIdAtom,
7+
deepLiquidityAtom,
78
quoteSourceAtom,
89
type QuoteSource,
910
} from '../../state/atoms'
@@ -39,6 +40,7 @@ const ZapSettings = () => {
3940
const [slippage, setSlippage] = useAtom(slippageAtom)
4041
const [forceMint, setForceMint] = useAtom(forceMintAtom)
4142
const [quoteSource, setQuoteSource] = useAtom(quoteSourceAtom)
43+
const [deepLiquidity, setDeepLiquidity] = useAtom(deepLiquidityAtom)
4244

4345
const handleSlippageChange = (value: string) => {
4446
setSlippage(value)
@@ -53,6 +55,11 @@ const ZapSettings = () => {
5355
setQuoteSource(value)
5456
}
5557

58+
const handleDeepLiquidityChange = (value: boolean | 'indeterminate') => {
59+
const newValue = value === 'indeterminate' ? false : value
60+
setDeepLiquidity(newValue)
61+
}
62+
5663
return (
5764
<div className="min-h-[306px] border-t border-border -mx-2 px-2 py-4 flex flex-col gap-4">
5865
<div className="flex flex-col gap-2">
@@ -105,6 +112,22 @@ const ZapSettings = () => {
105112
hideTitle
106113
/>
107114
</div>
115+
<div className="flex flex-col gap-2">
116+
<ZapSettingsRowTitle
117+
title="Enable Deep liquidity search?"
118+
help="Can improve price impact but it will take more time to get quotes."
119+
/>
120+
<div className="rounded-xl border border-border px-3 py-3 flex items-center gap-1 justify-between">
121+
<div className="flex items-center gap-1">
122+
<Search size={16} className="text-muted-foreground" />
123+
<div>Deep liquidity search</div>
124+
</div>
125+
<Checkbox
126+
checked={deepLiquidity}
127+
onCheckedChange={handleDeepLiquidityChange}
128+
/>
129+
</div>
130+
</div>
108131
<div className="flex flex-col gap-2">
109132
<ZapSettingsRowTitle
110133
title="Force DTF mint?"

src/hooks/useZapSwapQuery.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
import {
1010
apiUrlAtom,
1111
chainIdAtom,
12+
deepLiquidityAtom,
1213
indexDTFAtom,
1314
quoteSourceAtom,
1415
walletAtom,
@@ -74,6 +75,7 @@ const useZapSwapQuery = ({
7475
const quoteSource = useAtomValue(quoteSourceAtom)
7576
const setZapSwapEndpoint = useSetAtom(zapSwapEndpointAtom)
7677
const debug = useAtomValue(zapperDebugAtom)
78+
const deepLiquidity = useAtomValue(deepLiquidityAtom)
7779
const sessionId = useAtomValue(sessionIdAtom)
7880
const setQuoteId = useSetAtom(quoteIdAtom)
7981
const setRetryId = useSetAtom(retryIdAtom)
@@ -103,6 +105,7 @@ const useZapSwapQuery = ({
103105
trade: !forceMint,
104106
bypassCache: false,
105107
debug,
108+
deepLiquidity,
106109
})
107110

108111
if (!includeTracking) {
@@ -127,6 +130,7 @@ const useZapSwapQuery = ({
127130
account,
128131
forceMint,
129132
debug,
133+
deepLiquidity,
130134
sessionId,
131135
]
132136
)

src/state/atoms.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const walletAtom = atom<Address | undefined>(undefined)
2121
/**
2222
* Connect wallet atom - callback to be called to connect a wallet
2323
*/
24-
export const connectWalletAtom = atom<{ fn: () => void }>({ fn: () => {} })
24+
export const connectWalletAtom = atom<{ fn: () => void }>({ fn: () => { } })
2525

2626
/**
2727
* Token balances atom - maps token addresses to their balances
@@ -86,3 +86,10 @@ export const indexDTFIconsAtom = atom<Record<number, Record<string, string>>>(
8686
*/
8787
export type QuoteSource = 'best' | 'zap' | 'odos'
8888
export const quoteSourceAtom = atom<QuoteSource>('best')
89+
90+
/**
91+
* Enables deep liquidity search on the zapper
92+
* This will do a deeper look on available liquidity pools in order to improve price impact
93+
* It will make quotes slightly slower
94+
*/
95+
export const deepLiquidityAtom = atom(false)

src/types/api.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export type ZapPayload = {
1818
trade?: boolean
1919
bypassCache?: boolean
2020
debug?: boolean
21+
deepLiquidity?: boolean
2122
}
2223

2324
export type ZapResult = {
@@ -101,11 +102,12 @@ const zapper = {
101102
trade = true,
102103
bypassCache = false,
103104
debug = false,
105+
deepLiquidity = false,
104106
}: ZapPayload) =>
105107
`${getBaseZapApiUrl(
106108
url,
107109
chainId
108-
)}/swap?chainId=${chainId}&signer=${signer}&tokenIn=${tokenIn}&amountIn=${amountIn}&tokenOut=${tokenOut}&slippage=${slippage}&trade=${trade}&bypassCache=${bypassCache}${
110+
)}/swap?chainId=${chainId}&signer=${signer}&tokenIn=${tokenIn}&amountIn=${amountIn}&tokenOut=${tokenOut}&slippage=${slippage}&trade=${trade}&bypassCache=${bypassCache}&deepLiquidity=${deepLiquidity}${
109111
debug ? '&debug=true' : ''
110112
}`,
111113

0 commit comments

Comments
 (0)