Skip to content

Commit

Permalink
Merge branch 'master' into james/hyperliquid-integration
Browse files Browse the repository at this point in the history
  • Loading branch information
james-a-morris authored Jan 9, 2025
2 parents e84861b + 948b6f2 commit e2a8513
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 27 deletions.
2 changes: 2 additions & 0 deletions api/_constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,5 @@ export const DOMAIN_CALLDATA_DELIMITER = "0x1dc0de";
export const DEFAULT_LITE_CHAIN_USD_MAX_BALANCE = "250000";

export const DEFAULT_LITE_CHAIN_USD_MAX_DEPOSIT = "25000";

export const DEFAULT_FILL_DEADLINE_BUFFER_SECONDS = 2.5 * 60 * 60; // 2.5 hours
19 changes: 19 additions & 0 deletions api/_fill-deadline.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { DEFAULT_FILL_DEADLINE_BUFFER_SECONDS } from "./_constants";
import { getSpokePool } from "./_utils";

function getFillDeadlineBuffer(chainId: number) {
const bufferFromEnv = (
JSON.parse(process.env.FILL_DEADLINE_BUFFER_SECONDS || "{}") as Record<
string,
string
>
)?.[chainId.toString()];
return Number(bufferFromEnv ?? DEFAULT_FILL_DEADLINE_BUFFER_SECONDS);
}

export async function getFillDeadline(chainId: number): Promise<number> {
const fillDeadlineBuffer = getFillDeadlineBuffer(chainId);
const spokePool = getSpokePool(chainId);
const currentTime = await spokePool.callStatic.getCurrentTime();
return Number(currentTime) + fillDeadlineBuffer;
}
3 changes: 1 addition & 2 deletions api/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ const {
REACT_APP_HUBPOOL_CHAINID,
REACT_APP_PUBLIC_INFURA_ID,
REACT_APP_COINGECKO_PRO_API_KEY,
GAS_MARKUP, // To be deprecated and replaced by BASE_FEE_MARKUP and PRIORITY_FEE_MARKUP
BASE_FEE_MARKUP,
PRIORITY_FEE_MARKUP,
VERCEL_ENV,
Expand All @@ -94,7 +93,7 @@ const {

export const baseFeeMarkup: {
[chainId: string]: number;
} = JSON.parse(BASE_FEE_MARKUP || GAS_MARKUP || "{}");
} = JSON.parse(BASE_FEE_MARKUP || "{}");
export const priorityFeeMarkup: {
[chainId: string]: number;
} = JSON.parse(PRIORITY_FEE_MARKUP || "{}");
Expand Down
4 changes: 4 additions & 0 deletions api/suggested-fees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
AmountTooHighError,
AmountTooLowError,
} from "./_errors";
import { getFillDeadline } from "./_fill-deadline";

const { BigNumber } = ethers;

Expand Down Expand Up @@ -187,6 +188,7 @@ const handler = async (
[currentUt, nextUt, _quoteTimestamp, rawL1TokenConfig],
tokenPriceUsd,
limits,
fillDeadline,
] = await Promise.all([
callViaMulticall3(provider, multiCalls, { blockTag: quoteBlockNumber }),
getCachedTokenPrice(l1Token.address, "usd"),
Expand All @@ -203,6 +205,7 @@ const handler = async (
depositWithMessage ? relayer : undefined,
depositWithMessage ? message : undefined
),
getFillDeadline(destinationChainId),
]);
const { maxDeposit, maxDepositInstant, minDeposit, relayerFeeDetails } =
limits;
Expand Down Expand Up @@ -341,6 +344,7 @@ const handler = async (
maxDepositShortDelay: limits.maxDepositShortDelay,
recommendedDepositInstant: limits.recommendedDepositInstant,
},
fillDeadline: fillDeadline.toString(),
};

