Skip to content

Commit

Permalink
Feature/chihuahua integration (#267)
Browse files Browse the repository at this point in the history
* feature(chihuahua-integration): incentives and bonding

Restructured chain config for bonding and incentives

* feature(chihuahua-integration): checks included

Do not show Force Epoch button if genesis time havent been reached

Do not show take snapshots when wallet not connected

* feature(chihuahua-integration): retrieving new cosmwasm client when switching chain in useCosmwasmClient.ts

Clear cache of queryClient when switching chain

* feature(chihuahua-integration): disabling incentives
  • Loading branch information
worrex authored Jun 23, 2023
1 parent 9db2c58 commit d71ee1c
Show file tree
Hide file tree
Showing 46 changed files with 248 additions and 306 deletions.
15 changes: 9 additions & 6 deletions components/Pages/BondingActions/BondingActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import {
useConfig,
useDashboardData,
} from '../Dashboard/hooks/useDashboardData'
import { usePriceForOneToken } from 'features/swap/index'
import { BondingActionTooltip } from 'components/Pages/BondingActions/BondingAcionTooltip'
import usePrices from 'hooks/usePrices'

export enum WhaleTokenType {
ampWHALE,
Expand Down Expand Up @@ -66,11 +66,14 @@ const BondingActions = ({ globalAction }) => {

const { balance: liquidBWhale } = useTokenBalance(B_WHALE_TOKEN_SYMBOL)

const whalePrice =
usePriceForOneToken({
tokenASymbol: 'WHALE',
tokenBSymbol: 'axlUSDC',
})[0] || 0
const prices = usePrices()

const whalePrice = useMemo(() => {
if (prices && prices['WHALE']) {
return prices['WHALE']
}
return 0 // Default value
}, [prices])

const {
bondedAmpWhale,
Expand Down
2 changes: 1 addition & 1 deletion components/Pages/BondingActions/Withdraw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const Withdraw = ({
}

const TokenBox = ({ label, ampWhale, bWhale }) => {
const dollarValue = ((ampWhale + bWhale) * whalePrice).toLocaleString()
const dollarValue = ((ampWhale + bWhale) * whalePrice).toFixed(2)
return (
<Box
border="0.5px solid"
Expand Down
2 changes: 1 addition & 1 deletion components/Pages/BondingActions/hooks/bondTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const bondTokens = async (
},
},
}
return client.execute(address, config.whale_lair_address, handleMsg, [
return client.execute(address, config.whale_lair, handleMsg, [
coin(amount, denom),
])
}
2 changes: 1 addition & 1 deletion components/Pages/BondingActions/hooks/createNewEpoch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export const createNewEpoch = async (
const handleMsg = {
new_epoch: {},
}
return client.execute(address, config.fee_distributor_address, handleMsg)
return client.execute(address, config.fee_distributor, handleMsg)
}
2 changes: 1 addition & 1 deletion components/Pages/BondingActions/hooks/unbondTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ export const unbondTokens = (
},
},
}
return client.execute(address, config.whale_lair_address, handleMsg)
return client.execute(address, config.whale_lair, handleMsg)
}
2 changes: 1 addition & 1 deletion components/Pages/BondingActions/hooks/withdrawTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ export const withdrawTokens = (
denom: denom,
},
}
return client.execute(address, config.whale_lair_address, handleMsg)
return client.execute(address, config.whale_lair, handleMsg)
}
17 changes: 10 additions & 7 deletions components/Pages/Dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC, useEffect, useState } from 'react'
import { FC, useEffect, useMemo, useState } from 'react'
import { Flex, HStack, Text, VStack } from '@chakra-ui/react'
import BondingOverview, { ActionType, TokenType } from './BondingOverview'
import RewardsComponent from './RewardsComponent'
Expand All @@ -13,7 +13,7 @@ import {
B_WHALE_TOKEN_SYMBOL,
WHALE_TOKEN_SYMBOL,
} from 'constants/bonding_contract'
import { usePriceForOneToken } from 'features/swap/index'
import usePrices from 'hooks/usePrices'

