Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove legacy v1 token supports in sdk #458

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 1 addition & 43 deletions apps/scripts/src/config/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const EMPTY_MAP: TokenConfig["wrappedDetails"] = new Map();
export const DEVNET_SWIMUSD: TokenConfig = {
isDisabled: !isPoolRestructureEnabled(),
id: "devnet-swimusd",
projectId: TokenProjectId.SwimLpSolanaUsdcUsdt,
projectId: TokenProjectId.SwimUsd,
nativeEcosystemId: SOLANA_ECOSYSTEM_ID,
nativeDetails: {
address: "5ctnNpb7h1SyPqZ8t8m2kCykrtDGVZBtZgYWv6UAeDhr", // TODO: Update
Expand Down Expand Up @@ -147,18 +147,6 @@ export const DEVNET_TOKENS_FOR_RESTRUCTURE: readonly TokenConfig[] = [
},
wrappedDetails: EMPTY_MAP,
},
{
isDisabled:
!isPoolRestructureEnabled() || !process.env.REACT_APP_ENABLE_AURORA_USN,
id: "devnet-aurora-lp-usn",
projectId: TokenProjectId.SwimLpAuroraUsn,
nativeEcosystemId: EvmEcosystemId.Aurora,
nativeDetails: {
address: "0x1111111111111111111111111111111111111111", // TODO: Update
decimals: 8,
},
wrappedDetails: EMPTY_MAP,
},
{
isDisabled: !isPoolRestructureEnabled(),
id: "devnet-fantom-lp-usdc",
Expand Down Expand Up @@ -372,17 +360,6 @@ export const DEVNET_TOKENS: readonly TokenConfig[] = [
},
wrappedDetails: EMPTY_MAP,
},
{
isDisabled: !process.env.REACT_APP_ENABLE_AURORA_USN,
id: "devnet-solana-lp-meta-aurora-usn",
projectId: TokenProjectId.SwimAuroraUsnLp,
nativeEcosystemId: SOLANA_ECOSYSTEM_ID,
nativeDetails: {
address: "11111111111111111111111111111111", // TODO: Update
decimals: 8,
},
wrappedDetails: EMPTY_MAP,
},
{
isDisabled: !isEcosystemEnabled(EvmEcosystemId.Fantom),
id: "devnet-solana-lp-meta-fantom-usdc",
Expand Down Expand Up @@ -643,25 +620,6 @@ export const DEVNET_TOKENS: readonly TokenConfig[] = [
],
]),
},
{
isDisabled: !process.env.REACT_APP_ENABLE_AURORA_USN,
id: "devnet-aurora-usn",
projectId: TokenProjectId.Usn,
nativeEcosystemId: EvmEcosystemId.Aurora,
nativeDetails: {
address: "0x0000000000000000000000000000000000000000", // TODO: Update
decimals: 18,
},
wrappedDetails: new Map([
[
SOLANA_ECOSYSTEM_ID,
{
address: "11111111111111111111111111111111", // TODO: Update
decimals: 8,
},
],
]),
},
{
isDisabled: !isEcosystemEnabled(EvmEcosystemId.Fantom),
id: "devnet-fantom-usdc",
Expand Down
13 changes: 9 additions & 4 deletions apps/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
"last 1 safari version"
]
},
"jest": {
"moduleNameMapper": {
"!!url-loader!.+\\.svg": "<rootDir>/src/__mocks__/base64Mock.ts"
}
},
"engines": {
"node": "^16"
},
Expand All @@ -51,13 +56,13 @@
"@solana/spl-token": "^0.3.5",
"@solana/web3.js": "^1.62.0",
"@swim-io/aptos": "^0.40.0",
"@swim-io/core": "^0.40.0",
"@swim-io/evm": "^0.40.0",
"@swim-io/core": "workspace:^",
"@swim-io/evm": "workspace:^",
"@swim-io/evm-contracts": "^0.40.0",
"@swim-io/pool-math": "^0.40.0",
"@swim-io/solana": "^0.40.0",
"@swim-io/solana": "workspace:^",
"@swim-io/solana-contracts": "^0.40.0",
"@swim-io/token-projects": "^0.40.0",
"@swim-io/token-projects": "workspace:^",
"@swim-io/utils": "^0.40.0",
"@swim-io/wormhole": "^0.40.0",
"bn.js": "^5.2.1",
Expand Down
2 changes: 2 additions & 0 deletions apps/ui/src/__mocks__/base64Mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const dataUrl = "base64";
export default dataUrl;
10 changes: 5 additions & 5 deletions apps/ui/src/components/AddForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ import {
EuiText,
} from "@elastic/eui";
import { SOLANA_ECOSYSTEM_ID } from "@swim-io/solana";
import { TOKEN_PROJECTS_BY_ID } from "@swim-io/token-projects";
import { filterMap, isEachNotNull, isNotNull } from "@swim-io/utils";
import type Decimal from "decimal.js";
import type { FormEvent, ReactElement } from "react";
import { useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import shallow from "zustand/shallow.js";

import type { EcosystemId, PoolSpec, TokenConfig } from "../config";
import {
DISABLED_ECOSYSTEMS,
ECOSYSTEMS,
ECOSYSTEM_IDS,
getTokenProject,
isEcosystemEnabled,
} from "../config";
import type { EcosystemId, PoolSpec, TokenConfig } from "../config";
import { selectConfig } from "../core/selectors";
import { useEnvironment, useNotification } from "../core/store";
import { captureAndWrapException } from "../errors";
Expand Down Expand Up @@ -86,7 +86,7 @@ const TokenAddPanel = ({
onBlur,
}: TokenAddPanelProps): ReactElement => {
const { t } = useTranslation();
const tokenProject = TOKEN_PROJECTS_BY_ID[tokenConfig.projectId];
const tokenProject = getTokenProject(tokenConfig.projectId);
const balance = useUserBalanceAmount(tokenConfig, ecosystemId);
return (
<EuiFormRow
Expand Down Expand Up @@ -283,7 +283,7 @@ export const AddForm = ({

const lpTargetEcosystemOptions: readonly EuiRadioGroupOption[] = [
lpToken.nativeEcosystemId,
...(poolSpec.isLegacyPool ? lpToken.wrappedDetails.keys() : []),
...(poolSpec.isLegacyPool ? lpToken.wrappedDetails?.keys() ?? [] : []),
].map((ecosystemId) => {
const ecosystem = ECOSYSTEMS[ecosystemId];
return {
Expand Down Expand Up @@ -499,7 +499,7 @@ export const AddForm = ({
}
};

const lpTokenProject = TOKEN_PROJECTS_BY_ID[lpToken.projectId];
const lpTokenProject = getTokenProject(lpToken.projectId);
const receiveLabel = poolSpec.isStakingPool
? t("add_token_form.choose_receive_tokens_on", {
tokenSymbol: lpTokenProject.symbol,
Expand Down
2 changes: 1 addition & 1 deletion apps/ui/src/components/EuiFieldIntlNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* eslint-disable react/prop-types */

import { EuiFieldNumber } from "@elastic/eui";
import type { Override } from "@swim-io/utils";
import escapeStringRegexp from "escape-string-regexp";
import type { ComponentProps } from "react";
import { forwardRef, useCallback } from "react";
Expand All @@ -17,7 +18,6 @@ const MappedEuiFieldNumber = forwardRef<
return <EuiFieldNumber {...props} inputRef={ref} />;
});

type Override<T, U> = Omit<T, keyof U> & U;
type Props = Override<
Omit<ComponentProps<typeof CurrencyInput>, "customInput" | "onChange">,
{
Expand Down
4 changes: 2 additions & 2 deletions apps/ui/src/components/PoolListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
EuiTitle,
EuiToolTip,
} from "@elastic/eui";
import { TOKEN_PROJECTS_BY_ID } from "@swim-io/token-projects";
import { chunks } from "@swim-io/utils";
import Decimal from "decimal.js";
import type { ReactElement } from "react";
Expand All @@ -17,6 +16,7 @@ import { useNavigate } from "react-router-dom";

import { atomicToCurrencyString } from "../amounts";
import type { PoolSpec, TokenConfig } from "../config";
import { getTokenProject } from "../config";
import { i18next } from "../i18n";

import { TokenIcon } from "./TokenIcon";
Expand Down Expand Up @@ -92,7 +92,7 @@ export const PoolListItem = ({
style={{ margin: flexItemMargin }}
>
<TokenIcon
{...TOKEN_PROJECTS_BY_ID[tokenConfig.projectId]}
{...getTokenProject(tokenConfig.projectId)}
ecosystemId={
!isLegacyPool && poolEcosystem !== null
? poolEcosystem
Expand Down
11 changes: 5 additions & 6 deletions apps/ui/src/components/RemoveForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
import { APTOS_ECOSYSTEM_ID } from "@swim-io/aptos";
import { EvmEcosystemId } from "@swim-io/evm";
import { SOLANA_ECOSYSTEM_ID } from "@swim-io/solana";
import { TOKEN_PROJECTS_BY_ID } from "@swim-io/token-projects";
import type { ReadonlyRecord } from "@swim-io/utils";
import {
defaultIfError,
Expand All @@ -31,7 +30,7 @@ import { useTranslation } from "react-i18next";
import shallow from "zustand/shallow.js";

import type { EcosystemId, PoolSpec, TokenConfig } from "../config";
import { DISABLED_ECOSYSTEMS, ECOSYSTEMS } from "../config";
import { DISABLED_ECOSYSTEMS, ECOSYSTEMS, getTokenProject } from "../config";
import { selectConfig } from "../core/selectors";
import { useEnvironment, useNotification } from "../core/store";
import { captureAndWrapException } from "../errors";
Expand Down Expand Up @@ -337,7 +336,7 @@ export const RemoveForm = ({

const lpSourceEcosystemOptions: readonly EuiRadioGroupOption[] = [
lpToken.nativeEcosystemId,
...(poolSpec.isLegacyPool ? lpToken.wrappedDetails.keys() : []),
...(poolSpec.isLegacyPool ? lpToken.wrappedDetails?.keys() ?? [] : []),
].map((ecosystemId) => {
const ecosystem = ECOSYSTEMS[ecosystemId];
const lpBalance = userLpBalances[ecosystemId];
Expand Down Expand Up @@ -396,7 +395,7 @@ export const RemoveForm = ({
);
return {
value: id,
text: `${TOKEN_PROJECTS_BY_ID[tokenConfig.projectId].displayName} (${
text: `${getTokenProject(tokenConfig.projectId).displayName} (${
ECOSYSTEMS[tokenConfig.nativeEcosystemId].displayName
})`,
};
Expand Down Expand Up @@ -642,7 +641,7 @@ export const RemoveForm = ({
}
};

const lpTokenProject = TOKEN_PROJECTS_BY_ID[lpToken.projectId];
const lpTokenProject = getTokenProject(lpToken.projectId);
const maximumLpBurnLabel = poolSpec.isStakingPool
? t("remove_token_form.max_required_lp_tokens", {
tokenSymbol: lpTokenProject.symbol,
Expand Down Expand Up @@ -814,7 +813,7 @@ export const RemoveForm = ({
prepend={
<EuiButtonEmpty size="xs">
<TokenIcon
{...TOKEN_PROJECTS_BY_ID[tokenConfig.projectId]}
{...getTokenProject(tokenConfig.projectId)}
/>
</EuiButtonEmpty>
}
Expand Down
4 changes: 2 additions & 2 deletions apps/ui/src/components/SwapForm/SwapForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import {
} from "@elastic/eui";
import { EvmEcosystemId } from "@swim-io/evm";
import { SOLANA_ECOSYSTEM_ID } from "@swim-io/solana";
import { TOKEN_PROJECTS_BY_ID } from "@swim-io/token-projects";
import { defaultIfError, isEachNotNull } from "@swim-io/utils";
import type Decimal from "decimal.js";
import type { FormEvent, ReactElement, ReactNode } from "react";
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import shallow from "zustand/shallow.js";

import { getTokenProject } from "../../config";
import { selectConfig } from "../../core/selectors";
import { useEnvironment, useNotification } from "../../core/store";
import { captureAndWrapException } from "../../errors";
Expand Down Expand Up @@ -110,7 +110,7 @@ export const SwapForm = ({ maxSlippageFraction }: Props): ReactElement => {

const isLargeSwap = useIsLargeSwap(fromToken, toToken, inputAmount);
const isSmallEthSwap =
TOKEN_PROJECTS_BY_ID[fromToken.projectId].isStablecoin &&
getTokenProject(fromToken.projectId).isStablecoin &&
[fromToken.nativeEcosystemId, toToken.nativeEcosystemId].includes(
EvmEcosystemId.Ethereum,
) &&
Expand Down
5 changes: 2 additions & 3 deletions apps/ui/src/components/SwapFormV2/SwapFormV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import {
} from "@elastic/eui";
import { EvmEcosystemId } from "@swim-io/evm";
import { SOLANA_ECOSYSTEM_ID } from "@swim-io/solana";
import { TOKEN_PROJECTS_BY_ID } from "@swim-io/token-projects";
import { defaultIfError } from "@swim-io/utils";
import Decimal from "decimal.js";
import type { FormEvent, ReactElement, ReactNode } from "react";
import { useState } from "react";
import { useTranslation } from "react-i18next";
import shallow from "zustand/shallow.js";

import { getTokenDetailsForEcosystem } from "../../config";
import { getTokenDetailsForEcosystem, getTokenProject } from "../../config";
import { selectConfig } from "../../core/selectors";
import { useEnvironment, useNotification } from "../../core/store";
import { captureAndWrapException } from "../../errors";
Expand Down Expand Up @@ -109,7 +108,7 @@ export const SwapFormV2 = ({ maxSlippageFraction }: Props): ReactElement => {
maxSlippageFraction,
);
const isSmallEthSwap =
TOKEN_PROJECTS_BY_ID[fromTokenConfig.projectId].isStablecoin &&
getTokenProject(fromTokenConfig.projectId).isStablecoin &&
[fromTokenOption.ecosystemId, toTokenOption.ecosystemId].includes(
EvmEcosystemId.Ethereum,
) &&
Expand Down
7 changes: 3 additions & 4 deletions apps/ui/src/components/TokenIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { EuiIcon } from "@elastic/eui";
import type { TokenProject } from "@swim-io/token-projects";
import { TOKEN_PROJECTS_BY_ID } from "@swim-io/token-projects";
import type { ComponentProps, ReactElement } from "react";
import { Fragment } from "react";
import { Trans } from "react-i18next";

import type { EcosystemId, TokenConfig } from "../config";
import { ECOSYSTEMS } from "../config";
import { ECOSYSTEMS, getTokenProject } from "../config";
import { useIntlListSeparators } from "../hooks";
import type { Amount } from "../models/amount";

Expand Down Expand Up @@ -117,13 +116,13 @@ export const TokenConfigIcon = ({
ecosystem,
}: TokenConfigIconProps): ReactElement => (
<TokenIcon
{...TOKEN_PROJECTS_BY_ID[token.projectId]}
{...getTokenProject(token.projectId)}
ecosystemId={ecosystem ?? token.nativeEcosystemId}
/>
);

export const TokenSearchConfigIcon = ({
token,
}: Pick<TokenConfigIconProps, "token">): ReactElement => (
<TokenIcon {...TOKEN_PROJECTS_BY_ID[token.projectId]} />
<TokenIcon {...getTokenProject(token.projectId)} />
);
10 changes: 7 additions & 3 deletions apps/ui/src/components/TokenSearchModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ import {
EuiSelectable,
} from "@elastic/eui";
import type { EuiSelectableOption } from "@elastic/eui";
import { TOKEN_PROJECTS_BY_ID } from "@swim-io/token-projects";
import { useCallback } from "react";
import type { ReactElement } from "react";
import { useTranslation } from "react-i18next";
import shallow from "zustand/shallow.js";

import type { EcosystemId, TokenConfig } from "../config";
import { ECOSYSTEM_LIST, isEcosystemEnabled, isSwimUsd } from "../config";
import {
ECOSYSTEM_LIST,
getTokenProject,
isEcosystemEnabled,
isSwimUsd,
} from "../config";
import { selectConfig } from "../core/selectors";
import { useEnvironment } from "../core/store";
import { useUserBalanceAmount } from "../hooks";
Expand Down Expand Up @@ -88,7 +92,7 @@ export const TokenSearchModal = ({
);

const options = filteredTokens.map((token) => {
const tokenProject = TOKEN_PROJECTS_BY_ID[token.projectId];
const tokenProject = getTokenProject(token.projectId);
return {
label: `${tokenProject.symbol}`,
searchableLabel: `${tokenProject.symbol} ${tokenProject.displayName}`,
Expand Down
6 changes: 3 additions & 3 deletions apps/ui/src/components/molecules/AddTransfer.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { EuiLoadingSpinner, EuiText } from "@elastic/eui";
import { TOKEN_PROJECTS_BY_ID } from "@swim-io/token-projects";
import { filterMap } from "@swim-io/utils";
import type { VFC } from "react";
import { useTranslation } from "react-i18next";

import type { EcosystemId, TokenConfig } from "../../config";
import { getTokenProject } from "../../config";
import { useIntlListFormatter } from "../../hooks";
import type { Amount } from "../../models";

Expand All @@ -29,11 +29,11 @@ export const AddTransfer: VFC<Props> = ({
const listFormatter = useIntlListFormatter();
const nonZeroInputTokens = filterMap(
(amount: Amount) => !amount.isZero(),
(amount) => TOKEN_PROJECTS_BY_ID[amount.tokenConfig.projectId].symbol,
(amount) => getTokenProject(amount.tokenConfig.projectId).symbol,
fromAmounts,
);
const inputTokenNames = listFormatter.format(nonZeroInputTokens);
const outputTokenName = TOKEN_PROJECTS_BY_ID[toToken.projectId].symbol;
const outputTokenName = getTokenProject(toToken.projectId).symbol;

return (
<EuiText size="m">
Expand Down
Loading