-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4849008
commit 7a9ff04
Showing
1 changed file
with
62 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,86 @@ | ||
## Foundry | ||
# AutoSwapV3 | ||
|
||
**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.** | ||
This repository contains an **LSP1-UniversalReceiverDelegate** contract designed for automatic token swaps on transfers using Uniswap V3-based protocol (UniversalSwaps). | ||
|
||
Foundry consists of: | ||
> This is an educational project and only for test purposes. Still a work in progress and is being tested with different configs. | ||
- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools). | ||
- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data. | ||
- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network. | ||
- **Chisel**: Fast, utilitarian, and verbose solidity REPL. | ||
## Overview | ||
|
||
## Documentation | ||
The AutoSwapV3 contract is specifically designed to work with LSP7-DigitalAsset tokens, not ERC20 tokens. This is because ERC20 lacks the ability to inform the recipient about the transfer, preventing the recipient from deciding how to react to it. With LSP7, recipient can be notified about the transfers, and then can delegate the reaction to external contracts that decides how to react on transfer. In this case, users will use the `AutoSwapV3` contract. | ||
|
||
https://book.getfoundry.sh/ | ||
## Key Features | ||
|
||
## Usage | ||
- Automatic token swaps on transfer | ||
- Works with LSP7-DigitalAsset tokens | ||
- Works with UniversalSwapsV3 | ||
|
||
### Build | ||
## Setup | ||
|
||
```shell | ||
$ forge build | ||
``` | ||
This contract needs to be set as the **UniversalReceiverDelegate** for a Universal Profile and should be given the necessary permissions to execute from this profile. In the case of ownership via **LSP6-KeyManager**, it should be given **SUPER_CALL** and **REENTRANCY** permissions. | ||
|
||
### Test | ||
## Oracle Integration | ||
|
||
```shell | ||
$ forge test | ||
``` | ||
The AutoSwapV3 contract should include an oracle that feeds the minimum amount of tokens that the user is willing to receive. This amount should be reasonable based on a preferred deviation to protect against sandwich attacks. | ||
|
||
## Flow Diagram | ||
|
||
### Format | ||
The following diagram illustrates the flow of a token transfer and automatic swap: | ||
|
||
```shell | ||
$ forge fmt | ||
```mermaid | ||
sequenceDiagram | ||
participant User | ||
participant TokenA as Token A Contract | ||
participant UP as Universal Profile | ||
participant AutoSwapV3 | ||
participant UR as Universal Router | ||
User->>TokenA: Call transfer function | ||
TokenA->>UP: Inform about transfer | ||
UP->>AutoSwapV3: Inform about transfer | ||
AutoSwapV3->>UP: UP call to the token to start the swap | ||
UP->>TokenA: Call to Authorize the Universal Router | ||
TokenA->>UR: Authorize the token of the profile for a swap | ||
UR->>UR: Execute the Swap | ||
UR->>TokenA: Return swap result | ||
TokenA->>UP: Return result | ||
UP->>AutoSwapV3: Return result | ||
AutoSwapV3->>UP: Finalize swap | ||
``` | ||
|
||
### Gas Snapshots | ||
1. User calls the transfer function on Token A | ||
2. Token A informs the recipient's Universal Profile about the transfer | ||
3. The Universal Profile informs AutoSwapV3 about the transfer | ||
4. AutoSwapV3 calls the Universal Profile to authorize the swap | ||
5. The Universal Profile calls authorizeOperator on the token contract | ||
6. The token contract authorize the UniversalRouter and the authorization data contain the logic for the swap | ||
7. The swap result is returned through the chain of contracts back to AutoSwapV3 and the UniversalProfile | ||
|
||
```shell | ||
$ forge snapshot | ||
``` | ||
## Usage | ||
|
||
### Anvil | ||
To use the AutoSwapV3 contract: | ||
|
||
```shell | ||
$ anvil | ||
``` | ||
1. Deploy the `AutoSwapV3` contract | ||
2. Set it as the `UniversalReceiverDelegate` for your Universal Profile | ||
3. Grant necessary permissions (`SUPER_CALL` and `REENTRANCY`) if using LSP6-KeyManager | ||
4. Configure minimum swap amounts for each token | ||
|
||
### Deploy | ||
## Usage | ||
|
||
```shell | ||
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key> | ||
``` | ||
### Build | ||
|
||
### Cast | ||
```sh | ||
$ forge build | ||
``` | ||
### Gas Snapshots | ||
|
||
```shell | ||
$ cast <subcommand> | ||
```sh | ||
$ forge snapshot | ||
``` | ||
|
||
### Help | ||
## Contributing | ||
|
||
```shell | ||
$ forge --help | ||
$ anvil --help | ||
$ cast --help | ||
``` | ||
Contributions are welcome! Please feel free to submit a Pull Request. | ||
|
||
## License | ||
|
||
[MIT License](LICENSE) |