Code Monkey home page Code Monkey logo

Comments (5)

smye avatar smye commented on September 27, 2024 3

Never mind, I messed up some things myself. This example also works for v4!

Hey!

Glad you got it working 🙂

Will just leave what I think are the answers to your question below just in case anyone else finds them in the same situation:

  1. _data[4:] is for removing the function selector from the calldata returned by the 1inch API. The function selector determines what function is called

  2. V4 adds an extra return value spentAmount on the swap function:

    function swap(
            IAggregationExecutor caller,
            SwapDescription calldata desc,
            bytes calldata data
        )
            external
            payable
            returns (
                uint256 returnAmount,
                uint256 spentAmount,
                uint256 gasLeft
            )
        {

    So replace

     (uint returnAmount, uint gasLeft) = abi.decode(_data, (uint, uint));

    with

    (uint returnAmount, uint spentAmount, uint gasLeft) = abi.decode(_data, (uint, uint, uint));

from 1inch-swap.

RickVM avatar RickVM commented on September 27, 2024 1

Never mind, I messed up some things myself. This example also works for v4!

from 1inch-swap.

RickVM avatar RickVM commented on September 27, 2024 1
  1. V4 adds an extra return value spentAmount on the swap function:
    function swap(
            IAggregationExecutor caller,
            SwapDescription calldata desc,
            bytes calldata data
        )
            external
            payable
            returns (
                uint256 returnAmount,
                uint256 spentAmount,
                uint256 gasLeft
            )
        {

This is true for Ethereum but it seems 1inch has not updated this on Polygon and binance smart chain.
There, the old return parameters are still used

from 1inch-swap.

bmarcot avatar bmarcot commented on September 27, 2024

Never mind, I messed up some things myself. This example also works for v4!

Hey!

Glad you got it working 🙂

Will just leave what I think are the answers to your question below just in case anyone else finds them in the same situation:

  1. _data[4:] is for removing the function selector from the calldata returned by the 1inch API. The function selector determines what function is called

  2. V4 adds an extra return value spentAmount on the swap function:

    function swap(
            IAggregationExecutor caller,
            SwapDescription calldata desc,
            bytes calldata data
        )
            external
            payable
            returns (
                uint256 returnAmount,
                uint256 spentAmount,
                uint256 gasLeft
            )
        {

    So replace

     (uint returnAmount, uint gasLeft) = abi.decode(_data, (uint, uint));

    with

    (uint returnAmount, uint spentAmount, uint gasLeft) = abi.decode(_data, (uint, uint, uint));

Hey @smye, you assume the return type for swap() on V4 with extra spentAmount at positional arg. number 2. But 1inch docs for V4 says prototype is still the old V3 prototype. Can you confirm which is correct?

from 1inch-swap.

bmarcot avatar bmarcot commented on September 27, 2024

Never mind, I messed up some things myself. This example also works for v4!

Hey!
Glad you got it working 🙂
Will just leave what I think are the answers to your question below just in case anyone else finds them in the same situation:

  1. _data[4:] is for removing the function selector from the calldata returned by the 1inch API. The function selector determines what function is called

  2. V4 adds an extra return value spentAmount on the swap function:

    function swap(
            IAggregationExecutor caller,
            SwapDescription calldata desc,
            bytes calldata data
        )
            external
            payable
            returns (
                uint256 returnAmount,
                uint256 spentAmount,
                uint256 gasLeft
            )
        {

    So replace

     (uint returnAmount, uint gasLeft) = abi.decode(_data, (uint, uint));

    with

    (uint returnAmount, uint spentAmount, uint gasLeft) = abi.decode(_data, (uint, uint, uint));

Hey @smye, you assume the return type for swap() on V4 with extra spentAmount at positional arg. number 2. But 1inch docs for V4 says prototype is still the old V3 prototype. Can you confirm which is correct?

Nevermind, found it -- https://etherscan.io/address/0x1111111254fb6c44bac0bed2854e76f90643097d#code#L2319
Doc hasn't been updated.

from 1inch-swap.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.