Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bringing in the spec and the interface #40

Merged
merged 19 commits into from
Apr 23, 2024
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
[submodule "lib/erc3156"]
path = lib/erc3156
url = https://github.com/alcueca/erc3156
[submodule "lib/erc7399"]
path = lib/erc7399
url = https://github.com/alcueca/erc7399
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/openzeppelin/openzeppelin-contracts
Expand Down
39 changes: 36 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# ERC7399 Flash Lender Wrappers

This repository contains contracts that work as
[ERC7399](https://github.com/ethereum/EIPs/blob/d072207e24e3cc12b6315909e6a65275a38e1984/EIPS/eip-7399.md) entry points
for popular flash lenders.
This repository contains contracts that work as [ERC7399](https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7399.md)
entry points for popular flash lenders.

## How Do These Wrappers Work

Expand Down Expand Up @@ -87,6 +86,40 @@ gnosisSafeWrapperFactory.disableLendAll();
...
```

## Gnosis Safe Wrapper

The [Gnosis Safe Wrapper](src/gnosissafe/GnosisSafeWrapper.sol) is intended for individual users to flash lend their own
assets held in a Gnosis Safe and earn a fee. To enable it, from your own Gnosis Safe, execute a transaction bundle to
enable the GnosisSafeWrapperFactory and set the fees for individual assets.

```
safe.enableModule(gnosisSafeWrapperFactory);
gnosisSafeWrapperFactory.lend(asset, fee);
...
```

or an override to lend all assets in the safe:

```
safe.enableModule(gnosisSafeWrapperFactory);
gnosisSafeWrapperFactory.lendAll(fee);
...
```

The `fee` parameter can be zero for free flash loans. To disable lending, execute from your safe the following command:

```
gnosisSafeWrapperFactory.disableLend(asset);
...
```

If you set a lending override, you can disable it to go back to individual asset configuration:

```
gnosisSafeWrapperFactory.disableLendAll();
...
```

## Flash Loans

For detail on executing flash loans, please refer to the
Expand Down
1 change: 0 additions & 1 deletion lib/erc7399
Submodule erc7399 deleted from 501ffd
2 changes: 1 addition & 1 deletion src/BaseWrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Thanks to ultrasecr.eth
pragma solidity ^0.8.19;

import "erc7399/IERC7399.sol";
import { IERC7399 } from "./interfaces/IERC7399.sol";

import { IERC20Metadata as IERC20 } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
Expand Down
44 changes: 44 additions & 0 deletions src/interfaces/IERC7399.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-License-Identifier: CC0
pragma solidity >=0.8.19;

/// @dev Specification for flash lenders compatible with ERC-7399
interface IERC7399 {
/// @dev The amount of currency available to be lent.
/// @param asset The loan currency.
/// @return The amount of `asset` that can be borrowed.
function maxFlashLoan(address asset) external view returns (uint256);

/// @dev The fee to be charged for a given loan.
/// @param asset The loan currency.
/// @param amount The amount of assets lent.
/// @return The amount of `asset` to be charged for the loan, on top of the returned principal.
function flashFee(address asset, uint256 amount) external view returns (uint256);

/// @dev Initiate a flash loan.
/// @param loanReceiver The address receiving the flash loan
/// @param asset The asset to be loaned
/// @param amount The amount to loaned
/// @param data The ABI encoded user data
/// @param callback The address and signature of the callback function
/// @return result ABI encoded result of the callback
function flash(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add the vyper compatible function?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want, be my guest.

address loanReceiver,
address asset,
uint256 amount,
bytes calldata data,
/// @dev callback. This is a combination of the callback receiver address, and the signature of callback
/// function. It is encoded packed as 20 bytes + 4 bytes.
/// @dev the return of the callback function is not encoded in the parameter, but must be `returns (bytes
/// memory)` for compliance with the standard.
/// @param initiator The address that called this function
/// @param paymentReceiver The address that needs to receive the amount plus fee at the end of the callback
/// @param asset The asset to be loaned
/// @param amount The amount to loaned
/// @param fee The fee to be paid
/// @param data The ABI encoded data to be passed to the callback
/// @return result ABI encoded result of the callback
function(address, address, address, uint256, uint256, bytes memory) external returns (bytes memory) callback
)
external
returns (bytes memory);
}
2 changes: 1 addition & 1 deletion test/MockBorrower.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import "erc7399/IERC7399.sol";
import "../src/interfaces/IERC7399.sol";
import "src/BaseWrapper.sol";
import { GasSnapshot } from "forge-gas-snapshot/GasSnapshot.sol";

Expand Down
Loading