Skip to content

Commit

Permalink
Merge pull request #36 from balancer/limit-pool-symbol-length
Browse files Browse the repository at this point in the history
Limit pool symbol length
  • Loading branch information
MattPereira authored Jan 25, 2025
2 parents d84be27 + 64ff75c commit ba45aa1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
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;

0 comments on commit ba45aa1

Please sign in to comment.