allow use of reversed pol (#382)
* allow use of reversed pol * reversed pool
This commit is contained in:
parent
ae5741f86f
commit
37b3ef4daa
|
@ -391,8 +391,11 @@ const ListToken = ({ goBack }: { goBack: () => void }) => {
|
||||||
}
|
}
|
||||||
const bestSolPool = resp.pairs.find(
|
const bestSolPool = resp.pairs.find(
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// 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')) {
|
if (bestSolPool.dexId.includes('raydium')) {
|
||||||
setRaydiumPoolAddress(bestSolPool.pairAddress)
|
setRaydiumPoolAddress(bestSolPool.pairAddress)
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ import { WhirlpoolContext, buildWhirlpoolClient } from '@orca-so/whirlpools-sdk'
|
||||||
import { LIQUIDITY_STATE_LAYOUT_V4 } from '@raydium-io/raydium-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 { LISTING_PRESETS_KEY } from '@blockworks-foundation/mango-v4-settings/lib/helpers/listingTools'
|
||||||
import { sendTxAndConfirm } from 'utils/governance/tools'
|
import { sendTxAndConfirm } from 'utils/governance/tools'
|
||||||
|
import { WRAPPED_SOL_MINT } from '@metaplex-foundation/js'
|
||||||
|
|
||||||
const poolAddressError = 'no-pool-address-found'
|
const poolAddressError = 'no-pool-address-found'
|
||||||
const wrongTierPassedForCreation = 'Wrong tier passed for creation of oracle'
|
const wrongTierPassedForCreation = 'Wrong tier passed for creation of oracle'
|
||||||
|
@ -30,6 +31,7 @@ const SWITCHBOARD_PERMISSIONLESS_QUE =
|
||||||
'5JYwqvKkqp35w8Nq3ba4z1WYUeJQ1rB36V8XvaGp6zn1'
|
'5JYwqvKkqp35w8Nq3ba4z1WYUeJQ1rB36V8XvaGp6zn1'
|
||||||
const SWITCHBOARD_PERMISSIONLESS_CRANK =
|
const SWITCHBOARD_PERMISSIONLESS_CRANK =
|
||||||
'BKtF8yyQsj3Ft6jb2nkfpEKzARZVdGgdEPs6mFmZNmbA'
|
'BKtF8yyQsj3Ft6jb2nkfpEKzARZVdGgdEPs6mFmZNmbA'
|
||||||
|
const pythSolOracle = 'H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG'
|
||||||
|
|
||||||
type BaseProps = ModalProps & {
|
type BaseProps = ModalProps & {
|
||||||
openbookMarketPk: string
|
openbookMarketPk: string
|
||||||
|
@ -115,7 +117,11 @@ const CreateSwitchboardOracleModal = ({
|
||||||
|
|
||||||
const [creatingOracle, setCreatingOracle] = useState(false)
|
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') {
|
if (type === 'orca') {
|
||||||
const context = WhirlpoolContext.from(
|
const context = WhirlpoolContext.from(
|
||||||
connection,
|
connection,
|
||||||
|
@ -124,12 +130,12 @@ const CreateSwitchboardOracleModal = ({
|
||||||
)
|
)
|
||||||
const whirlPoolClient = buildWhirlpoolClient(context)
|
const whirlPoolClient = buildWhirlpoolClient(context)
|
||||||
const whirlpool = await whirlPoolClient.getPool(new PublicKey(poolPk))
|
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') {
|
if (type === 'raydium') {
|
||||||
const info = await connection.getAccountInfo(new PublicKey(poolPk))
|
const info = await connection.getAccountInfo(new PublicKey(poolPk))
|
||||||
const poolState = LIQUIDITY_STATE_LAYOUT_V4.decode(info!.data)
|
const poolState = LIQUIDITY_STATE_LAYOUT_V4.decode(info!.data)
|
||||||
return poolState.baseMint.toBase58() === USDC_MINT || false
|
return poolState.baseMint.toBase58() === baseMint || false
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -149,6 +155,7 @@ const CreateSwitchboardOracleModal = ({
|
||||||
const isReversePool = await isPoolReversed(
|
const isReversePool = await isPoolReversed(
|
||||||
orcaPoolAddress ? 'orca' : 'raydium',
|
orcaPoolAddress ? 'orca' : 'raydium',
|
||||||
poolAddress!,
|
poolAddress!,
|
||||||
|
!isSolPool ? USDC_MINT : WRAPPED_SOL_MINT.toBase58(),
|
||||||
)
|
)
|
||||||
|
|
||||||
const program = await SwitchboardProgram.load(CLUSTER, connection)
|
const program = await SwitchboardProgram.load(CLUSTER, connection)
|
||||||
|
@ -158,62 +165,69 @@ const CreateSwitchboardOracleModal = ({
|
||||||
CrankAccount.load(program, SWITCHBOARD_PERMISSIONLESS_CRANK),
|
CrankAccount.load(program, SWITCHBOARD_PERMISSIONLESS_CRANK),
|
||||||
])
|
])
|
||||||
|
|
||||||
let onFailureTaskDesc
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
if (!isSolPool) {
|
let onFailureTaskDesc: { [key: string]: any }[]
|
||||||
if (!isReversePool) {
|
if (!isReversePool) {
|
||||||
onFailureTaskDesc = [
|
|
||||||
{
|
|
||||||
lpExchangeRateTask: {
|
|
||||||
[poolPropertyName]: poolAddress,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]
|
|
||||||
} else {
|
|
||||||
onFailureTaskDesc = [
|
|
||||||
{
|
|
||||||
valueTask: {
|
|
||||||
big: 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
divideTask: {
|
|
||||||
job: {
|
|
||||||
tasks: [
|
|
||||||
{
|
|
||||||
lpExchangeRateTask: {
|
|
||||||
[poolPropertyName]: poolAddress,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
onFailureTaskDesc = [
|
onFailureTaskDesc = [
|
||||||
{
|
{
|
||||||
lpExchangeRateTask: {
|
lpExchangeRateTask: {
|
||||||
[poolPropertyName]: poolAddress,
|
[poolPropertyName]: poolAddress,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
]
|
||||||
|
if (isSolPool) {
|
||||||
|
onFailureTaskDesc.push({
|
||||||
multiplyTask: {
|
multiplyTask: {
|
||||||
job: {
|
job: {
|
||||||
tasks: [
|
tasks: [
|
||||||
{
|
{
|
||||||
oracleTask: {
|
oracleTask: {
|
||||||
//pyth sol address
|
pythAddress: pythSolOracle,
|
||||||
pythAddress:
|
|
||||||
'H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG',
|
|
||||||
pythAllowedConfidenceInterval: 0.1,
|
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]
|
const settingFromLib = tierSettings[tierKey]
|
||||||
|
|
|
@ -1108,6 +1108,7 @@ const mangoStore = create<MangoStore>()(
|
||||||
connection,
|
connection,
|
||||||
10000,
|
10000,
|
||||||
)) as SerumEvent[]
|
)) as SerumEvent[]
|
||||||
|
|
||||||
loadedFills = serumFills.filter((f) => !f?.eventFlags?.maker)
|
loadedFills = serumFills.filter((f) => !f?.eventFlags?.maker)
|
||||||
} else if (perpMarket) {
|
} else if (perpMarket) {
|
||||||
const perpFills = (await perpMarket.loadFills(
|
const perpFills = (await perpMarket.loadFills(
|
||||||
|
|
Loading…
Reference in New Issue