const Dashboard: FC = () => {
const [{ chainId, status, client, address, network }] =
Expand Down Expand Up @@ -105,11 +105,14 @@ const Dashboard: FC = () => {
setValues(TokenType.withdrawable, ampWhale + bWhale, null, ampWhale, bWhale)
}

const whalePrice =
usePriceForOneToken({
tokenASymbol: 'WHALE',
tokenBSymbol: 'axlUSDC',
})[0] || 0
const prices = usePrices()

const whalePrice = useMemo(() => {
if (prices && prices['WHALE']) {
return prices['WHALE']
}
return 0 // Default value
}, [prices])

const { balance: liquidWhale } = useTokenBalance(WHALE_TOKEN_SYMBOL)
const { balance: liquidAmpWhale } = useTokenBalance(AMP_WHALE_TOKEN_SYMBOL)
Expand Down
22 changes: 15 additions & 7 deletions components/Pages/Dashboard/RewardsComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ import { ActionType } from './BondingOverview'
import useTransaction, { TxStep } from '../BondingActions/hooks/useTransaction'
import { BondingActionTooltip } from 'components/Pages/BondingActions/BondingAcionTooltip'
import { RewardsTooltip } from 'components/Pages/Dashboard/RewardsTooltip'
import { useIncentiveConfig } from 'components/Pages/Incentivize/hooks/useIncentiveConfig'
import useForceEpochAndTakingSnapshots from 'components/Pages/Liquidity/hooks/useForceEpochAndTakingSnapshots'
import {
Config,
useConfig,
} from 'components/Pages/Dashboard/hooks/useDashboardData'

const pulseAnimation = keyframes`
0% {
Expand Down Expand Up @@ -123,7 +126,7 @@ const RewardsComponent = ({
} = useDisclosure()

const claimableRewards = useMemo(
() => totalGlobalClaimable * Number(weightInfo?.share),
() => totalGlobalClaimable * Number(weightInfo?.share || 0),
[totalGlobalClaimable, weightInfo]
)

Expand All @@ -147,7 +150,8 @@ const RewardsComponent = ({

const { txStep, submit } = useTransaction()

const { config } = useIncentiveConfig(network, chainId)
const config: Config = useConfig(network, chainId)

const forceEpochAndTakeSnapshots = useForceEpochAndTakingSnapshots({
noSnapshotTakenAddresses: null,
config: config,
Expand Down Expand Up @@ -181,6 +185,10 @@ const RewardsComponent = ({
100
)

const bondingHasStarted: boolean = useMemo(() => {
return genesisStartTimeInNano / 1_000_000 < Date.now()
}, [genesisStartTimeInNano])

return (
<>
{isLoading ? (
Expand All @@ -190,7 +198,7 @@ const RewardsComponent = ({
borderRadius={borderRadius}
minH={320}
w={450}
gap={4}
gap={3}
overflow="hidden"
position="relative"
display="flex"
Expand Down Expand Up @@ -238,7 +246,7 @@ const RewardsComponent = ({
<Text fontSize={20}>WHALE</Text>
</HStack>
<Text color="#7CFB7D" fontSize={18}>
${whalePrice.toFixed(6)}
${whalePrice?.toFixed(6)}
</Text>
</HStack>
<VStack>
Expand Down Expand Up @@ -272,7 +280,7 @@ const RewardsComponent = ({
: 'n/a'
}
isWalletConnected={isWalletConnected}
whale={claimableRewards}
whale={claimableRewards.toFixed(6)}
/>
</HStack>
<HStack>
Expand Down Expand Up @@ -324,7 +332,7 @@ const RewardsComponent = ({
>
{buttonLabel}
</Button>
{progress === 100 && isWalletConnected && (
{progress === 100 && isWalletConnected && bondingHasStarted && (
<Tooltip
label="Community driven enforcement of the next epoch."
borderRadius={10}
Expand Down
2 changes: 1 addition & 1 deletion components/Pages/Dashboard/hooks/claimRewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export const claimRewards = (
const handleMsg = {
claim: {},
}
return client.execute(address, config.fee_distributor_address, handleMsg)
return client.execute(address, config.fee_distributor, handleMsg)
}
2 changes: 1 addition & 1 deletion components/Pages/Dashboard/hooks/getBonded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const fetchBonded = async (
config: Config
): Promise<BondedInfo> => {
const result: JsonObject = await client.queryContractSmart(
config.whale_lair_address,
config.whale_lair,
{
bonded: { address: address },
}
Expand Down
2 changes: 1 addition & 1 deletion components/Pages/Dashboard/hooks/getBondingConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const fetchConfig = async (
config: Config
): Promise<BondingContractConfig> => {
const result: JsonObject = await client.queryContractSmart(
config.whale_lair_address,
config.whale_lair,
{
config: {},
}
Expand Down
2 changes: 1 addition & 1 deletion components/Pages/Dashboard/hooks/getClaimable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const fetchClaimableData = async (
config: Config
): Promise<Data> => {
const result: JsonObject = await client.queryContractSmart(
config.fee_distributor_address,
config.fee_distributor,
{
claimable: { address: address },
}
Expand Down
2 changes: 1 addition & 1 deletion components/Pages/Dashboard/hooks/getClaimableEpochs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const fetchClaimableEpoch = async (
config: Config
): Promise<Data> => {
const result: JsonObject = await client.queryContractSmart(
config.fee_distributor_address,
config.fee_distributor,
{
claimable_epochs: {},
}
Expand Down
4 changes: 2 additions & 2 deletions components/Pages/Dashboard/hooks/getCurrentEpoch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export const fetchCurrentEpoch = async (
client: Wallet,
config: Config
): Promise<Epoch> => {
const result: JsonObject = await client.queryContractSmart(
config.fee_distributor_address,
const result: JsonObject = await client?.queryContractSmart(
config.fee_distributor,
{
current_epoch: {},
}
Expand Down
70 changes: 0 additions & 70 deletions components/Pages/Dashboard/hooks/getEpochById.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const fetchConfig = async (
config: Config
): Promise<FeeDistributionConfig> => {
const result: JsonObject = await client.queryContractSmart(
config.fee_distributor_address,
config.fee_distributor,
{
config: {},
}
Expand Down
2 changes: 1 addition & 1 deletion components/Pages/Dashboard/hooks/getTotalBonded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const fetchTotalBonded = async (
config: Config
): Promise<TotalBondedInfo> => {
const result: JsonObject = await client.queryContractSmart(
config.whale_lair_address,
config.whale_lair,
{
total_bonded: {},
}
Expand Down
2 changes: 1 addition & 1 deletion components/Pages/Dashboard/hooks/getUnbonding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const fetchUnbonding = async (
): Promise<UnbondingInfo[]> => {
const results: UnbondingInfo[] = await Promise.all(
Object.entries(config.lsd_token).map(async ([key, token]) => {
return await client.queryContractSmart(config.whale_lair_address, {
return await client.queryContractSmart(config.whale_lair, {
unbonding: { address: address, denom: token.denom },
})
})
Expand Down
2 changes: 1 addition & 1 deletion components/Pages/Dashboard/hooks/getWeight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const fetchWeight = async (
config: Config
): Promise<WeightInfo> => {
const result: JsonObject = await client.queryContractSmart(
config.whale_lair_address,
config.whale_lair,
{
weight: { address: address },
}
Expand Down
2 changes: 1 addition & 1 deletion components/Pages/Dashboard/hooks/getWithdrawable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const fetchWithdrawable = async (
): Promise<WithdrawableInfo[]> => {
const results = await Promise.all(
Object.entries(config.lsd_token).map(async ([key, token]) => {
return await client.queryContractSmart(config.whale_lair_address, {
return await client.queryContractSmart(config.whale_lair, {
withdrawable: { address: address, denom: token.denom },
})
})
Expand Down
11 changes: 6 additions & 5 deletions components/Pages/Dashboard/hooks/useDashboardData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ export interface TokenDetails {
}

export interface Config {
whale_lair_address: string
fee_distributor_address: string
whale_lair: string
fee_distributor: string
incentive_factory: string
frontend_helper: string

whale_base_token: TokenDetails
lsd_token: {
ampWHALE: TokenDetails
Expand All @@ -37,9 +40,7 @@ export const useConfig = (network: string, chainId: string) => {
// Only execute if network and chainId are defined
const fetchConfig = async () => {
try {
const response = await fetch(
`/${network}/${chainId}/bonding_config.json`
)
const response = await fetch(`/${network}/${chainId}/config.json`)
const json: Config = await response.json()
setConfig(json)
} catch (error) {
Expand Down
Loading

0 comments on commit d71ee1c

Please sign in to comment.