From c9d3ce4976d9c83fd6aaa0a2954e596cd45308da Mon Sep 17 00:00:00 2001 From: shan Date: Thu, 31 Oct 2024 16:32:56 +0800 Subject: [PATCH] solana get account info to replace shyft --- .../src/solana/utils/accountUtils.ts | 30 ++++++++++++++----- packages/huma-shared/src/utils/env.ts | 2 +- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/packages/huma-shared/src/solana/utils/accountUtils.ts b/packages/huma-shared/src/solana/utils/accountUtils.ts index 4af3e675..eeded9ea 100644 --- a/packages/huma-shared/src/solana/utils/accountUtils.ts +++ b/packages/huma-shared/src/solana/utils/accountUtils.ts @@ -1,20 +1,36 @@ import { AnchorProvider, Program } from '@coral-xyz/anchor' -import { Connection, PublicKey } from '@solana/web3.js' +import { Connection } from '@solana/web3.js' +import { POOL_NAME } from '../../utils' import { SolanaChainEnum } from '../chain' import { Huma as HumaProgram } from '../idl/huma' import HumaIDL from '../idl/huma.json' +import { getSolanaPoolInfo } from './programUtils' -export const getHumaConfigAccountInfo = async ( - _chainId: SolanaChainEnum, +export const getPoolAccountInfos = async ( + chainId: SolanaChainEnum, + poolName: POOL_NAME, connection: Connection, ) => { + const poolInfo = getSolanaPoolInfo(chainId, poolName) + + if (!poolInfo) { + return null + } + // @ts-ignore const provider = new AnchorProvider(connection, null) const humaProgram = new Program(HumaIDL as HumaProgram, provider) - const humaConfigAccountResult = await humaProgram.account.humaConfig.fetch( - new PublicKey('F2it2fBcdjeX9KCaEAWcQ1H8LnMB2zPn3nrPpHc7J8vL'), - ) + const [humaConfigAccount, poolConfigAccount, poolStateAccount] = + await Promise.all([ + humaProgram.account.humaConfig.fetch(poolInfo.humaConfig), + humaProgram.account.poolConfig.fetch(poolInfo.poolConfig), + humaProgram.account.poolState.fetch(poolInfo.poolState), + ]) - console.log('humaConfigAccountResult', humaConfigAccountResult) + return { + humaConfigAccount, + poolConfigAccount, + poolStateAccount, + } } diff --git a/packages/huma-shared/src/utils/env.ts b/packages/huma-shared/src/utils/env.ts index b2d5811f..b774fe1e 100644 --- a/packages/huma-shared/src/utils/env.ts +++ b/packages/huma-shared/src/utils/env.ts @@ -1,5 +1,5 @@ export const checkIsDev = () => - !process.env.REACT_APP_FORCE_IS_DEV_FALSE && + process.env.REACT_APP_FORCE_IS_DEV_FALSE !== 'true' && !!( window.location.hostname.startsWith('dev') || window.location.hostname.startsWith('v2') ||