allow use of reversed pol (#382)

* allow use of reversed pol

* reversed pool
This commit is contained in:
Adrian Brzeziński 2024-02-03 00:05:35 +01:00 committed by GitHub
parent ae5741f86f
commit 37b3ef4daa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 59 additions and 41 deletions

View File

@ -391,8 +391,11 @@ const ListToken = ({ goBack }: { goBack: () => void }) => {
}
const bestSolPool = resp.pairs.find(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(x: any) => x.quoteToken.address === WRAPPED_SOL_MINT.toBase58(),
(x: any) =>
x.quoteToken.address === WRAPPED_SOL_MINT.toBase58() ||
x.baseToken.address === WRAPPED_SOL_MINT.toBase58(),
)
if (bestSolPool.dexId.includes('raydium')) {
setRaydiumPoolAddress(bestSolPool.pairAddress)
}

View File

@ -22,6 +22,7 @@ import { WhirlpoolContext, buildWhirlpoolClient } from '@orca-so/whirlpools-sdk'
import { LIQUIDITY_STATE_LAYOUT_V4 } from '@raydium-io/raydium-sdk'
import { LISTING_PRESETS_KEY } from '@blockworks-foundation/mango-v4-settings/lib/helpers/listingTools'
import { sendTxAndConfirm } from 'utils/governance/tools'
import { WRAPPED_SOL_MINT } from '@metaplex-foundation/js'
const poolAddressError = 'no-pool-address-found'
const wrongTierPassedForCreation = 'Wrong tier passed for creation of oracle'
@ -30,6 +31,7 @@ const SWITCHBOARD_PERMISSIONLESS_QUE =
'5JYwqvKkqp35w8Nq3ba4z1WYUeJQ1rB36V8XvaGp6zn1'
const SWITCHBOARD_PERMISSIONLESS_CRANK =
'BKtF8yyQsj3Ft6jb2nkfpEKzARZVdGgdEPs6mFmZNmbA'
const pythSolOracle = 'H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG'
type BaseProps = ModalProps & {
openbookMarketPk: string
@ -115,7 +117,11 @@ const CreateSwitchboardOracleModal = ({
const [creatingOracle, setCreatingOracle] = useState(false)
const isPoolReversed = async (type: 'orca' | 'raydium', poolPk: string) => {
const isPoolReversed = async (
type: 'orca' | 'raydium',
poolPk: string,
baseMint: string,
) => {
if (type === 'orca') {
const context = WhirlpoolContext.from(
connection,
@ -124,12 +130,12 @@ const CreateSwitchboardOracleModal = ({
)
const whirlPoolClient = buildWhirlpoolClient(context)
const whirlpool = await whirlPoolClient.getPool(new PublicKey(poolPk))
return whirlpool.getTokenAInfo().mint.toBase58() == USDC_MINT || false
return whirlpool.getTokenAInfo().mint.toBase58() == baseMint || false
}
if (type === 'raydium') {
const info = await connection.getAccountInfo(new PublicKey(poolPk))
const poolState = LIQUIDITY_STATE_LAYOUT_V4.decode(info!.data)
return poolState.baseMint.toBase58() === USDC_MINT || false
return poolState.baseMint.toBase58() === baseMint || false
}
return false
}
@ -149,6 +155,7 @@ const CreateSwitchboardOracleModal = ({
const isReversePool = await isPoolReversed(
orcaPoolAddress ? 'orca' : 'raydium',
poolAddress!,
!isSolPool ? USDC_MINT : WRAPPED_SOL_MINT.toBase58(),
)
const program = await SwitchboardProgram.load(CLUSTER, connection)
@ -158,62 +165,69 @@ const CreateSwitchboardOracleModal = ({
CrankAccount.load(program, SWITCHBOARD_PERMISSIONLESS_CRANK),
])
let onFailureTaskDesc
if (!isSolPool) {
if (!isReversePool) {
onFailureTaskDesc = [
{
lpExchangeRateTask: {
[poolPropertyName]: poolAddress,
},
},
]
} else {
onFailureTaskDesc = [
{
valueTask: {
big: 1,
},
},
{
divideTask: {
job: {
tasks: [
{
lpExchangeRateTask: {
[poolPropertyName]: poolAddress,
},
},
],
},
},
},
]
}
} else {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let onFailureTaskDesc: { [key: string]: any }[]
if (!isReversePool) {
onFailureTaskDesc = [
{
lpExchangeRateTask: {
[poolPropertyName]: poolAddress,
},
},
{
]
if (isSolPool) {
onFailureTaskDesc.push({
multiplyTask: {
job: {
tasks: [
{
oracleTask: {
//pyth sol address
pythAddress:
'H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG',
pythAddress: pythSolOracle,
pythAllowedConfidenceInterval: 0.1,
},
},
],
},
},
})
}
} else {
onFailureTaskDesc = [
{
valueTask: {
big: 1,
},
},
{
divideTask: {
job: {
tasks: [
{
lpExchangeRateTask: {
[poolPropertyName]: poolAddress,
},
},
],
},
},
},
]
if (isSolPool) {
onFailureTaskDesc.push({
multiplyTask: {
job: {
tasks: [
{
oracleTask: {
pythAddress: pythSolOracle,
pythAllowedConfidenceInterval: 0.1,
},
},
],
},
},
})
}
}
const settingFromLib = tierSettings[tierKey]

View File

@ -1108,6 +1108,7 @@ const mangoStore = create<MangoStore>()(
connection,
10000,
)) as SerumEvent[]
loadedFills = serumFills.filter((f) => !f?.eventFlags?.maker)
} else if (perpMarket) {
const perpFills = (await perpMarket.loadFills(