Skip to content

Commit ab3f7df

Browse files
committed
feat: correct slippage and price
1 parent 3d5301c commit ab3f7df

File tree

1 file changed

+15
-23
lines changed

1 file changed

+15
-23
lines changed

apps/namadillo/src/App/Ibc/OsmosisSwap.tsx

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { AccountType, BparamsMsgValue } from "@namada/types";
2-
import { calcAmountWithSlippage } from "@osmonauts/math";
32
import { defaultAccountAtom } from "atoms/accounts";
43
import {
54
namadaShieldedAssetsAtom,
@@ -25,7 +24,7 @@ async function _fetchPrices(coinGeckoIds: string[]): Promise<any> {
2524
}
2625

2726
const SUPPORTED_TOKENS_SYMBOLS = ["OSMO", "ATOM", "TIA"] as const;
28-
const SLIPPAGE = 0.1;
27+
const SLIPPAGE = 0.005;
2928

3029
export const OsmosisSwap: React.FC = () => {
3130
const osmosisSymbolAssetsMap = useAtomValue(osmosisSymbolAssetMapAtom);
@@ -62,10 +61,10 @@ export const OsmosisSwap: React.FC = () => {
6261
const response: SwapResponse = await quote.json();
6362

6463
if (!(response as SwapResponseError).message) {
65-
const minAmount = calcAmountWithSlippage(
66-
(response as SwapResponseOk).amount_out,
67-
SLIPPAGE
68-
);
64+
const r = response as SwapResponseOk;
65+
const minAmount = BigNumber(r.amount_out)
66+
.times(BigNumber(1).minus(SLIPPAGE))
67+
.toString();
6968
setQuote({ ...(response as SwapResponseOk), minAmount });
7069
} else {
7170
setQuote(null);
@@ -233,8 +232,17 @@ export const OsmosisSwap: React.FC = () => {
233232
Min amount out: {quote.minAmount}
234233
{osmosisBaseAssetsMap[to].denom_units[0].aliases?.[0] || to}
235234
</div>
236-
<div>Slippage: {SLIPPAGE}%</div>
235+
<div>Slippage: {SLIPPAGE * 100}%</div>
237236
<div>Routes: </div>
237+
<div>Effective fee: {BigNumber(quote.effective_fee).toString()}</div>
238+
<div>
239+
Price: 1 {osmosisBaseAssetsMap[from].symbol}{" "}
240+
{BigNumber(quote.amount_out).div(BigNumber(amount)).toString()}{" "}
241+
{osmosisBaseAssetsMap[to].symbol}
242+
</div>
243+
<div>
244+
Price impact: {BigNumber(quote.price_impact).dp(3).toString()}
245+
</div>
238246
<ul className="list-disc list-inside">
239247
{quote.route.map((r, i) => (
240248
<li key={i}>
@@ -250,22 +258,6 @@ export const OsmosisSwap: React.FC = () => {
250258
</li>
251259
))}
252260
</ul>
253-
<div>Effective fee: {BigNumber(quote.effective_fee).toString()}</div>
254-
<div>
255-
Price: 1 {osmosisBaseAssetsMap[from].symbol}{" "}
256-
{BigNumber(quote.in_base_out_quote_spot_price)
257-
.times(
258-
BigNumber(1)
259-
.minus(BigNumber(quote.effective_fee))
260-
.plus(BigNumber(quote.price_impact))
261-
)
262-
.dp(3)
263-
.toString()}{" "}
264-
{osmosisBaseAssetsMap[to].symbol}
265-
</div>
266-
<div>
267-
Price impact: {BigNumber(quote.price_impact).dp(3).toString()}
268-
</div>
269261
</div>
270262
)}
271263
</div>

0 commit comments

Comments
 (0)