From c8ebc1f611dff42ba80bffb667051c77c0783031 Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Thu, 23 Jun 2022 10:19:33 +0200 Subject: [PATCH] Rename MarginTrade -> FlashLoan --- programs/mango-v4/src/error.rs | 2 +- .../mango-v4/src/instructions/margin_trade.rs | 14 +++++++------- programs/mango-v4/src/lib.rs | 8 ++++---- .../mango-v4/tests/program_test/mango_client.rs | 12 ++++++------ programs/mango-v4/tests/test_margin_trade.rs | 8 ++++---- ts/client/src/client.ts | 6 +++--- ts/client/src/mango_v4.ts | 16 ++++++++-------- ts/client/src/types.ts | 2 +- 8 files changed, 34 insertions(+), 34 deletions(-) diff --git a/programs/mango-v4/src/error.rs b/programs/mango-v4/src/error.rs index 732bc0422..50c1529a0 100644 --- a/programs/mango-v4/src/error.rs +++ b/programs/mango-v4/src/error.rs @@ -13,7 +13,7 @@ pub enum MangoError { #[msg("")] UnknownOracleType, #[msg("")] - InvalidMarginTradeTargetCpiProgram, + InvalidFlashLoanTargetCpiProgram, #[msg("")] HealthMustBePositive, #[msg("The account is bankrupt")] diff --git a/programs/mango-v4/src/instructions/margin_trade.rs b/programs/mango-v4/src/instructions/margin_trade.rs index c41debd57..a53f205e3 100644 --- a/programs/mango-v4/src/instructions/margin_trade.rs +++ b/programs/mango-v4/src/instructions/margin_trade.rs @@ -9,7 +9,7 @@ use solana_program::instruction::Instruction; use std::cell::Ref; use std::collections::HashMap; -/// The margin trade instruction +/// The flash loan instruction /// /// In addition to these accounts, there must be a sequence of remaining_accounts: /// 1. health_accounts: accounts needed for health checking @@ -22,7 +22,7 @@ use std::collections::HashMap; /// Every vault that is to be withdrawn from must appear in the `withdraws` instruction argument. /// The corresponding bank may be used as an authority for vault withdrawals. #[derive(Accounts)] -pub struct MarginTrade<'info> { +pub struct FlashLoan<'info> { pub group: AccountLoader<'info, Group>, #[account( @@ -52,7 +52,7 @@ struct AllowedVault { } #[derive(AnchorDeserialize, AnchorSerialize, Clone, Copy)] -pub struct MarginTradeWithdraw { +pub struct FlashLoanWithdraw { /// Account index of the vault to withdraw from in the target_accounts section. /// Meaning that the first account after target_program_id would have index 0. pub index: u8, @@ -66,12 +66,12 @@ pub struct CpiData { pub data: Vec, } -/// - `withdraws` is a list of MarginTradeWithdraw requests. +/// - `withdraws` is a list of FlashLoanWithdraw requests. /// - `cpi_datas` is a list of bytes per cpi to call the target_program_id with. /// - `cpi_account_starts` is a list of index into the remaining accounts per cpi to call the target_program_id with. -pub fn margin_trade<'key, 'accounts, 'remaining, 'info>( - ctx: Context<'key, 'accounts, 'remaining, 'info, MarginTrade<'info>>, - withdraws: Vec, +pub fn flash_loan<'key, 'accounts, 'remaining, 'info>( + ctx: Context<'key, 'accounts, 'remaining, 'info, FlashLoan<'info>>, + withdraws: Vec, cpi_datas: Vec, ) -> Result<()> { require!(!cpi_datas.is_empty(), MangoError::SomeError); diff --git a/programs/mango-v4/src/lib.rs b/programs/mango-v4/src/lib.rs index d3c9c1181..cb571ff48 100644 --- a/programs/mango-v4/src/lib.rs +++ b/programs/mango-v4/src/lib.rs @@ -120,12 +120,12 @@ pub mod mango_v4 { instructions::token_withdraw(ctx, amount, allow_borrow) } - pub fn margin_trade<'key, 'accounts, 'remaining, 'info>( - ctx: Context<'key, 'accounts, 'remaining, 'info, MarginTrade<'info>>, - withdraws: Vec, + pub fn flash_loan<'key, 'accounts, 'remaining, 'info>( + ctx: Context<'key, 'accounts, 'remaining, 'info, FlashLoan<'info>>, + withdraws: Vec, cpi_datas: Vec, ) -> Result<()> { - instructions::margin_trade(ctx, withdraws, cpi_datas) + instructions::flash_loan(ctx, withdraws, cpi_datas) } /// diff --git a/programs/mango-v4/tests/program_test/mango_client.rs b/programs/mango-v4/tests/program_test/mango_client.rs index 185c988eb..f38bf43e1 100644 --- a/programs/mango-v4/tests/program_test/mango_client.rs +++ b/programs/mango-v4/tests/program_test/mango_client.rs @@ -6,7 +6,7 @@ use anchor_spl::token::{Token, TokenAccount}; use fixed::types::I80F48; use itertools::Itertools; use mango_v4::instructions::{ - CpiData, InterestRateParams, MarginTradeWithdraw, Serum3OrderType, Serum3SelfTradeBehavior, + CpiData, InterestRateParams, FlashLoanWithdraw, Serum3OrderType, Serum3SelfTradeBehavior, Serum3Side, }; use solana_program::instruction::Instruction; @@ -279,7 +279,7 @@ pub async fn account_position_f64(solana: &SolanaCookie, account: Pubkey, bank: // ClientInstruction impl // -pub struct MarginTradeInstruction<'keypair> { +pub struct FlashLoanInstruction<'keypair> { pub account: Pubkey, pub owner: &'keypair Keypair, pub mango_token_bank: Pubkey, @@ -291,9 +291,9 @@ pub struct MarginTradeInstruction<'keypair> { pub margin_trade_program_ix_cpi_data: Vec, } #[async_trait::async_trait(?Send)] -impl<'keypair> ClientInstruction for MarginTradeInstruction<'keypair> { - type Accounts = mango_v4::accounts::MarginTrade; - type Instruction = mango_v4::instruction::MarginTrade; +impl<'keypair> ClientInstruction for FlashLoanInstruction<'keypair> { + type Accounts = mango_v4::accounts::FlashLoan; + type Instruction = mango_v4::instruction::FlashLoan; async fn to_instruction( &self, account_loader: impl ClientAccountLoader + 'async_trait, @@ -319,7 +319,7 @@ impl<'keypair> ClientInstruction for MarginTradeInstruction<'keypair> { .await; let instruction = Self::Instruction { - withdraws: vec![MarginTradeWithdraw { + withdraws: vec![FlashLoanWithdraw { index: 1, amount: self.withdraw_amount, }], diff --git a/programs/mango-v4/tests/test_margin_trade.rs b/programs/mango-v4/tests/test_margin_trade.rs index e454077d5..6ed15fe9e 100644 --- a/programs/mango-v4/tests/test_margin_trade.rs +++ b/programs/mango-v4/tests/test_margin_trade.rs @@ -143,7 +143,7 @@ async fn test_margin_trade() -> Result<(), BanksClientError> { { send_tx( solana, - MarginTradeInstruction { + FlashLoanInstruction { account, owner, mango_token_bank: bank, @@ -193,7 +193,7 @@ async fn test_margin_trade() -> Result<(), BanksClientError> { { send_tx( solana, - MarginTradeInstruction { + FlashLoanInstruction { account, owner, mango_token_bank: bank, @@ -237,7 +237,7 @@ async fn test_margin_trade() -> Result<(), BanksClientError> { { send_tx( solana, - MarginTradeInstruction { + FlashLoanInstruction { account, owner, mango_token_bank: bank, @@ -283,7 +283,7 @@ async fn test_margin_trade() -> Result<(), BanksClientError> { { send_tx( solana, - MarginTradeInstruction { + FlashLoanInstruction { account, owner, mango_token_bank: bank, diff --git a/ts/client/src/client.ts b/ts/client/src/client.ts index f1583e52e..80967ccbb 100644 --- a/ts/client/src/client.ts +++ b/ts/client/src/client.ts @@ -41,7 +41,7 @@ import { ORCA_TOKEN_SWAP_ID_DEVNET, } from './integrations/orca/index'; import { IDL, MangoV4 } from './mango_v4'; -import { MarginTradeWithdraw } from './types'; +import { FlashLoanWithdraw } from './types'; import { getAssociatedTokenAddress, I64_MAX_BN, @@ -1146,13 +1146,13 @@ export class MangoClient { ); const targetRemainingAccounts = instruction.keys; - const withdraws: MarginTradeWithdraw[] = [ + const withdraws: FlashLoanWithdraw[] = [ { index: 3, amount: toU64(amountIn, 9) }, ]; const cpiData = instruction.data; return await this.program.methods - .marginTrade(withdraws, [ + .flashLoan(withdraws, [ { accountStart: new BN(parsedHealthAccounts.length), data: cpiData }, ]) .accounts({ diff --git a/ts/client/src/mango_v4.ts b/ts/client/src/mango_v4.ts index 88a3c4d4d..bed329b4d 100644 --- a/ts/client/src/mango_v4.ts +++ b/ts/client/src/mango_v4.ts @@ -616,7 +616,7 @@ export type MangoV4 = { ] }, { - "name": "marginTrade", + "name": "flashLoan", "accounts": [ { "name": "group", @@ -644,7 +644,7 @@ export type MangoV4 = { "name": "withdraws", "type": { "vec": { - "defined": "MarginTradeWithdraw" + "defined": "FlashLoanWithdraw" } } }, @@ -2577,7 +2577,7 @@ export type MangoV4 = { ], "types": [ { - "name": "MarginTradeWithdraw", + "name": "FlashLoanWithdraw", "type": { "kind": "struct", "fields": [ @@ -3274,7 +3274,7 @@ export type MangoV4 = { }, { "code": 6004, - "name": "InvalidMarginTradeTargetCpiProgram", + "name": "InvalidFlashLoanTargetCpiProgram", "msg": "" }, { @@ -3908,7 +3908,7 @@ export const IDL: MangoV4 = { ] }, { - "name": "marginTrade", + "name": "flashLoan", "accounts": [ { "name": "group", @@ -3936,7 +3936,7 @@ export const IDL: MangoV4 = { "name": "withdraws", "type": { "vec": { - "defined": "MarginTradeWithdraw" + "defined": "FlashLoanWithdraw" } } }, @@ -5869,7 +5869,7 @@ export const IDL: MangoV4 = { ], "types": [ { - "name": "MarginTradeWithdraw", + "name": "FlashLoanWithdraw", "type": { "kind": "struct", "fields": [ @@ -6566,7 +6566,7 @@ export const IDL: MangoV4 = { }, { "code": 6004, - "name": "InvalidMarginTradeTargetCpiProgram", + "name": "InvalidFlashLoanTargetCpiProgram", "msg": "" }, { diff --git a/ts/client/src/types.ts b/ts/client/src/types.ts index d01c35b14..b0e599fad 100644 --- a/ts/client/src/types.ts +++ b/ts/client/src/types.ts @@ -1,6 +1,6 @@ import { BN } from '@project-serum/anchor'; -export class MarginTradeWithdraw { +export class FlashLoanWithdraw { static index: number; static amount: BN; }