Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client refactor: imports, helper functions, code cleanup #21

Merged
merged 7 commits into from
Oct 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ module.exports = {
food: "1.svg",
children: [
"/",
"/globals",
"classes/dealerclient",
"classes/erc20token",
"interfaces/dealerresponse",
"interfaces/quoteresponse",
"interfaces/swapresponse",
"interfaces/dealerfilltransaction",
]
},
]
Expand Down
99 changes: 56 additions & 43 deletions docs/classes/dealerclient.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ A simple client for the Zaidan dealer server.
* [isBrowser](dealerclient.md#isbrowser)
* [networkId](dealerclient.md#networkid)
* [pairs](dealerclient.md#pairs)
* [subProvider](dealerclient.md#subprovider)
* [provider](dealerclient.md#provider)
* [tokens](dealerclient.md#tokens)
* [txPriority](dealerclient.md#txpriority)
* [web3](dealerclient.md#web3)
* [web3Wrapper](dealerclient.md#web3wrapper)
* [MAX_ALLOWANCE](dealerclient.md#static-max_allowance)
Expand All @@ -50,9 +51,9 @@ A simple client for the Zaidan dealer server.

### constructor

\+ **new DealerClient**(`dealerUri`: string, `web3Uri?`: string, `gasPrice`: number): *[DealerClient](dealerclient.md)*
\+ **new DealerClient**(`dealerUri`: string, `web3Uri?`: string, `txPriority`: [GasPriority](../globals.md#gaspriority)): *[DealerClient](dealerclient.md)*

*Defined in [DealerClient.ts:72](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/e458263/src/DealerClient.ts#L72)*
*Defined in [DealerClient.ts:81](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/df02572/src/DealerClient.ts#L81)*

Instantiate a new DealerClient. Prior to use, `client.init()` should
be called, which triggers a prompt for the user to allow MetaMask to
Expand All @@ -68,7 +69,7 @@ Name | Type | Default | Description |
------ | ------ | ------ | ------ |
`dealerUri` | string | - | the base RPC API path for the dealer server |
`web3Uri?` | string | - | optional Ethereum JSONRPC url for server-side usage |
`gasPrice` | number | 5 | optionally set the gas price for allowance transactions |
`txPriority` | [GasPriority](../globals.md#gaspriority) | "fast" | optionally set the gas price (via etherchain) as "fast", "average", or "safeLow" |

**Returns:** *[DealerClient](dealerclient.md)*

Expand All @@ -78,17 +79,17 @@ Name | Type | Default | Description |

• **GAS_PRICE**: *BigNumber*

*Defined in [DealerClient.ts:72](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/e458263/src/DealerClient.ts#L72)*
*Defined in [DealerClient.ts:75](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/df02572/src/DealerClient.ts#L75)*

Default gas price to use for allowance transactions.
Default gas price to use for allowance transactions (in wei).

___

### coinbase

• **coinbase**: *string*

*Defined in [DealerClient.ts:60](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/e458263/src/DealerClient.ts#L60)*
*Defined in [DealerClient.ts:63](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/df02572/src/DealerClient.ts#L63)*

Stores the current user's coinbase address.

Expand All @@ -98,7 +99,7 @@ ___

• **contractWrappers**: *ContractWrappers*

*Defined in [DealerClient.ts:63](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/e458263/src/DealerClient.ts#L63)*
*Defined in [DealerClient.ts:66](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/df02572/src/DealerClient.ts#L66)*

Initialized contract wrappers for interacting with the 0x system.

Expand All @@ -108,7 +109,7 @@ ___

• **initialized**: *boolean*

*Defined in [DealerClient.ts:66](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/e458263/src/DealerClient.ts#L66)*
*Defined in [DealerClient.ts:69](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/df02572/src/DealerClient.ts#L69)*

Set to 'true' after a successful .init(), must be called before use.

Expand All @@ -118,7 +119,7 @@ ___

• **isBrowser**: *boolean*

*Defined in [DealerClient.ts:69](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/e458263/src/DealerClient.ts#L69)*
*Defined in [DealerClient.ts:72](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/df02572/src/DealerClient.ts#L72)*

Set to 'true' if browser environment is detected.

Expand All @@ -128,7 +129,7 @@ ___

• **networkId**: *number*

*Defined in [DealerClient.ts:57](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/e458263/src/DealerClient.ts#L57)*
*Defined in [DealerClient.ts:60](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/df02572/src/DealerClient.ts#L60)*

Stores the configured Ethereum network ID.

Expand All @@ -138,27 +139,27 @@ ___

• **pairs**: *string[]*

*Defined in [DealerClient.ts:40](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/e458263/src/DealerClient.ts#L40)*
*Defined in [DealerClient.ts:43](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/df02572/src/DealerClient.ts#L43)*

An array of the currently supported pairs (as expected by `getQuote`).

___

### subProvider
### provider

• **subProvider**: *MetamaskSubprovider*
• **provider**: *Provider | SupportedProvider | MetamaskSubprovider*

*Defined in [DealerClient.ts:54](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/e458263/src/DealerClient.ts#L54)*
*Defined in [DealerClient.ts:57](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/df02572/src/DealerClient.ts#L57)*

SubProvider instance used to interact with MetaMask.
Provider instance used to interact with Ethereum.

___

### tokens

• **tokens**: *object*

*Defined in [DealerClient.ts:45](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/e458263/src/DealerClient.ts#L45)*
*Defined in [DealerClient.ts:48](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/df02572/src/DealerClient.ts#L48)*

Maps tokenTicker => address for looking up common tokens.

Expand All @@ -168,11 +169,22 @@ Maps tokenTicker => address for looking up common tokens.

___

### txPriority

• **txPriority**: *[GasPriority](../globals.md#gaspriority)*

*Defined in [DealerClient.ts:81](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/df02572/src/DealerClient.ts#L81)*

Transaction priority (according to ethgasstation.info API), defaults to
fast.

___

### web3

• **web3**: *Web3*

*Defined in [DealerClient.ts:48](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/e458263/src/DealerClient.ts#L48)*
*Defined in [DealerClient.ts:51](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/df02572/src/DealerClient.ts#L51)*

Main Web3 instance for interacting with Ethereum.

Expand All @@ -182,7 +194,7 @@ ___

• **web3Wrapper**: *Web3Wrapper*

*Defined in [DealerClient.ts:51](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/e458263/src/DealerClient.ts#L51)*
*Defined in [DealerClient.ts:54](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/df02572/src/DealerClient.ts#L54)*

Provides additional convenience methods for interacting with web3.

Expand All @@ -192,7 +204,7 @@ ___

▪ **MAX_ALLOWANCE**: *BigNumber* = new BigNumber(2).exponentiatedBy(256).minus(1)

*Defined in [DealerClient.ts:23](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/e458263/src/DealerClient.ts#L23)*
*Defined in [DealerClient.ts:26](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/df02572/src/DealerClient.ts#L26)*

2^256 - 1 represents an effectively "unlimited" allowance

Expand All @@ -202,7 +214,7 @@ ___

▸ **fromWei**(`weiAmount`: string): *string*

*Defined in [DealerClient.ts:426](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/e458263/src/DealerClient.ts#L426)*
*Defined in [DealerClient.ts:420](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/df02572/src/DealerClient.ts#L420)*

Convert a number of tokens, denominated in the smallest unit - "wei" - to
"full" units, called "ether". One ether = 1*10^18 wei.
Expand Down Expand Up @@ -232,7 +244,7 @@ ___

▸ **getBalance**(`tokenTicker`: string): *Promise‹string›*

*Defined in [DealerClient.ts:376](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/e458263/src/DealerClient.ts#L376)*
*Defined in [DealerClient.ts:370](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/df02572/src/DealerClient.ts#L370)*

Return the user's balance (in wei) of a specified supported token. Only
supported tickers will work (see `client.tokens`).
Expand Down Expand Up @@ -262,7 +274,7 @@ ___

▸ **getEtherscanLink**(`txId`: string): *string*

*Defined in [DealerClient.ts:460](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/e458263/src/DealerClient.ts#L460)*
*Defined in [DealerClient.ts:454](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/df02572/src/DealerClient.ts#L454)*

Returns the URL of the Etherscan status page for the specified TX ID.

Expand All @@ -282,9 +294,9 @@ ___

### getQuote

▸ **getQuote**(`size`: number, `symbol`: string, `side`: string): *Promise‹[DealerResponse](../interfaces/dealerresponse.md)›*
▸ **getQuote**(`size`: number, `symbol`: string, `side`: string): *Promise‹[QuoteResponse](../interfaces/quoteresponse.md)›*

*Defined in [DealerClient.ts:178](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/e458263/src/DealerClient.ts#L178)*
*Defined in [DealerClient.ts:183](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/df02572/src/DealerClient.ts#L183)*

Request a price quote a signed order from the dealer server. The response
includes price and fee information, as well as signed 0x order message for
Expand Down Expand Up @@ -317,17 +329,17 @@ Name | Type | Description |
`symbol` | string | the token pair the swap is for (ex: "WETH/DAI") |
`side` | string | either 'bid' or 'ask' depending on desired quote side |

**Returns:** *Promise‹[DealerResponse](../interfaces/dealerresponse.md)›*
**Returns:** *Promise‹[QuoteResponse](../interfaces/quoteresponse.md)›*

a price quote and signed maker order from the dealer server

___

### getSwapQuote

▸ **getSwapQuote**(`size`: number, `clientAsset`: string, `dealerAsset`: string): *Promise‹[DealerResponse](../interfaces/dealerresponse.md)›*
▸ **getSwapQuote**(`size`: number, `clientAsset`: string, `dealerAsset`: string): *Promise‹[SwapResponse](../interfaces/swapresponse.md)›*

*Defined in [DealerClient.ts:216](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/e458263/src/DealerClient.ts#L216)*
*Defined in [DealerClient.ts:221](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/df02572/src/DealerClient.ts#L221)*

An alternative interface for fetching a price quote using the concept of
an asset "swap" as opposed to a conventional base/quote bid/ask interface.
Expand Down Expand Up @@ -359,21 +371,21 @@ Name | Type | Description |
`clientAsset` | string | the ticker of the asset being sold (swapping for dealerAsset) |
`dealerAsset` | string | the ticker of the asset being bought that a price is quoted for |

**Returns:** *Promise‹[DealerResponse](../interfaces/dealerresponse.md)›*
**Returns:** *Promise‹[SwapResponse](../interfaces/swapresponse.md)›*

A price quote and signed maker order from the dealer server.

___

### handleTrade

▸ **handleTrade**(`order`: SignedOrder, `quoteId`: string): *Promise‹string›*
▸ **handleTrade**(`order`: SignedOrder, `quoteId`: string, `takerAddress`: string): *Promise‹string›*

*Defined in [DealerClient.ts:262](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/e458263/src/DealerClient.ts#L262)*
*Defined in [DealerClient.ts:267](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/df02572/src/DealerClient.ts#L267)*

Sign a 0x `fillOrder` transaction message, and submit it back to the
server for settlement. Signs a fill transaction for the entire specified
`takerAssetAmount`.
`takerAssetAmount`. Implements ZEIP-18 signing of the provided `order` object.

Allowances should be checked prior to calling this method.

Expand All @@ -396,10 +408,11 @@ await dealer.waitForTransactionSuccessOrThrow(txId);

**Parameters:**

Name | Type | Description |
------ | ------ | ------ |
`order` | SignedOrder | The signed maker order to submit for execution. |
`quoteId` | string | The unique quote UUID provided by the dealer server. |
Name | Type | Default | Description |
------ | ------ | ------ | ------ |
`order` | SignedOrder | - | The signed maker order to submit for execution. |
`quoteId` | string | - | The unique quote UUID provided by the dealer server. |
`takerAddress` | string | this.coinbase | - |

**Returns:** *Promise‹string›*

Expand All @@ -411,7 +424,7 @@ ___

▸ **hasAllowance**(`tokenTicker`: string): *Promise‹boolean›*

*Defined in [DealerClient.ts:320](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/e458263/src/DealerClient.ts#L320)*
*Defined in [DealerClient.ts:312](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/df02572/src/DealerClient.ts#L312)*

Check if the user has set an allowance for the specified token. If the
method returns `false`, allowance can be set with `client.setAllowance`.
Expand Down Expand Up @@ -444,7 +457,7 @@ ___

▸ **init**(): *Promise‹void›*

*Defined in [DealerClient.ts:116](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/e458263/src/DealerClient.ts#L116)*
*Defined in [DealerClient.ts:125](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/df02572/src/DealerClient.ts#L125)*

Initialize a DealerClient instance. A call to `client.init()` will trigger
a MetaMask pop-up prompting the user to sign in, or allow the site access.
Expand All @@ -461,7 +474,7 @@ ___

▸ **makeBigNumber**(`n`: number | string): *BigNumber*

*Defined in [DealerClient.ts:405](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/e458263/src/DealerClient.ts#L405)*
*Defined in [DealerClient.ts:399](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/df02572/src/DealerClient.ts#L399)*

Turn a `string` or primitive `number` into a `BigNumber` for math reasons.

Expand All @@ -487,7 +500,7 @@ ___

▸ **setAllowance**(`tokenTicker`: string): *Promise‹TransactionReceiptWithDecodedLogs›*

*Defined in [DealerClient.ts:354](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/e458263/src/DealerClient.ts#L354)*
*Defined in [DealerClient.ts:346](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/df02572/src/DealerClient.ts#L346)*

Set an unlimited proxy allowance for the 0x ERC20 Proxy contract for the
specified token ticker.
Expand Down Expand Up @@ -522,7 +535,7 @@ ___

▸ **supportedTickers**(): *string[]*

*Defined in [DealerClient.ts:483](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/e458263/src/DealerClient.ts#L483)*
*Defined in [DealerClient.ts:477](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/df02572/src/DealerClient.ts#L477)*

Return an array containing the list of supported token tickers.

Expand All @@ -541,7 +554,7 @@ ___

▸ **toWei**(`etherAmount`: string): *string*

*Defined in [DealerClient.ts:447](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/e458263/src/DealerClient.ts#L447)*
*Defined in [DealerClient.ts:441](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/df02572/src/DealerClient.ts#L441)*

Convert a number of tokens (full units, called "ether") to "wei", the
smallest denomination of most ERC-20 tokens with 18 decimals.
Expand Down Expand Up @@ -571,7 +584,7 @@ ___

▸ **waitForTransactionSuccessOrThrow**(`txId`: string): *Promise‹void›*

*Defined in [DealerClient.ts:388](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/e458263/src/DealerClient.ts#L388)*
*Defined in [DealerClient.ts:382](https://github.com/ParadigmFoundation/zaidan-dealer-client/blob/df02572/src/DealerClient.ts#L382)*

Wait for a specific Ethereum transaction to be successfully mined.

Expand Down
Loading