From 900c943e1fe585dede99b2a962711d530dfe87f8 Mon Sep 17 00:00:00 2001 From: jhlee-young Date: Mon, 19 Jun 2023 18:51:18 +0900 Subject: [PATCH] feat: support min_assets in lp withdrawa --- src/forms/SwapForm.tsx | 22 +++++++++++++++++++++- src/rest/useAPI.ts | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/forms/SwapForm.tsx b/src/forms/SwapForm.tsx index 27e14093..2ac0e2da 100644 --- a/src/forms/SwapForm.tsx +++ b/src/forms/SwapForm.tsx @@ -32,7 +32,13 @@ import { TooltipIcon } from "components/Tooltip" import Tooltip from "lang/Tooltip.json" import useGasPrice from "rest/useGasPrice" import { hasTaxToken } from "helpers/token" -import { Coins, CreateTxOptions, Fee, SignerInfo } from "@terra-money/terra.js" +import { + Coins, + CreateTxOptions, + Fee, + Numeric, + SignerInfo, +} from "@terra-money/terra.js" import { Type } from "pages/Swap" import usePool from "rest/usePool" import { insertIf } from "libs/utils" @@ -899,6 +905,19 @@ const SwapForm = ({ type, tabs }: { type: Type; tabs: TabViewProps }) => { sender: `${walletAddress}`, amount: `${value1}`, lpAddr: `${lpContract}`, + minAssets: poolResult?.estimated + .split("-") + .map( + (val, idx) => + Numeric.parse(val) + .mul( + Numeric.parse( + (1 - Number(slippageTolerance)).toString() + ) + ) + .toFixed(0) + (idx ? poolContract2 : poolContract1) + ) + .join(","), deadline: Number(txDeadlineMinute), }, }[type] as any @@ -961,6 +980,7 @@ const SwapForm = ({ type, tabs }: { type: Type; tabs: TabViewProps }) => { generateContractMessages, to, lpContract, + poolResult?.estimated, ] ) diff --git a/src/rest/useAPI.ts b/src/rest/useAPI.ts index 2c22ae78..373e73bb 100644 --- a/src/rest/useAPI.ts +++ b/src/rest/useAPI.ts @@ -362,6 +362,7 @@ const useAPI = (version: ApiVersion = "v2") => { lpAddr: string amount: number | string sender: string + minAssets?: string deadline?: number } ) => {