Skip to content
This repository has been archived by the owner on Apr 17, 2024. It is now read-only.

Commit

Permalink
perf: code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
JayJay1024 committed Mar 29, 2024
1 parent d3df880 commit baac712
Show file tree
Hide file tree
Showing 16 changed files with 10 additions and 567 deletions.
8 changes: 0 additions & 8 deletions src/bridges/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ export abstract class BaseBridge {
options?: TransferOptions & { askEstimateGas?: boolean },
): Promise<TransactionReceipt | bigint | undefined>;

isLnBridge() {
return false;
}

getLogo() {
return this.logo;
}
Expand All @@ -103,10 +99,6 @@ export abstract class BaseBridge {
return this.name;
}

getCategory() {
return this.category;
}

getContract() {
return this.contract;
}
Expand Down
34 changes: 0 additions & 34 deletions src/components/address-input.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/bridge-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default function BridgeSelect({ value, options = [], onChange = () => und
function bridgeName(category: BridgeCategory | null | undefined) {
if (category) {
const bridge = bridgeFactory({ category });
return bridge ? bridge.getName() : category === "lnbridge" ? "Helix LnBridge" : undefined;
return bridge?.getName();
}
return undefined;
}
2 changes: 1 addition & 1 deletion src/components/transfer-action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default function TransferAction({ recipient, transferable, transferAmount
sourceToken &&
targetToken &&
bridgeInstance &&
(bridgeInstance.getCategory().startsWith("xtoken") || bridgeFee) &&
bridgeFee &&
transferable &&
transferAmount.input &&
transferAmount.valid &&
Expand Down
8 changes: 0 additions & 8 deletions src/config/constant.ts

This file was deleted.

89 changes: 0 additions & 89 deletions src/config/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,46 +83,6 @@ export const GQL_HISTORY_RECORD_BY_ID = gql`
}
`;

export const GQL_QUERY_LNBRIDGE_RELAY_INFOS = gql`
query queryLnBridgeRelayInfos(
$fromChain: String
$toChain: String
$relayer: String
$row: Int
$page: Int
$version: String
) {
queryLnBridgeRelayInfos(
fromChain: $fromChain
toChain: $toChain
relayer: $relayer
row: $row
page: $page
version: $version
) {
total
records {
id
fromChain
toChain
bridge
relayer
sendToken
margin
baseFee
liquidityFeeRate
cost
profit
heartbeatTimestamp
messageChannel
lastTransferId
withdrawNonce
transferLimit
}
}
}
`;

export const GQL_HISTORY_RECORD_BY_TX_HASH = gql`
query historyRecordByTxHash($txHash: String) {
historyRecordByTxHash(txHash: $txHash) {
Expand All @@ -132,52 +92,3 @@ export const GQL_HISTORY_RECORD_BY_TX_HASH = gql`
}
}
`;

export const GQL_CHECK_LNBRIDGE_EXIST = gql`
query checkLnBridgeExist($fromChainId: Int, $toChainId: Int, $fromToken: String, $toToken: String, $version: String) {
checkLnBridgeExist(
fromChainId: $fromChainId
toChainId: $toChainId
fromToken: $fromToken
toToken: $toToken
version: $version
)
}
`;

export const GQL_GET_LN_BRIDGE_MESSAGE_CHANNEL = gql`
query GetLnBridgeMessageChannel($bridge: String = "", $fromChain: String = "", $toChain: String = "") {
queryLnBridgeRelayInfos(row: 1, page: 0, bridge: $bridge, fromChain: $fromChain, toChain: $toChain) {
records {
messageChannel
}
}
}
`;

export const GQL_GET_WITHDRAWABLE_LIQUIDITIES = gql`
query GetWithdrawableLiquidities(
$page: Int!
$relayer: String = ""
$recvTokenAddress: String = ""
$fromChain: String = ""
$toChain: String = ""
) {
historyRecords(
row: 10
page: $page
relayer: $relayer
recvTokenAddress: $recvTokenAddress
fromChains: [$fromChain]
toChains: [$toChain]
needWithdrawLiquidity: true
) {
total
records {
id
sendAmount
lastRequestWithdraw
}
}
}
`;
1 change: 0 additions & 1 deletion src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from "./constant";
export * from "./gql";
27 changes: 2 additions & 25 deletions src/types/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@ import { Address, Hex } from "viem";
import { PublicClient, WalletClient } from "wagmi";
import { ChainConfig } from "./chain";
import { Token } from "./token";
import { MessageChannel } from "./graphql";

export type LnBridgeVersion = "lnv2" | "lnv3";
export type LnBridgeV2Type = "default" | "opposite";

/**
* `lpbridge-darwinia-dvm` etc. are named from graphql indexer, except `lnbridge`.
* `lpbridge-darwinia-dvm` etc. are named from graphql indexer.
*/
export type LnBridgeCategory = "lnbridge" | "lnv2-default" | "lnv2-opposite" | "lnv3";
export type L2BridgeCategory = "l2arbitrumbridge-ethereum";
export type HelixLpBridgeCategory = "lpbridge-darwinia-dvm" | "lpbridge-ethereum";
export type HelixBridgeCategory =
Expand All @@ -24,12 +19,7 @@ export type XTokenBridgeCategory =
| "xtoken-darwinia-dvm"
| "xtoken-crab-dvm"
| "xtoken-pangolin-dvm";
export type BridgeCategory =
| LnBridgeCategory
| L2BridgeCategory
| HelixLpBridgeCategory
| HelixBridgeCategory
| XTokenBridgeCategory;
export type BridgeCategory = L2BridgeCategory | HelixLpBridgeCategory | HelixBridgeCategory | XTokenBridgeCategory;

export interface BridgeContract {
sourceAddress: Address;
Expand All @@ -55,8 +45,6 @@ export interface BridgeConstructorArgs {

export interface GetFeeArgs {
baseFee?: bigint;
protocolFee?: bigint;
liquidityFeeRate?: bigint;
transferAmount?: bigint;
sender?: Address;
recipient?: Address;
Expand All @@ -67,15 +55,4 @@ export interface TransferOptions {
relayer?: Address;
transferId?: Hex | null;
totalFee?: bigint;
withdrawNonce?: bigint;
depositedMargin?: bigint;
}

export interface GetWithdrawFeeArgs {
amount: bigint;
sender?: Address;
relayer?: Address;
transferId?: Hex | null;
withdrawNonce?: string | null;
messageChannel?: MessageChannel | null;
}
6 changes: 3 additions & 3 deletions src/types/cross-chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Action = "issue" | "redeem";
export type CrossChain =
| {
target: Target;
bridge: { category: L2BridgeCategory; lnv2Type?: never };
bridge: { category: L2BridgeCategory };
index?: never;
price?: never;
baseFee?: never;
Expand All @@ -28,7 +28,7 @@ export type CrossChain =
}
| {
target: Target;
bridge: { category: HelixBridgeCategory | XTokenBridgeCategory; lnv2Type?: never };
bridge: { category: HelixBridgeCategory | XTokenBridgeCategory };
index?: never;
price?: never;
baseFee?: never;
Expand All @@ -38,7 +38,7 @@ export type CrossChain =
}
| {
target: Target;
bridge: { category: HelixLpBridgeCategory; lnv2Type?: never };
bridge: { category: HelixLpBridgeCategory };
index: number; // One of the bridge contract transfer parameters
price?: bigint; // When transferring native token, we need to set the price
baseFee: bigint;
Expand Down
Loading

0 comments on commit baac712

Please sign in to comment.