aboutsummaryrefslogtreecommitdiffstats
path: root/packages/testnet-faucets/src/ts/dispense_asset_tasks.ts
diff options
context:
space:
mode:
authorBrandon Millman <brandon@0xproject.com>2018-02-08 03:16:24 +0800
committerGitHub <noreply@github.com>2018-02-08 03:16:24 +0800
commit852811b314de3d62ee9068e3c5cbcfaa0650b058 (patch)
tree2740ad3525a18986ebf09e7e24bba2a755fc35f4 /packages/testnet-faucets/src/ts/dispense_asset_tasks.ts
parente443cb2a3b58003c5e0dffc0ea2aaa955fc12366 (diff)
parent2404ff030422e5ad021536135d57a19e98bedcd8 (diff)
downloaddexon-0x-contracts-852811b314de3d62ee9068e3c5cbcfaa0650b058.tar.gz
dexon-0x-contracts-852811b314de3d62ee9068e3c5cbcfaa0650b058.tar.zst
dexon-0x-contracts-852811b314de3d62ee9068e3c5cbcfaa0650b058.zip
Merge pull request #375 from 0xProject/feature/testnet-faucets/queue-by-network
Organize async task queues by network
Diffstat (limited to 'packages/testnet-faucets/src/ts/dispense_asset_tasks.ts')
-rw-r--r--packages/testnet-faucets/src/ts/dispense_asset_tasks.ts44
1 files changed, 44 insertions, 0 deletions
diff --git a/packages/testnet-faucets/src/ts/dispense_asset_tasks.ts b/packages/testnet-faucets/src/ts/dispense_asset_tasks.ts
new file mode 100644
index 000000000..9aa47463c
--- /dev/null
+++ b/packages/testnet-faucets/src/ts/dispense_asset_tasks.ts
@@ -0,0 +1,44 @@
+import { ZeroEx } from '0x.js';
+import { BigNumber, promisify } from '@0xproject/utils';
+import * as _ from 'lodash';
+import * as Web3 from 'web3';
+
+import { configs } from './configs';
+import { errorReporter } from './error_reporter';
+import { utils } from './utils';
+
+const DISPENSE_AMOUNT_ETHER = 0.1;
+const DISPENSE_AMOUNT_TOKEN = 0.1;
+
+export const dispenseAssetTasks = {
+ dispenseEtherTask(recipientAddress: string, web3: Web3) {
+ return async () => {
+ utils.consoleLog(`Processing ETH ${recipientAddress}`);
+ const sendTransactionAsync = promisify(web3.eth.sendTransaction);
+ const txHash = await sendTransactionAsync({
+ from: configs.DISPENSER_ADDRESS,
+ to: recipientAddress,
+ value: web3.toWei(DISPENSE_AMOUNT_ETHER, 'ether'),
+ });
+ utils.consoleLog(`Sent ${DISPENSE_AMOUNT_ETHER} ETH to ${recipientAddress} tx: ${txHash}`);
+ };
+ },
+ dispenseTokenTask(recipientAddress: string, tokenSymbol: string, zeroEx: ZeroEx) {
+ return async () => {
+ utils.consoleLog(`Processing ${tokenSymbol} ${recipientAddress}`);
+ const amountToDispense = new BigNumber(DISPENSE_AMOUNT_TOKEN);
+ const token = await zeroEx.tokenRegistry.getTokenBySymbolIfExistsAsync(tokenSymbol);
+ if (_.isUndefined(token)) {
+ throw new Error(`Unsupported asset type: ${tokenSymbol}`);
+ }
+ const baseUnitAmount = ZeroEx.toBaseUnitAmount(amountToDispense, token.decimals);
+ const txHash = await zeroEx.token.transferAsync(
+ token.address,
+ configs.DISPENSER_ADDRESS,
+ recipientAddress,
+ baseUnitAmount,
+ );
+ utils.consoleLog(`Sent ${amountToDispense} ZRX to ${recipientAddress} tx: ${txHash}`);
+ };
+ },
+};