From 239038b13e1d5e8869cbbdf50d005ff848d2ff3a Mon Sep 17 00:00:00 2001 From: Sebastian Scatularo Date: Tue, 22 Oct 2024 16:55:49 -0300 Subject: [PATCH] remove injective support from advanced tools, since injective will be deprecated in flavor of ibc transfers --- docs/docs/faqs/liquid-markets.mdx | 13 -- package-lock.json | 4 - package.json | 4 - src/components/KeyAndBalance.tsx | 2 - src/components/Recovery.tsx | 66 +------ src/components/ShowTx.tsx | 5 - src/components/SmartAddress.tsx | 9 - .../TokenSelectors/InjectiveTokenPicker.tsx | 168 ------------------ .../TokenSelectors/SourceTokenSelector.tsx | 10 -- src/components/Transfer/RegisterNowButton.tsx | 2 - src/contexts/InjectiveWalletContext.tsx | 53 ------ src/hooks/useCheckIfWormholeWrapped.ts | 14 -- src/hooks/useFetchForeignAsset.ts | 13 -- src/hooks/useFetchTargetAsset.ts | 53 ------ src/hooks/useGetIsTransferCompleted.ts | 21 --- src/hooks/useGetSourceParsedTokenAccounts.ts | 5 - src/hooks/useGetTargetParsedTokenAccounts.ts | 91 ---------- src/hooks/useHandleAttest.tsx | 77 -------- src/hooks/useHandleCreateWrapped.tsx | 71 +------- src/hooks/useHandleRedeem.tsx | 74 +------- src/hooks/useHandleTransfer.tsx | 95 ---------- src/hooks/useInjectiveMetadata.ts | 88 --------- src/hooks/useInjectiveNativeBalances.ts | 52 ------ src/hooks/useIsWalletReady.ts | 9 - src/hooks/useMetadata.ts | 39 ---- src/hooks/useOriginalAsset.ts | 19 -- src/hooks/useSyncTargetAddress.ts | 10 -- src/index.tsx | 3 - src/utils/coinGecko.ts | 2 - src/utils/consts.ts | 63 ------- src/utils/injective.ts | 62 ------- 31 files changed, 3 insertions(+), 1194 deletions(-) delete mode 100644 src/components/TokenSelectors/InjectiveTokenPicker.tsx delete mode 100644 src/contexts/InjectiveWalletContext.tsx delete mode 100644 src/hooks/useInjectiveMetadata.ts delete mode 100644 src/hooks/useInjectiveNativeBalances.ts delete mode 100644 src/utils/injective.ts diff --git a/docs/docs/faqs/liquid-markets.mdx b/docs/docs/faqs/liquid-markets.mdx index 587bcfaa6..d92491833 100644 --- a/docs/docs/faqs/liquid-markets.mdx +++ b/docs/docs/faqs/liquid-markets.mdx @@ -31,8 +31,6 @@ import EthAptos from './_liquid-markets/eth-aptos.md' import EthAlgorand from './_liquid-markets/eth-algorand.md' import SolAlgorand from './_liquid-markets/sol-algorand.md' import AvaxAlgorand from './_liquid-markets/avax-algorand.md' -import SolInjective from './_liquid-markets/sol-injective.md' -import EthInjective from './_liquid-markets/eth-injective.md' import EthSui from './_liquid-markets/eth-sui.md' import SolSui from './_liquid-markets/sol-sui.md' import AptosOsmosis from './_liquid-markets/aptos-osmosis.md' @@ -201,17 +199,6 @@ Check out the [Wormhole Token list](https://github.com/certusone/wormhole-token- -## Target chain: Injective - - - - - - - - - - ## Target chain: Sui diff --git a/package-lock.json b/package-lock.json index 1dc21e4d9..29d4d7146 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,10 +11,6 @@ "@certusone/wormhole-sdk": "^0.10.17", "@cosmjs/cosmwasm-stargate": "^0.32.3", "@cosmjs/tendermint-rpc": "^0.32.3", - "@injectivelabs/networks": "^1.14.4", - "@injectivelabs/sdk-ts": "^1.14.4", - "@injectivelabs/ts-types": "^1.14.4", - "@injectivelabs/wallet-ts": "^1.14.4", "@manahippo/aptos-wallet-adapter": "^1.0.2", "@material-ui/core": "^4.12.2", "@material-ui/icons": "^4.11.2", diff --git a/package.json b/package.json index bc472a67d..3e5252969 100644 --- a/package.json +++ b/package.json @@ -6,10 +6,6 @@ "@certusone/wormhole-sdk": "^0.10.17", "@cosmjs/cosmwasm-stargate": "^0.32.3", "@cosmjs/tendermint-rpc": "^0.32.3", - "@injectivelabs/networks": "^1.14.4", - "@injectivelabs/sdk-ts": "^1.14.4", - "@injectivelabs/ts-types": "^1.14.4", - "@injectivelabs/wallet-ts": "^1.14.4", "@manahippo/aptos-wallet-adapter": "^1.0.2", "@material-ui/core": "^4.12.2", "@material-ui/icons": "^4.11.2", diff --git a/src/components/KeyAndBalance.tsx b/src/components/KeyAndBalance.tsx index bbe761af1..f88fa2d2d 100644 --- a/src/components/KeyAndBalance.tsx +++ b/src/components/KeyAndBalance.tsx @@ -2,7 +2,6 @@ import { ChainId, CHAIN_ID_ALGORAND, CHAIN_ID_APTOS, - CHAIN_ID_INJECTIVE, CHAIN_ID_NEAR, CHAIN_ID_SOLANA, CHAIN_ID_XPLA, @@ -22,7 +21,6 @@ function isChainAllowed(chainId: ChainId) { chainId === CHAIN_ID_NEAR || chainId === CHAIN_ID_XPLA || chainId === CHAIN_ID_APTOS || - chainId === CHAIN_ID_INJECTIVE || chainId === CHAIN_ID_SUI || chainId === CHAIN_ID_SEI ); diff --git a/src/components/Recovery.tsx b/src/components/Recovery.tsx index cce679ddb..15aba528d 100644 --- a/src/components/Recovery.tsx +++ b/src/components/Recovery.tsx @@ -3,7 +3,6 @@ import { CHAIN_ID_ACALA, CHAIN_ID_ALGORAND, CHAIN_ID_APTOS, - CHAIN_ID_INJECTIVE, CHAIN_ID_KARURA, CHAIN_ID_NEAR, CHAIN_ID_SOLANA, @@ -12,7 +11,6 @@ import { CHAIN_ID_SEI, getEmitterAddressAlgorand, getEmitterAddressEth, - getEmitterAddressInjective, getEmitterAddressSolana, getEmitterAddressTerra, getEmitterAddressXpla, @@ -25,14 +23,12 @@ import { parseNFTPayload, parseSequenceFromLogAlgorand, parseSequenceFromLogEth, - parseSequenceFromLogInjective, parseSequenceFromLogSolana, parseSequenceFromLogTerra, parseSequenceFromLogXpla, parseTransferPayload, parseVaa, queryExternalId, - queryExternalIdInjective, TerraChainId, uint8ArrayToHex, CHAIN_ID_SUI, @@ -115,10 +111,6 @@ import { getEmitterAddressAndSequenceFromResult, } from "../utils/aptos"; import { Types } from "aptos"; -import { - getInjectiveTxClient, - getInjectiveWasmClient, -} from "../utils/injective"; import { getSuiProvider } from "../utils/sui"; import { getEmitterAddressAndSequenceFromResponseSui, @@ -385,26 +377,6 @@ async function xpla(tx: string, enqueueSnackbar: any) { } } -async function injective(txHash: string, enqueueSnackbar: any) { - try { - const client = getInjectiveTxClient(); - const tx = await client.fetchTx(txHash); - if (!tx) { - throw new Error("Unable to fetch transaction"); - } - const sequence = parseSequenceFromLogInjective(tx); - if (!sequence) { - throw new Error("Sequence not found"); - } - const emitterAddress = await getEmitterAddressInjective( - getTokenBridgeAddressForChain(CHAIN_ID_INJECTIVE) - ); - return await fetchSignedVAA(CHAIN_ID_INJECTIVE, emitterAddress, sequence); - } catch (e) { - return handleError(e, enqueueSnackbar); - } -} - async function sui(digest: string, enqueueSnackbar: any) { try { const provider = getSuiProvider(); @@ -649,21 +621,6 @@ export default function Recovery() { } })(); } - if (parsedPayload && parsedPayload.targetChain === CHAIN_ID_INJECTIVE) { - (async () => { - const client = getInjectiveWasmClient(); - const tokenBridgeAddress = - getTokenBridgeAddressForChain(CHAIN_ID_INJECTIVE); - const tokenId = await queryExternalIdInjective( - client as any, - tokenBridgeAddress, - parsedPayload.originAddress - ); - if (!cancelled) { - setTokenId(tokenId || ""); - } - })(); - } if (parsedPayload && parsedPayload.targetChain === CHAIN_ID_SUI) { (async () => { @@ -845,26 +802,6 @@ export default function Recovery() { setIsVAAPending(isPending); } })(); - } else if (recoverySourceChain === CHAIN_ID_INJECTIVE) { - setRecoverySourceTxError(""); - setRecoverySourceTxIsLoading(true); - setTokenId(""); - (async () => { - const { vaa, isPending, error } = await injective( - recoverySourceTx, - enqueueSnackbar - ); - if (!cancelled) { - setRecoverySourceTxIsLoading(false); - if (vaa) { - setRecoverySignedVAA(vaa); - } - if (error) { - setRecoverySourceTxError(error); - } - setIsVAAPending(isPending); - } - })(); } else if (recoverySourceChain === CHAIN_ID_SUI) { setRecoverySourceTxError(""); setRecoverySourceTxIsLoading(true); @@ -1229,8 +1166,7 @@ export default function Recovery() { value={ parsedPayload ? parsedPayload.targetChain === CHAIN_ID_TERRA2 || - parsedPayload.targetChain === CHAIN_ID_XPLA || - parsedPayload.targetChain === CHAIN_ID_INJECTIVE + parsedPayload.targetChain === CHAIN_ID_XPLA ? tokenId : hexToNativeAssetString( parsedPayload.originAddress, diff --git a/src/components/ShowTx.tsx b/src/components/ShowTx.tsx index f6eb078de..82ab88c66 100644 --- a/src/components/ShowTx.tsx +++ b/src/components/ShowTx.tsx @@ -20,7 +20,6 @@ import { CHAIN_ID_XPLA, CHAIN_ID_APTOS, CHAIN_ID_ARBITRUM, - CHAIN_ID_INJECTIVE, CHAIN_ID_OPTIMISM, CHAIN_ID_SUI, CHAIN_ID_BASE, @@ -174,10 +173,6 @@ export default function ShowTx({ ? `https://${ CLUSTER === "testnet" ? "goerli." : "" }arbiscan.io/tx/${tx?.id}` - : chainId === CHAIN_ID_INJECTIVE - ? `https://${ - CLUSTER === "testnet" ? "testnet." : "" - }explorer.injective.network/transaction/${tx.id}` : chainId === CHAIN_ID_OPTIMISM ? `https://${ CLUSTER === "testnet" ? "goerli-optimism." : "optimistic." diff --git a/src/components/SmartAddress.tsx b/src/components/SmartAddress.tsx index 350502d38..9dd0643db 100644 --- a/src/components/SmartAddress.tsx +++ b/src/components/SmartAddress.tsx @@ -23,7 +23,6 @@ import { CHAIN_ID_APTOS, isValidAptosType, CHAIN_ID_ARBITRUM, - CHAIN_ID_INJECTIVE, terra, CHAIN_ID_OPTIMISM, CHAIN_ID_SUI, @@ -235,14 +234,6 @@ export default function SmartAddress({ ? `https://${CLUSTER === "testnet" ? "goerli." : ""}arbiscan.io/${ isAsset ? "token" : "address" }/${useableAddress}` - : chainId === CHAIN_ID_INJECTIVE - ? `https://${ - CLUSTER === "testnet" ? "testnet." : "" - }explorer.injective.network/${ - isAsset - ? `asset/?tokenType=${isNative ? "native" : "cw20"}&tokenIdentifier=` - : "account/" - }${useableAddress}` : chainId === CHAIN_ID_OPTIMISM ? `https://${ CLUSTER === "testnet" ? "goerli-optimism." : "optimistic." diff --git a/src/components/TokenSelectors/InjectiveTokenPicker.tsx b/src/components/TokenSelectors/InjectiveTokenPicker.tsx deleted file mode 100644 index 390411b37..000000000 --- a/src/components/TokenSelectors/InjectiveTokenPicker.tsx +++ /dev/null @@ -1,168 +0,0 @@ -import { - CHAIN_ID_INJECTIVE, - isNativeDenomInjective, - parseSmartContractStateResponse, -} from "@certusone/wormhole-sdk"; -import { formatUnits } from "@ethersproject/units"; -import { useCallback, useMemo, useRef } from "react"; -import { createParsedTokenAccount } from "../../hooks/useGetSourceParsedTokenAccounts"; -import useIsWalletReady from "../../hooks/useIsWalletReady"; -import useInjectiveNativeBalances from "../../hooks/useInjectiveNativeBalances"; -import { DataWrapper } from "../../store/helpers"; -import { NFTParsedTokenAccount } from "../../store/nftSlice"; -import { ParsedTokenAccount } from "../../store/transferSlice"; -import TokenPicker, { BasicAccountRender } from "./TokenPicker"; -import { - formatNativeDenom, - getInjectiveWasmClient, - INJECTIVE_NATIVE_DENOM, - isValidInjectiveAddress, - NATIVE_INJECTIVE_DECIMALS, -} from "../../utils/injective"; -import injectiveIcon from "../../icons/injective.svg"; - -type InjectiveTokenPickerProps = { - value: ParsedTokenAccount | null; - onChange: (newValue: ParsedTokenAccount | null) => void; - tokenAccounts: DataWrapper | undefined; - disabled: boolean; - resetAccounts: (() => void) | undefined; -}; - -const returnsFalse = () => false; - -export default function InjectiveTokenPicker(props: InjectiveTokenPickerProps) { - const { value, onChange, disabled } = props; - const { walletAddress } = useIsWalletReady(CHAIN_ID_INJECTIVE); - const nativeRefresh = useRef<() => void>(() => {}); - const { balances, isLoading: nativeIsLoading } = useInjectiveNativeBalances( - walletAddress, - nativeRefresh - ); - - const resetAccountWrapper = useCallback(() => { - //we can currently skip calling this as we don't read from sourceParsedTokenAccounts - //resetAccounts && resetAccounts(); - nativeRefresh.current(); - }, []); - const isLoading = nativeIsLoading; // || (tokenMap?.isFetching || false); - - const onChangeWrapper = useCallback( - async (account: NFTParsedTokenAccount | null) => { - if (account === null) { - onChange(null); - return Promise.resolve(); - } - onChange(account); - return Promise.resolve(); - }, - [onChange] - ); - - const injTokenArray = useMemo(() => { - const balancesItems = - balances && walletAddress - ? Object.keys(balances).map((denom) => - //This token account makes a lot of assumptions - createParsedTokenAccount( - walletAddress, - denom, - balances[denom], //amount - NATIVE_INJECTIVE_DECIMALS, //TODO actually get decimals rather than hardcode - 0, //uiAmount is unused - formatUnits(balances[denom], NATIVE_INJECTIVE_DECIMALS), //uiAmountString - formatNativeDenom(denom), // symbol - undefined, //name - injectiveIcon, - true //is native asset - ) - ) - : []; - return balancesItems.filter( - (metadata) => metadata.mintKey === INJECTIVE_NATIVE_DENOM - ); - }, [walletAddress, balances]); - - //TODO this only supports non-native assets. Native assets come from the hook. - //TODO correlate against token list to get metadata - const lookupInjectiveAddress = useCallback( - (lookupAsset: string) => { - if (!walletAddress) { - return Promise.reject("Wallet not connected"); - } - const client = getInjectiveWasmClient(); - return client - .fetchSmartContractState( - lookupAsset, - Buffer.from( - JSON.stringify({ - token_info: {}, - }) - ).toString("base64") - ) - .then((infoData) => - client - .fetchSmartContractState( - lookupAsset, - Buffer.from( - JSON.stringify({ - balance: { - address: walletAddress, - }, - }) - ).toString("base64") - ) - .then((balanceData) => { - if (infoData && balanceData) { - const balance = parseSmartContractStateResponse(balanceData); - const info = parseSmartContractStateResponse(infoData); - return createParsedTokenAccount( - walletAddress, - lookupAsset, - balance.balance.toString(), - info.decimals, - Number(formatUnits(balance.balance, info.decimals)), - formatUnits(balance.balance, info.decimals), - info.symbol, - info.name - ); - } else { - throw new Error("Failed to retrieve Injective account."); - } - }) - ) - .catch((e) => { - return Promise.reject(e); - }); - }, - [walletAddress] - ); - - const isSearchableAddress = useCallback((address: string) => { - return isValidInjectiveAddress(address) && !isNativeDenomInjective(address); - }, []); - - const RenderComp = useCallback( - ({ account }: { account: NFTParsedTokenAccount }) => { - return BasicAccountRender(account, returnsFalse, false); - }, - [] - ); - - return ( - - ); -} diff --git a/src/components/TokenSelectors/SourceTokenSelector.tsx b/src/components/TokenSelectors/SourceTokenSelector.tsx index a744e913f..d3e50f208 100644 --- a/src/components/TokenSelectors/SourceTokenSelector.tsx +++ b/src/components/TokenSelectors/SourceTokenSelector.tsx @@ -2,7 +2,6 @@ import { CHAIN_ID_ALGORAND, CHAIN_ID_APTOS, - CHAIN_ID_INJECTIVE, CHAIN_ID_NEAR, CHAIN_ID_SOLANA, CHAIN_ID_SUI, @@ -39,7 +38,6 @@ import RefreshButtonWrapper from "./RefreshButtonWrapper"; import SolanaTokenPicker from "./SolanaTokenPicker"; import TerraTokenPicker from "./TerraTokenPicker"; import XplaTokenPicker from "./XplaTokenPicker"; -import InjectiveTokenPicker from "./InjectiveTokenPicker"; import SuiTokenPicker from "./SuiTokenPicker"; import SeiTokenPicker from "./SeiTokenPicker"; @@ -162,14 +160,6 @@ export const TokenSelector = (props: TokenSelectorProps) => { tokenAccounts={maps?.tokenAccounts} nft={nft} /> - ) : lookupChain === CHAIN_ID_INJECTIVE ? ( - ) : lookupChain === CHAIN_ID_SUI ? ( { - const isValidNetwork = INJECTIVE_NETWORKS.includes( - process.env.REACT_APP_CLUSTER || "" - ); - if (!isValidNetwork) return []; - - const network = getInjectiveNetworkName(); - const networkEndpoints = getNetworkInfo(network); - - const opts = { - networkChainId: getInjectiveNetworkChainId(), - broadcasterOptions: { - network, - networkEndpoints, - }, - }; - - return [new KeplrWallet(opts)]; -}; - -export interface IInjectiveContext { - wallet?: InjectiveWallet; - address?: string; -} - -export const useInjectiveContext = (): IInjectiveContext => { - const wallet = useWallet(CHAIN_ID_INJECTIVE); - - const address = useMemo(() => wallet?.getAddress(), [wallet]); - - return useMemo( - () => ({ - wallet, - address, - }), - [wallet, address] - ); -}; diff --git a/src/hooks/useCheckIfWormholeWrapped.ts b/src/hooks/useCheckIfWormholeWrapped.ts index 6e616a6ad..8185ba063 100644 --- a/src/hooks/useCheckIfWormholeWrapped.ts +++ b/src/hooks/useCheckIfWormholeWrapped.ts @@ -16,8 +16,6 @@ import { isTerraChain, uint8ArrayToHex, WormholeWrappedInfo, - CHAIN_ID_INJECTIVE, - getOriginalAssetInjective, CHAIN_ID_SUI, getOriginalAssetSui, CHAIN_ID_ETH, @@ -64,7 +62,6 @@ import { import { getOriginalAssetNear, makeNearAccount } from "../utils/near"; import { LCDClient as XplaLCDClient } from "@xpla/xpla.js"; import { getAptosClient } from "../utils/aptos"; -import { getInjectiveWasmClient } from "../utils/injective"; import { getSuiProvider } from "../utils/sui"; import { getOriginalAssetSei, getSeiWasmClient } from "../utils/sei"; import { base58 } from "ethers/lib/utils"; @@ -300,17 +297,6 @@ function useCheckIfWormholeWrapped(nft?: boolean) { } } catch (e) {} } - if (sourceChain === CHAIN_ID_INJECTIVE && sourceAsset) { - try { - const client = getInjectiveWasmClient(); - const wrappedInfo = makeStateSafe( - await getOriginalAssetInjective(sourceAsset, client as any) - ); - if (!cancelled) { - dispatch(setSourceWormholeWrappedInfo(wrappedInfo)); - } - } catch (e) {} - } if (sourceChain === CHAIN_ID_SUI && sourceAsset) { try { const wrappedInfo = makeStateSafe( diff --git a/src/hooks/useFetchForeignAsset.ts b/src/hooks/useFetchForeignAsset.ts index 9ab2efdc9..1d949fc3a 100644 --- a/src/hooks/useFetchForeignAsset.ts +++ b/src/hooks/useFetchForeignAsset.ts @@ -3,7 +3,6 @@ import { ChainId, CHAIN_ID_ALGORAND, CHAIN_ID_APTOS, - CHAIN_ID_INJECTIVE, CHAIN_ID_NEAR, CHAIN_ID_SOLANA, CHAIN_ID_TERRA2, @@ -12,7 +11,6 @@ import { getForeignAssetAlgorand, getForeignAssetAptos, getForeignAssetEth, - getForeignAssetInjective, getForeignAssetSolana, getForeignAssetTerra, getForeignAssetXpla, @@ -52,7 +50,6 @@ import { import { useNearContext } from "../contexts/NearWalletContext"; import { LCDClient as XplaLCDClient } from "@xpla/xpla.js"; import { getAptosClient } from "../utils/aptos"; -import { getInjectiveWasmClient } from "../utils/injective"; import { getSuiProvider } from "../utils/sui"; import { getForeignAssetSei, getSeiWasmClient } from "../utils/sei"; @@ -227,16 +224,6 @@ function useFetchForeignAsset( ) .catch(() => Promise.reject("Failed to make Near account")); } - : foreignChain === CHAIN_ID_INJECTIVE - ? () => { - const client = getInjectiveWasmClient(); - return getForeignAssetInjective( - getTokenBridgeAddressForChain(foreignChain), - client as any, - originChain, - hexToUint8Array(originAssetHex) - ); - } : foreignChain === CHAIN_ID_SUI ? () => { return getForeignAssetSui( diff --git a/src/hooks/useFetchTargetAsset.ts b/src/hooks/useFetchTargetAsset.ts index 84dc373dd..13962f1e4 100644 --- a/src/hooks/useFetchTargetAsset.ts +++ b/src/hooks/useFetchTargetAsset.ts @@ -2,7 +2,6 @@ import { ChainId, CHAIN_ID_ALGORAND, CHAIN_ID_APTOS, - CHAIN_ID_INJECTIVE, CHAIN_ID_NEAR, CHAIN_ID_SOLANA, CHAIN_ID_TERRA2, @@ -12,7 +11,6 @@ import { getForeignAssetAlgorand, getForeignAssetAptos, getForeignAssetEth, - getForeignAssetInjective, getForeignAssetSolana, getForeignAssetTerra, getForeignAssetXpla, @@ -22,7 +20,6 @@ import { isEVMChain, isTerraChain, queryExternalId, - queryExternalIdInjective, CHAIN_ID_SUI, getForeignAssetSui, } from "@certusone/wormhole-sdk"; @@ -85,7 +82,6 @@ import { } from "../utils/near"; import { LCDClient as XplaLCDClient } from "@xpla/xpla.js"; import { getAptosClient } from "../utils/aptos"; -import { getInjectiveWasmClient } from "../utils/injective"; import { getSuiProvider } from "../utils/sui"; import { getForeignAssetSei, @@ -283,25 +279,6 @@ function useFetchTargetAsset(nft?: boolean) { ); } } - } else if (originChain === CHAIN_ID_INJECTIVE) { - const client = getInjectiveWasmClient(); - const tokenBridgeAddress = - getTokenBridgeAddressForChain(CHAIN_ID_INJECTIVE); - const tokenId = await queryExternalIdInjective( - client as any, - tokenBridgeAddress, - originAsset || "" - ); - if (!cancelled) { - dispatch( - setTargetAsset( - receiveDataWrapper({ - doesExist: true, - address: tokenId, - }) - ) - ); - } } else if (originChain === CHAIN_ID_SUI) { const coinType = await getForeignAssetSui( getSuiProvider(), @@ -648,36 +625,6 @@ function useFetchTargetAsset(nft?: boolean) { } } } - if (targetChain === CHAIN_ID_INJECTIVE && originChain && originAsset) { - dispatch(setTargetAsset(fetchDataWrapper())); - try { - const client = getInjectiveWasmClient(); - const asset = await getForeignAssetInjective( - getTokenBridgeAddressForChain(targetChain), - client as any, - originChain, - hexToUint8Array(originAsset) - ); - if (!cancelled) { - dispatch( - setTargetAsset( - receiveDataWrapper({ doesExist: !!asset, address: asset }) - ) - ); - setArgs(); - } - } catch (e) { - if (!cancelled) { - dispatch( - setTargetAsset( - errorDataWrapper( - "Unable to determine existence of wrapped asset" - ) - ) - ); - } - } - } if (targetChain === CHAIN_ID_SUI && originChain && originAsset) { dispatch(setTargetAsset(fetchDataWrapper())); try { diff --git a/src/hooks/useGetIsTransferCompleted.ts b/src/hooks/useGetIsTransferCompleted.ts index e6c60f52f..ee3c6034d 100644 --- a/src/hooks/useGetIsTransferCompleted.ts +++ b/src/hooks/useGetIsTransferCompleted.ts @@ -1,7 +1,6 @@ import { CHAIN_ID_ALGORAND, CHAIN_ID_APTOS, - CHAIN_ID_INJECTIVE, CHAIN_ID_NEAR, CHAIN_ID_SOLANA, CHAIN_ID_SUI, @@ -10,7 +9,6 @@ import { getIsTransferCompletedAlgorand, getIsTransferCompletedAptos, getIsTransferCompletedEth, - getIsTransferCompletedInjective, getIsTransferCompletedSolana, getIsTransferCompletedSui, getIsTransferCompletedTerra, @@ -45,7 +43,6 @@ import useIsWalletReady from "./useIsWalletReady"; import useTransferSignedVAA from "./useTransferSignedVAA"; import { LCDClient as XplaLCDClient } from "@xpla/xpla.js"; import { getAptosClient } from "../utils/aptos"; -import { getInjectiveWasmClient } from "../utils/injective"; import { getSuiProvider } from "../utils/sui"; import { getIsTransferCompletedSei, getSeiWasmClient } from "../utils/sei"; @@ -243,24 +240,6 @@ export default function useGetIsTransferCompleted( setIsLoading(false); } })(); - } else if (targetChain === CHAIN_ID_INJECTIVE) { - setIsLoading(true); - (async () => { - try { - const client = getInjectiveWasmClient(); - transferCompleted = await getIsTransferCompletedInjective( - getTokenBridgeAddressForChain(targetChain), - signedVAA, - client as any - ); - } catch (error) { - console.error(error); - } - if (!cancelled) { - setIsTransferCompleted(transferCompleted); - setIsLoading(false); - } - })(); } else if (targetChain === CHAIN_ID_SUI) { setIsLoading(true); (async () => { diff --git a/src/hooks/useGetSourceParsedTokenAccounts.ts b/src/hooks/useGetSourceParsedTokenAccounts.ts index 9a5209cde..80648c788 100644 --- a/src/hooks/useGetSourceParsedTokenAccounts.ts +++ b/src/hooks/useGetSourceParsedTokenAccounts.ts @@ -24,7 +24,6 @@ import { ethers_contracts, WSOL_ADDRESS, WSOL_DECIMALS, - CHAIN_ID_INJECTIVE, CHAIN_ID_SUI, CHAIN_ID_ARBITRUM, CHAIN_ID_BASE, @@ -2066,10 +2065,6 @@ function useGetAvailableTokens(nft: boolean = false) { tokenAccounts, resetAccounts: resetSourceAccounts, } - : lookupChain === CHAIN_ID_INJECTIVE - ? { - resetAccounts: resetSourceAccounts, - } : lookupChain === CHAIN_ID_SUI ? { tokenAccounts, diff --git a/src/hooks/useGetTargetParsedTokenAccounts.ts b/src/hooks/useGetTargetParsedTokenAccounts.ts index 2d0a12f66..17170bb73 100644 --- a/src/hooks/useGetTargetParsedTokenAccounts.ts +++ b/src/hooks/useGetTargetParsedTokenAccounts.ts @@ -1,7 +1,6 @@ import { CHAIN_ID_ALGORAND, CHAIN_ID_APTOS, - CHAIN_ID_INJECTIVE, CHAIN_ID_NEAR, CHAIN_ID_SOLANA, CHAIN_ID_SUI, @@ -10,7 +9,6 @@ import { ensureHexPrefix, ethers_contracts, isEVMChain, - isNativeDenomInjective, isNativeDenomXpla, isTerraChain, parseSmartContractStateResponse, @@ -52,12 +50,6 @@ import { LCDClient as XplaLCDClient } from "@xpla/xpla.js"; import { NATIVE_XPLA_DECIMALS } from "../utils/xpla"; import { useAptosContext } from "../contexts/AptosWalletContext"; import { getAptosClient } from "../utils/aptos"; -import { - getInjectiveBankClient, - NATIVE_INJECTIVE_DECIMALS, - getInjectiveWasmClient, -} from "../utils/injective"; -import { useInjectiveContext } from "../contexts/InjectiveWalletContext"; import { useTerraWallet } from "../contexts/TerraWalletContext"; import { useSuiWallet } from "../contexts/SuiWalletContext"; import { getSuiProvider } from "../utils/sui"; @@ -89,7 +81,6 @@ function useGetTargetParsedTokenAccounts() { const { address: algoAccount } = useAlgorandWallet(); const { accountId: nearAccountId } = useNearContext(); const { account: aptosAddress } = useAptosContext(); - const { address: injAddress } = useInjectiveContext(); const seiWallet = useSeiWallet(); const seiAddress = seiWallet?.getAddress(); const suiWallet = useSuiWallet(); @@ -589,87 +580,6 @@ function useGetTargetParsedTokenAccounts() { } } } - if (targetChain === CHAIN_ID_INJECTIVE && injAddress) { - if (isNativeDenomInjective(targetAsset)) { - const client = getInjectiveBankClient(); - client - .fetchBalance({ accountAddress: injAddress, denom: targetAsset }) - .then(({ amount }) => { - if (!cancelled) { - dispatch( - setTargetParsedTokenAccount( - createParsedTokenAccount( - "", - "", - amount, - NATIVE_INJECTIVE_DECIMALS, - Number(formatUnits(amount, NATIVE_INJECTIVE_DECIMALS)), - formatUnits(amount, NATIVE_INJECTIVE_DECIMALS), - symbol, - tokenName, - logo - ) - ) - ); - } - }) - .catch(() => { - if (!cancelled) { - // TODO: error state - } - }); - } else { - const client = getInjectiveWasmClient(); - client - .fetchSmartContractState( - targetAsset, - Buffer.from( - JSON.stringify({ - token_info: {}, - }) - ).toString("base64") - ) - .then((infoData) => - client - .fetchSmartContractState( - targetAsset, - Buffer.from( - JSON.stringify({ - balance: { - address: injAddress, - }, - }) - ).toString("base64") - ) - .then((balanceData) => { - if (infoData && balanceData && !cancelled) { - const balance = parseSmartContractStateResponse(balanceData); - const info = parseSmartContractStateResponse(infoData); - dispatch( - setTargetParsedTokenAccount( - createParsedTokenAccount( - "", - "", - balance.balance.toString(), - info.decimals, - Number(formatUnits(balance.balance, info.decimals)), - formatUnits(balance.balance, info.decimals), - symbol, - tokenName, - logo - ) - ) - ); - } - }) - ) - .catch((e) => { - if (!cancelled) { - // TODO: error state - } - }); - } - } return () => { cancelled = true; @@ -693,7 +603,6 @@ function useGetTargetParsedTokenAccounts() { nearAccountId, xplaWallet, aptosAddress, - injAddress, seiAddress, suiAddress, ]); diff --git a/src/hooks/useHandleAttest.tsx b/src/hooks/useHandleAttest.tsx index 563718040..16b286925 100644 --- a/src/hooks/useHandleAttest.tsx +++ b/src/hooks/useHandleAttest.tsx @@ -2,14 +2,12 @@ import { attestFromAlgorand, attestFromAptos, attestFromEth, - attestFromInjective, attestFromSolana, attestFromTerra, attestFromXpla, ChainId, CHAIN_ID_ALGORAND, CHAIN_ID_APTOS, - CHAIN_ID_INJECTIVE, CHAIN_ID_KLAYTN, CHAIN_ID_NEAR, CHAIN_ID_SOLANA, @@ -17,7 +15,6 @@ import { CHAIN_ID_SEI, getEmitterAddressAlgorand, getEmitterAddressEth, - getEmitterAddressInjective, getEmitterAddressSolana, getEmitterAddressTerra, getEmitterAddressXpla, @@ -26,7 +23,6 @@ import { isTerraChain, parseSequenceFromLogAlgorand, parseSequenceFromLogEth, - parseSequenceFromLogInjective, parseSequenceFromLogSolana, parseSequenceFromLogTerra, parseSequenceFromLogXpla, @@ -95,12 +91,9 @@ import parseError from "../utils/parseError"; import { signSendAndConfirm } from "../utils/solana"; import { postWithFees, waitForTerraExecution } from "../utils/terra"; import { postWithFeesXpla, waitForXplaExecution } from "../utils/xpla"; -import { useInjectiveContext } from "../contexts/InjectiveWalletContext"; -import { broadcastInjectiveTx } from "../utils/injective"; import { AlgorandWallet } from "@xlabs-libs/wallet-aggregator-algorand"; import { SolanaWallet } from "@xlabs-libs/wallet-aggregator-solana"; import { AptosWallet } from "@xlabs-libs/wallet-aggregator-aptos"; -import { InjectiveWallet } from "@xlabs-libs/wallet-aggregator-injective"; import { NearWallet } from "@xlabs-libs/wallet-aggregator-near"; import { useTerraWallet } from "../contexts/TerraWalletContext"; import { TerraWallet } from "@xlabs-libs/wallet-aggregator-terra"; @@ -515,63 +508,6 @@ async function terra( } } -async function injective( - dispatch: any, - enqueueSnackbar: any, - wallet: InjectiveWallet, - walletAddress: string, - asset: string, - onError: (error: any) => void, - onStart: (extra?: Partial) => void -) { - dispatch(setIsSending(true)); - try { - const tokenBridgeAddress = - getTokenBridgeAddressForChain(CHAIN_ID_INJECTIVE); - const msg = await attestFromInjective( - tokenBridgeAddress, - walletAddress, - asset - ); - const tx = await broadcastInjectiveTx( - wallet, - walletAddress, - msg, - "Attest Token" - ); - onStart?.({ txId: tx.txHash }); - dispatch(setAttestTx({ id: tx.txHash, block: tx.height })); - enqueueSnackbar(null, { - content: Transaction confirmed, - }); - const sequence = parseSequenceFromLogInjective(tx); - if (!sequence) { - throw new Error("Sequence not found"); - } - const emitterAddress = await getEmitterAddressInjective(tokenBridgeAddress); - enqueueSnackbar(null, { - content: Fetching VAA, - }); - const { vaaBytes } = await getSignedVAAWithRetry( - WORMHOLE_RPC_HOSTS, - CHAIN_ID_INJECTIVE, - emitterAddress, - sequence - ); - dispatch(setSignedVAAHex(uint8ArrayToHex(vaaBytes))); - enqueueSnackbar(null, { - content: Fetched Signed VAA, - }); - } catch (e) { - console.error(e); - enqueueSnackbar(null, { - content: {parseError(e)}, - }); - dispatch(setIsSending(false)); - onError(e); - } -} - async function sui( dispatch: any, enqueueSnackbar: any, @@ -729,7 +665,6 @@ export function useHandleAttest() { const { address: algoAccount, wallet: algoWallet } = useAlgorandWallet(); const { account: aptosAddress, wallet: aptosWallet } = useAptosContext(); const { accountId: nearAccountId, wallet } = useNearContext(); - const { wallet: injWallet, address: injAddress } = useInjectiveContext(); const seiWallet = useSeiWallet(); const seiAddress = seiWallet?.getAddress(); const suiWallet = useSuiWallet(); @@ -822,16 +757,6 @@ export function useHandleAttest() { onError, onStart ); - } else if (sourceChain === CHAIN_ID_INJECTIVE && injWallet && injAddress) { - injective( - dispatch, - enqueueSnackbar, - injWallet, - injAddress, - sourceAsset, - onError, - onStart - ); } else if (sourceChain === CHAIN_ID_SEI && seiWallet && seiAddress) { sei(dispatch, enqueueSnackbar, seiWallet, sourceAsset, onError, onStart); } else if ( @@ -855,8 +780,6 @@ export function useHandleAttest() { aptosAddress, nearAccountId, wallet, - injWallet, - injAddress, seiWallet, seiAddress, suiWallet, diff --git a/src/hooks/useHandleCreateWrapped.tsx b/src/hooks/useHandleCreateWrapped.tsx index c3ebdc12d..56c96bb7a 100644 --- a/src/hooks/useHandleCreateWrapped.tsx +++ b/src/hooks/useHandleCreateWrapped.tsx @@ -3,7 +3,6 @@ import { CHAIN_ID_ACALA, CHAIN_ID_ALGORAND, CHAIN_ID_APTOS, - CHAIN_ID_INJECTIVE, CHAIN_ID_KARURA, CHAIN_ID_KLAYTN, CHAIN_ID_NEAR, @@ -12,7 +11,6 @@ import { createWrappedOnAlgorand, createWrappedOnAptos, createWrappedOnEth, - createWrappedOnInjective, createWrappedOnSolana, createWrappedOnTerra, createWrappedOnXpla, @@ -21,7 +19,6 @@ import { isTerraChain, TerraChainId, updateWrappedOnEth, - updateWrappedOnInjective, updateWrappedOnSolana, updateWrappedOnTerra, updateWrappedOnXpla, @@ -78,12 +75,9 @@ import parseError from "../utils/parseError"; import { postVaa, signSendAndConfirm } from "../utils/solana"; import { postWithFees } from "../utils/terra"; import useAttestSignedVAA from "./useAttestSignedVAA"; -import { broadcastInjectiveTx } from "../utils/injective"; -import { useInjectiveContext } from "../contexts/InjectiveWalletContext"; import { AlgorandWallet } from "@xlabs-libs/wallet-aggregator-algorand"; import { SolanaWallet } from "@xlabs-libs/wallet-aggregator-solana"; import { AptosWallet } from "@xlabs-libs/wallet-aggregator-aptos"; -import { InjectiveWallet } from "@xlabs-libs/wallet-aggregator-injective"; import { NearWallet } from "@xlabs-libs/wallet-aggregator-near"; import { useTerraWallet } from "../contexts/TerraWalletContext"; import { TerraWallet } from "@xlabs-libs/wallet-aggregator-terra"; @@ -549,50 +543,6 @@ async function terra( } } -async function injective( - dispatch: any, - enqueueSnackbar: any, - wallet: InjectiveWallet, - walletAddress: string, - signedVAA: Uint8Array, - shouldUpdate: boolean, - onError: (error: any) => void, - onStart: (extra?: Partial) => void -) { - dispatch(setIsCreating(true)); - const tokenBridgeAddress = getTokenBridgeAddressForChain(CHAIN_ID_INJECTIVE); - try { - const msg = shouldUpdate - ? await updateWrappedOnInjective( - tokenBridgeAddress, - walletAddress, - signedVAA - ) - : await createWrappedOnInjective( - tokenBridgeAddress, - walletAddress, - signedVAA - ); - const tx = await broadcastInjectiveTx( - wallet, - walletAddress, - msg, - "Wormhole - Create Wrapped" - ); - onStart({ txId: tx.txHash }); - dispatch(setCreateTx({ id: tx.txHash, block: tx.height })); - enqueueSnackbar(null, { - content: Transaction confirmed, - }); - } catch (e) { - enqueueSnackbar(null, { - content: {parseError(e)}, - }); - dispatch(setIsCreating(false)); - onError(e); - } -} - async function sui( dispatch: any, enqueueSnackbar: any, @@ -648,7 +598,7 @@ async function sui( } const wrappedAssetSetupEvent = suiPrepareRegistrationTxRes.objectChanges?.find( - (oc) => + (oc: any) => oc.type === "created" && oc.objectType.includes("WrappedAssetSetup") ); const wrappedAssetSetupType = @@ -807,7 +757,6 @@ export function useHandleCreateWrapped( const xplaWallet = useXplaWallet(); const { address: algoAccount, wallet: algoWallet } = useAlgorandWallet(); const { account: aptosAddress, wallet: aptosWallet } = useAptosContext(); - const { wallet: injWallet, address: injAddress } = useInjectiveContext(); const { accountId: nearAccountId, wallet } = useNearContext(); const suiWallet = useSuiWallet(); const seiWallet = useSeiWallet(); @@ -937,22 +886,6 @@ export function useHandleCreateWrapped( onError, onStart ); - } else if ( - targetChain === CHAIN_ID_INJECTIVE && - injWallet && - injAddress && - !!signedVAA - ) { - injective( - dispatch, - enqueueSnackbar, - injWallet, - injAddress, - signedVAA, - shouldUpdate, - onError, - onStart - ); } else if ( targetChain === CHAIN_ID_SUI && suiWallet && @@ -1006,8 +939,6 @@ export function useHandleCreateWrapped( xplaWallet, aptosAddress, aptosWallet, - injWallet, - injAddress, foreignAddress, suiWallet, seiWallet, diff --git a/src/hooks/useHandleRedeem.tsx b/src/hooks/useHandleRedeem.tsx index e06d70a91..2b4402a42 100644 --- a/src/hooks/useHandleRedeem.tsx +++ b/src/hooks/useHandleRedeem.tsx @@ -2,7 +2,6 @@ import { ChainId, CHAIN_ID_ALGORAND, CHAIN_ID_APTOS, - CHAIN_ID_INJECTIVE, CHAIN_ID_KLAYTN, CHAIN_ID_NEAR, CHAIN_ID_SOLANA, @@ -12,7 +11,6 @@ import { redeemOnAlgorand, redeemOnEth, redeemOnEthNative, - redeemOnInjective, redeemOnSolana, redeemOnTerra, redeemOnXpla, @@ -81,12 +79,9 @@ import { postVaa, signSendAndConfirm } from "../utils/solana"; import { postWithFees } from "../utils/terra"; import useTransferSignedVAA from "./useTransferSignedVAA"; import { postWithFeesXpla } from "../utils/xpla"; -import { broadcastInjectiveTx } from "../utils/injective"; -import { useInjectiveContext } from "../contexts/InjectiveWalletContext"; import { AlgorandWallet } from "@xlabs-libs/wallet-aggregator-algorand"; import { SolanaWallet } from "@xlabs-libs/wallet-aggregator-solana"; import { AptosWallet } from "@xlabs-libs/wallet-aggregator-aptos"; -import { InjectiveWallet } from "@xlabs-libs/wallet-aggregator-injective"; import { NearWallet } from "@xlabs-libs/wallet-aggregator-near"; import { useTerraWallet } from "../contexts/TerraWalletContext"; import { TerraWallet } from "@xlabs-libs/wallet-aggregator-terra"; @@ -340,7 +335,7 @@ async function sei( try { const vaa = parseVaa(signedVAA); const transfer = parseTokenTransferPayload(vaa.payload); - const receiver = cosmos.humanAddress("sei", transfer.to); + const receiver = cosmos.humanAddress("sei", new Uint8Array(transfer.to)); const contractAddress = receiver === SEI_TRANSLATOR ? SEI_TRANSLATOR @@ -402,40 +397,6 @@ async function sei( } } -async function injective( - dispatch: any, - enqueueSnackbar: any, - wallet: InjectiveWallet, - walletAddress: string, - signedVAA: Uint8Array, - onSuccess?: () => void -) { - dispatch(setIsRedeeming(true)); - try { - const msg = await redeemOnInjective( - getTokenBridgeAddressForChain(CHAIN_ID_INJECTIVE), - walletAddress, - signedVAA - ); - const tx = await broadcastInjectiveTx( - wallet, - walletAddress, - msg, - "Wormhole - Complete Transfer" - ); - dispatch(setRedeemTx({ id: tx.txHash, block: tx.height })); - enqueueSnackbar(null, { - content: Transaction confirmed, - }); - onSuccess?.(); - } catch (e) { - enqueueSnackbar(null, { - content: {parseError(e)}, - }); - dispatch(setIsRedeeming(false)); - } -} - async function solana( dispatch: any, enqueueSnackbar: any, @@ -605,7 +566,6 @@ export function useHandleRedeem() { const { address: algoAccount, wallet: algoWallet } = useAlgorandWallet(); const { accountId: nearAccountId, wallet } = useNearContext(); const { account: aptosAddress, wallet: aptosWallet } = useAptosContext(); - const { wallet: injWallet, address: injAddress } = useInjectiveContext(); const suiWallet = useSuiWallet(); const seiWallet = useSeiWallet(); const seiAddress = seiWallet?.getAddress(); @@ -714,20 +674,6 @@ export function useHandleRedeem() { wallet, onSuccess ); - } else if ( - targetChain === CHAIN_ID_INJECTIVE && - injWallet && - injAddress && - signedVAA - ) { - injective( - dispatch, - enqueueSnackbar, - injWallet, - injAddress, - signedVAA, - onSuccess - ); } else if ( targetChain === CHAIN_ID_SUI && suiWallet?.getAddress() && @@ -749,8 +695,6 @@ export function useHandleRedeem() { algoAccount, nearAccountId, wallet, - injWallet, - injAddress, suiWallet, dispatch, enqueueSnackbar, @@ -805,20 +749,6 @@ export function useHandleRedeem() { !!signedVAA ) { algo(dispatch, enqueueSnackbar, algoWallet, signedVAA, onSuccess); - } else if ( - targetChain === CHAIN_ID_INJECTIVE && - injWallet && - injAddress && - signedVAA - ) { - injective( - dispatch, - enqueueSnackbar, - injWallet, - injAddress, - signedVAA, - onSuccess - ); } else if ( targetChain === CHAIN_ID_SEI && seiWallet && @@ -841,8 +771,6 @@ export function useHandleRedeem() { solPK, terraWallet, algoAccount, - injWallet, - injAddress, seiWallet, seiAddress, suiWallet, diff --git a/src/hooks/useHandleTransfer.tsx b/src/hooks/useHandleTransfer.tsx index 8ea67c908..1dec01294 100644 --- a/src/hooks/useHandleTransfer.tsx +++ b/src/hooks/useHandleTransfer.tsx @@ -2,7 +2,6 @@ import { ChainId, CHAIN_ID_ALGORAND, CHAIN_ID_APTOS, - CHAIN_ID_INJECTIVE, CHAIN_ID_KLAYTN, CHAIN_ID_SOLANA, CHAIN_ID_XPLA, @@ -11,7 +10,6 @@ import { createNonce, getEmitterAddressAlgorand, getEmitterAddressEth, - getEmitterAddressInjective, getEmitterAddressSolana, getEmitterAddressTerra, getEmitterAddressXpla, @@ -20,7 +18,6 @@ import { isTerraChain, parseSequenceFromLogAlgorand, parseSequenceFromLogEth, - parseSequenceFromLogInjective, parseSequenceFromLogSolana, parseSequenceFromLogTerra, parseSequenceFromLogXpla, @@ -28,7 +25,6 @@ import { transferFromAlgorand, transferFromEth, transferFromEthNative, - transferFromInjective, transferFromTerra, transferFromXpla, transferFromAptos, @@ -121,12 +117,9 @@ import { signSendAndConfirm } from "../utils/solana"; import { postWithFees, waitForTerraExecution } from "../utils/terra"; import useTransferTargetAddressHex from "./useTransferTargetAddress"; import { postWithFeesXpla, waitForXplaExecution } from "../utils/xpla"; -import { broadcastInjectiveTx } from "../utils/injective"; -import { useInjectiveContext } from "../contexts/InjectiveWalletContext"; import { AlgorandWallet } from "@xlabs-libs/wallet-aggregator-algorand"; import { SolanaWallet } from "@xlabs-libs/wallet-aggregator-solana"; import { AptosWallet } from "@xlabs-libs/wallet-aggregator-aptos"; -import { InjectiveWallet } from "@xlabs-libs/wallet-aggregator-injective"; import { NearWallet } from "@xlabs-libs/wallet-aggregator-near"; import { useTerraWallet } from "../contexts/TerraWalletContext"; import { TerraWallet } from "@xlabs-libs/wallet-aggregator-terra"; @@ -803,68 +796,6 @@ async function terra( } } -async function injective( - dispatch: any, - enqueueSnackbar: any, - wallet: InjectiveWallet, - walletAddress: string, - asset: string, - amount: string, - decimals: number, - targetChain: ChainId, - targetAddress: Uint8Array, - maybeAdditionalPayload: MaybeAdditionalPayloadFn, - relayerFee?: string, - onError?: (error: any) => void, - onStart?: (extra?: Partial) => void -) { - dispatch(setIsSending(true)); - try { - const baseAmountParsed = parseUnits(amount, decimals); - const feeParsed = parseUnits(relayerFee || "0", decimals); - const transferAmountParsed = baseAmountParsed.add(feeParsed); - const additionalPayload = maybeAdditionalPayload(); - const tokenBridgeAddress = - getTokenBridgeAddressForChain(CHAIN_ID_INJECTIVE); - const msgs = await transferFromInjective( - walletAddress, - tokenBridgeAddress, - asset, - transferAmountParsed.toString(), - targetChain, - additionalPayload?.receivingContract || targetAddress, - feeParsed.toString(), - additionalPayload?.payload - ); - const tx = await broadcastInjectiveTx( - wallet, - walletAddress, - msgs, - "Wormhole - Initiate Transfer" - ); - onStart?.({ txId: tx.txHash }); - dispatch(setTransferTx({ id: tx.txHash, block: tx.height })); - enqueueSnackbar(null, { - content: Transaction confirmed, - }); - const sequence = parseSequenceFromLogInjective(tx); - if (!sequence) { - throw new Error("Sequence not found"); - } - const emitterAddress = await getEmitterAddressInjective(tokenBridgeAddress); - await fetchSignedVAA( - CHAIN_ID_INJECTIVE, - emitterAddress, - sequence, - enqueueSnackbar, - dispatch - ); - } catch (e) { - handleError(e, enqueueSnackbar, dispatch); - onError?.(e); - } -} - async function sei( dispatch: any, enqueueSnackbar: any, @@ -1091,7 +1022,6 @@ export function useHandleTransfer() { const { address: algoAccount, wallet: algoWallet } = useAlgorandWallet(); const { accountId: nearAccountId, wallet } = useNearContext(); const { account: aptosAddress, wallet: aptosWallet } = useAptosContext(); - const { wallet: injWallet, address: injAddress } = useInjectiveContext(); const suiWallet = useSuiWallet(); const seiWallet = useSeiWallet(); const seiAddress = seiWallet?.getAddress(); @@ -1364,29 +1294,6 @@ export function useHandleTransfer() { onError, onStart ); - } else if ( - sourceChain === CHAIN_ID_INJECTIVE && - injWallet && - injAddress && - !!sourceAsset && - decimals !== undefined && - !!targetAddress - ) { - injective( - dispatch, - enqueueSnackbar, - injWallet, - injAddress, - sourceAsset, - amount, - decimals, - targetChain, - targetAddress, - maybeAdditionalPayload, - relayerFee, - onError, - onStart - ); } else if ( sourceChain === CHAIN_ID_SUI && suiWallet?.isConnected() && @@ -1434,8 +1341,6 @@ export function useHandleTransfer() { nearAccountId, wallet, aptosAddress, - injWallet, - injAddress, suiWallet, dispatch, enqueueSnackbar, diff --git a/src/hooks/useInjectiveMetadata.ts b/src/hooks/useInjectiveMetadata.ts deleted file mode 100644 index 940302b3f..000000000 --- a/src/hooks/useInjectiveMetadata.ts +++ /dev/null @@ -1,88 +0,0 @@ -import { parseSmartContractStateResponse } from "@certusone/wormhole-sdk"; -import { ChainGrpcWasmApi } from "@injectivelabs/sdk-ts"; -import { useLayoutEffect, useMemo, useState } from "react"; -import { DataWrapper } from "../store/helpers"; -import { getInjectiveWasmClient } from "../utils/injective"; - -export type InjectiveMetadata = { - symbol?: string; - logo?: string; - tokenName?: string; - decimals?: number; -}; - -const fetchSingleMetadata = async (address: string, client: ChainGrpcWasmApi) => - client - .fetchSmartContractState( - address, - Buffer.from(JSON.stringify({ token_info: {} })).toString("base64") - ) - .then((data) => { - const parsed = parseSmartContractStateResponse(data); - return { - symbol: parsed.symbol, - tokenName: parsed.name, - decimals: parsed.decimals, - } as InjectiveMetadata; - }); - -const fetchInjectiveMetadata = async (addresses: string[]) => { - const client = getInjectiveWasmClient(); - const promises: Promise[] = []; - addresses.forEach((address) => { - promises.push(fetchSingleMetadata(address, client)); - }); - const resultsArray = await Promise.all(promises); - const output = new Map(); - addresses.forEach((address, index) => { - output.set(address, resultsArray[index]); - }); - - return output; -}; - -const useInjectiveMetadata = ( - addresses: string[] -): DataWrapper> => { - const [isFetching, setIsFetching] = useState(false); - const [error, setError] = useState(""); - const [data, setData] = useState | null>(null); - - useLayoutEffect(() => { - let cancelled = false; - if (addresses.length) { - setIsFetching(true); - setError(""); - setData(null); - fetchInjectiveMetadata(addresses).then( - (results) => { - if (!cancelled) { - setData(results); - setIsFetching(false); - } - }, - () => { - if (!cancelled) { - setError("Could not retrieve contract metadata"); - setIsFetching(false); - } - } - ); - } - return () => { - cancelled = true; - }; - }, [addresses]); - - return useMemo( - () => ({ - data, - isFetching, - error, - receivedAt: null, - }), - [data, isFetching, error] - ); -}; - -export default useInjectiveMetadata; diff --git a/src/hooks/useInjectiveNativeBalances.ts b/src/hooks/useInjectiveNativeBalances.ts deleted file mode 100644 index ea0b5386b..000000000 --- a/src/hooks/useInjectiveNativeBalances.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { MutableRefObject, useEffect, useMemo, useState } from "react"; -import { getInjectiveBankClient } from "../utils/injective"; - -export interface InjectiveNativeBalances { - [index: string]: string; -} - -export default function useInjectiveNativeBalances( - walletAddress?: string, - refreshRef?: MutableRefObject<() => void> -) { - const [isLoading, setIsLoading] = useState(true); - const [balances, setBalances] = useState( - {} - ); - const [refresh, setRefresh] = useState(false); - useEffect(() => { - if (refreshRef) { - refreshRef.current = () => { - setRefresh(true); - }; - } - }, [refreshRef]); - useEffect(() => { - setRefresh(false); - if (walletAddress) { - setIsLoading(true); - setBalances(undefined); - const client = getInjectiveBankClient(); - client - .fetchBalances(walletAddress) - .then(({ balances }) => { - const nativeBalances = balances.reduce((obj, { denom, amount }) => { - obj[denom] = amount; - return obj; - }, {} as InjectiveNativeBalances); - setIsLoading(false); - setBalances(nativeBalances); - }) - .catch((e) => { - console.error(e); - setIsLoading(false); - setBalances(undefined); - }); - } else { - setIsLoading(false); - setBalances(undefined); - } - }, [walletAddress, refresh]); - const value = useMemo(() => ({ isLoading, balances }), [isLoading, balances]); - return value; -} diff --git a/src/hooks/useIsWalletReady.ts b/src/hooks/useIsWalletReady.ts index ca5e99a82..fad0feb0b 100644 --- a/src/hooks/useIsWalletReady.ts +++ b/src/hooks/useIsWalletReady.ts @@ -2,7 +2,6 @@ import { ChainId, CHAIN_ID_ALGORAND, CHAIN_ID_APTOS, - CHAIN_ID_INJECTIVE, CHAIN_ID_NEAR, CHAIN_ID_SOLANA, CHAIN_ID_XPLA, @@ -19,7 +18,6 @@ import { useSolanaWallet } from "../contexts/SolanaWalletContext"; import { APTOS_NETWORK, CLUSTER, getEvmChainId } from "../utils/consts"; import { useXplaWallet } from "../contexts/XplaWalletContext"; import { useAptosContext } from "../contexts/AptosWalletContext"; -import { useInjectiveContext } from "../contexts/InjectiveWalletContext"; import { useTerraWallet } from "../contexts/TerraWalletContext"; import { useSuiWallet } from "../contexts/SuiWalletContext"; import { useSeiWallet } from "../contexts/SeiWalletContext"; @@ -69,8 +67,6 @@ function useIsWalletReady( const hasCorrectAptosNetwork = aptosNetwork?.name?.toLowerCase().includes(APTOS_NETWORK.toLowerCase()) || (CLUSTER === "devnet" && aptosNetwork?.chainId === "4"); - const { address: injAddress } = useInjectiveContext(); - const hasInjWallet = !!injAddress; const suiWallet = useSuiWallet(); const suiAddress = suiWallet?.getAddress(); const seiWallet = useSeiWallet(); @@ -112,9 +108,6 @@ function useIsWalletReady( ); } } - if (chainId === CHAIN_ID_INJECTIVE && hasInjWallet && injAddress) { - return createWalletStatus(true, undefined, injAddress); - } if (chainId === CHAIN_ID_SUI && suiAddress) { return createWalletStatus(true, undefined, suiAddress); } @@ -155,8 +148,6 @@ function useIsWalletReady( hasAptosWallet, aptosAddress, hasCorrectAptosNetwork, - hasInjWallet, - injAddress, suiAddress, hasSeiWallet, seiAddress, diff --git a/src/hooks/useMetadata.ts b/src/hooks/useMetadata.ts index ac17eb6eb..34d15b28a 100644 --- a/src/hooks/useMetadata.ts +++ b/src/hooks/useMetadata.ts @@ -2,7 +2,6 @@ import { ChainId, CHAIN_ID_ALGORAND, CHAIN_ID_APTOS, - CHAIN_ID_INJECTIVE, CHAIN_ID_NEAR, CHAIN_ID_SOLANA, CHAIN_ID_TERRA2, @@ -21,9 +20,6 @@ import { Metadata } from "../utils/metaplex"; import useAlgoMetadata, { AlgoMetadata } from "./useAlgoMetadata"; import useAptosMetadata, { AptosMetadata } from "./useAptosMetadata"; import useEvmMetadata, { EvmMetadata } from "./useEvmMetadata"; -import useInjectiveMetadata, { - InjectiveMetadata, -} from "./useInjectiveMetadata"; import useMetaplexData from "./useMetaplexData"; import useNearMetadata from "./useNearMetadata"; import useSolanaTokenMap from "./useSolanaTokenMap"; @@ -241,33 +237,6 @@ const constructAptosMetadata = ( }; }; -const constructInjectiveMetadata = ( - addresses: string[], - metadataMap: DataWrapper> -) => { - const isFetching = metadataMap.isFetching; - const error = metadataMap.error; - const receivedAt = metadataMap.receivedAt; - const data = new Map(); - addresses.forEach((address) => { - const meta = metadataMap.data?.get(address); - const obj = { - symbol: meta?.symbol || undefined, - logo: undefined, - tokenName: meta?.tokenName || undefined, - decimals: meta?.decimals, - }; - data.set(address, obj); - }); - - return { - isFetching, - error, - receivedAt, - data, - }; -}; - const constructSuiMetadata = ( addresses: string[], metadataMap: DataWrapper> @@ -323,9 +292,6 @@ export default function useMetadata( const aptosAddresses = useMemo(() => { return chainId === CHAIN_ID_APTOS ? addresses : []; }, [chainId, addresses]); - const injAddresses = useMemo(() => { - return chainId === CHAIN_ID_INJECTIVE ? addresses : []; - }, [chainId, addresses]); const seiAddresses = useMemo(() => { return chainId === CHAIN_ID_SEI ? addresses : []; }, [chainId, addresses]); @@ -343,7 +309,6 @@ export default function useMetadata( const nearMetadata = useNearMetadata(nearAddresses); const xplaMetadata = useXplaMetadata(xplaAddresses); const aptosMetadata = useAptosMetadata(aptosAddresses); - const injMetadata = useInjectiveMetadata(injAddresses); const suiMetadata = useSuiMetadata(suiAddresses); const seiMetadata = useSeiMetadata(seiAddresses); @@ -368,8 +333,6 @@ export default function useMetadata( ? constructXplaMetadata(xplaAddresses, xplaMetadata) : chainId === CHAIN_ID_APTOS ? constructAptosMetadata(aptosAddresses, aptosMetadata) - : chainId === CHAIN_ID_INJECTIVE - ? constructInjectiveMetadata(injAddresses, injMetadata) : chainId === CHAIN_ID_SEI ? constructSeiMetadata(seiAddresses, seiMetadata) : chainId === CHAIN_ID_SUI @@ -393,8 +356,6 @@ export default function useMetadata( xplaMetadata, aptosAddresses, aptosMetadata, - injAddresses, - injMetadata, suiAddresses, suiMetadata, seiAddresses, diff --git a/src/hooks/useOriginalAsset.ts b/src/hooks/useOriginalAsset.ts index dd93729b9..52b08c6e2 100644 --- a/src/hooks/useOriginalAsset.ts +++ b/src/hooks/useOriginalAsset.ts @@ -2,7 +2,6 @@ import { ChainId, CHAIN_ID_ALGORAND, CHAIN_ID_APTOS, - CHAIN_ID_INJECTIVE, CHAIN_ID_NEAR, CHAIN_ID_SOLANA, CHAIN_ID_TERRA2, @@ -11,14 +10,12 @@ import { getOriginalAssetAptos, getOriginalAssetCosmWasm, getOriginalAssetEth, - getOriginalAssetInjective, getOriginalAssetSol, getTypeFromExternalAddress, hexToNativeAssetString, isEVMChain, isTerraChain, queryExternalId, - queryExternalIdInjective, uint8ArrayToHex, uint8ArrayToNative, CHAIN_ID_SUI, @@ -65,7 +62,6 @@ import { import useIsWalletReady from "./useIsWalletReady"; import { LCDClient as XplaLCDClient } from "@xpla/xpla.js"; import { getAptosClient } from "../utils/aptos"; -import { getInjectiveWasmClient } from "../utils/injective"; import { getSuiProvider } from "../utils/sui"; export type OriginalAssetInfo = { @@ -127,11 +123,6 @@ export async function getOriginalAssetToken( getTokenBridgeAddressForChain(CHAIN_ID_APTOS), foreignNativeStringAddress ); - } else if (foreignChain === CHAIN_ID_INJECTIVE) { - promise = await getOriginalAssetInjective( - foreignNativeStringAddress, - getInjectiveWasmClient() as any - ); } else if (foreignChain === CHAIN_ID_SUI) { promise = await getOriginalAssetSui( getSuiProvider(), @@ -339,16 +330,6 @@ function useOriginalAsset( getTokenBridgeAddressForChain(CHAIN_ID_APTOS), uint8ArrayToHex(result.assetAddress) ).then((tokenId) => setOriginAddress(tokenId || null)); - } else if (result.chainId === CHAIN_ID_INJECTIVE) { - const client = getInjectiveWasmClient(); - const tokenBridgeAddress = getTokenBridgeAddressForChain( - result.chainId - ); - queryExternalIdInjective( - client as any, - tokenBridgeAddress, - uint8ArrayToHex(result.assetAddress) - ).then((tokenId) => setOriginAddress(tokenId)); } else if (result.chainId === CHAIN_ID_SUI) { getForeignAssetSui( getSuiProvider(), diff --git a/src/hooks/useSyncTargetAddress.ts b/src/hooks/useSyncTargetAddress.ts index 6dabcba37..09c1ebab5 100644 --- a/src/hooks/useSyncTargetAddress.ts +++ b/src/hooks/useSyncTargetAddress.ts @@ -9,7 +9,6 @@ import { isEVMChain, isTerraChain, uint8ArrayToHex, - CHAIN_ID_INJECTIVE, CHAIN_ID_SUI, } from "@certusone/wormhole-sdk"; import { arrayify, zeroPad } from "@ethersproject/bytes"; @@ -42,7 +41,6 @@ import { getTransactionLastResult } from "near-api-js/lib/providers"; import BN from "bn.js"; import { useXplaWallet } from "../contexts/XplaWalletContext"; import { useAptosContext } from "../contexts/AptosWalletContext"; -import { useInjectiveContext } from "../contexts/InjectiveWalletContext"; import { useTerraWallet } from "../contexts/TerraWalletContext"; import { useSuiWallet } from "../contexts/SuiWalletContext"; import { useSeiWallet } from "../contexts/SeiWalletContext"; @@ -66,7 +64,6 @@ function useSyncTargetAddress(shouldFire: boolean, nft?: boolean) { const { address: algoAccount } = useAlgorandWallet(); const { account: aptosAddress } = useAptosContext(); const { accountId: nearAccountId, wallet } = useNearContext(); - const { address: injAddress } = useInjectiveContext(); const isTBTC = useSelector(selectTransferIsTBTC); const suiWallet = useSuiWallet(); const suiAddress = suiWallet?.getAddress(); @@ -163,12 +160,6 @@ function useSyncTargetAddress(shouldFire: boolean, nft?: boolean) { uint8ArrayToHex(decodeAddress(algoAccount).publicKey) ) ); - } else if (targetChain === CHAIN_ID_INJECTIVE && injAddress) { - dispatch( - setTargetAddressHex( - uint8ArrayToHex(zeroPad(cosmos.canonicalAddress(injAddress), 32)) - ) - ); } else if (targetChain === CHAIN_ID_NEAR && nearAccountId && wallet) { (async () => { try { @@ -249,7 +240,6 @@ function useSyncTargetAddress(shouldFire: boolean, nft?: boolean) { wallet, xplaWallet, aptosAddress, - injAddress, suiAddress, isTBTC, seiAddress, diff --git a/src/index.tsx b/src/index.tsx index b82896699..79e3263cc 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -4,7 +4,6 @@ import { CHAIN_ID_ALGORAND, CHAIN_ID_APTOS, CHAIN_ID_ETH, - CHAIN_ID_INJECTIVE, CHAIN_ID_NEAR, CHAIN_ID_SOLANA, CHAIN_ID_SUI, @@ -24,7 +23,6 @@ import { getAlgorandWallets } from "./contexts/AlgorandWalletContext"; import { getWrappedWallets as getWrappedAptosWallets } from "./contexts/AptosWalletContext"; import { BetaContextProvider } from "./contexts/BetaContext"; import { getEvmWallets } from "./contexts/EthereumProviderContext"; -import { getInjectiveWallets } from "./contexts/InjectiveWalletContext"; import { getNearWallets } from "./contexts/NearWalletContext"; import { getWrappedWallets as getWrappedSolanaWallets } from "./contexts/SolanaWalletContext"; import { getSuiWallets } from "./contexts/SuiWalletContext"; @@ -44,7 +42,6 @@ const AGGREGATOR_WALLETS_BUILDER = async () => { [CHAIN_ID_ETH]: getEvmWallets(), [CHAIN_ID_SOLANA]: getWrappedSolanaWallets(), [CHAIN_ID_APTOS]: getWrappedAptosWallets(), - [CHAIN_ID_INJECTIVE]: getInjectiveWallets(), [CHAIN_ID_NEAR]: await getNearWallets(), [CHAIN_ID_TERRA2]: await getTerraWallets(), [CHAIN_ID_XPLA]: await getXplaWallets(), diff --git a/src/utils/coinGecko.ts b/src/utils/coinGecko.ts index 4fa2b8a49..fc239dfcd 100644 --- a/src/utils/coinGecko.ts +++ b/src/utils/coinGecko.ts @@ -369,8 +369,6 @@ export const COIN_GECKO_IMAGE_URLS: CoinGeckoIdToImageUrl = { "https://assets.coingecko.com/coins/images/21976/small/i-DYP-Logo-1.png?1640570294", infinitup: "https://assets.coingecko.com/coins/images/18890/small/fc_qo2M7_400x400.jpg?1633749805", - "injective-protocol": - "https://assets.coingecko.com/coins/images/12882/small/Secondary_Symbol.png?1628233237", insure: "https://assets.coingecko.com/coins/images/10354/small/logo-grey-circle.png?1614910406", "interest-bearing-bitcoin": diff --git a/src/utils/consts.ts b/src/utils/consts.ts index fbd1cddab..3e88e0945 100644 --- a/src/utils/consts.ts +++ b/src/utils/consts.ts @@ -12,7 +12,6 @@ import { CHAIN_ID_CELO, CHAIN_ID_ETH, CHAIN_ID_FANTOM, - CHAIN_ID_INJECTIVE, CHAIN_ID_KARURA, CHAIN_ID_KLAYTN, CHAIN_ID_MOONBEAM, @@ -79,11 +78,8 @@ import xplaIcon from "../icons/xpla.svg"; import evmosIcon from "../icons/evmos.svg"; import osmosIcon from "../icons/osmos.svg"; import kujiraIcon from "../icons/kujira.svg"; -import injectiveIcon from "../icons/injective.svg"; import { ConnectConfig, keyStores } from "near-api-js"; import { AptosNetwork } from "./aptos"; -import { getNetworkInfo, Network } from "@injectivelabs/networks"; -import { ChainId as InjectiveChainId } from "@injectivelabs/ts-types"; import { ChainConfiguration } from "@sei-js/react"; import { Connection } from "@mysten/sui.js"; import { chainToIcon } from "@wormhole-foundation/sdk-icons"; @@ -182,11 +178,6 @@ export const CHAINS: ChainInfo[] = name: "Fantom", logo: fantomIcon, }, - { - id: CHAIN_ID_INJECTIVE, - name: "Injective", - logo: injectiveIcon, - }, { id: CHAIN_ID_KARURA, name: "Karura", @@ -325,11 +316,6 @@ export const CHAINS: ChainInfo[] = name: "Fantom", logo: fantomIcon, }, - { - id: CHAIN_ID_INJECTIVE, - name: "Injective", - logo: injectiveIcon, - }, { id: CHAIN_ID_KARURA, name: "Karura", @@ -718,8 +704,6 @@ export const getDefaultNativeCurrencySymbol = (chainId: ChainId) => ? "APTOS" : chainId === CHAIN_ID_ARBITRUM ? "ETH" - : chainId === CHAIN_ID_INJECTIVE - ? "INJ" : chainId === CHAIN_ID_SUI ? "SUI" : ""; @@ -979,41 +963,6 @@ export const SEI_TRANSLATOR = export const SEI_TRANSLATER_TARGET = cosmos.canonicalAddress(SEI_TRANSLATOR); export const SEI_DECIMALS = 6; -export const getInjectiveNetworkName = () => { - if (CLUSTER === "mainnet") { - return Network.MainnetSentry; - } else if (CLUSTER === "testnet") { - return Network.TestnetK8s; - } - throw Error("Unsupported injective network"); -}; -export const getInjectiveNetwork = () => { - if (CLUSTER === "mainnet") { - return Network.MainnetSentry; - } else if (CLUSTER === "testnet") { - return Network.TestnetK8s; - } - throw Error("Unsupported injective network"); -}; - -export const getInjectiveNetworkInfo = () => { - if (CLUSTER === "mainnet") { - return getNetworkInfo(Network.MainnetSentry); - } else if (CLUSTER === "testnet") { - return getNetworkInfo(Network.TestnetK8s); - } - throw Error("Unsupported injective network"); -}; - -export const getInjectiveNetworkChainId = () => { - if (CLUSTER === "mainnet") { - return InjectiveChainId.Mainnet; - } else if (CLUSTER === "testnet") { - return InjectiveChainId.Testnet; - } - throw Error("Unsupported injective network"); -}; - export const SUI_CONNECTION = CLUSTER === "mainnet" ? new Connection({ fullnode: "https://fullnode.mainnet.sui.io:443" }) @@ -2159,9 +2108,6 @@ export const DISABLED_TOKEN_TRANSFERS: { [CHAIN_ID_BSC]: { "0xa2B726B1145A4773F68593CF171187d8EBe4d495": [], // INJ }, - [CHAIN_ID_INJECTIVE]: { - inj: [], // INJ - }, }; export const getIsTokenTransferDisabled = ( @@ -2205,15 +2151,6 @@ export const DISABLED_TOKEN_REASONS: { }, }, // INJ }, - [CHAIN_ID_INJECTIVE]: { - inj: { - text: "Transfers of INJ token can be made through the Injective Bridge.", - link: { - text: "Click here to go to Injective Bridge", - url: "https://hub.injective.network/bridge/", - }, - }, // INJ - }, }; export const getIsTokenTransferDisabledReasons = ( diff --git a/src/utils/injective.ts b/src/utils/injective.ts deleted file mode 100644 index 64e04d8fc..000000000 --- a/src/utils/injective.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { cosmos, isNativeDenomInjective } from "@certusone/wormhole-sdk"; -import { - ChainGrpcBankApi, - ChainGrpcWasmApi, - Msgs, - TxGrpcClient, -} from "@injectivelabs/sdk-ts"; -import { InjectiveWallet } from "@xlabs-libs/wallet-aggregator-injective"; -import { getInjectiveNetworkInfo } from "./consts"; - -export const NATIVE_INJECTIVE_DECIMALS = 18; - -export const INJECTIVE_NATIVE_DENOM = "inj"; - -export const getInjectiveWasmClient = () => - new ChainGrpcWasmApi(getInjectiveNetworkInfo().grpc); - -export const getInjectiveBankClient = () => - new ChainGrpcBankApi(getInjectiveNetworkInfo().grpc); - -export const getInjectiveTxClient = () => - new TxGrpcClient(getInjectiveNetworkInfo().grpc); - -export const isValidInjectiveAddress = (address: string) => { - if (isNativeDenomInjective(address)) { - return true; - } - try { - const startsWithInj = address && address.startsWith("inj"); - const isParsable = cosmos.canonicalAddress(address); - const isLengthOk = isParsable.length === 20; - return !!(startsWithInj && isParsable && isLengthOk); - } catch (error) { - return false; - } -}; - -export const formatNativeDenom = (denom: string) => - denom === INJECTIVE_NATIVE_DENOM ? "INJ" : ""; - -export const broadcastInjectiveTx = async ( - wallet: InjectiveWallet, - address: string, - msgs: Msgs | Msgs[], - memo: string = "" -) => { - const client = getInjectiveTxClient(); - const result = await wallet.sendTransaction({ - // @ts-ignore - msgs, - address, - memo, - }); - const tx = await client.fetchTxPoll(result.id); - if (!tx) { - throw new Error("Unable to fetch transaction"); - } - if (tx.code !== 0) { - throw new Error(`Transaction failed: ${tx.rawLog}`); - } - return tx; -};