From 9c5b7c9054fbdd0449b47b028ba36a2a45327689 Mon Sep 17 00:00:00 2001 From: jackburrus Date: Mon, 10 Feb 2025 11:17:48 -0700 Subject: [PATCH 1/3] adds zap contract to getHyperdrive Co-authored-by: Danny Delott --- .../useAppConfigForConnectedChain.ts | 7 +++ .../ui/hyperdrive/hooks/useReadHyperdrive.ts | 1 + .../hooks/useReadWriteHyperdrive.ts | 1 + .../ui/hyperdrive/hooks/useUnpausedPools.ts | 1 + .../longs/hooks/useTotalOpenLongsValue.ts | 4 ++ .../lp/hooks/useTotalOpenLpPositions.ts | 2 + .../shorts/hooks/useTotalOpenShortsValue.ts | 5 +- .../src/ui/markets/hooks/usePoolsList.ts | 1 + .../src/ui/portfolio/longs/LongsContainer.tsx | 4 +- .../portfolio/longs/usePortfolioLongsData.ts | 10 +++- .../src/ui/portfolio/lp/usePortfolioLpData.ts | 5 ++ .../shorts/usePortfolioShortsData.ts | 5 ++ apps/sdk-sandbox/scripts/example.ts | 2 +- .../src/hyperdrive/ReadHyperdrive.ts | 47 ++++++++++--------- .../src/hyperdrive/getHyperdrive.ts | 2 + 15 files changed, 71 insertions(+), 26 deletions(-) diff --git a/apps/hyperdrive-trading/src/ui/appconfig/useAppConfigForConnectedChain.ts b/apps/hyperdrive-trading/src/ui/appconfig/useAppConfigForConnectedChain.ts index 142a0c11b..8b4b2deaa 100644 --- a/apps/hyperdrive-trading/src/ui/appconfig/useAppConfigForConnectedChain.ts +++ b/apps/hyperdrive-trading/src/ui/appconfig/useAppConfigForConnectedChain.ts @@ -2,6 +2,7 @@ import { AppConfig, // eslint-disable-next-line no-restricted-imports appConfig as appConfigFromImport, + HyperdriveConfig, isMainnetChain, mainnetAppConfig, testnetAppConfig, @@ -39,6 +40,12 @@ export function useAppConfigForConnectedChain( if (tokenList) { return { ...appConfig, + hyperdrives: [ + appConfig.hyperdrives.find( + (hyperdrive) => + hyperdrive.address === "0x324395D5d835F84a02A75Aa26814f6fD22F25698", + ) as HyperdriveConfig, + ], tokens: uniqBy( [...appConfig.tokens, ...tokenList], (token) => `${token.address}-${token.chainId}`, diff --git a/apps/hyperdrive-trading/src/ui/hyperdrive/hooks/useReadHyperdrive.ts b/apps/hyperdrive-trading/src/ui/hyperdrive/hooks/useReadHyperdrive.ts index cec794346..d537b8c3d 100644 --- a/apps/hyperdrive-trading/src/ui/hyperdrive/hooks/useReadHyperdrive.ts +++ b/apps/hyperdrive-trading/src/ui/hyperdrive/hooks/useReadHyperdrive.ts @@ -33,6 +33,7 @@ export function useReadHyperdrive({ address, drift, earliestBlock: initializationBlock, + zapContractAddress: appConfig.zaps[chainId].address, }); } : undefined, diff --git a/apps/hyperdrive-trading/src/ui/hyperdrive/hooks/useReadWriteHyperdrive.ts b/apps/hyperdrive-trading/src/ui/hyperdrive/hooks/useReadWriteHyperdrive.ts index d5df13051..a6a9c9123 100644 --- a/apps/hyperdrive-trading/src/ui/hyperdrive/hooks/useReadWriteHyperdrive.ts +++ b/apps/hyperdrive-trading/src/ui/hyperdrive/hooks/useReadWriteHyperdrive.ts @@ -34,6 +34,7 @@ export function useReadWriteHyperdrive({ address, drift, earliestBlock: initializationBlock, + zapContractAddress: appConfig.zaps[chainId].address, }); } : undefined, diff --git a/apps/hyperdrive-trading/src/ui/hyperdrive/hooks/useUnpausedPools.ts b/apps/hyperdrive-trading/src/ui/hyperdrive/hooks/useUnpausedPools.ts index b2d508244..38edd9ff2 100644 --- a/apps/hyperdrive-trading/src/ui/hyperdrive/hooks/useUnpausedPools.ts +++ b/apps/hyperdrive-trading/src/ui/hyperdrive/hooks/useUnpausedPools.ts @@ -46,6 +46,7 @@ export function useUnpausedPools(): { address: hyperdrive.address, drift: getDrift({ chainId: hyperdrive.chainId }), earliestBlock: hyperdrive.initializationBlock, + zapContractAddress: appConfig.zaps[hyperdrive.chainId].address, }); // We only show hyperdrives that are not paused diff --git a/apps/hyperdrive-trading/src/ui/hyperdrive/longs/hooks/useTotalOpenLongsValue.ts b/apps/hyperdrive-trading/src/ui/hyperdrive/longs/hooks/useTotalOpenLongsValue.ts index 156f42386..a31b83017 100644 --- a/apps/hyperdrive-trading/src/ui/hyperdrive/longs/hooks/useTotalOpenLongsValue.ts +++ b/apps/hyperdrive-trading/src/ui/hyperdrive/longs/hooks/useTotalOpenLongsValue.ts @@ -6,6 +6,7 @@ import { import { useQuery } from "@tanstack/react-query"; import { makeQueryKey2 } from "src/base/makeQueryKey"; import { getDrift } from "src/drift/getDrift"; +import { useAppConfigForConnectedChain } from "src/ui/appconfig/useAppConfigForConnectedChain"; import { Address } from "viem"; export function useTotalOpenLongsValueTwo({ account, @@ -22,6 +23,7 @@ export function useTotalOpenLongsValueTwo({ isLoading: boolean; totalOpenLongsValueError: Error; } { + const appConfig = useAppConfigForConnectedChain(); const queryEnabled = !!account && !!longs && enabled; const { data: totalOpenLongsValue, @@ -45,6 +47,8 @@ export function useTotalOpenLongsValueTwo({ address: long.hyperdrive.address, drift: getDrift({ chainId: long.hyperdrive.chainId }), earliestBlock: long.hyperdrive.initializationBlock, + zapContractAddress: + appConfig.zaps[long.hyperdrive.chainId].address, }); const preview = await readHyperdrive.previewCloseLong({ maturityTime: long.details?.maturity || 0n, diff --git a/apps/hyperdrive-trading/src/ui/hyperdrive/lp/hooks/useTotalOpenLpPositions.ts b/apps/hyperdrive-trading/src/ui/hyperdrive/lp/hooks/useTotalOpenLpPositions.ts index 84cd95252..eb19647b8 100644 --- a/apps/hyperdrive-trading/src/ui/hyperdrive/lp/hooks/useTotalOpenLpPositions.ts +++ b/apps/hyperdrive-trading/src/ui/hyperdrive/lp/hooks/useTotalOpenLpPositions.ts @@ -51,6 +51,8 @@ export function useTotalOpenLpPositions({ address: position.hyperdrive.address, drift: getDrift({ chainId: position.hyperdrive.chainId }), earliestBlock: position.hyperdrive.initializationBlock, + zapContractAddress: + appConfig.zaps[position.hyperdrive.chainId].address, }); const openLpPosition = await readHyperdrive.getOpenLpPosition({ account, diff --git a/apps/hyperdrive-trading/src/ui/hyperdrive/shorts/hooks/useTotalOpenShortsValue.ts b/apps/hyperdrive-trading/src/ui/hyperdrive/shorts/hooks/useTotalOpenShortsValue.ts index 49f06b12b..2a611d0c2 100644 --- a/apps/hyperdrive-trading/src/ui/hyperdrive/shorts/hooks/useTotalOpenShortsValue.ts +++ b/apps/hyperdrive-trading/src/ui/hyperdrive/shorts/hooks/useTotalOpenShortsValue.ts @@ -3,6 +3,7 @@ import { getHyperdrive, OpenShort } from "@delvtech/hyperdrive-js"; import { useQuery } from "@tanstack/react-query"; import { makeQueryKey2 } from "src/base/makeQueryKey"; import { getDrift } from "src/drift/getDrift"; +import { useAppConfigForConnectedChain } from "src/ui/appconfig/useAppConfigForConnectedChain"; import { Address } from "viem"; export function useTotalOpenShortsValue({ @@ -15,7 +16,7 @@ export function useTotalOpenShortsValue({ enabled: boolean; }): { totalOpenShortsValue: bigint | undefined; isLoading: boolean } { const queryEnabled = !!account && !!shorts && enabled; - + const appConfig = useAppConfigForConnectedChain(); const { data: totalOpenShortsValue, isLoading } = useQuery({ queryKey: makeQueryKey2({ namespace: "portfolio", @@ -34,6 +35,8 @@ export function useTotalOpenShortsValue({ address: short.hyperdrive.address, drift: getDrift({ chainId: short.hyperdrive.chainId }), earliestBlock: short.hyperdrive.initializationBlock, + zapContractAddress: + appConfig.zaps[short.hyperdrive.chainId].address, }); const preview = await readHyperdrive.previewCloseShort({ maturityTime: short.maturity, diff --git a/apps/hyperdrive-trading/src/ui/markets/hooks/usePoolsList.ts b/apps/hyperdrive-trading/src/ui/markets/hooks/usePoolsList.ts index c386e0bb7..854dc7f10 100644 --- a/apps/hyperdrive-trading/src/ui/markets/hooks/usePoolsList.ts +++ b/apps/hyperdrive-trading/src/ui/markets/hooks/usePoolsList.ts @@ -130,6 +130,7 @@ function useSortedPools({ address: hyperdrive.address, drift: getDrift({ chainId: hyperdrive.chainId }), earliestBlock: hyperdrive.initializationBlock, + zapContractAddress: appConfig.zaps[hyperdrive.chainId].address, }); const publicClient = getPublicClient(wagmiConfig as any, { chainId: hyperdrive.chainId, diff --git a/apps/hyperdrive-trading/src/ui/portfolio/longs/LongsContainer.tsx b/apps/hyperdrive-trading/src/ui/portfolio/longs/LongsContainer.tsx index 280fa1c74..afe86e300 100644 --- a/apps/hyperdrive-trading/src/ui/portfolio/longs/LongsContainer.tsx +++ b/apps/hyperdrive-trading/src/ui/portfolio/longs/LongsContainer.tsx @@ -5,11 +5,11 @@ import { ExternalLink } from "src/ui/analytics/ExternalLink"; import { useAppConfigForConnectedChain } from "src/ui/appconfig/useAppConfigForConnectedChain"; import LoadingState from "src/ui/base/components/LoadingState"; import { NonIdealState } from "src/ui/base/components/NonIdealState"; -import { usePortfolioLongsData } from "src/ui/portfolio/longs/usePortfolioLongsData"; import { NoWalletConnected } from "src/ui/portfolio/NoWalletConnected"; import { PositionContainer } from "src/ui/portfolio/PositionContainer"; import { Address } from "viem"; import { OpenLongsTableDesktop } from "./OpenLongsTable/OpenLongsTableDesktop"; +import { usePortfolioLongsData } from "./usePortfolioLongsData"; export function OpenLongsContainer({ account, @@ -21,6 +21,8 @@ export function OpenLongsContainer({ account, }); + console.log("openLongPositions", openLongPositions); + const hyperdrivesByChainAndYieldSource = groupBy( appConfig.hyperdrives, (hyperdrive) => `${hyperdrive.chainId}-${hyperdrive.yieldSource}`, diff --git a/apps/hyperdrive-trading/src/ui/portfolio/longs/usePortfolioLongsData.ts b/apps/hyperdrive-trading/src/ui/portfolio/longs/usePortfolioLongsData.ts index 4f5157006..efbfdd19e 100644 --- a/apps/hyperdrive-trading/src/ui/portfolio/longs/usePortfolioLongsData.ts +++ b/apps/hyperdrive-trading/src/ui/portfolio/longs/usePortfolioLongsData.ts @@ -24,7 +24,6 @@ export function usePortfolioLongsData({ } { const appConfigForConnectedChain = useAppConfigForConnectedChain(); const queryEnabled = !!account && !!appConfigForConnectedChain; - const { data: openLongPositions, status: openLongPositionsStatus } = useQuery( { queryKey: makeQueryKey("portfolioLongs", { account }), @@ -37,11 +36,14 @@ export function usePortfolioLongsData({ address: hyperdrive.address, drift: getDrift({ chainId: hyperdrive.chainId }), earliestBlock: hyperdrive.initializationBlock, + zapContractAddress: + appConfigForConnectedChain.zaps[hyperdrive.chainId].address, }); const allLongs = await readHyperdrive.getOpenLongPositions({ account, }); + console.log("allLongs", allLongs); const openLongs = await Promise.all( allLongs.map(async (long) => ({ ...long, @@ -51,6 +53,8 @@ export function usePortfolioLongsData({ }), })), ); + + console.log("all Open Longs", openLongs); return { hyperdrive, openLongs, @@ -80,7 +84,7 @@ export function usePortfolioLongsDataFromHyperdrives({ openLongPositionsStatus: "error" | "success" | "loading"; } { const queryEnabled = !!account && !!hyperdrives.length; - + const appConfigForConnectedChain = useAppConfigForConnectedChain(); const { data: openLongPositions, status: openLongPositionsStatus } = useQuery( { queryKey: makeQueryKey2({ @@ -96,6 +100,8 @@ export function usePortfolioLongsDataFromHyperdrives({ address: hyperdrive.address, drift: getDrift({ chainId: hyperdrive.chainId }), earliestBlock: hyperdrive.initializationBlock, + zapContractAddress: + appConfigForConnectedChain.zaps[hyperdrive.chainId].address, }); const allLongs = await readHyperdrive.getOpenLongPositions({ account, diff --git a/apps/hyperdrive-trading/src/ui/portfolio/lp/usePortfolioLpData.ts b/apps/hyperdrive-trading/src/ui/portfolio/lp/usePortfolioLpData.ts index 399e35d17..3d728fd17 100644 --- a/apps/hyperdrive-trading/src/ui/portfolio/lp/usePortfolioLpData.ts +++ b/apps/hyperdrive-trading/src/ui/portfolio/lp/usePortfolioLpData.ts @@ -22,6 +22,7 @@ export function usePortfolioLpDataFromHyperdrives({ openLpPositions: LpPosition[] | undefined; openLpPositionStatus: "error" | "success" | "loading"; } { + const appConfigForConnectedChain = useAppConfigForConnectedChain(); const queryEnabled = !!account && !!hyperdrives.length; const { data, status } = useQuery({ queryKey: makeQueryKey("portfolioLp", { @@ -39,6 +40,8 @@ export function usePortfolioLpDataFromHyperdrives({ address: hyperdrive.address, drift: getDrift({ chainId: hyperdrive.chainId }), earliestBlock: hyperdrive.initializationBlock, + zapContractAddress: + appConfigForConnectedChain.zaps[hyperdrive.chainId].address, }); const [lpShares, withdrawalShares] = await Promise.all([ @@ -88,6 +91,8 @@ export function usePortfolioLpData({ address: hyperdrive.address, drift: getDrift({ chainId: hyperdrive.chainId }), earliestBlock: hyperdrive.initializationBlock, + zapContractAddress: + appConfigForConnectedChain.zaps[hyperdrive.chainId].address, }); const [lpShares, withdrawalShares] = await Promise.all([ diff --git a/apps/hyperdrive-trading/src/ui/portfolio/shorts/usePortfolioShortsData.ts b/apps/hyperdrive-trading/src/ui/portfolio/shorts/usePortfolioShortsData.ts index bff0a786a..a8de8454c 100644 --- a/apps/hyperdrive-trading/src/ui/portfolio/shorts/usePortfolioShortsData.ts +++ b/apps/hyperdrive-trading/src/ui/portfolio/shorts/usePortfolioShortsData.ts @@ -34,6 +34,8 @@ export function usePortfolioShortsData({ address: hyperdrive.address, drift: getDrift({ chainId: hyperdrive.chainId }), earliestBlock: hyperdrive.initializationBlock, + zapContractAddress: + appConfigForConnectedChain.zaps[hyperdrive.chainId].address, }); return { @@ -64,6 +66,7 @@ export function usePortfolioShortsDataFromHyperdrives({ | undefined; openShortPositionsStatus: "error" | "success" | "loading"; } { + const appConfigForConnectedChain = useAppConfigForConnectedChain(); const queryEnabled = !!account && !!hyperdrives.length; const { data: openShortPositions, status: openShortPositionsStatus } = useQuery({ @@ -80,6 +83,8 @@ export function usePortfolioShortsDataFromHyperdrives({ address: hyperdrive.address, drift: getDrift({ chainId: hyperdrive.chainId }), earliestBlock: hyperdrive.initializationBlock, + zapContractAddress: + appConfigForConnectedChain.zaps[hyperdrive.chainId].address, }); const openShorts = await readHyperdrive.getOpenShorts({ account, diff --git a/apps/sdk-sandbox/scripts/example.ts b/apps/sdk-sandbox/scripts/example.ts index 046a0d62b..03bc1320a 100644 --- a/apps/sdk-sandbox/scripts/example.ts +++ b/apps/sdk-sandbox/scripts/example.ts @@ -27,7 +27,7 @@ const writePool = new ReadWriteHyperdrive({ const readPool = new ReadHyperdrive({ address: poolAddress, drift, - auxiliaryContractAddress: zapsConfig.address, + zapContractAddress: zapsConfig.address, earliestBlock, }); diff --git a/packages/hyperdrive-js/src/hyperdrive/ReadHyperdrive.ts b/packages/hyperdrive-js/src/hyperdrive/ReadHyperdrive.ts index f3dd225eb..b0a2b8577 100644 --- a/packages/hyperdrive-js/src/hyperdrive/ReadHyperdrive.ts +++ b/packages/hyperdrive-js/src/hyperdrive/ReadHyperdrive.ts @@ -859,28 +859,33 @@ export class ReadHyperdrive extends ReadClient { filter: { trader: account, assetId }, }); - // Handle transfers sent to the contract. - const transfersSentToAux = await this.contract.getEvents("TransferSingle", { - filter: { from: account, to: this.zapContractAddress }, - toBlock: options?.block, - }); - - if (transfersSentToAux.length) { - const accountTxHashes = transfersSentToAux.map( - ({ transactionHash }) => transactionHash, - ); - // Fetch CloseLong events emitted by the auxiliary contract in the relevant block range. - const allAuxCloses = await this.contract.getEvents("CloseLong", { - filter: { trader: this.zapContractAddress, assetId }, - fromBlock: transfersSentToAux[0].blockNumber, - toBlock: transfersSentToAux.at(-1)?.blockNumber, - }); - // Only include events that occurred in the same transactions. - const auxClosesForAccount = allAuxCloses.filter(({ transactionHash }) => - accountTxHashes.includes(transactionHash as `0x${string}`), + if (this.zapContractAddress) { + // Handle transfers sent to the zap contract. + const transfersSentToZap = await this.contract.getEvents( + "TransferSingle", + { + filter: { from: account, to: this.zapContractAddress }, + toBlock: options?.block, + }, ); - for (const event of auxClosesForAccount) { - closeLongEvents.push(event); + + if (transfersSentToZap.length) { + const accountTxHashes = transfersSentToZap.map( + ({ transactionHash }) => transactionHash, + ); + // Fetch CloseLong events emitted by the auxiliary contract in the relevant block range. + const allZapCloses = await this.contract.getEvents("CloseLong", { + filter: { trader: this.zapContractAddress, assetId }, + fromBlock: transfersSentToZap[0].blockNumber, + toBlock: transfersSentToZap.at(-1)?.blockNumber, + }); + // Only include events that occurred in the same transactions. + const zapClosesForAccount = allZapCloses.filter(({ transactionHash }) => + accountTxHashes.includes(transactionHash as `0x${string}`), + ); + for (const event of zapClosesForAccount) { + closeLongEvents.push(event); + } } } diff --git a/packages/hyperdrive-js/src/hyperdrive/getHyperdrive.ts b/packages/hyperdrive-js/src/hyperdrive/getHyperdrive.ts index 062016ff7..efc2f2811 100644 --- a/packages/hyperdrive-js/src/hyperdrive/getHyperdrive.ts +++ b/packages/hyperdrive-js/src/hyperdrive/getHyperdrive.ts @@ -31,6 +31,7 @@ export async function getHyperdrive({ cacheNamespace, earliestBlock, debugName, + zapContractAddress, }: HyperdriveOptions): Promise> { cacheNamespace ??= await drift.getChainId(); @@ -41,6 +42,7 @@ export async function getHyperdrive({ cacheNamespace, earliestBlock, debugName, + zapContractAddress, }; const isReadWrite = isReadWriteOptions(options); From e8d937c9f25592dac6f4a60d9638aa1b1d3b2445 Mon Sep 17 00:00:00 2001 From: jackburrus Date: Mon, 10 Feb 2025 11:59:46 -0700 Subject: [PATCH 2/3] cleanup console logs --- .../src/ui/appconfig/useAppConfigForConnectedChain.ts | 7 ------- .../src/ui/portfolio/longs/LongsContainer.tsx | 4 +--- .../src/ui/portfolio/longs/usePortfolioLongsData.ts | 2 -- 3 files changed, 1 insertion(+), 12 deletions(-) diff --git a/apps/hyperdrive-trading/src/ui/appconfig/useAppConfigForConnectedChain.ts b/apps/hyperdrive-trading/src/ui/appconfig/useAppConfigForConnectedChain.ts index 8b4b2deaa..142a0c11b 100644 --- a/apps/hyperdrive-trading/src/ui/appconfig/useAppConfigForConnectedChain.ts +++ b/apps/hyperdrive-trading/src/ui/appconfig/useAppConfigForConnectedChain.ts @@ -2,7 +2,6 @@ import { AppConfig, // eslint-disable-next-line no-restricted-imports appConfig as appConfigFromImport, - HyperdriveConfig, isMainnetChain, mainnetAppConfig, testnetAppConfig, @@ -40,12 +39,6 @@ export function useAppConfigForConnectedChain( if (tokenList) { return { ...appConfig, - hyperdrives: [ - appConfig.hyperdrives.find( - (hyperdrive) => - hyperdrive.address === "0x324395D5d835F84a02A75Aa26814f6fD22F25698", - ) as HyperdriveConfig, - ], tokens: uniqBy( [...appConfig.tokens, ...tokenList], (token) => `${token.address}-${token.chainId}`, diff --git a/apps/hyperdrive-trading/src/ui/portfolio/longs/LongsContainer.tsx b/apps/hyperdrive-trading/src/ui/portfolio/longs/LongsContainer.tsx index afe86e300..280fa1c74 100644 --- a/apps/hyperdrive-trading/src/ui/portfolio/longs/LongsContainer.tsx +++ b/apps/hyperdrive-trading/src/ui/portfolio/longs/LongsContainer.tsx @@ -5,11 +5,11 @@ import { ExternalLink } from "src/ui/analytics/ExternalLink"; import { useAppConfigForConnectedChain } from "src/ui/appconfig/useAppConfigForConnectedChain"; import LoadingState from "src/ui/base/components/LoadingState"; import { NonIdealState } from "src/ui/base/components/NonIdealState"; +import { usePortfolioLongsData } from "src/ui/portfolio/longs/usePortfolioLongsData"; import { NoWalletConnected } from "src/ui/portfolio/NoWalletConnected"; import { PositionContainer } from "src/ui/portfolio/PositionContainer"; import { Address } from "viem"; import { OpenLongsTableDesktop } from "./OpenLongsTable/OpenLongsTableDesktop"; -import { usePortfolioLongsData } from "./usePortfolioLongsData"; export function OpenLongsContainer({ account, @@ -21,8 +21,6 @@ export function OpenLongsContainer({ account, }); - console.log("openLongPositions", openLongPositions); - const hyperdrivesByChainAndYieldSource = groupBy( appConfig.hyperdrives, (hyperdrive) => `${hyperdrive.chainId}-${hyperdrive.yieldSource}`, diff --git a/apps/hyperdrive-trading/src/ui/portfolio/longs/usePortfolioLongsData.ts b/apps/hyperdrive-trading/src/ui/portfolio/longs/usePortfolioLongsData.ts index efbfdd19e..a0af2139a 100644 --- a/apps/hyperdrive-trading/src/ui/portfolio/longs/usePortfolioLongsData.ts +++ b/apps/hyperdrive-trading/src/ui/portfolio/longs/usePortfolioLongsData.ts @@ -43,7 +43,6 @@ export function usePortfolioLongsData({ const allLongs = await readHyperdrive.getOpenLongPositions({ account, }); - console.log("allLongs", allLongs); const openLongs = await Promise.all( allLongs.map(async (long) => ({ ...long, @@ -54,7 +53,6 @@ export function usePortfolioLongsData({ })), ); - console.log("all Open Longs", openLongs); return { hyperdrive, openLongs, From b98ecb6c53af90ce65c2592024fdc3de0f83ab4c Mon Sep 17 00:00:00 2001 From: jackburrus Date: Mon, 10 Feb 2025 12:17:34 -0700 Subject: [PATCH 3/3] updates per comments --- .../src/ui/portfolio/longs/usePortfolioLongsData.ts | 6 ++++-- .../src/ui/portfolio/lp/usePortfolioLpData.ts | 4 ++-- .../src/ui/portfolio/shorts/usePortfolioShortsData.ts | 6 ++++-- packages/hyperdrive-js/src/hyperdrive/ReadHyperdrive.ts | 4 ++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/apps/hyperdrive-trading/src/ui/portfolio/longs/usePortfolioLongsData.ts b/apps/hyperdrive-trading/src/ui/portfolio/longs/usePortfolioLongsData.ts index a0af2139a..366a29ee9 100644 --- a/apps/hyperdrive-trading/src/ui/portfolio/longs/usePortfolioLongsData.ts +++ b/apps/hyperdrive-trading/src/ui/portfolio/longs/usePortfolioLongsData.ts @@ -37,7 +37,8 @@ export function usePortfolioLongsData({ drift: getDrift({ chainId: hyperdrive.chainId }), earliestBlock: hyperdrive.initializationBlock, zapContractAddress: - appConfigForConnectedChain.zaps[hyperdrive.chainId].address, + appConfigForConnectedChain.zaps[hyperdrive.chainId] + ?.address, }); const allLongs = await readHyperdrive.getOpenLongPositions({ @@ -99,7 +100,8 @@ export function usePortfolioLongsDataFromHyperdrives({ drift: getDrift({ chainId: hyperdrive.chainId }), earliestBlock: hyperdrive.initializationBlock, zapContractAddress: - appConfigForConnectedChain.zaps[hyperdrive.chainId].address, + appConfigForConnectedChain.zaps[hyperdrive.chainId] + ?.address, }); const allLongs = await readHyperdrive.getOpenLongPositions({ account, diff --git a/apps/hyperdrive-trading/src/ui/portfolio/lp/usePortfolioLpData.ts b/apps/hyperdrive-trading/src/ui/portfolio/lp/usePortfolioLpData.ts index 3d728fd17..b63c88b93 100644 --- a/apps/hyperdrive-trading/src/ui/portfolio/lp/usePortfolioLpData.ts +++ b/apps/hyperdrive-trading/src/ui/portfolio/lp/usePortfolioLpData.ts @@ -41,7 +41,7 @@ export function usePortfolioLpDataFromHyperdrives({ drift: getDrift({ chainId: hyperdrive.chainId }), earliestBlock: hyperdrive.initializationBlock, zapContractAddress: - appConfigForConnectedChain.zaps[hyperdrive.chainId].address, + appConfigForConnectedChain.zaps[hyperdrive.chainId]?.address, }); const [lpShares, withdrawalShares] = await Promise.all([ @@ -92,7 +92,7 @@ export function usePortfolioLpData({ drift: getDrift({ chainId: hyperdrive.chainId }), earliestBlock: hyperdrive.initializationBlock, zapContractAddress: - appConfigForConnectedChain.zaps[hyperdrive.chainId].address, + appConfigForConnectedChain.zaps[hyperdrive.chainId]?.address, }); const [lpShares, withdrawalShares] = await Promise.all([ diff --git a/apps/hyperdrive-trading/src/ui/portfolio/shorts/usePortfolioShortsData.ts b/apps/hyperdrive-trading/src/ui/portfolio/shorts/usePortfolioShortsData.ts index a8de8454c..99489a787 100644 --- a/apps/hyperdrive-trading/src/ui/portfolio/shorts/usePortfolioShortsData.ts +++ b/apps/hyperdrive-trading/src/ui/portfolio/shorts/usePortfolioShortsData.ts @@ -35,7 +35,8 @@ export function usePortfolioShortsData({ drift: getDrift({ chainId: hyperdrive.chainId }), earliestBlock: hyperdrive.initializationBlock, zapContractAddress: - appConfigForConnectedChain.zaps[hyperdrive.chainId].address, + appConfigForConnectedChain.zaps[hyperdrive.chainId] + ?.address, }); return { @@ -84,7 +85,8 @@ export function usePortfolioShortsDataFromHyperdrives({ drift: getDrift({ chainId: hyperdrive.chainId }), earliestBlock: hyperdrive.initializationBlock, zapContractAddress: - appConfigForConnectedChain.zaps[hyperdrive.chainId].address, + appConfigForConnectedChain.zaps[hyperdrive.chainId] + ?.address, }); const openShorts = await readHyperdrive.getOpenShorts({ account, diff --git a/packages/hyperdrive-js/src/hyperdrive/ReadHyperdrive.ts b/packages/hyperdrive-js/src/hyperdrive/ReadHyperdrive.ts index b0a2b8577..3d5844a8f 100644 --- a/packages/hyperdrive-js/src/hyperdrive/ReadHyperdrive.ts +++ b/packages/hyperdrive-js/src/hyperdrive/ReadHyperdrive.ts @@ -52,7 +52,7 @@ export class ReadHyperdrive extends ReadClient { readonly contract: ReadContract; /** - * The optional address of an auxiliary contract such as a zap contract. + * The optional address of the zap contract. */ readonly zapContractAddress?: Address; @@ -873,7 +873,7 @@ export class ReadHyperdrive extends ReadClient { const accountTxHashes = transfersSentToZap.map( ({ transactionHash }) => transactionHash, ); - // Fetch CloseLong events emitted by the auxiliary contract in the relevant block range. + // Fetch CloseLong events emitted by the zap contract in the relevant block range. const allZapCloses = await this.contract.getEvents("CloseLong", { filter: { trader: this.zapContractAddress, assetId }, fromBlock: transfersSentToZap[0].blockNumber,