aboutsummaryrefslogtreecommitdiffstats
path: root/packages/testnet-faucets/src/ts
diff options
context:
space:
mode:
authorJacob Evans <jacob@dekz.net>2018-02-27 10:45:56 +0800
committerJacob Evans <jacob@dekz.net>2018-02-27 13:15:11 +0800
commitaddca63938c459635aba777104bab05dee0a5183 (patch)
tree711d1be1be3e69639a5fcd222d22bc3888484ff8 /packages/testnet-faucets/src/ts
parent709fa9e02ec21cee9fc145b4a578742c8dd190aa (diff)
downloaddexon-sol-tools-addca63938c459635aba777104bab05dee0a5183.tar
dexon-sol-tools-addca63938c459635aba777104bab05dee0a5183.tar.gz
dexon-sol-tools-addca63938c459635aba777104bab05dee0a5183.tar.bz2
dexon-sol-tools-addca63938c459635aba777104bab05dee0a5183.tar.lz
dexon-sol-tools-addca63938c459635aba777104bab05dee0a5183.tar.xz
dexon-sol-tools-addca63938c459635aba777104bab05dee0a5183.tar.zst
dexon-sol-tools-addca63938c459635aba777104bab05dee0a5183.zip
Prevent a single account from draining the faucet
Diffstat (limited to 'packages/testnet-faucets/src/ts')
-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..fd7350704 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 = 5;
+const DISPENSE_MAX_AMOUNT_ETHER = 5;
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.greaterThan(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.greaterThan(maxAmountBaseUnits)) {
+ utils.consoleLog(
+ `User exceeded token balance maximum (${maxAmountBaseUnits}) ${recipientAddress} ${userBalanceBaseUnits} `,
+ );
+ return;
+ }
const txHash = await zeroEx.token.transferAsync(
token.address,
configs.DISPENSER_ADDRESS,