flash loan: Add a "swap without fees" option (#882)

This commit is contained in:
Christian Kamm 2024-02-19 09:00:30 +01:00 committed by GitHub
parent 5d29eb2f0b
commit 8a3a3bf70b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 20 additions and 3 deletions

View File

@ -10580,6 +10580,9 @@
},
{
"name": "Swap"
},
{
"name": "SwapWithoutFee"
}
]
}

View File

@ -92,6 +92,12 @@ pub struct FlashLoanEnd<'info> {
#[derive(PartialEq, Copy, Clone, Debug, AnchorSerialize, AnchorDeserialize)]
#[repr(u8)]
pub enum FlashLoanType {
/// An arbitrary flash loan
Unknown,
/// A flash loan used for a swap where one token is exchanged for another.
///
/// Deposits in this type get charged the flash_loan_swap_fee_rate
Swap,
/// Like Swap, but without the flash_loan_swap_fee_rate
SwapWithoutFee,
}

View File

@ -378,10 +378,10 @@ pub fn flash_loan_end<'key, 'accounts, 'remaining, 'info>(
match flash_loan_type {
FlashLoanType::Unknown => {}
FlashLoanType::Swap => {
FlashLoanType::Swap | FlashLoanType::SwapWithoutFee => {
require_msg!(
changes.len() == 2,
"when flash_loan_type is Swap there must be exactly 2 token vault changes"
"when flash_loan_type is Swap or SwapWithoutFee there must be exactly 2 token vault changes"
)
}
}

View File

@ -10580,6 +10580,9 @@ export type MangoV4 = {
},
{
"name": "Swap"
},
{
"name": "SwapWithoutFee"
}
]
}
@ -24755,6 +24758,9 @@ export const IDL: MangoV4 = {
},
{
"name": "Swap"
},
{
"name": "SwapWithoutFee"
}
]
}

View File

@ -9,11 +9,13 @@ export class FlashLoanWithdraw {
export type FlashLoanType =
| { unknown: Record<string, never> }
| { swap: Record<string, never> };
| { swap: Record<string, never> }
| { swapWithoutFee: Record<string, never> };
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace FlashLoanType {
export const unknown = { unknown: {} };
export const swap = { swap: {} };
export const swapWithoutFee = { swapWithoutFee: {} };
}
export class InterestRateParams {