@kosu/create-portal-helper
v0.2.1
Published
Abstraction library for simplifying web-portal interactions.
Downloads
4
Readme
Create
Kind: global class
- Create
- new Create()
- .init()
- .createAndSignOrder(options)
- .signAndPost(signedZeroExOrder)
- .convertToWei(etherAmount) ⇒ Promise.<string>
- .convertFromWei(weiAmount) ⇒ Promise.<string>
- .isValidAddress(address) ⇒ boolean
- .userHasBond(userAddress) ⇒ Promise.<boolean>
- .awaitTransactionSuccessOrThrow(txID) ⇒
- .getUserWethBalance(userAddress) ⇒ Promise.<BigNumber>
- .getUserWethAllowance(userAddress) ⇒ Promise.<BigNumber>
- .setProxyAllowanceWeth(userAddress) ⇒ string
- .getUserZrxBalance(userAddress) ⇒ Promise.<BigNumber>
- .getUserZrxAllowance(userAddress) ⇒ Promise.<BigNumber>
- .setProxyAllowanceZrx(userAddress) ⇒ Promise.<string>
- .getUserDaiBalance(userAddress) ⇒ Promise.<BigNumber>
- .getUserDaiAllowance(userAddress) ⇒ Promise.<BigNumber>
- .setProxyAllowanceDai(userAddress) ⇒ Promise.<string>
- .getUserCustomBalance(tokenAddress, userAddress) ⇒ Promise.<BigNumber>
- .getUserCustomAllowance(tokenAddress, userAddress) ⇒ Promise.<BigNumber>
- .setProxyAllowanceCustom(tokenAddress, userAddress) ⇒ Promise.<string>
new Create()
create.init()
Kind: instance method of Create
create.createAndSignOrder(options)
Kind: instance method of Create
| Param | Type | Description | | ------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | options | object | object with the following properties: makerAssetAddress: either ("WETH/DAI/ZRX") or a full 42 char hex address takerAssetAddress: either ("WETH/DAI/ZRX") or a full 42 char hex address makerAssetAmount: units are wei, value can be string/number or BigNumber takerAssetAmount: units are wei, value can be string/number or BigNumber orderDuration: the number of seconds the order should be valid for makerAddress: can be provided to override coinbase, but shouldn't |
Example
// create an order for 0.5 WETH <> 80 custom token, valid for 10 minutes
let order = await create.createAndSignOrder({
makerAssetAddress: "WETH",
takerAssetAddress: "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2",
makerAssetAmount: create.convertToWei("0.5"),
takerAssetAmount: create.convertToWei("80"),
orderDuration: 600,
});
create.signAndPost(signedZeroExOrder)
Kind: instance method of Create
Todo:: - undo split-network ugly-ness
- don't pull
makerArguments
from subcontract if provided - ability to use direct kosu.js to sign
| Param | Type | Description | | ----------------- | ------------------- | -------------------------------------------------------- | | signedZeroExOrder | object | as outputted from createAndSignOrder |
create.convertToWei(etherAmount) ⇒ Promise.<string>
Kind: instance method of Create
Returns: Promise.<string> - the same amount in wei
| Param | Type | Description | | ----------- | --------------------------------------------- | ----------------------------------------------- | | etherAmount | string | BigNumber | a number of tokens in full units (ether) |
Example
// convert 100 tokens (as entered by user) to wei
create.convertToWei("100"); // > "100000000000000000000" (BigNumber)
create.convertToWei(100); // > "100000000000000000000" (BigNumber)
create.convertFromWei(weiAmount) ⇒ Promise.<string>
Kind: instance method of Create
Returns: Promise.<string> - the same amount in ether
| Param | Type | Description | | --------- | --------------------------------------------- | ------------------------------------------------- | | weiAmount | string | BigNumber | a number of tokens in smallest units (wei) |
Example
// convert 100 tokens (as received as balance or allowance) to tokens
create.convertToWei("100000000000000000000"); // > "100" (BigNumber)
create.convertToWei(100000000000000000000); // > "100" (BigNumber)
create.isValidAddress(address) ⇒ boolean
Kind: instance method of Create
Returns: boolean - true if valid Ethereum address, otherwise false
| Param | Type | Description | | ------- | ------------------- | ------------------------------------------------------ | | address | string | a string to be validated as an Ethereum address |
Example
create.isValidAddress("0x4f833a24e1f95d70f028921e27040ca56e09ab0b"); // > true
create.isValidAddress("4f833a24e1f95d70f028921e27040ca56e09ab0b"); // > false
create.isValidAddress("0x4f833a24e1f95d70f028921e27040ca56e09ab0"); // > false
create.userHasBond(userAddress) ⇒ Promise.<boolean>
Kind: instance method of Create
Returns: Promise.<boolean> - true if user has active bond, false otherwise
| Param | Type | Description | | ----------- | ------------------- | ---------------------------------------------------------- | | userAddress | string | can be provided to override coinbase, but shouldn't |
create.awaitTransactionSuccessOrThrow(txID) ⇒
Kind: instance method of Create
Returns: the full decoded transaction receipt (usually will not need)
| Param | Type | Description | | ----- | ------------------- | ----------------------------------------------------- | | txID | string | 32 byte (64-char) 0x-prefixed transaction hash |
Example
const txId = await create.setProxyAllowanceWeth();
// wait for the transaction to be mined, show loading icon, etc.
await create.awaitTransactionSuccessOrThrow(txId);
create.getUserWethBalance(userAddress) ⇒ Promise.<BigNumber>
Kind: instance method of Create
Returns: Promise.<BigNumber> - the user's WETH balance in wei
| Param | Type | Description | | ----------- | ------------------- | ------------------------------------------------ | | userAddress | string | override user's detected coinbase address |
create.getUserWethAllowance(userAddress) ⇒ Promise.<BigNumber>
Kind: instance method of Create
Returns: Promise.<BigNumber> - the user's 0x proxy WETH allowance in wei
| Param | Type | Description | | ----------- | ------------------- | ------------------------------------------------ | | userAddress | string | override user's detected coinbase address |
create.setProxyAllowanceWeth(userAddress) ⇒ string
Kind: instance method of Create
Returns: string - the transaction hash of the resulting tx
| Param | Type | Description | | ----------- | ------------------- | ------------------------------------------------ | | userAddress | string | override user's detected coinbase address |
create.getUserZrxBalance(userAddress) ⇒ Promise.<BigNumber>
Kind: instance method of Create
Returns: Promise.<BigNumber> - the user's ZRX balance in wei
| Param | Type | Description | | ----------- | ------------------- | ------------------------------------------------ | | userAddress | string | override user's detected coinbase address |
create.getUserZrxAllowance(userAddress) ⇒ Promise.<BigNumber>
Kind: instance method of Create
Returns: Promise.<BigNumber> - the user's 0x proxy ZRX allowance in wei
| Param | Type | Description | | ----------- | ------------------- | ------------------------------------------------ | | userAddress | string | override user's detected coinbase address |
create.setProxyAllowanceZrx(userAddress) ⇒ Promise.<string>
Kind: instance method of Create
Returns: Promise.<string> - the transaction hash of the resulting tx
| Param | Type | Description | | ----------- | ------------------- | ------------------------------------------------ | | userAddress | string | override user's detected coinbase address |
create.getUserDaiBalance(userAddress) ⇒ Promise.<BigNumber>
Kind: instance method of Create
Returns: Promise.<BigNumber> - the user's DAI balance in wei
| Param | Type | Description | | ----------- | ------------------- | ------------------------------------------------ | | userAddress | string | override user's detected coinbase address |
create.getUserDaiAllowance(userAddress) ⇒ Promise.<BigNumber>
Kind: instance method of Create
Returns: Promise.<BigNumber> - the user's 0x proxy DAI allowance in wei
| Param | Type | Description | | ----------- | ------------------- | ------------------------------------------------ | | userAddress | string | override user's detected coinbase address |
create.setProxyAllowanceDai(userAddress) ⇒ Promise.<string>
Kind: instance method of Create
Returns: Promise.<string> - the transaction hash of the resulting tx
| Param | Type | Description | | ----------- | ------------------- | ------------------------------------------------ | | userAddress | string | override user's detected coinbase address |
create.getUserCustomBalance(tokenAddress, userAddress) ⇒ Promise.<BigNumber>
Kind: instance method of Create
Returns: Promise.<BigNumber> - the user's balance in wei of custom token
| Param | Type | Description | | ------------ | ------------------- | ------------------------------------------------ | | tokenAddress | string | 0x-prefixed address of the custom token | | userAddress | string | override user's detected coinbase address |
Example
const balance = await create.getUserCustomBalance("0x4f833a24e1f95d70f028921e27040ca56e09ab0b");
create.getUserCustomAllowance(tokenAddress, userAddress) ⇒ Promise.<BigNumber>
Kind: instance method of Create
Returns: Promise.<BigNumber> - the user's 0x proxy allowance in wei for custom token
| Param | Type | Description | | ------------ | ------------------- | ------------------------------------------------ | | tokenAddress | string | 0x-prefixed address of the custom token | | userAddress | string | override user's detected coinbase address |
Example
const allowance = await create.getUserCustomAllowance("0x4f833a24e1f95d70f028921e27040ca56e09ab0b");
create.setProxyAllowanceCustom(tokenAddress, userAddress) ⇒ Promise.<string>
Kind: instance method of Create
Returns: Promise.<string> - the transaction hash of the resulting tx
| Param | Type | Description | | ------------ | ------------------- | ------------------------------------------------ | | tokenAddress | string | 0x-prefixed address of the custom token | | userAddress | string | override user's detected coinbase address |
Example
await create.setProxyAllowanceCustom("0x4f833a24e1f95d70f028921e27040ca56e09ab0b");