Skip to content

Commit

Permalink
XLabs/portal-bridge-ui#980 - refactor and fix check availability logic (
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianscatularo committed Aug 7, 2024
1 parent 9e807eb commit cf810d9
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 192 deletions.
1 change: 0 additions & 1 deletion wormhole-connect/src/routes/abstracts/routeAbstract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export abstract class RouteAbstract {
amount: string,
sourceChain: ChainName | ChainId,
destChain: ChainName | ChainId,
manualAddress?: boolean,
): Promise<RouteAvailability>;

public abstract isSupportedChain(chain: ChainName): boolean;
Expand Down
21 changes: 0 additions & 21 deletions wormhole-connect/src/routes/bridge/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ import { SignedMessage } from '../types';
import { isGatewayChain } from '../../utils/cosmos';
import { fetchVaa } from '../../utils/vaa';
import { getSolanaAssociatedTokenAccount } from 'utils/solana';
import {
RouteAvailability,
REASON_MANUAL_ADDRESS_NOT_SUPPORTED,
} from 'routes/abstracts';

export class BridgeRoute extends BaseRoute {
readonly NATIVE_GAS_DROPOFF_SUPPORTED: boolean = false;
Expand Down Expand Up @@ -81,23 +77,6 @@ export class BridgeRoute extends BaseRoute {
return false;
}

async isRouteAvailable(
sourceToken: string,
destToken: string,
amount: string,
sourceChain: ChainName | ChainId,
destChain: ChainName | ChainId,
manualAddress?: boolean,
): Promise<RouteAvailability> {
// this route is not available if the target addres is manual
if (manualAddress)
return {
isAvailable: false,
reason: REASON_MANUAL_ADDRESS_NOT_SUPPORTED,
};
return { isAvailable: true };
}

isSupportedChain(chain: ChainName): boolean {
// all chains are supported for manual
return true;
Expand Down
21 changes: 0 additions & 21 deletions wormhole-connect/src/routes/cctpManual/cctpManual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ import {
import { TokenPrices } from 'store/tokenPrices';
import { getNativeVersionOfToken } from 'store/transferInput';
import { PublicKey } from '@solana/web3.js';
import {
REASON_MANUAL_ADDRESS_NOT_SUPPORTED,
RouteAvailability,
} from 'routes/abstracts';

export class CCTPManualRoute extends BaseRoute {
readonly NATIVE_GAS_DROPOFF_SUPPORTED: boolean = false;
Expand Down Expand Up @@ -180,23 +176,6 @@ export class CCTPManualRoute extends BaseRoute {
);
}

async isRouteAvailable(
sourceToken: string,
destToken: string,
amount: string,
sourceChain: ChainName | ChainId,
destChain: ChainName | ChainId,
manualAddress?: boolean,
): Promise<RouteAvailability> {
// this route is not available if the target addres is manual
if (manualAddress)
return {
isAvailable: false,
reason: REASON_MANUAL_ADDRESS_NOT_SUPPORTED,
};
return { isAvailable: true };
}

async computeReceiveAmount(
sendAmount: number,
token: string,
Expand Down
21 changes: 0 additions & 21 deletions wormhole-connect/src/routes/cosmosGateway/cosmosGateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ import {
getUnsignedMessageFromCosmos,
} from './utils';
import { TokenPrices } from 'store/tokenPrices';
import {
REASON_MANUAL_ADDRESS_NOT_SUPPORTED,
RouteAvailability,
} from 'routes/abstracts';

export class CosmosGatewayRoute extends BaseRoute {
readonly NATIVE_GAS_DROPOFF_SUPPORTED: boolean = false;
Expand Down Expand Up @@ -82,23 +78,6 @@ export class CosmosGatewayRoute extends BaseRoute {
);
}

async isRouteAvailable(
sourceToken: string,
destToken: string,
amount: string,
sourceChain: ChainName | ChainId,
destChain: ChainName | ChainId,
manualAddress?: boolean,
): Promise<RouteAvailability> {
// this route is not available if the target addres is manual
if (manualAddress)
return {
isAvailable: false,
reason: REASON_MANUAL_ADDRESS_NOT_SUPPORTED,
};
return { isAvailable: true };
}

async computeReceiveAmount(
sendAmount: number,
token: string,
Expand Down
22 changes: 0 additions & 22 deletions wormhole-connect/src/routes/ntt/nttManual.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,8 @@
import { Route } from 'config/types';
import { NttBase } from './nttBase';
import { ChainId, ChainName } from '@wormhole-foundation/wormhole-connect-sdk';
import {
REASON_MANUAL_ADDRESS_NOT_SUPPORTED,
RouteAvailability,
} from 'routes/abstracts';

export class NttManual extends NttBase {
readonly NATIVE_GAS_DROPOFF_SUPPORTED: boolean = false;
readonly AUTOMATIC_DEPOSIT: boolean = false;
readonly TYPE: Route = Route.NttManual;

async isRouteAvailable(
sourceToken: string,
destToken: string,
amount: string,
sourceChain: ChainName | ChainId,
destChain: ChainName | ChainId,
manualAddress?: boolean,
): Promise<RouteAvailability> {
// this route is not available if the target addres is manual
if (manualAddress)
return {
isAvailable: false,
reason: REASON_MANUAL_ADDRESS_NOT_SUPPORTED,
};
return { isAvailable: true };
}
}
2 changes: 0 additions & 2 deletions wormhole-connect/src/routes/operator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ export class Operator {
amount: string,
sourceChain: ChainName | ChainId,
destChain: ChainName | ChainId,
manualAddress?: boolean,
): Promise<RouteAvailability> {
if (!config.routes.includes(route)) {
return { isAvailable: false };
Expand All @@ -234,7 +233,6 @@ export class Operator {
amount,
sourceChain,
destChain,
manualAddress,
);
}
allSupportedChains(): ChainName[] {
Expand Down
21 changes: 0 additions & 21 deletions wormhole-connect/src/routes/porticoBridge/porticoBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ import {
import { PorticoBridgeState, PorticoSwapAmounts } from 'store/porticoBridge';
import { TokenPrices } from 'store/tokenPrices';
import { estimateAverageGasFee } from 'utils/gas';
import {
REASON_MANUAL_ADDRESS_NOT_SUPPORTED,
RouteAvailability,
} from 'routes/abstracts';

export abstract class PorticoBridge extends BaseRoute {
readonly NATIVE_GAS_DROPOFF_SUPPORTED: boolean = false;
Expand Down Expand Up @@ -158,23 +154,6 @@ export abstract class PorticoBridge extends BaseRoute {
return true;
}

async isRouteAvailable(
sourceToken: string,
destToken: string,
amount: string,
sourceChain: ChainName | ChainId,
destChain: ChainName | ChainId,
manualAddress?: boolean,
): Promise<RouteAvailability> {
// this route is not available if the target addres is manual
if (manualAddress)
return {
isAvailable: false,
reason: REASON_MANUAL_ADDRESS_NOT_SUPPORTED,
};
return { isAvailable: true };
}

async computeSwapAmounts(
sendAmount: number,
token: string,
Expand Down
13 changes: 1 addition & 12 deletions wormhole-connect/src/routes/sdkv2/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ import {
} from '@wormhole-foundation/wormhole-connect-sdk';
import { Route, TokenConfig, Network as NetworkV1 } from 'config/types';
import { BigNumber } from 'ethers';
import {
RouteAvailability,
RouteAbstract,
REASON_MANUAL_ADDRESS_NOT_SUPPORTED,
} from 'routes/abstracts';
import { RouteAvailability, RouteAbstract } from 'routes/abstracts';
import {
RelayerFee,
SignedMessage,
Expand Down Expand Up @@ -220,14 +216,7 @@ export class SDKv2Route<N extends Network> extends RouteAbstract {
amount: string,
sourceChain: ChainName | ChainId,
destChain: ChainName | ChainId,
manualAddress?: boolean,
): Promise<RouteAvailability> {
// this route is not available if the target addres is manual
if (manualAddress)
return {
isAvailable: false,
reason: REASON_MANUAL_ADDRESS_NOT_SUPPORTED,
};
return { isAvailable: true };
}

Expand Down
21 changes: 0 additions & 21 deletions wormhole-connect/src/routes/tbtc/tbtc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ import { BaseRoute } from '../bridge';
import { postVaa, signAndSendTransaction, TransferWallet } from 'utils/wallet';
import { isTBTCCanonicalChain } from './utils';
import { isGatewayChain } from 'utils/cosmos';
import {
REASON_MANUAL_ADDRESS_NOT_SUPPORTED,
RouteAvailability,
} from 'routes/abstracts';

const THRESHOLD_ARBITER_FEE = 0;
const THRESHOLD_NONCE = 0;
Expand Down Expand Up @@ -117,23 +113,6 @@ export class TBTCRoute extends BaseRoute {
return true;
}

async isRouteAvailable(
sourceToken: string,
destToken: string,
amount: string,
sourceChain: ChainName | ChainId,
destChain: ChainName | ChainId,
manualAddress?: boolean,
): Promise<RouteAvailability> {
// this route is not available if the target addres is manual
if (manualAddress)
return {
isAvailable: false,
reason: REASON_MANUAL_ADDRESS_NOT_SUPPORTED,
};
return { isAvailable: true };
}

async computeReceiveAmount(
sendAmount: number,
token: string,
Expand Down
Loading

0 comments on commit cf810d9

Please sign in to comment.