Skip to content

Commit

Permalink
Merge pull request #1989 from galacticcouncil/rococo
Browse files Browse the repository at this point in the history
Rococo => prod
  • Loading branch information
DuriSK authored Dec 23, 2024
2 parents 3320112 + de38544 commit c5f705f
Show file tree
Hide file tree
Showing 57 changed files with 1,434 additions and 1,676 deletions.
2 changes: 1 addition & 1 deletion .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ VITE_STABLECOIN_ASSET_ID=10
VITE_FF_DISPLAY_ASSET_ENABLED=true
VITE_FF_ADD_TOKEN=true
VITE_REFERENDUM_LINK=https://hydration.subsquare.io/democracy/referendum
VITE_REFERENDUM_DATA_URL=https://hydration.subsquare.io/api/democracy/referendums
VITE_REFERENDUM_DATA_URL=https://hydration.subsquare.io/api/gov2/referendums
VITE_EVM_CHAIN_ID=222222
VITE_EVM_NATIVE_ASSET_ID=20
VITE_MIGRATION_TRIGGER_DOMAIN="deploy-preview-1334--testnet-hydra-app.netlify.app"
Expand Down
2 changes: 1 addition & 1 deletion .env.production
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ VITE_STABLECOIN_ASSET_ID=10
VITE_FF_DISPLAY_ASSET_ENABLED=false
VITE_FF_ADD_TOKEN=true
VITE_REFERENDUM_LINK=https://hydration.subsquare.io/democracy/referendum
VITE_REFERENDUM_DATA_URL=https://hydration.subsquare.io/api/democracy/referendums
VITE_REFERENDUM_DATA_URL=https://hydration.subsquare.io/api/gov2/referendums
VITE_EVM_CHAIN_ID=222222
VITE_EVM_NATIVE_ASSET_ID=20
VITE_MIGRATION_TRIGGER_DOMAIN="app.hydradx.io"
Expand Down
2 changes: 1 addition & 1 deletion .env.rococo
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ VITE_STABLECOIN_ASSET_ID=10
VITE_FF_DISPLAY_ASSET_ENABLED=false
VITE_FF_ADD_TOKEN=false
VITE_REFERENDUM_LINK=https://hydration.subsquare.io/democracy/referendum
VITE_REFERENDUM_DATA_URL=https://hydration.subsquare.io/api/democracy/referendums
VITE_REFERENDUM_DATA_URL=https://hydration.subsquare.io/api/gov2/referendums
VITE_EVM_CHAIN_ID=
VITE_EVM_NATIVE_ASSET_ID=20
VITE_MIGRATION_TRIGGER_DOMAIN=""
Expand Down
90 changes: 88 additions & 2 deletions src/api/democracy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ import { QUERY_KEYS } from "utils/queryKeys"
import { useAccount } from "sections/web3-connect/Web3Connect.utils"
import { useRpcProvider } from "providers/rpcProvider"
import { undefinedNoop } from "utils/helpers"
import { PalletDemocracyVoteAccountVote } from "@polkadot/types/lookup"
import BN from "bignumber.js"
import {
PalletDemocracyVoteAccountVote,
PalletReferendaReferendumStatus,
PalletReferendaCurve,
} from "@polkadot/types/lookup"
import BN, { BigNumber } from "bignumber.js"
import { BN_0 } from "utils/constants"
import { humanizeUnderscoredString } from "utils/formatting"
import { useActiveRpcUrlList } from "./provider"

const REFERENDUM_DATA_URL = import.meta.env.VITE_REFERENDUM_DATA_URL as string

Expand Down Expand Up @@ -65,6 +71,38 @@ export const useReferendumInfo = (referendumIndex: string) => {
)
}

export const useOpenGovReferendas = () => {
const rpcUrlList = useActiveRpcUrlList()
const { api, isLoaded } = useRpcProvider()

return useQuery(
QUERY_KEYS.openGovReferendas(rpcUrlList.join(".")),
getOpenGovRegerendas(api),
{
enabled: isLoaded,
},
)
}

const getOpenGovRegerendas = (api: ApiPromise) => async () => {
const newReferendumsRaw =
await api.query.referenda.referendumInfoFor.entries()

// get only ongoing referenas so far
return newReferendumsRaw.reduce<
Array<{ id: string; referendum: PalletReferendaReferendumStatus }>
>((acc, [key, dataRaw]) => {
const id = key.args[0].toString()
const data = dataRaw.unwrap()

if (!data.isNone && data.isOngoing) {
acc.push({ id, referendum: data.asOngoing })
}

return acc
}, [])
}

