v1.8.0
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 fromFiberRouter
. - 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
tosendToken
inremoveLiquidityByManager
improves consistency in token handling and leverages the functionality provided by theTokenReceivable
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:
-
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.
- Implemented a new function,
-
Enhancements in
removeLiquidityByManager
:- Modified the
removeLiquidityByManager
function to utilize theTokenReceivable.sendToken
method directly, replacing the previous use ofsafeTransfer
. - Ensured the function continues to validate a positive amount and a valid token address before proceeding with liquidity removal.
- Modified the
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:
-
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.
-
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.
-
_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