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

fix: bridge fee ints #2239

Closed
wants to merge 6 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import constants from '../../../../fixtures/constans.json';
import { skipState } from '../../../../support/steps/common';
import { configEnvWithTenderlyAvalancheFork } from '../../../../support/steps/configuration.steps';
import { borrow, repay, supply, withdraw } from '../../../../support/steps/main.steps';
import {
dashboardAssetValuesVerification,
} from '../../../../support/steps/verification.steps';
import { dashboardAssetValuesVerification } from '../../../../support/steps/verification.steps';
import { RequestedTokens, tokenSet } from '../../../4-gho-ethereum/helpers/token.helper';

const tokensToRequest: RequestedTokens = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import constants from '../../../../fixtures/constans.json';
import { skipState } from '../../../../support/steps/common';
import { configEnvWithTenderlyAvalancheFork } from '../../../../support/steps/configuration.steps';
import { borrow, repay, supply, withdraw } from '../../../../support/steps/main.steps';
import {
dashboardAssetValuesVerification,
} from '../../../../support/steps/verification.steps';
import { dashboardAssetValuesVerification } from '../../../../support/steps/verification.steps';
import { RequestedTokens, tokenSet } from '../../../4-gho-ethereum/helpers/token.helper';

const tokensToRequest: RequestedTokens = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import constants from '../../../../fixtures/constans.json';
import { skipState } from '../../../../support/steps/common';
import { configEnvWithTenderlyAvalancheFork } from '../../../../support/steps/configuration.steps';
import { borrow, repay, supply, withdraw } from '../../../../support/steps/main.steps';
import {
dashboardAssetValuesVerification,
} from '../../../../support/steps/verification.steps';
import { dashboardAssetValuesVerification } from '../../../../support/steps/verification.steps';
import { RequestedTokens, tokenSet } from '../../../4-gho-ethereum/helpers/token.helper';

const tokensToRequest: RequestedTokens = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import constants from '../../../../fixtures/constans.json';
import { skipState } from '../../../../support/steps/common';
import { configEnvWithTenderlyAvalancheFork } from '../../../../support/steps/configuration.steps';
import { borrow, repay, supply, withdraw } from '../../../../support/steps/main.steps';
import {
dashboardAssetValuesVerification,
} from '../../../../support/steps/verification.steps';
import { dashboardAssetValuesVerification } from '../../../../support/steps/verification.steps';
import { RequestedTokens, tokenSet } from '../../../4-gho-ethereum/helpers/token.helper';

const tokensToRequest: RequestedTokens = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import constants from '../../../../fixtures/constans.json';
import { skipState } from '../../../../support/steps/common';
import { configEnvWithTenderlyAEthereumV3Fork } from '../../../../support/steps/configuration.steps';
import { borrow, repay, supply, withdraw } from '../../../../support/steps/main.steps';
import {
dashboardAssetValuesVerification,
} from '../../../../support/steps/verification.steps';
import { dashboardAssetValuesVerification } from '../../../../support/steps/verification.steps';
import { RequestedTokens, tokenSet } from '../../../4-gho-ethereum/helpers/token.helper';

const tokensToRequest: RequestedTokens = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import constants from '../../../../fixtures/constans.json';
import { skipState } from '../../../../support/steps/common';
import { configEnvWithTenderlyAEthereumV3Fork } from '../../../../support/steps/configuration.steps';
import { borrow, repay, supply, withdraw } from '../../../../support/steps/main.steps';
import {
dashboardAssetValuesVerification,
} from '../../../../support/steps/verification.steps';
import { dashboardAssetValuesVerification } from '../../../../support/steps/verification.steps';
import { RequestedTokens, tokenSet } from '../../../4-gho-ethereum/helpers/token.helper';

const tokensToRequest: RequestedTokens = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import constants from '../../../../fixtures/constans.json';
import { skipState } from '../../../../support/steps/common';
import { configEnvWithTenderlyArbitrumFork } from '../../../../support/steps/configuration.steps';
import { borrow, repay, supply, withdraw } from '../../../../support/steps/main.steps';
import {
dashboardAssetValuesVerification,
} from '../../../../support/steps/verification.steps';
import { dashboardAssetValuesVerification } from '../../../../support/steps/verification.steps';
import { RequestedTokens, tokenSet } from '../../../4-gho-ethereum/helpers/token.helper';

const tokensToRequest: RequestedTokens = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import constants from '../../../../fixtures/constans.json';
import { skipState } from '../../../../support/steps/common';
import { configEnvWithTenderlyArbitrumFork } from '../../../../support/steps/configuration.steps';
import { borrow, repay, supply, withdraw } from '../../../../support/steps/main.steps';
import {
dashboardAssetValuesVerification,
} from '../../../../support/steps/verification.steps';
import { dashboardAssetValuesVerification } from '../../../../support/steps/verification.steps';
import { RequestedTokens, tokenSet } from '../../../4-gho-ethereum/helpers/token.helper';

const tokensToRequest: RequestedTokens = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import constants from '../../../../fixtures/constans.json';
import { skipState } from '../../../../support/steps/common';
import { configEnvWithTenderlyAvalancheFork } from '../../../../support/steps/configuration.steps';
import { borrow, repay, supply, withdraw } from '../../../../support/steps/main.steps';
import {
dashboardAssetValuesVerification,
} from '../../../../support/steps/verification.steps';
import { dashboardAssetValuesVerification } from '../../../../support/steps/verification.steps';
import { RequestedTokens, tokenSet } from '../../../4-gho-ethereum/helpers/token.helper';

const tokensToRequest: RequestedTokens = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import constants from '../../../../fixtures/constans.json';
import { skipState } from '../../../../support/steps/common';
import { configEnvWithTenderlyAvalancheFork } from '../../../../support/steps/configuration.steps';
import { borrow, repay, supply, withdraw } from '../../../../support/steps/main.steps';
import {
dashboardAssetValuesVerification,
} from '../../../../support/steps/verification.steps';
import { dashboardAssetValuesVerification } from '../../../../support/steps/verification.steps';
import { RequestedTokens, tokenSet } from '../../../4-gho-ethereum/helpers/token.helper';

const tokensToRequest: RequestedTokens = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import constants from '../../../../fixtures/constans.json';
import { skipState } from '../../../../support/steps/common';
import { configEnvWithTenderlyAvalancheFork } from '../../../../support/steps/configuration.steps';
import { borrow, repay, supply, withdraw } from '../../../../support/steps/main.steps';
import {
dashboardAssetValuesVerification,
} from '../../../../support/steps/verification.steps';
import { dashboardAssetValuesVerification } from '../../../../support/steps/verification.steps';
import { RequestedTokens, tokenSet } from '../../../4-gho-ethereum/helpers/token.helper';

const tokensToRequest: RequestedTokens = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import constants from '../../../../fixtures/constans.json';
import { skipState } from '../../../../support/steps/common';
import { configEnvWithTenderlyPolygonFork } from '../../../../support/steps/configuration.steps';
import { borrow, repay, supply, withdraw } from '../../../../support/steps/main.steps';
import {
dashboardAssetValuesVerification,
} from '../../../../support/steps/verification.steps';
import { dashboardAssetValuesVerification } from '../../../../support/steps/verification.steps';
import { RequestedTokens, tokenSet } from '../../../4-gho-ethereum/helpers/token.helper';

const tokensToRequest: RequestedTokens = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import constants from '../../../../fixtures/constans.json';
import { skipState } from '../../../../support/steps/common';
import { configEnvWithTenderlyPolygonFork } from '../../../../support/steps/configuration.steps';
import { borrow, repay, supply, withdraw } from '../../../../support/steps/main.steps';
import {
dashboardAssetValuesVerification,
} from '../../../../support/steps/verification.steps';
import { dashboardAssetValuesVerification } from '../../../../support/steps/verification.steps';
import { RequestedTokens, tokenSet } from '../../../4-gho-ethereum/helpers/token.helper';

const tokensToRequest: RequestedTokens = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import constants from '../../../../fixtures/constans.json';
import { skipState } from '../../../../support/steps/common';
import { configEnvWithTenderlyPolygonFork } from '../../../../support/steps/configuration.steps';
import { borrow, repay, supply, withdraw } from '../../../../support/steps/main.steps';
import {
dashboardAssetValuesVerification,
} from '../../../../support/steps/verification.steps';
import { dashboardAssetValuesVerification } from '../../../../support/steps/verification.steps';
import { RequestedTokens, tokenSet } from '../../../4-gho-ethereum/helpers/token.helper';

const tokensToRequest: RequestedTokens = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import constants from '../../../../fixtures/constans.json';
import { skipState } from '../../../../support/steps/common';
import { configEnvWithTenderlyOptimismFork } from '../../../../support/steps/configuration.steps';
import { borrow, repay, supply, withdraw } from '../../../../support/steps/main.steps';
import {
dashboardAssetValuesVerification,
} from '../../../../support/steps/verification.steps';
import { dashboardAssetValuesVerification } from '../../../../support/steps/verification.steps';
import { RequestedTokens, tokenSet } from '../../../4-gho-ethereum/helpers/token.helper';

const tokensToRequest: RequestedTokens = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import constants from '../../../../fixtures/constans.json';
import { skipState } from '../../../../support/steps/common';
import { configEnvWithTenderlyFantomFork } from '../../../../support/steps/configuration.steps';
import { borrow, repay, supply, withdraw } from '../../../../support/steps/main.steps';
import {
dashboardAssetValuesVerification,
} from '../../../../support/steps/verification.steps';
import { dashboardAssetValuesVerification } from '../../../../support/steps/verification.steps';

const testData = {
depositBaseAmount: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import constants from '../../../../fixtures/constans.json';
import { skipState } from '../../../../support/steps/common';
import { configEnvWithTenderlyFantomFork } from '../../../../support/steps/configuration.steps';
import { borrow, repay, supply, withdraw } from '../../../../support/steps/main.steps';
import {
dashboardAssetValuesVerification,
} from '../../../../support/steps/verification.steps';
import { dashboardAssetValuesVerification } from '../../../../support/steps/verification.steps';

const testData = {
depositBaseAmount: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import constants from '../../../../fixtures/constans.json';
import { skipState } from '../../../../support/steps/common';
import { configEnvWithTenderlyFantomFork } from '../../../../support/steps/configuration.steps';
import { borrow, repay, supply, withdraw } from '../../../../support/steps/main.steps';
import {
dashboardAssetValuesVerification,
} from '../../../../support/steps/verification.steps';
import { dashboardAssetValuesVerification } from '../../../../support/steps/verification.steps';

const testData = {
depositBaseAmount: {
Expand Down
52 changes: 12 additions & 40 deletions src/components/transactions/Bridge/BridgeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ type Config = {
wrappedNativeOracle: string; // Used to get the fee price in USD
lockReleaseTokenPool?: string; // Only exists on Ethereum
burnMintTokenPool?: string; // Only exists on non-Ethereum networks
destinations: {
destinationChainId: ChainId;
onRamp: string;
}[];
feeTokens: TokenInfoWithBalance[];
};

Expand All @@ -48,12 +44,6 @@ const prodConfig: Config[] = [
tokenOracle: '0x3f12643d3f6f874d39c2a4c9f2cd6f2dbac877fc',
wrappedNativeOracle: AaveV3Ethereum.ASSETS.WETH.ORACLE,
subgraphUrl: `https://gateway-arbitrum.network.thegraph.com/api/${process.env.NEXT_PUBLIC_SUBGRAPH_API_KEY}/subgraphs/id/E11p8T4Ff1DHZbwSUC527hkUb5innVMdTuP6A2s1xtm1`,
destinations: [
{
destinationChainId: ChainId.arbitrum_one,
onRamp: '0x925228d7b82d883dde340a55fe8e6da56244a22c',
},
],
feeTokens: [
{
name: 'Gho Token',
Expand Down Expand Up @@ -92,12 +82,6 @@ const prodConfig: Config[] = [
tokenOracle: '0xb05984ad83c20b3ade7bf97a9a0cb539dde28dbb',
wrappedNativeOracle: AaveV3Arbitrum.ASSETS.WETH.ORACLE,
subgraphUrl: `https://gateway-arbitrum.network.thegraph.com/api/${process.env.NEXT_PUBLIC_SUBGRAPH_API_KEY}/subgraphs/id/GPpZfiGoDChLsiWoMG5fxXdRNEYrsVDrKJ39moGcbz6i`,
destinations: [
{
destinationChainId: ChainId.mainnet,
onRamp: '0xce11020d56e5fdbfe46d9fc3021641ffbbb5adee',
},
],
feeTokens: [
{
name: 'Gho Token',
Expand Down Expand Up @@ -138,13 +122,7 @@ const testnetConfig: Config[] = [
router: '0x0BF3dE8c5D3e8A2B34D2BEeB17ABfCeBaf363A59',
tokenOracle: '0x98458D6A99489F15e6eB5aFa67ACFAcf6F211051', // mock oracle
wrappedNativeOracle: AaveV3Sepolia.ASSETS.WETH.ORACLE,
subgraphUrl: 'https://api.studio.thegraph.com/query/75867/gho-ccip-sepolia/version/latest',
destinations: [
{
destinationChainId: ChainId.arbitrum_sepolia,
onRamp: '0xBc09627e58989Ba8F1eDA775e486467d2A00944F',
},
],
subgraphUrl: `https://gateway.thegraph.com/api/${process.env.NEXT_PUBLIC_SUBGRAPH_API_KEY}/subgraphs/id/8NWTrc4S6xwaBbajongofytQfQisqYm1zR2ghGEtRFSc`,
feeTokens: [
{
name: 'Gho Token',
Expand Down Expand Up @@ -182,13 +160,7 @@ const testnetConfig: Config[] = [
router: '0x2a9C5afB0d0e4BAb2BCdaE109EC4b0c4Be15a165',
tokenOracle: '0x1f885520b7BD528E46b390040F12E753Dce43004', // mock oracle
wrappedNativeOracle: AaveV3ArbitrumSepolia.ASSETS.WETH.ORACLE,
subgraphUrl: 'https://api.studio.thegraph.com/query/75867/gho-ccip-arb-sepolia/version/latest',
destinations: [
{
destinationChainId: ChainId.sepolia,
onRamp: '0x64d78F20aD987c7D52FdCB8FB0777bD00de53210',
},
],
subgraphUrl: `https://gateway.thegraph.com/api/${process.env.NEXT_PUBLIC_SUBGRAPH_API_KEY}/subgraphs/id/8bpqvL6XBCVhN4heE9rdEwgTketeZ2U5vVGEh5fDoUEH`,
feeTokens: [
{
name: 'Gho Token',
Expand Down Expand Up @@ -233,6 +205,16 @@ export function getChainSelectorFor(chainId: ChainId) {
return chainSelector;
}

export function getChainIdFor(chainSelector: string) {
const chainId = laneConfig.find(
(config) => config.chainSelector === chainSelector
)?.sourceChainId;
if (!chainId) {
throw new Error(`No chainId found for chainSelector ${chainSelector}`);
}
return chainId;
}

export function getRouterFor(chainId: ChainId) {
const router = laneConfig.find((config) => config.sourceChainId === chainId)?.router;
if (!router) {
Expand All @@ -245,16 +227,6 @@ export function getSupportedSourceChains() {
return laneConfig.map((config) => config.sourceChainId);
}

export function getDestinationChainFor(sourceChainId: ChainId, onRamp: string) {
const destinationChainId = laneConfig
.find((config) => config.sourceChainId === sourceChainId)
?.destinations.find((dest) => dest.onRamp === onRamp)?.destinationChainId;
if (!destinationChainId) {
throw new Error(`No destination chain found for onRamp ${onRamp}`);
}
return destinationChainId;
}

export function getConfigFor(sourceChainId: ChainId) {
const config = laneConfig.find((config) => config.sourceChainId === sourceChainId);
if (!config) {
Expand Down
71 changes: 49 additions & 22 deletions src/components/transactions/Bridge/BridgeModalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,25 +221,6 @@ export const BridgeModalContent = () => {
setSelectedFeeToken(newFilteredFeeTokens[0]);
};

const bridgeActionsProps: BridgeActionProps = {
amountToBridge: amount,
isWrongNetwork,
symbol: GHO_SYMBOL,
blocked:
loadingBridgeMessage ||
!destinationAccount ||
bridgeLimitExceeded ||
rateLimitExceeded ||
loadingLimits,
decimals: 18,
message,
fees: bridgeFee,
sourceChainId: sourceNetworkObj.chainId,
destinationChainId: destinationNetworkObj.chainId,
tokenAddress: sourceTokenInfo?.address || constants.AddressZero,
isCustomFeeToken: selectedFeeToken.address !== constants.AddressZero,
};

if (txError && txError.blocking) {
return <TxErrorView txError={txError} />;
}
Expand Down Expand Up @@ -314,13 +295,45 @@ export const BridgeModalContent = () => {
</TextWithTooltip>
);

// string formatting for tx display
const amountUsd = Number(amount) * sourceTokenInfo.tokenPriceUSD;
const parsedAmountFee = new BigNumber(amount || '0');
const parsedAmountBn = new BigNumber(amount || '0');
const parsedBridgeFee = new BigNumber(bridgeFeeFormatted || '0');
const amountAfterFee = parsedAmountFee.minus(parsedBridgeFee);
const parsedWalletBalance = new BigNumber(selectedFeeToken.balance || '0');

// Calculate amount after fee (this is the amount that will actually be bridged)
const amountAfterFee =
selectedFeeToken.address !== constants.AddressZero
? BigNumber.max(parsedAmountBn.minus(parsedBridgeFee), new BigNumber(0))
: parsedAmountBn;
const amountAfterFeeFormatted = amountAfterFee.toString();

// Check if we have enough balance for both amount and fee
let hasSufficientBalance = true;
if (selectedFeeToken.address !== constants.AddressZero) {
const totalRequired = parsedAmountBn.plus(parsedBridgeFee);
hasSufficientBalance = parsedWalletBalance.gte(totalRequired);
}

const bridgeActionsProps: BridgeActionProps = {
amountToBridge: amount,
isWrongNetwork,
symbol: GHO_SYMBOL,
blocked:
loadingBridgeMessage ||
!destinationAccount ||
bridgeLimitExceeded ||
rateLimitExceeded ||
loadingLimits ||
!hasSufficientBalance,
decimals: 18,
message,
fees: bridgeFee,
sourceChainId: sourceNetworkObj.chainId,
destinationChainId: destinationNetworkObj.chainId,
tokenAddress: sourceTokenInfo?.address || constants.AddressZero,
isCustomFeeToken: selectedFeeToken.address !== constants.AddressZero,
};

return (
<>
<Box display="flex" justifyContent="space-between" alignItems="center">
Expand Down Expand Up @@ -617,6 +630,20 @@ export const BridgeModalContent = () => {
</Warning>
)}

{selectedFeeToken.address !== constants.AddressZero &&
!hasSufficientBalance &&
amount !== '' &&
!loadingBridgeMessage && (
<Warning severity="warning" sx={{ mt: 4 }} icon={false}>
<Typography variant="caption">
<Trans>
You dont have enough balance to cover with fees. Switch the fee token to network
token.
</Trans>
</Typography>
</Warning>
)}

{/* {bridgeLimitExceeded && (
<Warning severity="error" sx={{ mt: 4 }} icon={false}>
<Typography variant="caption">
Expand Down
Loading
Loading