Skip to content

Commit

Permalink
Merge pull request #770 from autonomys/ft/updateAutoSDK0.1.8
Browse files Browse the repository at this point in the history
Update to auto sdk 0.1.8
  • Loading branch information
marc-aurele-besner authored Jul 25, 2024
2 parents e315077 + a3f0583 commit 695ff80
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 169 deletions.
8 changes: 2 additions & 6 deletions explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,18 @@
"dependencies": {
"@apollo/client": "^3.7.0",
"@apollo/experimental-nextjs-app-support": "^0.8.0",
"@autonomys/auto-consensus": "^0.1.4",
"@autonomys/auto-utils": "^0.1.4",
"@autonomys/auto-consensus": "^0.1.8",
"@autonomys/auto-utils": "^0.1.8",
"@headlessui/react": "^1.7.18",
"@headlessui/tailwindcss": "^0.2.0",
"@heroicons/react": "^2.1.1",
"@next/third-parties": "^14.2.3",
"@nivo/core": "^0.84.0",
"@nivo/line": "^0.84.0",
"@nivo/pie": "^0.84.0",
"@polkadot/api": "^10.12.1",
"@polkadot/extension-dapp": "^0.46.7",
"@polkadot/extension-inject": "^0.46.7",
"@polkadot/keyring": "^12.6.2",
"@polkadot/react-identicon": "^3.6.5",
"@polkadot/util": "^12.6.2",
"@polkadot/util-crypto": "^12.6.2",
"@subwallet/wallet-connect": "^0.2.7",
"@tailwindcss/forms": "^0.5.7",
"@tanstack/match-sorter-utils": "^8.11.8",
Expand Down
16 changes: 10 additions & 6 deletions explorer/src/app/api/claim/[...params]/route.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { AuthProvider } from '@/constants'
import { balance, transfer } from '@autonomys/auto-consensus'
import { ActivateWalletInput, activateWallet } from '@autonomys/auto-utils'
import type { ApiPromise } from '@polkadot/api'
import { stringToU8a } from '@polkadot/util'
import { decodeAddress, signatureVerify } from '@polkadot/util-crypto'
import {
activateWallet,
ActivateWalletParams,
ApiPromise,
decode,
signatureVerify,
stringToU8a,
} from '@autonomys/auto-utils'
import { chains } from 'constants/chains'
import { CLAIM_TYPES } from 'constants/routes'
import { NextRequest, NextResponse } from 'next/server'
Expand Down Expand Up @@ -54,7 +58,7 @@ export const POST = async (req: NextRequest) => {
const { message, signature, address } = claim

// Verify the signature
const publicKey = decodeAddress(address)
const publicKey = decode(address)
const isValid = signatureVerify(stringToU8a(message), signature, publicKey).isValid
if (!isValid) return NextResponse.json({ error: 'Invalid signature' }, { status: 400 })

Expand All @@ -66,7 +70,7 @@ export const POST = async (req: NextRequest) => {
} = await activateWallet({
uri: process.env.WALLET_CLAIM_OPERATOR_DISBURSEMENT_URI,
networkId: 'autonomys-' + chainMatch.urls.page,
} as ActivateWalletInput)
} as ActivateWalletParams)

// Get wallet free balance
const { free } = await balance(api as unknown as ApiPromise, wallet.address)
Expand Down
8 changes: 2 additions & 6 deletions explorer/src/components/Staking/RegisterOperators.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
'use client'

