-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from dhedge/feat/add-use-pools-dynamic-hook
Feat/add use pools dynamic hook
- Loading branch information
Showing
61 changed files
with
1,613 additions
and
465 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export { usePoolStatic } from './use-pool.static' | ||
export { usePoolDynamic } from './use-pool.dynamic' | ||
export { usePoolManagerStatic } from './use-pool-manager.static' | ||
export { usePoolManagerDynamic } from './use-pool-manager.dynamic' | ||
export { usePoolsDynamic } from './use-pools.dynamic' |
41 changes: 35 additions & 6 deletions
41
packages/core-ui-kit/src/hooks/pool/multicall/use-pool-manager.dynamic.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 0 additions & 75 deletions
75
packages/core-ui-kit/src/hooks/pool/multicall/use-pool.dynamic.ts
This file was deleted.
Oops, something went wrong.
98 changes: 98 additions & 0 deletions
98
packages/core-ui-kit/src/hooks/pool/multicall/use-pools.dynamic.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import chunk from 'lodash.chunk' | ||
|
||
import { PoolLogicAbi } from 'abi' | ||
import { AddressZero, DEFAULT_CHAIN_ID } from 'const' | ||
import { useTradingPanelPoolConfigs } from 'hooks/state' | ||
import { | ||
useAccount, | ||
useContractReadErrorLogging, | ||
useReadContracts, | ||
} from 'hooks/web3' | ||
import type { | ||
Address, | ||
ContractFunctionReturnType, | ||
DynamicPoolContractData, | ||
PoolContractAccountCallParams, | ||
} from 'types' | ||
|
||
const getPoolContracts = ({ | ||
account, | ||
chainId, | ||
address, | ||
}: PoolContractAccountCallParams) => | ||
[ | ||
{ | ||
address, | ||
abi: PoolLogicAbi, | ||
functionName: 'balanceOf', | ||
chainId, | ||
args: [account ?? AddressZero], | ||
}, | ||
{ | ||
address, | ||
abi: PoolLogicAbi, | ||
functionName: 'tokenPrice', | ||
chainId, | ||
args: [], | ||
}, | ||
{ | ||
address, | ||
abi: PoolLogicAbi, | ||
functionName: 'getFundSummary', | ||
chainId, | ||
}, | ||
] as const | ||
|
||
type GetFundSummary = ContractFunctionReturnType< | ||
typeof PoolLogicAbi, | ||
'view', | ||
'getFundSummary' | ||
> | ||
|
||
type PoolsMap = Record<Address, DynamicPoolContractData> | ||
|
||
const getContracts = (pools: PoolContractAccountCallParams[]) => | ||
pools.flatMap(getPoolContracts) | ||
|
||
const POOL_CHUNK_SIZE = getPoolContracts({ | ||
account: AddressZero, | ||
chainId: DEFAULT_CHAIN_ID, | ||
address: AddressZero, | ||
}).length | ||
|
||
export const usePoolsDynamic = () => { | ||
const { account = AddressZero } = useAccount() | ||
const pools = useTradingPanelPoolConfigs() | ||
|
||
const result = useReadContracts({ | ||
contracts: getContracts(pools.map((pool) => ({ ...pool, account }))), | ||
query: { | ||
select: (data) => | ||
chunk(data, POOL_CHUNK_SIZE).reduce<PoolsMap>( | ||
(acc, [balanceOf, tokenPrice, getFundSummary], index) => { | ||
const poolAddress = pools?.[index]?.address ?? AddressZero | ||
const summary = getFundSummary?.result as GetFundSummary | ||
|
||
return { | ||
...acc, | ||
[poolAddress]: { | ||
userBalance: balanceOf?.result?.toString(), | ||
tokenPrice: tokenPrice?.result?.toString(), | ||
totalValue: summary?.totalFundValue?.toString(), | ||
totalSupply: summary?.totalSupply?.toString(), | ||
isPrivateVault: summary?.privatePool, | ||
performanceFee: summary?.performanceFeeNumerator?.toString(), | ||
streamingFee: summary?.managerFeeNumerator?.toString(), | ||
entryFee: summary?.entryFeeNumerator?.toString(), | ||
}, | ||
} | ||
}, | ||
{}, | ||
), | ||
}, | ||
}) | ||
|
||
useContractReadErrorLogging({ error: result.error, status: result.status }) | ||
|
||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 1 addition & 6 deletions
7
packages/core-ui-kit/src/hooks/pool/use-invalidate-pool-contract-data.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,14 @@ | ||
import { usePoolDynamic, usePoolManagerDynamic } from './multicall' | ||
import { usePoolManagerDynamic } from './multicall' | ||
import { useTradingPanelPoolConfig } from '../state' | ||
import { useInvalidateOnBlock } from '../web3' | ||
|
||
export const useInvalidatePoolContractData = () => { | ||
const { address, chainId } = useTradingPanelPoolConfig() | ||
const { queryKey: poolDynamicKey } = usePoolDynamic({ | ||
address, | ||
chainId, | ||
}) | ||
|
||
const { queryKey: poolManagerDynamicKey } = usePoolManagerDynamic({ | ||
address, | ||
chainId, | ||
}) | ||
|
||
useInvalidateOnBlock({ queryKey: poolDynamicKey }) | ||
useInvalidateOnBlock({ queryKey: poolManagerDynamicKey }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.