aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/md
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2018-10-16 14:27:56 +0800
committerBrandon Millman <brandon.millman@gmail.com>2018-10-17 01:00:49 +0800
commitaa1085c8f3866da4965c0102be27c0f5e19b3db6 (patch)
treed3645836619952a9a9d15af8db4a1120112fb206 /packages/website/md
parent55be070dcfd7b9704ba24bc387bca0001f0c47f5 (diff)
downloaddexon-sol-tools-aa1085c8f3866da4965c0102be27c0f5e19b3db6.tar
dexon-sol-tools-aa1085c8f3866da4965c0102be27c0f5e19b3db6.tar.gz
dexon-sol-tools-aa1085c8f3866da4965c0102be27c0f5e19b3db6.tar.bz2
dexon-sol-tools-aa1085c8f3866da4965c0102be27c0f5e19b3db6.tar.lz
dexon-sol-tools-aa1085c8f3866da4965c0102be27c0f5e19b3db6.tar.xz
dexon-sol-tools-aa1085c8f3866da4965c0102be27c0f5e19b3db6.tar.zst
dexon-sol-tools-aa1085c8f3866da4965c0102be27c0f5e19b3db6.zip
feat(website): add asset-buyer documentation
Diffstat (limited to 'packages/website/md')
-rw-r--r--packages/website/md/docs/asset_buyer/installation.md17
-rw-r--r--packages/website/md/docs/asset_buyer/introduction.md1
-rw-r--r--packages/website/md/docs/asset_buyer/usage.md39
3 files changed, 57 insertions, 0 deletions
diff --git a/packages/website/md/docs/asset_buyer/installation.md b/packages/website/md/docs/asset_buyer/installation.md
new file mode 100644
index 000000000..483ee2b65
--- /dev/null
+++ b/packages/website/md/docs/asset_buyer/installation.md
@@ -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;
+```
diff --git a/packages/website/md/docs/asset_buyer/introduction.md b/packages/website/md/docs/asset_buyer/introduction.md
new file mode 100644
index 000000000..a40d20cc9
--- /dev/null
+++ b/packages/website/md/docs/asset_buyer/introduction.md
@@ -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).
diff --git a/packages/website/md/docs/asset_buyer/usage.md b/packages/website/md/docs/asset_buyer/usage.md
new file mode 100644
index 000000000..93c681f40
--- /dev/null
+++ b/packages/website/md/docs/asset_buyer/usage.md
@@ -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
+```