Rename MarginTrade -> FlashLoan

This commit is contained in:
Christian Kamm 2022-06-23 10:19:33 +02:00
parent d8a6a29e70
commit c8ebc1f611
8 changed files with 34 additions and 34 deletions

View File

@ -13,7 +13,7 @@ pub enum MangoError {
#[msg("")]
UnknownOracleType,
#[msg("")]
InvalidMarginTradeTargetCpiProgram,
InvalidFlashLoanTargetCpiProgram,
#[msg("")]
HealthMustBePositive,
#[msg("The account is bankrupt")]

View File

@ -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<u8>,
}
/// - `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<MarginTradeWithdraw>,
pub fn flash_loan<'key, 'accounts, 'remaining, 'info>(
ctx: Context<'key, 'accounts, 'remaining, 'info, FlashLoan<'info>>,
withdraws: Vec<FlashLoanWithdraw>,
cpi_datas: Vec<CpiData>,
) -> Result<()> {
require!(!cpi_datas.is_empty(), MangoError::SomeError);

View File

@ -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<MarginTradeWithdraw>,
pub fn flash_loan<'key, 'accounts, 'remaining, 'info>(
ctx: Context<'key, 'accounts, 'remaining, 'info, FlashLoan<'info>>,
withdraws: Vec<FlashLoanWithdraw>,
cpi_datas: Vec<CpiData>,
) -> Result<()> {
instructions::margin_trade(ctx, withdraws, cpi_datas)
instructions::flash_loan(ctx, withdraws, cpi_datas)
}
///

View File

@ -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<u8>,
}
#[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,
}],

View File

@ -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,

View File

@ -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({

View File

@ -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": ""
},
{

View File

@ -1,6 +1,6 @@
import { BN } from '@project-serum/anchor';
export class MarginTradeWithdraw {
export class FlashLoanWithdraw {
static index: number;
static amount: BN;
}