From 732e1f3cc68635355b985dad43126ef81b2d2c2c Mon Sep 17 00:00:00 2001 From: worrex <68468180+worrex@users.noreply.github.com> Date: Wed, 18 Dec 2024 21:22:24 +0100 Subject: [PATCH 1/6] added migrtion page --- components/AssetInput/WhaleInput.tsx | 8 +- components/Navbar/Navbar.tsx | 25 +++ components/Pages/Trade/Migrate/Migrate.tsx | 216 +++++++++++++++++++++ components/Pages/Trade/Migrate/index.ts | 1 + pages/terra/pools/migrate/index.tsx | 5 + 5 files changed, 250 insertions(+), 5 deletions(-) create mode 100644 components/Pages/Trade/Migrate/Migrate.tsx create mode 100644 components/Pages/Trade/Migrate/index.ts create mode 100644 pages/terra/pools/migrate/index.tsx diff --git a/components/AssetInput/WhaleInput.tsx b/components/AssetInput/WhaleInput.tsx index 6f708ed6..7e078d1a 100644 --- a/components/AssetInput/WhaleInput.tsx +++ b/components/AssetInput/WhaleInput.tsx @@ -126,11 +126,9 @@ ref) => { onChange={({ target }) => { onChange({ ...token, - amount: amountInputValidation( - target.value, - tokenInfo?.decimals - ), - }); + amount: amountInputValidation(target.value, + tokenInfo?.decimals), + }) }} /> diff --git a/components/Navbar/Navbar.tsx b/components/Navbar/Navbar.tsx index db15f8bd..ddbbdbad 100644 --- a/components/Navbar/Navbar.tsx +++ b/components/Navbar/Navbar.tsx @@ -10,6 +10,7 @@ import { IconButton, VStack, useDisclosure, + Text, } from '@chakra-ui/react' import BurgerIcon from 'components/Icons/BurgerIcon' import { ACTIVE_BONDING_NETWORKS, ChainId } from 'constants/index' @@ -24,12 +25,15 @@ import luncMenuLinks from './LUNCNavMenu.json' import NavbarPopper from './NavbarPopper' import bondingDisabledMenuLinks from './NavBondingDisabledMenu.json' import menuLinks from './NavMenu.json' +import { InfoIcon } from '@chakra-ui/icons' +import { useRouter } from 'next/router' const Navbar = () => { const { chainId, chainName } = useRecoilValue(chainState) const { isOpen, onOpen, onClose } = useDisclosure() const currentChainName = chainName + const router = useRouter() const links = [ { @@ -132,6 +136,27 @@ const Navbar = () => { Open + {/* Announcement Banner */} + {chainId === 'phoenix-1' && router.push('/terra/pools/migrate')} + borderRadius='md' + marginTop={5} + > + + + Attention: We’re migrating pools. Click here to learn more and proceed. + + + } diff --git a/components/Pages/Trade/Migrate/Migrate.tsx b/components/Pages/Trade/Migrate/Migrate.tsx new file mode 100644 index 00000000..c5197c6d --- /dev/null +++ b/components/Pages/Trade/Migrate/Migrate.tsx @@ -0,0 +1,216 @@ +import { useEffect, useMemo, useState } from 'react' + +import { + VStack, + Text, + useMediaQuery, + Heading, + Box, + Divider, +} from '@chakra-ui/react' +import { Button } from '@chakra-ui/react' // Ensure you import Button if not already +import { useChain } from '@cosmos-kit/react-lite' +import DepositForm from 'components/Pages/Trade/Liquidity/DepositForm' +import useProvideLP from 'components/Pages/Trade/Liquidity/hooks/useProvideLP' +import { usePoolsListQuery } from 'components/Pages/Trade/Pools/hooks/usePoolsListQuery' +import { + PoolEntityTypeWithLiquidity, + useQueryPoolsLiquidity, +} from 'components/Pages/Trade/Pools/hooks/useQueryPoolsLiquidity' +import { useClients } from 'hooks/useClients' +import { useQueriesDataSelector } from 'hooks/useQueriesDataSelector' +import { useTokenList } from 'hooks/useTokenList' +import { useRecoilState, useRecoilValue } from 'recoil' +import { chainState } from 'state/chainState' +import { tokenItemState } from 'state/tokenItemState' +import { TokenItemState, TxStep } from 'types/index' +import { getDecimals } from 'util/conversion/index' + +const Migrate = () => { + const { walletChainName } = useRecoilValue(chainState) + const { isWalletConnected, address } = useChain(walletChainName) + const [isMobile] = useMediaQuery('(max-width: 720px)') + + // Mock states and values for demonstration + const [oldPoolLiquidity, setOldPoolLiquidity] = useState(500) // Hardcoded for demonstration + const [hasWithdrawn, setHasWithdrawn] = useState(false) + const [hasDeposited, setHasDeposited] = useState(false) + + // States required for DepositForm: + const [reverse, setReverse] = useState(false) + const clearForm = () => {} + const chainId = 'phoenix-1' + const openView = () => {} + const incentivesEnabled = true + + const { data: poolData } = usePoolsListQuery() + const { cosmWasmClient } = useClients(walletChainName) + + const [pools]: readonly [PoolEntityTypeWithLiquidity[], boolean, boolean] = + useQueriesDataSelector(useQueryPoolsLiquidity({ + refetchInBackground: false, + pools: poolData?.pools, + cosmWasmClient, + })) + + const pool = useMemo(() => pools?.find((p) => p.pool_id === 'USDC-USDt'), [pools]) + const [tokenList] = useTokenList() + const [isTokenSet, setIsToken] = useState(false) + + const [[tokenA, tokenB], setTokenItemState] = useRecoilState(tokenItemState) + + useEffect(() => { + if (pool?.pool_id) { + const [tokenASymbol, tokenBSymbol] = pool?.pool_id?.split('-') || [] + setTokenItemState([ + { + tokenSymbol: tokenASymbol, + amount: 0, + decimals: getDecimals(tokenASymbol, tokenList), + }, + { + tokenSymbol: tokenBSymbol, + amount: 0, + decimals: getDecimals(tokenBSymbol, tokenList), + }, + ]) + setIsToken(true) + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [pool]) + + const [bondingDays, setBondingDays] = useState(0) + const { simulated, tx } = useProvideLP({ + reverse, + bondingDays, + }) + + const onInputChange = ({ tokenSymbol, amount }: any, index: number) => { + if (tx?.txStep === TxStep.Failed || tx?.txStep === TxStep.Success) { + tx.reset() + } + + const newState: [TokenItemState?, TokenItemState?] = [tokenA, tokenB] + newState[index] = { + ...newState.find((item) => item?.tokenSymbol === tokenSymbol), + tokenSymbol, + amount: Number(amount), + } + setTokenItemState(newState) + } + + // Example button usage snippet: + const PrimaryButton = ({ + label, + onClick, + isLoading = false, + isDisabled = false, + }: { + label: string + onClick?: () => void + isLoading?: boolean + isDisabled?: boolean + }) => ( + + ) + + return ( + + + + + Migrate Liquidity to New USDC/USDT Pool + + + + + {/* Step 1 */} + + Step 1: Check Old Pool Liquidity + {oldPoolLiquidity !== null && oldPoolLiquidity > 0 ? ( + You have {oldPoolLiquidity} LP tokens in the old USDC/USDT XYK pool. + ) : ( + You have no liquidity in the old pool. + )} + + + + + {/* Step 2 */} + + Step 2: Withdraw Liquidity + Withdraw all liquidity from the old XYK pool before migrating. + setHasWithdrawn(true)} + /> + + + + + {/* Step 3 */} + + Step 3: Deposit into the New StableSwap Pool + Now deposit your USDC and USDT into the new StableSwap pool. + + + + + + {/* Step 4 */} + + Step 4: Vote with Your Liquidity + Your new liquidity is now deposited in the StableSwap pool. + Proceed to Eris Protocol to use your liquidity for voting and other governance actions. + + + + + + ) +} + +export default Migrate diff --git a/components/Pages/Trade/Migrate/index.ts b/components/Pages/Trade/Migrate/index.ts new file mode 100644 index 00000000..79e34dd1 --- /dev/null +++ b/components/Pages/Trade/Migrate/index.ts @@ -0,0 +1 @@ +export { default } from 'components/Pages/Trade/Migrate/Migrate' diff --git a/pages/terra/pools/migrate/index.tsx b/pages/terra/pools/migrate/index.tsx new file mode 100644 index 00000000..98703d88 --- /dev/null +++ b/pages/terra/pools/migrate/index.tsx @@ -0,0 +1,5 @@ +import Migrate from 'components/Pages/Trade/Migrate/index' + +const MigratePage = () => + +export default MigratePage From b70c0a4036ddd565fe3af753bdf6952588e8f3f7 Mon Sep 17 00:00:00 2001 From: worrex <68468180+worrex@users.noreply.github.com> Date: Fri, 20 Dec 2024 15:33:43 +0100 Subject: [PATCH 2/6] added withdrawal and liq check --- components/Pages/Trade/Migrate/Migrate.tsx | 42 ++- .../Pages/Trade/Migrate/hooks/deposit.ts | 61 +++++ .../Trade/Migrate/hooks/useFetchStaked.ts | 37 +++ .../Trade/Migrate/hooks/useMigrateTx.tsx | 254 ++++++++++++++++++ .../Pages/Trade/Migrate/hooks/withdraw.ts | 44 +++ 5 files changed, 416 insertions(+), 22 deletions(-) create mode 100644 components/Pages/Trade/Migrate/hooks/deposit.ts create mode 100644 components/Pages/Trade/Migrate/hooks/useFetchStaked.ts create mode 100644 components/Pages/Trade/Migrate/hooks/useMigrateTx.tsx create mode 100644 components/Pages/Trade/Migrate/hooks/withdraw.ts diff --git a/components/Pages/Trade/Migrate/Migrate.tsx b/components/Pages/Trade/Migrate/Migrate.tsx index c5197c6d..88290059 100644 --- a/components/Pages/Trade/Migrate/Migrate.tsx +++ b/components/Pages/Trade/Migrate/Migrate.tsx @@ -1,17 +1,11 @@ import { useEffect, useMemo, useState } from 'react' -import { - VStack, - Text, - useMediaQuery, - Heading, - Box, - Divider, -} from '@chakra-ui/react' -import { Button } from '@chakra-ui/react' // Ensure you import Button if not already +import { Box, Button, Divider, Heading, Text, useMediaQuery, VStack } from '@chakra-ui/react' // Ensure you import Button if not already import { useChain } from '@cosmos-kit/react-lite' import DepositForm from 'components/Pages/Trade/Liquidity/DepositForm' import useProvideLP from 'components/Pages/Trade/Liquidity/hooks/useProvideLP' +import { useFetchStaked } from 'components/Pages/Trade/Migrate/hooks/useFetchStaked' +import useMigrateTx, { MigrateAction } from 'components/Pages/Trade/Migrate/hooks/useMigrateTx' import { usePoolsListQuery } from 'components/Pages/Trade/Pools/hooks/usePoolsListQuery' import { PoolEntityTypeWithLiquidity, @@ -28,20 +22,17 @@ import { getDecimals } from 'util/conversion/index' const Migrate = () => { const { walletChainName } = useRecoilValue(chainState) - const { isWalletConnected, address } = useChain(walletChainName) + const { isWalletConnected, address, openView } = useChain(walletChainName) const [isMobile] = useMediaQuery('(max-width: 720px)') - - // Mock states and values for demonstration - const [oldPoolLiquidity, setOldPoolLiquidity] = useState(500) // Hardcoded for demonstration - const [hasWithdrawn, setHasWithdrawn] = useState(false) - const [hasDeposited, setHasDeposited] = useState(false) + const data = useFetchStaked(address) + const { submit } = useMigrateTx() + const isAmpLp = useMemo(() => data?.denom.includes('amplp'), [data]) + const amount = useMemo(() => Number(data?.amount ?? 0) * (10 ** -6), [data]) // States required for DepositForm: const [reverse, setReverse] = useState(false) const clearForm = () => {} const chainId = 'phoenix-1' - const openView = () => {} - const incentivesEnabled = true const { data: poolData } = usePoolsListQuery() const { cosmWasmClient } = useClients(walletChainName) @@ -144,9 +135,13 @@ const Migrate = () => { {/* Step 1 */} Step 1: Check Old Pool Liquidity - {oldPoolLiquidity !== null && oldPoolLiquidity > 0 ? ( - You have {oldPoolLiquidity} LP tokens in the old USDC/USDT XYK pool. - ) : ( + { isAmpLp && amount > 0 && ( + You have {amount.toFixed(6)} ampLP tokens in the old USDC/USDT XYK pool. + )} + {!isAmpLp && amount > 0 && ( + You have {amount.toFixed(6)} LP tokens in the old USDC/USDT XYK pool. + )} + {Number(data?.amount ?? 0) === 0 && ( You have no liquidity in the old pool. )} @@ -158,8 +153,11 @@ const Migrate = () => { Step 2: Withdraw Liquidity Withdraw all liquidity from the old XYK pool before migrating. setHasWithdrawn(true)} + isDisabled={!(isWalletConnected && (amount > 0)) } + label={isWalletConnected && (amount > 0) ? 'Withdraw' : 'Nothing to withdraw'} + onClick={() => submit( + MigrateAction.Withdraw, amount, data.denom, + )} /> diff --git a/components/Pages/Trade/Migrate/hooks/deposit.ts b/components/Pages/Trade/Migrate/hooks/deposit.ts new file mode 100644 index 00000000..4ece7183 --- /dev/null +++ b/components/Pages/Trade/Migrate/hooks/deposit.ts @@ -0,0 +1,61 @@ +import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' +import { ADV_MEMO } from 'constants/index' +import { createGasFee } from 'services/treasuryService' +import { createExecuteMessage } from 'util/messages/createExecuteMessage' + +export const deposit: any = async ( + signingClient: SigningCosmWasmClient, + address: string, + denom: string, + amount: number, +) => { + const ampLpPostMessage = { + liquid_stake: { + compounder: 'terra1zly98gvcec54m3caxlqexce7rus6rzgplz7eketsdz7nh750h2rqvu8uzx', + receiver: null, + gauge: 'bluechip', + }, + } + const lpPostMessage = { + stake: { + asset_staking: 'terra14mmvqn0kthw6sre75vku263lafn5655mkjdejqjedjga4cw0qx2qlf4arv', + receiver: null, + }, + } + + const handleMsg1 = { + create_lp: { + min_received: '6307', + assets: [ + { + native: 'ibc/2C962DAB9F57FE0921435426AE75196009FAA1981BF86991203C8411F8980FDB', + }, + { + native: 'ibc/9B19062D46CAB50361CE9B0A3E6D0A7A53AC9E7CB361F32A73CC733144A9A9E5', + }, + ], + stage: { + white_whale: { + pair: 'terra17vas9rhxhc6j6f5wrup9cqapxn74jvpft069py7l7l9kr7wx3tnsxrazux', + }, + }, + post_action: { + stake: { + asset_staking: 'terra14mmvqn0kthw6sre75vku263lafn5655mkjdejqjedjga4cw0qx2qlf4arv', + receiver: null, + }, + }, + }, + } + + const execMsg = createExecuteMessage({ senderAddress: address, + contractAddress: 'terra1zly98gvcec54m3caxlqexce7rus6rzgplz7eketsdz7nh750h2rqvu8uzx', + message: handleMsg1, + funds: [{ amount: Math.ceil(amount).toString(), + denom }] }) + return await signingClient.signAndBroadcast( + address, [execMsg], await createGasFee( + signingClient, address, [execMsg], + ), ADV_MEMO, + ) +} diff --git a/components/Pages/Trade/Migrate/hooks/useFetchStaked.ts b/components/Pages/Trade/Migrate/hooks/useFetchStaked.ts new file mode 100644 index 00000000..8d931c51 --- /dev/null +++ b/components/Pages/Trade/Migrate/hooks/useFetchStaked.ts @@ -0,0 +1,37 @@ +import { useQuery } from 'react-query' + +import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' +import { WalletChainName } from 'constants/index' +import { useClients } from 'hooks/useClients' + +const fetchStaked = async (client: CosmWasmClient, + address: string) => { + const lpToken = await client.getBalance(address, 'factory/terra17vas9rhxhc6j6f5wrup9cqapxn74jvpft069py7l7l9kr7wx3tnsxrazux/uLP') + const ampLpToken = await client.getBalance(address, 'factory/terra1zly98gvcec54m3caxlqexce7rus6rzgplz7eketsdz7nh750h2rqvu8uzx/7/bluechip/amplp') + + /* + * Const result: JsonObject = await client.queryContractSmart('terra14mmvqn0kthw6sre75vku263lafn5655mkjdejqjedjga4cw0qx2qlf4arv', + * { + * staked_balance: { + * address, + * asset: { + * native: 'factory/terra17vas9rhxhc6j6f5wrup9cqapxn74jvpft069py7l7l9kr7wx3tnsxrazux/uLP', + * }, + * }, + * }) + */ + return Number(lpToken.amount) > 0 ? lpToken : ampLpToken +} +export const useFetchStaked = (address: string): {amount: string, denom: string } => { + const { cosmWasmClient } = useClients(WalletChainName.terra) + const { data } = useQuery({ + queryKey: ['fetchStaked', address], + queryFn: () => fetchStaked(cosmWasmClient, address), + enabled: Boolean(cosmWasmClient) && Boolean(address), + staleTime: 30_000, // 30 seconds + cacheTime: 1 * 60 * 1_000, // 5 minutes + }); + + // Ensure the hook always returns an object with defaults + return data +} diff --git a/components/Pages/Trade/Migrate/hooks/useMigrateTx.tsx b/components/Pages/Trade/Migrate/hooks/useMigrateTx.tsx new file mode 100644 index 00000000..0e7f4fd4 --- /dev/null +++ b/components/Pages/Trade/Migrate/hooks/useMigrateTx.tsx @@ -0,0 +1,254 @@ +import { useCallback, useEffect, useMemo, useState } from 'react' +import { useMutation, useQuery } from 'react-query' + +import { useToast } from '@chakra-ui/react' +import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' +import { useChain } from '@cosmos-kit/react-lite' +import Finder from 'components/Finder' +import { deposit } from 'components/Pages/Trade/Migrate/hooks/deposit' +import { withdraw } from 'components/Pages/Trade/Migrate/hooks/withdraw' +import { useClients } from 'hooks/useClients' +import { useRecoilValue } from 'recoil' +import { chainState } from 'state/chainState' +import { TxStep } from 'types/index' + +export enum MigrateAction { Withdraw, Deposit } +export const useMigrateTx = () => { + const toast = useToast() + const { chainId, walletChainName } = useRecoilValue(chainState) + const { address } = useChain(walletChainName) + const { signingClient } = useClients(walletChainName) + const [txStep, setTxStep] = useState(TxStep.Idle) + const [migrateAction, setMigrateAction] = useState(null) + const [txHash, setTxHash] = useState(null) + const [error, setError] = useState(null) + const [buttonLabel, setButtonLabel] = useState(null) + + const { data: fee } = useQuery( + ['fee', error], + () => { + setError(null) + setTxStep(TxStep.Estimating) + try { + const response = 0 // Await client.simulate(senderAddress, debouncedMsgs, '') + if (buttonLabel) { + setButtonLabel(null) + } + setTxStep(TxStep.Ready) + return response + } catch (error) { + if ( + (/insufficient funds/u).test(error.toString()) || + (/Overflow: Cannot Sub with/u).test(error.toString()) + ) { + console.error(error.toString()) + setTxStep(TxStep.Idle) + setError('Insufficient Funds') + setButtonLabel('Insufficient Funds') + throw new Error('Insufficient Funds') + } else if ((/account sequence mismatch/u).test(error?.toString())) { + setError('You have pending transaction') + setButtonLabel('You have pending transaction') + throw new Error('You have pending transaction') + } else { + console.error(error.toString()) + setTxStep(TxStep.Idle) + setError(error?.message) + throw Error(error?.message) + /* + * SetTxStep(TxStep.Idle) + * setError("Failed to execute transaction.") + * throw Error("Failed to execute transaction.") + */ + } + } + }, + { + enabled: txStep === TxStep.Idle && !error && Boolean(signingClient), + refetchOnWindowFocus: false, + retry: false, + staleTime: 0, + onSuccess: () => { + setTxStep(TxStep.Ready) + }, + onError: () => { + setTxStep(TxStep.Idle) + }, + }, + ) + + const { mutate } = useMutation(async (data: { signingClient: SigningCosmWasmClient, migrateAction: MigrateAction, address: string, denom: string, amount: number }) => { + console.log({ data }) + if (data.migrateAction === MigrateAction.Withdraw) { + return withdraw( + signingClient, address, data.denom, (data.amount * (10 ** 6)), + ) + } else { + return deposit( + signingClient, address, data.denom, (data.amount * (10 ** 6)), + ) + } + }, + { + onMutate: () => { + setTxStep(TxStep.Posting) + }, + onError: (e) => { + let message: any = '' + console.error(e?.toString()) + setTxStep(TxStep.Failed) + if ( + (/insufficient funds/u).test(e?.toString()) || + (/Overflow: Cannot Sub with/u).test(e?.toString()) + ) { + setError('Insufficient Funds') + message = 'Insufficient Funds' + } else if ((/Request rejected/u).test(e?.toString())) { + setError('User Denied') + message = 'User Denied' + } else if ((/account sequence mismatch/u).test(e?.toString())) { + setError('You have pending transaction') + message = 'You have pending transaction' + } else if ((/out of gas/u).test(e?.toString())) { + setError('Out of gas, try increasing gas limit on wallet.') + message = 'Out of gas, try increasing gas limit on wallet.' + } else if ((/before the new\/latest epoch/u).test(e?.toString())) { + setError('Epoch not yet created.') + message = 'Please force the pending epoch on the bonding page.' + } else if ( + (/There are unclaimed rewards available./u).test(e?.toString()) + ) { + setError('There are unclaimed rewards available.') + message = + 'There are unclaimed rewards available. Claim them before attempting to bond/unbond.' + } else if ( + (/was submitted but was not yet found on the chain/u).test(e?.toString()) + ) { + setError(e?.toString()) + message = ( + + {' '} + + ) + } else { + setError('Failed to execute transaction.') + message = 'Failed to execute transaction.' + } + + toast({ + title: (() => { + switch (migrateAction) { + case MigrateAction.Withdraw: + return 'Bonding Failed.' + case MigrateAction.Deposit: + return 'Unbonding Failed' + default: + return '' + } + })(), + description: message, + status: 'error', + duration: 9000, + position: 'top-right', + isClosable: true, + }) + }, + onSuccess: (data: any) => { + setTxStep(TxStep.Broadcasting) + setTxHash(data?.transactionHash) + toast({ + title: (() => { + switch (migrateAction) { + case MigrateAction.Deposit: + return 'Deposit Successful.' + case MigrateAction.Withdraw: + return 'Withdrawal Successful.' + default: + return '' + } + })(), + description: ( + + {' '} + + ), + status: 'success', + duration: 9000, + position: 'top-right', + isClosable: true, + }) + }, + }) + + const { data: txInfo } = useQuery( + ['txInfo', txHash], + () => { + if (!txHash) { + return null + } + return signingClient?.getTx(txHash) + }, + { + enabled: Boolean(txHash), + retry: true, + }, + ) + + const reset = () => { + setError(null) + setTxHash(null) + setTxStep(TxStep.Idle) + } + + const submit = useCallback(( + migrateAction: MigrateAction, + amount: number | null, + denom: string | null, + ) => { + setMigrateAction(migrateAction) + console.log(amount, denom) + mutate({ + fee, + address, + migrateAction, + denom, + amount, + }) + }, + [address, fee, mutate]) + + useEffect(() => { + if (txInfo && txHash) { + if (txInfo?.code) { + setTxStep(TxStep.Failed) + } else { + setTxStep(TxStep.Success) + } + } + }, [txInfo, txHash, error]) + + useEffect(() => { + if (error) { + setError(null) + } + + if (txStep !== TxStep.Idle) { + setTxStep(TxStep.Idle) + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []) // DebouncedMsgs + + return useMemo(() => ({ + fee, + buttonLabel, + submit, + txStep, + txInfo, + txHash, + error, + reset, + }), + [txStep, txInfo, txHash, error, fee]) +} + +export default useMigrateTx diff --git a/components/Pages/Trade/Migrate/hooks/withdraw.ts b/components/Pages/Trade/Migrate/hooks/withdraw.ts new file mode 100644 index 00000000..9aed9789 --- /dev/null +++ b/components/Pages/Trade/Migrate/hooks/withdraw.ts @@ -0,0 +1,44 @@ +import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' +import { ADV_MEMO } from 'constants/index' +import { createGasFee } from 'services/treasuryService' +import { createExecuteMessage } from 'util/messages/createExecuteMessage' + +export const withdraw: any = async ( + signingClient: SigningCosmWasmClient, + address: string, + denom: string, + amount: number, +) => { + const handleMsg1 = { + unstake: { + recipient: 'terra1qdjsxsv96aagrdxz83gwtjk8qvf2mrg4y8y3dqjxg556lm79pg5qdgmaxl', + }, + } + const handleMsg2 = { + withdraw_lp: { + stage: { + white_whale: { + pair: 'terra17vas9rhxhc6j6f5wrup9cqapxn74jvpft069py7l7l9kr7wx3tnsxrazux', + }, + }, + }, + } + console.log(denom, amount) + + const execMsg1 = createExecuteMessage({ senderAddress: address, + contractAddress: 'terra1zly98gvcec54m3caxlqexce7rus6rzgplz7eketsdz7nh750h2rqvu8uzx', + message: handleMsg1, + funds: [{ amount: Math.ceil(amount).toString(), + denom }] }) + + const execMsg2 = createExecuteMessage({ senderAddress: address, + contractAddress: 'terra1qdjsxsv96aagrdxz83gwtjk8qvf2mrg4y8y3dqjxg556lm79pg5qdgmaxl', + message: handleMsg2, + funds: [] }) + const messages = denom.includes('amplp') ? [execMsg1, execMsg2] : [execMsg2] + return await signingClient.signAndBroadcast( + address, messages, await createGasFee( + signingClient, address, messages, + ), ADV_MEMO, + ) +} From e9aa200c4cd882eeee1e8195467c71668af8e4d4 Mon Sep 17 00:00:00 2001 From: worrex <68468180+worrex@users.noreply.github.com> Date: Tue, 24 Dec 2024 11:41:54 +0100 Subject: [PATCH 3/6] migration page + messaging --- components/Navbar/Navbar.tsx | 18 ++-- .../Pages/Trade/Liquidity/DepositForm.tsx | 2 + .../Liquidity/hooks/useDepositTransaction.tsx | 2 +- .../Trade/Liquidity/hooks/useProvideLP.ts | 33 ++++++-- components/Pages/Trade/Migrate/Migrate.tsx | 36 ++++---- components/Pages/Trade/Migrate/constants.ts | 3 + .../Migrate/hooks/createDepositErisMsgs.ts | 40 +++++++++ .../Pages/Trade/Migrate/hooks/deposit.ts | 61 -------------- .../Trade/Migrate/hooks/useFetchStaked.ts | 44 ++++++---- .../Trade/Migrate/hooks/useMigrateTx.tsx | 83 +++++-------------- .../Pages/Trade/Migrate/hooks/withdraw.ts | 68 ++++++++++++--- .../pools/migrate/index.tsx | 0 pages/pools/index.tsx | 5 -- 13 files changed, 205 insertions(+), 190 deletions(-) create mode 100644 components/Pages/Trade/Migrate/constants.ts create mode 100644 components/Pages/Trade/Migrate/hooks/createDepositErisMsgs.ts delete mode 100644 components/Pages/Trade/Migrate/hooks/deposit.ts rename pages/{terra => [chainId]}/pools/migrate/index.tsx (100%) delete mode 100644 pages/pools/index.tsx diff --git a/components/Navbar/Navbar.tsx b/components/Navbar/Navbar.tsx index ddbbdbad..e7300491 100644 --- a/components/Navbar/Navbar.tsx +++ b/components/Navbar/Navbar.tsx @@ -1,3 +1,4 @@ +import { InfoIcon } from '@chakra-ui/icons' import { Box, Drawer, @@ -14,6 +15,7 @@ import { } from '@chakra-ui/react' import BurgerIcon from 'components/Icons/BurgerIcon' import { ACTIVE_BONDING_NETWORKS, ChainId } from 'constants/index' +import { useRouter } from 'next/router' import { useRecoilValue } from 'recoil' import { chainState } from 'state/chainState' @@ -25,8 +27,6 @@ import luncMenuLinks from './LUNCNavMenu.json' import NavbarPopper from './NavbarPopper' import bondingDisabledMenuLinks from './NavBondingDisabledMenu.json' import menuLinks from './NavMenu.json' -import { InfoIcon } from '@chakra-ui/icons' -import { useRouter } from 'next/router' const Navbar = () => { const { chainId, chainName } = useRecoilValue(chainState) @@ -142,17 +142,17 @@ const Navbar = () => { maxWidth="container.xl" display={{ base: 'none', md: 'flex' }} - alignItems='center' - justifyContent='center' - bgGradient='linear(to-r, blue.500, orange.500)' + alignItems="center" + justifyContent="center" + bgGradient="linear(to-r, blue.500, orange.500)" p={3} - cursor='pointer' + cursor="pointer" onClick={() => router.push('/terra/pools/migrate')} - borderRadius='md' + borderRadius="md" marginTop={5} > - - + + Attention: We’re migrating pools. Click here to learn more and proceed. diff --git a/components/Pages/Trade/Liquidity/DepositForm.tsx b/components/Pages/Trade/Liquidity/DepositForm.tsx index 11edaa5f..18291280 100644 --- a/components/Pages/Trade/Liquidity/DepositForm.tsx +++ b/components/Pages/Trade/Liquidity/DepositForm.tsx @@ -31,6 +31,7 @@ type Props = { poolId: string openView: any incentivesEnabled?:boolean + depositEris?: any } const DepositForm = ({ @@ -49,6 +50,7 @@ const DepositForm = ({ mobile, poolId, openView, + depositEris, incentivesEnabled = false, }: Props) => { const { walletChainName } = useRecoilValue(chainState) diff --git a/components/Pages/Trade/Liquidity/hooks/useDepositTransaction.tsx b/components/Pages/Trade/Liquidity/hooks/useDepositTransaction.tsx index faf6d22e..0df4f185 100644 --- a/components/Pages/Trade/Liquidity/hooks/useDepositTransaction.tsx +++ b/components/Pages/Trade/Liquidity/hooks/useDepositTransaction.tsx @@ -56,7 +56,7 @@ export const useTransaction: any = ({ async () => { setError(null) setTxStep(TxStep.Estimating) - if (!signingClient || !debouncedMsgs || debouncedMsgs?.length == 0) { + if (!signingClient || !debouncedMsgs || debouncedMsgs?.length === 0) { return } try { diff --git a/components/Pages/Trade/Liquidity/hooks/useProvideLP.ts b/components/Pages/Trade/Liquidity/hooks/useProvideLP.ts index 6d3455b2..d6423c6c 100644 --- a/components/Pages/Trade/Liquidity/hooks/useProvideLP.ts +++ b/components/Pages/Trade/Liquidity/hooks/useProvideLP.ts @@ -8,6 +8,7 @@ import useFactoryConfig from 'components/Pages/Trade/Incentivize/hooks/useFactor import createLpMsg, { createLPExecuteMsgs } from 'components/Pages/Trade/Liquidity/hooks/createLPMsg' import useTransaction from 'components/Pages/Trade/Liquidity/hooks/useDepositTransaction' import useIsNewPosition from 'components/Pages/Trade/Liquidity/hooks/useIsNewPosition' +import { createDepositErisMsgs } from 'components/Pages/Trade/Migrate/hooks/createDepositErisMsgs' import { useQueryMatchingPoolForSwap } from 'components/Pages/Trade/Pools/hooks/useQueryMatchingPoolForSwap' import { useQueryPoolLiquidity } from 'components/Pages/Trade/Pools/hooks/useQueryPoolsLiquidity' import { useClients } from 'hooks/useClients' @@ -17,7 +18,7 @@ import { useRecoilValue } from 'recoil' import { chainState } from 'state/chainState' import { tokenItemState } from 'state/tokenItemState' -const useProvideLP = ({ reverse = false, bondingDays }) => { +const useProvideLP = ({ reverse = false, bondingDays, isEris = false }) => { const [lpTokenA, lpTokenB] = useRecoilValue(tokenItemState) const { chainId, network, walletChainName } = useRecoilValue(chainState) const { address } = useChain(walletChainName) @@ -52,7 +53,7 @@ const useProvideLP = ({ reverse = false, bondingDays }) => { useQueryPoolLiquidity({ poolId }) // Const lpBalance = liquidity?.providedTotal?.tokenAmount || 0 let provideInitialLiquidity = false - if (liquidity?.reserves?.total[0] == 0 && window.debugLogsEnabled) { + if (liquidity?.reserves?.total[0] === 0 && window.debugLogsEnabled) { provideInitialLiquidity = true } const [tokenA, tokenB, flipped] = useMemo(() => { @@ -145,7 +146,25 @@ const useProvideLP = ({ reverse = false, bondingDays }) => { ? tokenBAmount : toChainAmount(simulated, tokenInfoB?.decimals), }), - encodedMsgs: createLPExecuteMsgs({ + encodedMsgs: isEris ? createDepositErisMsgs( + address, reverse + ? flipped + ? tokenAAmount + : toChainAmount(simulated, tokenInfoA?.decimals) + : flipped + ? tokenAAmount + : tokenAAmount, [{ denom: tokenA.denom, + amount: reverse + ? flipped + ? tokenAAmount + : toChainAmount(simulated, tokenInfoA?.decimals) + : tokenAAmount }, { denom: tokenB.denom, + amount: reverse + ? tokenBAmount + : flipped + ? tokenBAmount + : toChainAmount(simulated, tokenInfoB?.decimals) }], + ) : createLPExecuteMsgs({ minUnbondingDuration, tokenA, bondingDays, @@ -156,14 +175,10 @@ const useProvideLP = ({ reverse = false, bondingDays }) => { ? flipped ? tokenAAmount : toChainAmount(simulated, tokenInfoA?.decimals) - : flipped - ? tokenAAmount - : tokenAAmount, + : tokenAAmount, tokenB, amountB: reverse - ? flipped - ? tokenBAmount - : tokenBAmount + ? tokenBAmount : flipped ? tokenBAmount : toChainAmount(simulated, tokenInfoB?.decimals), diff --git a/components/Pages/Trade/Migrate/Migrate.tsx b/components/Pages/Trade/Migrate/Migrate.tsx index 88290059..0195682b 100644 --- a/components/Pages/Trade/Migrate/Migrate.tsx +++ b/components/Pages/Trade/Migrate/Migrate.tsx @@ -26,9 +26,12 @@ const Migrate = () => { const [isMobile] = useMediaQuery('(max-width: 720px)') const data = useFetchStaked(address) const { submit } = useMigrateTx() - const isAmpLp = useMemo(() => data?.denom.includes('amplp'), [data]) - const amount = useMemo(() => Number(data?.amount ?? 0) * (10 ** -6), [data]) + const ampLp = useMemo(() => data?.ampLpToken, [data]) + const erisLp = useMemo(() => data?.erisLpToken, [data]) + const wwLp = useMemo(() => data?.wwLpToken, [data]) + const lpTokens = [wwLp, erisLp, ampLp] + const lpSum = lpTokens.reduce((acc, token) => acc + (token?.amount ?? 0), 0) // States required for DepositForm: const [reverse, setReverse] = useState(false) const clearForm = () => {} @@ -74,6 +77,7 @@ const Migrate = () => { const { simulated, tx } = useProvideLP({ reverse, bondingDays, + isEris: true, }) const onInputChange = ({ tokenSymbol, amount }: any, index: number) => { @@ -135,13 +139,19 @@ const Migrate = () => { {/* Step 1 */} Step 1: Check Old Pool Liquidity - { isAmpLp && amount > 0 && ( - You have {amount.toFixed(6)} ampLP tokens in the old USDC/USDT XYK pool. - )} - {!isAmpLp && amount > 0 && ( - You have {amount.toFixed(6)} LP tokens in the old USDC/USDT XYK pool. - )} - {Number(data?.amount ?? 0) === 0 && ( + {lpTokens.map((token, index) => { + const tokenAmount = token?.amount ?? 0 + if (index === 0 && tokenAmount > 0) { + return You have {tokenAmount.toFixed(6)} WhiteWhale LP tokens in the old USDC/USDT XYK pool. + } else if (index === 1 && tokenAmount > 0) { + return You have {tokenAmount.toFixed(6)} Eris LP tokens in the old USDC/USDT XYK pool. + } else if (index === 2 && tokenAmount > 0) { + return You have {tokenAmount.toFixed(6)} Eris ampLP tokens in the old USDC/USDT XYK pool. + } else { + return <> + } + })} + {lpSum === 0 && ( You have no liquidity in the old pool. )} @@ -153,11 +163,9 @@ const Migrate = () => { Step 2: Withdraw Liquidity Withdraw all liquidity from the old XYK pool before migrating. 0)) } - label={isWalletConnected && (amount > 0) ? 'Withdraw' : 'Nothing to withdraw'} - onClick={() => submit( - MigrateAction.Withdraw, amount, data.denom, - )} + isDisabled={!(isWalletConnected && (lpSum > 0)) } + label={isWalletConnected && (lpSum > 0) ? 'Withdraw' : 'Nothing to withdraw'} + onClick={() => submit(MigrateAction.Withdraw, lpTokens)} /> diff --git a/components/Pages/Trade/Migrate/constants.ts b/components/Pages/Trade/Migrate/constants.ts new file mode 100644 index 00000000..9b292d9e --- /dev/null +++ b/components/Pages/Trade/Migrate/constants.ts @@ -0,0 +1,3 @@ +export const newPool = 'terra178ca7z2w6346wlkmxwpw80s2a5fmas9q28xlzegkt4c4rdam67aql5fgxj' +export const oldPool = 'terra17vas9rhxhc6j6f5wrup9cqapxn74jvpft069py7l7l9kr7wx3tnsxrazux' +export const newPoolLP = 'factory/terra178ca7z2w6346wlkmxwpw80s2a5fmas9q28xlzegkt4c4rdam67aql5fgxj/uLP' diff --git a/components/Pages/Trade/Migrate/hooks/createDepositErisMsgs.ts b/components/Pages/Trade/Migrate/hooks/createDepositErisMsgs.ts new file mode 100644 index 00000000..974f4dea --- /dev/null +++ b/components/Pages/Trade/Migrate/hooks/createDepositErisMsgs.ts @@ -0,0 +1,40 @@ +import { newPool } from 'components/Pages/Trade/Migrate/constants' +import { createExecuteMessage } from 'util/messages/index' + +export const createDepositErisMsgs = ( + address: string, tokenAmount: string, assets: {denom: string, amount: string}[], +) => { + const createLpMessage = { + create_lp: { + min_received: tokenAmount, + assets: [ + { + native: 'ibc/2C962DAB9F57FE0921435426AE75196009FAA1981BF86991203C8411F8980FDB', + }, + { + native: 'ibc/9B19062D46CAB50361CE9B0A3E6D0A7A53AC9E7CB361F32A73CC733144A9A9E5', + }, + ], + stage: { + white_whale: { + pair: newPool, + }, + }, + post_action: { + stake: { + asset_staking: 'terra14mmvqn0kthw6sre75vku263lafn5655mkjdejqjedjga4cw0qx2qlf4arv', + receiver: null, + }, + }, + }, + } + + return [ + createExecuteMessage({ + senderAddress: address, + contractAddress: 'terra1qdjsxsv96aagrdxz83gwtjk8qvf2mrg4y8y3dqjxg556lm79pg5qdgmaxl', + message: createLpMessage, + funds: assets, + }), + ] +} diff --git a/components/Pages/Trade/Migrate/hooks/deposit.ts b/components/Pages/Trade/Migrate/hooks/deposit.ts deleted file mode 100644 index 4ece7183..00000000 --- a/components/Pages/Trade/Migrate/hooks/deposit.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' -import { ADV_MEMO } from 'constants/index' -import { createGasFee } from 'services/treasuryService' -import { createExecuteMessage } from 'util/messages/createExecuteMessage' - -export const deposit: any = async ( - signingClient: SigningCosmWasmClient, - address: string, - denom: string, - amount: number, -) => { - const ampLpPostMessage = { - liquid_stake: { - compounder: 'terra1zly98gvcec54m3caxlqexce7rus6rzgplz7eketsdz7nh750h2rqvu8uzx', - receiver: null, - gauge: 'bluechip', - }, - } - const lpPostMessage = { - stake: { - asset_staking: 'terra14mmvqn0kthw6sre75vku263lafn5655mkjdejqjedjga4cw0qx2qlf4arv', - receiver: null, - }, - } - - const handleMsg1 = { - create_lp: { - min_received: '6307', - assets: [ - { - native: 'ibc/2C962DAB9F57FE0921435426AE75196009FAA1981BF86991203C8411F8980FDB', - }, - { - native: 'ibc/9B19062D46CAB50361CE9B0A3E6D0A7A53AC9E7CB361F32A73CC733144A9A9E5', - }, - ], - stage: { - white_whale: { - pair: 'terra17vas9rhxhc6j6f5wrup9cqapxn74jvpft069py7l7l9kr7wx3tnsxrazux', - }, - }, - post_action: { - stake: { - asset_staking: 'terra14mmvqn0kthw6sre75vku263lafn5655mkjdejqjedjga4cw0qx2qlf4arv', - receiver: null, - }, - }, - }, - } - - const execMsg = createExecuteMessage({ senderAddress: address, - contractAddress: 'terra1zly98gvcec54m3caxlqexce7rus6rzgplz7eketsdz7nh750h2rqvu8uzx', - message: handleMsg1, - funds: [{ amount: Math.ceil(amount).toString(), - denom }] }) - return await signingClient.signAndBroadcast( - address, [execMsg], await createGasFee( - signingClient, address, [execMsg], - ), ADV_MEMO, - ) -} diff --git a/components/Pages/Trade/Migrate/hooks/useFetchStaked.ts b/components/Pages/Trade/Migrate/hooks/useFetchStaked.ts index 8d931c51..1ee62657 100644 --- a/components/Pages/Trade/Migrate/hooks/useFetchStaked.ts +++ b/components/Pages/Trade/Migrate/hooks/useFetchStaked.ts @@ -1,28 +1,40 @@ import { useQuery } from 'react-query' -import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' +import { CosmWasmClient, JsonObject } from '@cosmjs/cosmwasm-stargate' import { WalletChainName } from 'constants/index' import { useClients } from 'hooks/useClients' const fetchStaked = async (client: CosmWasmClient, address: string) => { - const lpToken = await client.getBalance(address, 'factory/terra17vas9rhxhc6j6f5wrup9cqapxn74jvpft069py7l7l9kr7wx3tnsxrazux/uLP') + const oldDenom = 'factory/terra17vas9rhxhc6j6f5wrup9cqapxn74jvpft069py7l7l9kr7wx3tnsxrazux/uLP' + const wwLpToken = await client.getBalance(address, oldDenom) const ampLpToken = await client.getBalance(address, 'factory/terra1zly98gvcec54m3caxlqexce7rus6rzgplz7eketsdz7nh750h2rqvu8uzx/7/bluechip/amplp') - - /* - * Const result: JsonObject = await client.queryContractSmart('terra14mmvqn0kthw6sre75vku263lafn5655mkjdejqjedjga4cw0qx2qlf4arv', - * { - * staked_balance: { - * address, - * asset: { - * native: 'factory/terra17vas9rhxhc6j6f5wrup9cqapxn74jvpft069py7l7l9kr7wx3tnsxrazux/uLP', - * }, - * }, - * }) - */ - return Number(lpToken.amount) > 0 ? lpToken : ampLpToken + const erisLpToken = { denom: oldDenom, + amount: '0' } + try { + const stakedLpBalance: JsonObject = await client.queryContractSmart('terra14mmvqn0kthw6sre75vku263lafn5655mkjdejqjedjga4cw0qx2qlf4arv', + { + staked_balance: { + address, + asset: { + native: oldDenom, + }, + }, + }) + erisLpToken.amount = stakedLpBalance.asset.amount + } catch (e) { + console.error('Error: ', e) + } + return { wwLpToken: { denom: wwLpToken.denom, + amount: Number(wwLpToken.amount) * (10 ** -6) }, + erisLpToken: { denom: erisLpToken.denom, + amount: Number(erisLpToken.amount) * (10 ** -6) }, + ampLpToken: { denom: ampLpToken.denom, + amount: Number(ampLpToken.amount) * (10 ** -6) } } } -export const useFetchStaked = (address: string): {amount: string, denom: string } => { +export const useFetchStaked = (address: string): { wwLpToken: {amount: number, denom: string }, + erisLpToken: {amount: number, denom: string }, + ampLpToken: {amount: number, denom: string } } => { const { cosmWasmClient } = useClients(WalletChainName.terra) const { data } = useQuery({ queryKey: ['fetchStaked', address], diff --git a/components/Pages/Trade/Migrate/hooks/useMigrateTx.tsx b/components/Pages/Trade/Migrate/hooks/useMigrateTx.tsx index 0e7f4fd4..c36e3810 100644 --- a/components/Pages/Trade/Migrate/hooks/useMigrateTx.tsx +++ b/components/Pages/Trade/Migrate/hooks/useMigrateTx.tsx @@ -5,21 +5,18 @@ import { useToast } from '@chakra-ui/react' import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' import { useChain } from '@cosmos-kit/react-lite' import Finder from 'components/Finder' -import { deposit } from 'components/Pages/Trade/Migrate/hooks/deposit' import { withdraw } from 'components/Pages/Trade/Migrate/hooks/withdraw' import { useClients } from 'hooks/useClients' import { useRecoilValue } from 'recoil' import { chainState } from 'state/chainState' import { TxStep } from 'types/index' -export enum MigrateAction { Withdraw, Deposit } export const useMigrateTx = () => { const toast = useToast() const { chainId, walletChainName } = useRecoilValue(chainState) const { address } = useChain(walletChainName) const { signingClient } = useClients(walletChainName) const [txStep, setTxStep] = useState(TxStep.Idle) - const [migrateAction, setMigrateAction] = useState(null) const [txHash, setTxHash] = useState(null) const [error, setError] = useState(null) const [buttonLabel, setButtonLabel] = useState(null) @@ -76,19 +73,22 @@ export const useMigrateTx = () => { }, }, ) - - const { mutate } = useMutation(async (data: { signingClient: SigningCosmWasmClient, migrateAction: MigrateAction, address: string, denom: string, amount: number }) => { - console.log({ data }) - if (data.migrateAction === MigrateAction.Withdraw) { - return withdraw( - signingClient, address, data.denom, (data.amount * (10 ** 6)), - ) - } else { - return deposit( - signingClient, address, data.denom, (data.amount * (10 ** 6)), - ) - } - }, + const { data: txInfo } = useQuery( + ['txInfo', txHash], + () => { + if (!txHash) { + return null + } + return signingClient?.getTx(txHash) + }, + { + enabled: Boolean(txHash), + retry: true, + }, + ) + const { mutate } = useMutation((data: { signingClient: SigningCosmWasmClient, address: string, lpTokens: {denom: string, amount: number}[] }) => withdraw( + signingClient, address, data.lpTokens, + ), { onMutate: () => { setTxStep(TxStep.Posting) @@ -136,16 +136,7 @@ export const useMigrateTx = () => { } toast({ - title: (() => { - switch (migrateAction) { - case MigrateAction.Withdraw: - return 'Bonding Failed.' - case MigrateAction.Deposit: - return 'Unbonding Failed' - default: - return '' - } - })(), + title: (() => 'Withdrawal Failed.')(), description: message, status: 'error', duration: 9000, @@ -157,16 +148,7 @@ export const useMigrateTx = () => { setTxStep(TxStep.Broadcasting) setTxHash(data?.transactionHash) toast({ - title: (() => { - switch (migrateAction) { - case MigrateAction.Deposit: - return 'Deposit Successful.' - case MigrateAction.Withdraw: - return 'Withdrawal Successful.' - default: - return '' - } - })(), + title: (() => 'Withdrawal Successful.')(), description: ( {' '} @@ -179,40 +161,17 @@ export const useMigrateTx = () => { }) }, }) - - const { data: txInfo } = useQuery( - ['txInfo', txHash], - () => { - if (!txHash) { - return null - } - return signingClient?.getTx(txHash) - }, - { - enabled: Boolean(txHash), - retry: true, - }, - ) - const reset = () => { setError(null) setTxHash(null) setTxStep(TxStep.Idle) } - const submit = useCallback(( - migrateAction: MigrateAction, - amount: number | null, - denom: string | null, - ) => { - setMigrateAction(migrateAction) - console.log(amount, denom) + const submit = useCallback((lpTokens: {denom: string, amount: number}[]) => { mutate({ - fee, + signingClient, address, - migrateAction, - denom, - amount, + lpTokens, }) }, [address, fee, mutate]) diff --git a/components/Pages/Trade/Migrate/hooks/withdraw.ts b/components/Pages/Trade/Migrate/hooks/withdraw.ts index 9aed9789..8fe23380 100644 --- a/components/Pages/Trade/Migrate/hooks/withdraw.ts +++ b/components/Pages/Trade/Migrate/hooks/withdraw.ts @@ -1,4 +1,5 @@ import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient' +import { oldPool } from 'components/Pages/Trade/Migrate/constants' import { ADV_MEMO } from 'constants/index' import { createGasFee } from 'services/treasuryService' import { createExecuteMessage } from 'util/messages/createExecuteMessage' @@ -6,36 +7,77 @@ import { createExecuteMessage } from 'util/messages/createExecuteMessage' export const withdraw: any = async ( signingClient: SigningCosmWasmClient, address: string, - denom: string, - amount: number, + lpTokens: {denom: string, amount: number}[], ) => { - const handleMsg1 = { + const withdrawWWLp = { + withdraw_liquidity: {}, + } + + const unstakeAmpLp = { unstake: { recipient: 'terra1qdjsxsv96aagrdxz83gwtjk8qvf2mrg4y8y3dqjxg556lm79pg5qdgmaxl', }, } - const handleMsg2 = { + + const unstakeErisLp = { + unstake: { + asset: { + amount: lpTokens[1].amount, + info: { + native: lpTokens[1].denom, + }, + }, + recipient: 'terra1qdjsxsv96aagrdxz83gwtjk8qvf2mrg4y8y3dqjxg556lm79pg5qdgmaxl', + }, + } + + const withdrawErisLp = { withdraw_lp: { stage: { white_whale: { - pair: 'terra17vas9rhxhc6j6f5wrup9cqapxn74jvpft069py7l7l9kr7wx3tnsxrazux', + pair: oldPool, }, }, }, } - console.log(denom, amount) - const execMsg1 = createExecuteMessage({ senderAddress: address, + const execMsgUnstakeAmpLp = createExecuteMessage({ senderAddress: address, contractAddress: 'terra1zly98gvcec54m3caxlqexce7rus6rzgplz7eketsdz7nh750h2rqvu8uzx', - message: handleMsg1, - funds: [{ amount: Math.ceil(amount).toString(), - denom }] }) + message: unstakeAmpLp, + funds: [{ amount: Math.ceil(lpTokens[2].amount * (10 ** 6)).toString(), + denom: lpTokens[2].denom }] }) + + const execMsgUnstakeErisLp = createExecuteMessage({ senderAddress: address, + contractAddress: 'terra14mmvqn0kthw6sre75vku263lafn5655mkjdejqjedjga4cw0qx2qlf4arv', + message: unstakeErisLp, + funds: [] }) - const execMsg2 = createExecuteMessage({ senderAddress: address, + const execMsgWithdrawErisLp = createExecuteMessage({ senderAddress: address, contractAddress: 'terra1qdjsxsv96aagrdxz83gwtjk8qvf2mrg4y8y3dqjxg556lm79pg5qdgmaxl', - message: handleMsg2, + message: withdrawErisLp, funds: [] }) - const messages = denom.includes('amplp') ? [execMsg1, execMsg2] : [execMsg2] + + const execMsgWithdrawWWLp = createExecuteMessage({ senderAddress: address, + contractAddress: oldPool, + message: withdrawWWLp, + funds: [{ + amount: (lpTokens[0].amount * (10 ** 6)).toString(), + denom: lpTokens[0].denom, + }] }) + const messages = [] + + if (lpTokens[2].amount > 0) { + messages.push(execMsgUnstakeAmpLp) + } + if (lpTokens[1].amount > 0) { + messages.push(execMsgUnstakeErisLp) + messages.push(execMsgWithdrawErisLp) + } + if (lpTokens[0].amount > 0) { + messages.push(execMsgWithdrawWWLp) + } + console.log({lpTokens}) + console.log({messages}) return await signingClient.signAndBroadcast( address, messages, await createGasFee( signingClient, address, messages, diff --git a/pages/terra/pools/migrate/index.tsx b/pages/[chainId]/pools/migrate/index.tsx similarity index 100% rename from pages/terra/pools/migrate/index.tsx rename to pages/[chainId]/pools/migrate/index.tsx diff --git a/pages/pools/index.tsx b/pages/pools/index.tsx deleted file mode 100644 index 658b6076..00000000 --- a/pages/pools/index.tsx +++ /dev/null @@ -1,5 +0,0 @@ -import Pools from 'components/Pages/Trade/Pools' - -const PoolsPage = () => - -export default PoolsPage From 14db1b5c16c4ebf1f43a128ce11bcfd9d1e23e43 Mon Sep 17 00:00:00 2001 From: worrex <68468180+worrex@users.noreply.github.com> Date: Tue, 24 Dec 2024 13:26:28 +0100 Subject: [PATCH 4/6] add withdraw msg --- components/Pages/Trade/Migrate/hooks/withdraw.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/components/Pages/Trade/Migrate/hooks/withdraw.ts b/components/Pages/Trade/Migrate/hooks/withdraw.ts index 8fe23380..1290c06d 100644 --- a/components/Pages/Trade/Migrate/hooks/withdraw.ts +++ b/components/Pages/Trade/Migrate/hooks/withdraw.ts @@ -68,6 +68,7 @@ export const withdraw: any = async ( if (lpTokens[2].amount > 0) { messages.push(execMsgUnstakeAmpLp) + messages.push(execMsgWithdrawErisLp) } if (lpTokens[1].amount > 0) { messages.push(execMsgUnstakeErisLp) From b255b1d915266cdcb36f009c2aaa515be1a4ee91 Mon Sep 17 00:00:00 2001 From: worrex <68468180+worrex@users.noreply.github.com> Date: Tue, 24 Dec 2024 13:32:04 +0100 Subject: [PATCH 5/6] fix input params --- components/Pages/Trade/Migrate/Migrate.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/Pages/Trade/Migrate/Migrate.tsx b/components/Pages/Trade/Migrate/Migrate.tsx index 0195682b..675f9ac2 100644 --- a/components/Pages/Trade/Migrate/Migrate.tsx +++ b/components/Pages/Trade/Migrate/Migrate.tsx @@ -5,7 +5,7 @@ import { useChain } from '@cosmos-kit/react-lite' import DepositForm from 'components/Pages/Trade/Liquidity/DepositForm' import useProvideLP from 'components/Pages/Trade/Liquidity/hooks/useProvideLP' import { useFetchStaked } from 'components/Pages/Trade/Migrate/hooks/useFetchStaked' -import useMigrateTx, { MigrateAction } from 'components/Pages/Trade/Migrate/hooks/useMigrateTx' +import useMigrateTx from 'components/Pages/Trade/Migrate/hooks/useMigrateTx' import { usePoolsListQuery } from 'components/Pages/Trade/Pools/hooks/usePoolsListQuery' import { PoolEntityTypeWithLiquidity, @@ -165,7 +165,7 @@ const Migrate = () => { 0)) } label={isWalletConnected && (lpSum > 0) ? 'Withdraw' : 'Nothing to withdraw'} - onClick={() => submit(MigrateAction.Withdraw, lpTokens)} + onClick={() => submit(lpTokens)} /> From d1ff21ad293d8ce2a9310d80b3e713f00ba28dc9 Mon Sep 17 00:00:00 2001 From: worrex <68468180+worrex@users.noreply.github.com> Date: Sat, 28 Dec 2024 16:57:06 +0100 Subject: [PATCH 6/6] addjusted link and text --- components/Pages/Trade/Liquidity/hooks/useProvideLP.ts | 2 +- components/Pages/Trade/Migrate/Migrate.tsx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/Pages/Trade/Liquidity/hooks/useProvideLP.ts b/components/Pages/Trade/Liquidity/hooks/useProvideLP.ts index d6423c6c..ca3c15e7 100644 --- a/components/Pages/Trade/Liquidity/hooks/useProvideLP.ts +++ b/components/Pages/Trade/Liquidity/hooks/useProvideLP.ts @@ -44,7 +44,7 @@ const useProvideLP = ({ reverse = false, bondingDays, isEris = false }) => { }) const factoryConfig = useFactoryConfig(config?.incentive_factory) - let minUnbondingDuration = 86400 + let minUnbondingDuration = 86_400 if (factoryConfig) { minUnbondingDuration = factoryConfig?.minUnbondingDuration } diff --git a/components/Pages/Trade/Migrate/Migrate.tsx b/components/Pages/Trade/Migrate/Migrate.tsx index 675f9ac2..f95da37c 100644 --- a/components/Pages/Trade/Migrate/Migrate.tsx +++ b/components/Pages/Trade/Migrate/Migrate.tsx @@ -201,10 +201,10 @@ const Migrate = () => { Step 4: Vote with Your Liquidity Your new liquidity is now deposited in the StableSwap pool. - Proceed to Eris Protocol to use your liquidity for voting and other governance actions. + Proceed to Eris Protocol to deposit your USDC/USDT Stable LP and adjust your VP to the new stable pool.