export const getReferendums =
(api: ApiPromise, accountId?: string) => async () => {
const [referendumRaw, votesRaw] = await Promise.all([
Expand Down Expand Up @@ -228,3 +266,51 @@ export const getAccountUnlockedVotes =

return unlockedVotes
}

export const useReferendaTracks = () => {
const rpcUrlList = useActiveRpcUrlList()
const { api, isLoaded } = useRpcProvider()

return useQuery(
QUERY_KEYS.referendaTracks(rpcUrlList.join(".")),
async () => {
const tracks = await api.consts.referenda.tracks

const data: Map<string, TReferenda> = new Map(
tracks.map(([key, dataRaw]) => [
key.toString(),
{
name: dataRaw.name.toString(),
nameHuman: humanizeUnderscoredString(dataRaw.name.toString()),
maxDeciding: dataRaw.maxDeciding.toBigNumber(),
decisionDeposit: dataRaw.decisionDeposit.toBigNumber(),
preparePeriod: dataRaw.preparePeriod.toBigNumber(),
decisionPeriod: dataRaw.decisionPeriod.toBigNumber(),
confirmPeriod: dataRaw.confirmPeriod.toBigNumber(),
minEnactmentPeriod: dataRaw.minEnactmentPeriod.toBigNumber(),
minApproval: dataRaw.minApproval,
minSupport: dataRaw.minSupport,
},
]),
)

return data
},
{
enabled: isLoaded,
},
)
}

export type TReferenda = {
name: string
nameHuman: string
maxDeciding: BigNumber
decisionDeposit: BigNumber
preparePeriod: BigNumber
decisionPeriod: BigNumber
confirmPeriod: BigNumber
minEnactmentPeriod: BigNumber
minApproval: PalletReferendaCurve
minSupport: PalletReferendaCurve
}
9 changes: 3 additions & 6 deletions src/api/farms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import { TDeposit, useAccountAssets } from "./deposits"
import { useDisplayPrices } from "utils/displayAsset"
import { millisecondsInHour, millisecondsInMinute } from "date-fns/constants"
import { getCurrentLoyaltyFactor } from "utils/farms/apr"
import { useClaimingRange } from "sections/pools/farms/components/claimingRange/claimingRange.utils"
import { useAccount } from "sections/web3-connect/Web3Connect.utils"
import { BalanceClient } from "@galacticcouncil/sdk"

Expand Down Expand Up @@ -632,11 +631,10 @@ export const getYieldFarmCreated = (indexerUrl: string) => async () => {
export const useRefetchClaimableFarmValues = () => {
const { account } = useAccount()
const queryClient = useQueryClient()
const { range } = useClaimingRange()

return () => {
queryClient.resetQueries(
QUERY_KEYS.accountClaimableFarmValues(account?.address, range),
QUERY_KEYS.accountClaimableFarmValues(account?.address),
)
}
}
Expand All @@ -645,7 +643,6 @@ export const useAccountClaimableFarmValues = () => {
const { api, isLoaded } = useRpcProvider()
const { tokens, getAssetWithFallback } = useAssets()
const { data } = useAccountAssets()
const { range } = useClaimingRange()

const {
omnipoolDeposits = [],
Expand All @@ -656,7 +653,7 @@ export const useAccountClaimableFarmValues = () => {
const allDeposits = [...omnipoolDeposits, ...xykDeposits]

return useQuery(
QUERY_KEYS.accountClaimableFarmValues(accountAddress, range),
QUERY_KEYS.accountClaimableFarmValues(accountAddress),
async () => {
const accountResolver = getAccountResolver(api.registry)

Expand Down Expand Up @@ -762,7 +759,7 @@ export const useAccountClaimableFarmValues = () => {
(lp) => lp.depositId === deposit.id,
)

const isClaimable = BN(loyaltyFactor).gt(range)
const isClaimable = true

const isActiveFarm = yieldFarm.state.isActive

Expand Down
3 changes: 1 addition & 2 deletions src/api/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,12 @@ export const useProviderData = () => {
PoolType.XYK,
PoolType.LBP,
]
await poolService.syncRegistry(externalTokens[dataEnv])

const tradeRouter = new TradeRouter(poolService, {
includeOnly: traderRoutes,
})

await poolService.syncRegistry(externalTokens[dataEnv])

const [isDispatchPermitEnabled] = await Promise.all([
api.tx.multiTransactionPayment.dispatchPermit,
tradeRouter.getPools(),
Expand Down
89 changes: 15 additions & 74 deletions src/api/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import request, { gql } from "graphql-request"
import { useActiveProvider } from "./provider"
import { useRpcProvider } from "providers/rpcProvider"
import { useAccount } from "sections/web3-connect/Web3Connect.utils"
import { undefinedNoop } from "utils/helpers"

interface ISubscanData {
code: number
Expand Down Expand Up @@ -46,19 +45,23 @@ export type TStakingPosition = Awaited<
ReturnType<ReturnType<typeof getStakingPosition>>
>

export const useCirculatingSupply = () => {
export const useHDXSupplyFromSubscan = () => {
return useQuery(
QUERY_KEYS.circulatingSupply,
QUERY_KEYS.hdxSupply,
async () => {
const res = await getCirculatingSupply()()
const res = await getHDXSupplyFromSubscan()()

return res.data.detail["HDX"].available_balance
const data = res.data.detail["HDX"]
return {
totalIssuance: data.total_issuance,
circulatingSupply: data.available_balance,
}
},
{ retry: 0 },
)
}

const getCirculatingSupply = () => async () => {
const getHDXSupplyFromSubscan = () => async () => {
const res = await fetch("https://hydration.api.subscan.io/api/scan/token")

const data: Promise<ISubscanData> = res.json()
Expand Down Expand Up @@ -112,7 +115,7 @@ const getStake = (api: ApiPromise, address: string | undefined) => async () => {
const getStakingPosition = (api: ApiPromise, id: number) => async () => {
const [position, votesRes] = await Promise.all([
api.query.staking.positions(id),
api.query.staking.positionVotes(id),
api.query.staking.votes(id),
])
const positionData = position.unwrap()

Expand All @@ -122,6 +125,7 @@ const getStakingPosition = (api: ApiPromise, id: number) => async () => {
id: BN
amount: BN
conviction: string
//@ts-ignore
}> = await votesRes.votes.reduce(async (acc, [key, data]) => {
const prevAcc = await acc
const id = key.toBigNumber()
Expand Down Expand Up @@ -202,29 +206,6 @@ type TStakingInitialized = StakeEventBase & {
name: "Staking.StakingInitialized"
}

type TPositionBalance = StakeEventBase &
(
| {
name: "Staking.PositionCreated"
args: {
positionId: string
stake: string
who: string
}
}
| {
name: "Staking.StakeAdded"
args: {
lockedRewards: string
positionId: string
slashedPoints: string
stake: string
totalStake: string
who: string
}
}
)

export type TAccumulatedRpsUpdated = StakeEventBase & {
name: "Staking.AccumulatedRpsUpdated"
args: {
Expand All @@ -251,18 +232,6 @@ export const useStakingEvents = () => {
})
}

export const useStakingPositionBalances = (positionId?: string) => {
const { indexerUrl } = useActiveProvider()

return useQuery(
QUERY_KEYS.stakingPositionBalances(positionId),
positionId
? getStakingPositionBalances(indexerUrl, positionId)
: undefinedNoop,
{ enabled: !!positionId },
)
}

const getAccumulatedRpsUpdatedEvents = (indexerUrl: string) => async () => {
return {
...(await request<{
Expand Down Expand Up @@ -307,36 +276,7 @@ const getStakingInitializedEvents = (indexerUrl: string) => async () => {
}
}

const getStakingPositionBalances =
(indexerUrl: string, positionId: string) => async () => {
return {
...(await request<{
events: Array<TPositionBalance>
}>(
indexerUrl,
gql`
query StakingPositionBalances($positionId: String!) {
events(
where: {
name_contains: "Staking"
args_jsonContains: { positionId: $positionId }
}
orderBy: [block_height_ASC]
) {
name
block {
height
}
args
}
}
`,
{ positionId },
)),
}
}

export const useProcessedVotesIds = () => {
export const useVotesRewardedIds = () => {
const { account } = useAccount()
const { api } = useRpcProvider()

Expand All @@ -345,7 +285,7 @@ export const useProcessedVotesIds = () => {
return []
}

const processedVotesRes = await api.query.staking.processedVotes.entries(
const processedVotesRes = await api.query.staking.votesRewarded.entries(
account.address,
)

Expand All @@ -363,7 +303,8 @@ export const usePositionVotesIds = () => {
const { api } = useRpcProvider()

return useMutation(async (positionId: number) => {
const positionVotesRes = await api.query.staking.positionVotes(positionId)
const positionVotesRes = await api.query.staking.votes(positionId)
//@ts-ignore
const positionVotesIds = positionVotesRes.votes.map(([position]) =>
position.toString(),
)
Expand Down
2 changes: 1 addition & 1 deletion src/api/xyk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const useAllXykPools = () => {
})
}

export const useXYKPools = () => {
export const useXYKSDKPools = () => {
return useQuery<PoolBase[]>(QUERY_KEYS.xykPools, {
enabled: false,
staleTime: Infinity,
Expand Down
3 changes: 3 additions & 0 deletions src/assets/icons/Calendar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/icons/ChevronFull.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions src/assets/icons/ChevronRightSmall.svg

This file was deleted.

9 changes: 9 additions & 0 deletions src/assets/icons/StakingVote.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit c5f705f

Please sign in to comment.