Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Add transfer simulator and reorder Exchange transfers #1868

Merged
merged 9 commits into from
Jun 21, 2019

Conversation

abandeali1
Copy link
Member

Description

  • Adds MixinTransferSimulator, which performs a series of transfers and then always reverts. Example usage can be found in OrderTransferSimulationUtils.
  • Adds OrderTransferSimulationUtils, which allows batch order transfer simulations.
  • Reorders transfers in fillOrder and matchOrders such that the maker can spend the takerAsset and such that both the maker/taker can spend received assets on fees.
    -Removes some redundant checks done before transfers. dispatchTransferFrom will already not perform a transfer if from == to.

Testing instructions

Types of changes

Checklist:

  • Prefix PR title with [WIP] if necessary.
  • Add tests to cover changes as needed.
  • Update documentation as needed.
  • Add new entries to the relevant CHANGELOG.jsons.

@coveralls
Copy link

coveralls commented Jun 17, 2019

Coverage Status

Coverage remained the same at 78.262% when pulling b59145e on feat/3.0/transferSimulator into 123be92 on 3.0.

Copy link
Contributor

@dorothy-zbornak dorothy-zbornak left a comment

Choose a reason for hiding this comment

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

Just one slight oversight in the tests, but looks great!

@@ -418,6 +382,167 @@ describe('Exchange core', () => {
});
});

describe.only('Fill transfer ordering', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
describe.only('Fill transfer ordering', () => {
describe('Fill transfer ordering', () => {

@abandeali1 abandeali1 force-pushed the feat/3.0/transferSimulator branch from 7191d76 to 8b2f64a Compare June 18, 2019 15:57
@abandeali1 abandeali1 force-pushed the feat/3.0/transferSimulator branch from 8b2f64a to e959dd1 Compare June 21, 2019 16:23
Copy link
Contributor

@hysz hysz left a comment

Choose a reason for hiding this comment

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

Clever! A few minor nits and questions, but looks great. +1

} else if (keccak256(returnData) == _TRANSFERS_SUCCESSFUL_RESULT_HASH) {
// All transfers were successful
return OrderTransferResults.TransfersSuccessful;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit - it could be good to add a catch-all else here to show that we've considered all cases + for future-proofing.

{
uint256 length = assetData.length;
for (uint256 i = 0; i != length; i++) {
_dispatchTransferFrom(
Copy link
Contributor

Choose a reason for hiding this comment

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

Somewhere it may be helpful to note that passing in the index as the order hash is not simply filler, but necessary for getSimulatedOrderTransferResults to retrieve the index of the failed transfer.

@@ -336,39 +335,34 @@ contract MixinMatchOrders is
) {
// Fee recipients and taker fee assets are identical, so we can
// transfer them in one go.
if (takerAddress != leftFeeRecipientAddress) {
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 RIP

/// As they would occur through the Exchange contract. Note that this function
/// will always revert, even if all transfers are successful. However, it may
/// be used with eth_call or with a try/catch pattern in order to simulate
/// the results of the transfers.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is an interesting design pattern. Why is this better than reverting only when there is an error?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we would need a way to detect we're in an eth_call context otherwise.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, that's right. Okay 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Because it's a public function with access to assets, so we want to ensure that it always reverts state when called :) The purpose of this is to allow validation of arbitrary transfers within a single RPC call (people have been experiencing rate limiting issues + this will speed up validation a good amount).

@abandeali1 abandeali1 merged commit eafa0a3 into 3.0 Jun 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants