1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
|
import {
colors,
constants,
constants as sharedConstants,
NestedSidebarMenu,
utils as sharedUtils,
} from '@0xproject/react-shared';
import * as _ from 'lodash';
import * as React from 'react';
import DocumentTitle = require('react-document-title');
import { Element as ScrollElement } from 'react-scroll';
import { DocsContentTopBar } from 'ts/components/documentation/docs_content_top_bar';
import { DocsLogo } from 'ts/components/documentation/docs_logo';
import { TutorialButton } from 'ts/components/documentation/tutorial_button';
import { Container } from 'ts/components/ui/container';
import { Link } from 'ts/components/ui/link';
import { Text } from 'ts/components/ui/text';
import { Dispatcher } from 'ts/redux/dispatcher';
import { Deco, Key, ScreenWidths, TutorialInfo, WebsitePaths } from 'ts/types';
import { Translate } from 'ts/utils/translate';
import { utils } from 'ts/utils/utils';
interface Package {
name: string;
description: string;
to: string;
isExternal?: boolean;
shouldOpenInNewTab?: boolean;
}
const THROTTLE_TIMEOUT = 100;
const TOP_BAR_HEIGHT = 80;
const SCROLLER_WIDTH = 4;
const TUTORIALS: TutorialInfo[] = [
{
title: Key.DevelopOnEthereum,
iconUrl: '/images/developers/tutorials/develop_on_ethereum.svg',
description: Key.DevelopOnEthereumDescription,
location: `${WebsitePaths.Wiki}#Ethereum-Development`,
},
{
title: Key.BuildARelayer,
iconUrl: '/images/developers/tutorials/build_a_relayer.svg',
description: Key.BuildARelayerDescription,
location: `${WebsitePaths.Wiki}#Build-A-Relayer`,
},
{
title: Key.OrderBasics,
iconUrl: '/images/developers/tutorials/0x_order_basics.svg',
description: Key.OrderBasicsDescription,
location: `${WebsitePaths.Wiki}#Create,-Validate,-Fill-Order`,
},
{
title: Key.UseSharedLiquidity,
iconUrl: '/images/developers/tutorials/use_shared_liquidity.svg',
description: Key.UseSharedLiquidityDescription,
location: `${WebsitePaths.Wiki}#Find,-Submit,-Fill-Order-From-Relayer`,
},
];
enum Categories {
ZeroExProtocol = '0x Protocol',
Ethereum = 'Ethereum',
CommunityMaintained = 'Community Maintained',
}
const CATEGORY_TO_PACKAGES: { [category: string]: Package[] } = {
[Categories.ZeroExProtocol]: [
{
name: '0x.js',
description:
'A library for interacting with the 0x protocol. It is a high level package which combines a number of smaller specific-purpose packages such as `order-utils` and `contract-wrappers`.',
to: WebsitePaths.ZeroExJs,
},
{
name: '0x starter project',
description:
'A Typescript starter project that will walk you through the basics of how to interact with 0x Protocol and trade of an SRA relayer',
to: 'https://github.com/0xProject/0x-starter-project',
isExternal: true,
shouldOpenInNewTab: true,
},
{
name: '@0xproject/connect',
description:
'An http & websocket client for interacting with relayers that have implemented the Standard Relayer API',
to: WebsitePaths.Connect,
},
{
name: '@0xproject/contract-wrappers',
description:
'Typescript/Javascript wrappers of the 0x protocol Ethereum smart contracts. Use this library to call methods on the 0x smart contracts, subscribe to contract events and to fetch information stored in the contracts.',
to: WebsitePaths.ContractWrappers,
},
{
name: '@0xproject/json-schemas',
description:
'A collection of 0x-related JSON-schemas (incl. SRA request/response schemas, 0x order message format schema, etc...)',
to: WebsitePaths.JSONSchemas,
},
{
name: '@0xproject/order-utils',
description:
'A set of utils for working with 0x orders. It includes utilities for creating, signing, validating 0x orders, encoding/decoding assetData and much more.',
to: WebsitePaths.OrderUtils,
},
{
name: '@0xproject/order-watcher',
description:
"A daemon that watches a set of 0x orders and emits events when an order's fillability has changed. Can be used by a relayer to prune their orderbook or by a trader to keep their view of the market up-to-date.",
to: WebsitePaths.OrderWatcher,
},
{
name: '@0xproject/sra-spec',
description:
'Contains the Standard Relayer API OpenAPI Spec. The package distributes both a javascript object version and a json version.',
to: 'https://github.com/0xProject/0x-monorepo/tree/development/packages/sra-spec',
isExternal: true,
shouldOpenInNewTab: true,
},
],
[Categories.Ethereum]: [
{
name: 'abi-gen',
description:
"This package allows you to generate TypeScript contract wrappers from ABI files. It's heavily inspired by Geth abigen but takes a different approach. You can write your custom handlebars templates which will allow you to seamlessly integrate the generated code into your existing codebase with existing conventions.",
to: 'https://github.com/0xProject/0x-monorepo/tree/development/packages/abi-gen',
isExternal: true,
shouldOpenInNewTab: true,
},
{
name: 'ethereum-types',
description:
'A collection of Typescript types that are useful when working on an Ethereum-based project (e.g RawLog, Transaction, TxData, SolidityTypes, etc...).',
to: WebsitePaths.EthereumTypes,
},
{
name: '@0xproject/sol-compiler',
description:
'A wrapper around `solc-js` that adds smart re-compilation, ability to compile an entire project, Solidity version specific compilation, standard input description support and much more.',
to: WebsitePaths.SolCompiler,
},
{
name: '@0xproject/sol-cov',
description:
'A Solidity code coverage tool. Sol-cov uses transaction traces to figure out which lines of your code has been covered by your tests.',
to: WebsitePaths.SolCov,
},
{
name: '@0xproject/subproviders',
description:
'A collection of subproviders to use with `web3-provider-engine` (e.g subproviders for interfacing with Ledger hardware wallet, Mnemonic wallet, private key wallet, etc...)',
to: WebsitePaths.Subproviders,
},
{
name: '@0xproject/web3-wrapper',
description:
'A raw Ethereum JSON RPC client to simplify interfacing with Ethereum nodes. Also includes some convenience functions for awaiting transactions to be mined, converting between token units, etc...',
to: WebsitePaths.Web3Wrapper,
},
],
[Categories.CommunityMaintained]: [
{
name: '0x Event Extractor',
description:
'NodeJS worker originally built for 0x Tracker which extracts 0x fill events from the Ethereum blockchain and persists them to MongoDB. Support for both V1 and V2 of the 0x protocol is included with events tagged against the protocol version they belong to.',
to: 'https://github.com/0xTracker/0x-event-extractor',
shouldOpenInNewTab: true,
isExternal: true,
},
{
name: '0x Tracker Worker',
description:
'NodeJS worker built for 0x Tracker which performs various ETL tasks related to the 0x protocol trading data and other information used on 0x Tracker.',
to: 'https://github.com/0xTracker/0x-tracker-worker',
shouldOpenInNewTab: true,
isExternal: true,
},
{
name: 'Aquaduct',
description:
"ERCdex's Javascript SDK for trading on their relayer, as well as other Aquaduct partner relayers",
to: 'https://www.npmjs.com/package/aqueduct',
shouldOpenInNewTab: true,
isExternal: true,
},
{
name: 'Aquaduct Server SDK',
description:
'SDKs for automation using Aqueduct & ERC dEX. Aqueduct Server is a lightweight, portable and secure server that runs locally on any workstation. The server exposes a small number of foundational endpoints that enable working with the decentralized Aqueduct liquidity pool from any context or programming language.',
to: 'https://github.com/ERCdEX/aqueduct-server-sdk',
shouldOpenInNewTab: true,
isExternal: true,
},
{
name: 'DDEX Node.js SDK',
description: 'A node.js SDK for trading on the DDEX relayer',
to: 'https://www.npmjs.com/package/ddex-api',
shouldOpenInNewTab: true,
isExternal: true,
},
{
name: 'ERCdex Widget',
description: "The ERC dEX Trade Widget let's any website provide token liquidity to it's users",
to: 'https://github.com/ERCdEX/widget',
shouldOpenInNewTab: true,
isExternal: true,
},
{
name: 'ERCdex Java SDK',
description: "ERCdex's Java SDK for trading on their relayer, as well as other Aquaduct partner relayers",
to: 'https://github.com/ERCdEX/java',
shouldOpenInNewTab: true,
isExternal: true,
},
{
name: 'ERCdex Python SDK',
description: "ERCdex's Python SDK for trading on their relayer, as well as other Aquaduct partner relayers",
to: 'https://github.com/ERCdEX/python',
shouldOpenInNewTab: true,
isExternal: true,
},
{
name: 'Massive',
description:
'A set of command-line tools for creating command-line scripts for interacting with the Ethereum blockchain in general, and 0x in particular',
to: 'https://github.com/NoteGio/massive',
shouldOpenInNewTab: true,
isExternal: true,
},
{
name: 'OpenRelay',
description: 'An open-source API-only Relayer written in Go',
to: 'https://github.com/NoteGio/openrelay',
shouldOpenInNewTab: true,
isExternal: true,
},
{
name: 'OpenRelay.js',
description:
'A JavaScript Library for Interacting with OpenRelay.xyz and other 0x Standard Relayer API Implementations',
to: 'https://github.com/NoteGio/openrelay.js',
shouldOpenInNewTab: true,
isExternal: true,
},
{
name: 'Radar SDK',
description:
'The Radar Relay SDK is a software development kit that simplifies the interactions with Radar Relay’s APIs',
to: 'https://github.com/RadarRelay/sdk',
shouldOpenInNewTab: true,
isExternal: true,
},
{
name: 'The Ocean Javascript SDK',
description:
'The Ocean provides a simple REST API, WebSockets API, and JavaScript library to help you integrate decentralized trading into your existing trading strategy.',
to: 'https://github.com/TheOceanTrade/theoceanx-javascript',
shouldOpenInNewTab: true,
isExternal: true,
},
{
name: 'Tokenlon Javascript SDK',
description: "Tokenlon SDK provides APIs for developers to trade of imToken's relayer",
to: 'https://www.npmjs.com/package/tokenlon-sdk',
shouldOpenInNewTab: true,
isExternal: true,
},
{
name: 'AssetData decoder library in Java',
description: 'A small library that implements the 0x order assetData encoding/decoding in Java',
to: 'https://github.com/wildnothing/asset-data-decoder',
shouldOpenInNewTab: true,
isExternal: true,
},
],
};
export interface HomeProps {
location: Location;
translate: Translate;
screenWidth: ScreenWidths;
dispatcher: Dispatcher;
}
export interface HomeState {
isHoveringSidebar: boolean;
isHoveringMainContent: boolean;
}
export class Home extends React.Component<HomeProps, HomeState> {
private readonly _throttledScreenWidthUpdate: () => void;
constructor(props: HomeProps) {
super(props);
this._throttledScreenWidthUpdate = _.throttle(this._updateScreenWidth.bind(this), THROTTLE_TIMEOUT);
this.state = {
isHoveringSidebar: false,
isHoveringMainContent: false,
};
}
public componentDidMount(): void {
window.addEventListener('resize', this._throttledScreenWidthUpdate);
window.scrollTo(0, 0);
}
public componentWillUnmount(): void {
window.removeEventListener('resize', this._throttledScreenWidthUpdate);
}
public render(): React.ReactNode {
const mainContainerStyle: React.CSSProperties = {
position: 'absolute',
top: 80,
left: 0,
bottom: 0,
right: 0,
overflowX: 'hidden',
overflowY: 'scroll',
minHeight: `calc(100vh - ${TOP_BAR_HEIGHT}px)`,
WebkitOverflowScrolling: 'touch',
};
const isSmallScreen = this.props.screenWidth === ScreenWidths.Sm;
const mainContentPadding = isSmallScreen ? 20 : 50;
const topLevelMenu = {
'Starter guides': _.map(TUTORIALS, tutorialInfo =>
this.props.translate.get(tutorialInfo.title as Key, Deco.Cap),
),
[Categories.ZeroExProtocol]: _.map(CATEGORY_TO_PACKAGES[Categories.ZeroExProtocol], pkg => pkg.name),
[Categories.Ethereum]: _.map(CATEGORY_TO_PACKAGES[Categories.Ethereum], pkg => pkg.name),
[Categories.CommunityMaintained]: _.map(
CATEGORY_TO_PACKAGES[Categories.CommunityMaintained],
pkg => pkg.name,
),
};
_.each(TUTORIALS, tutorialInfo => {
const id = sharedUtils.getIdFromName(this.props.translate.get(tutorialInfo.title as Key, Deco.Cap));
});
return (
<Container
className="flex items-center"
width="100%"
background={`linear-gradient(to right, ${colors.grey100} 0%, ${colors.grey100} 50%, ${
colors.white
} 50%, ${colors.white} 100%)`}
>
<DocumentTitle title="0x Docs Home" />
<div className="flex mx-auto" style={{ height: '100vh' }}>
<Container
className="sm-hide xs-hide relative"
width={234}
paddingLeft={22}
paddingRight={22}
paddingTop={2}
backgroundColor={colors.grey100}
>
<DocsLogo height={36} containerStyle={{ paddingTop: 30, paddingBottom: 12 }} />
<div
style={{
...mainContainerStyle,
paddingTop: 35,
overflow: this.state.isHoveringSidebar ? 'auto' : 'hidden',
}}
onMouseEnter={this._onSidebarHover.bind(this)}
onMouseLeave={this._onSidebarHoverOff.bind(this)}
>
<NestedSidebarMenu
topLevelMenu={topLevelMenu}
menuSubsectionsBySection={{}}
shouldDisplaySectionHeaders={true}
shouldReformatMenuItemNames={false}
/>
</div>
</Container>
<Container
className="relative"
width={isSmallScreen ? '100vw' : 716}
paddingBottom="100px"
backgroundColor={colors.white}
>
<Container paddingLeft={mainContentPadding} paddingRight={mainContentPadding}>
<DocsContentTopBar
location={this.props.location}
translate={this.props.translate}
menu={topLevelMenu}
/>
</Container>
<div
id={sharedConstants.SCROLL_CONTAINER_ID}
className="absolute"
style={{
...mainContainerStyle,
paddingTop: 30,
paddingLeft: mainContentPadding,
paddingRight: this.state.isHoveringMainContent
? mainContentPadding - SCROLLER_WIDTH
: mainContentPadding,
overflow: this.state.isHoveringMainContent ? 'auto' : 'hidden',
}}
onMouseEnter={this._onMainContentHover.bind(this)}
onMouseLeave={this._onMainContentHoverOff.bind(this)}
>
<div>
{this._renderSectionTitle('Start building on 0x')}
<Container paddingTop="12px">
{this._renderSectionDescription(
'Follow one of our "Getting started" guides to learn more about building ontop of 0x.',
)}
<Container marginTop="36px">
{_.map(TUTORIALS, tutorialInfo => (
<ScrollElement
name={sharedUtils.getIdFromName(
this.props.translate.get(tutorialInfo.title as Key, Deco.Cap),
)}
key={`tutorial-${tutorialInfo.title}`}
>
<TutorialButton
translate={this.props.translate}
tutorialInfo={tutorialInfo}
/>
</ScrollElement>
))}
</Container>
</Container>
</div>
<div className="mt4">
{this._renderSectionTitle(
this.props.translate.get(Key.LibrariesAndTools, Deco.CapWords),
)}
<Container paddingTop="12px">
{this._renderSectionDescription(
'A list of available tools maintained by the 0x core developers and wider community for building on top of 0x Protocol and Ethereum',
)}
<Container marginTop="36px">
{_.map(CATEGORY_TO_PACKAGES, (pkgs, category) =>
this._renderPackageCategory(category, pkgs),
)}
</Container>
</Container>
</div>
</div>
</Container>
</div>
</Container>
);
}
private _renderPackageCategory(category: string, pkgs: Package[]): React.ReactNode {
return (
<div key={`category-${category}`}>
<Text fontSize="18px">{category}</Text>
<div>{_.map(pkgs, pkg => this._renderPackage(pkg))}</div>
</div>
);
}
private _renderPackage(pkg: Package): React.ReactNode {
const id = sharedUtils.getIdFromName(pkg.name);
return (
<ScrollElement name={id} key={`package-${pkg.name}`}>
<div className="pb2">
<div
style={{
width: '100%',
height: 1,
backgroundColor: colors.grey300,
marginTop: 11,
}}
/>
<div className="clearfix mt2 pt1">
<div className="md-col lg-col md-col-4 lg-col-4">
<Link
to={pkg.to}
className="text-decoration-none"
style={{ color: colors.lightLinkBlue }}
isExternal={!!pkg.isExternal}
shouldOpenInNewTab={!!pkg.shouldOpenInNewTab}
>
<Text Tag="div" fontColor={colors.lightLinkBlue} fontWeight="bold">
{pkg.name}
</Text>
</Link>
</div>
<div className="md-col lg-col md-col-6 lg-col-6 sm-py2">
<Text Tag="div" fontColor={colors.grey700}>
{pkg.description}
</Text>
</div>
<div className="md-col lg-col md-col-2 lg-col-2 sm-pb2 relative">
<Link
to={pkg.to}
className="text-decoration-none absolute"
style={{ right: 0, color: colors.lightLinkBlue }}
isExternal={!!pkg.isExternal}
shouldOpenInNewTab={!!pkg.shouldOpenInNewTab}
>
<div className="flex">
<div>{this.props.translate.get(Key.More, Deco.Cap)}</div>
<Container paddingTop="1px" paddingLeft="6px">
<i
className="zmdi zmdi-chevron-right bold"
style={{ fontSize: 18, color: colors.lightLinkBlue }}
/>
</Container>
</div>
</Link>
</div>
</div>
</div>
</ScrollElement>
);
}
private _renderSectionTitle(text: string): React.ReactNode {
return (
<Text fontColor="#333333" fontSize="30px" fontWeight="bold">
{text}
</Text>
);
}
private _renderSectionDescription(text: string): React.ReactNode {
return (
<Text fontColor="#999999" fontSize="18px" fontFamily="Roboto Mono">
{text}
</Text>
);
}
private _updateScreenWidth(): void {
const newScreenWidth = utils.getScreenWidth();
this.props.dispatcher.updateScreenWidth(newScreenWidth);
}
private _onSidebarHover(_event: React.FormEvent<HTMLInputElement>): void {
this.setState({
isHoveringSidebar: true,
});
}
private _onSidebarHoverOff(): void {
this.setState({
isHoveringSidebar: false,
});
}
private _onMainContentHover(_event: React.FormEvent<HTMLInputElement>): void {
this.setState({
isHoveringMainContent: true,
});
}
private _onMainContentHoverOff(): void {
this.setState({
isHoveringMainContent: false,
});
}
}
|