Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { styled } from 'styled-components'
import { isAddress } from 'viem'
import { NG_ASSET_TYPE } from '@/dex/components/PageCreatePool/constants'
import {
CategoryDataRow,
SummaryDataTitle,
Expand Down Expand Up @@ -39,28 +40,28 @@ const OracleSummary = ({ chainId }: Props) => {

return (
<OraclesWrapper>
{tokenA.ngAssetType === 1 && tokenA.address !== '' && (
{tokenA.ngAssetType === NG_ASSET_TYPE.ORACLE && tokenA.address !== '' && (
<OracleTokenSummary chainId={chainId} token={tokenA} title={t`Token A`} />
)}
{tokenB.ngAssetType === 1 && tokenB.address !== '' && (
{tokenB.ngAssetType === NG_ASSET_TYPE.ORACLE && tokenB.address !== '' && (
<OracleTokenSummary chainId={chainId} token={tokenB} title={t`Token B`} />
)}
{tokenC.ngAssetType === 1 && tokenC.address !== '' && (
{tokenC.ngAssetType === NG_ASSET_TYPE.ORACLE && tokenC.address !== '' && (
<OracleTokenSummary chainId={chainId} token={tokenC} title={t`Token C`} />
)}
{tokenD.ngAssetType === 1 && tokenD.address !== '' && (
{tokenD.ngAssetType === NG_ASSET_TYPE.ORACLE && tokenD.address !== '' && (
<OracleTokenSummary chainId={chainId} token={tokenD} title={t`Token D`} />
)}
{tokenD.ngAssetType === 1 && tokenE.address !== '' && (
{tokenD.ngAssetType === NG_ASSET_TYPE.ORACLE && tokenE.address !== '' && (
<OracleTokenSummary chainId={chainId} token={tokenE} title={t`Token E`} />
)}
{tokenD.ngAssetType === 1 && tokenF.address !== '' && (
{tokenD.ngAssetType === NG_ASSET_TYPE.ORACLE && tokenF.address !== '' && (
<OracleTokenSummary chainId={chainId} token={tokenF} title={t`Token F`} />
)}
{tokenD.ngAssetType === 1 && tokenG.address !== '' && (
{tokenD.ngAssetType === NG_ASSET_TYPE.ORACLE && tokenG.address !== '' && (
<OracleTokenSummary chainId={chainId} token={tokenG} title={t`Token G`} />
)}
{tokenD.ngAssetType === 1 && tokenH.address !== '' && (
{tokenD.ngAssetType === NG_ASSET_TYPE.ORACLE && tokenH.address !== '' && (
<OracleTokenSummary chainId={chainId} token={tokenH} title={t`Token H`} />
)}
</OraclesWrapper>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { styled } from 'styled-components'
import { STABLESWAP } from '@/dex/components/PageCreatePool/constants'
import {
STABLESWAP,
TOKEN_A,
TOKEN_B,
TOKEN_C,
Expand All @@ -9,6 +9,7 @@ import {
TOKEN_F,
TOKEN_G,
TOKEN_H,
NG_ASSET_TYPE,
} from '@/dex/components/PageCreatePool/constants'
import OracleSummary from '@/dex/components/PageCreatePool/Summary/OracleSummary'
import {
Expand Down Expand Up @@ -208,10 +209,10 @@ const TokenSummary = ({ blockchainId, token, chainId, swapType }: TokenSummary)
</TokenSymbol>
{swapType === STABLESWAP && network.stableswapFactory && (
<TokenType>
{token.ngAssetType === 0 && t`Standard`}
{token.ngAssetType === 1 && t`Oracle`}
{token.ngAssetType === 2 && t`Rebasing`}
{token.ngAssetType === 3 && t`ERC4626`}
{token.ngAssetType === NG_ASSET_TYPE.STANDARD && t`Standard`}
{token.ngAssetType === NG_ASSET_TYPE.ORACLE && t`Oracle`}
{token.ngAssetType === NG_ASSET_TYPE.REBASING && t`Rebasing`}
{token.ngAssetType === NG_ASSET_TYPE.ERC4626 && t`ERC4626`}
</TokenType>
)}
</Box>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Key } from 'react'
import { styled } from 'styled-components'
import { type Address } from 'viem'
import {
STABLESWAP,
CRYPTOSWAP,
Expand All @@ -11,7 +12,9 @@ import {
TOKEN_F,
TOKEN_G,
TOKEN_H,
NG_ASSET_TYPE,
} from '@/dex/components/PageCreatePool/constants'
import { useAutoDetectErc4626 } from '@/dex/components/PageCreatePool/hooks/useAutoDetectErc4626'
import {
CreateToken,
TokenState,
Expand All @@ -27,6 +30,7 @@ import Button from '@ui/Button'
import Checkbox from '@ui/Checkbox'
import Icon from '@ui/Icon'
import { t } from '@ui-kit/lib/i18n'
import WarningBox from '../components/WarningBox'
import SelectTokenButton from './SelectTokenButton'

type Props = {
Expand Down Expand Up @@ -59,6 +63,10 @@ const SelectToken = ({
const clearToken = useStore((state) => state.createPool.clearToken)
const tokensInPool = useStore((state) => state.createPool.tokensInPool)
const { data: network } = useNetworkByChain({ chainId })
void useAutoDetectErc4626({
tokenId,
address: token.address as Address,
})

const getTokenName = (tokenId: TokenId) => {
if (tokenId === TOKEN_D) return t`Token D`
Expand Down Expand Up @@ -116,28 +124,31 @@ const SelectToken = ({
onSelectionChange={(value: Key) => handleInpChange(tokenId, value as string, tokensInPool)}
/>
{swapType === STABLESWAP && (network.stableswapFactory || network.stableswapFactoryOld) && !token.basePool && (
<StableSwapTogglesRow>
<StyledCheckbox
isSelected={token.ngAssetType === 0}
onChange={() => updateNgAssetType(tokenId, 0)}
isDisabled={false}
>{t`Standard`}</StyledCheckbox>
<StyledCheckbox
isSelected={token.ngAssetType === 1}
isDisabled={false}
onChange={() => updateNgAssetType(tokenId, 1)}
>{t`Oracle`}</StyledCheckbox>
<StyledCheckbox
isSelected={token.ngAssetType === 2}
onChange={() => updateNgAssetType(tokenId, 2)}
isDisabled={false}
>{t`Rebasing`}</StyledCheckbox>
<StyledCheckbox
isSelected={token.ngAssetType === 3}
isDisabled={false}
onChange={() => updateNgAssetType(tokenId, 3)}
>{t`ERC4626`}</StyledCheckbox>
</StableSwapTogglesRow>
<>
<StableSwapTogglesRow>
<StyledCheckbox
isSelected={token.ngAssetType === NG_ASSET_TYPE.STANDARD}
onChange={() => updateNgAssetType(tokenId, NG_ASSET_TYPE.STANDARD)}
>{t`Standard`}</StyledCheckbox>
<StyledCheckbox
isSelected={token.ngAssetType === NG_ASSET_TYPE.ORACLE}
onChange={() => updateNgAssetType(tokenId, NG_ASSET_TYPE.ORACLE)}
>{t`Oracle`}</StyledCheckbox>
<StyledCheckbox
isSelected={token.ngAssetType === NG_ASSET_TYPE.REBASING}
onChange={() => updateNgAssetType(tokenId, NG_ASSET_TYPE.REBASING)}
>{t`Rebasing`}</StyledCheckbox>
<StyledCheckbox
isSelected={token.ngAssetType === NG_ASSET_TYPE.ERC4626}
onChange={() => updateNgAssetType(tokenId, NG_ASSET_TYPE.ERC4626)}
>{t`ERC4626`}</StyledCheckbox>
</StableSwapTogglesRow>
{token.erc4626.isErc4626 && token.ngAssetType !== NG_ASSET_TYPE.ERC4626 && (
<WarningBox
message={t`${token.symbol} is identified as an ERC4626 token, please select ERC4626 as the asset type.`}
/>
)}
</>
)}
</TokenPickerContainer>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
TOKEN_F,
TOKEN_G,
TOKEN_H,
NG_ASSET_TYPE,
} from '@/dex/components/PageCreatePool/constants'
import type { TokenState, TokenId } from '@/dex/components/PageCreatePool/types'
import { validateOracleFunction } from '@/dex/components/PageCreatePool/utils'
Expand All @@ -26,41 +27,24 @@ type OracleInputProps = {
}

const SetOracle = () => {
const tokenA = useStore((state) => state.createPool.tokensInPool.tokenA)
const tokenB = useStore((state) => state.createPool.tokensInPool.tokenB)
const tokenC = useStore((state) => state.createPool.tokensInPool.tokenC)
const tokenD = useStore((state) => state.createPool.tokensInPool.tokenD)
const tokenE = useStore((state) => state.createPool.tokensInPool.tokenE)
const tokenF = useStore((state) => state.createPool.tokensInPool.tokenF)
const tokenG = useStore((state) => state.createPool.tokensInPool.tokenG)
const tokenH = useStore((state) => state.createPool.tokensInPool.tokenH)
const tokens = useStore((state) => state.createPool.tokensInPool)

const oracleTokens: { token: TokenState; tokenId: TokenId; title: string }[] = [
{ token: tokens.tokenA, tokenId: TOKEN_A as TokenId, title: t`Token A` },
{ token: tokens.tokenB, tokenId: TOKEN_B as TokenId, title: t`Token B` },
{ token: tokens.tokenC, tokenId: TOKEN_C as TokenId, title: t`Token C` },
{ token: tokens.tokenD, tokenId: TOKEN_D as TokenId, title: t`Token D` },
{ token: tokens.tokenE, tokenId: TOKEN_E as TokenId, title: t`Token E` },
{ token: tokens.tokenF, tokenId: TOKEN_F as TokenId, title: t`Token F` },
{ token: tokens.tokenG, tokenId: TOKEN_G as TokenId, title: t`Token G` },
{ token: tokens.tokenH, tokenId: TOKEN_H as TokenId, title: t`Token H` },
].filter(({ token }) => token.ngAssetType === NG_ASSET_TYPE.ORACLE && token.address !== '')

return (
<OracleWrapper>
{tokenA.ngAssetType === 1 && tokenA.address !== '' && (
<OracleInputs token={tokenA} tokenId={TOKEN_A} title={t`Token A`} />
)}
{tokenB.ngAssetType === 1 && tokenB.address !== '' && (
<OracleInputs token={tokenB} tokenId={TOKEN_B} title={t`Token B`} />
)}
{tokenC.ngAssetType === 1 && tokenC.address !== '' && (
<OracleInputs token={tokenC} tokenId={TOKEN_C} title={t`Token C`} />
)}
{tokenD.ngAssetType === 1 && tokenD.address !== '' && (
<OracleInputs token={tokenD} tokenId={TOKEN_D} title={t`Token D`} />
)}
{tokenD.ngAssetType === 1 && tokenD.address !== '' && (
<OracleInputs token={tokenE} tokenId={TOKEN_E} title={t`Token E`} />
)}
{tokenD.ngAssetType === 1 && tokenD.address !== '' && (
<OracleInputs token={tokenF} tokenId={TOKEN_F} title={t`Token F`} />
)}
{tokenD.ngAssetType === 1 && tokenD.address !== '' && (
<OracleInputs token={tokenG} tokenId={TOKEN_G} title={t`Token G`} />
)}
{tokenD.ngAssetType === 1 && tokenD.address !== '' && (
<OracleInputs token={tokenH} tokenId={TOKEN_H} title={t`Token H`} />
)}
{oracleTokens.map(({ token, tokenId, title }) => (
<OracleInputs key={tokenId} token={token} tokenId={tokenId} title={title} />
))}
</OracleWrapper>
)
}
Expand Down
40 changes: 25 additions & 15 deletions apps/main/src/dex/components/PageCreatePool/TokensInPool/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ import {
TOKEN_G,
TOKEN_H,
FXSWAP,
NG_ASSET_TYPE,
} from '@/dex/components/PageCreatePool/constants'
import SelectToken from '@/dex/components/PageCreatePool/TokensInPool/SelectToken'
import SetOracle from '@/dex/components/PageCreatePool/TokensInPool/SetOracle'
import { CreateToken, TokenId, TokensInPoolState } from '@/dex/components/PageCreatePool/types'
import { checkMetaPool, containsOracle, getBasepoolCoins } from '@/dex/components/PageCreatePool/utils'
import { useNetworkByChain } from '@/dex/entities/networks'
import useTokensMapper from '@/dex/hooks/useTokensMapper'
import { DEFAULT_CREATE_POOL_STATE } from '@/dex/store/createCreatePoolSlice'
import { DEFAULT_CREATE_POOL_STATE, DEFAULT_ERC4626_STATUS } from '@/dex/store/createCreatePoolSlice'
import useStore from '@/dex/store/useStore'
import { CurveApi, ChainId, BasePool } from '@/dex/types/main.types'
import Box from '@ui/Box'
Expand All @@ -47,11 +48,11 @@ const TokensInPool = ({ curve, chainId, haveSigner }: Props) => {
const updateTokensInPool = useStore((state) => state.createPool.updateTokensInPool)
const updateTokenAmount = useStore((state) => state.createPool.updateTokenAmount)
const updateSwapType = useStore((state) => state.createPool.updateSwapType)
const updateNgAssetType = useStore((state) => state.createPool.updateNgAssetType)
const basePools = useStore((state) => state.pools.basePools[chainId]) ?? DEFAULT_POOLS
const userBalances = useStore((state) => state.userBalances.userBalancesMapper)
const { tokensMapper } = useTokensMapper(chainId)
const nativeToken = curve.getNetworkConstants().NATIVE_TOKEN

const {
data: { createDisabledTokens, stableswapFactory, tricryptoFactory, twocryptoFactory },
} = useNetworkByChain({ chainId })
Expand Down Expand Up @@ -99,7 +100,15 @@ const TokensInPool = ({ curve, chainId, haveSigner }: Props) => {

const handleInpChange = useCallback(
(name: TokenId, value: string, tokensInPoolState: TokensInPoolState) => {
if (!value.startsWith('0x')) return
const normalizedValue = value.toLowerCase()

if (!normalizedValue.startsWith('0x')) return
const previousAddress = tokensInPoolState[name].address.toLowerCase()

if (normalizedValue === previousAddress) return

// reset the ngAssetType to Standard by default
updateNgAssetType(name, NG_ASSET_TYPE.STANDARD)

const basePoolCoins: string[] = getBasepoolCoins(
value,
Expand Down Expand Up @@ -144,7 +153,7 @@ const TokensInPool = ({ curve, chainId, haveSigner }: Props) => {
...updatedFormValues,
[TOKEN_A]: {
...updatedFormValues[TOKEN_A],
ngAssetType: 0,
ngAssetType: NG_ASSET_TYPE.STANDARD,
address: value,
basePool: true,
},
Expand All @@ -163,7 +172,7 @@ const TokensInPool = ({ curve, chainId, haveSigner }: Props) => {
...updatedFormValues,
[TOKEN_A]: {
...updatedFormValues[TOKEN_A],
ngAssetType: 0,
ngAssetType: NG_ASSET_TYPE.STANDARD,
symbol: findSymbol(value),
address: value,
basePool: true,
Expand Down Expand Up @@ -217,7 +226,7 @@ const TokensInPool = ({ curve, chainId, haveSigner }: Props) => {
...updatedFormValues,
[TOKEN_B]: {
...updatedFormValues[TOKEN_B],
ngAssetType: 0,
ngAssetType: NG_ASSET_TYPE.STANDARD,
address: value,
symbol: findSymbol(value),
basePool: true,
Expand All @@ -237,7 +246,7 @@ const TokensInPool = ({ curve, chainId, haveSigner }: Props) => {
...updatedFormValues,
[TOKEN_B]: {
...updatedFormValues[TOKEN_B],
ngAssetType: 0,
ngAssetType: NG_ASSET_TYPE.STANDARD,
address: value,
symbol: findSymbol(value),
basePool: true,
Expand Down Expand Up @@ -291,7 +300,7 @@ const TokensInPool = ({ curve, chainId, haveSigner }: Props) => {
...updatedFormValues,
[TOKEN_A]: {
...updatedFormValues[TOKEN_A],
ngAssetType: 0,
ngAssetType: NG_ASSET_TYPE.STANDARD,
address: value,
symbol: findSymbol(value),
basePool: true,
Expand Down Expand Up @@ -327,7 +336,7 @@ const TokensInPool = ({ curve, chainId, haveSigner }: Props) => {
...updatedFormValues,
[TOKEN_A]: {
...updatedFormValues[TOKEN_A],
ngAssetType: 0,
ngAssetType: NG_ASSET_TYPE.STANDARD,
address: value,
symbol: findSymbol(value),
basePool: true,
Expand Down Expand Up @@ -363,7 +372,7 @@ const TokensInPool = ({ curve, chainId, haveSigner }: Props) => {
...updatedFormValues,
[TOKEN_A]: {
...updatedFormValues[TOKEN_A],
ngAssetType: 0,
ngAssetType: NG_ASSET_TYPE.STANDARD,
address: value,
symbol: findSymbol(value),
basePool: true,
Expand Down Expand Up @@ -399,7 +408,7 @@ const TokensInPool = ({ curve, chainId, haveSigner }: Props) => {
...updatedFormValues,
[TOKEN_A]: {
...updatedFormValues[TOKEN_A],
ngAssetType: 0,
ngAssetType: NG_ASSET_TYPE.STANDARD,
address: value,
symbol: findSymbol(value),
basePool: true,
Expand Down Expand Up @@ -435,7 +444,7 @@ const TokensInPool = ({ curve, chainId, haveSigner }: Props) => {
...updatedFormValues,
[TOKEN_A]: {
...updatedFormValues[TOKEN_A],
ngAssetType: 0,
ngAssetType: NG_ASSET_TYPE.STANDARD,
address: value,
symbol: findSymbol(value),
basePool: true,
Expand Down Expand Up @@ -471,7 +480,7 @@ const TokensInPool = ({ curve, chainId, haveSigner }: Props) => {
...updatedFormValues,
[TOKEN_A]: {
...updatedFormValues[TOKEN_A],
ngAssetType: 0,
ngAssetType: NG_ASSET_TYPE.STANDARD,
address: value,
symbol: findSymbol(value),
basePool: true,
Expand Down Expand Up @@ -512,7 +521,7 @@ const TokensInPool = ({ curve, chainId, haveSigner }: Props) => {
updatedFormValues[TOKEN_H],
)
},
[tokensInPool, updateTokensInPool, curve, findSymbol, swapType, basePools],
[tokensInPool, updateTokensInPool, curve, findSymbol, swapType, basePools, updateNgAssetType],
)

const addToken = useCallback(() => {
Expand All @@ -538,9 +547,10 @@ const TokensInPool = ({ curve, chainId, haveSigner }: Props) => {
...tokensInPoolState[token],
address: tokenId === token ? '' : tokensInPoolState[token].address,
symbol: tokenId === token ? '' : tokensInPoolState[token].symbol,
ngAssetType: tokenId === token ? 0 : tokensInPoolState[token].ngAssetType,
ngAssetType: tokenId === token ? NG_ASSET_TYPE.STANDARD : tokensInPoolState[token].ngAssetType,
oracleAddress: tokenId === token ? '' : tokensInPoolState[token].oracleAddress,
oracleFunction: tokenId === token ? '' : tokensInPoolState[token].oracleFunction,
erc4626: tokenId === token ? { ...DEFAULT_ERC4626_STATUS } : tokensInPoolState[token].erc4626,
})

updateTokensInPool(
Expand Down
Loading