configure rpc url

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
microwavedcola1 2024-07-02 11:39:55 +02:00
parent 3b031cc53d
commit 74bffa9b4f
1 changed files with 8 additions and 9 deletions

View File

@ -42,17 +42,11 @@ export const TRITON_DEDICATED_URL = process.env.NEXT_PUBLIC_TRITON_TOKEN
type CurrentTiersResponse = CurrentTier[]
async function buildClient(): Promise<MangoClient | undefined> {
async function buildClient(rpcUrl: string): Promise<MangoClient | undefined> {
try {
const clientKeypair = new Keypair()
const options = AnchorProvider.defaultOptions()
const rpcUrl = process.env.NEXT_PUBLIC_ENDPOINT || TRITON_DEDICATED_URL
console.log(rpcUrl, '@@@@@@@')
if (!rpcUrl) {
throw new Error('MANGO_RPC_URL environment variable is not set')
}
const connection = new Connection(rpcUrl, options)
const clientWallet = new Wallet(clientKeypair)
const clientProvider = new AnchorProvider(connection, clientWallet, options)
@ -76,8 +70,14 @@ export default async function handler(
CurrentTiersResponse | { error: string; details: string }
>,
) {
const { body } = req
console.log(body)
if (!('rpcUrl' in body)) {
throw new Error(`${body} should contain rpcUrl!`)
}
try {
const client = await buildClient()
const client = await buildClient(body['rpcUrl'])
if (!client) {
console.log('Client build failed')
@ -95,7 +95,6 @@ export default async function handler(
const midPriceImpacts = getMidPriceImpacts(
priceImpacts.length ? priceImpacts : [],
)
console.log(midPriceImpacts)
const tokenThresholds: {
[symbol: string]: { below1Percent: number; below2Percent: number }