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