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(tangle-dapp): Integrate bridge ERC-20 tokens into restaking #2783

Merged
merged 37 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
c895520
refactor(tangle-dapp): Remove outdated parachain LS logic
yurixander Jan 26, 2025
83b39d7
Merge branch 'develop' into yuri/relayer-subsidized-txs
yurixander Jan 26, 2025
053ba15
feat(tangle-dapp): Implement `useProvider`
yurixander Jan 27, 2025
4e9bcb2
feat(tangle-dapp): Implement `useEvmTxRelayer`
yurixander Jan 27, 2025
a582e0a
refactor(tangle-dapp): Move things around a bit
yurixander Jan 27, 2025
b5da859
refactor(tangle-dapp): Remove logs
yurixander Jan 27, 2025
e7089c0
fix(tangle-dapp): Fix errors left over from LS
yurixander Jan 27, 2025
ffe40d0
feat(tangle-dapp): Integrate into `useEvmPrecompileCall`
yurixander Jan 28, 2025
3c9971d
feat(tangle-dapp): Add `isEvmTxRelayerEligible`
yurixander Jan 28, 2025
f8e5150
feat(tangle-dapp): Estimate gas with `useEvmGasEstimate`
yurixander Jan 28, 2025
eff2e61
feat(tangle-dapp): Use TX relayer in `useRestakeApi`
yurixander Jan 28, 2025
5e9b62e
fix(tangle-dapp): Fix verifying contract address
yurixander Jan 28, 2025
a999bcc
Merge branch 'develop' into yuri/relayer-subsidized-txs
yurixander Jan 28, 2025
b6c3c0b
fix(tangle-dapp): Fix revert error
yurixander Jan 29, 2025
4553ffa
Merge branch 'develop' into yuri/relayer-subsidized-txs
yurixander Jan 29, 2025
16a581b
style(tangle-dapp): Disable `Execute All` button sometimes
yurixander Jan 29, 2025
1659d2e
refactor(tangle-dapp): Use bridge ERC-20 assets
yurixander Jan 30, 2025
ddf7161
ci(tangle-dapp): Fix imports
yurixander Jan 30, 2025
4a82de1
Merge branch 'develop' into yuri/integrate-bridge-assets-into-restaking
yurixander Jan 30, 2025
817ef74
refactor(tangle-dapp): Prefer `useQuery`
yurixander Jan 31, 2025
967901f
feat(tangle-dapp): More efficient balance fetching
yurixander Jan 31, 2025
1c9a4dc
Merge branch 'develop' into yuri/integrate-bridge-assets-into-restaking
yurixander Jan 31, 2025
91a65fe
fix(tangle-dapp): Identify ghost network issue
yurixander Jan 31, 2025
6de8873
refactor(tangle-dapp): Get rid of `rpcEndpoint` property
yurixander Jan 31, 2025
9b18e53
refactor(tangle-dapp): Update balances table
yurixander Jan 31, 2025
19c9d35
Merge branch 'develop' into yuri/integrate-bridge-assets-into-restaking
yurixander Jan 31, 2025
e1d5b1e
ci(tangle-dapp): Fix CI
yurixander Jan 31, 2025
93aa39c
style(tangle-dapp): Minor styling fixes
yurixander Jan 31, 2025
487cde7
fix(tangle-dapp): Fix integration with bridge assets
yurixander Feb 1, 2025
92aeb5e
Merge branch 'develop' into yuri/integrate-bridge-assets-into-restaking
yurixander Feb 1, 2025
2ab751a
fix(tangle-dapp): Fix restaking balance calculations
yurixander Feb 1, 2025
e698237
Merge branch 'develop' into yuri/integrate-bridge-assets-into-restaking
yurixander Feb 3, 2025
b1569c0
refactor(tangle-dapp): Disable source chain switch
yurixander Feb 3, 2025
95f56d8
Merge branch 'develop' into yuri/integrate-bridge-assets-into-restaking
yurixander Feb 3, 2025
687ad82
fix(tangle-dapp): Fix requested changes
yurixander Feb 3, 2025
8c81615
style(tangle-dapp): Fix font weight
yurixander Feb 3, 2025
c39a585
fix(tangle-dapp): Fix asset balance in delegate tab
yurixander Feb 3, 2025
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
68 changes: 0 additions & 68 deletions apps/tangle-dapp/src/abi/erc20.ts

