Skip to content

Commit

Permalink
Fix USDT decimals (#545)
Browse files Browse the repository at this point in the history
* fix usdt decimals

* valid fee rate check

* fix FEE_RATE_MAX

* update FeeRateInput placeholder
  • Loading branch information
JayJay1024 authored Oct 24, 2023
1 parent 7ac9210 commit 58ed7ce
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/apps/src/components/fee-rate-input.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Input from "@/ui/input";
import { parseFeeRate } from "@/utils/misc";
import { isValidFeeRate, parseFeeRate } from "@/utils/misc";

export default function FeeRateInput({
placeholder,
Expand All @@ -10,7 +10,7 @@ export default function FeeRateInput({
value?: { formatted: number; value: string };
onChange?: (value: { formatted: number; value: string }) => void;
}) {
const invalid = (value?.formatted || 0) < 0 || 100000 < (value?.formatted || 0);
const invalid = !isValidFeeRate(value?.formatted || 0);
return (
<div
className={`gap-small bg-app-bg p-small lg:p-middle normal-input-wrap flex items-center justify-between ${
Expand Down
4 changes: 2 additions & 2 deletions packages/apps/src/components/relayer-manage-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useNetwork, useSwitchNetwork } from "wagmi";
import { formatBalance } from "@/utils/balance";
import { useRelayer } from "@/hooks/use-relayer";
import dynamic from "next/dynamic";
import { formatFeeRate } from "@/utils/misc";
import { formatFeeRate, isValidFeeRate } from "@/utils/misc";

type TabKey = "update" | "deposit" | "withdraw";
const Modal = dynamic(() => import("@/ui/modal"), { ssr: false });
Expand Down Expand Up @@ -207,7 +207,7 @@ export default function RelayerManageModal({ relayerInfo, isOpen, onClose, onSuc
busy={busy}
disabledCancel={busy}
disabledOk={
activeKey === "update" && baseFee.formatted === 0n && feeRate.formatted === 0
activeKey === "update" && !(baseFee.value && feeRate.value && isValidFeeRate(feeRate.formatted))
? true
: activeKey === "deposit" && margin.formatted === 0n
? true
Expand Down
7 changes: 4 additions & 3 deletions packages/apps/src/components/relayer-register.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Token, TokenSymbol } from "@/types/token";
import { BridgeCategory } from "@/types/bridge";
import { useAccount, useNetwork, useSwitchNetwork } from "wagmi";
import Image from "next/image";
import { formatFeeRate, getChainLogoSrc, getTokenLogoSrc } from "@/utils/misc";
import { formatFeeRate, getChainLogoSrc, getTokenLogoSrc, isValidFeeRate } from "@/utils/misc";
import Tooltip from "@/ui/tooltip";
import StepCompleteItem from "./step-complete-item";
import { BalanceInput } from "./balance-input";
Expand Down Expand Up @@ -321,7 +321,7 @@ export default function RelayerRegister() {
label="Liquidity Fee Rate"
tips="The percentage deducted by the relayer from the transfer amount in a transaction"
>
<FeeRateInput placeholder="Enter 0 ~ 100" value={feeRate} onChange={setFeeRate} />
<FeeRateInput placeholder="Enter 0 ~ 0.25" value={feeRate} onChange={setFeeRate} />
</LabelItem>

<Divider />
Expand Down Expand Up @@ -372,7 +372,8 @@ export default function RelayerRegister() {
}
}}
disabled={
(sourceChain?.id === chain?.id && (!margin.formatted || !baseFee.formatted || !feeRate.formatted)) ||
(sourceChain?.id === chain?.id &&
!(margin.value && baseFee.value && feeRate.value && isValidFeeRate(feeRate.formatted))) ||
(bridgeCategory === "lnbridgev20-default" && !completeMargin)
}
busy={busy}
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/src/config/chains/arbitrum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const arbitrumChain: ChainConfig = {
cross: [{ target: { network: "ethereum", symbol: "RING" }, bridge: { category: "lnbridgev20-opposite" } }],
},
{
decimals: 18,
decimals: 6,
symbol: "USDT",
name: "USDT",
type: "erc20",
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/src/config/chains/mantle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const mantleChain: ChainConfig = {
},
tokens: [
{
decimals: 18,
decimals: 6,
symbol: "USDT",
name: "USDT",
type: "erc20",
Expand Down
3 changes: 3 additions & 0 deletions packages/apps/src/config/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
* If the fee rate is 10.123%, its value in the contract is 10123 (10.123 * 1000)
*/
export const FEE_RATE_BASE = 1000;

export const FEE_RATE_MIN = 0;
export const FEE_RATE_MAX = 0.25 * FEE_RATE_BASE; // 0.25%
6 changes: 5 additions & 1 deletion packages/apps/src/utils/misc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FEE_RATE_BASE } from "@/config/constant";
import { FEE_RATE_BASE, FEE_RATE_MAX, FEE_RATE_MIN } from "@/config/constant";
import { RecordStatus } from "@/types/graphql";

export function formatRecordStatus(status: RecordStatus) {
Expand Down Expand Up @@ -37,3 +37,7 @@ export function parseFeeRate(rate: string) {
export function formatFeeRate(rate: number) {
return Number((rate / FEE_RATE_BASE).toFixed(3));
}

export function isValidFeeRate(formatted: number) {
return FEE_RATE_MIN <= formatted && formatted <= FEE_RATE_MAX;
}

0 comments on commit 58ed7ce

Please sign in to comment.