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

Chainlink stop-limit orders #2473

Merged
merged 8 commits into from
Feb 11, 2020
Merged

Conversation

moodlezoup
Copy link
Contributor

Description

Implements stop-limit orders at a StaticCall target, using Chainlink as an on-chain price oracle.

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.

@moodlezoup moodlezoup force-pushed the feature/chainlink-stop-limit branch from c6b7cbc to f56278c Compare February 6, 2020 02:02
@buildsize
Copy link

buildsize bot commented Feb 6, 2020

File name Previous Size New Size Change
init.py 60.43 KB 60.43 KB 0 bytes (0%)
abi_gen_dummy.ts 85.45 KB [deleted]
lib_dummy.ts 7.13 KB [deleted]
test_lib_dummy.ts 10.56 KB [deleted]
environment.pickle 1.72 MB 1.72 MB 0 bytes (0%)
index.doctree 436.61 KB 436.61 KB 0 bytes (0%)
.buildinfo 230 bytes 230 bytes 0 bytes (0%)
genindex.html 31.42 KB 31.42 KB 0 bytes (0%)
index.html 4.69 KB 4.69 KB 0 bytes (0%)
objects.inv 1 KB 1 KB 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 11.97 KB 11.97 KB 0 bytes (0%)
index.rst.txt 2.22 KB 2.22 KB 0 bytes (0%)
alabaster.css 10.92 KB 10.92 KB 0 bytes (0%)
basic.css 11.97 KB 11.97 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 324 bytes 324 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.65 KB 15.65 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.56 KB 12.56 KB 0 bytes (0%)
order_utils.html 47.16 KB 47.16 KB 0 bytes (0%)
erc20_token.html 93.56 KB 93.56 KB 0 bytes (0%)
exchange.html 730.72 KB 730.72 KB 0 bytes (0%)
tx_params.html 9.41 KB 9.41 KB 0 bytes (0%)
local_message_signer.html 15.08 KB 15.08 KB 0 bytes (0%)
asset_data_utils.html 22.66 KB 22.66 KB 0 bytes (0%)
asset_proxy_owner.html 337.39 KB 337.39 KB 0 bytes (0%)
coordinator.html 128.72 KB 128.72 KB 0 bytes (0%)
coordinator_registry.html 39.59 KB 39.59 KB 0 bytes (0%)
dutch_auction.html 66.13 KB 66.13 KB 0 bytes (0%)
erc20_proxy.html 111.83 KB 111.83 KB 0 bytes (0%)
erc721_proxy.html 111.95 KB 111.95 KB 0 bytes (0%)
erc721_token.html 150.2 KB 150.2 KB 0 bytes (0%)
forwarder.html 130.08 KB 130.08 KB 0 bytes (0%)
i_asset_proxy.html 40.18 KB 40.18 KB 0 bytes (0%)
i_validator.html 27.06 KB 27.06 KB 0 bytes (0%)
i_wallet.html 24.9 KB 24.9 KB 0 bytes (0%)
multi_asset_proxy.html 146.81 KB 146.81 KB 0 bytes (0%)
order_validator.html 107.69 KB 107.69 KB 0 bytes (0%)
weth9.html 133.39 KB 133.39 KB 0 bytes (0%)
zrx_token.html 107.61 KB 107.61 KB 0 bytes (0%)
dev_utils.html 593.43 KB 593.43 KB 0 bytes (0%)
types.html 8.54 KB 8.54 KB 0 bytes (0%)
erc1155_mintable.html 276.51 KB 276.51 KB 0 bytes (0%)
erc1155_proxy.html 133.15 KB 133.15 KB 0 bytes (0%)
static_call_proxy.html 34.04 KB 34.04 KB 0 bytes (0%)
relayer_api.html 113.37 KB 113.37 KB 0 bytes (0%)
relayer_api_asset_data_pairs_response_schema.html 13.86 KB 13.86 KB 0 bytes (0%)
relayer_api_asset_data_trade_info_schema.html 23.09 KB 23.09 KB 0 bytes (0%)
relayer_api_error_response_schema.html 19.74 KB 19.74 KB 0 bytes (0%)
relayer_api_error_response_schema_validation_errors.html 19.92 KB 19.92 KB 0 bytes (0%)
relayer_api_fee_recipients_response_schema.html 13.83 KB 13.83 KB 0 bytes (0%)
relayer_api_order_config_payload_schema.html 39.52 KB 39.52 KB 0 bytes (0%)
relayer_api_order_config_response_schema.html 25.23 KB 25.23 KB 0 bytes (0%)
relayer_api_order_schema.html 15.88 KB 15.88 KB 0 bytes (0%)
relayer_api_orderbook_response_schema.html 16.2 KB 16.2 KB 0 bytes (0%)
relayer_api_orders_channel_subscribe_payload_schema.html 35.06 KB 35.06 KB 0 bytes (0%)
relayer_api_orders_channel_subscribe_schema.html 22.98 KB 22.98 KB 0 bytes (0%)
relayer_api_orders_channel_update_schema.html 22.83 KB 22.83 KB 0 bytes (0%)
relayer_api_orders_response_schema.html 13.75 KB 13.75 KB 0 bytes (0%)
signed_order_schema.html 14.36 KB 14.36 KB 0 bytes (0%)

