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(wallet-dashboard): determine max ptb for unlock/unwrap and unstake timelocked objects #5165

Merged
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
4f85c45
feat: add max tx byte size to migration tx
brancoder Jan 29, 2025
e04f3f5
fix: add reduction step constant
brancoder Jan 30, 2025
7da32e7
fix: change reduction step size
brancoder Jan 30, 2025
fd0c379
Merge branch 'develop' into tooling-dashboard/add-partial-migration
brancoder Jan 30, 2025
6a1f4b7
fix: resolve conflicts
brancoder Jan 31, 2025
b836a5b
fix: catch max size bytes error
brancoder Jan 31, 2025
37ccc3c
feat: add changeset
brancoder Jan 31, 2025
7060428
Merge branch 'develop' into tooling-dashboard/add-partial-migration
brancoder Jan 31, 2025
7a94600
feat: add useMaxTransactionSizeBytes hook
brancoder Jan 31, 2025
abe1354
fix: move max size bytes error message to hook
brancoder Jan 31, 2025
d14dd21
fix: code improvements
brancoder Feb 3, 2025
2a6be57
Merge branch 'develop' into tooling-dashboard/add-partial-migration
brancoder Feb 3, 2025
fa37e12
feat(dashboard): determine max ptb for unstake timelocked objects.
panteleymonchuk Feb 3, 2025
f59bbdb
feat: refactor unlock timelocked objects transaction and improve supp…
panteleymonchuk Feb 3, 2025
ddb0236
feat: enhance unlock timelocked objects transaction handling with dyn…
panteleymonchuk Feb 3, 2025
5d3c933
feat: implement optimal limit search for unlocking timelocked objects…
panteleymonchuk Feb 3, 2025
6e006ae
fix: add catch for SizeLimitExceeded error code
brancoder Feb 4, 2025
90508ec
Merge branch 'develop' into tooling-dashboard/add-partial-migration
brancoder Feb 4, 2025
2a8a1d3
feat: improve transaction handling for unstaking timelocked objects w…
panteleymonchuk Feb 4, 2025
001544f
Merge remote-tracking branch 'origin/tooling-dashboard/add-partial-mi…
panteleymonchuk Feb 4, 2025
2444022
refactor: remove low high for unlock timelock objects
panteleymonchuk Feb 4, 2025
5d0d140
feat: enhance vesting dashboard with supply increase unlocked max siz…
panteleymonchuk Feb 4, 2025
321f34e
feat: implement partial unstake handling for size limit errors in tim…
panteleymonchuk Feb 4, 2025
a6932f1
Merge branch 'develop' into tooling-dashboard/handle-max-unstake-time…
cpl121 Feb 4, 2025
30d57b5
feat: refactor unstake handling to use state for reduction size and i…
panteleymonchuk Feb 4, 2025
68a357c
refactor: standardize variable naming for maximum transaction size in…
panteleymonchuk Feb 4, 2025
a4af9fb
fix: remove redundant argument in transaction build calls for unlock …
panteleymonchuk Feb 4, 2025
9e86230
Merge remote-tracking branch 'origin/develop' into tooling-dashboard/…
panteleymonchuk Feb 5, 2025
86ed299
refactor(wallet-dashboard): Replace SIZE_LIMIT_EXCEEDED checks with i…
panteleymonchuk Feb 5, 2025
b00f98c
refactor(dashboard): Introduce isUnlockPending state and update butto…
panteleymonchuk Feb 5, 2025
004fa50
Merge remote-tracking branch 'origin/develop' into tooling-dashboard/…
panteleymonchuk Feb 5, 2025
513d26b
fix(dashboard): reset max transaction size error after successful tra…
panteleymonchuk Feb 5, 2025
bcf820e
Merge branch 'develop' into tooling-dashboard/handle-max-unstake-time…
cpl121 Feb 5, 2025
62db252
feat(wallet-dashboard): add resetMaxTransactionSize function to manag…
panteleymonchuk Feb 5, 2025
04e1c2d
refactor(utils): rename isSizeExceedError to isSizeExceededError for …
panteleymonchuk Feb 5, 2025
aff8035
chore(wallet-dashboard): rename dashboard title
begonaalvarezd Feb 5, 2025
0e43732
fix(wallet-dashboard): update enabled conditions to ensure proper han…
panteleymonchuk Feb 5, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@
import { useIotaClient } from '@iota/dapp-kit';
import { createUnlockTimelockedObjectsTransaction } from '../utils';
import { useQuery } from '@tanstack/react-query';
import { useMaxTransactionSizeBytes } from './useMaxTransactionSizeBytes';

export function useUnlockTimelockedObjectsTransaction(address: string, objectIds: string[]) {
const client = useIotaClient();
const { data: maxSizeBytes = Infinity } = useMaxTransactionSizeBytes();

return useQuery({
// eslint-disable-next-line @tanstack/query/exhaustive-deps
queryKey: ['unlock-timelocked-objects', address, objectIds],
queryFn: async () => {
const transaction = createUnlockTimelockedObjectsTransaction({ address, objectIds });
transaction.setSender(address);
await transaction.build({ client });
await transaction.build({ client, maxSizeBytes });
return transaction;
},
enabled: !!address && !!objectIds,
Expand Down
32 changes: 30 additions & 2 deletions apps/wallet-dashboard/app/(protected)/vesting/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ import {
LoadingIndicator,
LabelText,
LabelTextSize,
InfoBox,
InfoBoxStyle,
InfoBoxType,
} from '@iota/apps-ui-kit';
import {
Theme,
Expand All @@ -52,7 +55,7 @@ import {
} from '@iota/dapp-kit';
import { IotaValidatorSummary } from '@iota/iota-sdk/client';
import { IOTA_TYPE_ARG } from '@iota/iota-sdk/utils';
import { Calendar, StarHex } from '@iota/apps-ui-icons';
import { Calendar, StarHex, Warning } from '@iota/apps-ui-icons';
import { useRouter } from 'next/navigation';
import { useEffect, useState } from 'react';
import { StakedTimelockObject } from '@/components';
Expand Down Expand Up @@ -90,6 +93,10 @@ export default function VestingDashboardPage(): JSX.Element {
refreshStakeList,
isSupplyIncreaseVestingScheduleEmpty,
supplyIncreaseVestingMapped,
isMaxTransactionSizeError,
supplyIncreaseVestingUnlockedMaxSize,
isUnlockPending,
resetMaxTransactionSize,
} = useGetSupplyIncreaseVestingObjects(address);

const timelockedStakedObjectsGrouped: TimelockedStakedObjectsGrouped[] =
Expand Down Expand Up @@ -159,6 +166,11 @@ export default function VestingDashboardPage(): JSX.Element {
IOTA_TYPE_ARG,
);

const [
formattedSupplyIncreaseVestingUnlockedMaxSize,
supplyIncreaseVestingUnlockedMaxSizeSymbol,
] = useFormatCoin(supplyIncreaseVestingUnlockedMaxSize, IOTA_TYPE_ARG);

function handleOnSuccess(digest: string): void {
setTimelockedObjectsToUnstake(null);

Expand All @@ -182,6 +194,10 @@ export default function VestingDashboardPage(): JSX.Element {
onSuccess: (tx) => {
handleOnSuccess(tx.digest);
ampli.timelockCollect();

if (isMaxTransactionSizeError) {
resetMaxTransactionSize();
}
},
},
)
Expand Down Expand Up @@ -261,12 +277,24 @@ export default function VestingDashboardPage(): JSX.Element {
onClick={handleCollect}
title="Collect"
buttonType={ButtonType.Primary}
iconAfterText={isUnlockPending}
icon={isUnlockPending ? <LoadingIndicator /> : null}
buttonDisabled={
!supplyIncreaseVestingSchedule.availableClaiming ||
supplyIncreaseVestingSchedule.availableClaiming === 0n
supplyIncreaseVestingSchedule.availableClaiming === 0n ||
isUnlockPending
}
/>
</Card>
{isMaxTransactionSizeError ? (
<InfoBox
title="Partial collect"
supportingText={`Due to the large number of objects, a partial collect will be attempted for ${formattedSupplyIncreaseVestingUnlockedMaxSize} ${supplyIncreaseVestingUnlockedMaxSizeSymbol}. After the operation is complete, you can collect the remaining value.`}
style={InfoBoxStyle.Elevated}
type={InfoBoxType.Error}
icon={<Warning />}
/>
) : null}
<Card type={CardType.Outlined}>
<CardImage
type={ImageType.BgSolid}
Expand Down
2 changes: 1 addition & 1 deletion apps/wallet-dashboard/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function HomeDashboardPage(): JSX.Element {
<div className="flex flex-col items-center gap-4">
<span className="text-headline-sm text-neutral-40">Welcome to</span>
<h1 className="text-display-lg text-neutral-10 dark:text-neutral-100">
IOTA Wallet
IOTA Wallet Dashboard
</h1>
<span className="text-title-lg text-neutral-40">
Connecting you to the decentralized web and IOTA network
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { TransactionDialogView } from '../TransactionDialog';
import { MigrationDialogView } from './enums';
import { ConfirmMigrationView } from './views';
import { ampli } from '@/lib/utils/analytics';
import { SIZE_LIMIT_EXCEEDED } from '@iota/core';
import { isSizeExceededError } from '@/lib/utils';

// Number of objects to reduce on every attempt
const REDUCTION_STEP_SIZE = 25;
Expand Down Expand Up @@ -53,7 +53,7 @@ export function MigrationDialog({
useSignAndExecuteTransaction();

useEffect(() => {
if (isMigrationError && error?.message.includes(SIZE_LIMIT_EXCEEDED)) {
if (isMigrationError && isSizeExceededError(error)) {
reductionSize.current += REDUCTION_STEP_SIZE;
setBasicOutputs(basicOutputObjects.slice(0, -reductionSize.current));
setNftOutputs(nftOutputObjects.slice(0, -reductionSize.current));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import {
useGetActiveValidatorsInfo,
useTimeAgo,
} from '@iota/core';
import { ExtendedDelegatedTimelockedStake, TimelockedStakedObjectsGrouped } from '@/lib/utils';
import {
ExtendedDelegatedTimelockedStake,
TimelockedStakedObjectsGrouped,
isSizeExceededError,
} from '@/lib/utils';
import { formatAddress, IOTA_TYPE_ARG } from '@iota/iota-sdk/utils';
import {
Panel,
Expand All @@ -21,11 +25,16 @@ import {
Header,
ButtonType,
Button,
InfoBox,
InfoBoxStyle,
InfoBoxType,
} from '@iota/apps-ui-kit';
import { useCurrentAccount, useSignAndExecuteTransaction } from '@iota/dapp-kit';
import { IotaSignAndExecuteTransactionOutput } from '@iota/wallet-standard';
import toast from 'react-hot-toast';
import { ampli } from '@/lib/utils/analytics';
import { Warning } from '@iota/apps-ui-icons';
import { useEffect, useRef, useState } from 'react';

interface UnstakeTimelockedObjectsViewProps {
onClose: () => void;
Expand All @@ -34,22 +43,35 @@ interface UnstakeTimelockedObjectsViewProps {
onBack?: () => void;
}

const REDUCTION_STEP_SIZE = 5;

export function UnstakeTimelockedObjectsView({
groupedTimelockedObjects,
onClose,
onBack,
onSuccess,
}: UnstakeTimelockedObjectsViewProps) {
const reductionSize = useRef(0);
const [isMaxTransactionSizeError, setIsMaxTransactionSizeError] = useState(false);
panteleymonchuk marked this conversation as resolved.
Show resolved Hide resolved
const activeAddress = useCurrentAccount()?.address ?? '';
const { data: activeValidators } = useGetActiveValidatorsInfo();

const stakes = groupedTimelockedObjects.stakes;
const stakes = (() => {
if (isMaxTransactionSizeError) {
return groupedTimelockedObjects.stakes.slice(0, -reductionSize.current);
}
return groupedTimelockedObjects.stakes;
})();

const timelockedStakedIotaIds = stakes.map((stake) => stake.timelockedStakedIotaId);

const { data: unstakeData, isPending: isUnstakeTxPending } = useNewUnstakeTimelockedTransaction(
activeAddress,
timelockedStakedIotaIds,
);
const {
data: unstakeData,
isPending: isUnstakeTxPending,
isError: isUnstakeError,
error: unstakeError,
} = useNewUnstakeTimelockedTransaction(activeAddress, timelockedStakedIotaIds);

const { mutateAsync: signAndExecuteTransaction, isPending: isTransactionPending } =
useSignAndExecuteTransaction();

Expand All @@ -58,13 +80,19 @@ export function UnstakeTimelockedObjectsView({
validatorAddress === groupedTimelockedObjects.validatorAddress,
);

const stakeId = stakes[0].timelockedStakedIotaId;
const totalStakedAmount = stakes.reduce((acc, stake) => acc + parseInt(stake.principal), 0);
const stakeId = stakes[0]?.timelockedStakedIotaId;
const totalStakedAmount = stakes.reduce((acc, stake) => acc + BigInt(stake.principal), 0n);

const totalRewards = stakes.reduce(
(acc, stake) => acc + (stake.status === 'Active' ? parseInt(stake.estimatedReward) : 0),
0,
);

const [totalStakedAmountFormatted, totalStakedAmountSymbol] = useFormatCoin(
totalStakedAmount,
IOTA_TYPE_ARG,
);

const [rewardsPoolFormatted, rewardsToken] = useFormatCoin(
validatorInfo?.rewardsPool,
IOTA_TYPE_ARG,
Expand Down Expand Up @@ -95,6 +123,14 @@ export function UnstakeTimelockedObjectsView({
});
}

useEffect(() => {
if (isUnstakeError && isSizeExceededError(unstakeError)) {
setIsMaxTransactionSizeError(true);
reductionSize.current += REDUCTION_STEP_SIZE;
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isUnstakeError, unstakeError]);

return (
<DialogLayout>
<Header title="Unstake" onClose={onClose} onBack={onBack} />
Expand Down Expand Up @@ -151,6 +187,17 @@ export function UnstakeTimelockedObjectsView({
</div>
</DialogLayoutBody>
<DialogLayoutFooter>
{isMaxTransactionSizeError ? (
<div className="mb-2">
<InfoBox
title="Partial unstake"
supportingText={`Due to the large number of objects, a partial unstake of ${totalStakedAmountFormatted} ${totalStakedAmountSymbol} will be attempted. After the operation is complete, you can unstake the remaining value.`}
style={InfoBoxStyle.Elevated}
type={InfoBoxType.Error}
icon={<Warning />}
/>
</div>
) : null}
<Button
onClick={handleUnstake}
text="Unstake"
Expand Down
panteleymonchuk marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
formatDelegatedTimelockedStake,
getLatestOrEarliestSupplyIncreaseVestingPayout,
getVestingOverview,
isSizeExceededError,
isSupplyIncreaseVestingObject,
isTimelockedUnlockable,
mapTimelockObjects,
Expand All @@ -25,6 +26,9 @@ import {
useUnlockTimelockedObjectsTransaction,
} from '@iota/core';
import { Transaction } from '@iota/iota-sdk/transactions';
import { useEffect, useState } from 'react';

const REDUCTION_STEP_SIZE = 5;

interface SupplyIncreaseVestingObject {
nextPayout: SupplyIncreaseVestingPayout | undefined;
Expand All @@ -41,9 +45,16 @@ interface SupplyIncreaseVestingObject {
| undefined;
refreshStakeList: () => void;
isSupplyIncreaseVestingScheduleEmpty: boolean;
isMaxTransactionSizeError: boolean;
supplyIncreaseVestingUnlockedMaxSize: bigint;
isUnlockPending: boolean;
resetMaxTransactionSize: () => void;
}

export function useGetSupplyIncreaseVestingObjects(address: string): SupplyIncreaseVestingObject {
const [reductionSize, setReductionSize] = useState(0);
const [isMaxTransactionSizeError, setIsMaxTransactionSizeError] = useState(false);

const { data: currentEpochMs } = useGetCurrentEpochStartTimestamp();

const { data: timelockedObjects, refetch: refetchGetAllOwnedObjects } = useGetAllOwnedObjects(
Expand Down Expand Up @@ -85,13 +96,32 @@ export function useGetSupplyIncreaseVestingObjects(address: string): SupplyIncre
const supplyIncreaseVestingPortfolio =
lastPayout && buildSupplyIncreaseVestingSchedule(lastPayout, Number(currentEpochMs));

const supplyIncreaseVestingUnlocked = supplyIncreaseVestingMapped?.filter(
(supplyIncreaseVestingObject) =>
const supplyIncreaseVestingUnlocked = (() => {
let filtered = supplyIncreaseVestingMapped?.filter((supplyIncreaseVestingObject) =>
isTimelockedUnlockable(supplyIncreaseVestingObject, Number(currentEpochMs)),
);
);

if (isMaxTransactionSizeError) {
filtered = filtered.slice(0, -reductionSize);
}

return filtered;
})();

const supplyIncreaseVestingUnlockedObjectIds: string[] =
supplyIncreaseVestingUnlocked.map((unlockedObject) => unlockedObject.id.id) || [];
const { data: unlockAllSupplyIncreaseVesting } = useUnlockTimelockedObjectsTransaction(

const supplyIncreaseVestingUnlockedMaxSize = supplyIncreaseVestingUnlocked.reduce(
(acc, curr) => (acc += curr.locked.value),
0n,
);

const {
data: unlockAllSupplyIncreaseVesting,
isPending: isUnlockPending,
isError: isUnlockError,
error: unlockError,
} = useUnlockTimelockedObjectsTransaction(
address || '',
supplyIncreaseVestingUnlockedObjectIds,
);
Expand All @@ -108,6 +138,19 @@ export function useGetSupplyIncreaseVestingObjects(address: string): SupplyIncre
refetchGetAllOwnedObjects();
}

function resetMaxTransactionSize() {
setIsMaxTransactionSizeError(false);
setReductionSize(0);
}

useEffect(() => {
if (isUnlockError && isSizeExceededError(unlockError)) {
setIsMaxTransactionSizeError(true);
setReductionSize((prev) => prev + REDUCTION_STEP_SIZE);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isUnlockError, unlockError]);

return {
nextPayout,
lastPayout,
Expand All @@ -119,5 +162,9 @@ export function useGetSupplyIncreaseVestingObjects(address: string): SupplyIncre
unlockAllSupplyIncreaseVesting,
refreshStakeList,
isSupplyIncreaseVestingScheduleEmpty,
isMaxTransactionSizeError,
supplyIncreaseVestingUnlockedMaxSize,
isUnlockPending,
resetMaxTransactionSize,
};
}
9 changes: 7 additions & 2 deletions apps/wallet-dashboard/hooks/useNewUnstakeTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import { createTimelockedUnstakeTransaction, createUnstakeTransaction } from '@iota/core';
import {
createTimelockedUnstakeTransaction,
createUnstakeTransaction,
useMaxTransactionSizeBytes,
} from '@iota/core';
import { useIotaClient } from '@iota/dapp-kit';
import { useQuery } from '@tanstack/react-query';

Expand Down Expand Up @@ -33,14 +37,15 @@ export function useNewUnstakeTimelockedTransaction(
timelockedUnstakeIotaIds: string[],
) {
const client = useIotaClient();
const { data: maxSizeBytes = Infinity } = useMaxTransactionSizeBytes();

return useQuery({
// eslint-disable-next-line @tanstack/query/exhaustive-deps
queryKey: ['timelocked-unstake-transaction', timelockedUnstakeIotaIds, senderAddress],
queryFn: async () => {
const transaction = createTimelockedUnstakeTransaction(timelockedUnstakeIotaIds);
transaction.setSender(senderAddress);
await transaction.build({ client });
await transaction.build({ client, maxSizeBytes: maxSizeBytes });
begonaalvarezd marked this conversation as resolved.
Show resolved Hide resolved
return transaction;
},
enabled: !!(senderAddress && timelockedUnstakeIotaIds?.length),
Expand Down
1 change: 1 addition & 0 deletions apps/wallet-dashboard/lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from './timelock';
export * from './migration';
export * from './transaction';
export * from './growthbook';
export * from './isSizeExceededError';
8 changes: 8 additions & 0 deletions apps/wallet-dashboard/lib/utils/isSizeExceededError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import { SIZE_LIMIT_EXCEEDED } from '@iota/core';

export function isSizeExceededError(e: Error | null) {
return e?.message?.includes(SIZE_LIMIT_EXCEEDED);
}
Loading