Skip to content

Commit

Permalink
feat: add deposit tracking
Browse files Browse the repository at this point in the history
Signed-off-by: james-a-morris <[email protected]>
  • Loading branch information
james-a-morris committed Jan 9, 2025
1 parent c11100b commit 4d2880e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/components/DepositsTable/cells/RouteCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@ import styled from "@emotion/styled";
import { Text } from "components/Text";
import { IconPair } from "components/IconPair";
import { Deposit } from "hooks/useDeposits";
import { getChainInfo } from "utils";
import { ChainInfo, getChainInfo, isHyperLiquidBoundDeposit } from "utils";

import { BaseCell } from "./BaseCell";
import { externConfigs } from "constants/chains/configs";

type Props = {
deposit: Deposit;
width: number;
};

export function RouteCell({ deposit, width }: Props) {
const isHyperLiquidDeposit = isHyperLiquidBoundDeposit(deposit);

const sourceChain = getChainInfo(deposit.sourceChainId);
const destinationChain = getChainInfo(deposit.destinationChainId);
const destinationChain: Pick<ChainInfo, "name" | "logoURI"> =
isHyperLiquidDeposit
? externConfigs["hyper-liquid"]
: getChainInfo(deposit.destinationChainId);

return (
<StyledRouteCell width={width}>
Expand Down
32 changes: 32 additions & 0 deletions src/utils/hyperliquid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Deposit } from "hooks/useDeposits";
import { CHAIN_IDs } from "@across-protocol/constants";
import { utils } from "ethers";

export function isHyperLiquidBoundDeposit(deposit: Deposit) {
if (deposit.destinationChainId !== CHAIN_IDs.ARBITRUM || !deposit.message) {
return false;
}

try {
// Try to decode the message as Instructions struct
const decoded = utils.defaultAbiCoder.decode(
[
"tuple(tuple(address target, bytes callData, uint256 value)[] calls, address fallbackRecipient)",
],
deposit.message
);

// Check if it has exactly 2 calls
if (decoded[0].calls.length !== 2) {
return false;
}

// Check if second call is to HyperLiquid Bridge2 contract
return (
decoded[0].calls[1].target.toLowerCase() ===
"0x2Df1c51E09aECF9cacB7bc98cB1742757f163dF7".toLowerCase()
);
} catch {
return false;
}
}
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ export * from "./types";
export * from "./network";
export * from "./url";
export * from "./sdk";
export * from "./hyperliquid";
4 changes: 2 additions & 2 deletions src/views/Bridge/hooks/useBridgeAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ export function useBridgeAction(
// 4. We must construct a payload to send to HL's Bridge2 contract
// 5. The user must sign this signature

// For now let's assume a 0.05% loss in the amount
const amount = frozenDepositArgs.amount.mul(9995).div(10000);
// For now let's assume a 2% loss in the amount
const amount = frozenDepositArgs.amount.mul(98).div(100);

// Build the payload
const hyperLiquidPayload = await generateHyperLiquidPayload(
Expand Down

0 comments on commit 4d2880e

Please sign in to comment.