feat(website): add asset-buyer documentation
This commit is contained in:
		
							
								
								
									
										17
									
								
								packages/website/md/docs/asset_buyer/installation.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								packages/website/md/docs/asset_buyer/installation.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
				
			|||||||
 | 
					**Install**
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```bash
 | 
				
			||||||
 | 
					yarn add @0xproject/asset-buyer
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					**Import**
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```javascript
 | 
				
			||||||
 | 
					import { AssetBuyer } from '@0xproject/asset-buyer';
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					or
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```javascript
 | 
				
			||||||
 | 
					var AssetBuyer = require('@0xproject/asset-buyer').AssetBuyer;
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
							
								
								
									
										1
									
								
								packages/website/md/docs/asset_buyer/introduction.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								packages/website/md/docs/asset_buyer/introduction.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					Welcome to the [@0xproject/asset-buyer](https://github.com/0xProject/0x-monorepo/tree/development/packages/asset-buyer) documentation! AssetBuyer is a library that provides an easy way to buy any asset with ETH in one click, leveraging 0x liquidity and the [Forwarder contract](https://0xproject.com/docs/contracts#Forwarder).
 | 
				
			||||||
							
								
								
									
										39
									
								
								packages/website/md/docs/asset_buyer/usage.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								packages/website/md/docs/asset_buyer/usage.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,39 @@
 | 
				
			|||||||
 | 
					**Construction**
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Connecting to a standard relayer API compliant url:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```typescript
 | 
				
			||||||
 | 
					const provider = web3.currentProvider;
 | 
				
			||||||
 | 
					const apiUrl = 'https://api.relayer.com/v2';
 | 
				
			||||||
 | 
					const assetBuyer = AssetBuyer.getAssetBuyerForStandardRelayerAPIUrl(provider, apiUrl);
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Providing your own orders:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```typescript
 | 
				
			||||||
 | 
					const provider = web3.currentProvider;
 | 
				
			||||||
 | 
					const orders = []; // get these from your own API, a relayer, a friend, from anywhere
 | 
				
			||||||
 | 
					const assetBuyer = AssetBuyer.getAssetBuyerForProvidedOrders(provider, orders);
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					**Get a quote**
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					A [BuyQuote](#types-BuyQuote) object contains enough information to display buy information to an end user
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```typescript
 | 
				
			||||||
 | 
					const erc20TokenAddress = '0x5fa3c....';
 | 
				
			||||||
 | 
					const amountToBuy = new BigNumber(50000000000000000000);
 | 
				
			||||||
 | 
					const buyQuote = await assetBuyer.getBuyQuoteForERC20TokenAddressAsync(erc20TokenAddress, amountToBuy);
 | 
				
			||||||
 | 
					const quoteInfo = buyQuote.worstCaseQuoteInfo;
 | 
				
			||||||
 | 
					console.log(quoteInfo.ethAmount); // the total amount the user needs to pay to buy the desired amount (including fees)
 | 
				
			||||||
 | 
					console.log(quoteInfo.feeAmount); // a portion of the total ethAmount above that was used to buy fees
 | 
				
			||||||
 | 
					console.log(quoteInfo.ethPerAssetPrice); // the rate that this quote provides (e.g. 0.0035ETH / REP)
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					**Perform a buy**
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Pass the [BuyQuote](#types-BuyQuote) object from above back to the assetBuyer in order to initiate the buy transaction
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```typescript
 | 
				
			||||||
 | 
					const txHash = await assetBuyer.executeBuyQuoteAsync(buyQuote); // the hash of the transaction submitted to the Ethereum network
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
@@ -73,6 +73,7 @@
 | 
				
			|||||||
    "WIKI": "wiki",
 | 
					    "WIKI": "wiki",
 | 
				
			||||||
    "WEB3_WRAPPER": "Web3Wrapper",
 | 
					    "WEB3_WRAPPER": "Web3Wrapper",
 | 
				
			||||||
    "ORDER_UTILS": "Order Utils",
 | 
					    "ORDER_UTILS": "Order Utils",
 | 
				
			||||||
 | 
					    "ASSET_BUYER": "AssetBuyer",
 | 
				
			||||||
    "FAQ": "FAQ",
 | 
					    "FAQ": "FAQ",
 | 
				
			||||||
    "SMART_CONTRACTS": "0x smart contracts",
 | 
					    "SMART_CONTRACTS": "0x smart contracts",
 | 
				
			||||||
    "STANDARD_RELAYER_API": "standard relayer API",
 | 
					    "STANDARD_RELAYER_API": "standard relayer API",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -92,6 +92,7 @@ const DOC_WEBSITE_PATHS_TO_KEY = {
 | 
				
			|||||||
    [WebsitePaths.ZeroExJs]: Key.ZeroExJs,
 | 
					    [WebsitePaths.ZeroExJs]: Key.ZeroExJs,
 | 
				
			||||||
    [WebsitePaths.OrderUtils]: Key.OrderUtils,
 | 
					    [WebsitePaths.OrderUtils]: Key.OrderUtils,
 | 
				
			||||||
    [WebsitePaths.OrderWatcher]: Key.OrderWatcher,
 | 
					    [WebsitePaths.OrderWatcher]: Key.OrderWatcher,
 | 
				
			||||||
 | 
					    [WebsitePaths.AssetBuyer]: Key.AssetBuyer,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const DEFAULT_HEIGHT = 68;
 | 
					const DEFAULT_HEIGHT = 68;
 | 
				
			||||||
@@ -214,6 +215,12 @@ export class TopBar extends React.Component<TopBarProps, TopBarState> {
 | 
				
			|||||||
                    primaryText={this.props.translate.get(Key.EthereumTypes, Deco.CapWords)}
 | 
					                    primaryText={this.props.translate.get(Key.EthereumTypes, Deco.CapWords)}
 | 
				
			||||||
                />
 | 
					                />
 | 
				
			||||||
            </Link>,
 | 
					            </Link>,
 | 
				
			||||||
 | 
					            <Link key="subMenuItem-asset-buyer" to={WebsitePaths.AssetBuyer} className="text-decoration-none">
 | 
				
			||||||
 | 
					                <MenuItem
 | 
				
			||||||
 | 
					                    style={{ fontSize: styles.menuItem.fontSize }}
 | 
				
			||||||
 | 
					                    primaryText={this.props.translate.get(Key.AssetBuyer, Deco.CapWords)}
 | 
				
			||||||
 | 
					                />
 | 
				
			||||||
 | 
					            </Link>,
 | 
				
			||||||
            <a
 | 
					            <a
 | 
				
			||||||
                key="subMenuItem-whitePaper"
 | 
					                key="subMenuItem-whitePaper"
 | 
				
			||||||
                target="_blank"
 | 
					                target="_blank"
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										69
									
								
								packages/website/ts/containers/asset_buyer_documentation.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								packages/website/ts/containers/asset_buyer_documentation.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,69 @@
 | 
				
			|||||||
 | 
					import { DocsInfo, DocsInfoConfig, SupportedDocJson } from '@0xproject/react-docs';
 | 
				
			||||||
 | 
					import * as React from 'react';
 | 
				
			||||||
 | 
					import { connect } from 'react-redux';
 | 
				
			||||||
 | 
					import { Dispatch } from 'redux';
 | 
				
			||||||
 | 
					import { DocPage as DocPageComponent, DocPageProps } from 'ts/pages/documentation/doc_page';
 | 
				
			||||||
 | 
					import { Dispatcher } from 'ts/redux/dispatcher';
 | 
				
			||||||
 | 
					import { State } from 'ts/redux/reducer';
 | 
				
			||||||
 | 
					import { DocPackages } from 'ts/types';
 | 
				
			||||||
 | 
					import { Translate } from 'ts/utils/translate';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* tslint:disable:no-var-requires */
 | 
				
			||||||
 | 
					const IntroMarkdown = require('md/docs/asset_buyer/introduction');
 | 
				
			||||||
 | 
					const InstallationMarkdown = require('md/docs/asset_buyer/installation');
 | 
				
			||||||
 | 
					const UsageMarkdown = require('md/docs/asset_buyer/usage');
 | 
				
			||||||
 | 
					/* tslint:enable:no-var-requires */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const markdownSections = {
 | 
				
			||||||
 | 
					    introduction: 'introduction',
 | 
				
			||||||
 | 
					    installation: 'installation',
 | 
				
			||||||
 | 
					    usage: 'usage',
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const docsInfoConfig: DocsInfoConfig = {
 | 
				
			||||||
 | 
					    id: DocPackages.AssetBuyer,
 | 
				
			||||||
 | 
					    packageName: '@0xproject/asset-buyer',
 | 
				
			||||||
 | 
					    type: SupportedDocJson.TypeDoc,
 | 
				
			||||||
 | 
					    displayName: 'AssetBuyer',
 | 
				
			||||||
 | 
					    packageUrl: 'https://github.com/0xProject/0x-monorepo',
 | 
				
			||||||
 | 
					    markdownMenu: {
 | 
				
			||||||
 | 
					        introduction: [markdownSections.introduction],
 | 
				
			||||||
 | 
					        install: [markdownSections.installation],
 | 
				
			||||||
 | 
					        usage: [markdownSections.usage],
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    sectionNameToMarkdownByVersion: {
 | 
				
			||||||
 | 
					        '0.0.1': {
 | 
				
			||||||
 | 
					            [markdownSections.introduction]: IntroMarkdown,
 | 
				
			||||||
 | 
					            [markdownSections.installation]: InstallationMarkdown,
 | 
				
			||||||
 | 
					            [markdownSections.usage]: UsageMarkdown,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    markdownSections,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					const docsInfo = new DocsInfo(docsInfoConfig);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					interface ConnectedState {
 | 
				
			||||||
 | 
					    docsVersion: string;
 | 
				
			||||||
 | 
					    availableDocVersions: string[];
 | 
				
			||||||
 | 
					    docsInfo: DocsInfo;
 | 
				
			||||||
 | 
					    translate: Translate;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					interface ConnectedDispatch {
 | 
				
			||||||
 | 
					    dispatcher: Dispatcher;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const mapStateToProps = (state: State, _ownProps: DocPageProps): ConnectedState => ({
 | 
				
			||||||
 | 
					    docsVersion: state.docsVersion,
 | 
				
			||||||
 | 
					    availableDocVersions: state.availableDocVersions,
 | 
				
			||||||
 | 
					    translate: state.translate,
 | 
				
			||||||
 | 
					    docsInfo,
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const mapDispatchToProps = (dispatch: Dispatch<State>): ConnectedDispatch => ({
 | 
				
			||||||
 | 
					    dispatcher: new Dispatcher(dispatch),
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const Documentation: React.ComponentClass<DocPageProps> = connect(mapStateToProps, mapDispatchToProps)(
 | 
				
			||||||
 | 
					    DocPageComponent,
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
@@ -68,6 +68,9 @@ const LazyOrderUtilsDocumentation = createLazyComponent('Documentation', async (
 | 
				
			|||||||
const LazyEthereumTypesDocumentation = createLazyComponent('Documentation', async () =>
 | 
					const LazyEthereumTypesDocumentation = createLazyComponent('Documentation', async () =>
 | 
				
			||||||
    import(/* webpackChunkName: "ethereumTypesDocs" */ 'ts/containers/ethereum_types_documentation'),
 | 
					    import(/* webpackChunkName: "ethereumTypesDocs" */ 'ts/containers/ethereum_types_documentation'),
 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
 | 
					const LazyAssetBuyerDocumentation = createLazyComponent('Documentation', async () =>
 | 
				
			||||||
 | 
					    import(/* webpackChunkName: "assetBuyerDocs" */ 'ts/containers/asset_buyer_documentation'),
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const DOCUMENT_TITLE = '0x: The Protocol for Trading Tokens';
 | 
					const DOCUMENT_TITLE = '0x: The Protocol for Trading Tokens';
 | 
				
			||||||
const DOCUMENT_DESCRIPTION = 'An Open Protocol For Decentralized Exchange On The Ethereum Blockchain';
 | 
					const DOCUMENT_DESCRIPTION = 'An Open Protocol For Decentralized Exchange On The Ethereum Blockchain';
 | 
				
			||||||
@@ -133,7 +136,10 @@ render(
 | 
				
			|||||||
                                    path={`${WebsitePaths.EthereumTypes}/:version?`}
 | 
					                                    path={`${WebsitePaths.EthereumTypes}/:version?`}
 | 
				
			||||||
                                    component={LazyEthereumTypesDocumentation}
 | 
					                                    component={LazyEthereumTypesDocumentation}
 | 
				
			||||||
                                />
 | 
					                                />
 | 
				
			||||||
 | 
					                                <Route
 | 
				
			||||||
 | 
					                                    path={`${WebsitePaths.AssetBuyer}/:version?`}
 | 
				
			||||||
 | 
					                                    component={LazyAssetBuyerDocumentation}
 | 
				
			||||||
 | 
					                                />
 | 
				
			||||||
                                {/* Legacy endpoints */}
 | 
					                                {/* Legacy endpoints */}
 | 
				
			||||||
                                <Route
 | 
					                                <Route
 | 
				
			||||||
                                    path={`${WebsiteLegacyPaths.ZeroExJs}/:version?`}
 | 
					                                    path={`${WebsiteLegacyPaths.ZeroExJs}/:version?`}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -43,6 +43,7 @@ const docIdToSubpackageName: { [id: string]: string } = {
 | 
				
			|||||||
    [DocPackages.OrderUtils]: 'order-utils',
 | 
					    [DocPackages.OrderUtils]: 'order-utils',
 | 
				
			||||||
    [DocPackages.OrderWatcher]: 'order-watcher',
 | 
					    [DocPackages.OrderWatcher]: 'order-watcher',
 | 
				
			||||||
    [DocPackages.EthereumTypes]: 'ethereum-types',
 | 
					    [DocPackages.EthereumTypes]: 'ethereum-types',
 | 
				
			||||||
 | 
					    [DocPackages.AssetBuyer]: 'asset-buyer',
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface DocPageProps {
 | 
					export interface DocPageProps {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -363,6 +363,7 @@ export enum WebsitePaths {
 | 
				
			|||||||
    Subproviders = '/docs/subproviders',
 | 
					    Subproviders = '/docs/subproviders',
 | 
				
			||||||
    OrderUtils = '/docs/order-utils',
 | 
					    OrderUtils = '/docs/order-utils',
 | 
				
			||||||
    EthereumTypes = '/docs/ethereum-types',
 | 
					    EthereumTypes = '/docs/ethereum-types',
 | 
				
			||||||
 | 
					    AssetBuyer = '/docs/asset-buyer',
 | 
				
			||||||
    Careers = '/careers',
 | 
					    Careers = '/careers',
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -379,6 +380,7 @@ export enum DocPackages {
 | 
				
			|||||||
    EthereumTypes = 'ETHEREUM_TYPES',
 | 
					    EthereumTypes = 'ETHEREUM_TYPES',
 | 
				
			||||||
    ContractWrappers = 'CONTRACT_WRAPPERS',
 | 
					    ContractWrappers = 'CONTRACT_WRAPPERS',
 | 
				
			||||||
    OrderWatcher = 'ORDER_WATCHER',
 | 
					    OrderWatcher = 'ORDER_WATCHER',
 | 
				
			||||||
 | 
					    AssetBuyer = 'ASSET_BUYER',
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export enum Key {
 | 
					export enum Key {
 | 
				
			||||||
@@ -440,6 +442,7 @@ export enum Key {
 | 
				
			|||||||
    ZeroExJs = '0X_JS',
 | 
					    ZeroExJs = '0X_JS',
 | 
				
			||||||
    ContractWrappers = 'CONTRACT_WRAPPERS',
 | 
					    ContractWrappers = 'CONTRACT_WRAPPERS',
 | 
				
			||||||
    OrderWatcher = 'ORDER_WATCHER',
 | 
					    OrderWatcher = 'ORDER_WATCHER',
 | 
				
			||||||
 | 
					    AssetBuyer = 'ASSET_BUYER',
 | 
				
			||||||
    Blog = 'BLOG',
 | 
					    Blog = 'BLOG',
 | 
				
			||||||
    Forum = 'FORUM',
 | 
					    Forum = 'FORUM',
 | 
				
			||||||
    Connect = 'CONNECT',
 | 
					    Connect = 'CONNECT',
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user