Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FillOrderTo 1inch Swap and Allowance Fix in FiberRouter #43

Merged
merged 3 commits into from Feb 20, 2024

Conversation

salmanferrum
Copy link
Contributor

@salmanferrum salmanferrum commented Feb 16, 2024

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.

@taha-abbasi taha-abbasi merged commit 989c561 into ferrumnet:develop Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants