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

Limit pool symbol length #36

Merged
merged 1 commit into from
Jan 25, 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: 2 additions & 1 deletion packages/nextjs/app/v3/_components/ChooseInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PoolType } from "@balancer/sdk";
import { ArrowTopRightOnSquareIcon } from "@heroicons/react/24/outline";
import { Alert, TextField } from "~~/components/common";
import { useBoostableWhitelist, useCheckIfV3PoolExists, usePoolCreationStore, useUserDataStore } from "~~/hooks/v3";
import { MAX_POOL_NAME_LENGTH } from "~~/utils/constants";
import { MAX_POOL_NAME_LENGTH, MAX_POOL_SYMBOL_LENGTH } from "~~/utils/constants";

/**
* @dev Gauge creation reverts if the name is longer than 32 characters
Expand Down Expand Up @@ -60,6 +60,7 @@ export const ChooseInfo = () => {
label="Pool symbol"
placeholder="Enter pool symbol"
value={symbol}
maxLength={MAX_POOL_SYMBOL_LENGTH}
onChange={e => {
updatePool({ symbol: e.target.value.trim() });
updateUserData({ hasEditedPoolSymbol: true });
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/components/common/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const TextField: React.FC<TextFieldProps> = ({
if (!isValidAddress) return "Invalid address";
if (isRateProvider && !isValidRateProvider) return "Invalid rate provider";
if (isPoolHooksContract && !isValidPoolHooksContract) return "Invalid pool hooks contract";
if (maxLength && !isValidLength) return `Pool name is too long: ${value?.length ?? 0}/${maxLength}`;
if (maxLength && !isValidLength) return `Too many characters: ${value?.length ?? 0}/${maxLength}`;
return null;
};

Expand Down
5 changes: 3 additions & 2 deletions packages/nextjs/hooks/v3/useValidatePoolCreationInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { PoolType, TokenType } from "@balancer/sdk";
import { isAddress, parseUnits } from "viem";
import { useWalletClient } from "wagmi";
import { usePoolCreationStore, useUserDataStore, useValidateHooksContract, useValidateNetwork } from "~~/hooks/v3";
import { MAX_POOL_NAME_LENGTH } from "~~/utils/constants";
import { MAX_POOL_NAME_LENGTH, MAX_POOL_SYMBOL_LENGTH } from "~~/utils/constants";

export function useValidatePoolCreationInput() {
const { isWrongNetwork } = useValidateNetwork();
Expand Down Expand Up @@ -76,7 +76,8 @@ export function useValidatePoolCreationInput() {
!isUsingHooks || isValidPoolHooksContract,
].every(Boolean);

const isInfoValid = !!name && !!symbol && name.length <= MAX_POOL_NAME_LENGTH;
const isInfoValid =
!!name && !!symbol && name.length <= MAX_POOL_NAME_LENGTH && symbol.length <= MAX_POOL_SYMBOL_LENGTH;

const isPoolCreationInputValid = isTypeValid && isTokensValid && isParametersValid && isInfoValid;

Expand Down
2 changes: 2 additions & 0 deletions packages/nextjs/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ export const COW_MIN_AMOUNT = BigInt(1e6);

/**
* @dev Gauge creation reverts if the name is longer than 32 characters
* @dev Gauge creation reverts if the symbol is longer than 26 characters (Franz said so)
* https://github.com/balancer/pool-creator/issues/17#issuecomment-2430158673
*/
export const MAX_POOL_NAME_LENGTH = 32;
export const MAX_POOL_SYMBOL_LENGTH = 26;
Loading