reverse pool check (#325)

* reverse pool check

* deduplicate packages
This commit is contained in:
Adrian Brzeziński 2023-11-23 12:13:47 +01:00 committed by GitHub
parent 7805d23135
commit 0fd43fd39d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 134 additions and 18 deletions

View File

@ -366,6 +366,7 @@ const ListToken = ({ goBack }: { goBack: () => void }) => {
const raydiumPool = swapInfos?.find(
(x) => x.label?.toLowerCase().includes('raydium'),
)
setOrcaPoolAddress(orcaPool?.ammKey || '')
setRaydiumPoolAddress(raydiumPool?.ammKey || '')
}

View File

@ -11,13 +11,15 @@ import { OracleJob } from '@switchboard-xyz/common'
import Button from '@components/shared/Button'
import { MANGO_DAO_WALLET } from 'utils/governance/constants'
import { USDC_MINT } from 'utils/constants'
import { Transaction } from '@solana/web3.js'
import { PublicKey, Transaction } from '@solana/web3.js'
import chunk from 'lodash/chunk'
import { useTranslation } from 'next-i18next'
import { notify } from 'utils/notifications'
import { isMangoError } from 'types'
import { useCallback, useState } from 'react'
import Loading from '@components/shared/Loading'
import { WhirlpoolContext, buildWhirlpoolClient } from '@orca-so/whirlpools-sdk'
import { LIQUIDITY_STATE_LAYOUT_V4 } from '@raydium-io/raydium-sdk'
const poolAddressError = 'no-pool-address-found'
@ -95,6 +97,25 @@ const CreateSwitchboardOracleModal = ({
const [creatingOracle, setCreatingOracle] = useState(false)
const isPoolReversed = async (type: 'orca' | 'raydium', poolPk: string) => {
if (type === 'orca') {
const context = WhirlpoolContext.from(
connection,
wallet as never,
new PublicKey('whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc'),
)
const whirlPoolClient = buildWhirlpoolClient(context)
const whirlpool = await whirlPoolClient.getPool(new PublicKey(poolPk))
return whirlpool.getTokenAInfo().mint.toBase58() == USDC_MINT || false
}
if (type === 'raydium') {
const info = await connection.getAccountInfo(new PublicKey(poolPk))
const poolState = LIQUIDITY_STATE_LAYOUT_V4.decode(info!.data)
return poolState.quoteMint.toBase58() === USDC_MINT || false
}
return false
}
const create = useCallback(async () => {
try {
const swapValue = tierToSwapValue[tier]
@ -107,6 +128,10 @@ const CreateSwitchboardOracleModal = ({
? 'orcaPoolAddress'
: 'raydiumPoolAddress'
const poolAddress = orcaPoolAddress ? orcaPoolAddress : raydiumPoolAddress
const isReversePool = await isPoolReversed(
orcaPoolAddress ? 'orca' : 'raydium',
poolAddress!,
)
const program = await SwitchboardProgram.load(CLUSTER, connection)
@ -115,6 +140,38 @@ const CreateSwitchboardOracleModal = ({
CrankAccount.load(program, SWITCHBOARD_PERMISSIONLESS_CRANK),
])
let onFailureTaskDesc
if (isReversePool) {
onFailureTaskDesc = [
{
lpExchangeRateTask: {
[poolPropertyName]: poolAddress,
},
},
]
} else {
onFailureTaskDesc = [
{
valueTask: {
big: 1,
},
},
{
divideTask: {
job: {
tasks: [
{
lpExchangeRateTask: {
[poolPropertyName]: poolAddress,
},
},
],
},
},
},
]
}
const [aggregatorAccount, txArray1] =
await queueAccount.createFeedInstructions(payer, {
name: `${baseTokenName}/${quoteTokenName}`,
@ -233,13 +290,7 @@ const CreateSwitchboardOracleModal = ({
},
},
],
onFailure: [
{
lpExchangeRateTask: {
[poolPropertyName]: poolAddress,
},
},
],
onFailure: onFailureTaskDesc,
},
},
{

View File

@ -30,8 +30,10 @@
"@heroicons/react": "2.0.18",
"@jup-ag/referral-sdk": "0.1.5",
"@metaplex-foundation/js": "0.19.4",
"@orca-so/whirlpools-sdk": "0.11.7",
"@project-serum/anchor": "0.25.0",
"@pythnetwork/client": "2.15.0",
"@raydium-io/raydium-sdk": "1.3.1-beta.31",
"@sentry/nextjs": "7.80.0",
"@solana/spl-governance": "0.3.27",
"@solana/spl-token": "0.3.7",

View File

@ -124,7 +124,7 @@
eventemitter3 "^4.0.7"
uuid "^8.3.2"
"@coral-xyz/anchor@0.28.1-beta.2", "@coral-xyz/anchor@^0.26.0", "@coral-xyz/anchor@^0.27.0", "@coral-xyz/anchor@^0.28.0", "@coral-xyz/anchor@^0.28.1-beta.2":
"@coral-xyz/anchor@0.28.1-beta.2", "@coral-xyz/anchor@^0.26.0", "@coral-xyz/anchor@^0.27.0", "@coral-xyz/anchor@^0.28.0", "@coral-xyz/anchor@^0.28.1-beta.2", "@coral-xyz/anchor@~0.27.0":
version "0.27.0"
resolved "https://registry.yarnpkg.com/@coral-xyz/anchor/-/anchor-0.27.0.tgz#621e5ef123d05811b97e49973b4ed7ede27c705c"
integrity sha512-+P/vPdORawvg3A9Wj02iquxb4T0C5m4P6aZBVYysKl4Amk+r6aMPZkUhilBkD6E4Nuxnoajv3CFykUfkGE0n5g==
@ -1106,6 +1106,28 @@
node-gyp "^7.1.0"
read-package-json-fast "^2.0.1"
"@orca-so/common-sdk@^0.3.3":
version "0.3.5"
resolved "https://registry.yarnpkg.com/@orca-so/common-sdk/-/common-sdk-0.3.5.tgz#c89692a1f096ebab9271c7456fb2e2a6eaa4c9d3"
integrity sha512-A53MjI8Zh5Ri18Ee7JwM5hFFlAWwKtqc2V/V6/bPu709DirhsOXR8xx4w7qM5WOj1N1Gfelm4BfU/Py4C/KYpQ==
dependencies:
"@solana/spl-token" "^0.3.8"
"@solana/web3.js" "^1.75.0"
decimal.js "^10.3.1"
tiny-invariant "^1.2.0"
"@orca-so/whirlpools-sdk@0.11.7":
version "0.11.7"
resolved "https://registry.yarnpkg.com/@orca-so/whirlpools-sdk/-/whirlpools-sdk-0.11.7.tgz#5878344f58084c735e9b7c313786d4e4a9289e08"
integrity sha512-XyrKd22Ur7KWePBMrzGy3x4IPIhl6bGfKbgNcJF8Ihytvg2HkYugYPZw9zC0TB4M4WBg68T0ibDt1iFSIZC4Ew==
dependencies:
"@coral-xyz/anchor" "~0.27.0"
"@orca-so/common-sdk" "^0.3.3"
"@solana/spl-token" "^0.3.8"
"@solana/web3.js" "^1.75.0"
decimal.js "^10.3.1"
tiny-invariant "^1.2.0"
"@particle-network/auth@^0.5.5":
version "0.5.6"
resolved "https://registry.yarnpkg.com/@particle-network/auth/-/auth-0.5.6.tgz#058e00980511fdf72189b6d4a7576e67934a008a"
@ -1300,6 +1322,22 @@
dependencies:
"@randlabs/communication-bridge" "1.0.1"
"@raydium-io/raydium-sdk@1.3.1-beta.31":
version "1.3.1-beta.31"
resolved "https://registry.yarnpkg.com/@raydium-io/raydium-sdk/-/raydium-sdk-1.3.1-beta.31.tgz#70e927b9538aec72c2d348404d3f723d32c5a91c"
integrity sha512-UuaAg1xBXPmRmvq3d8wvuWiqQgnTjVvycihV7kS/wMHxyZ5VCA2/amjZSctGlT6Qn7OFCQJ+y+35fmEwbKxoWg==
dependencies:
"@solana/buffer-layout" "^4.0.1"
"@solana/spl-token" "^0.3.9"
axios "^1.6.2"
big.js "^6.2.1"
bn.js "^5.2.1"
decimal.js "^10.4.3"
decimal.js-light "^2.5.1"
fecha "^4.2.3"
lodash "^4.17.21"
toformat "^2.0.0"
"@react-native-async-storage/async-storage@^1.17.7":
version "1.19.3"
resolved "https://registry.yarnpkg.com/@react-native-async-storage/async-storage/-/async-storage-1.19.3.tgz#ad5fe3ed0a82d4624aa4500321c1e09c02daeb46"
@ -1523,7 +1561,7 @@
bigint-buffer "^1.1.5"
bignumber.js "^9.0.1"
"@solana/buffer-layout@^4.0.0":
"@solana/buffer-layout@^4.0.0", "@solana/buffer-layout@^4.0.1":
version "4.0.1"
resolved "https://registry.yarnpkg.com/@solana/buffer-layout/-/buffer-layout-4.0.1.tgz#b996235eaec15b1e0b5092a8ed6028df77fa6c15"
integrity sha512-E1ImOIAD1tBZFRdjeM4/pzTiTApC0AOBGwyAMS4fwIodCWArzJ3DWdoh8cKxeFM2fElkxBh2Aqts1BPC373rHA==
@ -1564,7 +1602,7 @@
"@solana/buffer-layout-utils" "^0.2.0"
buffer "^6.0.3"
"@solana/spl-token@0.3.8", "@solana/spl-token@^0.3.5", "@solana/spl-token@^0.3.6", "@solana/spl-token@^0.3.8":
"@solana/spl-token@0.3.8":
version "0.3.8"
resolved "https://registry.yarnpkg.com/@solana/spl-token/-/spl-token-0.3.8.tgz#8e9515ea876e40a4cc1040af865f61fc51d27edf"
integrity sha512-ogwGDcunP9Lkj+9CODOWMiVJEdRtqHAtX2rWF62KxnnSWtMZtV9rDhTrZFshiyJmxDnRL/1nKE1yJHg4jjs3gg==
@ -1585,6 +1623,15 @@
buffer-layout "^1.2.0"
dotenv "10.0.0"
"@solana/spl-token@^0.3.5", "@solana/spl-token@^0.3.6", "@solana/spl-token@^0.3.8", "@solana/spl-token@^0.3.9":
version "0.3.9"
resolved "https://registry.yarnpkg.com/@solana/spl-token/-/spl-token-0.3.9.tgz#477e703c3638ffb17dd29b82a203c21c3e465851"
integrity sha512-1EXHxKICMnab35MvvY/5DBc/K/uQAOJCYnDZXw83McCAYUAfi+rwq6qfd6MmITmSTEhcfBcl/zYxmW/OSN0RmA==
dependencies:
"@solana/buffer-layout" "^4.0.0"
"@solana/buffer-layout-utils" "^0.2.0"
buffer "^6.0.3"
"@solana/wallet-adapter-alpha@^0.1.10":
version "0.1.10"
resolved "https://registry.yarnpkg.com/@solana/wallet-adapter-alpha/-/wallet-adapter-alpha-0.1.10.tgz#497ac17634dac4de17eba643768df9b30a13129a"
@ -2044,7 +2091,7 @@
"@wallet-standard/app" "^1.0.1"
"@wallet-standard/base" "^1.0.1"
"@solana/web3.js@^1.17.0", "@solana/web3.js@^1.21.0", "@solana/web3.js@^1.22.0", "@solana/web3.js@^1.32.0", "@solana/web3.js@^1.36.0", "@solana/web3.js@^1.44.3", "@solana/web3.js@^1.50.1", "@solana/web3.js@^1.56.2", "@solana/web3.js@^1.63.1", "@solana/web3.js@^1.66.2", "@solana/web3.js@^1.68.0", "@solana/web3.js@^1.77.3", "@solana/web3.js@^1.78.2", "@solana/web3.js@^1.78.3":
"@solana/web3.js@^1.17.0", "@solana/web3.js@^1.21.0", "@solana/web3.js@^1.22.0", "@solana/web3.js@^1.32.0", "@solana/web3.js@^1.36.0", "@solana/web3.js@^1.44.3", "@solana/web3.js@^1.50.1", "@solana/web3.js@^1.56.2", "@solana/web3.js@^1.63.1", "@solana/web3.js@^1.66.2", "@solana/web3.js@^1.68.0", "@solana/web3.js@^1.75.0", "@solana/web3.js@^1.77.3", "@solana/web3.js@^1.78.2", "@solana/web3.js@^1.78.3":
version "1.87.6"
resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.87.6.tgz#6744cfc5f4fc81e0f58241c0a92648a7320bb3bf"
integrity sha512-LkqsEBgTZztFiccZZXnawWa8qNCATEqE97/d0vIwjTclmVlc8pBpD1DmjfVHtZ1HS5fZorFlVhXfpwnCNDZfyg==
@ -3441,10 +3488,10 @@ axios@^0.25.0:
dependencies:
follow-redirects "^1.14.7"
axios@^1.1.3, axios@^1.4.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.5.0.tgz#f02e4af823e2e46a9768cfc74691fdd0517ea267"
integrity sha512-D4DdjDo5CY50Qms0qGQTTw6Q44jl7zRwY7bthds06pUGfChBCTcQs+N743eFWGEd6pRTMd6A+I87aWyFV5wiZQ==
axios@^1.1.3, axios@^1.4.0, axios@^1.6.2:
version "1.6.2"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.2.tgz#de67d42c755b571d3e698df1b6504cde9b0ee9f2"
integrity sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==
dependencies:
follow-redirects "^1.15.0"
form-data "^4.0.0"
@ -4325,7 +4372,7 @@ decamelize@^1.2.0:
resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290"
integrity sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==
decimal.js-light@^2.4.1:
decimal.js-light@^2.4.1, decimal.js-light@^2.5.1:
version "2.5.1"
resolved "https://registry.yarnpkg.com/decimal.js-light/-/decimal.js-light-2.5.1.tgz#134fd32508f19e208f4fb2f8dac0d2626a867934"
integrity sha512-qIMFpTMZmny+MMIitAB6D7iVPEorVw6YQRWkvarTkT4tBeSLLiHzcwj6q0MmYSFCiVpiqPJTJEYIrpcPzVEIvg==
@ -4335,7 +4382,7 @@ decimal.js@10.4.0:
resolved "https://registry.yarnpkg.com/decimal.js/-/decimal.js-10.4.0.tgz#97a7448873b01e92e5ff9117d89a7bca8e63e0fe"
integrity sha512-Nv6ENEzyPQ6AItkGwLE2PGKinZZ9g59vSh2BeH6NqPu0OTKZ5ruJsVqh/orbAnqXc9pBbgXAIrc2EyaCj8NpGg==
decimal.js@^10.4.3:
decimal.js@^10.3.1, decimal.js@^10.4.3:
version "10.4.3"
resolved "https://registry.yarnpkg.com/decimal.js/-/decimal.js-10.4.3.tgz#1044092884d245d1b7f65725fa4ad4c6f781cc23"
integrity sha512-VBBaLc1MgL5XpzgIP7ny5Z6Nx3UrRkIViUkPUdtl9aya5amy3De1gsUUSB1g3+3sExYNjCAsAznmukyxCb1GRA==
@ -5212,6 +5259,11 @@ fastq@^1.6.0:
dependencies:
reusify "^1.0.4"
fecha@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/fecha/-/fecha-4.2.3.tgz#4d9ccdbc61e8629b259fdca67e65891448d569fd"
integrity sha512-OP2IUU6HeYKJi3i0z4A19kHMQoLVs4Hc+DPqqxI2h/DPZHTm/vjsfC6P0b4jCMy14XizLBqvndQ+UilD7707Jw==
fetch-blob@^3.1.2, fetch-blob@^3.1.4:
version "3.2.0"
resolved "https://registry.yarnpkg.com/fetch-blob/-/fetch-blob-3.2.0.tgz#f09b8d4bbd45adc6f0c20b7e787e793e309dcce9"
@ -8387,6 +8439,11 @@ three@^0.155.0:
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"
integrity sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg==
tiny-invariant@^1.2.0:
version "1.3.1"
resolved "https://registry.yarnpkg.com/tiny-invariant/-/tiny-invariant-1.3.1.tgz#8560808c916ef02ecfd55e66090df23a4b7aa642"
integrity sha512-AD5ih2NlSssTCwsMznbvwMZpJ1cbhkGd2uueNxzv2jDlEeZdU04JQfRnggJQ8DrcVBGjAsCKwFBbDlVNtEMlzw==
tippy.js@^6.3.1:
version "6.3.7"
resolved "https://registry.yarnpkg.com/tippy.js/-/tippy.js-6.3.7.tgz#8ccfb651d642010ed9a32ff29b0e9e19c5b8c61c"
@ -8422,6 +8479,11 @@ to-regex-range@^5.0.1:
dependencies:
is-number "^7.0.0"
toformat@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/toformat/-/toformat-2.0.0.tgz#7a043fd2dfbe9021a4e36e508835ba32056739d8"
integrity sha512-03SWBVop6nU8bpyZCx7SodpYznbZF5R4ljwNLBcTQzKOD9xuihRo/psX58llS1BMFhhAI08H3luot5GoXJz2pQ==
toggle-selection@^1.0.6:
version "1.0.6"
resolved "https://registry.yarnpkg.com/toggle-selection/-/toggle-selection-1.0.6.tgz#6e45b1263f2017fa0acc7d89d78b15b8bf77da32"