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

asset-swapper V3 rebase, pay protocol fees, etc. #2350

Merged
merged 5 commits into from
Nov 19, 2019

Conversation

dorothy-zbornak
Copy link
Contributor

Description

  • Rebases [WIP] Upgrade asset-swapper for v3. #2272 against development.
  • @0x/asset-swapper now pays protocol fees (now that staking gets hooked up during migration).
  • @0x/asset-swapper removed dependency on @0x/contract-wrappers.
  • @0x/migrations now deploys Forwarder AFTER staking is attached to the Exchange.

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.

@dorothy-zbornak dorothy-zbornak force-pushed the fix/asset-swapper/rebase-and-pay-protocol-fees branch from c3a4b7e to a6a09ef Compare November 18, 2019 14:44
}
// TODO(dorothy-zbornak): Handle signature request denied
Copy link
Contributor Author

@dorothy-zbornak dorothy-zbornak Nov 18, 2019

Choose a reason for hiding this comment

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

I removed the try/catch that was here because it was doing nothing. ContractError.SignatureRequestDenied didn't actually get thrown by contract wrappers, and sendTransactionAsync() only mines the TX immediately on ganache, so you won't detect a failure on mainnet.

ContractError.SignatureRequestDenied denied is easy enough to detect, but maybe the logic should live in another package. Detecting a CompleteFillFailed will have to be accomplished by doing a callAsync() at the same block - 1 the TX was mined. Let's add tasks for this.

}
// TODO(dorothy-zbornak): Handle signature request denied
Copy link
Contributor Author

@dorothy-zbornak dorothy-zbornak Nov 18, 2019

Choose a reason for hiding this comment

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

I removed the try/catch that was here because it was doing nothing. ContractError.SignatureRequestDenied didn't actually get thrown by contract wrappers, and sendTransactionAsync() only mines the TX immediately on ganache, so you won't detect a failure on mainnet.

ContractError.SignatureRequestDenied denied is easy enough to detect, but maybe the logic should live in another package. Detecting a IncompleteFill will have to be accomplished by doing a callAsync() at the same block -1 the TX was mined. Let's add tasks for this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, yeah that try-catch was residual from asset-buyer, I do want to ask though, not very familiar with the nuances of the wrappers, how are errors handled? One of the large feedbacks I received at EthWaterloo was the vague errors thrown, don't want us to make asset-swapper more opaque with errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SignatureRequestDenied was just running a regex against the thrown error message (by Metamask or w/e).

If the use awaitTransactionSuccessAsync() instead of sendTransactionAsync(), it will throw if the TX fails. Then we can use callAsync() to replay the TX and get the actual rich revert, which gives us deeper detail.


const ethAmountWithFees = affiliateFeeUtils
.getTotalEthAmountWithAffiliateFee(worstCaseQuoteInfo, feePercentage)
.plus(worstCaseQuoteInfo.protocolFeeInEthAmount);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if this is what we want, but here I just add protocol fees to the total payable amount.

Copy link
Contributor

Choose a reason for hiding this comment

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

getTotalEthAmountWithAffiliateFee will consider protocol fees since affiliateFee is dependent on protocolFee (as of current forwarder design).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ahh, yeah, that makes sense

// if no ethAmount is provided, default to the worst totalTakerAssetAmount
const ethAmountWithFees = affiliateFeeUtils
.getTotalEthAmountWithAffiliateFee(worstCaseQuoteInfo, feePercentage)
.plus(worstCaseQuoteInfo.protocolFeeInEthAmount);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor

Choose a reason for hiding this comment

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

same case, do not need to add protocolFee

methodAbi,
ethAmount: quote.worstCaseQuoteInfo.protocolFeeInEthAmount,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added to pay protocol fees.

Copy link
Contributor

Choose a reason for hiding this comment

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

nice catch, I completely forgot about adding that in.

} else {
throw err;
}
const value = ethAmount || quote.worstCaseQuoteInfo.protocolFeeInEthAmount;
Copy link
Contributor Author