This file was deleted.

7 changes: 2 additions & 5 deletions apps/tangle-dapp/src/components/ErrorMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@ export default function ErrorMessage({
<p
{...props}
className={twMerge(
'flex items-start gap-2 text-red-70 dark:text-red-50',
'flex items-center justify-center gap-0.5 text-red-70 dark:text-red-50 mt-2 ml-2',
className,
)}
>
{isDefined(children) ? (
<InformationLine
size="md"
className="fill-current dark:fill-current mt-1 shrink-0"
/>
<InformationLine size="md" className="fill-current dark:fill-current" />
) : null}

<Typography
Expand Down
2 changes: 1 addition & 1 deletion apps/tangle-dapp/src/components/StatItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const StatItem: FC<StatItemProps> = ({

return (
<div className={className}>
<Typography className="dark:text-mono-0" variant="body1" fw="bold">
<Typography className="dark:text-mono-0" variant="body1">
{title}
</Typography>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ import useWalletClient from '../../data/bridge/useWalletClient';

import { makeExplorerUrl } from '@webb-tools/api-provider-environment/transaction/utils';
import { FeeDetail, FeeDetailProps } from './FeeDetail';
import {
ROUTER_TX_EXPLORER_URL,
ROUTER_TX_STATUS_URL,
mailboxAddress,
} from '../../constants/bridge';
import useBridgeTxQueue from '../../context/bridge/BridgeTxQueueContext/useBridgeTxQueue';
import { useHyperlaneTransfer } from '../../data/bridge/useHyperlaneTransfer';
import { useRouterTransfer } from '../../data/bridge/useRouterTransfer';
Expand All @@ -47,6 +42,11 @@ import { EVMChainId } from '@webb-tools/dapp-types/ChainId';
import { ArrowTopRightOnSquareIcon } from '@heroicons/react/24/solid';
import { ArrowDownIcon } from '@webb-tools/icons';
import axios from 'axios';
import {
mailboxAddress,
ROUTER_TX_EXPLORER_URL,
ROUTER_TX_STATUS_URL,
} from '@webb-tools/tangle-shared-ui/constants/bridge';
import useIsBridgeNativeToken from '../../hooks/useIsBridgeNativeToken';
import useLocalStorage, {
LocalStorageKey,
Expand Down Expand Up @@ -489,7 +489,7 @@ export const BridgeConfirmationModal = ({
options: {
address: token.address,
decimals: token.decimals,
symbol: token.tokenSymbol,
symbol: token.symbol,
},
});

Expand All @@ -507,12 +507,12 @@ export const BridgeConfirmationModal = ({
});

notificationApi({
message: `${token.tokenSymbol} was successfully added to your wallet`,
message: `${token.symbol} was successfully added to your wallet`,
variant: 'success',
});
} else {
notificationApi({
message: `Failed to add ${token.tokenSymbol} to your wallet`,
message: `Failed to add ${token.symbol} to your wallet`,
variant: 'error',
});
}
Expand All @@ -536,7 +536,7 @@ export const BridgeConfirmationModal = ({
token.address,
token.tokenType,
token.decimals,
token.tokenSymbol,
token.symbol,
handleClose,
clearBridgeStore,
cachedTokensToAcc?.value,
Expand Down
12 changes: 3 additions & 9 deletions apps/tangle-dapp/src/containers/DebugMetrics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import {
import { SkeletonLoader, Typography } from '@webb-tools/webb-ui-components';
import { FC, useCallback, useEffect, useState } from 'react';

import useDebugMetricsStore from '../context/useDebugMetricsStore';

/**
* Format bytes to megabytes, rounded to two decimal places
* and suffixed with `mb`.
Expand All @@ -23,8 +21,7 @@ function formatBytes(bytes: number): string {

const DebugMetrics: FC = () => {
const [isCollapsed, setIsCollapsed] = useState(true);
const { rpcEndpoint } = useNetworkStore();
const { requestCount, subscriptionCount } = useDebugMetricsStore();
const rpcEndpoint = useNetworkStore((store) => store.network.wsRpcEndpoint);

const { result: api } = usePromise(
useCallback(() => getApiPromise(rpcEndpoint), [rpcEndpoint]),
Expand All @@ -40,9 +37,7 @@ const DebugMetrics: FC = () => {
const [tick, setTick] = useState(0);

const totalRequests =
(api?.stats?.total.requests ?? 0) +
(apiRx?.stats?.total.requests ?? 0) +
requestCount;
(api?.stats?.total.requests ?? 0) + (apiRx?.stats?.total.requests ?? 0);

const totalBytesReceived =
(api?.stats?.total.bytesRecv ?? 0) + (apiRx?.stats?.total.bytesRecv ?? 0);
Expand All @@ -55,8 +50,7 @@ const DebugMetrics: FC = () => {

const totalActiveSubscriptions =
(api?.stats?.active.subscriptions ?? 0) +
(apiRx?.stats?.active.subscriptions ?? 0) +
subscriptionCount;
(apiRx?.stats?.active.subscriptions ?? 0);

// Manually trigger a re-render every second, since the stats
// are not automatically updated.
Expand Down
69 changes: 40 additions & 29 deletions apps/tangle-dapp/src/containers/VaultsAndBalancesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
CircularProgress,
EMPTY_VALUE_PLACEHOLDER,
formatDisplayAmount,
InfoIconWithTooltip,
isEvmAddress,
Table,
Typography,
Expand Down Expand Up @@ -57,8 +58,10 @@ type Row = {
tvlInUsd?: number;
available: BN;
availableInUsd?: number;
locked: BN;
lockedInUsd?: number;
deposited: BN;
depositedInUsd?: number;
delegated: BN;
delegatedInUsd?: number;
points?: number;
decimals: number;
apyPercentage?: number;
Expand Down Expand Up @@ -119,24 +122,34 @@ const COLUMNS = [
);
},
}),
COLUMN_HELPER.accessor('locked', {
COLUMN_HELPER.accessor('deposited', {
header: () => 'Deposits',
sortingFn: sortByBn((row) => row.locked),
sortingFn: sortByBn((row) => row.deposited),
cell: (props) => {
const fmtLocked = formatDisplayAmount(
props.getValue(),
const fmtDeposited = formatDisplayAmount(
props.row.original.deposited,
props.row.original.decimals,
AmountFormatStyle.SHORT,
);

const subtitle =
props.row.original.lockedInUsd === undefined
? undefined
: `$${props.row.original.lockedInUsd}`;
const fmtDelegated = formatDisplayAmount(
props.row.original.delegated,
props.row.original.decimals,
AmountFormatStyle.SHORT,
);

return (
<TableCellWrapper>
<StatItem title={fmtLocked} subtitle={subtitle} removeBorder />
<Typography
variant="body1"
className="flex gap-1 items-center justify-center dark:text-mono-0"
>
{fmtDeposited}

<InfoIconWithTooltip
content={`${fmtDelegated}/${fmtDeposited} delegated`}
/>
</Typography>
</TableCellWrapper>
);
},
Expand Down Expand Up @@ -188,7 +201,7 @@ const COLUMNS = [
/>
)}

<Typography variant="body1">
<Typography variant="body1" className="dark:text-mono-0">
{fmtTvl === undefined
? `${fmtDepositCap}`
: `${fmtTvl} | ${fmtDepositCap}`}
Expand Down Expand Up @@ -255,15 +268,15 @@ const VaultsAndBalancesTable: FC = () => {
const isAccountConnected = useIsAccountConnected();

const assetsTvl = useRestakeAssetsTvl();
const erc20Balances = useTangleEvmErc20Balances();
const { data: erc20Balances } = useTangleEvmErc20Balances();

const {
vaults,
balances: customAssetBalances,
isLoading,
} = useRestakeContext();

const getTotalLockedInAsset = useCallback(
const getAssetTvl = useCallback(
(assetId: RestakeAssetId) => {
const deposits = delegatorInfo?.deposits ?? {};
const deposit = get(deposits, assetId);
Expand All @@ -274,23 +287,14 @@ const VaultsAndBalancesTable: FC = () => {

const depositAmount = deposit.amount;

const delegation = delegatorInfo?.delegations.find((delegation) => {
return delegation.assetId === assetId.toString();
});

const depositAmountBn =
depositAmount === undefined
? BN_ZERO
: new BN(depositAmount.toString());

const delegationBn =
delegation === undefined
? BN_ZERO
: new BN(delegation.amountBonded.toString());

return depositAmountBn.add(delegationBn);
return depositAmountBn;
},
[delegatorInfo?.delegations, delegatorInfo?.deposits],
[delegatorInfo?.deposits],
);

const vaultRows = useMemo<Row[]>(() => {
Expand All @@ -315,7 +319,8 @@ const VaultsAndBalancesTable: FC = () => {
? undefined
: new BN(config.depositCap.toString());

const tvl = assetsTvl === null ? undefined : assetsTvl.get(assetId);
const delegated =
(assetsTvl === null ? undefined : assetsTvl.get(assetId)) ?? BN_ZERO;

const assetBalances:
| (typeof customAssetBalances)[RestakeAssetId]
Expand All @@ -334,12 +339,17 @@ const VaultsAndBalancesTable: FC = () => {
}
})();

const deposits = delegatorInfo?.deposits ?? {};
const depositedBigInt = get(deposits, assetId)?.amount ?? BigInt(0);
const deposited = new BN(depositedBigInt.toString());

return {
vaultId: metadata.vaultId,
name: metadata.name,
tvl,
tvl: getAssetTvl(assetId),
available,
locked: getTotalLockedInAsset(assetId),
deposited,
delegated,
// TODO: This won't work because reward config is PER VAULT not PER ASSET. But isn't each asset its own vault?
apyPercentage,
tokenSymbol: metadata.symbol,
Expand All @@ -353,7 +363,8 @@ const VaultsAndBalancesTable: FC = () => {
rewardConfig,
assetsTvl,
customAssetBalances,
getTotalLockedInAsset,
delegatorInfo?.deposits,
getAssetTvl,
erc20Balances,
]);

Expand Down
6 changes: 3 additions & 3 deletions apps/tangle-dapp/src/containers/bridge/BridgeContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import { BridgeConfirmationModal } from '../../components/bridge/BridgeConfirmat
import { FeeDetail, FeeDetailProps } from '../../components/bridge/FeeDetail';
import { AssetConfig, AssetList } from '../../components/Lists/AssetList';
import { ChainList } from '../../components/Lists/ChainList';
import { ROUTER_NATIVE_TOKEN_ADDRESS } from '../../constants/bridge';
import useBridgeStore from '../../context/bridge/useBridgeStore';
import useBalances from '../../data/balances/useBalances';
import { BridgeTokenWithBalance } from '@webb-tools/tangle-shared-ui/types';
Expand All @@ -52,6 +51,7 @@ import { WalletFillIcon } from '@webb-tools/icons';
import { useBalance } from 'wagmi';
import convertDecimalToBn from '@webb-tools/tangle-shared-ui/utils/convertDecimalToBn';
import { useBridgeEvmBalances } from '../../data/bridge/useBridgeEvmBalances';
import { ROUTER_NATIVE_TOKEN_ADDRESS } from '@webb-tools/tangle-shared-ui/constants/bridge';
import useIsBridgeNativeToken from '../../hooks/useIsBridgeNativeToken';

interface BridgeContainerProps {
Expand Down Expand Up @@ -340,7 +340,7 @@ export default function BridgeContainer({ className }: BridgeContainerProps) {
.div(new Decimal(10).pow(selectedToken.decimals))
.toString();

const formattedSendingAmount = `${sendingAmount} ${selectedToken.tokenSymbol}`;
const formattedSendingAmount = `${sendingAmount} ${selectedToken.symbol}`;

const formattedGasFee =
formatEther(hyperlaneQuote.fees.local.amount) +
Expand Down Expand Up @@ -437,7 +437,7 @@ export default function BridgeContainer({ className }: BridgeContainerProps) {

return {
symbol: token.tokenType,
optionalSymbol: token.tokenSymbol,
optionalSymbol: token.symbol,
balance:
activeAccount && balance
? parseFloat(balance.toString()).toFixed(6)
Expand Down
Loading
Loading