always supply usdc fallback oracle (#22)

This commit is contained in:
Lou-Kamades 2024-03-19 20:58:14 +01:00 committed by GitHub
parent 1419ddab2f
commit 07013ea349
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 34 additions and 11 deletions

View File

@ -36,7 +36,7 @@
},
"dependencies": {
"@blockworks-foundation/mango-feeds": "0.1.7",
"@blockworks-foundation/mango-v4": "0.23.0-rc2",
"@blockworks-foundation/mango-v4": "0.23.0-rc5",
"@blockworks-foundation/mango-v4-settings": "0.14.15",
"@glitchful-dev/sol-apy-sdk": "3.0.2",
"@headlessui/react": "1.6.6",

View File

@ -36,6 +36,7 @@ import {
BOOST_DATA_API_URL,
CONNECTION_COMMITMENT,
DEFAULT_MARKET_NAME,
FALLBACK_ORACLES,
INPUT_TOKEN_DEFAULT,
MANGO_DATA_API_URL,
MAX_PRIORITY_FEE_KEYS,
@ -111,10 +112,14 @@ export const emptyWallet = new EmptyWallet(Keypair.generate())
const initMangoClient = (
provider: AnchorProvider,
opts = { prioritizationFee: DEFAULT_PRIORITY_FEE },
opts = {
prioritizationFee: DEFAULT_PRIORITY_FEE,
fallbackOracleConfig: FALLBACK_ORACLES,
},
): MangoClient => {
return MangoClient.connect(provider, CLUSTER, MANGO_BOOST_ID, {
prioritizationFee: opts.prioritizationFee,
fallbackOracleConfig: opts.fallbackOracleConfig,
idsSource: 'get-program-accounts',
postSendTxCallback: ({ txid }: { txid: string }) => {
notify({
@ -777,6 +782,7 @@ const mangoStore = create<MangoStore>()(
const priorityFee = get().priorityFee ?? DEFAULT_PRIORITY_FEE
const client = initMangoClient(provider, {
prioritizationFee: priorityFee,
fallbackOracleConfig: FALLBACK_ORACLES,
})
set((s) => {
@ -827,7 +833,11 @@ const mangoStore = create<MangoStore>()(
options,
)
newProvider.opts.skipPreflight = true
const newClient = initMangoClient(newProvider)
const priorityFee = get().priorityFee ?? DEFAULT_PRIORITY_FEE
const newClient = initMangoClient(newProvider, {
prioritizationFee: priorityFee,
fallbackOracleConfig: FALLBACK_ORACLES,
})
set((state) => {
state.connection = newConnection
state.client = newClient
@ -880,6 +890,7 @@ const mangoStore = create<MangoStore>()(
const newClient = initMangoClient(provider, {
prioritizationFee: feeEstimate,
fallbackOracleConfig: FALLBACK_ORACLES,
})
set((state) => {
state.priorityFee = feeEstimate

View File

@ -1,3 +1,5 @@
import { PublicKey } from '@solana/web3.js'
// lev stake
export const BORROW_TOKEN = 'USDC'
@ -188,3 +190,7 @@ export const MAX_ACCOUNTS = {
export const ACCOUNT_ACTIONS_NUMBER_FORMAT_CLASSES =
'w-full rounded-lg rounded-l-none border border-th-input-border bg-th-input-bkg p-3 text-right font-mono text-xl text-th-fgd-1 focus-visible:border-th-fgd-4 focus:outline-none md:hover:border-th-input-border-hover md:hover:focus-visible:border-th-fgd-4'
export const FALLBACK_ORACLES = [
new PublicKey('Gnt27xtC473ZT2Mw5u8wZ68Z3gULkSTb5DuxJy7eJotD'),
] // USDC

View File

@ -56,7 +56,7 @@ export const withdrawAndClose = async (
}
const stakeBalance = mangoAccount.getTokenBalanceUi(stakeBank)
const withdrawHealthRemainingAccounts: PublicKey[] =
client.buildHealthRemainingAccounts(group, [mangoAccount], [], [], [])
await client.buildHealthRemainingAccounts(group, [mangoAccount], [], [], [])
const withdrawMax =
amount >= floorToDecimal(stakeBalance, stakeBank.mintDecimals).toNumber()
console.log('withdrawMax: ', withdrawMax)
@ -167,7 +167,13 @@ export const unstakeAndSwap = async (
)
const swapHealthRemainingAccounts: PublicKey[] = mangoAccount
? client.buildHealthRemainingAccounts(group, [mangoAccount], [], [], [])
? await client.buildHealthRemainingAccounts(
group,
[mangoAccount],
[],
[],
[],
)
: [stakeBank.publicKey, stakeBank.oracle]
const [swapIxs, alts] = await createSwapIxs({
client: client,
@ -245,7 +251,7 @@ export const stakeAndCreate = async (
}
const depositHealthRemainingAccounts: PublicKey[] = mangoAccount
? client.buildHealthRemainingAccounts(
? await client.buildHealthRemainingAccounts(
group,
[mangoAccount],
[stakeBank],
@ -367,7 +373,7 @@ export const depositAndCreate = async (
}
const depositHealthRemainingAccounts: PublicKey[] = mangoAccount
? client.buildHealthRemainingAccounts(
? await client.buildHealthRemainingAccounts(
group,
[mangoAccount],
[depositBank],

View File

@ -39,10 +39,10 @@
bn.js "^5.2.1"
eslint-config-prettier "^9.0.0"
"@blockworks-foundation/mango-v4@0.23.0-rc2":
version "0.23.0-rc2"
resolved "https://registry.yarnpkg.com/@blockworks-foundation/mango-v4/-/mango-v4-0.23.0-rc2.tgz#f59e053fa5372432cb5bf9fae1cefb2a178e08e6"
integrity sha512-v3mUGggMEK3+z7fUsMa9KA7knkROcPQzpFfuRpEuVdyhFmHAe0eHueMnABvhBNurIdtfA5/dcut1TN+GDyJVew==
"@blockworks-foundation/mango-v4@0.23.0-rc5":
version "0.23.0-rc5"
resolved "https://registry.yarnpkg.com/@blockworks-foundation/mango-v4/-/mango-v4-0.23.0-rc5.tgz#8b49aa9439f9b997732246ef3834e929d28cf225"
integrity sha512-IS2zW3bG3slPSCDYeDpSGmHTHJ9qJEPiARLzpwtiQxYf3WfqgTHwgC7sxorZGcmjkZeZTr4xPgBzqaOeTWGDsw==
dependencies:
"@blockworks-foundation/mango-v4-settings" "0.14.15"
"@blockworks-foundation/mangolana" "0.0.14"