aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorJacob Evans <dekz@dekz.net>2018-03-01 06:40:17 +0800
committerGitHub <noreply@github.com>2018-03-01 06:40:17 +0800
commit451a0dacbe85d7a0d16ef007c1eb945a4c1977cb (patch)
treefdf446278f1a4056e86af2b8a9cfab8ed547dbd5 /packages
parente25cc301fddbc67f793ca0eb0f7635cdb9147a71 (diff)
parenta46199e37dddd255fbfa6339d9f5a2a4d035ee86 (diff)
downloaddexon-sol-tools-451a0dacbe85d7a0d16ef007c1eb945a4c1977cb.tar.gz
dexon-sol-tools-451a0dacbe85d7a0d16ef007c1eb945a4c1977cb.tar.zst
dexon-sol-tools-451a0dacbe85d7a0d16ef007c1eb945a4c1977cb.zip
Merge pull request #418 from 0xProject/feature/facuet/balance-check
Prevent a single account from draining the faucet
Diffstat (limited to 'packages')
-rw-r--r--packages/testnet-faucets/src/ts/dispense_asset_tasks.ts21
1 files changed, 21 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
index 9aa47463c..56b0a9e45 100644
--- a/packages/testnet-faucets/src/ts/dispense_asset_tasks.ts
+++ b/packages/testnet-faucets/src/ts/dispense_asset_tasks.ts
@@ -9,11 +9,21 @@ import { utils } from './utils';
const DISPENSE_AMOUNT_ETHER = 0.1;
const DISPENSE_AMOUNT_TOKEN = 0.1;
+const DISPENSE_MAX_AMOUNT_TOKEN = 2;
+const DISPENSE_MAX_AMOUNT_ETHER = 2;
export const dispenseAssetTasks = {
dispenseEtherTask(recipientAddress: string, web3: Web3) {
return async () => {
utils.consoleLog(`Processing ETH ${recipientAddress}`);
+ const userBalance = await promisify<BigNumber>(web3.eth.getBalance)(recipientAddress);
+ const maxAmountInWei = new BigNumber(web3.toWei(DISPENSE_MAX_AMOUNT_ETHER, 'ether'));
+ if (userBalance.greaterThanOrEqualTo(maxAmountInWei)) {
+ utils.consoleLog(
+ `User exceeded ETH balance maximum (${maxAmountInWei}) ${recipientAddress} ${userBalance} `,
+ );
+ return;
+ }
const sendTransactionAsync = promisify(web3.eth.sendTransaction);
const txHash = await sendTransactionAsync({
from: configs.DISPENSER_ADDRESS,
@@ -32,6 +42,17 @@ export const dispenseAssetTasks = {
throw new Error(`Unsupported asset type: ${tokenSymbol}`);
}
const baseUnitAmount = ZeroEx.toBaseUnitAmount(amountToDispense, token.decimals);
+ const userBalanceBaseUnits = await zeroEx.token.getBalanceAsync(token.address, recipientAddress);
+ const maxAmountBaseUnits = ZeroEx.toBaseUnitAmount(
+ new BigNumber(DISPENSE_MAX_AMOUNT_TOKEN),
+ token.decimals,
+ );
+ if (userBalanceBaseUnits.greaterThanOrEqualTo(maxAmountBaseUnits)) {
+ utils.consoleLog(
+ `User exceeded token balance maximum (${maxAmountBaseUnits}) ${recipientAddress} ${userBalanceBaseUnits} `,
+ );
+ return;
+ }
const txHash = await zeroEx.token.transferAsync(
token.address,
configs.DISPENSER_ADDRESS,