diff --git a/apps/hub/src/app/pools/components/parameters-input.tsx b/apps/hub/src/app/pools/components/parameters-input.tsx index 44b19a844..ab631eefd 100644 --- a/apps/hub/src/app/pools/components/parameters-input.tsx +++ b/apps/hub/src/app/pools/components/parameters-input.tsx @@ -14,8 +14,8 @@ import { InputWithLabel } from "@bera/ui/input"; import { PoolType } from "@berachain-foundation/berancer-sdk"; import { Address } from "viem"; +import { ParameterPreset } from "~/utils/constants"; import BeraTooltip from "~/components/bera-tooltip"; -import { ParameterPreset } from "../create/CreatePageContent"; import { AmplificationInput } from "./amplification-parameter"; import { SwapFeeInput } from "./swap-fee"; diff --git a/apps/hub/src/app/pools/create/CreatePageContent.tsx b/apps/hub/src/app/pools/create/CreatePageContent.tsx index cfebfbd55..f757e269d 100755 --- a/apps/hub/src/app/pools/create/CreatePageContent.tsx +++ b/apps/hub/src/app/pools/create/CreatePageContent.tsx @@ -19,7 +19,6 @@ import { type Token, type TokenInput as TokenInputType, } from "@bera/berajs"; -import { getTokenCurrentPrices } from "@bera/berajs/actions"; import { balancerDelegatedOwnershipAddress, balancerVaultAddress, @@ -47,6 +46,24 @@ import { import { Address, decodeEventLog, isAddress, zeroAddress } from "viem"; import { usePublicClient } from "wagmi"; +import { + DEFAULT_ALGORITHMIC_AMPLIFICATION, + DEFAULT_AMPLIFICATION, + DEFAULT_LIQUIDITY, + DEFAULT_ORACLES, + DEFAULT_OWNER, + DEFAULT_OWNERSHIP_TYPE, + DEFAULT_PARAMETER_PRESET, + DEFAULT_POOL_TYPE, + DEFAULT_TOKENS, + DEFAULT_USD_BACKED_AMPLIFICATION, + DEFAULT_WEIGHTS, + LAST_FORM_STEP_NUM, + ParameterPreset, + emptyOracle, + emptyToken, + emptyTokenInput, +} from "~/utils/constants"; import { isBera, isBeratoken } from "~/utils/isBeraToken"; import { usePoolWeights } from "~/b-sdk/usePoolWeights"; import useMultipleTokenApprovalsWithSlippage from "~/hooks/useMultipleTokenApprovalsWithSlippage"; @@ -59,112 +76,6 @@ import PoolTypeSelector from "../components/pool-type-selector"; import ProcessSteps, { VerifiedSteps } from "../components/process-steps"; import { getPoolUrl } from "../fetchPools"; -export enum ParameterPreset { - USDBACKED = "USD-Backed Stablecoin", - ALGORITHMIC = "Algorithmic Stablecoin", -} - -/** - * Default pool amplification factor (responsiveness to price fluctuations) for USD-backed stablecoins. - * @constant {number} - */ -const DEFAULT_USD_BACKED_AMPLIFICATION = 2500; - -/** - * Default pool amplification factor (responsiveness to price fluctuations) for algorithmic stablecoins. - * @constant {number} - */ -const DEFAULT_ALGORITHMIC_AMPLIFICATION = 200; - -/** - * Default pool type for pools is a composable stable pool, which can be referred to as a 'stable pool'. - * @constant {PoolType} - */ -const DEFAULT_POOL_TYPE = PoolType.ComposableStable; - -/** - * Default amplification factor for pools is a higher value for USD-backed stablecoin pools (max 5k). - * @constant {number} - */ -const DEFAULT_AMPLIFICATION = DEFAULT_USD_BACKED_AMPLIFICATION; - -/** - * Default owner for pools is fixed type, which is the 0x0 address. - * @constant {Address} - */ -const DEFAULT_OWNER = ZERO_ADDRESS; - -/** - * Default ownership type for pools is Fixed which yields the 0x0 owner address. - * @constant {OwnershipType} - */ -const DEFAULT_OWNERSHIP_TYPE = OwnershipType.Fixed; - -/** - * Default weights for pools is an event split since we default to two tokens. - * @constant {bigint[]} - */ -const DEFAULT_WEIGHTS = [500000000000000000n, 500000000000000000n]; - -/** - * Default parameter preset for pools is USD-backed stablecoin preset. - * @constant {ParameterPreset} - */ -const DEFAULT_PARAMETER_PRESET = ParameterPreset.USDBACKED; - -/** - * Last form step number. - * @constant {number} - */ -const LAST_FORM_STEP_NUM = 4; // NOTE: in the future we might consider making this more dynamic/strongly typed via enums. - -const emptyTokenInput: TokenInputType = { - address: "" as `0x${string}`, - amount: "0", - decimals: 18, - exceeding: false, - name: "", - symbol: "", -}; -const emptyToken: Token = { - address: "" as `0x${string}`, - decimals: 18, - name: "", - symbol: "", -}; - -/** - * Default tokens for pools is two empty tokens. - * NOTE: if in the future we streamline the token selection process, we might consider tying this closer to TokenInputs - * @constant {Token[]} - */ -const DEFAULT_TOKENS = [emptyToken, emptyToken]; - -/** - * Default liquidity for pools is two empty tokens. - * @constant {TokenInputType[]} - */ -const DEFAULT_LIQUIDITY = [emptyTokenInput, emptyTokenInput]; - -/** - * If a rate provider (oracle) is provided, this is the default update interval in seconds (using block.timestamp internally). - * @constant {number} - */ -const DEFAULT_ORACLE_CACHE_DURATION = 100; - -const emptyOracle: Oracle = { - mode: OracleMode.None, - address: ZERO_ADDRESS, - tokenAddress: "", - cacheDuration: DEFAULT_ORACLE_CACHE_DURATION, // NOTE: even if we dont use an oracle, we pass a safe value for this to pool create -}; - -/** - * Default oracles for pools is two empty oracles. - * @constant {Oracle[]} - */ -const DEFAULT_ORACLES: Oracle[] = [emptyOracle, emptyOracle]; - export default function CreatePageContent() { const router = useRouter(); const { captureException, track } = useAnalytics(); @@ -254,6 +165,7 @@ export default function CreatePageContent() { return null; } + // @ts-ignore return event.args.poolId ?? null; } catch (error) { console.error(error); diff --git a/apps/hub/src/utils/constants.ts b/apps/hub/src/utils/constants.ts index b7319f46d..5e132dd58 100755 --- a/apps/hub/src/utils/constants.ts +++ b/apps/hub/src/utils/constants.ts @@ -1,3 +1,13 @@ +import { + Oracle, + OracleMode, + type Token, + type TokenInput as TokenInputType, +} from "@bera/berajs"; +import { PoolType, ZERO_ADDRESS } from "@berachain-foundation/berancer-sdk"; + +import { OwnershipType } from "~/app/pools/components/parameters-input"; + export enum LOCAL_STORAGE_KEYS { CONNECTOR_ID = "CONNECTOR_ID", SLIPPAGE_TOLERANCE = "SLIPPAGE_TOLERANCE", @@ -194,3 +204,109 @@ export enum POLLING { NORMAL = 20000, SLOW = 200000, } + +export enum ParameterPreset { + USDBACKED = "USD-Backed Stablecoin", + ALGORITHMIC = "Algorithmic Stablecoin", +} + +/** + * Default pool amplification factor (responsiveness to price fluctuations) for USD-backed stablecoins. + * @constant {number} + */ +export const DEFAULT_USD_BACKED_AMPLIFICATION = 2500; + +/** + * Default pool amplification factor (responsiveness to price fluctuations) for algorithmic stablecoins. + * @constant {number} + */ +export const DEFAULT_ALGORITHMIC_AMPLIFICATION = 200; + +/** + * Default pool type for pools is a composable stable pool, which can be referred to as a 'stable pool'. + * @constant {PoolType} + */ +export const DEFAULT_POOL_TYPE = PoolType.ComposableStable; + +/** + * Default amplification factor for pools is a higher value for USD-backed stablecoin pools (max 5k). + * @constant {number} + */ +export const DEFAULT_AMPLIFICATION = DEFAULT_USD_BACKED_AMPLIFICATION; + +/** + * Default owner for pools is fixed type, which is the 0x0 address. + * @constant {Address} + */ +export const DEFAULT_OWNER = ZERO_ADDRESS; + +/** + * Default ownership type for pools is Fixed which yields the 0x0 owner address. + * @constant {OwnershipType} + */ +export const DEFAULT_OWNERSHIP_TYPE = OwnershipType.Fixed; + +/** + * Default weights for pools is an event split since we default to two tokens. + * @constant {bigint[]} + */ +export const DEFAULT_WEIGHTS = [500000000000000000n, 500000000000000000n]; + +/** + * Default parameter preset for pools is USD-backed stablecoin preset. + * @constant {ParameterPreset} + */ +export const DEFAULT_PARAMETER_PRESET = ParameterPreset.USDBACKED; + +/** + * Last form step number. + * @constant {number} + */ +export const LAST_FORM_STEP_NUM = 4; // NOTE: in the future we might consider making this more dynamic/strongly typed via enums. + +export const emptyTokenInput: TokenInputType = { + address: "" as `0x${string}`, + amount: "0", + decimals: 18, + exceeding: false, + name: "", + symbol: "", +}; +export const emptyToken: Token = { + address: "" as `0x${string}`, + decimals: 18, + name: "", + symbol: "", +}; + +/** + * Default tokens for pools is two empty tokens. + * NOTE: if in the future we streamline the token selection process, we might consider tying this closer to TokenInputs + * @constant {Token[]} + */ +export const DEFAULT_TOKENS = [emptyToken, emptyToken]; + +/** + * Default liquidity for pools is two empty tokens. + * @constant {TokenInputType[]} + */ +export const DEFAULT_LIQUIDITY = [emptyTokenInput, emptyTokenInput]; + +/** + * If a rate provider (oracle) is provided, this is the default update interval in seconds (using block.timestamp internally). + * @constant {number} + */ +export const DEFAULT_ORACLE_CACHE_DURATION = 100; + +export const emptyOracle: Oracle = { + mode: OracleMode.None, + address: ZERO_ADDRESS, + tokenAddress: "", + cacheDuration: DEFAULT_ORACLE_CACHE_DURATION, // NOTE: even if we dont use an oracle, we pass a safe value for this to pool create +}; + +/** + * Default oracles for pools is two empty oracles. + * @constant {Oracle[]} + */ +export const DEFAULT_ORACLES: Oracle[] = [emptyOracle, emptyOracle];