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

Feat/solana #2034

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@polkadot/util": "^13.1.1",
"@polkadot/util-crypto": "^13.1.1",
"@polkadot/ui-shared": "^3.1.4",
"@galacticcouncil/xcm-core": "^5.5.0",
"@galacticcouncil/xcm-core": "^6.0.0",
"strip-ansi": "6.0.1",
"string-width": "4.2.2",
"wrap-ansi": "7.0.0",
Expand All @@ -38,18 +38,18 @@
"@emotion/styled": "^11.10.4",
"@ethersproject/address": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@galacticcouncil/apps": "^9.2.1",
"@galacticcouncil/apps": "^10.0.2",
"@galacticcouncil/math-lbp": "^1.0.0",
"@galacticcouncil/math-liquidity-mining": "^1.0.0",
"@galacticcouncil/math-omnipool": "^1.0.0",
"@galacticcouncil/math-stableswap": "^1.0.0",
"@galacticcouncil/math-staking": "^1.0.0",
"@galacticcouncil/math-xyk": "^1.0.0",
"@galacticcouncil/sdk": "^5.1.0",
"@galacticcouncil/ui": "^5.2.3",
"@galacticcouncil/xcm-cfg": "^6.0.1",
"@galacticcouncil/xcm-core": "^5.5.0",
"@galacticcouncil/xcm-sdk": "^7.0.1",
"@galacticcouncil/sdk": "^5.2.0",
"@galacticcouncil/ui": "^5.3.1",
"@galacticcouncil/xcm-cfg": "^7.0.0",
"@galacticcouncil/xcm-core": "^6.0.0",
"@galacticcouncil/xcm-sdk": "^8.0.0",
"@hookform/resolvers": "^3.3.4",
"@lit-labs/react": "^1.1.0",
"@polkadot/api": "14.0.1",
Expand All @@ -68,6 +68,7 @@
"@radix-ui/react-toast": "^1.1.4",
"@radix-ui/react-toggle-group": "^1.0.4",
"@radix-ui/react-tooltip": "^1.0.6",
"@solana/web3.js": "^1.98.0",
"@talismn/connect-wallets": "^1.2.5",
"@tanstack/react-location": "^3.7.4",
"@tanstack/react-query": "^4.14.5",
Expand Down
19 changes: 13 additions & 6 deletions src/api/external/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ export const useExternalApi = (chainKey: string) => {
)
}

export const useExternalWhitelist = () => {
return useQuery(
QUERY_KEYS.externalStore,
async () => MetadataStore.getInstance().externalWhitelist(),
{
cacheTime: 1000 * 60 * 60 * 24, // 24 hours,
staleTime: 1000 * 60 * 60 * 1, // 1 hour
},
)
}

/**
* Used for fetching tokens from supported parachains
*/
Expand Down Expand Up @@ -296,11 +307,7 @@ export const useExternalAssetsWhiteList = () => {
const { isExternal, getAsset } = useAssets()
const { isLoaded } = useRpcProvider()
const assetRegistry = useExternalAssetRegistry()

const whitelist = useMemo(
() => MetadataStore.getInstance().externalWhitelist(),
[],
)
const { data: whitelist } = useExternalWhitelist()

const getIsWhiteListed = useCallback(
(assetId: string) => {
Expand All @@ -311,7 +318,7 @@ export const useExternalAssetsWhiteList = () => {
? assetRegistry[+asset.parachainId]?.data?.get(asset.externalId ?? "")
: null

const isManuallyWhiteListed = whitelist.includes(asset.id)
const isManuallyWhiteListed = !!whitelist?.includes(asset.id)
const isWhiteListed =
isManuallyWhiteListed ||
asset?.isWhiteListed ||
Expand Down
4 changes: 2 additions & 2 deletions src/api/vesting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import { compareAsc } from "date-fns"
import { useRpcProvider } from "providers/rpcProvider"

export const useVestingSchedules = (address: Maybe<AccountId32 | string>) => {
const { api } = useRpcProvider()
const { api, isLoaded } = useRpcProvider()
return useQuery(
QUERY_KEYS.vestingSchedules(address),
address != null ? getVestingSchedules(api, address) : undefinedNoop,
{ enabled: !!address },
{ enabled: !!address && isLoaded },
)
}

Expand Down
20 changes: 14 additions & 6 deletions src/api/xcm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import {
chainsMap,
routesMap,
validations,
swaps,
HydrationConfigService,
} from "@galacticcouncil/xcm-cfg"
import { SubstrateApis } from "@galacticcouncil/xcm-core"
import { Wallet } from "@galacticcouncil/xcm-sdk"
import { useMutation } from "@tanstack/react-query"
import { Transaction, useStore } from "state/store"
import { isAnyParachain } from "utils/helpers"
import { external } from "@galacticcouncil/apps"
import { TRegisteredAsset } from "sections/wallet/addToken/AddToken.utils"
import { useMemo } from "react"
import { useTranslation } from "react-i18next"
Expand All @@ -37,9 +37,7 @@ export const syncAssethubXcmConfig = (
asset: TRegisteredAsset,
config: HydrationConfigService,
) => {
const hubAsset = external.toHubAsset(asset)
const paraAsset = external.toParachainAsset(asset)
config.addExternalHubRoute(hubAsset, paraAsset)
config.registerExternal([asset])
}

export const useCrossChainWallet = () => {
Expand All @@ -52,11 +50,21 @@ export const useCrossChainWallet = () => {
routes: routesMap,
})

return new Wallet({
const wallet = new Wallet({
configService: configService,
poolService: poolService,
transferValidations: validations,
})

// Register chain swaps
const hydration = configService.getChain("hydration")
const assethub = configService.getChain("assethub")

wallet.registerSwaps(
new swaps.HydrationSwap(hydration, poolService),
new swaps.AssethubSwap(assethub),
)

return wallet
}, [poolService])
}

Expand Down
4 changes: 4 additions & 0 deletions src/assets/icons/PhantomLogo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions src/assets/icons/SolflareLogo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 19 additions & 2 deletions src/components/AccountAvatar/AccountAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import { JdenticonAvatar } from "./JdenticonAvatar"
import { PolkadotAvatar } from "./PolkadotAvatar"
import { MetaMaskAvatar } from "./MetaMaskAvatar"
import { isEvmAccount, isEvmAddress, safeConvertAddressH160 } from "utils/evm"
import { WalletProviderType } from "sections/web3-connect/constants/providers"
import {
SOLANA_PROVIDERS,
WalletProviderType,
} from "sections/web3-connect/constants/providers"
import { genesisHashToChain } from "utils/helpers"
import type { Icon } from "@polkadot/networks/types"

Expand All @@ -24,12 +27,26 @@ export const AccountAvatar: FC<Props> = (props) => {
const chainIcon: Icon =
props.genesisHash && chain?.icon ? chain.icon : "polkadot"

const isSolana = !!props.provider && SOLANA_PROVIDERS.includes(props.provider)
const isEvm = isEvmAccount(props.address) || isEvmAddress(props.address)

const theme = props.provider?.startsWith("talisman")
? "talisman"
: isEvm
? "evm"
: chainIcon
: isSolana
? "jdenticon"
: chainIcon

if (theme === "jdenticon") {
return (
<JdenticonAvatar
publicKey={props.address}
size={props.size}
className={props.className}
/>
)
}

if (theme === "evm") {
return (
Expand Down
1 change: 1 addition & 0 deletions src/i18n/locales/en/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@
"walletConnect.provider.disconnect": "Disconnect",
"walletConnect.provider.connectAll": "Connect all",
"walletConnect.provider.mode.substrate": "Polkadot",
"walletConnect.provider.mode.solana": "Solana",
"walletConnect.provider.mode.evm": "EVM",
"walletConnect.provider.mode.all": "All",
"walletConnect.provider.section.installed": "Installed & recently used",
Expand Down
3 changes: 3 additions & 0 deletions src/polkadot.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { InjectedWindowProvider } from "@polkadot/extension-inject/types"
import { MetaMaskLikeProvider } from "utils/metamask"
import { SolanaWalletProvider } from "utils/solana"

import BigNumber from "bignumber.js"

Expand All @@ -20,7 +21,9 @@ declare global {
SubWallet?: MetaMaskLikeProvider
phantom?: {
ethereum: MetaMaskLikeProvider
solana: SolanaWalletProvider
}
solflare?: SolanaWalletProvider
injectedWeb3?: Record<string, InjectedWindowProvider>
walletExtension?: { isNovaWallet?: boolean }
}
Expand Down
10 changes: 3 additions & 7 deletions src/sections/pools/PoolsPage.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import { useTVL } from "api/stats"
import { scaleHuman } from "utils/balance"
import { useAccountAssets } from "api/deposits"
import { TAsset, TShareToken, useAssets } from "providers/assets"
import { MetadataStore } from "@galacticcouncil/ui"
import { getTradabilityFromBits } from "api/omnipool"
import { useOmnipoolFarms, useXYKFarms } from "api/farms"
import { useExternalWhitelist } from "api/external"

export const isXYKPoolType = (pool: TPool | TXYKPool): pool is TXYKPool =>
!!(pool as TXYKPool).shareTokenIssuance
Expand Down Expand Up @@ -248,11 +248,7 @@ export const useXYKPools = () => {
const { data: xykConsts } = useXYKConsts()
const { shareTokens } = useAssets()
const { data: accountAssets } = useAccountAssets()

const whitelist = useMemo(
() => MetadataStore.getInstance().externalWhitelist(),
[],
)
const { data: whitelist } = useExternalWhitelist()

const { validShareTokens, allShareTokens } = useMemo(() => {
return shareTokens.reduce<{
Expand All @@ -261,7 +257,7 @@ export const useXYKPools = () => {
}>(
(acc, shareToken) => {
const isInvalid = !shareToken.assets.some(
(asset) => asset.isSufficient || whitelist.includes(asset.id),
(asset) => asset.isSufficient || whitelist?.includes(asset.id),
)

if (!isInvalid) acc.validShareTokens.push(shareToken)
Expand Down
13 changes: 11 additions & 2 deletions src/sections/transaction/ReviewTransaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import { ReviewTransactionToast } from "./ReviewTransactionToast"
import { ReviewTransactionXCallForm } from "./ReviewTransactionXCallForm"
import { ReviewTransactionEvmTxForm } from "sections/transaction/ReviewTransactionEvmTxForm"
import { WalletUpgradeModal } from "sections/web3-connect/upgrade/WalletUpgradeModal"
import { isEvmXCall } from "sections/transaction/ReviewTransactionXCallForm.utils"
import {
isEvmCall,
isSolanaCall,
} from "sections/transaction/ReviewTransactionXCallForm.utils"
import { useRpcProvider } from "providers/rpcProvider"

export const ReviewTransaction = (props: Transaction) => {
Expand All @@ -25,6 +28,7 @@ export const ReviewTransaction = (props: Transaction) => {
sendTx,
sendEvmTx,
sendPermitTx,
sendSolanaTx,
isLoading,
isSuccess,
isError: isSendError,
Expand Down Expand Up @@ -168,7 +172,8 @@ export const ReviewTransaction = (props: Transaction) => {
sendPermitTx(permit)
}}
/>
) : isEvmXCall(props.xcall) && props.xcallMeta ? (
) : (isEvmCall(props.xcall) || isSolanaCall(props.xcall)) &&
props.xcallMeta ? (
<ReviewTransactionXCallForm
xcall={props.xcall}
xcallMeta={props.xcallMeta}
Expand All @@ -177,6 +182,10 @@ export const ReviewTransaction = (props: Transaction) => {
props.onSubmitted?.()
sendEvmTx(data)
}}
onSolanaSigned={(data) => {
props.onSubmitted?.()
sendSolanaTx(data)
}}
onSignError={setSignError}
/>
) : null}
Expand Down
Loading
Loading