Skip to content

v1.6.0

Compare
Choose a tag to compare
@taha-abbasi taha-abbasi released this 20 Feb 04:50
· 145 commits to main since this release

What's Changed

  • MultiSwapForge Contracts for GasEstimation by @salmanferrum in #42
  • FillOrderTo 1inch Swap and Allowance Fix in FiberRouter by @salmanferrum in #43

Overview

This pull request introduces enhancements and new features to the FiberRouter smart contract, along with updates to its dependencies (OneInchSwap and OneInchDecoder contracts). The primary focus is on facilitating and optimizing the execution of the fillOrderTo operation involving the 1inch aggregator to accommodate new token swaps. Moreover, to resolve the allowance issue, the allowance check condition is added.

Changes Introduced

1. handleFillOrderTo Function (In FiberRouter)

  • The new function handleFillOrderTo has been introduced to streamline the execution of the fillOrderTo operation.
  • This function enables the swapping of new tokens, incorporates validations, and interacts seamlessly with the 1inch aggregator router.

2. Updates in Dependencies

  • OneInchSwap Contract:

    • The fillOrderTo function in the OneInchSwap contract has been updated to align with the changes in FiberRouter.
    • The updates ensure compatibility and extended functionality for 1inch swap operations.
  • OneInchDecoder Contract:

    • The decodeFillOrderTo function has been introduced to decode data related to the fillOrderTo operation.
    • This function extracts relevant parameters, including the order, signature, interaction, and more.

3. Resolved SafeERC20 Allowance Issue:**

To address the "execution reverted: SafeERC20: approve from non-zero to non-zero allowance" error encountered during swaps, the following condition has been added in both the withdrawSignedAndSwapOneInch and _swapAndCrossOneInch functions of FiberRouter.

// Check if allowance is non-zero
if (IERC20(foundryToken).allowance(address(this), oneInchAggregatorRouter) != 0) {
    // Reset it to zero
    IERC20(foundryToken).safeApprove(oneInchAggregatorRouter, 0);
}
// Set the allowance to the swap amount
IERC20(foundryToken).safeApprove(oneInchAggregatorRouter, amountIn);

This modification ensures that the allowance is appropriately managed, avoiding the mentioned error during token swaps on the 1inch aggregator. The contract now resets the allowance to zero before setting it to the intended swap amount, ensuring a seamless and error-free execution of swaps.

4. Testing Scripts Added

  • For deploying the contracts all at once, a new deploy script is created deployContracts.js
  • For getting the 1inch swap data response, oneInchAPI.js is added
  • For verifying the correct signer from a signature / msgHash combination, verifySigner.js is added
  • For generating withdrawal signature & testing the withdraw functions, withdrawSigned.js script is modified

Additional Notes

This pull request brings significant improvements to the FiberRouter contract, enhancing its capabilities in handling 1inch aggregator swaps and providing a more reliable and efficient trading experience for users. The combination of new features, dependency updates, and issue resolution contributes to the overall robustness and functionality of MultiSwap.

Summary of Additional Key Changes

This release refines the contract architecture to incorporate gas estimation functionality and segregate production contracts from gas estimation contracts. The notable changes include:

  • MultiSwapForge: Inherited from FiberRouter contract to simulate withdrawals with gas estimation, featuring estimateGasForWithdrawSigned and estimateGasForWithdrawSignedAndSwapOneInch functions.
  • ForgeFundManager: A forgeFundManager gas estimation contract inherited from FundManager with a hardcoded signer for generating forge signatures.
  • Changed the visibility modifier of FiberRouter'swithdrawSigned & withdrawSignedSwapAndCrossOneInch to public virtual
  • Changed the visibility modifier of FundManager's AddSigner function to public

These changes enhance gas estimation capabilities, ensuring more precise simulations and separating gas estimation logic from production transactions.

Full Changelog: v1.5.0...v1.6.0