diff --git a/components/Navbar/Logo.tsx b/components/Navbar/Logo.tsx index c98a8582..e389856f 100644 --- a/components/Navbar/Logo.tsx +++ b/components/Navbar/Logo.tsx @@ -1,9 +1,9 @@ import React from 'react' import { HStack, Image, Text } from '@chakra-ui/react' +import { useRouter } from 'next/router' import { useRecoilState } from 'recoil' import { walletState } from 'state/atoms/walletAtoms' -import { useRouter } from 'next/router' const Logo = () => { const [currentWalletState, setCurrentWalletState] = @@ -11,18 +11,18 @@ const Logo = () => { const router = useRouter() return ( - { - setCurrentWalletState({ - ...currentWalletState, - chainId: 'migaloo-1' - }) - await router.push('/migaloo/swap') - } - } - > - WhiteWhale Logo - + { + setCurrentWalletState({ + ...currentWalletState, + chainId: 'migaloo-1', + }) + await router.push('/migaloo/swap') + } + } + > + WhiteWhale Logo + White diff --git a/components/Pages/Dashboard/BondingActions/Bond.tsx b/components/Pages/Dashboard/BondingActions/Bond.tsx index dc160db0..ed742860 100644 --- a/components/Pages/Dashboard/BondingActions/Bond.tsx +++ b/components/Pages/Dashboard/BondingActions/Bond.tsx @@ -2,13 +2,12 @@ import React, { useEffect, useMemo, useState } from 'react' import { Controller, useForm } from 'react-hook-form' import { VStack } from '@chakra-ui/react' +import AssetInput from 'components/AssetInput/index' +import { bondingAtom } from 'components/Pages/Dashboard/BondingActions/bondAtoms' import { useConfig } from 'components/Pages/Dashboard/hooks/useDashboardData' import { useRecoilState, useRecoilValue } from 'recoil' import { WalletStatusType, walletState } from 'state/atoms/walletAtoms' -import AssetInput from 'components/AssetInput/index' -import { bondingAtom } from 'components/Pages/Dashboard/BondingActions/bondAtoms' - export interface BondingTokenState { tokenSymbol: string amount: number diff --git a/components/Pages/Dashboard/BondingActions/BondingActions.tsx b/components/Pages/Dashboard/BondingActions/BondingActions.tsx index 9d97c2bf..39e74e44 100644 --- a/components/Pages/Dashboard/BondingActions/BondingActions.tsx +++ b/components/Pages/Dashboard/BondingActions/BondingActions.tsx @@ -10,27 +10,27 @@ import { VStack, useDisclosure, } from '@chakra-ui/react' +import Loader from 'components/Loader' +import { Bond, BondingTokenState } from 'components/Pages/Dashboard/BondingActions/Bond' +import { bondingAtom } from 'components/Pages/Dashboard/BondingActions/bondAtoms' import { BondingActionTooltip } from 'components/Pages/Dashboard/BondingActions/BondingAcionTooltip' +import useTransaction, { TxStep } from 'components/Pages/Dashboard/BondingActions/hooks/useTransaction' +import Unbond from 'components/Pages/Dashboard/BondingActions/Unbond' +import Withdraw from 'components/Pages/Dashboard/BondingActions/Withdraw' +import { ActionType } from 'components/Pages/Dashboard/BondingOverview' import { WithdrawableInfo } from 'components/Pages/Dashboard/hooks/getWithdrawable' +import { + Config, + useConfig, + useDashboardData, +} from 'components/Pages/Dashboard/hooks/useDashboardData' +import WalletModal from 'components/Wallet/Modal/Modal' import { useChains } from 'hooks/useChainInfo' import { useMultipleTokenBalance } from 'hooks/useTokenBalance' import { useRouter } from 'next/router' import { useRecoilState } from 'recoil' import { WalletStatusType, walletState } from 'state/atoms/walletAtoms' -import Loader from 'components/Loader' -import WalletModal from 'components/Wallet/Modal/Modal' -import { ActionType } from 'components/Pages/Dashboard/BondingOverview' -import { - Config, - useConfig, - useDashboardData, -} from 'components/Pages/Dashboard/hooks/useDashboardData' -import { Bond, BondingTokenState } from 'components/Pages/Dashboard/BondingActions/Bond' -import { bondingAtom } from 'components/Pages/Dashboard/BondingActions/bondAtoms' -import useTransaction, { TxStep } from 'components/Pages/Dashboard/BondingActions/hooks/useTransaction' -import Unbond from 'components/Pages/Dashboard/BondingActions/Unbond' -import Withdraw from 'components/Pages/Dashboard/BondingActions/Withdraw' const BondingActions = ({ globalAction }) => { const [{ chainId, client, address, status, network }, _] = diff --git a/components/Pages/Dashboard/BondingActions/Unbond.tsx b/components/Pages/Dashboard/BondingActions/Unbond.tsx index 5ca827cc..2a03eb3b 100644 --- a/components/Pages/Dashboard/BondingActions/Unbond.tsx +++ b/components/Pages/Dashboard/BondingActions/Unbond.tsx @@ -2,15 +2,14 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react' import { Controller, useForm } from 'react-hook-form' import { VStack } from '@chakra-ui/react' +import AssetInput from 'components/AssetInput/index' +import { BondingTokenState, TokenBalance } from 'components/Pages/Dashboard/BondingActions/Bond' +import { bondingAtom } from 'components/Pages/Dashboard/BondingActions/bondAtoms' import { BondedData } from 'components/Pages/Dashboard/hooks/getBonded' import { useConfig } from 'components/Pages/Dashboard/hooks/useDashboardData' import { useRecoilState, useRecoilValue } from 'recoil' import { WalletStatusType, walletState } from 'state/atoms/walletAtoms' -import AssetInput from 'components/AssetInput/index' -import { BondingTokenState, TokenBalance } from 'components/Pages/Dashboard/BondingActions/Bond' -import { bondingAtom } from 'components/Pages/Dashboard/BondingActions/bondAtoms' - const Unbond = ({ bondedAssets }: { bondedAssets: BondedData[] }) => { const { status, chainId, network } = useRecoilValue(walletState) const [currentBondState, setCurrentBondState] = diff --git a/components/Pages/Dashboard/BondingActions/Withdraw.tsx b/components/Pages/Dashboard/BondingActions/Withdraw.tsx index 1b0fc884..4aaad027 100644 --- a/components/Pages/Dashboard/BondingActions/Withdraw.tsx +++ b/components/Pages/Dashboard/BondingActions/Withdraw.tsx @@ -3,6 +3,7 @@ import { useMemo } from 'react' import { Box, HStack, Text, VStack } from '@chakra-ui/react' import { UnbondingData } from 'components/Pages/Dashboard/hooks/getUnbonding' import { WithdrawableInfo } from 'components/Pages/Dashboard/hooks/getWithdrawable' +import { WhaleTooltip } from 'components/Pages/Dashboard/WhaleTooltip' import usePrices from 'hooks/usePrices' import { useTokenList } from 'hooks/useTokenList' import { useRecoilValue } from 'recoil' @@ -13,8 +14,6 @@ import { nanoToMilli, } from 'util/conversion/index' -import { WhaleTooltip } from 'components/Pages/Dashboard/WhaleTooltip' - type Props = { unbondingRequests: UnbondingData[] withdrawableInfos: WithdrawableInfo[] diff --git a/components/Pages/Dashboard/BondingActions/bondAtoms.ts b/components/Pages/Dashboard/BondingActions/bondAtoms.ts index ec9e225d..54bb862e 100644 --- a/components/Pages/Dashboard/BondingActions/bondAtoms.ts +++ b/components/Pages/Dashboard/BondingActions/bondAtoms.ts @@ -1,6 +1,5 @@ -import { atom } from 'recoil' - import { BondingTokenState } from 'components/Pages/Dashboard/BondingActions/Bond' +import { atom } from 'recoil' export const bondingAtom = atom({ key: 'bondingToken', diff --git a/components/Pages/Dashboard/BondingActions/hooks/bondTokens.ts b/components/Pages/Dashboard/BondingActions/hooks/bondTokens.ts index f234740c..4e07b235 100644 --- a/components/Pages/Dashboard/BondingActions/hooks/bondTokens.ts +++ b/components/Pages/Dashboard/BondingActions/hooks/bondTokens.ts @@ -1,6 +1,7 @@ import { coin } from '@cosmjs/stargate' import { Config } from 'components/Pages/Dashboard/hooks/useDashboardData' import { TerraTreasuryService } from 'services/treasuryService' +import { createExecuteMessage } from 'util/messages/createExecuteMessage' import { Wallet } from 'util/wallet-adapters/index' export const bondTokens = async ( @@ -23,13 +24,21 @@ export const bondTokens = async ( }, }, } + const execMsg = createExecuteMessage({ senderAddress: address, + contractAddress: config.whale_lair, + message: handleMsg, + funds: [coin(amount, denom)] }) let fee = null if (chainId === 'columbus-5') { - fee = await TerraTreasuryService.getInstance().getTerraClassicFee(amount, denom) + const gas = Math.ceil(await client.simulate( + address, [execMsg], '', + ) * 1.3) + fee = await TerraTreasuryService.getInstance().getTerraClassicFee( + amount, denom, gas, + ) } - return client.execute( - address, config.whale_lair, handleMsg, [ - coin(amount, denom), - ], fee, + return await client.post( + address, [execMsg], '', fee, ) } + diff --git a/components/Pages/Dashboard/BondingActions/hooks/claimRewards.ts b/components/Pages/Dashboard/BondingActions/hooks/claimRewards.ts index b90c7b1e..bec43631 100644 --- a/components/Pages/Dashboard/BondingActions/hooks/claimRewards.ts +++ b/components/Pages/Dashboard/BondingActions/hooks/claimRewards.ts @@ -1,7 +1,10 @@ import { Config } from 'components/Pages/Dashboard/hooks/useDashboardData' +import { createExecuteMessage } from 'util/messages/createExecuteMessage' import { Wallet } from 'util/wallet-adapters/index' -export const claimRewards = ( +import { TerraTreasuryService } from '../../../../../services/treasuryService' + +export const claimRewards = async ( client: Wallet, address: string, config: Config, @@ -9,7 +12,21 @@ export const claimRewards = ( const handleMsg = { claim: {}, } - return client.execute( - address, config.fee_distributor, handleMsg, + + const execMsg = createExecuteMessage({ senderAddress: address, + contractAddress: config.fee_distributor, + message: handleMsg, + funds: [] }) + let fee = null + if (await client.getChainId() === 'columbus-5') { + const gas = Math.ceil(await client.simulate( + address, [execMsg], '', + ) * 1.3) + fee = await TerraTreasuryService.getInstance().getTerraClassicFee( + 0, '', gas, + ) + } + return await client.post( + address, [execMsg], '', fee, ) } diff --git a/components/Pages/Dashboard/BondingActions/hooks/createNewEpoch.ts b/components/Pages/Dashboard/BondingActions/hooks/createNewEpoch.ts index e98f89c4..c0338b62 100644 --- a/components/Pages/Dashboard/BondingActions/hooks/createNewEpoch.ts +++ b/components/Pages/Dashboard/BondingActions/hooks/createNewEpoch.ts @@ -1,6 +1,9 @@ import { Config } from 'components/Pages/Dashboard/hooks/useDashboardData' +import { createExecuteMessage } from 'util/messages/createExecuteMessage' import { Wallet } from 'util/wallet-adapters/index' +import { TerraTreasuryService } from '../../../../../services/treasuryService' + export const createNewEpoch = async ( client: Wallet, config: Config, @@ -9,7 +12,21 @@ export const createNewEpoch = async ( const handleMsg = { new_epoch: {}, } - return client.execute( - address, config.fee_distributor, handleMsg, + + const execMsg = createExecuteMessage({ senderAddress: address, + contractAddress: config.fee_distributor, + message: handleMsg, + funds: [] }) + let fee = null + if (await client.getChainId() === 'columbus-5') { + const gas = Math.ceil(await client.simulate( + address, [execMsg], '', + ) * 1.3) + fee = await TerraTreasuryService.getInstance().getTerraClassicFee( + 0, '', gas, + ) + } + return await client.post( + address, [execMsg], '', fee, ) } diff --git a/components/Pages/Dashboard/BondingActions/hooks/unbondTokens.ts b/components/Pages/Dashboard/BondingActions/hooks/unbondTokens.ts index b610f9b8..96bc305e 100644 --- a/components/Pages/Dashboard/BondingActions/hooks/unbondTokens.ts +++ b/components/Pages/Dashboard/BondingActions/hooks/unbondTokens.ts @@ -1,7 +1,10 @@ import { Config } from 'components/Pages/Dashboard/hooks/useDashboardData' +import { createExecuteMessage } from 'util/messages/createExecuteMessage' import { Wallet } from 'util/wallet-adapters/index' -export const unbondTokens = ( +import { TerraTreasuryService } from '../../../../../services/treasuryService' + +export const unbondTokens = async ( client: Wallet, address: string, amount: number, @@ -20,7 +23,19 @@ export const unbondTokens = ( }, }, } - return client.execute( - address, config.whale_lair, handleMsg, + + const execMsg = createExecuteMessage({ senderAddress: address, + contractAddress: config.whale_lair, + message: handleMsg, + funds: [] }) + let fee = null + if (chainId === 'columbus-5') { + const gas = Math.ceil(await client.simulate( + address, [execMsg], '', + ) * 1.3) + fee = await TerraTreasuryService.getInstance().getTerraClassicFee(amount, denom) + } + return await client.post( + address, [execMsg], '', fee, ) } diff --git a/components/Pages/Dashboard/BondingActions/hooks/useTransaction.tsx b/components/Pages/Dashboard/BondingActions/hooks/useTransaction.tsx index 3a56a3e2..38f47f8e 100644 --- a/components/Pages/Dashboard/BondingActions/hooks/useTransaction.tsx +++ b/components/Pages/Dashboard/BondingActions/hooks/useTransaction.tsx @@ -3,8 +3,12 @@ import { useMutation, useQuery } from 'react-query' import { useToast } from '@chakra-ui/react' import Finder from 'components/Finder' +import { bondTokens } from 'components/Pages/Dashboard/BondingActions/hooks/bondTokens' import { claimRewards } from 'components/Pages/Dashboard/BondingActions/hooks/claimRewards' import { createNewEpoch } from 'components/Pages/Dashboard/BondingActions/hooks/createNewEpoch' +import { unbondTokens } from 'components/Pages/Dashboard/BondingActions/hooks/unbondTokens' +import { withdrawTokens } from 'components/Pages/Dashboard/BondingActions/hooks/withdrawTokens' +import { ActionType } from 'components/Pages/Dashboard/BondingOverview' import { Config, useConfig, @@ -13,11 +17,6 @@ import { useRecoilValue } from 'recoil' import { walletState } from 'state/atoms/walletAtoms' import { convertDenomToMicroDenom } from 'util/conversion/index' -import { ActionType } from 'components/Pages/Dashboard/BondingOverview' -import { bondTokens } from 'components/Pages/Dashboard/BondingActions/hooks/bondTokens' -import { unbondTokens } from 'components/Pages/Dashboard/BondingActions/hooks/unbondTokens' -import { withdrawTokens } from 'components/Pages/Dashboard/BondingActions/hooks/withdrawTokens' - export enum TxStep { /** * Idle diff --git a/components/Pages/Dashboard/BondingActions/hooks/withdrawTokens.ts b/components/Pages/Dashboard/BondingActions/hooks/withdrawTokens.ts index c2ee5ee8..aa92ee05 100644 --- a/components/Pages/Dashboard/BondingActions/hooks/withdrawTokens.ts +++ b/components/Pages/Dashboard/BondingActions/hooks/withdrawTokens.ts @@ -1,7 +1,10 @@ import { Config } from 'components/Pages/Dashboard/hooks/useDashboardData' +import { createExecuteMessage } from 'util/messages/createExecuteMessage' import { Wallet } from 'util/wallet-adapters/index' -export const withdrawTokens = ( +import { TerraTreasuryService } from '../../../../../services/treasuryService' + +export const withdrawTokens = async ( client: Wallet, address: string, denom: string, @@ -12,7 +15,21 @@ export const withdrawTokens = ( denom, }, } - return client.execute( - address, config.whale_lair, handleMsg, + + const execMsg = createExecuteMessage({ senderAddress: address, + contractAddress: config.whale_lair, + message: handleMsg, + funds: [] }) + let fee = null + if (chainId === 'columbus-5') { + const gas = Math.ceil(await client.simulate( + address, [execMsg], '', + ) * 1.3) + fee = await TerraTreasuryService.getInstance().getTerraClassicFee( + 0, '', gas, + ) + } + return await client.post( + address, [execMsg], '', fee, ) } diff --git a/components/Pages/Dashboard/RewardsComponent.tsx b/components/Pages/Dashboard/RewardsComponent.tsx index beee63d5..a5da13c4 100644 --- a/components/Pages/Dashboard/RewardsComponent.tsx +++ b/components/Pages/Dashboard/RewardsComponent.tsx @@ -12,6 +12,7 @@ import { useDisclosure, } from '@chakra-ui/react' import { BondingActionTooltip } from 'components/Pages/Dashboard/BondingActions/BondingAcionTooltip' +import useTransaction, { TxStep } from 'components/Pages/Dashboard/BondingActions/hooks/useTransaction' import { Config, useConfig, @@ -24,7 +25,6 @@ import { calculateRewardDurationString, nanoToMilli } from 'util/conversion' import Loader from '../../Loader' import WalletModal from '../../Wallet/Modal/Modal' -import useTransaction, { TxStep } from 'components/Pages/Dashboard/BondingActions/hooks/useTransaction' import { ActionType } from './BondingOverview' const pulseAnimation = keyframes` diff --git a/components/Pages/Flashloan/Vaults/AllVaultsTable.tsx b/components/Pages/Flashloan/Vaults/AllVaultsTable.tsx index f634d143..503084f3 100644 --- a/components/Pages/Flashloan/Vaults/AllVaultsTable.tsx +++ b/components/Pages/Flashloan/Vaults/AllVaultsTable.tsx @@ -18,7 +18,6 @@ import { useReactTable, } from '@tanstack/react-table' import Loader from 'components/Loader' - import VaultName from 'components/Pages/Flashloan/Vaults/VaultName' export type Vault = { diff --git a/components/Pages/Flashloan/Vaults/ManagePoistion/DepositForm.tsx b/components/Pages/Flashloan/Vaults/ManagePoistion/DepositForm.tsx index 600f0af9..d4ef7c58 100644 --- a/components/Pages/Flashloan/Vaults/ManagePoistion/DepositForm.tsx +++ b/components/Pages/Flashloan/Vaults/ManagePoistion/DepositForm.tsx @@ -3,11 +3,10 @@ import { useCallback, useEffect, useMemo, useState } from 'react' import { Button, VStack, useToast } from '@chakra-ui/react' import AssetInput from 'components/AssetInput/index' import Finder from 'components/Finder' -import { useRecoilValue } from 'recoil' -import { WalletStatusType, walletState } from 'state/atoms/walletAtoms' - import useDepost from 'components/Pages/Flashloan/Vaults/hooks/useDeposit' import { TxStep } from 'components/Pages/Flashloan/Vaults/hooks/useTransaction' +import { useRecoilValue } from 'recoil' +import { WalletStatusType, walletState } from 'state/atoms/walletAtoms' type Props = { connected: WalletStatusType diff --git a/components/Pages/Flashloan/Vaults/ManagePoistion/ManagePosition.tsx b/components/Pages/Flashloan/Vaults/ManagePoistion/ManagePosition.tsx index 287342f7..95a0f13e 100644 --- a/components/Pages/Flashloan/Vaults/ManagePoistion/ManagePosition.tsx +++ b/components/Pages/Flashloan/Vaults/ManagePoistion/ManagePosition.tsx @@ -13,16 +13,15 @@ import { Text, VStack, } from '@chakra-ui/react' +import useVault, { useVaultDeposit } from 'components/Pages/Flashloan/Vaults/hooks/useVaults' +import DepositForm from 'components/Pages/Flashloan/Vaults/ManagePoistion/DepositForm' +import WithdrawForm from 'components/Pages/Flashloan/Vaults/ManagePoistion/WithdrawForm' import { useChains } from 'hooks/useChainInfo' import { useTokenBalance } from 'hooks/useTokenBalance' import { NextRouter, useRouter } from 'next/router' import { useRecoilValue } from 'recoil' import { walletState } from 'state/atoms/walletAtoms' -import useVault, { useVaultDeposit } from 'components/Pages/Flashloan/Vaults/hooks/useVaults' -import DepositForm from 'components/Pages/Flashloan/Vaults/ManagePoistion/DepositForm' -import WithdrawForm from 'components/Pages/Flashloan/Vaults/ManagePoistion/WithdrawForm' - const ManagePosition = () => { const router: NextRouter = useRouter() const { vaults, refetch: vaultsRefetch } = useVault() diff --git a/components/Pages/Flashloan/Vaults/ManagePoistion/WithdrawForm.tsx b/components/Pages/Flashloan/Vaults/ManagePoistion/WithdrawForm.tsx index fca85f73..4b763f47 100644 --- a/components/Pages/Flashloan/Vaults/ManagePoistion/WithdrawForm.tsx +++ b/components/Pages/Flashloan/Vaults/ManagePoistion/WithdrawForm.tsx @@ -3,13 +3,12 @@ import { useCallback, useEffect, useMemo, useState } from 'react' import { Button, VStack, useToast } from '@chakra-ui/react' import AssetInput from 'components/AssetInput/index' import Finder from 'components/Finder' +import { TxStep } from 'components/Pages/Flashloan/Vaults/hooks/useTransaction' +import useWithdraw from 'components/Pages/Flashloan/Vaults/hooks/useWithdraw' import { fromChainAmount } from 'libs/num' import { useRecoilValue } from 'recoil' import { WalletStatusType, walletState } from 'state/atoms/walletAtoms' -import { TxStep } from 'components/Pages/Flashloan/Vaults/hooks/useTransaction' -import useWithdraw from 'components/Pages/Flashloan/Vaults/hooks/useWithdraw' - type Props = { connected: WalletStatusType isLoading: boolean diff --git a/components/Pages/Flashloan/Vaults/NewPosition.tsx b/components/Pages/Flashloan/Vaults/NewPosition.tsx index a1c42611..2386d7ab 100644 --- a/components/Pages/Flashloan/Vaults/NewPosition.tsx +++ b/components/Pages/Flashloan/Vaults/NewPosition.tsx @@ -2,15 +2,14 @@ import { useEffect, useMemo } from 'react' import { ArrowBackIcon } from '@chakra-ui/icons' import { Box, HStack, IconButton, Text, VStack } from '@chakra-ui/react' +import useVault, { useVaultDeposit } from 'components/Pages/Flashloan/Vaults/hooks/useVaults' +import DepositForm from 'components/Pages/Flashloan/Vaults/ManagePoistion/DepositForm' import { useChains } from 'hooks/useChainInfo' import { useTokenBalance } from 'hooks/useTokenBalance' import { NextRouter, useRouter } from 'next/router' import { useRecoilValue } from 'recoil' import { walletState } from 'state/atoms/walletAtoms' -import useVault, { useVaultDeposit } from 'components/Pages/Flashloan/Vaults/hooks/useVaults' -import DepositForm from 'components/Pages/Flashloan/Vaults/ManagePoistion/DepositForm' - const NewPosition = () => { const router: NextRouter = useRouter() const { vaults, refetch: vaultsRefetch } = useVault() diff --git a/components/Pages/Flashloan/Vaults/Vaults.tsx b/components/Pages/Flashloan/Vaults/Vaults.tsx index b89c6389..78120bdd 100644 --- a/components/Pages/Flashloan/Vaults/Vaults.tsx +++ b/components/Pages/Flashloan/Vaults/Vaults.tsx @@ -1,13 +1,12 @@ import React, { FC, useMemo, useState } from 'react' import { Box, HStack, Text, VStack } from '@chakra-ui/react' +import AllVaultsTable from 'components/Pages/Flashloan/Vaults/AllVaultsTable' +import useVault from 'components/Pages/Flashloan/Vaults/hooks/useVaults' import { useRouter } from 'next/router' import { useRecoilValue } from 'recoil' import { WalletStatusType, walletState } from 'state/atoms/walletAtoms' -import AllVaultsTable from 'components/Pages/Flashloan/Vaults/AllVaultsTable' -import useVault from 'components/Pages/Flashloan/Vaults/hooks/useVaults' - const Vaults: FC = () => { const [allVaultsInitialized, setAllVaultsInitialized] = useState(false) diff --git a/components/Pages/Flashloan/Vaults/hooks/useDeposit.tsx b/components/Pages/Flashloan/Vaults/hooks/useDeposit.tsx index aa09acb6..83f09905 100644 --- a/components/Pages/Flashloan/Vaults/hooks/useDeposit.tsx +++ b/components/Pages/Flashloan/Vaults/hooks/useDeposit.tsx @@ -1,13 +1,12 @@ import { useMemo } from 'react' +import { createDepostExecuteMsgs, createDepostMsg } from 'components/Pages/Flashloan/Vaults/hooks/createDepositMsgs' +import useTransaction from 'components/Pages/Flashloan/Vaults/hooks/useTransaction' import { useTokenInfo } from 'hooks/useTokenInfo' import { toChainAmount } from 'libs/num' import { useRecoilValue } from 'recoil' import { walletState } from 'state/atoms/walletAtoms' -import { createDepostExecuteMsgs, createDepostMsg } from 'components/Pages/Flashloan/Vaults/hooks/createDepositMsgs' -import useTransaction from 'components/Pages/Flashloan/Vaults/hooks/useTransaction' - type DepostProps = { token: { amount: number diff --git a/components/Pages/Flashloan/Vaults/hooks/useTransaction.tsx b/components/Pages/Flashloan/Vaults/hooks/useTransaction.tsx index b52c3532..82c6f7ac 100644 --- a/components/Pages/Flashloan/Vaults/hooks/useTransaction.tsx +++ b/components/Pages/Flashloan/Vaults/hooks/useTransaction.tsx @@ -3,9 +3,8 @@ import { useMutation, useQuery, useQueryClient } from 'react-query' import { useToast } from '@chakra-ui/react' import Finder from 'components/Finder' -import useDebounceValue from 'hooks/useDebounceValue' - import { executeVault } from 'components/Pages/Flashloan/Vaults/hooks/executeVault' +import useDebounceValue from 'hooks/useDebounceValue' export enum TxStep { /** diff --git a/components/Pages/Flashloan/Vaults/hooks/useWithdraw.tsx b/components/Pages/Flashloan/Vaults/hooks/useWithdraw.tsx index c5e834ca..9d39ec7a 100644 --- a/components/Pages/Flashloan/Vaults/hooks/useWithdraw.tsx +++ b/components/Pages/Flashloan/Vaults/hooks/useWithdraw.tsx @@ -1,15 +1,14 @@ import { useMemo } from 'react' -import { useTokenInfo } from 'hooks/useTokenInfo' -import { toChainAmount } from 'libs/num' -import { useRecoilValue } from 'recoil' -import { walletState } from 'state/atoms/walletAtoms' - import { createWithdrawExecuteMsgs, createWithdrawMsg, } from 'components/Pages/Flashloan/Vaults/hooks/createWithdrawMsgs' import useTransaction from 'components/Pages/Flashloan/Vaults/hooks/useTransaction' +import { useTokenInfo } from 'hooks/useTokenInfo' +import { toChainAmount } from 'libs/num' +import { useRecoilValue } from 'recoil' +import { walletState } from 'state/atoms/walletAtoms' type DepostProps = { token: { diff --git a/components/Pages/Trade/Incentivize/Create.tsx b/components/Pages/Trade/Incentivize/Create.tsx index b4df4eb7..ef41494a 100644 --- a/components/Pages/Trade/Incentivize/Create.tsx +++ b/components/Pages/Trade/Incentivize/Create.tsx @@ -9,6 +9,7 @@ import { Stack, } from '@chakra-ui/react' import Input from 'components/AssetInput/Input' +import { useOpenFlow } from 'components/Pages/Trade/Incentivize/hooks/useOpenFlow' import SubmitButton from 'components/SubmitButton' import { TooltipWithChildren } from 'components/TooltipWithChildren' import { useRecoilValue } from 'recoil' @@ -16,8 +17,6 @@ import { txAtom } from 'state/atoms/tx' import { WalletStatusType, walletState } from 'state/atoms/walletAtoms' import { TxStep } from 'types/common' -import { useOpenFlow } from 'components/Pages/Trade/Incentivize/hooks/useOpenFlow' - const defaultToken = { tokenSymbol: 'WHALE', amount: '', diff --git a/components/Pages/Trade/Incentivize/Incentivize.tsx b/components/Pages/Trade/Incentivize/Incentivize.tsx index c8906f65..3048d308 100644 --- a/components/Pages/Trade/Incentivize/Incentivize.tsx +++ b/components/Pages/Trade/Incentivize/Incentivize.tsx @@ -13,6 +13,7 @@ import { Text, VStack, } from '@chakra-ui/react' +import Create from 'components/Pages/Trade/Incentivize/Create' import PositionsOverview from 'components/Pages/Trade/Incentivize/PositionsOverview' import { useChains } from 'hooks/useChainInfo' import { useCosmwasmClient } from 'hooks/useCosmwasmClient' @@ -23,8 +24,6 @@ import { useQueryPoolsLiquidity } from 'queries/useQueryPoolsLiquidity' import { useRecoilValue } from 'recoil' import { walletState } from 'state/atoms/walletAtoms' -import Create from 'components/Pages/Trade/Incentivize/Create' - const Incentivize: FC = () => { const router: NextRouter = useRouter() const chains: Array = useChains() diff --git a/components/Pages/Trade/Incentivize/PositionsOverview.tsx b/components/Pages/Trade/Incentivize/PositionsOverview.tsx index aa815b27..98411858 100644 --- a/components/Pages/Trade/Incentivize/PositionsOverview.tsx +++ b/components/Pages/Trade/Incentivize/PositionsOverview.tsx @@ -1,10 +1,9 @@ import React, { useMemo, useState } from 'react' import { Box, Button, Divider, HStack, Image, Text } from '@chakra-ui/react' -import { num } from 'libs/num' - import { useClosePosition } from 'components/Pages/Trade/Incentivize/hooks/useClosePosition' import PositionsTable from 'components/Pages/Trade/Incentivize/PositionsTable' +import { num } from 'libs/num' type Props = { flows: any[] diff --git a/components/Pages/Trade/Incentivize/hooks/useIncentivePoolInfo.ts b/components/Pages/Trade/Incentivize/hooks/useIncentivePoolInfo.ts index f057c06a..08b82851 100644 --- a/components/Pages/Trade/Incentivize/hooks/useIncentivePoolInfo.ts +++ b/components/Pages/Trade/Incentivize/hooks/useIncentivePoolInfo.ts @@ -70,7 +70,7 @@ export const useIncentivePoolInfo = ( useEffect(() => { const fetchPoolData = async () => { - currentChainPrefix = chainId === 'columbus-5' ? 'terra-classic': currentChainPrefix + currentChainPrefix = chainId === 'columbus-5' ? 'terra-classic' : currentChainPrefix const poolData = currentChainPrefix === 'terra' && chainId !== 'columbus-5' ? await getPairAprAndDailyVolumeTerra(pools) diff --git a/components/Pages/Trade/Incentivize/hooks/useOpenFlow.ts b/components/Pages/Trade/Incentivize/hooks/useOpenFlow.ts index 58ab918e..2611dea6 100644 --- a/components/Pages/Trade/Incentivize/hooks/useOpenFlow.ts +++ b/components/Pages/Trade/Incentivize/hooks/useOpenFlow.ts @@ -7,6 +7,8 @@ import { Config, useConfig, } from 'components/Pages/Dashboard/hooks/useDashboardData' +import useEpoch from 'components/Pages/Trade/Incentivize/hooks/useEpoch' +import useFactoryConfig from 'components/Pages/Trade/Incentivize/hooks/useFactoryConfig' import useSimulate from 'hooks/useSimulate' import { useTokenInfo } from 'hooks/useTokenInfo' import useTxStatus from 'hooks/useTxStatus' @@ -14,16 +16,13 @@ import { num, toChainAmount } from 'libs/num' import { usePoolFromListQueryById } from 'queries/usePoolsListQuery' import { useRecoilValue } from 'recoil' import { createAsset } from 'services/asset' +import { TerraTreasuryService } from 'services/treasuryService' import { walletState } from 'state/atoms/walletAtoms' import { createExecuteMessage, createIncreaseAllowanceMessage, } from 'util/messages/index' -import useEpoch from 'components/Pages/Trade/Incentivize/hooks/useEpoch' -import useFactoryConfig from 'components/Pages/Trade/Incentivize/hooks/useFactoryConfig' -import { TerraTreasuryService } from 'services/treasuryService' - interface Props { poolId: string token: any @@ -116,12 +115,19 @@ export const useOpenFlow = ({ poolId, token, startDate, endDate }: Props) => { }) const { mutate: submit, ...tx } = useMutation({ - mutationFn: async() => { + mutationFn: async () => { let fee = null if (chainId === 'columbus-5') { - fee = await TerraTreasuryService.getInstance().getTerraClassicIncentiveFee(amount, tokenInfo?.denom) + const gas = Math.ceil(await client.simulate( + address, msgs, '', + ) * 1.3) + fee = await TerraTreasuryService.getInstance().getTerraClassicFee( + amount, tokenInfo?.denom, gas, + ) } - return await client.post(address, msgs,null, fee) + return await client.post( + address, msgs, null, fee, + ) }, onError, onSuccess, diff --git a/components/Pages/Trade/Liquidity/Action.tsx b/components/Pages/Trade/Liquidity/Action.tsx index 5a0008df..431dae6f 100644 --- a/components/Pages/Trade/Liquidity/Action.tsx +++ b/components/Pages/Trade/Liquidity/Action.tsx @@ -1,5 +1,4 @@ import { Box, Button } from '@chakra-ui/react' - import { useClosePosition } from 'components/Pages/Trade/Liquidity/hooks/useClosePosition' import { useWithdrawPosition } from 'components/Pages/Trade/Liquidity/hooks/useWithdrawPosition' import { STATE } from 'components/Pages/Trade/Liquidity/Positions' diff --git a/components/Pages/Trade/Liquidity/Claim.tsx b/components/Pages/Trade/Liquidity/Claim.tsx index f9ebf049..fa73cae1 100644 --- a/components/Pages/Trade/Liquidity/Claim.tsx +++ b/components/Pages/Trade/Liquidity/Claim.tsx @@ -2,18 +2,17 @@ import { useMemo } from 'react' import { HStack, VStack } from '@chakra-ui/react' import { useConfig } from 'components/Pages/Dashboard/hooks/useDashboardData' +import ClaimTable from 'components/Pages/Trade/Liquidity/ClaimTable' import { useCheckIncentiveSnapshots } from 'components/Pages/Trade/Liquidity/hooks/useCheckIncentiveSnapshots' +import { useClaim } from 'components/Pages/Trade/Liquidity/hooks/useClaim' import useForceEpochAndTakingSnapshots from 'components/Pages/Trade/Liquidity/hooks/useForceEpochAndTakingSnapshots' +import useRewards from 'components/Pages/Trade/Liquidity/hooks/useRewards' import SubmitButton from 'components/SubmitButton' import { TooltipWithChildren } from 'components/TooltipWithChildren' import { useRecoilValue } from 'recoil' import { walletState } from 'state/atoms/walletAtoms' import { TxStep } from 'types/common' -import ClaimTable from 'components/Pages/Trade/Liquidity/ClaimTable' -import { useClaim } from 'components/Pages/Trade/Liquidity/hooks/useClaim' -import useRewards from 'components/Pages/Trade/Liquidity/hooks/useRewards' - const AvailableRewards = ({ totalValue }: { totalValue: number }) => ( { const router: NextRouter = useRouter() const chains: Array = useChains() diff --git a/components/Pages/Trade/Liquidity/Multiplicator.tsx b/components/Pages/Trade/Liquidity/Multiplicator.tsx index 0e6eeb63..e62f8fc0 100644 --- a/components/Pages/Trade/Liquidity/Multiplicator.tsx +++ b/components/Pages/Trade/Liquidity/Multiplicator.tsx @@ -1,7 +1,6 @@ import { HStack, VStack } from '@chakra-ui/react' -import { TooltipWithChildren } from 'components/TooltipWithChildren' - import InfoTooltip from 'components/InfoTooltip' +import { TooltipWithChildren } from 'components/TooltipWithChildren' type Props = { multiplicator: string diff --git a/components/Pages/Trade/Liquidity/Overview.tsx b/components/Pages/Trade/Liquidity/Overview.tsx index b503f962..8eda29da 100644 --- a/components/Pages/Trade/Liquidity/Overview.tsx +++ b/components/Pages/Trade/Liquidity/Overview.tsx @@ -1,9 +1,8 @@ import { useMemo } from 'react' import { Box, Text, VStack } from '@chakra-ui/react' -import useLockedPositions from 'components/Pages/Trade/Liquidity/hooks/useLockedPositions' - import { Action } from 'components/Pages/Trade/Liquidity/Action' +import useLockedPositions from 'components/Pages/Trade/Liquidity/hooks/useLockedPositions' import useRewards from 'components/Pages/Trade/Liquidity/hooks/useRewards' import { Positions } from 'components/Pages/Trade/Liquidity/Positions' import { Rewards } from 'components/Pages/Trade/Liquidity/Rewards' diff --git a/components/Pages/Trade/Liquidity/Positions.tsx b/components/Pages/Trade/Liquidity/Positions.tsx index c9f85c80..2df99de7 100644 --- a/components/Pages/Trade/Liquidity/Positions.tsx +++ b/components/Pages/Trade/Liquidity/Positions.tsx @@ -1,7 +1,6 @@ import { useState } from 'react' import { Box, Button, Divider, HStack } from '@chakra-ui/react' - import { PositionsTable } from 'components/Pages/Trade/Liquidity/PositionsTable' export enum STATE { @@ -21,23 +20,23 @@ export const Positions = ({ positions }: Props) => { const [columnFilters, setColumnFilters] = useState([]) return ( - + - {[ STATE.ALL, STATE.ACTIVE, STATE.UNBONDING, STATE.WITHDRAW ].map((item) => ( + {[STATE.ALL, STATE.ACTIVE, STATE.UNBONDING, STATE.WITHDRAW].map((item) => ( ))} - + ) diff --git a/components/Pages/Trade/Liquidity/PositionsTable.tsx b/components/Pages/Trade/Liquidity/PositionsTable.tsx index 5f178deb..43ebbdd6 100644 --- a/components/Pages/Trade/Liquidity/PositionsTable.tsx +++ b/components/Pages/Trade/Liquidity/PositionsTable.tsx @@ -22,9 +22,8 @@ import { getSortedRowModel, useReactTable, } from '@tanstack/react-table' -import { TooltipWithChildren } from 'components/TooltipWithChildren' - import { AvailableRewards } from 'components/Pages/Trade/Liquidity/AvailableRewards' +import { TooltipWithChildren } from 'components/TooltipWithChildren' type TableProps = { duration: string diff --git a/components/Pages/Trade/Liquidity/Rewards.tsx b/components/Pages/Trade/Liquidity/Rewards.tsx index 56f6894a..df9e4972 100644 --- a/components/Pages/Trade/Liquidity/Rewards.tsx +++ b/components/Pages/Trade/Liquidity/Rewards.tsx @@ -1,9 +1,8 @@ import { useMemo } from 'react' import { Divider, HStack, Text, VStack } from '@chakra-ui/react' -import { TooltipWithChildren } from 'components/TooltipWithChildren' - import { AvailableRewards } from 'components/Pages/Trade/Liquidity/AvailableRewards' +import { TooltipWithChildren } from 'components/TooltipWithChildren' export const Rewards = ({ rewards = [], totalValue, dailyEmissions = [] }) => { const totalUsdValue = useMemo(() => dailyEmissions.reduce((total, item) => total + (isNaN(item.dailyUsdEmission) ? 0 : item.dailyUsdEmission), diff --git a/components/Pages/Trade/Liquidity/WithdrawForm.tsx b/components/Pages/Trade/Liquidity/WithdrawForm.tsx index 960bc61a..2a4225ab 100644 --- a/components/Pages/Trade/Liquidity/WithdrawForm.tsx +++ b/components/Pages/Trade/Liquidity/WithdrawForm.tsx @@ -3,6 +3,8 @@ import { useForm } from 'react-hook-form' import { VStack } from '@chakra-ui/react' import Input from 'components/AssetInput/Input' +import useClaimableLP from 'components/Pages/Trade/Liquidity/hooks/useClaimableLP' +import useWithdraw, { useSimulateWithdraw } from 'components/Pages/Trade/Liquidity/hooks/useWithdraw' import ShowError from 'components/ShowError' import SubmitButton from 'components/SubmitButton' import { TxStep } from 'hooks/useTransaction' @@ -10,9 +12,6 @@ import { fromChainAmount, num, toChainAmount } from 'libs/num' import { useQueryPoolLiquidity } from 'queries/useQueryPoolsLiquidity' import { WalletStatusType } from 'state/atoms/walletAtoms' -import useClaimableLP from 'components/Pages/Trade/Liquidity/hooks/useClaimableLP' -import useWithdraw, { useSimulateWithdraw } from 'components/Pages/Trade/Liquidity/hooks/useWithdraw' - type Props = { poolId: string connected: WalletStatusType diff --git a/components/Pages/Trade/Liquidity/hooks/useDepositTransaction.tsx b/components/Pages/Trade/Liquidity/hooks/useDepositTransaction.tsx index 8fd2d9c6..69843213 100644 --- a/components/Pages/Trade/Liquidity/hooks/useDepositTransaction.tsx +++ b/components/Pages/Trade/Liquidity/hooks/useDepositTransaction.tsx @@ -191,7 +191,7 @@ export const useTransaction = ({ setTxHash(data?.transactionHash || data?.txHash) onBroadcasting?.(data?.transactionHash || data?.txHash) - await queryClient.invalidateQueries({ queryKey: ['@pool-liquidity','multipleTokenBalances','tokenBalance', 'positions'] }) + await queryClient.invalidateQueries({ queryKey: ['@pool-liquidity', 'multipleTokenBalances', 'tokenBalance', 'positions'] }) toast({ title: 'Add Liquidity Success.', diff --git a/components/Pages/Trade/Liquidity/hooks/useLockedPositions.ts b/components/Pages/Trade/Liquidity/hooks/useLockedPositions.ts index db0c5b94..aece59f5 100644 --- a/components/Pages/Trade/Liquidity/hooks/useLockedPositions.ts +++ b/components/Pages/Trade/Liquidity/hooks/useLockedPositions.ts @@ -1,5 +1,6 @@ import { useQuery } from 'react-query' +import { STATE } from 'components/Pages/Trade/Liquidity/Positions' import dayjs from 'dayjs' import usePrices from 'hooks/usePrices' import { useTokenList } from 'hooks/useTokenList' @@ -10,7 +11,6 @@ import { useRecoilValue } from 'recoil' import { walletState } from 'state/atoms/walletAtoms' import { protectAgainstNaN } from 'util/conversion/index' import { formatSeconds } from 'util/formatSeconds' -import { STATE } from 'components/Pages/Trade/Liquidity/Positions' export type Position = { poolId: string diff --git a/components/Pages/Trade/Liquidity/hooks/useProvideLP.ts b/components/Pages/Trade/Liquidity/hooks/useProvideLP.ts index 896a22ed..65259c30 100644 --- a/components/Pages/Trade/Liquidity/hooks/useProvideLP.ts +++ b/components/Pages/Trade/Liquidity/hooks/useProvideLP.ts @@ -4,6 +4,11 @@ import { Config, useConfig, } from 'components/Pages/Dashboard/hooks/useDashboardData' +import useFactoryConfig from 'components/Pages/Trade/Incentivize/hooks/useFactoryConfig' +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 { tokenLpAtom } from 'components/Pages/Trade/Liquidity/lpAtoms' import { useTokenInfo } from 'hooks/useTokenInfo' import { num, toChainAmount } from 'libs/num' import { useQueryMatchingPoolForSwap } from 'queries/useQueryMatchingPoolForSwap' @@ -11,12 +16,6 @@ import { useQueryPoolLiquidity } from 'queries/useQueryPoolsLiquidity' import { useRecoilValue } from 'recoil' import { walletState } from 'state/atoms/walletAtoms' -import useFactoryConfig from 'components/Pages/Trade/Incentivize/hooks/useFactoryConfig' -import { tokenLpAtom } from 'components/Pages/Trade/Liquidity/lpAtoms' -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' - const useProvideLP = ({ reverse = false, bondingDays = 0 }) => { const [lpTokenA, lpTokenB] = useRecoilValue(tokenLpAtom) const { address, client, network, chainId } = useRecoilValue(walletState) diff --git a/components/Pages/Trade/Liquidity/hooks/useWithdraw.ts b/components/Pages/Trade/Liquidity/hooks/useWithdraw.ts index 0081e26f..708db6f8 100644 --- a/components/Pages/Trade/Liquidity/hooks/useWithdraw.ts +++ b/components/Pages/Trade/Liquidity/hooks/useWithdraw.ts @@ -1,16 +1,15 @@ import { useMemo } from 'react' -import { num } from 'libs/num' -import { useRecoilValue } from 'recoil' -import { isNativeToken } from 'services/asset' -import { walletState } from 'state/atoms/walletAtoms' -import { protectAgainstNaN } from 'util/conversion/index' - import { createWithdrawExecuteMsgs, createWithdrawMsg, } from 'components/Pages/Trade/Liquidity/hooks/createWithdrawMsgs' import { useWithdrawTransaction } from 'components/Pages/Trade/Liquidity/hooks/useWithdrawTransaction' +import { num } from 'libs/num' +import { useRecoilValue } from 'recoil' +import { isNativeToken } from 'services/asset' +import { walletState } from 'state/atoms/walletAtoms' +import { protectAgainstNaN } from 'util/conversion/index' type Props = { amount: string diff --git a/components/Pages/Trade/Pools/AllPoolsTable.tsx b/components/Pages/Trade/Pools/AllPoolsTable.tsx index 8dc921da..bbb8fef6 100644 --- a/components/Pages/Trade/Pools/AllPoolsTable.tsx +++ b/components/Pages/Trade/Pools/AllPoolsTable.tsx @@ -22,7 +22,6 @@ import { getSortedRowModel, useReactTable, } from '@tanstack/react-table' - import { IncentiveTooltip } from 'components/InfoTooltip' import Loader from 'components/Loader' import Apr from 'components/Pages/Trade/Pools/components/Apr' diff --git a/components/Pages/Trade/Pools/Incentives.tsx b/components/Pages/Trade/Pools/Incentives.tsx index 1e0aa64a..d5d99a02 100644 --- a/components/Pages/Trade/Pools/Incentives.tsx +++ b/components/Pages/Trade/Pools/Incentives.tsx @@ -15,7 +15,6 @@ import { Thead, Tr, } from '@chakra-ui/react' - import { IncentivesLogos } from 'components/Pages/Trade/Pools/IncentivesLogos' export const Incentives = ({ flows }) => { diff --git a/components/Pages/Trade/Pools/MobilePools.tsx b/components/Pages/Trade/Pools/MobilePools.tsx index 2a756d86..dd40941b 100644 --- a/components/Pages/Trade/Pools/MobilePools.tsx +++ b/components/Pages/Trade/Pools/MobilePools.tsx @@ -1,5 +1,4 @@ import { Button, HStack, Text, VStack } from '@chakra-ui/react' - import PoolName from 'components/Pages/Trade/Pools/components/PoolName' import { Pool } from 'components/Pages/Trade/Pools/types/index' diff --git a/components/Pages/Trade/Pools/MyPoolsTable.tsx b/components/Pages/Trade/Pools/MyPoolsTable.tsx index 53e09528..cc9ff0cf 100644 --- a/components/Pages/Trade/Pools/MyPoolsTable.tsx +++ b/components/Pages/Trade/Pools/MyPoolsTable.tsx @@ -17,7 +17,6 @@ import { getCoreRowModel, useReactTable, } from '@tanstack/react-table' - import { IncentiveTooltip } from 'components/InfoTooltip' import Loader from 'components/Loader' import Apr from 'components/Pages/Trade/Pools/components/Apr' diff --git a/components/Pages/Trade/Pools/Pools.tsx b/components/Pages/Trade/Pools/Pools.tsx index 60bb089a..80ad876d 100644 --- a/components/Pages/Trade/Pools/Pools.tsx +++ b/components/Pages/Trade/Pools/Pools.tsx @@ -11,7 +11,11 @@ import { VStack, } from '@chakra-ui/react' import { useIncentivePoolInfo } from 'components/Pages/Trade/Incentivize/hooks/useIncentivePoolInfo' +import { ActionCTAs } from 'components/Pages/Trade/Pools/ActionCTAs' +import AllPoolsTable from 'components/Pages/Trade/Pools/AllPoolsTable' import { Incentives } from 'components/Pages/Trade/Pools/Incentives' +import MobilePools from 'components/Pages/Trade/Pools/MobilePools' +import MyPoolsTable from 'components/Pages/Trade/Pools/MyPoolsTable' import { ACTIVE_INCENTIVE_NETWORKS, STABLE_COIN_LIST } from 'constants/index' import { useChains } from 'hooks/useChainInfo' import { useCosmwasmClient } from 'hooks/useCosmwasmClient' @@ -30,11 +34,6 @@ import { import { WalletStatusType, walletState } from 'state/atoms/walletAtoms' import { EnigmaPoolData } from 'util/enigma' -import { ActionCTAs } from 'components/Pages/Trade/Pools/ActionCTAs' -import AllPoolsTable from 'components/Pages/Trade/Pools/AllPoolsTable' -import MobilePools from 'components/Pages/Trade/Pools/MobilePools' -import MyPoolsTable from 'components/Pages/Trade/Pools/MyPoolsTable' - type PoolData = PoolEntityTypeWithLiquidity & EnigmaPoolData & { displayName: string @@ -85,7 +84,9 @@ const Pools = () => { if (window.debugLogsEnabled) { console.log('Pools-Liquidity: ', pools) console.log('Incentive-Pool-Infos: ', incentivePoolInfos) - console.log('Loading-Info: ', isLoading, isInitLoading, pairInfos.length === 0) + console.log( + 'Loading-Info: ', isLoading, isInitLoading, pairInfos.length === 0, + ) console.log('Pools: ', pools) console.log('Pair Infos: ', pairInfos) } diff --git a/components/Pages/Trade/Swap/Swap.tsx b/components/Pages/Trade/Swap/Swap.tsx index 8560918b..2e4b81fd 100644 --- a/components/Pages/Trade/Swap/Swap.tsx +++ b/components/Pages/Trade/Swap/Swap.tsx @@ -1,6 +1,11 @@ import { FC, useEffect, useMemo, useState } from 'react' import { HStack, Text, VStack } from '@chakra-ui/react' +import defaultTokens from 'components/Pages/Trade/Swap/defaultTokens.json' +import useSwap from 'components/Pages/Trade/Swap/hooks/useSwap' +import { tokenSwapAtom } from 'components/Pages/Trade/Swap/swapAtoms' +import SwapForm from 'components/Pages/Trade/Swap/SwapForm' +import SwapSettings from 'components/Pages/Trade/Swap/SwapSettings' import { useChains } from 'hooks/useChainInfo' import { TxStep } from 'hooks/useTransaction' import { fromChainAmount } from 'libs/num' @@ -10,12 +15,6 @@ import { useRecoilState, useRecoilValue } from 'recoil' import { walletState } from 'state/atoms/walletAtoms' import { TokenItemState } from 'types/index' -import defaultTokens from 'components/Pages/Trade/Swap/defaultTokens.json' -import useSwap from 'components/Pages/Trade/Swap/hooks/useSwap' -import { tokenSwapAtom } from 'components/Pages/Trade/Swap/swapAtoms' -import SwapForm from 'components/Pages/Trade/Swap/SwapForm' -import SwapSettings from 'components/Pages/Trade/Swap/SwapSettings' - type SwapProps = { /* Will be used if provided on first render instead of internal state */ initialTokenPair?: readonly [string, string] diff --git a/components/Pages/Trade/Swap/SwapForm.tsx b/components/Pages/Trade/Swap/SwapForm.tsx index ee06c115..99efbebd 100644 --- a/components/Pages/Trade/Swap/SwapForm.tsx +++ b/components/Pages/Trade/Swap/SwapForm.tsx @@ -14,6 +14,7 @@ import { } from '@chakra-ui/react' import AssetInput from 'components/AssetInput/index' import DoubleArrowsIcon from 'components/icons/DoubleArrowsIcon' +import { Simulated } from 'components/Pages/Trade/Swap/hooks/useSimulate' import { useTokenBalance } from 'hooks/useTokenBalance' import { useTokenInfo } from 'hooks/useTokenInfo' import { TxStep } from 'hooks/useTransaction' @@ -22,8 +23,6 @@ import { usePoolsListQuery } from 'queries/usePoolsListQuery' import { WalletStatusType } from 'state/atoms/walletAtoms' import { TokenItemState } from 'types/index' -import { Simulated } from 'components/Pages/Trade/Swap/hooks/useSimulate' - type Props = { connected: WalletStatusType tokenA: TokenItemState diff --git a/components/Pages/Trade/Swap/SwapSettings.tsx b/components/Pages/Trade/Swap/SwapSettings.tsx index ea96e89d..a1dd0946 100644 --- a/components/Pages/Trade/Swap/SwapSettings.tsx +++ b/components/Pages/Trade/Swap/SwapSettings.tsx @@ -17,9 +17,8 @@ import { VStack, useBoolean, } from '@chakra-ui/react' -import { useRecoilState } from 'recoil' - import { slippageAtom } from 'components/Pages/Trade/Swap/swapAtoms' +import { useRecoilState } from 'recoil' const SwapSettings = () => { const [slippage, setSlippage] = useRecoilState(slippageAtom) diff --git a/components/Pages/Trade/Swap/hooks/directTokenSwap.ts b/components/Pages/Trade/Swap/hooks/directTokenSwap.ts index b2f0c850..7dafa832 100644 --- a/components/Pages/Trade/Swap/hooks/directTokenSwap.ts +++ b/components/Pages/Trade/Swap/hooks/directTokenSwap.ts @@ -1,13 +1,12 @@ import { coin } from '@cosmjs/stargate' import { TokenInfo } from 'queries/usePoolsListQuery' +import { TerraTreasuryService } from 'services/treasuryService' import { createExecuteMessage, createIncreaseAllowanceMessage, validateTransactionSuccess, } from 'util/messages/index' - import { Wallet } from 'util/wallet-adapters/index' -import { TerraTreasuryService } from 'services/treasuryService' type DirectTokenSwapArgs = { tokenAmount: string @@ -17,6 +16,7 @@ type DirectTokenSwapArgs = { client: Wallet msgs: Record chainId?: string + gas:number } export const directTokenSwap = async ({ @@ -27,6 +27,7 @@ export const directTokenSwap = async ({ client, msgs, chainId, + gas, }: DirectTokenSwapArgs) => { if (!tokenA.native) { const increaseAllowanceMessage = createIncreaseAllowanceMessage({ @@ -48,12 +49,19 @@ export const directTokenSwap = async ({ ])) } let fee = null + const execMsg = createExecuteMessage({ senderAddress, + contractAddress: swapAddress, + message: msgs, + funds: [coin(tokenAmount, tokenA.denom)] }) if (chainId === 'columbus-5') { - fee = await TerraTreasuryService.getInstance().getTerraClassicFee(tokenAmount, tokenA.denom) + const gas = Math.ceil(await client.simulate( + senderAddress, [execMsg], '', + ) * 1.3) + fee = await TerraTreasuryService.getInstance().getTerraClassicFee( + tokenAmount, tokenA.denom, gas, + ) } - return client.execute( - senderAddress, swapAddress, msgs, [ - coin(tokenAmount, tokenA.denom), - ],fee + return await client.post( + senderAddress, [execMsg], '', fee, ) } diff --git a/components/Pages/Trade/Swap/hooks/useSwap.ts b/components/Pages/Trade/Swap/hooks/useSwap.ts index 0f206539..a423a549 100644 --- a/components/Pages/Trade/Swap/hooks/useSwap.ts +++ b/components/Pages/Trade/Swap/hooks/useSwap.ts @@ -1,5 +1,8 @@ import { useMemo } from 'react' +import useRoute from 'components/Pages/Trade/Swap/hooks/useRoute' +import useSimulate from 'components/Pages/Trade/Swap/hooks/useSimulate' +import useTransaction from 'components/Pages/Trade/Swap/hooks/useTransaction' import { slippageAtom, tokenSwapAtom } from 'components/Pages/Trade/Swap/swapAtoms' import { useTokenInfo } from 'hooks/useTokenInfo' import { num, toChainAmount } from 'libs/num' @@ -8,10 +11,6 @@ import { usePoolsListQuery } from 'queries/usePoolsListQuery' import { useRecoilValue } from 'recoil' import { walletState } from 'state/atoms/walletAtoms' -import useRoute from 'components/Pages/Trade/Swap/hooks/useRoute' -import useSimulate from 'components/Pages/Trade/Swap/hooks/useSimulate' -import useTransaction from 'components/Pages/Trade/Swap/hooks/useTransaction' - const useSwap = ({ reverse }) => { const [swapTokenA, swapTokenB] = useRecoilValue(tokenSwapAtom) const { address, client } = useRecoilValue(walletState) diff --git a/components/Pages/Trade/Swap/hooks/useTokenSwap.tsx b/components/Pages/Trade/Swap/hooks/useTokenSwap.tsx index 8824d56e..e82ca794 100644 --- a/components/Pages/Trade/Swap/hooks/useTokenSwap.tsx +++ b/components/Pages/Trade/Swap/hooks/useTokenSwap.tsx @@ -1,6 +1,7 @@ import { toast } from 'react-hot-toast' import { useMutation } from 'react-query' +import { slippageAtom, tokenSwapAtom } from 'components/Pages/Trade/Swap/swapAtoms' import { useRefetchQueries } from 'hooks/useRefetchQueries' import { useTokenInfo } from 'hooks/useTokenInfo' // TODO: These should be deprecated in place of some other chakra component so we can remove the dep on junoblocks @@ -22,8 +23,6 @@ import { import { WalletStatusType, walletState } from 'state/atoms/walletAtoms' import { convertDenomToMicroDenom } from 'util/conversion/index' -import { slippageAtom, tokenSwapAtom } from 'components/Pages/Trade/Swap/swapAtoms' - type UseTokenSwapArgs = { tokenASymbol: string tokenBSymbol: string diff --git a/components/Pages/Trade/Swap/hooks/useTransaction.tsx b/components/Pages/Trade/Swap/hooks/useTransaction.tsx index 8723d689..fc95e538 100644 --- a/components/Pages/Trade/Swap/hooks/useTransaction.tsx +++ b/components/Pages/Trade/Swap/hooks/useTransaction.tsx @@ -3,9 +3,8 @@ import { useMutation, useQuery, useQueryClient } from 'react-query' import { useToast } from '@chakra-ui/react' import Finder from 'components/Finder' -import useDebounceValue from 'hooks/useDebounceValue' - import { directTokenSwap } from 'components/Pages/Trade/Swap/hooks/directTokenSwap' +import useDebounceValue from 'hooks/useDebounceValue' import { useRecoilValue } from 'recoil' import { walletState } from 'state/atoms/walletAtoms' @@ -74,7 +73,8 @@ export const useTransaction = ({ const [tokenA, tokenB] = swapAssets const toast = useToast() const queryClient = useQueryClient() - const {chainId} = useRecoilValue(walletState) + const { chainId } = useRecoilValue(walletState) + const [gas, setGas] = useState(0) const [txStep, setTxStep] = useState(TxStep.Idle) const [txHash, setTxHash] = useState(undefined) @@ -90,6 +90,7 @@ export const useTransaction = ({ const response = await client.simulate( senderAddress, debouncedMsgs, '', ) + setGas(response) if (buttonLabel) { setButtonLabel(null) } @@ -145,7 +146,6 @@ export const useTransaction = ({ }, }, ) - const { mutate } = useMutation(() => directTokenSwap({ tokenA, swapAddress, @@ -153,7 +153,8 @@ export const useTransaction = ({ msgs, tokenAmount: amount, client, - chainId + chainId, + gas, }), { onMutate: () => { @@ -193,7 +194,7 @@ export const useTransaction = ({ onError?.() }, - onSuccess: async(data: any) => { + onSuccess: async (data: any) => { setTxStep(TxStep.Broadcasting) setTxHash(data.transactionHash || data?.txHash) onBroadcasting?.(data.transactionHash) diff --git a/components/Pages/Trade/Swap/hooks/useTxRates.ts b/components/Pages/Trade/Swap/hooks/useTxRates.ts index 887db717..cb42ed57 100644 --- a/components/Pages/Trade/Swap/hooks/useTxRates.ts +++ b/components/Pages/Trade/Swap/hooks/useTxRates.ts @@ -1,9 +1,8 @@ +import { usePriceForOneToken } from 'components/Pages/Trade/Swap/hooks/usePriceForOneToken' import { useTokenDollarValue } from 'hooks/useTokenDollarValue' import { usePersistance } from 'junoblocks' import { protectAgainstNaN } from 'util/conversion/index' -import { usePriceForOneToken } from 'components/Pages/Trade/Swap/hooks/usePriceForOneToken' - function calculateTokenToTokenConversionRate({ tokenAAmount, tokenToTokenPrice, diff --git a/pages/api/cors.ts b/pages/api/cors.ts index bb38e3fc..00873d91 100644 --- a/pages/api/cors.ts +++ b/pages/api/cors.ts @@ -6,8 +6,10 @@ const Cors = async (req, res) => { try { const _res = await axios.get(url) res.status(200).send(_res.data) - // Add a cache of 10 seconds to avoid constantly returning the same data - // res.setHeader('Cache-Control', 's-maxage=10') + /* + * Add a cache of 10 seconds to avoid constantly returning the same data + * res.setHeader('Cache-Control', 's-maxage=10') + */ } catch (error) { res.status(400).send(error.toString()) } diff --git a/pages/index.tsx b/pages/index.tsx index 6b1805e2..d6d6915c 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -1,4 +1,2 @@ -const Index = () => { - return
-} +const Index = () =>
export default Index diff --git a/services/liquidity/executeAddLiquidity.ts b/services/liquidity/executeAddLiquidity.ts index 361cce7c..d6a76730 100644 --- a/services/liquidity/executeAddLiquidity.ts +++ b/services/liquidity/executeAddLiquidity.ts @@ -31,8 +31,11 @@ export const executeAddLiquidity = async ({ }: ExecuteAddLiquidityArgs): Promise => { let fee = null if (chainId === 'columbus-5') { + const gas = Math.ceil(await client.simulate( + senderAddress, msgs, '', + ) * 1.3) fee = await TerraTreasuryService.getInstance().getTerraClassicFeeForDeposit( - tokenAAmount, tokenA.denom, tokenBAmount, tokenB.denom, + tokenAAmount, tokenA.denom, tokenBAmount, tokenB.denom, gas, ) } return client.post( diff --git a/services/treasuryService.ts b/services/treasuryService.ts index 654a1d4a..fb42c20e 100644 --- a/services/treasuryService.ts +++ b/services/treasuryService.ts @@ -1,7 +1,7 @@ import axios from 'axios' import chains from 'public/mainnet/chain_info.json' -import { aggregateAndSortTaxAmounts } from 'util/conversion/index' import columbusConfig from 'public/mainnet/columbus-5/config.json' +import { aggregateAndSortTaxAmounts } from 'util/conversion/index' class FCDBaseClient { private readonly baseURL: string = 'https://terra-classic-lcd.publicnode.com/terra' @@ -53,51 +53,60 @@ export class TerraTreasuryService extends FCDBaseClient { return Math.ceil(Math.min(Number(amount) * Number(taxRate), Number(taxCap))) } - async getTerraClassicFee(amount: number | string, denom: string): Promise { + async getTerraClassicFee( + amount: number | string, denom: string, gas:number, + ): Promise { const terraClassic = chains.find((chain) => chain.chainId === 'columbus-5') const tax = await this.getTerraTax(amount) - const amounts = [{ - denom, - amount: tax.toString() - }, - // Passing another native token as tax to avoid error - { denom: columbusConfig.whale_base_token.denom, amount: '1' }, - { - denom: terraClassic.stakeCurrency.coinMinimalDenom, - amount: (Number(terraClassic.gasPriceStep.average) * 10 ** 6).toString() - } - ] + let amounts = [] + if (tax == 0) { + amounts = [] + } else { + amounts.push({ + denom, + amount: tax.toString(), + }) + } + amounts.push({ denom: columbusConfig.whale_base_token.denom, + amount: '1' }, + { + denom: terraClassic.stakeCurrency.coinMinimalDenom, + amount: (Math.ceil(Number(terraClassic.gasPriceStep.average) * gas)).toString(), + }) + // Passing another native token as tax to avoid error return { amount: aggregateAndSortTaxAmounts(amounts), - gas: '1000000' + gas: String(gas), } } - async getTerraClassicIncentiveFee(amount: number | string, denom: string): Promise { + async getTerraClassicIncentiveFee( + amount: number | string, denom: string, gas:number, + ): Promise { const terraClassic = chains.find((chain) => chain.chainId === 'columbus-5') const tax = await this.getTerraTax(amount) const whaleTax = await this.getTerraTax('1000000000') const amounts = [{ denom, - amount: tax.toString() + amount: tax.toString(), + }, + { + denom: columbusConfig.whale_base_token.denom, + amount: whaleTax.toString(), + }, + { + denom: terraClassic.stakeCurrency.coinMinimalDenom, + amount: (Math.ceil(Number(terraClassic.gasPriceStep.average) * gas)).toString(), }, - { - denom: columbusConfig.whale_base_token.denom, - amount: whaleTax.toString() - }, - { - denom: terraClassic.stakeCurrency.coinMinimalDenom, - amount: (Number(terraClassic.gasPriceStep.average) * 10 ** 6).toString() - } ] return { amount: aggregateAndSortTaxAmounts(amounts), - gas: '1000000' + gas: String(gas), } } async getTerraClassicFeeForDeposit( - amountA: number | string, denomA: string, amountB: number | string, denomB: string + amountA: number | string, denomA: string, amountB: number | string, denomB: string, gas:number, ): Promise { const terraClassic = chains.find((chain) => chain.chainId === 'columbus-5') const taxA = await this.getTerraTax(amountA) @@ -105,21 +114,21 @@ export class TerraTreasuryService extends FCDBaseClient { const amounts = [ { denom: denomA, - amount: taxA.toString() + amount: taxA.toString(), }, { denom: denomB, - amount: taxB.toString() + amount: taxB.toString(), }, { denom: terraClassic.stakeCurrency.coinMinimalDenom, - amount: (Number(terraClassic.gasPriceStep.average) * 10 ** 6).toString() - } + amount: (Math.ceil(Number(terraClassic.gasPriceStep.average) * gas)).toString(), + }, ] return { amount: aggregateAndSortTaxAmounts(amounts), - gas: '1000000' + gas: String(gas), } } diff --git a/util/conversion/conversion.ts b/util/conversion/conversion.ts index 0a4f7c6d..0522650f 100644 --- a/util/conversion/conversion.ts +++ b/util/conversion/conversion.ts @@ -87,14 +87,13 @@ export const calculateDurationString = (durationInMilli: number): string => { } export const nanoToMilli = (nano: number) => nano / 1_000_000 - -export const aggregateAndSortTaxAmounts = (amounts: { denom: string, amount: string }[])=>amounts.reduce((acc, cur) => { - const existingAmount = acc.find((a) => a.denom === cur.denom); - if (existingAmount) { - existingAmount.amount = (parseFloat(existingAmount.amount) + parseFloat(cur.amount)).toString(); - } else { - acc.push(cur); - } - return acc; - }, [] as { denom: string, amount: string }[]).sort((a,b)=> a.denom.localeCompare(b.denom)); +export const aggregateAndSortTaxAmounts = (amounts: { denom: string, amount: string }[]) => amounts.reduce((acc, cur) => { + const existingAmount = acc.find((a) => a.denom === cur.denom); + if (existingAmount) { + existingAmount.amount = (parseFloat(existingAmount.amount) + parseFloat(cur.amount)).toString(); + } else { + acc.push(cur); + } + return acc; +}, [] as { denom: string, amount: string }[]).sort((a, b) => a.denom.localeCompare(b.denom)); diff --git a/util/enigma.ts b/util/enigma.ts index 5a77e312..20697c8c 100644 --- a/util/enigma.ts +++ b/util/enigma.ts @@ -78,7 +78,9 @@ export const getPairAprAndDailyVolume = async (pools: any[], // @ts-ignore if (window.debugLogsEnabled) { - console.log('Raw Pair Infos for ',chainPrefix, ': ', pairInfos) + console.log( + 'Raw Pair Infos for ', chainPrefix, ': ', pairInfos, + ) } if (pairInfos.length > 0) {