Skip to content

Commit

Permalink
updates docs
Browse files Browse the repository at this point in the history
  • Loading branch information
0xDEnYO committed May 20, 2024
1 parent 4ad5ed9 commit 95d888c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
16 changes: 8 additions & 8 deletions docs/GenericSwapFacetV3.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Generic Swap Facet
# GenericSwapFacetV3

## How it works

The Generic Swap Facet is used to make single swaps or multiple same-chain swaps in a single transaction. It will send the result of the (final) swap to the receiver.

It does this by using the [LibSwap](./LibSwap.md) library.
The GenericSwapFacetV3 is a gas-optimized new version of the GenericSwapFacet and offers the same functionality as its predecessor: executing single swaps or multiple same-chain swaps in a single transaction.
It will send the result of the (final) swap to the specified receiver address.
New in this version is that in cases where a DEX does not pull/use all of the inputTokens for a swap (positive slippage), these tokens will be sent to the receiver address.

```mermaid
graph LR;
D{LiFiDiamond}-- DELEGATECALL -->GenericSwapFacet;
GenericSwapFacet -- SWAPs --> GenericSwapFacet
GenericSwapFacet -- withdraw --> USER
D{LiFiDiamond}-- DELEGATECALL -->GenericSwapFacetV3;
GenericSwapFacetV3 -- SWAPs --> GenericSwapFacetV3
GenericSwapFacetV3 -- withdraw --> USER
```

## Public Methods
Expand Down Expand Up @@ -38,6 +38,6 @@ graph LR;

Some methods accept a `SwapData _swapData` parameter.

Swapping is performed by a swap specific library that expects an array of calldata to can be run on various DEXs (i.e. Uniswap) to make one or multiple swaps before performing another action.
This parameter is defined in the following library:

The swap library can be found [here](../src/Libraries/LibSwap.sol).
2 changes: 1 addition & 1 deletion src/Facets/GenericSwapFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Validatable } from "../Helpers/Validatable.sol";
import { LibUtil } from "../Libraries/LibUtil.sol";
import { InvalidReceiver } from "../Errors/GenericErrors.sol";

/// @title Generic Swap Facet
/// @title GenericSwapFacet
/// @author LI.FI (https://li.fi)
/// @notice Provides functionality for swapping through ANY APPROVED DEX
/// @dev Uses calldata to execute APPROVED arbitrary methods on DEXs
Expand Down
6 changes: 5 additions & 1 deletion test/solidity/utils/MockUniswapDEX.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ pragma solidity 0.8.17;
import { InsufficientBalance } from "lifi/Errors/GenericErrors.sol";
import { ERC20, SafeTransferLib } from "solmate/utils/SafeTransferLib.sol";

// this contract is used for testing purposes and mocks the behaviour of a Uniswap-like DEX
// it has two main functionalities:
// 1) pull a specified amount of the input token (for testing of cases where not all inputTokens are used by a DEX)
// 2) return any token/amount combination to the receiver address as specificied prior to the call
contract MockUniswapDEX {
using SafeTransferLib for ERC20;

Expand Down Expand Up @@ -56,7 +60,7 @@ contract MockUniswapDEX {
}

// this function will:
// - return preset the 'outputAmount' of 'outputToken' to the receiver (to)
// - return the preset 'outputAmount' of 'outputToken' to the receiver (to)
function swapExactTokensForTokens(
uint256,
uint256 amountInMax,
Expand Down

0 comments on commit 95d888c

Please sign in to comment.