Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rococo => prod #1989

Merged
merged 25 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
67b3297
Implement Open Gov
vkulinich-cl Sep 25, 2024
b2af798
wip
vkulinich-cl Oct 3, 2024
0c12d8b
Merge branch 'master' into open-gov
vkulinich-cl Oct 4, 2024
426fc22
Merge branch 'master' into open-gov
vkulinich-cl Oct 7, 2024
aae1259
wip
vkulinich-cl Oct 7, 2024
0f4fdbd
Revert claiming
vkulinich-cl Dec 11, 2024
01e4620
Merge branch 'master' into open-gov
vkulinich-cl Dec 17, 2024
63966aa
Merge branch 'master' into revert-claiming
vkulinich-cl Dec 19, 2024
b493c92
wip
vkulinich-cl Dec 19, 2024
ac07264
clean
vkulinich-cl Dec 19, 2024
7491598
Merge branch 'master' into open-gov
vkulinich-cl Dec 23, 2024
5e2ea3a
Update query names
vkulinich-cl Dec 20, 2024
d3ad499
Query xyk balances from sdk
vkulinich-cl Dec 23, 2024
783e1c1
add support label
vkulinich-cl Dec 23, 2024
539ecf8
wip
vkulinich-cl Dec 23, 2024
7b10f1c
wip
vkulinich-cl Dec 23, 2024
764c211
wip
vkulinich-cl Dec 23, 2024
39ae97e
Merge pull request #1669 from galacticcouncil/open-gov
vkulinich-cl Dec 23, 2024
6e84d51
Merge branch 'master' into revert-claiming
vkulinich-cl Dec 23, 2024
8b86db7
Merge pull request #1953 from galacticcouncil/revert-claiming
vkulinich-cl Dec 23, 2024
e6f4a18
Merge branch 'master' into xyk-sdk-balance
vkulinich-cl Dec 23, 2024
04dd787
Merge pull request #1986 from galacticcouncil/xyk-sdk-balance
vkulinich-cl Dec 23, 2024
47a90a7
Update link
vkulinich-cl Dec 23, 2024
c3737bc
Merge pull request #1988 from galacticcouncil/update-link
vkulinich-cl Dec 23, 2024
de38544
Merge pull request #1987 from galacticcouncil/master
vkulinich-cl Dec 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading