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

feat: aggregate total supply and Omni send payouts #4600

Merged
merged 2 commits into from
Mar 23, 2025
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions src/locales/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -4511,6 +4511,9 @@ msgstr ""
msgid "Project contracts"
msgstr ""

msgid "Chain"
msgstr ""

msgid "Failed to update project metadata"
msgstr ""

Expand Down
10 changes: 6 additions & 4 deletions src/packages/v4/components/ChainSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { t } from '@lingui/macro'
import { ChainLogo } from './ChainLogo'
import { JBChainId } from 'juice-sdk-core'
import { JuiceListbox } from 'components/inputs/JuiceListbox'
import { NETWORKS } from 'constants/networks'
import { JBChainId } from 'juice-sdk-core'
import React from 'react'
import { ChainLogo } from './ChainLogo'
import { t } from '@lingui/macro'

function ChainSelectOption({
chainId,
Expand Down Expand Up @@ -73,7 +73,9 @@ export const ChainSelect = ({
className={className}
value={_value}
onChange={({ value: selectedChainId }) => {
onChange(selectedChainId as JBChainId)
if (selectedChainId) {
onChange(selectedChainId)
}
}}
options={networkOptions}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { DEFAULT_METADATA, NATIVE_TOKEN } from 'juice-sdk-core'
import { DEFAULT_METADATA, NATIVE_TOKEN, readJbDirectoryPrimaryTerminalOf } from 'juice-sdk-core'
import {
JBChainId,
useJBChainId,
useJBContractContext,
useJBRulesetContext,
usePreparePayMetadata,
useWriteJbMultiTerminalPay,
useWriteJbMultiTerminalPay
} from 'juice-sdk-react'
import { useCallback, useContext, useMemo } from 'react'
import { Address, Hash, parseEther } from 'viem'
import { Address, Hash, parseEther, zeroAddress } from 'viem'

import { waitForTransactionReceipt } from '@wagmi/core'
import { TxHistoryContext } from 'contexts/Transaction/TxHistoryContext'
Expand Down Expand Up @@ -128,6 +128,11 @@ export const usePayProjectTx = ({
return
}

const terminalAddress = await readJbDirectoryPrimaryTerminalOf(wagmiConfig, {
chainId,
args: [projectId ?? 0n, NATIVE_TOKEN],
})

const { messageString, attachedUrl } = values.message
const memo = buildPaymentMemo({
text: messageString,
Expand Down Expand Up @@ -158,10 +163,11 @@ export const usePayProjectTx = ({
// functionName: 'pay',
// args,
// })

try {
const hash = await writePay({
chainId,
address: contracts.primaryNativeTerminal.data,
address: terminalAddress ?? zeroAddress,
args,
value: weiAmount,
})
Expand Down
58 changes: 58 additions & 0 deletions src/packages/v4/hooks/usePayoutLimitOfChain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import * as constants from '@ethersproject/constants'

import {
JBChainId,
useJBContractContext,
useJBRuleset,
useReadJbFundAccessLimitsPayoutLimitsOf,
} from 'juice-sdk-react'

import { NATIVE_TOKEN } from 'juice-sdk-core'
import { V4CurrencyOption } from '../models/v4CurrencyOption'
import { V4_CURRENCY_ETH } from '../utils/currency'

/**
* V4todo: add to SDK
*/
export function usePayoutLimitOfChain({
chainId,
projectId,
}: {
chainId: JBChainId | undefined,
projectId: bigint | undefined
}) {
const {
contracts: { primaryNativeTerminal, fundAccessLimits },
} = useJBContractContext()
const { data: ruleset } = useJBRuleset()
const { data: payoutLimits, isLoading } =
useReadJbFundAccessLimitsPayoutLimitsOf({
address: fundAccessLimits.data ?? undefined,
chainId,
args: [
projectId ?? 0n,
BigInt(ruleset?.id ?? 0),
primaryNativeTerminal.data ?? constants.AddressZero, // v4TODO: should be below?
// useReadJbDirectoryPrimaryTerminalOf({
// chainId,
// args: [projectId, NATIVE_TOKEN],
// })
NATIVE_TOKEN,
],
})

const payoutLimit = payoutLimits?.[0]

return {
data: payoutLimit
? {
...payoutLimit,
currency: Number(payoutLimit.currency) as V4CurrencyOption,
}
: {
amount: 0n,
currency: V4_CURRENCY_ETH,
},
isLoading,
}
}
69 changes: 69 additions & 0 deletions src/packages/v4/hooks/useSuckersTotalSupply.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import {
SuckerPair,
readJbControllerTotalTokenSupplyWithReservedTokensOf,
readJbDirectoryControllerOf
} from "juice-sdk-core";
import { useJBChainId, useJBContractContext, useSuckers } from "juice-sdk-react";

import { useConfig } from "wagmi";
import { useQuery } from "wagmi/query";
import { wagmiConfig } from "../wagmiConfig";

export function useSuckersTotalSupply() {
const config = useConfig();

const chainId = useJBChainId();

const { projectId } = useJBContractContext();

const suckersQuery = useSuckers();
const pairs: SuckerPair[] = suckersQuery.data ?? [];

const totalSupplyQuery = useQuery({
queryKey: [
"suckersTotalSupply",
projectId?.toString() || "0",
chainId?.toString() || "0",
pairs?.map(p => p.peerChainId).join(",") || "noPairs",
],
queryFn: async () => {
if (!chainId) return null;
if (!pairs || pairs.length === 0) return [];

return await Promise.all(
pairs.map(async pair => {
const { peerChainId, projectId: peerProjectId } = pair;

const controllerAddress = await readJbDirectoryControllerOf(wagmiConfig, {
chainId,
args: [BigInt(projectId)],
})

const totalSupply = await readJbControllerTotalTokenSupplyWithReservedTokensOf(config, {
chainId: Number(peerChainId),
address: controllerAddress,
args: [peerProjectId],
});

return {
chainId: peerChainId,
projectId: peerProjectId,
totalSupply,
};
})
);
},
});

return {
isLoading: totalSupplyQuery.isLoading || suckersQuery.isLoading,
isError: totalSupplyQuery.isError || suckersQuery.isError,
data: totalSupplyQuery.data as
| {
chainId: number;
projectId: bigint;
totalSupply: bigint;
}[]
| undefined,
};
}
25 changes: 19 additions & 6 deletions src/packages/v4/hooks/useUsedPayoutLimitOf.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
import { NATIVE_CURRENCY_ID, NATIVE_TOKEN } from 'juice-sdk-core'
import {
useJBContractContext,
JBChainId,
useJBRulesetContext,
useJBTerminalContext,
useReadJbTerminalStoreUsedPayoutLimitOf,
useReadJbDirectoryPrimaryTerminalOf,
useReadJbTerminalStoreUsedPayoutLimitOf
} from 'juice-sdk-react'

import { zeroAddress } from 'viem'

export const useUsedPayoutLimitOf = () => {
export const useUsedPayoutLimitOf = ({
chainId,
projectId,
}: {
chainId: JBChainId | undefined,
projectId: bigint | undefined
}) => {
const { store } = useJBTerminalContext()
const { projectId, contracts } = useJBContractContext()
const { ruleset } = useJBRulesetContext()

const { data: terminalAddress } = useReadJbDirectoryPrimaryTerminalOf({
chainId,
args: [projectId ?? 0n, NATIVE_TOKEN],
})

const { data: usedPayoutLimit, isLoading } =
useReadJbTerminalStoreUsedPayoutLimitOf({
address: store.data ?? undefined,
chainId,
args: [
contracts.primaryNativeTerminal.data ?? zeroAddress,
projectId,
terminalAddress ?? zeroAddress,
projectId ?? 0n,
NATIVE_TOKEN,
BigInt(ruleset.data?.cycleNumber ?? 0),
BigInt(NATIVE_CURRENCY_ID),
Expand Down
21 changes: 14 additions & 7 deletions src/packages/v4/hooks/useV4BalanceOfNativeTerminal.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
import { NATIVE_TOKEN } from 'juice-sdk-core';
import {
useJBContractContext,
JBChainId,
useJBTerminalContext,
useReadJbTerminalStoreBalanceOf,
useReadJbDirectoryPrimaryTerminalOf,
useReadJbTerminalStoreBalanceOf
} from 'juice-sdk-react';

import { NATIVE_TOKEN } from 'juice-sdk-core';
import { zeroAddress } from 'viem';

export const useV4BalanceOfNativeTerminal = () => {
export const useV4BalanceOfNativeTerminal = ({ chainId, projectId }: { chainId: JBChainId | undefined, projectId: bigint | undefined }) => {
const { store } = useJBTerminalContext();
const { projectId, contracts } = useJBContractContext();

const { data: terminalAddress } = useReadJbDirectoryPrimaryTerminalOf({
chainId,
args: [projectId ?? 0n, NATIVE_TOKEN],
})

const { data: treasuryBalance, isLoading } = useReadJbTerminalStoreBalanceOf({
address: store.data ?? undefined,
chainId,
args: [
contracts.primaryNativeTerminal.data ?? zeroAddress,
projectId,
terminalAddress ?? zeroAddress,
projectId ?? 0n,
NATIVE_TOKEN,
],
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { Trans, t } from '@lingui/macro'

import { ChainSelect } from 'packages/v4/components/ChainSelect'
import { InformationCircleIcon } from '@heroicons/react/24/outline'
import { currentCycleRemainingLengthTooltip } from 'components/Project/ProjectTabs/CyclesPayoutsTab/CyclesPanelTooltips'
import { UpcomingCycleChangesCallout } from 'components/Project/ProjectTabs/CyclesPayoutsTab/UpcomingCycleChangesCallout'
import { TitleDescriptionDisplayCard } from 'components/Project/ProjectTabs/TitleDescriptionDisplayCard'
import { ProjectChainSelect } from 'packages/v4/components/ProjectDashboard/ProjectChainSelect'
import { RulesetCountdownProvider } from 'packages/v4/contexts/RulesetCountdownProvider'
import { useState } from 'react'
import { TitleDescriptionDisplayCard } from 'components/Project/ProjectTabs/TitleDescriptionDisplayCard'
import { UpcomingCycleChangesCallout } from 'components/Project/ProjectTabs/CyclesPayoutsTab/UpcomingCycleChangesCallout'
import { V4ConfigurationDisplayCard } from './V4ConfigurationDisplayCard'
import { V4PayoutsSubPanel } from './V4PayoutsSubPanel'
import { currentCycleRemainingLengthTooltip } from 'components/Project/ProjectTabs/CyclesPayoutsTab/CyclesPanelTooltips'
import { twMerge } from 'tailwind-merge'
import { useCyclesPanelSelectedChain } from './contexts/CyclesPanelSelectedChainContext'
import { useRulesetCountdown } from '../../hooks/useRulesetCountdown'
import { useState } from 'react'
import { useSuckers } from 'juice-sdk-react'
import { useV4CurrentUpcomingSubPanel } from '../../hooks/useV4CurrentUpcomingSubPanel'
import { useCyclesPanelSelectedChain } from './contexts/CyclesPanelSelectedChainContext'
import { useV4UpcomingRulesetHasChanges } from './hooks/useV4UpcomingRulesetHasChanges'
import { V4ConfigurationDisplayCard } from './V4ConfigurationDisplayCard'
import { V4PayoutsSubPanel } from './V4PayoutsSubPanel'

function CountdownClock({ rulesetUnlocked }: { rulesetUnlocked: boolean }) {
const { timeRemainingText } = useRulesetCountdown()
Expand All @@ -39,6 +40,8 @@ export const V4CurrentUpcomingSubPanel = ({
const { selectedChainId, setSelectedChainId } = useCyclesPanelSelectedChain()
// const { data: rulesetsDiffAcrossChains } = useProjectRulesetsDiffAcrossChains({ rulesetNumber: info.rulesetNumber} )

const { data: suckers} = useSuckers()

const rulesetLengthTooltip =
info.type === 'current' ? currentCycleRemainingLengthTooltip : undefined

Expand Down Expand Up @@ -96,10 +99,13 @@ export const V4CurrentUpcomingSubPanel = ({
<div className="absolute left-44 top-[-6px]">
{selectedChainId ? (
<div className="flex items-center gap-1">
<ProjectChainSelect
value={selectedChainId}
onChange={chainId => setSelectedChainId(chainId)}
/>
{suckers && suckers.length > 1 ? (
<ChainSelect
value={selectedChainId}
onChange={(chainId) => setSelectedChainId(chainId)}
chainIds={suckers.map(s => s.peerChainId)}
/>
): null}
{/* { rulesetsDiffAcrossChains?.length ?
<Tooltip
title={
Expand Down
Loading