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(suggested-fees): Use dest provider for contract determination #884

Merged
merged 1 commit into from
Oct 26, 2023
Merged
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
17 changes: 9 additions & 8 deletions api/suggested-fees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const handler = async (
let {
amount: amountInput,
token,
destinationChainId,
destinationChainId: _destinationChainId,
originChainId,
timestamp,
skipAmountLimit,
Expand All @@ -73,9 +73,10 @@ const handler = async (
message,
} = query;

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

relayerAddress ??= sdk.constants.DEFAULT_SIMULATED_RELAYER_ADDRESS;
recipientAddress ??= sdk.constants.DEFAULT_SIMULATED_RELAYER_ADDRESS;
Expand All @@ -97,7 +98,7 @@ const handler = async (
}
const isRecipientAContract = await sdk.utils.isContractDeployedToAddress(
recipientAddress,
provider
getProvider(destinationChainId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. This is a subtle bug

);
if (!isRecipientAContract) {
throw new InputError(
Expand All @@ -111,7 +112,7 @@ 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}`
Expand Down Expand Up @@ -163,7 +164,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 @@ -174,7 +175,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 @@ -189,7 +190,7 @@ const handler = async (
blockTag,
},
computedOriginChainId,
Number(destinationChainId)
destinationChainId
),
getCachedTokenPrice(l1Token, baseCurrency),
]);
Expand All @@ -202,7 +203,7 @@ const handler = async (
l1Token,
amount,
computedOriginChainId,
Number(destinationChainId),
destinationChainId,
recipientAddress,
tokenPrice,
message,
Expand Down
Loading