Adjust UI displayed toAmount for taker fees (#47)
This commit is contained in:
parent
b23d21b0a7
commit
6125d18e3b
|
@ -16,7 +16,7 @@ import {
|
|||
useOpenOrders,
|
||||
useRouteVerbose,
|
||||
useMarket,
|
||||
BASE_TAKER_FEE_BPS,
|
||||
FEE_MULTIPLIER,
|
||||
} from "../context/Dex";
|
||||
import { useTokenMap } from "../context/TokenList";
|
||||
import { useMint, useOwnedTokenAccount } from "../context/Token";
|
||||
|
@ -342,9 +342,7 @@ export function SwapButton() {
|
|||
}
|
||||
const amount = new BN(fromAmount * 10 ** fromMintInfo.decimals);
|
||||
const minExchangeRate = {
|
||||
rate: new BN(
|
||||
(10 ** toMintInfo.decimals * (1 - BASE_TAKER_FEE_BPS)) / fair
|
||||
)
|
||||
rate: new BN((10 ** toMintInfo.decimals * FEE_MULTIPLIER) / fair)
|
||||
.muln(100 - slippage)
|
||||
.divn(100),
|
||||
fromDecimals: fromMintInfo.decimals,
|
||||
|
|
|
@ -25,7 +25,8 @@ import { useTokenMap, useTokenListContext } from "./TokenList";
|
|||
import { fetchSolletInfo, requestWormholeSwapMarketIfNeeded } from "./Sollet";
|
||||
import { setMintCache } from "./Token";
|
||||
|
||||
export const BASE_TAKER_FEE_BPS = 0.0022;
|
||||
const BASE_TAKER_FEE_BPS = 0.0022;
|
||||
export const FEE_MULTIPLIER = 1 - BASE_TAKER_FEE_BPS;
|
||||
|
||||
type DexContext = {
|
||||
// Maps market address to open orders accounts.
|
||||
|
|
|
@ -9,7 +9,12 @@ import {
|
|||
} from "@solana/spl-token";
|
||||
import { Market } from "@project-serum/serum";
|
||||
import { SRM_MINT, USDC_MINT, USDT_MINT } from "../utils/pubkeys";
|
||||
import { useFairRoute, useRouteVerbose, useDexContext } from "./Dex";
|
||||
import {
|
||||
useFairRoute,
|
||||
useRouteVerbose,
|
||||
useDexContext,
|
||||
FEE_MULTIPLIER,
|
||||
} from "./Dex";
|
||||
import {
|
||||
useTokenListContext,
|
||||
SPL_REGISTRY_SOLLET_TAG,
|
||||
|
@ -99,7 +104,7 @@ export function SwapContextProvider(props: any) {
|
|||
throw new Error("Fair price not found");
|
||||
}
|
||||
_setFromAmount(amount);
|
||||
_setToAmount(amount / fair);
|
||||
_setToAmount(FEE_MULTIPLIER * (amount / fair));
|
||||
};
|
||||
|
||||
const setToAmount = (amount: number) => {
|
||||
|
@ -107,7 +112,7 @@ export function SwapContextProvider(props: any) {
|
|||
throw new Error("Fair price not found");
|
||||
}
|
||||
_setToAmount(amount);
|
||||
_setFromAmount(amount * fair);
|
||||
_setFromAmount((amount * fair) / FEE_MULTIPLIER);
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
Loading…
Reference in New Issue