@dorothy-zbornak dorothy-zbornak Nov 18, 2019

Choose a reason for hiding this comment

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

Added to pay protocol fees.

@dorothy-zbornak dorothy-zbornak marked this pull request as ready for review November 18, 2019 15:51
@dorothy-zbornak dorothy-zbornak force-pushed the fix/asset-swapper/rebase-and-pay-protocol-fees branch from a6a09ef to 7ee46f3 Compare November 19, 2019 02:56
@buildsize
Copy link

buildsize bot commented Nov 19, 2019

File name Previous Size New Size Change
init.py 60.25 KB 60.25 KB 0 bytes (0%)
abi_gen_dummy.ts 77.71 KB [deleted]
lib_dummy.ts 7.08 KB [deleted]
test_lib_dummy.ts 10.34 KB [deleted]
environment.pickle 1.61 MB 1.61 MB 0 bytes (0%)
index.doctree 184.11 KB 184.11 KB 0 bytes (0%)
.buildinfo 230 bytes 230 bytes 0 bytes (0%)
genindex.html 5.6 KB 5.6 KB 0 bytes (0%)
index.html 2.52 KB 2.52 KB 0 bytes (0%)
objects.inv 375 bytes 375 bytes 0 bytes (0%)
py-modindex.html 3.07 KB 3.07 KB 0 bytes (0%)
search.html 2.84 KB 2.84 KB 0 bytes (0%)
searchindex.js 5.98 KB 5.98 KB 0 bytes (0%)
index.rst.txt 415 bytes 415 bytes 0 bytes (0%)
alabaster.css 10.92 KB 10.92 KB 0 bytes (0%)
basic.css 11.89 KB 11.89 KB 0 bytes (0%)
custom.css 42 bytes 42 bytes 0 bytes (0%)
doctools.js 9.05 KB 9.05 KB 0 bytes (0%)
documentation_options.js 303 bytes 303 bytes 0 bytes (0%)
file.png 286 bytes 286 bytes 0 bytes (0%)
jquery-[version].js 273.79 KB 273.79 KB 0 bytes (0%)
jquery.js 86.08 KB 86.08 KB 0 bytes (0%)
language_data.js 10.59 KB 10.59 KB 0 bytes (0%)
minus.png 90 bytes 90 bytes 0 bytes (0%)
plus.png 90 bytes 90 bytes 0 bytes (0%)
pygments.css 4.69 KB 4.69 KB 0 bytes (0%)
searchtools.js 15.61 KB 15.61 KB 0 bytes (0%)
underscore-[version].js 34.34 KB 34.34 KB 0 bytes (0%)
underscore.js 11.86 KB 11.86 KB 0 bytes (0%)
contract_addresses.html 16.8 KB 16.8 KB 0 bytes (0%)
contract_artifacts.html 8.24 KB 8.24 KB 0 bytes (0%)
json_schemas.html 12.55 KB 12.55 KB 0 bytes (0%)
order_utils.html 46.85 KB 46.85 KB 0 bytes (0%)
erc20_token.html 93.54 KB 93.54 KB 0 bytes (0%)
exchange.html 718.37 KB 718.37 KB 0 bytes (0%)
tx_params.html 9.41 KB 9.41 KB 0 bytes (0%)
local_message_signer.html 15.07 KB 15.07 KB 0 bytes (0%)
asset_data_utils.html 22.65 KB 22.65 KB 0 bytes (0%)
default_api.html 113.16 KB 113.16 KB 0 bytes (0%)
asset_proxy_owner.html 337.37 KB 337.37 KB 0 bytes (0%)
coordinator.html 128.71 KB 128.71 KB 0 bytes (0%)
coordinator_registry.html 39.58 KB 39.58 KB 0 bytes (0%)
dutch_auction.html 66.12 KB 66.12 KB 0 bytes (0%)
erc20_proxy.html 109.06 KB 109.06 KB 0 bytes (0%)
erc721_proxy.html 109.18 KB 109.18 KB 0 bytes (0%)
erc721_token.html 150.19 KB 150.19 KB 0 bytes (0%)
forwarder.html 121.63 KB 121.63 KB 0 bytes (0%)
i_asset_proxy.html 40.17 KB 40.17 KB 0 bytes (0%)
i_validator.html 27.05 KB 27.05 KB 0 bytes (0%)
i_wallet.html 24.88 KB 24.88 KB 0 bytes (0%)
multi_asset_proxy.html 144.02 KB 144.02 KB 0 bytes (0%)
order_validator.html 107.67 KB 107.67 KB 0 bytes (0%)
weth9.html 132.08 KB 132.08 KB 0 bytes (0%)
zrx_token.html 107.6 KB 107.6 KB 0 bytes (0%)
dev_utils.html 491.09 KB 491.09 KB 0 bytes (0%)
types.html 8.54 KB 8.54 KB 0 bytes (0%)
erc1155_mintable.html 276.5 KB 276.5 KB 0 bytes (0%)
erc1155_proxy.html 130.37 KB 130.37 KB 0 bytes (0%)
static_call_proxy.html 34.02 KB 34.02 KB 0 bytes (0%)

@coveralls
Copy link

coveralls commented Nov 19, 2019

Coverage Status

Coverage remained the same at 75.612% when pulling 38adc72 on fix/asset-swapper/rebase-and-pay-protocol-fees into 176e088 on development.

const FAKE_ERC20_TAKER_ASSET_DATA = '0xf47261b22222222222222222222222222222222222222222222222222222222222222222';
const FAKE_ERC20_MAKER_ASSET_DATA = '0xf47261b11111111111111111111111111111111111111111111111111111111111111111';

describe('sortingUtils', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice work! Very cleanly communicates / tests the sorting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't write like 99% of this PR (it just looks that way because of the rebase), so props to @dave4506

}

// tslint:disable-next-line: prefer-function-over-method
private _filterForFillableAndPermittedFeeTypeOrders(
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a lot going on in this function. Could be good to add some inline comments.

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.

Nice job, it's clear a lot of meticulous work went into this 👏👏👏. I mostly dug into the new logic. I think it looks great - very clear and thoroughly tested.

I skimmed the upgrades to existing logic and from what I can see they make sense. Although it would be good to have a engineer who's more intimately familiar with these packages to read through these areas as well.

Copy link
Contributor

@fragosti fragosti left a comment

Choose a reason for hiding this comment

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

Lets MERGEEEEEEEEEEE

@dorothy-zbornak dorothy-zbornak force-pushed the fix/asset-swapper/rebase-and-pay-protocol-fees branch from 554658c to 362c7c5 Compare November 19, 2019 19:49
}
// TODO(dorothy-zbornak): Handle signature request denied
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, yeah that try-catch was residual from asset-buyer, I do want to ask though, not very familiar with the nuances of the wrappers, how are errors handled? One of the large feedbacks I received at EthWaterloo was the vague errors thrown, don't want us to make asset-swapper more opaque with errors.


const ethAmountWithFees = affiliateFeeUtils
.getTotalEthAmountWithAffiliateFee(worstCaseQuoteInfo, feePercentage)
.plus(worstCaseQuoteInfo.protocolFeeInEthAmount);
Copy link
Contributor

Choose a reason for hiding this comment

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

getTotalEthAmountWithAffiliateFee will consider protocol fees since affiliateFee is dependent on protocolFee (as of current forwarder design).

// if no ethAmount is provided, default to the worst totalTakerAssetAmount
const ethAmountWithFees = affiliateFeeUtils
.getTotalEthAmountWithAffiliateFee(worstCaseQuoteInfo, feePercentage)
.plus(worstCaseQuoteInfo.protocolFeeInEthAmount);
Copy link
Contributor

Choose a reason for hiding this comment

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

same case, do not need to add protocolFee

@dave4506 dave4506 merged commit 8b94bbb into development Nov 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants