Skip to content

Commit

Permalink
Feat/terra classic integration (White-Whale-Defi-Platform#360)
Browse files Browse the repository at this point in the history
* feat(terra-classic-integration): added chain config

* feat(terra-classic-integration): added configs, logos and integrated tax calculation

* feat(terra-classic-integration): link fixes and pool styling improvements

* feat(terra-classic-integration): debug commit

* feat(terra-classic-integration): debug commit

* feat(terra-classic-integration): debug commit

* feat(terra-classic-integration): debug commit

* feat(terra-classic-integration): debug commit

* feat(terra-classic-integration): debug commit

* feat(terra-classic-integration): undo debug changes

* feat(terra-classic-integration): swap tax calc

* feat(terra-classic-integration): fixed ustc related operations

* feat(terra-classic-integration): sorting by denoms in fees

* feat(terra-classic-integration): enabled incentives and added fee calc for incentive creation

* feat(terra-classic-integration): fix

* feat(terra-classic-integration): removed cors header

* Update networks.ts

---------

Co-authored-by: Sen Com <[email protected]>
  • Loading branch information
worrex and Sen-Com authored Aug 31, 2023
1 parent beed867 commit 7db0f73
Show file tree
Hide file tree
Showing 46 changed files with 668 additions and 117 deletions.
4 changes: 4 additions & 0 deletions components/Finder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ const getUrl = (chainId, txHash) => {
return `https://explorer.injective.network/transaction/${txHash}`
case 'comdex-1':
return `https://mintscan.io/comdex/txs/${txHash}`
case 'pacific-1':
return `https://ping.pub/sei/tx/${txHash}`
case 'columbus-5':
return `https://ping.pub/terra-luna/tx/${txHash}`
default:
return null
}
Expand Down
10 changes: 5 additions & 5 deletions components/InfoTooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { InfoOutlineIcon } from '@chakra-ui/icons'
import { Box, Icon, Tooltip } from '@chakra-ui/react'

const InfoTooltip = ({ IconSize, description }) => (
const InfoTooltip = ({ iconSize, description }) => (
<Tooltip
label={
<Box
Expand All @@ -23,14 +23,14 @@ const InfoTooltip = ({ IconSize, description }) => (
closeOnClick={false}
arrowSize={0}
>
<Icon as={InfoOutlineIcon} blockSize={IconSize} color={'white'} />
<Icon as={InfoOutlineIcon} blockSize={iconSize} color={'white'} />
</Tooltip>
)
export const IncentiveTooltip = ({ IconSize }) => (
export const IncentiveTooltip = ({ iconSize }) => (
<InfoTooltip
IconSize={IconSize}
iconSize={iconSize}
description={
'The Incentive Flow Creator can close their flows anytime. All unclaimed tokens will be clawed back.'
'The incentive flow creator can close their flows anytime. All unclaimed tokens will be clawed back.'
}
/>
)
Expand Down
5 changes: 5 additions & 0 deletions components/Layout/RadialGradient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ const backgrounds = {
'linear-gradient(90deg, rgba(60, 205, 100, 0.25) 2.83%, rgba(43, 68, 46, 0.50) 97.47%)',
'migaloo-1':
'linear-gradient(90deg, rgba(60, 205, 100, 0.25) 2.83%, rgba(43, 68, 46, 0.50) 97.47%)',
'columbus-5':
'linear-gradient(90deg, rgba(60, 205, 100, 0.25) 2.83%, rgba(255, 255, 0, 0.25) 50%, rgba(0, 117, 255, 0.25) 97.47%)',
'rebel-2':
'linear-gradient(90deg, rgba(60, 205, 100, 0.25) 2.83%, rgba(255, 255, 0, 0.25) 50%, rgba(0, 117, 255, 0.25) 97.47%)',

}

const RadialGradient: FC = () => {
Expand Down
26 changes: 26 additions & 0 deletions components/Navbar/LUNCNavMenu.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[
{
"label": "Dashboard",
"isExternal" : false,
"link": "/dashboard"
},
{
"label": "Trade",
"isExternal" : false,
"children": [
{
"label": "Swap",
"link": "/swap"
},
{
"label": "Pools",
"link": "/pools"
}
]
},
{
"label": "Bridge",
"isExternal" : true,
"link": "https://tfm.com/bridge"
}
]
16 changes: 9 additions & 7 deletions components/Navbar/Logo.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
import React from 'react'

import { HStack, Image, Text } from '@chakra-ui/react'
import Link from 'next/link'
import { useRecoilState } from 'recoil'
import { walletState } from 'state/atoms/walletAtoms'
import { useRouter } from 'next/router'

const Logo = () => {
const [currentWalletState, setCurrentWalletState] =
useRecoilState(walletState)
const router = useRouter()
return (
<HStack alignItems="center">
<Link href="/">
<a
onClick={() => setCurrentWalletState({
...currentWalletState,
chainId: 'migaloo-1',
})
onClick={async() => {
setCurrentWalletState({
...currentWalletState,
chainId: 'migaloo-1'
})
await router.push('/migaloo/swap')
}
}
>
<Image src="/img/logo.svg" alt="WhiteWhale Logo" boxSize={[8, 12]} />
</a>
</Link>
<HStack display={['none', 'flex']}>
<Text pl={2} fontSize="26" fontWeight="400">
White
Expand Down
3 changes: 2 additions & 1 deletion components/Navbar/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import WalletModal from '../Wallet/Modal/Modal'
import Wallet from '../Wallet/Wallet'
import DrawerLink from './DrawerLink'
import Logo from './Logo'
import luncMenuLinks from './LUNCNavMenu.json'
import NavbarPopper from './NavbarPopper'
import bondingDisabledMenuLinks from './NavBondingDisabledMenu.json'
import menuLinks from './NavMenu.json'
Expand Down Expand Up @@ -102,7 +103,7 @@ const Navbar = () => {
<Logo />
</Box>
<Card paddingX={10} gap={6}>
{(ACTIVE_BONDING_NETWORKS.includes(chainId)
{(chainId === 'columbus-5' ? luncMenuLinks : ACTIVE_BONDING_NETWORKS.includes(chainId)
? menuLinks
: bondingDisabledMenuLinks
).map((menu) => (
Expand Down
2 changes: 1 addition & 1 deletion components/Pages/BondingActions/Bond.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const Bond = ({ balances, tokenSymbols }) => {
currentBondState,
},
})
const currentTokenBalance = useMemo(() => tokenBalances?.find((balance) => balance.tokenSymbol === currentBondState.tokenSymbol).amount,
const currentTokenBalance = useMemo(() => tokenBalances?.find((balance) => balance.tokenSymbol === currentBondState.tokenSymbol)?.amount,
[tokenBalances, currentBondState.tokenSymbol])
return (
<VStack px={7} width="full">
Expand Down
8 changes: 7 additions & 1 deletion components/Pages/BondingActions/hooks/bondTokens.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { coin } from '@cosmjs/stargate'
import { Config } from 'components/Pages/Dashboard/hooks/useDashboardData'
import { TerraTreasuryService } from 'services/treasuryService'
import { Wallet } from 'util/wallet-adapters'

export const bondTokens = async (
Expand All @@ -8,6 +9,7 @@ export const bondTokens = async (
amount: number,
denom: string,
config: Config,
chainId?: string,
) => {
const handleMsg = {
bond: {
Expand All @@ -21,9 +23,13 @@ export const bondTokens = async (
},
},
}
let fee = null
if (chainId === 'columbus-5') {
fee = await TerraTreasuryService.getInstance().getTerraClassicFee(amount, denom)
}
return client.execute(
address, config.whale_lair, handleMsg, [
coin(amount, denom),
],
], fee,
)
}
3 changes: 2 additions & 1 deletion components/Pages/BondingActions/hooks/useTransaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useMutation, useQuery } from 'react-query'

import { useToast } from '@chakra-ui/react'
import Finder from 'components/Finder'
import { claimRewards } from 'components/Pages/BondingActions/hooks/claimRewards'
import { createNewEpoch } from 'components/Pages/BondingActions/hooks/createNewEpoch'
import {
Config,
Expand All @@ -13,7 +14,6 @@ import { walletState } from 'state/atoms/walletAtoms'
import { convertDenomToMicroDenom } from 'util/conversion'

import { ActionType } from '../../Dashboard/BondingOverview'
import { claimRewards } from '../../Dashboard/hooks/claimRewards'
import { bondTokens } from './bondTokens'
import { unbondTokens } from './unbondTokens'
import { withdrawTokens } from './withdrawTokens'
Expand Down Expand Up @@ -130,6 +130,7 @@ export const useTransaction = () => {
adjustedAmount,
data.denom,
config,
chainId,
)
} else if (data.bondingAction === ActionType.unbond) {
return unbondTokens(
Expand Down
3 changes: 2 additions & 1 deletion components/Pages/Incentivize/hooks/useIncentivePoolInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ export const useIncentivePoolInfo = (

useEffect(() => {
const fetchPoolData = async () => {
currentChainPrefix = chainId === 'columbus-5' ? 'terra-classic': currentChainPrefix
const poolData =
currentChainPrefix === 'terra'
currentChainPrefix === 'terra' && chainId !== 'columbus-5'
? await getPairAprAndDailyVolumeTerra(pools)
: await getPairAprAndDailyVolume(pools, currentChainPrefix)
setPoolsWithAprAnd24HrVolume(poolData)
Expand Down
11 changes: 9 additions & 2 deletions components/Pages/Incentivize/hooks/useOpenFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {

import useEpoch from './useEpoch'
import useFactoryConfig from './useFactoryConfig'
import { TerraTreasuryService } from 'services/treasuryService'

interface Props {
poolId: string
Expand Down Expand Up @@ -81,7 +82,7 @@ export const useOpenFlow = ({ poolId, token, startDate, endDate }: Props) => {
/* Increase allowance for each non-native token */
if (!tokenInfo?.native) {
increaseAllowanceMessages.push(createIncreaseAllowanceMessage({
tokenAmount: Number(amount),
tokenAmount: amount,
tokenAddress: tokenInfo?.denom,
senderAddress: address,
swapAddress: pool?.staking_address,
Expand Down Expand Up @@ -115,7 +116,13 @@ export const useOpenFlow = ({ poolId, token, startDate, endDate }: Props) => {
})

const { mutate: submit, ...tx } = useMutation({
mutationFn: () => client.post(address, msgs),
mutationFn: async() => {
let fee = null
if (chainId === 'columbus-5') {
fee = await TerraTreasuryService.getInstance().getTerraClassicIncentiveFee(amount, tokenInfo?.denom)
}
return await client.post(address, msgs, fee)
},
onError,
onSuccess,
onMutate,
Expand Down
26 changes: 10 additions & 16 deletions components/Pages/Liquidity/hooks/useDepositTransaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { useMutation, useQuery, useQueryClient } from 'react-query'
import { useToast } from '@chakra-ui/react'
import Finder from 'components/Finder'
import useDebounceValue from 'hooks/useDebounceValue'
import { useRecoilValue } from 'recoil'
import { executeAddLiquidity } from 'services/liquidity'
import { walletState } from 'state/atoms/walletAtoms'
import { TxStep } from 'types/common'

type Params = {
Expand All @@ -28,16 +30,13 @@ type Params = {
}

export const useTransaction = ({
poolId,
enabled,
swapAddress,
swapAssets,
client,
senderAddress,
msgs,
encodedMsgs,
amount,
price,
tokenAAmount,
tokenBAmount,
onBroadcasting,
Expand All @@ -47,7 +46,7 @@ export const useTransaction = ({
const debouncedMsgs = useDebounceValue(encodedMsgs, 200)
const [tokenA, tokenB] = swapAssets
const toast = useToast()

const { chainId } = useRecoilValue(walletState)
const [txStep, setTxStep] = useState<TxStep>(TxStep.Idle)
const [txHash, setTxHash] = useState<string | undefined>(undefined)
const [error, setError] = useState<unknown | null>(null)
Expand Down Expand Up @@ -124,15 +123,16 @@ export const useTransaction = ({
},
)

const { mutate } = useMutation((data: any) => executeAddLiquidity({
const { mutate } = useMutation(() => executeAddLiquidity({
tokenA,
tokenB,
tokenAAmount,
maxTokenBAmount: tokenBAmount,
tokenBAmount,
client,
swapAddress,
senderAddress,
msgs: encodedMsgs,
chainId,
}),
{
onMutate: () => {
Expand Down Expand Up @@ -186,15 +186,12 @@ export const useTransaction = ({

onError?.()
},
onSuccess: (data: any) => {
onSuccess: async (data: any) => {
setTxStep(TxStep.Broadcasting)
setTxHash(data?.transactionHash || data?.txHash)
onBroadcasting?.(data?.transactionHash || data?.txHash)

queryClient.invalidateQueries({ queryKey: ['@pool-liquidity'] })
queryClient.invalidateQueries({ queryKey: ['multipleTokenBalances'] })
queryClient.invalidateQueries({ queryKey: ['tokenBalance'] })
queryClient.invalidateQueries({ queryKey: ['positions'] })
await queryClient.invalidateQueries({ queryKey: ['@pool-liquidity','multipleTokenBalances','tokenBalance', 'positions'] })

toast({
title: 'Add Liquidity Success.',
Expand Down Expand Up @@ -239,11 +236,8 @@ export const useTransaction = ({
return
}

mutate({
msgs,
fee,
})
}, [msgs, fee, mutate, price])
mutate()
}, [msgs, fee, mutate])

useEffect(() => {
if (txInfo != null && txHash != null) {
Expand Down
2 changes: 1 addition & 1 deletion components/Pages/Pools/AllPoolsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const columns = [
columnHelper.accessor('incentives', {
header: () => (
<HStack paddingTop={'4'}>
<IncentiveTooltip IconSize={'3'} />
<IncentiveTooltip iconSize={'3'} />
<Text align="left" color="brand.50">
{'Incentives'}
</Text>
Expand Down
4 changes: 2 additions & 2 deletions components/Pages/Pools/MyPoolsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ const columns = [
}),
columnHelper.accessor('incentives', {
header: () => (
<HStack paddingTop={'4'}>
<IncentiveTooltip IconSize={'3'} />
<HStack>
<IncentiveTooltip iconSize={'3'} />
<Text align="left" color="brand.50">
{'Incentives'}
</Text>
Expand Down
15 changes: 9 additions & 6 deletions components/Pages/Pools/Pools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,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('Pools: ', pools)
console.log('Pair Infos: ', pairInfos)
}

const calculateMyPosition = (pool) => {
Expand Down Expand Up @@ -227,16 +230,16 @@ const Pools = () => {
const allPoolsForShown = useMemo(() => allPools?.filter((item) => !myPoolsId?.includes(item.pool)),
[allPools, myPoolsId])
const parseLiquidity = (liqString) => {
const value = parseFloat(liqString.replace(/[^\d.-]/g, ''))
const value = parseFloat(liqString?.replace(/[^\d.-]/g, ''))
/*
* We do this mutation because by now we already have modified the string to include a letter abbreviation
* if the liquidity goes over 1000
* If its in the thousands, multiple the value by 1000, if the millions 1000000
* If it's in the thousands, multiply the value by 1000, if millions 1000000
*/
return liqString.toUpperCase().includes('K')
? value * 1000
: liqString.toUpperCase().includes('M')
? value * 1000000
return liqString?.toUpperCase().includes('K')
? value * 1_000
: liqString?.toUpperCase().includes('M')
? value * 1_000_000
: value
}
const showAllPoolsList = useMemo(() => {
Expand Down
1 change: 0 additions & 1 deletion components/Pages/Swap/SwapForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,6 @@ const SwapForm: FC<Props> = ({
balance={tokenBBalance}
disabled={isInputDisabled}
showBalanceSlider={false}
// OnInputFocus={() => setIsReverse(true)}
onChange={(value, isTokenChange) => {
if (tokenB?.tokenSymbol && !isTokenChange) {
setReverse(true)
Expand Down
Loading

0 comments on commit 7db0f73

Please sign in to comment.