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

Modify findTransitiveTransfer to call the pathfinder service #165

Merged
merged 46 commits into from
Mar 21, 2023

Conversation

llunaCreixent
Copy link
Member

@llunaCreixent llunaCreixent commented Feb 15, 2023

Closes #164

Modify the findTransitiveTransfer method to make request to the pathfinder service API instead of the circles-api.

The core constructor requires two new parameters: pathfinderServiceEndpoint and pathfinderType.

The format of the response of the pathfinder server has changed wrt the cli version. The pathfinder server output is:

{
  "jsonrpc": "2.0",
  "id": "875634786",
  "result": {
    "maxFlowValue": "2000000000000000000000",
    "final": true,
    "transferSteps": [
      {
        "from": "0x0001",
        "to": "0x0002",
        "token_owner": "0x0003",
        "value": "158277265717615256803"
      },
      {
        "from": "0x0001",
        "to": "0x0002",
        "token_owner": "0x0004",
        "value": "158277265717615256803"
      }
    ]
  }
}

While the cli output is:

{
  "status": "ok",
  "data": {
    "from": "0x0001",
    "to": "0x0002",
    "maxFlowValue": "2000000000000000000000",
    "processDuration": 74697,
    "transferValue": "2000000000000000000000",
    "transferSteps": [
      {
        "from": "0x0001",
        "to": "0x0002",
        "value": "158277265717615256803",
        "step": 0,
        "tokenOwnerAddress": "0x0003"
      },
      {
        "from": "0x0001",
        "to": "0x0002",
        "value": "158277265717615256803",
        "step": 1,
        "tokenOwnerAddress": "0x0004"
      }
    ]
  }
}

The optional parameters for the pathfinder compute_transfer method have changed: hops is not available anymore. max_transfers is used by the pathfinder service to try to remove individual transfers to stay below the limit, even if this results in less value being transferred.

Furthermore, the logic of token.transfer is improved by trying first a direct transfer with the token of the 'to' address, and if not possible then try with the token of the 'from' address.

Moreover, we adapted the tests to work with automatic block mining enabled (blockTime option in ganache): adding loops to wait for the data to be available in the blockchain.

The Token tests are parametrized to either deploy a core instance with the pathfinderType as cli or server.

While implementing this PR, I've found out something interesting: the checkSendLimit method of the core checks the sent limit of the token of the 'from' address, which is contradictory with the policy of "returning tokens to their owners". This method is only used by myxo when calculating maxFlow. I suggest we refactor the method to include the tokenOwner as param too. #168

Another discussion is whether the max_steps = 52 is too large. #166

Finally there is a possible issue to explore: if we transfer all the balance of a token that was supposed to be used for paying the relayer for the tx gas, would it generate an error? #167

@JacqueGM JacqueGM marked this pull request as ready for review February 27, 2023 15:54
juanenrisley
juanenrisley previously approved these changes Mar 20, 2023
Copy link
Collaborator

@juanenrisley juanenrisley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏿 💯

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.

create new method to interact with Pathfinder service
3 participants