code review
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
parent
c626b68a4a
commit
d9c7260375
|
@ -7,5 +7,7 @@ pub enum MangoError {
|
||||||
#[msg("")]
|
#[msg("")]
|
||||||
SomeError,
|
SomeError,
|
||||||
#[msg("")]
|
#[msg("")]
|
||||||
UnknownOracle,
|
UnexpectedOracle,
|
||||||
|
#[msg("")]
|
||||||
|
UnknownOracleType,
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,6 +132,8 @@ pub fn withdraw(ctx: Context<Withdraw>, amount: u64, allow_borrow: bool) -> Resu
|
||||||
// converts the token value to the basis token value for health computations
|
// converts the token value to the basis token value for health computations
|
||||||
// TODO: health basis token == USDC?
|
// TODO: health basis token == USDC?
|
||||||
let oracle_type = determine_oracle_type(oracle_ai)?;
|
let oracle_type = determine_oracle_type(oracle_ai)?;
|
||||||
|
require!(bank.oracle == oracle_ai.key(), MangoError::UnexpectedOracle);
|
||||||
|
|
||||||
let price = match oracle_type {
|
let price = match oracle_type {
|
||||||
OracleType::Stub => {
|
OracleType::Stub => {
|
||||||
AccountLoader::<'_, StubOracle>::try_from(oracle_ai)?
|
AccountLoader::<'_, StubOracle>::try_from(oracle_ai)?
|
||||||
|
|
|
@ -23,5 +23,5 @@ pub fn determine_oracle_type(account: &AccountInfo) -> Result<OracleType> {
|
||||||
return Ok(OracleType::Stub);
|
return Ok(OracleType::Stub);
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(MangoError::UnknownOracle.into())
|
Err(MangoError::UnknownOracleType.into())
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ use solana_program::instruction::Instruction;
|
||||||
use solana_sdk::instruction;
|
use solana_sdk::instruction;
|
||||||
use solana_sdk::signature::{Keypair, Signer};
|
use solana_sdk::signature::{Keypair, Signer};
|
||||||
use solana_sdk::transport::TransportError;
|
use solana_sdk::transport::TransportError;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
use super::solana::SolanaCookie;
|
use super::solana::SolanaCookie;
|
||||||
use mango_v4::state::*;
|
use mango_v4::state::*;
|
||||||
|
@ -294,6 +295,7 @@ impl<'keypair> ClientInstruction for RegisterTokenInstruction<'keypair> {
|
||||||
pub struct SetStubOracle<'keypair> {
|
pub struct SetStubOracle<'keypair> {
|
||||||
pub mint: Pubkey,
|
pub mint: Pubkey,
|
||||||
pub payer: &'keypair Keypair,
|
pub payer: &'keypair Keypair,
|
||||||
|
pub price: &'static str,
|
||||||
}
|
}
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl<'keypair> ClientInstruction for SetStubOracle<'keypair> {
|
impl<'keypair> ClientInstruction for SetStubOracle<'keypair> {
|
||||||
|
@ -306,7 +308,7 @@ impl<'keypair> ClientInstruction for SetStubOracle<'keypair> {
|
||||||
) -> (Self::Accounts, Instruction) {
|
) -> (Self::Accounts, Instruction) {
|
||||||
let program_id = mango_v4::id();
|
let program_id = mango_v4::id();
|
||||||
let instruction = Self::Instruction {
|
let instruction = Self::Instruction {
|
||||||
price: I80F48::from_num(1.0),
|
price: I80F48::from_str(self.price).unwrap(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let oracle = Pubkey::find_program_address(
|
let oracle = Pubkey::find_program_address(
|
||||||
|
|
|
@ -65,16 +65,7 @@ async fn test_basic() -> Result<(), TransportError> {
|
||||||
SetStubOracle {
|
SetStubOracle {
|
||||||
mint: mint0.pubkey,
|
mint: mint0.pubkey,
|
||||||
payer,
|
payer,
|
||||||
},
|
price: "1.0",
|
||||||
)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
send_tx(
|
|
||||||
solana,
|
|
||||||
CreateStubOracle {
|
|
||||||
mint: mint0.pubkey,
|
|
||||||
payer,
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
|
Loading…
Reference in New Issue