You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 11, 2025. It is now read-only.
/// Must match the reserve liquidity fee receiver.
25
+
/// 8. `[writable]` Host fee receiver.
26
+
/// .. `[any]` Additional accounts expected by the receiving program's `ReceiveFlashLoan` instruction.
27
+
FlashLoan {
28
+
/// The amount that is to be borrowed
29
+
amount:u64,
30
+
},
31
+
}
32
+
```
33
+
34
+
In the implementation, we do the following in order:
35
+
36
+
1. Perform safety checks and calculate fees
37
+
2. Transfer `amount` from the source liquidity account to the destination liquidity account
38
+
2. Call the `ReceiveFlashLoan` function (the flash loan receiver program is required to have this function with tag `0`).
39
+
The additional account required for `ReceiveFlashLoan` is given from the 10th account of the `FlashLoan` instruction, i.e. after host fee receiver.
40
+
3. Check that the returned amount with the fee is in the reserve account after the completion of `ReceiveFlashLoan` function.
41
+
42
+
The flash loan receiver program should have a `ReceiveFlashLoan` instruction which executes the user-defined operation and return the funds to the reserve in the end.
43
+
44
+
```rust
45
+
pubenumFlashLoanReceiverInstruction {
46
+
47
+
/// Receive a flash loan and perform user-defined operation and finally return the fund back.
48
+
///
49
+
/// Accounts expected:
50
+
///
51
+
/// 0. `[writable]` Source liquidity (matching the destination from above).
52
+
/// 1. `[writable]` Destination liquidity (matching the source from above).
53
+
/// 2. `[]` Token program id
54
+
/// .. `[any]` Additional accounts provided to the lending program's `FlashLoan` instruction above.
55
+
ReceiveFlashLoan {
56
+
// Amount that is loaned to the receiver program
57
+
amount:u64
58
+
}
59
+
}
60
+
61
+
```
62
+
63
+
You can view a sample implementation [here](https://github.com/solana-labs/solana-program-library/tree/master/token-lending/program/tests/helpers/flash_loan_receiver.rs).
0 commit comments