Skip to content

v1.8.0

Compare
Choose a tag to compare
@taha-abbasi taha-abbasi released this 04 Apr 18:38
· 120 commits to main since this release

What's Changed

  • MultiSwap Gas Optimisation & Improvements by @salmanferrum in #45

Changes Proposed

This PR introduces a significant improvement to the gas efficiency of our system. The 1inchDecoder smart contract has been moved to the backend, and its functionality to decode the name of the function to be called on 1inch is now integrated into the swapHelperForOneInch function. The swapHelperForOneInch function now takes an enum parameter, representing the function to be called on 1inch.

1inch Decoder Context

The primary motivation behind this change is to enhance gas efficiency by eliminating the need for a separate smart contract (1inchDecoder) on the blockchain. By moving the decoding logic to the backend, we can reduce gas costs and improve overall system performance.

1inch Changes Overview

  • 1inchDecoder Removal: The 1inchDecoder smart contract has been removed from FiberRouter.
  • Function Name Decoding: The decoding logic for 1inch function names is now handled in the backend and a parameter funcSelector is passed to the swap or withdrawal functions.
  • Enum Parameter: The swapHelperForOneInch function now takes an enum parameter to identify the specific function to be called on 1inch.

Change Regarding LiquidityManagerRole / TokenReceivable

Background:

The changes were prompted by an issue identified in the TokenReceivable contract. Specifically, when attempting to remove liquidity using removeLiquidityByManager, the existing implementation with safeTransfer caused discrepancies in the token inventory and causing the transaction to fail.

Root Cause:

The discrepancy arose from a mismatch between how tokens were removed (using safeTransfer) in the LiquidityManagerRole contract and how the inventory was updated in the TokenReceivable contract. The absence of proper synchronization led to negative balances during subsequent calls to TokenReceivable.sync.

Resolution:

To address this, we introduced the addLiquidityByManager function, which utilizes the TokenReceivable.sendToken method for secure token transfers. This ensures consistency in token handling and updates the inventory using the TokenReceivable.sync method.

Similarly, in removeLiquidityByManager, the direct use of TokenReceivable.sendToken was introduced, providing a unified approach for managing token transfers and updating the inventory.

Additional Context:

  • The adjustment from safeTransfer to sendToken in removeLiquidityByManager improves consistency in token handling and leverages the functionality provided by the TokenReceivable library.
  • The addition of the addLiquidityByManager function enriches the contract's feature set, allowing liquidity managers to contribute assets in a controlled manner.

Changes Made:

  1. Introduction of addLiquidityByManager Function:

    • Implemented a new function, addLiquidityByManager, empowering designated liquidity managers to add a specified amount of liquidity for a given token.
    • This addition enhances the contract's flexibility by allowing controlled liquidity addition while ensuring secure token transfers to the FundManager contract. The inventory is also updated using the TokenReceivable.sync method.
  2. Enhancements in removeLiquidityByManager:

    • Modified the removeLiquidityByManager function to utilize the TokenReceivable.sendToken method directly, replacing the previous use of safeTransfer.
    • Ensured the function continues to validate a positive amount and a valid token address before proceeding with liquidity removal.

Same Network Swap Feature

This PR introduces new functionalities to the fiberRouter contract to enable same network token swaps on MultiSwap. The following key functions have been added:

  1. swapOnSameNetwork: This external function allows users to perform token swaps between two tokens on the same network using 1inch exchange. It takes parameters such as input amount, output amount, source token, target token, target address, and 1inch swap data.

  2. swapOnSameNetworkETH: Another external function introduced to enable swaps between native currency and a desired token on the same network. Users can swap native currency (ETH) to a target token using 1inch exchange. Parameters include output amount, target token, target address, and 1inch swap data.

  3. _swapOnSameNetwork: An internal function called within the above two functions to execute the token swaps using 1inch helper functions in fiberRouter.

These functions enhance the usability and flexibility of the fiberRouter contract by providing seamless token swapping capabilities within the same network using the powerful 1inch exchange.

Full Changelog: v1.7.1...v1.8.0