Skip to content

Commit

Permalink
Merge pull request #198 from dezswap/feat/provide-slippage
Browse files Browse the repository at this point in the history
feat: support slippage tolerance for liquidity provision
  • Loading branch information
jhlee-young authored May 10, 2023
2 parents a12122a + 3b5eff6 commit 4f36f63
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/hooks/useAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,16 @@ export const useAPI = (version: ApiVersion = "v1") => {
);

const getVerifiedTokenInfo = useCallback(async () => {
const { data } = await apiClient.get("https://assets.xpla.io/cw20/tokens.json");
const { data } = await apiClient.get(
"https://assets.xpla.io/cw20/tokens.json",
);
return data;
}, []);

const getVerifiedIbcTokenInfo = useCallback(async () => {
const { data } = await apiClient.get("https://assets.xpla.io/ibc/tokens.json");
const { data } = await apiClient.get(
"https://assets.xpla.io/ibc/tokens.json",
);
return data;
}, []);

Expand Down
5 changes: 4 additions & 1 deletion src/pages/Pool/Provide/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import useSettingsModal from "hooks/modals/useSettingsModal";
import ProgressBar from "components/ProgressBar";
import Box from "components/Box";
import useInvalidPathModal from "hooks/modals/useInvalidPathModal";
import useSlippageTolerance from "hooks/useSlippageTolerance";

enum FormKey {
asset1Value = "asset1Value",
Expand All @@ -67,7 +68,7 @@ function ProvidePage() {
const connectedWallet = useConnectedWallet();
const connectWalletModal = useConnectWalletModal();
const settingsModal = useSettingsModal({
items: ["txDeadline"],
items: ["slippageTolerance", "txDeadline"],
});
const { value: txDeadlineMinutes } = useTxDeadlineMinutes();
const { pairAddress } = useParams<{ pairAddress: string }>();
Expand All @@ -78,6 +79,7 @@ function ProvidePage() {
const [isReversed, setIsReversed] = useState(false);
const [balanceApplied, setBalanceApplied] = useState(false);
const network = useNetwork();
const { value: slippageTolerance } = useSlippageTolerance();

const handleModalClose = useCallback(() => {
navigate("/pool", { replace: true });
Expand Down Expand Up @@ -181,6 +183,7 @@ function ProvidePage() {
"0",
},
],
`${slippageTolerance}`,
txDeadlineMinutes ? txDeadlineMinutes * 60 : undefined,
),
}
Expand Down
4 changes: 4 additions & 0 deletions src/utils/dezswap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export const generateAddLiquidityMsg = (
senderAddress: string,
contractAddress: string,
assets: { address: string; amount: string }[],
slippageTolerance: string,
txDeadlineSeconds = 1200,
) => [
...assets
Expand Down Expand Up @@ -141,6 +142,9 @@ export const generateAddLiquidityMsg = (
deadline: Number(
Number((Date.now() / 1000).toFixed(0)) + txDeadlineSeconds,
),
slippage_tolerance: `${(parseFloat(slippageTolerance) / 100).toFixed(
4,
)}`,
},
},
getCoins(assets),
Expand Down

0 comments on commit 4f36f63

Please sign in to comment.