import { registerOperator } from '@autonomys/auto-consensus'
import { createAccountIdType, isHex, Keyring, u8aToHex } from '@autonomys/auto-utils'
import { Listbox, Transition } from '@headlessui/react'
import { CheckIcon, ChevronDownIcon, ExclamationTriangleIcon } from '@heroicons/react/20/solid'
import { sendGAEvent } from '@next/third-parties/google'
import { Keyring } from '@polkadot/api'
import { createType } from '@polkadot/types'
import { isHex, u8aToHex } from '@polkadot/util'
import { WalletIcon } from 'components/icons'
import { PreferredExtensionModal } from 'components/layout/PreferredExtensionModal'
import { EXTERNAL_ROUTES } from 'constants/routes'
Expand Down Expand Up @@ -209,9 +207,7 @@ export const RegisterOperators = () => {
const Operator = OperatorKeyring.addFromUri(seed)

const signingKey = u8aToHex(Operator.publicKey)
const signature = Operator.sign(
createType(api.registry, 'AccountId', actingAccount.address).toU8a(),
)
const signature = Operator.sign(createAccountIdType(api, actingAccount.address))
setFieldValue('signingKey', signingKey)
setFieldValue('signature', signature)
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isAddress } from '@polkadot/util-crypto'
import { isAddress } from '@autonomys/auto-utils'
import { Modal } from 'components/common/Modal'
import { AccountPreferenceSection, WalletType } from 'constants/wallet'
import { Field, FieldArray, Form, Formik, FormikState } from 'formik'
Expand Down
3 changes: 1 addition & 2 deletions explorer/src/components/WalletSideKick/ActionsModal.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { remark, transfer } from '@autonomys/auto-consensus'
import { Hash, SignerResult } from '@autonomys/auto-utils'
import { Listbox, Transition } from '@headlessui/react'
import { sendGAEvent } from '@next/third-parties/google'
import { SignerResult } from '@polkadot/api/types'
import { Hash } from '@polkadot/types/interfaces'
import { CopyButton } from 'components/common/CopyButton'
import { Modal } from 'components/common/Modal'
import { Tooltip } from 'components/common/Tooltip'
Expand Down
4 changes: 2 additions & 2 deletions explorer/src/components/WalletSideKick/ExtrinsicsLab.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { camelToNormal } from '@/utils/string'
import { SubmittableModuleExtrinsics } from '@autonomys/auto-utils'
import { Listbox, Transition } from '@headlessui/react'
import { CheckIcon, ChevronDownIcon } from '@heroicons/react/20/solid'
import { SubmittableModuleExtrinsics } from '@polkadot/api/types'
import { Field, FieldArray, FormikErrors, FormikTouched } from 'formik'
import { FC, Fragment, useCallback, useMemo, useState } from 'react'
import { camelToNormal } from 'utils/string'

export type ExtrinsicModule = SubmittableModuleExtrinsics<'promise'>
export type ExtrinsicsList = { [key: string]: ExtrinsicModule }
Expand Down
3 changes: 1 addition & 2 deletions explorer/src/hooks/useSearch.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use client'

import { useLazyQuery } from '@apollo/client'
import { isHex } from '@polkadot/util'
import { isAddress } from '@polkadot/util-crypto'
import { isAddress, isHex } from '@autonomys/auto-utils'
import { GET_RESULTS } from 'components/common/queries'
import { INTERNAL_ROUTES } from 'constants/routes'
import { useRouter } from 'next/navigation'
Expand Down
6 changes: 3 additions & 3 deletions explorer/src/hooks/useTxHelper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { TransactionStatus } from '@/constants'
import type { ISubmittableResult, Signer, SubmittableExtrinsic } from '@autonomys/auto-utils'
import { sendGAEvent } from '@next/third-parties/google'
import type { Signer, SubmittableExtrinsic } from '@polkadot/api/types'
import type { ISubmittableResult } from '@polkadot/types/types'
import useDomains from 'hooks/useDomains'
import useWallet from 'hooks/useWallet'
import { useCallback } from 'react'
Expand All @@ -11,7 +10,8 @@ import { useTransactionsStates } from 'states/transactions'
export interface SendAndSaveTx {
call: string
tx: SubmittableExtrinsic<'promise', ISubmittableResult>
signer: Signer
// eslint-disable-next-line @typescript-eslint/no-explicit-any
signer: Signer | any
to?: string
amount?: string
fee?: string
Expand Down
9 changes: 3 additions & 6 deletions explorer/src/providers/WalletProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use client'

import { activate, ApiPromise } from '@autonomys/auto-utils'
import { sendGAEvent } from '@next/third-parties/google'
import { ApiPromise, WsProvider } from '@polkadot/api'
import { InjectedExtension } from '@polkadot/extension-inject/types'
import { getWalletBySource } from '@subwallet/wallet-connect/dotsama/wallets'
import { Chains, chains } from 'constants/chains'
import { WalletType } from 'constants/wallet'
import { useSafeLocalStorage } from 'hooks/useSafeLocalStorage'
import { getSession, signOut } from 'next-auth/react'
import { useParams } from 'next/navigation'
import { FC, ReactNode, createContext, useCallback, useEffect, useState } from 'react'
import { createContext, FC, ReactNode, useCallback, useEffect, useState } from 'react'
import type { ChainParam } from 'types/app'
import type { WalletAccountWithType } from 'types/wallet'
import { formatAddress } from 'utils/formatAddress'
Expand Down Expand Up @@ -55,10 +55,7 @@ export const WalletProvider: FC<Props> = ({ children }) => {

const prepareApi = useCallback(async (chain: (typeof chains)[0]) => {
try {
const wsProvider = new WsProvider(chain.urls.rpc)
const api = await ApiPromise.create({ provider: wsProvider })
await api.isReady
return api
return await activate({ networkId: 'autonomys-' + chain.urls.page })
} catch (error) {
console.error('Failed to prepare API for chain', chain.title, 'error:', error)
}
Expand Down
3 changes: 1 addition & 2 deletions explorer/src/states/consensus.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Deposit, Withdrawal } from '@autonomys/auto-consensus'
import {
ConfirmedDomainBlock,
Deposit,
Domain,
DomainRegistry,
DomainStakingSummary,
Expand All @@ -9,7 +9,6 @@ import {
Operators,
PendingStakingOperationCount,
SuccessfulBundle,
Withdrawal,
} from 'types/consensus'
import { bigIntDeserializer, bigIntSerializer } from 'utils/number'
import { create } from 'zustand'
Expand Down
65 changes: 0 additions & 65 deletions explorer/src/types/consensus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,68 +99,3 @@ export type SuccessfulBundle = {
id: number
bundle: string[]
}

export type RawDeposit = {
known: {
shares: number
storageFeeDeposit: number
}
pending: {
effectiveDomainEpoch: [number, number]
amount: string
storageFeeDeposit: string
} | null
}

export type Deposit = {
operatorId: number
account: string
shares: bigint
storageFeeDeposit: bigint
known: {
shares: bigint
storageFeeDeposit: bigint
}
pending: {
effectiveDomainId: number
effectiveDomainEpoch: number
amount: bigint
storageFeeDeposit: bigint
} | null
}

export type RawWithdrawal = {
totalWithdrawalAmount: string
withdrawals: {
domainId: number
unlockAtConfirmedDomainBlockNumber: number
amountToUnlock: string
storageFeeRefund: string
}[]
withdrawalInShares: {
domainEpoch: number[]
unlockAtConfirmedDomainBlockNumber: number
shares: string
storageFeeRefund: string
}
}

export type WithdrawalUnlock = {
domainId: number
unlockAtConfirmedDomainBlockNumber: number
amountToUnlock: bigint
storageFeeRefund: bigint
}

export type Withdrawal = {
operatorId: number
account: string
totalWithdrawalAmount: bigint
withdrawals: WithdrawalUnlock[]
withdrawalInShares: {
domainEpoch: number[]
unlockAtConfirmedDomainBlockNumber: number
shares: bigint
storageFeeRefund: bigint
}
}
2 changes: 1 addition & 1 deletion explorer/src/utils/auth/providers/subspace.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cryptoWaitReady, signatureVerify } from '@polkadot/util-crypto'
import { cryptoWaitReady, signatureVerify } from '@autonomys/auto-utils'
import { AuthProvider, DEFAULT_DISCORD_TOKEN } from 'constants/session'
import { User } from 'next-auth'
import type { Provider } from 'next-auth/providers'
Expand Down
57 changes: 5 additions & 52 deletions explorer/src/utils/chainStateParsing.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { StorageKey } from '@polkadot/types'
import type { AnyTuple, Codec } from '@polkadot/types-codec/types'
import { Deposit, Operators, RawDeposit, RawWithdrawal, Withdrawal } from 'types/consensus'
import { parseDeposit, parseWithdrawal } from '@autonomys/auto-consensus'
import type { AnyTuple, Codec, StorageKey } from '@autonomys/auto-utils'
import { Operators } from 'types/consensus'

export const formatOperators = (
operators: [StorageKey<AnyTuple>, Codec][],
Expand All @@ -21,54 +21,7 @@ export const formatOperators = (
})

export const formatDeposits = (deposits: [StorageKey<AnyTuple>, Codec][]) =>
deposits.map((deposit) => {
const depositHeader = deposit[0].toHuman() as [string, string]
const parsedDeposit = deposit[1].toJSON() as RawDeposit
const pending =
parsedDeposit.pending !== null
? {
effectiveDomainId: parsedDeposit.pending.effectiveDomainEpoch[0],
effectiveDomainEpoch: parsedDeposit.pending.effectiveDomainEpoch[1],
amount: BigInt(parsedDeposit.pending.amount),
storageFeeDeposit: BigInt(parsedDeposit.pending.storageFeeDeposit),
}
: null
return {
operatorId: parseInt(depositHeader[0]),
account: depositHeader[1],
shares: BigInt(parsedDeposit.known.shares.toString()),
storageFeeDeposit: BigInt(parsedDeposit.known.storageFeeDeposit.toString()),
known: {
shares: BigInt(parsedDeposit.known.shares.toString()),
storageFeeDeposit: BigInt(parsedDeposit.known.storageFeeDeposit.toString()),
},
pending,
} as Deposit
})
deposits.map((deposit) => parseDeposit(deposit))

export const formatWithdrawals = (withdrawals: [StorageKey<AnyTuple>, Codec][]) =>
withdrawals.map((withdrawal) => {
const withdrawalHeader = withdrawal[0].toHuman() as [string, string]
const parsedWithdrawal = withdrawal[1].toJSON() as RawWithdrawal
return {
operatorId: parseInt(withdrawalHeader[0]),
account: withdrawalHeader[1],
totalWithdrawalAmount: BigInt(parsedWithdrawal.totalWithdrawalAmount),
withdrawalInShares: {
domainEpoch: parsedWithdrawal.withdrawalInShares.domainEpoch,
unlockAtConfirmedDomainBlockNumber:
parsedWithdrawal.withdrawalInShares.unlockAtConfirmedDomainBlockNumber,
shares: BigInt(parsedWithdrawal.withdrawalInShares.shares),
storageFeeRefund: BigInt(parsedWithdrawal.withdrawalInShares.storageFeeRefund),
},
withdrawals:
parsedWithdrawal.withdrawals &&
parsedWithdrawal.withdrawals.length > 0 &&
parsedWithdrawal.withdrawals.map((w) => ({
domainId: w.domainId,
unlockAtConfirmedDomainBlockNumber: w.unlockAtConfirmedDomainBlockNumber,
amountToUnlock: BigInt(w.amountToUnlock),
storageFeeRefund: BigInt(w.storageFeeRefund),
})),
} as Withdrawal
})
withdrawals.map((withdrawal) => parseWithdrawal(withdrawal))
8 changes: 3 additions & 5 deletions explorer/src/utils/formatAddress.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { SUBSPACE_ACC_PREFIX } from '@/constants/general'
import Keyring from '@polkadot/keyring'
import { u8aToHex } from '@polkadot/util'
import { decodeAddress, isAddress } from '@polkadot/util-crypto'
import { decode, isAddress, Keyring, u8aToHex } from '@autonomys/auto-utils'
import { SUBSPACE_ACC_PREFIX } from 'constants/general'

export const formatAddress = (accountId?: string): string | undefined => {
if (!accountId || !isAddress(accountId)) return undefined
Expand All @@ -18,7 +16,7 @@ export const formatAddress = (accountId?: string): string | undefined => {
}

export const accountIdToHex = (accountId: string): string => {
const hex = u8aToHex(decodeAddress(accountId))
const hex = u8aToHex(decode(accountId))

return hex
}
20 changes: 10 additions & 10 deletions explorer/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,17 @@
dependencies:
node-fetch "^2.6.1"

"@autonomys/auto-consensus@^0.1.4":
version "0.1.4"
resolved "https://registry.yarnpkg.com/@autonomys/auto-consensus/-/auto-consensus-0.1.4.tgz#6d8a6022a3f5ff54265b60c67a0e48849cbcd2ad"
integrity sha512-LH2vZnLAsz6NScH/+/ehiKJP9Mtug9wKZf75h5Lflk3mFzjCaB+6RQOosKdNRKk4Oh+5y2XM8SbfUaERk8omqw==
"@autonomys/auto-consensus@^0.1.8":
version "0.1.8"
resolved "https://registry.yarnpkg.com/@autonomys/auto-consensus/-/auto-consensus-0.1.8.tgz#3d15cfdc8bc8e06f43ae939099b0c61c0b189222"
integrity sha512-bo+U6l3xEQtiUATzI6wJ0aZ7abqbg3+SphVFR/bT9HZ7G3wgwOIbzvoXmghJbehcLY+i51WDiqsB5hbDI3U0qg==
dependencies:
"@autonomys/auto-utils" "^0.1.4"
"@autonomys/auto-utils" "^0.1.8"

"@autonomys/auto-utils@^0.1.4":
version "0.1.4"
resolved "https://registry.yarnpkg.com/@autonomys/auto-utils/-/auto-utils-0.1.4.tgz#084cb164762c5eafa41f1d23b9795e065a83f205"
integrity sha512-+GSO9/a/IRobMS+Hgad1UKanDsiSVDihXWF9EEJ+UJj5xJZaq+Sszc665srJ2BcW0MupXbR9kblErjWBjRKbSg==
"@autonomys/auto-utils@^0.1.8":
version "0.1.8"
resolved "https://registry.yarnpkg.com/@autonomys/auto-utils/-/auto-utils-0.1.8.tgz#269090c20e339f6f62d55218c2b4bb019c476b3f"
integrity sha512-0Ak93TYNh8UZbx/zLKXeo4+CuHcj50O1ql+/CO/SqeLRhgzA/l++lOlGRb4vWpr2IVReWGPY76986Yo4kSqHXQ==
dependencies:
"@polkadot/api" "^11.2.1"
"@polkadot/extension-dapp" "^0.47.5"
Expand Down Expand Up @@ -2461,7 +2461,7 @@
rxjs "^7.8.1"
tslib "^2.6.2"

"@polkadot/api@10.12.1", "@polkadot/api@^10.11.3", "@polkadot/api@^10.12.1":
"@polkadot/api@10.12.1", "@polkadot/api@^10.11.3":
version "10.12.1"
resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-10.12.1.tgz#a2fa0bde2dafd74a2374ab166f85d80bf1ca588b"
integrity sha512-6pZPpgyxSphse9PCZ/QxUygk0BYbcCNjr5ERZZsTE/F1znZ62Ce63A8AE0bwga9ITkiVISLDSU36hghKs3tVhA==
Expand Down

0 comments on commit 695ff80

Please sign in to comment.