Skip to content

Commit

Permalink
Merge branch 'master' into james/acx-1620-fe-fill-estimates-for-snx-w…
Browse files Browse the repository at this point in the history
…ill-be-invalid
  • Loading branch information
james-a-morris authored Oct 31, 2023
2 parents e81bec4 + 23c2680 commit 047d1de
Show file tree
Hide file tree
Showing 54 changed files with 162 additions and 1,033 deletions.
17 changes: 12 additions & 5 deletions api/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,11 +525,9 @@ export const getRelayerFeeDetails = async (
relayerAddress,
tokenPrice
);
} catch (_e: unknown) {
// Resolve and transform the error
const e = _e as Error;
// We want to mask this error as an Input error.
throw new InputError(e?.message);
} catch (err: unknown) {
const reason = resolveEthersError(err);
throw new InputError(`Relayer fill simulation failed - ${reason}`);
}
};

Expand Down Expand Up @@ -730,6 +728,15 @@ export function applyMapFilter<InputType, MapType>(
}, []);
}

export function resolveEthersError(err: unknown): string {
// prettier-ignore
return sdk.typeguards.isEthersError(err)
? `${err.reason}: ${err.code}`
: sdk.typeguards.isError(err)
? err.message
: "unknown error";
}

/**
* Handles the recurring case of error handling
* @param endpoint A string numeric to indicate to the logging utility where this error occurs
Expand Down
9 changes: 6 additions & 3 deletions api/limits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,13 @@ const handler = async (
]);
// If any of the above fails or the route is not enabled, we assume that the
if (
disabledL1Tokens.includes(l1Token.toLowerCase()) ||
tokenDetailsResult.status === "rejected" ||
routeEnabledResult.status === "rejected" ||
!routeEnabledResult.value
routeEnabledResult.status === "rejected"
) {
throw new InputError(`Unable to query route.`);
} else if (
!routeEnabledResult.value ||
disabledL1Tokens.includes(l1Token.toLowerCase())
) {
throw new InputError(`Route is not enabled.`);
}
Expand Down
40 changes: 22 additions & 18 deletions api/suggested-fees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
disabledL1Tokens,
DEFAULT_QUOTE_TIMESTAMP_BUFFER,
TOKEN_SYMBOLS_MAP,
DEFAULT_SIMULATED_RECIPIENT_ADDRESS,
} from "./_constants";
import { TypedVercelRequest } from "./_types";
import {
Expand Down Expand Up @@ -40,8 +41,8 @@ const SuggestedFeesQueryParamsSchema = type({
timestamp: optional(positiveIntStr()),
skipAmountLimit: optional(boolStr()),
message: optional(string()),
recipientAddress: optional(validAddress()),
relayerAddress: optional(validAddress()),
recipient: optional(validAddress()),
relayer: optional(validAddress()),
});

type SuggestedFeesQueryParams = Infer<typeof SuggestedFeesQueryParamsSchema>;
Expand Down Expand Up @@ -69,20 +70,22 @@ const handler = async (
let {
amount: amountInput,
token,
destinationChainId,
destinationChainId: _destinationChainId,
originChainId,
timestamp,
skipAmountLimit,
recipientAddress,
relayerAddress,
recipient,
relayer,
message,
} = query;

if (originChainId === destinationChainId) {
if (originChainId === _destinationChainId) {
throw new InputError("Origin and destination chains cannot be the same");
}
const destinationChainId = Number(_destinationChainId);

recipientAddress ??= sdk.constants.DEFAULT_SIMULATED_RELAYER_ADDRESS;
relayer ??= sdk.constants.DEFAULT_SIMULATED_RELAYER_ADDRESS;
recipient ??= DEFAULT_SIMULATED_RECIPIENT_ADDRESS;
token = ethers.utils.getAddress(token);

const [latestBlock, tokenDetails] = await Promise.all([
Expand Down Expand Up @@ -113,8 +116,8 @@ const handler = async (
throw new InputError("Message must be an even hex string");
}
const isRecipientAContract = await sdk.utils.isContractDeployedToAddress(
recipientAddress,
provider
recipient,
getProvider(destinationChainId)
);
if (!isRecipientAContract) {
throw new InputError(
Expand All @@ -128,20 +131,21 @@ const handler = async (
// of the `handleAcrossMessage` we will check that the balance of the relayer is sufficient to
// support this deposit.
const destinationToken =
sdk.utils.getL2TokenAddresses(l1Token)?.[Number(destinationChainId)];
sdk.utils.getL2TokenAddresses(l1Token)?.[destinationChainId];
if (!sdk.utils.isDefined(destinationToken)) {
throw new InputError(
`Could not resolve token address on ${destinationChainId} for ${l1Token}`
);
}
const balanceOfToken = await getCachedTokenBalance(
destinationChainId,
relayerAddress,
relayer,
destinationToken
);
if (balanceOfToken.lt(amountInput)) {
throw new InputError(
`Relayer Address (${relayerAddress}) doesn't have enough funds to support this deposit. For help, please reach out to https://discord.across.to`
`Relayer Address (${relayer}) doesn't have enough funds to support this deposit;` +
` for help, please reach out to https://discord.across.to`
);
}
}
Expand Down Expand Up @@ -180,7 +184,7 @@ const handler = async (
const blockFinder = new BlockFinder(provider.getBlock.bind(provider));
const [{ number: blockTag }, routeEnabled] = await Promise.all([
blockFinder.getBlockForTimestamp(parsedTimestamp),
isRouteEnabled(computedOriginChainId, Number(destinationChainId), token),
isRouteEnabled(computedOriginChainId, destinationChainId, token),
]);

if (!routeEnabled || disabledL1Tokens.includes(l1Token.toLowerCase()))
Expand All @@ -191,7 +195,7 @@ const handler = async (
provider
);

const baseCurrency = destinationChainId === "137" ? "matic" : "eth";
const baseCurrency = destinationChainId === 137 ? "matic" : "eth";

const [currentUt, nextUt, rateModel, tokenPrice] = await Promise.all([
hubPool.callStatic.liquidityUtilizationCurrent(l1Token, {
Expand All @@ -206,7 +210,7 @@ const handler = async (
blockTag,
},
computedOriginChainId,
Number(destinationChainId)
destinationChainId
),
getCachedTokenPrice(l1Token, baseCurrency),
]);
Expand All @@ -219,11 +223,11 @@ const handler = async (
l1Token,
amount,
computedOriginChainId,
Number(destinationChainId),
recipientAddress,
destinationChainId,
recipient,
tokenPrice,
message,
relayerAddress
relayer
);

const skipAmountLimitEnabled = skipAmountLimit === "true";
Expand Down
12 changes: 0 additions & 12 deletions src/components/Box/Box.tsx

This file was deleted.

1 change: 0 additions & 1 deletion src/components/Box/index.ts

This file was deleted.

5 changes: 2 additions & 3 deletions src/components/Buttons/BaseButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import styled from "@emotion/styled";
import { COLORS } from "utils";

export const BaseButton = styled.button`
--radius: 30px;
Expand Down Expand Up @@ -28,7 +27,7 @@ export const PrimaryButton = styled(BaseButton)`
bottom: 0;
opacity: 0;
border-radius: var(--radius);
box-shadow: 0 0 16px hsla(${COLORS.primary[500]} / 0.55);
box-shadow: 0 0 16px hsla(var(--color-gray) / 0.55);
transition: opacity 0.2s;
}
&:hover:not(:disabled) {
Expand All @@ -50,7 +49,7 @@ export const SecondaryButton = styled(BaseButton)`
bottom: 0;
opacity: 0;
border-radius: var(--radius);
box-shadow: 0 0 16px hsla(${COLORS.gray[500]} / 0.55);
box-shadow: 0 0 16px hsla(var(--color-gray) / 0.55);
transition: opacity 0.2s;
}
&:hover:not(:disabled) {
Expand Down
60 changes: 0 additions & 60 deletions src/components/Dialog/Dialog.styles.tsx

This file was deleted.

21 changes: 0 additions & 21 deletions src/components/Dialog/Dialog.tsx

This file was deleted.

2 changes: 0 additions & 2 deletions src/components/Dialog/index.ts

This file was deleted.

36 changes: 0 additions & 36 deletions src/components/DotStepper/DotStepper.tsx

This file was deleted.

1 change: 0 additions & 1 deletion src/components/DotStepper/index.ts

This file was deleted.

Loading

0 comments on commit 047d1de

Please sign in to comment.