logger.debug({
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"@across-protocol/constants": "^3.1.24",
"@across-protocol/contracts": "^3.0.19",
"@across-protocol/contracts-v3.0.6": "npm:@across-protocol/[email protected]",
"@across-protocol/sdk": "^3.4.5",
"@across-protocol/sdk": "^3.4.7",
"@amplitude/analytics-browser": "^2.3.5",
"@balancer-labs/sdk": "1.1.6-beta.16",
"@emotion/react": "^11.13.0",
Expand Down
17 changes: 4 additions & 13 deletions src/utils/bridge.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ethers, BigNumber } from "ethers";
import {
ChainId,
DEFAULT_FILL_DEADLINE_BUFFER_SECONDS,
fixedPointAdjustment,
referrerDelimiterHex,
} from "./constants";
Expand Down Expand Up @@ -32,6 +31,7 @@ export type BridgeFees = {
estimatedFillTimeSec: number;
exclusiveRelayer: string;
exclusivityDeadline: number;
fillDeadline: number;
};

type GetBridgeFeesArgs = {
Expand Down Expand Up @@ -77,6 +77,7 @@ export async function getBridgeFees({
estimatedFillTimeSec,
exclusiveRelayer,
exclusivityDeadline,
fillDeadline,
} = await getApiEndpoint().suggestedFees(
amount,
getConfig().getTokenInfoBySymbol(fromChainId, inputTokenSymbol).address,
Expand All @@ -103,6 +104,7 @@ export async function getBridgeFees({
estimatedFillTimeSec,
exclusiveRelayer,
exclusivityDeadline,
fillDeadline,
};
}

Expand Down Expand Up @@ -150,7 +152,7 @@ export type AcrossDepositArgs = {
export type AcrossDepositV3Args = AcrossDepositArgs & {
inputTokenAddress: string;
outputTokenAddress: string;
fillDeadline?: number;
fillDeadline: number;
exclusivityDeadline?: number;
exclusiveRelayer?: string;
};
Expand Down Expand Up @@ -236,7 +238,6 @@ export async function sendDepositV3Tx(
const outputAmount = inputAmount.sub(
inputAmount.mul(relayerFeePct).div(fixedPointAdjustment)
);
fillDeadline ??= await getFillDeadline(spokePool);

const useExclusiveRelayer =
exclusiveRelayer !== ethers.constants.AddressZero &&
Expand Down Expand Up @@ -350,7 +351,6 @@ export async function sendSwapAndBridgeTx(
const outputAmount = inputAmount.sub(
inputAmount.mul(relayerFeePct).div(fixedPointAdjustment)
);
fillDeadline ??= await getFillDeadline(spokePool);

const tx = await swapAndBridge.populateTransaction.swapAndBridge(
swapQuote.routerCalldata,
Expand Down Expand Up @@ -424,15 +424,6 @@ export async function getSpokePoolAndVerifier({
};
}

async function getFillDeadline(spokePool: SpokePool): Promise<number> {
const fillDeadlineBuffer = Number(
process.env.FILL_DEADLINE_BUFFER_SECONDS ??
DEFAULT_FILL_DEADLINE_BUFFER_SECONDS
);
const currentTime = await spokePool.callStatic.getCurrentTime();
return Number(currentTime) + fillDeadlineBuffer;
}

async function _tagRefAndSignTx(
tx: ethers.PopulatedTransaction,
referrer: string,
Expand Down
2 changes: 0 additions & 2 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,5 +551,3 @@ export const defaultSwapSlippage = Number(

export const indexerApiBaseUrl =
process.env.REACT_APP_INDEXER_BASE_URL || undefined;

export const DEFAULT_FILL_DEADLINE_BUFFER_SECONDS = 2.5 * 60 * 60; // 2.5 hours
1 change: 1 addition & 0 deletions src/utils/serverless-api/mocked/suggested-fees.mocked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ export async function suggestedFeesMockedApiCall(
},
exclusiveRelayer: ethers.constants.AddressZero,
exclusivityDeadline: 0,
fillDeadline: Date.now(),
};
}
1 change: 1 addition & 0 deletions src/utils/serverless-api/prod/suggested-fees.prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,6 @@ export async function suggestedFeesApiCall(
estimatedFillTimeSec,
exclusiveRelayer,
exclusivityDeadline,
fillDeadline: result.fillDeadline,
};
}
1 change: 1 addition & 0 deletions src/utils/serverless-api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export type SuggestedApiFeeReturnType = {
estimatedFillTimeSec: number;
exclusiveRelayer: string;
exclusivityDeadline: number;
fillDeadline: number;
};

export type SuggestedApiFeeType = (
Expand Down
2 changes: 2 additions & 0 deletions src/views/Bridge/hooks/useBridgeAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ export function useBridgeAction(
// Disabling until we update the contract.
exclusiveRelayer: constants.AddressZero,
exclusivityDeadline: 0,
fillDeadline: frozenFeeQuote.fillDeadline,
},
networkMismatchHandler
);
Expand Down Expand Up @@ -266,6 +267,7 @@ export function useBridgeAction(
toAddress: externalProjectIsHyperLiquid
? "0x924a9f036260DdD5808007E1AA95f08eD08aA569" // Default multicall handler
: frozenDepositArgs.toAddress,
fillDeadline: frozenFeeQuote.fillDeadline,
},
spokePool,
networkMismatchHandler
Expand Down
13 changes: 4 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@
resolved "https://registry.yarnpkg.com/@across-protocol/constants/-/constants-3.1.25.tgz#60d6d9814582ff91faf2b6d9f51d6dccb447b4ce"
integrity sha512-GpZoYn7hETYL2BPMM2GqXAer6+l/xuhder+pvpb00HJcb/sqCjF7vaaeKxjKJ3jKtyeulYmdu0NDkeNm5KbNWA==

"@across-protocol/constants@^3.1.25":
version "3.1.25"
resolved "https://registry.yarnpkg.com/@across-protocol/constants/-/constants-3.1.25.tgz#60d6d9814582ff91faf2b6d9f51d6dccb447b4ce"
integrity sha512-GpZoYn7hETYL2BPMM2GqXAer6+l/xuhder+pvpb00HJcb/sqCjF7vaaeKxjKJ3jKtyeulYmdu0NDkeNm5KbNWA==

"@across-protocol/constants@^3.1.9":
version "3.1.13"
resolved "https://registry.yarnpkg.com/@across-protocol/constants/-/constants-3.1.13.tgz#b4caf494e9d9fe50290cca91b7883ea408fdb90a"
Expand Down Expand Up @@ -88,10 +83,10 @@
yargs "^17.7.2"
zksync-web3 "^0.14.3"

"@across-protocol/sdk@^3.4.5":
version "3.4.5"
resolved "https://registry.yarnpkg.com/@across-protocol/sdk/-/sdk-3.4.5.tgz#343f53be92e92afd2fd4dbea16f180533093ea26"
integrity sha512-o1DovRfSriL0GTa304rd2KcBDwWYbK2SHT8mElyCLg6beX5RnJKT0YiMUMuCMfZ7MZJscdGzV023e5BhbyeP5A==
"@across-protocol/sdk@^3.4.7":
version "3.4.7"
resolved "https://registry.yarnpkg.com/@across-protocol/sdk/-/sdk-3.4.7.tgz#6ddf9698f918d7b7e0216327d60b54b37fe14f22"
integrity sha512-GeyzDG8EzlN8oddmjXASqND+usZPkWDLpzbdWfAfBfHT3pjIMatntZqZghfCfjy+ICf+rlYrAb8I24H4jlct8Q==
dependencies:
"@across-protocol/across-token" "^1.0.0"
"@across-protocol/constants" "^3.1.25"
Expand Down

0 comments on commit e2a8513

Please sign in to comment.