Skip to content

Commit

Permalink
fix provider
Browse files Browse the repository at this point in the history
  • Loading branch information
abrzezinski94 committed Jul 2, 2024
1 parent 4bd5b7c commit 5599ee1
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions pages/api/tokentiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
LISTING_PRESETS,
getMidPriceImpacts,
} from '@blockworks-foundation/mango-v4-settings/lib/helpers/listingTools'
import { web3 } from '@project-serum/anchor'
import { CONNECTION_COMMITMENT } from 'utils/constants'

interface TokenDetails {
reduceOnly?: number
Expand Down Expand Up @@ -62,12 +64,27 @@ export default async function handler(
throw new Error('MANGO_RPC_URL environment variable is not set')
}

const connection = new Connection(rpcUrl, options)
let connection = new Connection(rpcUrl, options)
const clientWallet = new Wallet(clientKeypair)
const clientProvider = new AnchorProvider(connection, clientWallet, options)

try {
// if connection is using Triton RpcPool then use whirligig
// https://docs.triton.one/project-yellowstone/whirligig-websockets
if (rpcUrl.includes('rpcpool')) {
connection = new web3.Connection(rpcUrl, {
wsEndpoint: `${rpcUrl.replace('http', 'ws')}/whirligig/`,
commitment: CONNECTION_COMMITMENT,
})
} else {
connection = new web3.Connection(rpcUrl, CONNECTION_COMMITMENT)
}
} catch {
connection = new web3.Connection(rpcUrl, CONNECTION_COMMITMENT)
}
const provider = new AnchorProvider(connection, clientWallet, options)

const client = await MangoClient.connect(
clientProvider,
provider,
'mainnet-beta',
MANGO_V4_ID['mainnet-beta'],
{
Expand Down

0 comments on commit 5599ee1

Please sign in to comment.