-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFlash.sol
More file actions
39 lines (34 loc) · 1.53 KB
/
Flash.sol
File metadata and controls
39 lines (34 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import {RollupOrders} from "zenith/src/orders/RollupOrders.sol";
import {SignetL2} from "../Signet.sol";
/// @notice This contract provides a modifier that allows functions to
/// utilize liquidity only during the duration of a function.
abstract contract Flash is SignetL2 {
/// @notice This modifier enables a contract to access some amount only
/// during function execution - the amount is received by the
/// contract before the function executes, then is sent directly
/// back at the end.
///
/// This way, the function can utilize the liquidity during
/// transaction execution.
/// @param asset The address of the asset to be flash held.
/// @param amount The amount of the asset to be flash held.
modifier flash(address asset, uint256 amount) {
_;
_flash(asset, amount);
}
function _flash(address asset, uint256 amount) internal {
// Output is received *before* the modified function is called
RollupOrders.Output[] memory outputs = new RollupOrders.Output[](1);
outputs[0] = makeRollupOutput(asset, amount, address(this));
// Input is sent back after the modified function
RollupOrders.Input[] memory inputs = new RollupOrders.Input[](1);
inputs[0] = makeInput(asset, amount);
ORDERS.initiate(
block.timestamp, // this is equivalent to no deadline
inputs,
outputs
);
}
}