pub trait ValidateMarketBalances:
BaseMarket<{ constants::MARKET_DECIMALS }, Num = u128>
+ Bank<Pubkey, Num = u64>
+ HasMarketMeta {
// Provided methods
fn validate_market_balance_for_the_given_token(
&self,
token: &Pubkey,
excluded: u64,
) -> Result<()> { ... }
fn validate_market_balances(
&self,
long_excluding_amount: u64,
short_excluding_amount: u64,
) -> Result<()> { ... }
fn validate_market_balances_excluding_the_given_token_amounts(
&self,
first_token: &Pubkey,
second_token: &Pubkey,
first_excluding_amount: u64,
second_excluding_amount: u64,
) -> Result<()> { ... }
}
Expand description
Extension trait for validating market balances.
Provided Methods§
Sourcefn validate_market_balance_for_the_given_token(
&self,
token: &Pubkey,
excluded: u64,
) -> Result<()>
fn validate_market_balance_for_the_given_token( &self, token: &Pubkey, excluded: u64, ) -> Result<()>
Validate market balance for the given token.
§Notes
Unlike the Solidity version, this function does not actually verify the token balance but only checks the balance recorded in the market state. This is because we use a shared vaults design, making it unlikely to sum all markets in a single instruction and then verify the vault’s balance.
The reason we adopt a shared vaults design is to avoid performing a large number of CPIs when executing swaps along the swap path, which could easily lead to heap memory overflows if we used Solana’s default heap allocator.
Sourcefn validate_market_balances(
&self,
long_excluding_amount: u64,
short_excluding_amount: u64,
) -> Result<()>
fn validate_market_balances( &self, long_excluding_amount: u64, short_excluding_amount: u64, ) -> Result<()>
Validate market balances.
Sourcefn validate_market_balances_excluding_the_given_token_amounts(
&self,
first_token: &Pubkey,
second_token: &Pubkey,
first_excluding_amount: u64,
second_excluding_amount: u64,
) -> Result<()>
fn validate_market_balances_excluding_the_given_token_amounts( &self, first_token: &Pubkey, second_token: &Pubkey, first_excluding_amount: u64, second_excluding_amount: u64, ) -> Result<()>
Validate market balances excluding the given token amounts.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.