diff --git a/bin/liquidator/src/liquidate.rs b/bin/liquidator/src/liquidate.rs index c355aaa19..fd39d4964 100644 --- a/bin/liquidator/src/liquidate.rs +++ b/bin/liquidator/src/liquidate.rs @@ -263,7 +263,7 @@ impl<'a> LiquidateHelper<'a> { liq_ixs.cu = liq_ixs.cu.max(self.config.compute_limit_for_liq_ix); let txsig = self .client - .send_and_confirm_owner_tx(liq_ixs.to_instructions()) + .send_and_confirm_authority_tx(liq_ixs.to_instructions()) .await .context("sending perp_liq_base_or_positive_pnl_instruction")?; info!( @@ -309,7 +309,7 @@ impl<'a> LiquidateHelper<'a> { liq_ixs.cu = liq_ixs.cu.max(self.config.compute_limit_for_liq_ix); let txsig = self .client - .send_and_confirm_owner_tx(liq_ixs.to_instructions()) + .send_and_confirm_authority_tx(liq_ixs.to_instructions()) .await .context("sending perp_liq_negative_pnl_or_bankruptcy_instruction")?; info!( @@ -503,7 +503,7 @@ impl<'a> LiquidateHelper<'a> { liq_ixs.cu = liq_ixs.cu.max(self.config.compute_limit_for_liq_ix); let txsig = self .client - .send_and_confirm_owner_tx(liq_ixs.to_instructions()) + .send_and_confirm_authority_tx(liq_ixs.to_instructions()) .await .context("sending liq_token_with_token")?; info!( @@ -560,7 +560,7 @@ impl<'a> LiquidateHelper<'a> { liq_ixs.cu = liq_ixs.cu.max(self.config.compute_limit_for_liq_ix); let txsig = self .client - .send_and_confirm_owner_tx(liq_ixs.to_instructions()) + .send_and_confirm_authority_tx(liq_ixs.to_instructions()) .await .context("sending liq_token_with_token")?; info!( diff --git a/bin/liquidator/src/rebalance.rs b/bin/liquidator/src/rebalance.rs index 0472e300c..625e2a470 100644 --- a/bin/liquidator/src/rebalance.rs +++ b/bin/liquidator/src/rebalance.rs @@ -644,7 +644,7 @@ impl Rebalancer { let tx_builder = TransactionBuilder { instructions: ixs.to_instructions(), - signers: vec![self.mango_client.owner.clone()], + signers: vec![self.mango_client.authority.clone()], ..self.mango_client.transaction_builder().await? }; diff --git a/bin/liquidator/src/telemetry.rs b/bin/liquidator/src/telemetry.rs index 5cc87bf9a..06887840f 100644 --- a/bin/liquidator/src/telemetry.rs +++ b/bin/liquidator/src/telemetry.rs @@ -21,9 +21,9 @@ async fn report(client: &MangoClient, min_health_ratio: f64) -> anyhow::Result<( }) .to_string(); - let signature = client.owner.sign_message(message.as_bytes()); + let signature = client.authority.sign_message(message.as_bytes()); let payload = serde_json::json!({ - "wallet_pk": client.owner.pubkey().to_string(), + "wallet_pk": client.authority.pubkey().to_string(), "message": message, "signature": signature.to_string(), }); diff --git a/bin/liquidator/src/trigger_tcs.rs b/bin/liquidator/src/trigger_tcs.rs index 8a3ef06ee..04d802f3f 100644 --- a/bin/liquidator/src/trigger_tcs.rs +++ b/bin/liquidator/src/trigger_tcs.rs @@ -1202,7 +1202,7 @@ impl Context { let fee_payer = self.mango_client.client.fee_payer(); TransactionBuilder { instructions: vec![compute_ix], - signers: vec![self.mango_client.owner.clone(), fee_payer], + signers: vec![self.mango_client.authority.clone(), fee_payer], ..self.mango_client.transaction_builder().await? } }; diff --git a/bin/settler/src/tcs_start.rs b/bin/settler/src/tcs_start.rs index 9f8e37011..9cde5efa7 100644 --- a/bin/settler/src/tcs_start.rs +++ b/bin/settler/src/tcs_start.rs @@ -142,7 +142,7 @@ impl State { } let txsig = match mango_client - .send_and_confirm_owner_tx(instructions.to_instructions()) + .send_and_confirm_authority_tx(instructions.to_instructions()) .await { Ok(v) => v, diff --git a/lib/client/src/client.rs b/lib/client/src/client.rs index bae7592f5..52e84b591 100644 --- a/lib/client/src/client.rs +++ b/lib/client/src/client.rs @@ -273,7 +273,7 @@ pub struct MangoClient { // call to refresh banks etc -- if it's backed by websockets, these could just do nothing pub account_fetcher: Arc, - pub owner: Arc, + pub authority: Arc, pub mango_account_address: Pubkey, pub context: MangoGroupContext, @@ -406,7 +406,7 @@ impl MangoClient { pub async fn new_for_existing_account( client: Client, account: Pubkey, - owner: Arc, + authority: Arc, ) -> anyhow::Result { let rpc = client.new_rpc_async(); let account_fetcher = Arc::new(CachedAccountFetcher::new(Arc::new(RpcAccountFetcher { @@ -415,25 +415,25 @@ impl MangoClient { let mango_account = account_fetcher_fetch_mango_account(&*account_fetcher, &account).await?; let group = mango_account.fixed.group; - if mango_account.fixed.owner != owner.pubkey() { + if mango_account.fixed.owner != authority.pubkey() { anyhow::bail!( "bad owner for account: expected {} got {}", mango_account.fixed.owner, - owner.pubkey() + authority.pubkey() ); } let rpc = client.rpc_async(); let group_context = MangoGroupContext::new_from_rpc(&rpc, group).await?; - Self::new_detail(client, account, owner, group_context, account_fetcher) + Self::new_detail(client, account, authority, group_context, account_fetcher) } /// Allows control of AccountFetcher and externally created MangoGroupContext pub fn new_detail( client: Client, account: Pubkey, - owner: Arc, + authority: Arc, // future: maybe pass Arc, so it can be extenally updated? group_context: MangoGroupContext, account_fetcher: Arc, @@ -441,15 +441,15 @@ impl MangoClient { Ok(Self { client, account_fetcher, - owner, + authority, mango_account_address: account, context: group_context, http_client: reqwest::Client::new(), }) } - pub fn owner(&self) -> Pubkey { - self.owner.pubkey() + pub fn authority(&self) -> Pubkey { + self.authority.pubkey() } pub fn group(&self) -> Pubkey { @@ -554,12 +554,15 @@ impl MangoClient { &mango_v4::accounts::TokenDeposit { group: self.group(), account: self.mango_account_address, - owner: self.owner(), + owner: self.authority(), bank: token.first_bank(), vault: token.first_vault(), oracle: token.oracle, - token_account: get_associated_token_address(&self.owner(), &token.mint), - token_authority: self.owner(), + token_account: get_associated_token_address( + &self.authority(), + &token.mint, + ), + token_authority: self.authority(), token_program: Token::id(), }, None, @@ -574,7 +577,8 @@ impl MangoClient { }, self.instruction_cu(health_cu), ); - self.send_and_confirm_owner_tx(ixs.to_instructions()).await + self.send_and_confirm_authority_tx(ixs.to_instructions()) + .await } /// Assert that health of account is > N @@ -639,7 +643,7 @@ impl MangoClient { let ixs = PreparedInstructions::from_vec( vec![ spl_associated_token_account::instruction::create_associated_token_account_idempotent( - &self.owner(), + &self.authority(), &account.fixed.owner, &mint, &Token::id(), @@ -651,7 +655,7 @@ impl MangoClient { &mango_v4::accounts::TokenWithdraw { group: self.group(), account: self.mango_account_address, - owner: self.owner(), + owner: self.authority(), bank: token.first_bank(), vault: token.first_vault(), oracle: token.oracle, @@ -687,7 +691,8 @@ impl MangoClient { let ixs = self .token_withdraw_instructions(&account, mint, amount, allow_borrow) .await?; - self.send_and_confirm_owner_tx(ixs.to_instructions()).await + self.send_and_confirm_authority_tx(ixs.to_instructions()) + .await } pub async fn bank_oracle_price(&self, token_index: TokenIndex) -> anyhow::Result { @@ -739,8 +744,8 @@ impl MangoClient { serum_program: s3.serum_program, serum_market_external: s3.serum_market_external, open_orders, - owner: self.owner(), - sol_destination: self.owner(), + owner: self.authority(), + sol_destination: self.authority(), }, None, ), @@ -755,7 +760,8 @@ impl MangoClient { pub async fn serum3_close_open_orders(&self, name: &str) -> anyhow::Result { let market_index = self.context.serum3_market_index(name); let ix = self.serum3_close_open_orders_instruction(market_index); - self.send_and_confirm_owner_tx(ix.to_instructions()).await + self.send_and_confirm_authority_tx(ix.to_instructions()) + .await } pub fn serum3_create_open_orders_instruction( @@ -777,8 +783,8 @@ impl MangoClient { serum_program: s3.serum_program, serum_market_external: s3.serum_market_external, open_orders, - owner: self.owner(), - payer: self.owner(), + owner: self.authority(), + payer: self.authority(), system_program: System::id(), rent: sysvar::rent::id(), }, @@ -810,7 +816,7 @@ impl MangoClient { pub async fn serum3_create_open_orders(&self, name: &str) -> anyhow::Result { let market_index = self.context.serum3_market_index(name); let ix = self.serum3_create_open_orders_instruction(market_index); - self.send_and_confirm_owner_tx(vec![ix]).await + self.send_and_confirm_authority_tx(vec![ix]).await } #[allow(clippy::too_many_arguments)] @@ -868,7 +874,7 @@ impl MangoClient { market_base_vault: s3.coin_vault, market_quote_vault: s3.pc_vault, market_vault_signer: s3.vault_signer, - owner: self.owner(), + owner: self.authority(), token_program: Token::id(), }, None, @@ -1131,7 +1137,8 @@ impl MangoClient { let mut ixs = PreparedInstructions::new(); ixs.append(create_or_replace_ixs); ixs.append(place_order_ixs); - self.send_and_confirm_owner_tx(ixs.to_instructions()).await + self.send_and_confirm_authority_tx(ixs.to_instructions()) + .await } pub async fn serum3_settle_funds(&self, name: &str) -> anyhow::Result { @@ -1161,7 +1168,7 @@ impl MangoClient { market_base_vault: s3.coin_vault, market_quote_vault: s3.pc_vault, market_vault_signer: s3.vault_signer, - owner: self.owner(), + owner: self.authority(), token_program: Token::id(), }, v2: mango_v4::accounts::Serum3SettleFundsV2Extra { @@ -1175,7 +1182,7 @@ impl MangoClient { fees_to_dao: true, }), }; - self.send_and_confirm_owner_tx(vec![ix]).await + self.send_and_confirm_authority_tx(vec![ix]).await } pub fn serum3_cancel_all_orders_instruction( @@ -1201,7 +1208,7 @@ impl MangoClient { serum_market: s3.address, serum_program: s3.serum_program, serum_market_external: s3.serum_market_external, - owner: self.owner(), + owner: self.authority(), }, None, ), @@ -1340,7 +1347,7 @@ impl MangoClient { market_bids: s3.bids, market_asks: s3.asks, market_event_queue: s3.event_q, - owner: self.owner(), + owner: self.authority(), }, None, ) @@ -1350,7 +1357,7 @@ impl MangoClient { order_id, }), }; - self.send_and_confirm_owner_tx(vec![ix]).await + self.send_and_confirm_authority_tx(vec![ix]).await } // @@ -1403,7 +1410,7 @@ impl MangoClient { &mango_v4::accounts::PerpPlaceOrder { group: self.group(), account: self.mango_account_address, - owner: self.owner(), + owner: self.authority(), perp_market: perp.address, bids: perp.bids, asks: perp.asks, @@ -1508,7 +1515,8 @@ impl MangoClient { self_trade_behavior, ) .await?; - self.send_and_confirm_owner_tx(ixs.to_instructions()).await + self.send_and_confirm_authority_tx(ixs.to_instructions()) + .await } pub fn perp_cancel_all_orders_instruction( @@ -1526,7 +1534,7 @@ impl MangoClient { &mango_v4::accounts::PerpCancelAllOrders { group: self.group(), account: self.mango_account_address, - owner: self.owner(), + owner: self.authority(), perp_market: perp.address, bids: perp.bids, asks: perp.asks, @@ -1551,7 +1559,8 @@ impl MangoClient { let ixs = self .perp_deactivate_position_instruction(market_index) .await?; - self.send_and_confirm_owner_tx(ixs.to_instructions()).await + self.send_and_confirm_authority_tx(ixs.to_instructions()) + .await } async fn perp_deactivate_position_instruction( @@ -1568,7 +1577,7 @@ impl MangoClient { &mango_v4::accounts::PerpDeactivatePosition { group: self.group(), account: self.mango_account_address, - owner: self.owner(), + owner: self.authority(), perp_market: perp.address, }, None, @@ -1611,7 +1620,7 @@ impl MangoClient { &mango_v4::accounts::PerpSettlePnl { group: self.group(), settler: self.mango_account_address, - settler_owner: self.owner(), + settler_owner: self.authority(), perp_market: perp.address, account_a: *account_a.0, account_b: *account_b.0, @@ -1715,7 +1724,7 @@ impl MangoClient { perp_market: perp.address, oracle: perp.oracle, liqor: self.mango_account_address, - liqor_owner: self.owner(), + liqor_owner: self.authority(), liqee: *liqee.0, settle_bank: settle_token_info.first_bank(), settle_vault: settle_token_info.first_vault(), @@ -1775,7 +1784,7 @@ impl MangoClient { perp_market: perp.address, oracle: perp.oracle, liqor: self.mango_account_address, - liqor_owner: self.owner(), + liqor_owner: self.authority(), liqee: *liqee.0, settle_bank: settle_token_info.first_bank(), settle_vault: settle_token_info.first_vault(), @@ -1883,7 +1892,7 @@ impl MangoClient { group: self.group(), liqee: *liqee.0, liqor: self.mango_account_address, - liqor_owner: self.owner(), + liqor_owner: self.authority(), }, None, ); @@ -1944,7 +1953,7 @@ impl MangoClient { group: self.group(), liqee: *liqee.0, liqor: self.mango_account_address, - liqor_owner: self.owner(), + liqor_owner: self.authority(), liab_mint_info: liab_info.mint_info_address, quote_vault: quote_info.first_vault(), insurance_vault: group.insurance_vault, @@ -2004,7 +2013,7 @@ impl MangoClient { group: self.group(), liqee: *liqee.0, liqor: self.mango_account_address, - liqor_authority: self.owner(), + liqor_authority: self.authority(), }, None, ); @@ -2051,7 +2060,7 @@ impl MangoClient { group: self.group(), liqee: *account.0, liqor: self.mango_account_address, - liqor_authority: self.owner(), + liqor_authority: self.authority(), }, None, ); @@ -2252,7 +2261,7 @@ impl MangoClient { self.context.compute_estimates.cu_per_mango_instruction + health_cu } - pub async fn send_and_confirm_owner_tx( + pub async fn send_and_confirm_authority_tx( &self, instructions: Vec, ) -> anyhow::Result { @@ -2260,7 +2269,7 @@ impl MangoClient { instructions, ..self.transaction_builder().await? }; - tx_builder.signers.push(self.owner.clone()); + tx_builder.signers.push(self.authority.clone()); tx_builder.send_and_confirm(&self.client).await } diff --git a/lib/client/src/swap/jupiter_v6.rs b/lib/client/src/swap/jupiter_v6.rs index 1ebe27d89..864c049c4 100644 --- a/lib/client/src/swap/jupiter_v6.rs +++ b/lib/client/src/swap/jupiter_v6.rs @@ -230,14 +230,14 @@ impl<'a> JupiterV6<'a> { .map(util::to_writable_account_meta) .collect::>(); - let owner = self.mango_client.owner(); + let authority = self.mango_client.authority(); let account = &self.mango_client.mango_account().await?; let token_ams = [source_token.mint, target_token.mint] .into_iter() .map(|mint| { util::to_writable_account_meta( - anchor_spl::associated_token::get_associated_token_address(&owner, &mint), + anchor_spl::associated_token::get_associated_token_address(&authority, &mint), ) }) .collect::>(); @@ -274,7 +274,7 @@ impl<'a> JupiterV6<'a> { .post(format!("{}/swap-instructions", config.jupiter_v6_url)) .query(&query_args) .json(&SwapRequest { - user_public_key: owner.to_string(), + user_public_key: authority.to_string(), wrap_and_unwrap_sol: false, use_shared_accounts: true, fee_account: None, @@ -304,8 +304,8 @@ impl<'a> JupiterV6<'a> { // Ensure the source token account is created (jupiter takes care of the output account) instructions.push( spl_associated_token_account::instruction::create_associated_token_account_idempotent( - &owner, - &owner, + &authority, + &authority, &source_token.mint, &Token::id(), ), @@ -317,7 +317,7 @@ impl<'a> JupiterV6<'a> { let mut ams = anchor_lang::ToAccountMetas::to_account_metas( &mango_v4::accounts::FlashLoanBegin { account: self.mango_client.mango_account_address, - owner, + owner: authority, token_program: Token::id(), instructions: solana_sdk::sysvar::instructions::id(), }, @@ -340,7 +340,7 @@ impl<'a> JupiterV6<'a> { let mut ams = anchor_lang::ToAccountMetas::to_account_metas( &mango_v4::accounts::FlashLoanEnd { account: self.mango_client.mango_account_address, - owner, + owner: authority, token_program: Token::id(), }, None, @@ -375,13 +375,13 @@ impl<'a> JupiterV6<'a> { .await?; address_lookup_tables.extend(jup_alts.into_iter()); - let payer = owner; // maybe use fee_payer? but usually it's the same + let payer = authority; // maybe use fee_payer? but usually it's the same Ok(TransactionBuilder { instructions, address_lookup_tables, payer, - signers: vec![self.mango_client.owner.clone()], + signers: vec![self.mango_client.authority.clone()], config: self .mango_client .client diff --git a/lib/client/src/swap/sanctum.rs b/lib/client/src/swap/sanctum.rs index ddd2bed06..d93ca4d2f 100644 --- a/lib/client/src/swap/sanctum.rs +++ b/lib/client/src/swap/sanctum.rs @@ -124,14 +124,14 @@ impl<'a> Sanctum<'a> { .map(util::to_writable_account_meta) .collect::>(); - let owner = self.mango_client.owner(); + let authority = self.mango_client.authority(); let account = &self.mango_client.mango_account().await?; let token_ams = [source_token.mint, target_token.mint] .into_iter() .map(|mint| { util::to_writable_account_meta( - anchor_spl::associated_token::get_associated_token_address(&owner, &mint), + anchor_spl::associated_token::get_associated_token_address(&authority, &mint), ) }) .collect::>(); @@ -176,7 +176,7 @@ impl<'a> Sanctum<'a> { input: input_mint.to_string(), mode: "ExactIn".to_string(), output_lst_mint: output_mint.to_string(), - signer: owner.to_string(), + signer: authority.to_string(), swap_src: quote.swap_src.clone(), }) .timeout(self.timeout_duration) @@ -244,8 +244,8 @@ impl<'a> Sanctum<'a> { // Ensure the source token account is created (sanctum takes care of the output account) instructions.push( spl_associated_token_account::instruction::create_associated_token_account_idempotent( - &owner, - &owner, + &authority, + &authority, &source_token.mint, &Token::id(), ), @@ -257,7 +257,7 @@ impl<'a> Sanctum<'a> { let mut ams = anchor_lang::ToAccountMetas::to_account_metas( &mango_v4::accounts::FlashLoanBegin { account: self.mango_client.mango_account_address, - owner, + owner: authority, token_program: Token::id(), instructions: solana_sdk::sysvar::instructions::id(), }, @@ -284,7 +284,7 @@ impl<'a> Sanctum<'a> { let mut ams = anchor_lang::ToAccountMetas::to_account_metas( &mango_v4::accounts::FlashLoanEnd { account: self.mango_client.mango_account_address, - owner, + owner: authority, token_program: Token::id(), }, None, @@ -308,13 +308,13 @@ impl<'a> Sanctum<'a> { let mut address_lookup_tables = self.mango_client.mango_address_lookup_tables().await?; address_lookup_tables.extend(sanctum_alts.into_iter()); - let payer = owner; // maybe use fee_payer? but usually it's the same + let payer = authority; // maybe use fee_payer? but usually it's the same Ok(TransactionBuilder { instructions, address_lookup_tables, payer, - signers: vec![self.mango_client.owner.clone()], + signers: vec![self.mango_client.authority.clone()], config: self .mango_client .client