Merge branch 'dev'

This commit is contained in:
microwavedcola1 2022-05-24 22:06:36 +02:00
commit f9cdf731cf
6 changed files with 89 additions and 43 deletions

View File

@ -1,22 +1,26 @@
2022-05-24,Benchmark,9227
2022-05-24,CloseAccount,4758
2022-05-24,CreateAccount,21436
2022-05-24,CreateAccount,22936
2022-05-24,CreateAccount,24436
2022-05-24,CreateAccount,25781
2022-05-24,CreateGroup,15147
2022-05-24,CreateGroup,16647
2022-05-24,CreateStubOracle,21810
2022-05-24,CreateStubOracle,24810
2022-05-24,CreateStubOracle,5129
2022-05-24,CreateStubOracle,51734
2022-05-24,CreateStubOracle,56202
2022-05-24,CreateStubOracle,59202
2022-05-24,Deposit,20310
2022-05-24,Deposit,26053
2022-05-24,Deposit,5129
2022-05-24,InitializeAccount,17310
2022-05-24,Deposit,26565
2022-05-24,InitializeAccount,16936
2022-05-24,InitializeAccount,34110
2022-05-24,InitializeAccount,36061
2022-05-24,InitializeAccount,40066
2022-05-24,InitializeAccount,5129
2022-05-24,InitializeAccount,51693
2022-05-24,InitializeAccount,57716
2022-05-24,InitializeAccount,57725
2022-05-24,InitializeAccount,62193
2022-05-24,InitializeAccount,63693
2022-05-24,InitializeAccount,38114
2022-05-24,InitializeAccount,44193
2022-05-24,InitializeAccount,56202
2022-05-24,InitializeAccount,57693
2022-05-24,InitializeAccount,63702
2022-05-24,InitializeAccount,65193
2022-05-24,InitializeAccount,66693
2022-05-24,LiqTokenWithToken,57875
2022-05-24,LiqTokenWithToken,59885
2022-05-24,LiqTokenWithToken,61768
@ -24,37 +28,39 @@
2022-05-24,PerpCancelOrder,8951
2022-05-24,PerpCancelOrderByClientOrderId,8958
2022-05-24,PerpConsumeEvents,6388
2022-05-24,PerpCreateMarket,30751
2022-05-24,PerpCreateMarket,26251
2022-05-24,PerpPlaceOrder,20751
2022-05-24,PerpPlaceOrder,20884
2022-05-24,PerpPlaceOrder,21451
2022-05-24,PerpPlaceOrder,22082
2022-05-24,PerpPlaceOrder,23137
2022-05-24,RegisterToken,17310
2022-05-24,RegisterToken,18810
2022-05-24,RegisterToken,5129
2022-05-24,RegisterToken,53193
2022-05-24,RegisterToken,57693
2022-05-24,Revoke,93207
2022-05-24,Revoke,97260
2022-05-24,Revoke,97669
2022-05-24,RegisterToken,53202
2022-05-24,RegisterToken,54693
2022-05-24,Revoke,93216
2022-05-24,Revoke,97269
2022-05-24,Revoke,97678
2022-05-24,Serum3CancelOrder,24472
2022-05-24,Serum3CreateOpenOrders,26373
2022-05-24,Serum3CreateOpenOrders,26465
2022-05-24,Serum3CreateOpenOrders,26475
2022-05-24,Serum3CreateOpenOrders,26487
2022-05-24,Serum3CreateOpenOrders,26470
2022-05-24,Serum3CreateOpenOrders,26493
2022-05-24,Serum3CreateOpenOrders,26500
2022-05-24,Serum3CreateOpenOrders,26558
2022-05-24,Serum3CreateOpenOrders,27981
2022-05-24,Serum3CreateOpenOrders,29470
2022-05-24,Serum3CreateOpenOrders,27873
2022-05-24,Serum3CreateOpenOrders,27965
2022-05-24,Serum3CreateOpenOrders,27975
2022-05-24,Serum3CreateOpenOrders,27987
2022-05-24,Serum3CreateOpenOrders,29481
2022-05-24,Serum3CreateOpenOrders,29500
2022-05-24,Serum3RegisterMarket,24281
2022-05-24,Serum3RegisterMarket,28781
2022-05-24,Serum3RegisterMarket,27281
2022-05-24,SetStubOracle,17310
2022-05-24,Transfer,22297
2022-05-24,Transfer,22338
2022-05-24,Transfer,22347
2022-05-24,Transfer,25862
2022-05-24,Transfer,25910
2022-05-24,Transfer,26390
2022-05-24,Transfer,26565
2022-05-24,Transfer,26708
2022-05-24,Transfer,27631
2022-05-24,Transfer,27793
@ -74,20 +80,18 @@
2022-05-24,Transfer,31927
2022-05-24,Transfer,32444
2022-05-24,Transfer,32708
2022-05-24,Transfer,33238
2022-05-24,Transfer,34119
2022-05-24,Transfer,35581
2022-05-24,Transfer,38114
2022-05-24,Transfer,40066
2022-05-24,Transfer,40535
2022-05-24,Transfer,42249
2022-05-24,Transfer,44193
2022-05-24,Transfer,45726
2022-05-24,Transfer,48659
2022-05-24,Transfer,50696
2022-05-24,Transfer,55672
2022-05-24,Transfer,60658
2022-05-24,Transfer,65977
2022-05-24,Transfer,65986
2022-05-24,Transfer,76337
2022-05-24,Transfer,89560
2022-05-24,Transfer,89889
2022-05-24,UpdateIndex,20940
2022-05-24,Withdraw,57999
2022-05-24,Withdraw,33238

View File

@ -50,6 +50,12 @@ struct AllowedVault {
loan_amount: I80F48,
}
#[derive(AnchorDeserialize, AnchorSerialize, Clone, Copy)]
pub struct MarginTradeWithdraw {
pub index: u8,
pub amount: u64,
}
/// - `num_health_accounts` is the number of health accounts that remaining_accounts starts with.
/// - `withdraws` is a list of tuples containing the index to a vault in target_accounts and the
/// amount that the target program shall be allowed to withdraw
@ -57,7 +63,7 @@ struct AllowedVault {
pub fn margin_trade<'key, 'accounts, 'remaining, 'info>(
ctx: Context<'key, 'accounts, 'remaining, 'info, MarginTrade<'info>>,
num_health_accounts: usize,
withdraws: Vec<(u8, u64)>,
withdraws: Vec<MarginTradeWithdraw>,
cpi_data: Vec<u8>,
) -> Result<()> {
let group = ctx.accounts.group.load()?;
@ -155,8 +161,9 @@ pub fn margin_trade<'key, 'accounts, 'remaining, 'info>(
if let Some(vault_info) = used_vaults.get_mut(&bank.vault) {
let withdraw_amount = withdraws
.iter()
.find_map(|&(index, amount)| {
(index as usize == vault_info.vault_cpi_ai_index).then(|| amount)
.find_map(|&withdraw| {
(withdraw.index as usize == vault_info.vault_cpi_ai_index)
.then(|| withdraw.amount)
})
// Even if we don't withdraw from a vault we still need to track it:
// Possibly the invoked program will deposit funds into it.

View File

@ -32,7 +32,7 @@ mod create_group;
mod create_stub_oracle;
mod deposit;
mod liq_token_with_token;
mod margin_trade;
pub mod margin_trade;
mod perp_cancel_all_orders;
mod perp_cancel_all_orders_by_side;
mod perp_cancel_order;

View File

@ -100,7 +100,7 @@ pub mod mango_v4 {
pub fn margin_trade<'key, 'accounts, 'remaining, 'info>(
ctx: Context<'key, 'accounts, 'remaining, 'info, MarginTrade<'info>>,
num_health_accounts: usize,
withdraws: Vec<(u8, u64)>,
withdraws: Vec<MarginTradeWithdraw>,
cpi_data: Vec<u8>,
) -> Result<()> {
instructions::margin_trade(ctx, num_health_accounts, withdraws, cpi_data)

View File

@ -6,7 +6,7 @@ use anchor_spl::token::{Token, TokenAccount};
use fixed::types::I80F48;
use itertools::Itertools;
use mango_v4::instructions::{
InterestRateParams, Serum3OrderType, Serum3SelfTradeBehavior, Serum3Side,
InterestRateParams, MarginTradeWithdraw, Serum3OrderType, Serum3SelfTradeBehavior, Serum3Side,
};
use solana_program::instruction::Instruction;
use solana_sdk::instruction;
@ -295,7 +295,10 @@ impl<'keypair> ClientInstruction for MarginTradeInstruction<'keypair> {
let instruction = Self::Instruction {
num_health_accounts: health_check_metas.len(),
withdraws: vec![(1, self.withdraw_amount)],
withdraws: vec![MarginTradeWithdraw {
index: 1,
amount: self.withdraw_amount,
}],
cpi_data: self.margin_trade_program_ix_cpi_data.clone(),
};

View File

@ -530,7 +530,7 @@ export type MangoV4 = {
"name": "withdraws",
"type": {
"vec": {
"defined": "(u8,u64)"
"defined": "MarginTradeWithdraw"
}
}
},
@ -2201,6 +2201,22 @@ export type MangoV4 = {
}
],
"types": [
{
"name": "MarginTradeWithdraw",
"type": {
"kind": "struct",
"fields": [
{
"name": "index",
"type": "u8"
},
{
"name": "amount",
"type": "u64"
}
]
}
},
{
"name": "InterestRateParams",
"type": {
@ -3387,7 +3403,7 @@ export const IDL: MangoV4 = {
"name": "withdraws",
"type": {
"vec": {
"defined": "(u8,u64)"
"defined": "MarginTradeWithdraw"
}
}
},
@ -5058,6 +5074,22 @@ export const IDL: MangoV4 = {
}
],
"types": [
{
"name": "MarginTradeWithdraw",
"type": {
"kind": "struct",
"fields": [
{
"name": "index",
"type": "u8"
},
{
"name": "amount",
"type": "u64"
}
]
}
},
{
"name": "InterestRateParams",
"type": {