@coveralls
Copy link

coveralls commented Feb 6, 2020

Coverage Status

Coverage decreased (-0.2%) to 79.563% when pulling 6361dbd on feature/chainlink-stop-limit into dfd9443 on development.


int256 latestPrice = IChainlinkAggregator(oracle).latestAnswer();
require(
latestPrice >= stopPrice && latestPrice <= limitPrice,
Copy link
Member

Choose a reason for hiding this comment

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

Can we just rename these minPrice and maxPrice? It's less opinionated, which matters depending on if this is a buy or sell order.


uint256 latestTimestamp = IChainlinkAggregator(oracle).latestTimestamp();
require(
now.safeSub(latestTimestamp) <= priceFreshness, // solhint-disable-line not-rely-on-time
Copy link
Member

Choose a reason for hiding this comment

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

Nit: we use block.timestamp instead of now throughout the rest of the codebase.

Copy link
Member

Choose a reason for hiding this comment

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

This is a pretty interesting parameter. In what scenarios do you see it being most useful?

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 can imagine arb bots monitoring the mempool for updates to the aggregator's price, which would serve as an indicator for arb opportunities on these stop-limit orders. The price freshness parameter would mitigate this was my thought

@moodlezoup moodlezoup force-pushed the feature/chainlink-stop-limit branch 2 times, most recently from 747c973 to be1f300 Compare February 6, 2020 22:00
@moodlezoup moodlezoup requested a review from abandeali1 February 6, 2020 23:30
Copy link
Member

@abandeali1 abandeali1 left a comment

Choose a reason for hiding this comment

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

One small change, then LGTM!


contract ChainlinkStopLimit {

using LibSafeMath for uint256;
Copy link
Member

Choose a reason for hiding this comment

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

Looks like we don't use this anymore.

@moodlezoup moodlezoup force-pushed the feature/chainlink-stop-limit branch 3 times, most recently from c2f469f to 6d11a8d Compare February 11, 2020 01:14
* Encodes the given stop limit data parameters into StaticCall asset data so that it can be used
* in a 0x order.
*/
export function encodeStopLimiStaticCallData(
Copy link
Contributor

Choose a reason for hiding this comment

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

encodeStopLimiStaticCallDataencodeStopLimitStaticCallData 🇨🇦

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.

Lgtm! One minor 🇨🇦 fix. Also, are we planning to do a mainnet integration test?

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.

Looks p p good

@moodlezoup moodlezoup force-pushed the feature/chainlink-stop-limit branch from 9f46fa9 to 6361dbd Compare February 11, 2020 22:37
@moodlezoup moodlezoup merged commit f471c79 into development Feb 11, 2020
@moodlezoup moodlezoup deleted the feature/chainlink-stop-limit branch February 11, 2020 23:10
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