chore: env variables for rpcs (#1407)
* chore: env variables for rpcs * Remove console log
This commit is contained in:
parent
77db9ee53b
commit
a888ba318c
|
@ -12,7 +12,7 @@ import {
|
||||||
UPGRADE_MULTISIG,
|
UPGRADE_MULTISIG,
|
||||||
} from 'xc_admin_common'
|
} from 'xc_admin_common'
|
||||||
import { ClusterContext } from '../contexts/ClusterContext'
|
import { ClusterContext } from '../contexts/ClusterContext'
|
||||||
import { pythClusterApiUrls } from '../utils/pythClusterApiUrl'
|
import { deriveWsUrl, pythClusterApiUrls } from '../utils/pythClusterApiUrl'
|
||||||
|
|
||||||
export interface MultisigHookData {
|
export interface MultisigHookData {
|
||||||
isLoading: boolean
|
isLoading: boolean
|
||||||
|
@ -69,9 +69,9 @@ export const useMultisig = (): MultisigHookData => {
|
||||||
|
|
||||||
const connection = useMemo(() => {
|
const connection = useMemo(() => {
|
||||||
const urls = pythClusterApiUrls(multisigCluster)
|
const urls = pythClusterApiUrls(multisigCluster)
|
||||||
return new Connection(urls[urlsIndex].rpcUrl, {
|
return new Connection(urls[urlsIndex], {
|
||||||
commitment: 'confirmed',
|
commitment: 'confirmed',
|
||||||
wsEndpoint: urls[urlsIndex].wsUrl,
|
wsEndpoint: deriveWsUrl(urls[urlsIndex]),
|
||||||
})
|
})
|
||||||
}, [urlsIndex, multisigCluster])
|
}, [urlsIndex, multisigCluster])
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ import { Connection, PublicKey } from '@solana/web3.js'
|
||||||
import assert from 'assert'
|
import assert from 'assert'
|
||||||
import { useContext, useEffect, useRef, useState } from 'react'
|
import { useContext, useEffect, useRef, useState } from 'react'
|
||||||
import { ClusterContext } from '../contexts/ClusterContext'
|
import { ClusterContext } from '../contexts/ClusterContext'
|
||||||
import { pythClusterApiUrls } from '../utils/pythClusterApiUrl'
|
import { deriveWsUrl, pythClusterApiUrls } from '../utils/pythClusterApiUrl'
|
||||||
|
|
||||||
const ONES = '11111111111111111111111111111111'
|
const ONES = '11111111111111111111111111111111'
|
||||||
|
|
||||||
|
@ -67,9 +67,9 @@ const usePyth = (): PythHookData => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let cancelled = false
|
let cancelled = false
|
||||||
const urls = pythClusterApiUrls(cluster)
|
const urls = pythClusterApiUrls(cluster)
|
||||||
const connection = new Connection(urls[urlsIndex].rpcUrl, {
|
const connection = new Connection(urls[urlsIndex], {
|
||||||
commitment: 'confirmed',
|
commitment: 'confirmed',
|
||||||
wsEndpoint: urls[urlsIndex].wsUrl,
|
wsEndpoint: deriveWsUrl(urls[urlsIndex]),
|
||||||
})
|
})
|
||||||
|
|
||||||
connectionRef.current = connection
|
connectionRef.current = connection
|
||||||
|
|
|
@ -1,88 +1,40 @@
|
||||||
import { PythCluster } from '@pythnetwork/client/lib/cluster'
|
import {
|
||||||
|
PythCluster,
|
||||||
|
getPythClusterApiUrl,
|
||||||
|
} from '@pythnetwork/client/lib/cluster'
|
||||||
|
|
||||||
const CLUSTER_URLS: Record<PythCluster, any> = {
|
const CLUSTER_URLS: Record<PythCluster, string[]> = {
|
||||||
'mainnet-beta': [
|
'mainnet-beta': [
|
||||||
{
|
process.env.NEXT_PUBLIC_MAINNET_RPC || getPythClusterApiUrl('mainnet-beta'),
|
||||||
rpcUrl: 'http://mainnet.xyz.pyth.network',
|
'https://pyth-network.rpcpool.com/' +
|
||||||
wsUrl: 'ws://mainnet.xyz.pyth.network',
|
(process.env.NEXT_PUBLIC_RPC_POOL_TOKEN || ''),
|
||||||
},
|
'http://pyth-rpc1.certus.one:8899/',
|
||||||
{
|
'http://pyth-rpc2.certus.one:8899/',
|
||||||
rpcUrl:
|
'https://api.mainnet-beta.solana.com/',
|
||||||
'https://pyth-network.rpcpool.com/' +
|
|
||||||
(process.env.NEXT_PUBLIC_RPC_POOL_TOKEN || ''),
|
|
||||||
wsUrl:
|
|
||||||
'wss://pyth-network.rpcpool.com/' +
|
|
||||||
(process.env.NEXT_PUBLIC_RPC_POOL_TOKEN || ''),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
rpcUrl: 'http://pyth-rpc1.certus.one:8899/',
|
|
||||||
wsUrl: 'ws://pyth-rpc1.certus.one:8900/',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
rpcUrl: 'http://pyth-rpc2.certus.one:8899/',
|
|
||||||
wsUrl: 'ws://pyth-rpc2.certus.one:8900/',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
rpcUrl: 'https://api.mainnet-beta.solana.com/',
|
|
||||||
wsUrl: 'wss://api.mainnet-beta.solana.com/',
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
devnet: [
|
devnet: [
|
||||||
{
|
process.env.NEXT_PUBLIC_DEVNET_RPC || getPythClusterApiUrl('devnet'),
|
||||||
rpcUrl: 'http://devnet.xyz.pyth.network',
|
'https://api.devnet.solana.com/',
|
||||||
wsUrl: 'ws://devnet.xyz.pyth.network',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
rpcUrl: 'https://api.devnet.solana.com/',
|
|
||||||
wsUrl: 'wss://api.devnet.solana.com/',
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
testnet: [
|
testnet: [
|
||||||
{
|
process.env.NEXT_PUBLIC_TESTNET_RPC || getPythClusterApiUrl('testnet'),
|
||||||
rpcUrl: 'http://testnet.xyz.pyth.network',
|
'https://api.testnet.solana.com/',
|
||||||
wsUrl: 'ws://testnet.xyz.pyth.network',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
rpcUrl: 'https://api.testnet.solana.com/',
|
|
||||||
wsUrl: 'wss://api.testnet.solana.com/',
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
'pythtest-conformance': [
|
'pythtest-conformance': [
|
||||||
{
|
process.env.NEXT_PUBLIC_PYTHTEST_RPC ||
|
||||||
rpcUrl: 'http://pythtest.xyz.pyth.network',
|
getPythClusterApiUrl('pythtest-conformance'),
|
||||||
wsUrl: 'ws://pythtest.xyz.pyth.network',
|
'https://api.pythtest.pyth.network/',
|
||||||
},
|
|
||||||
{
|
|
||||||
rpcUrl: 'https://api.pythtest.pyth.network/',
|
|
||||||
wsUrl: 'wss://api.pythtest.pyth.network/',
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
'pythtest-crosschain': [
|
'pythtest-crosschain': [
|
||||||
{
|
process.env.NEXT_PUBLIC_PYTHTEST_RPC ||
|
||||||
rpcUrl: 'http://pythtest.xyz.pyth.network',
|
getPythClusterApiUrl('pythtest-crosschain'),
|
||||||
wsUrl: 'ws://pythtest.xyz.pyth.network',
|
'https://api.pythtest.pyth.network/',
|
||||||
},
|
|
||||||
{
|
|
||||||
rpcUrl: 'https://api.pythtest.pyth.network/',
|
|
||||||
wsUrl: 'wss://api.pythtest.pyth.network/',
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
pythnet: [
|
pythnet: [
|
||||||
{
|
process.env.NEXT_PUBLIC_PYTHNET_RPC || getPythClusterApiUrl('pythnet'),
|
||||||
rpcUrl: 'http://pythnet.xyz.pyth.network',
|
'https://pythnet.rpcpool.com/',
|
||||||
wsUrl: 'ws://pythnet.xyz.pyth.network',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
rpcUrl: 'https://pythnet.rpcpool.com/',
|
|
||||||
wsUrl: 'wss://pythnet.rpcpool.com/',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
localnet: [
|
|
||||||
{
|
|
||||||
rpcUrl: 'http://localhost:8899/',
|
|
||||||
wsUrl: 'ws://localhost:8900/',
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
|
localnet: ['http://localhost:8899/'],
|
||||||
}
|
}
|
||||||
|
|
||||||
export function pythClusterApiUrls(cluster: PythCluster) {
|
export function pythClusterApiUrls(cluster: PythCluster) {
|
||||||
|
@ -92,3 +44,11 @@ export function pythClusterApiUrls(cluster: PythCluster) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function deriveWsUrl(httpUrl: string) {
|
||||||
|
if (httpUrl.startsWith('https://')) {
|
||||||
|
return 'wss://' + httpUrl.slice(8)
|
||||||
|
} else {
|
||||||
|
return 'ws://' + httpUrl.slice(7)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue