diff options
author | Fabio Berger <me@fabioberger.com> | 2018-03-02 21:44:53 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-03-02 21:44:53 +0800 |
commit | 406aedfdc2062ecbdbc6db4a53ae2bb945fb79d3 (patch) | |
tree | d2b21e04c65608dcef473da44b902a9efa12016e /packages/testnet-faucets/src/ts/dispense_asset_tasks.ts | |
parent | 67c834841ea0f8fb4d8d194c0f68802f48e764ee (diff) | |
parent | 4a57f2a762619932a882d08e62006e83a584a684 (diff) | |
download | dexon-sol-tools-406aedfdc2062ecbdbc6db4a53ae2bb945fb79d3.tar dexon-sol-tools-406aedfdc2062ecbdbc6db4a53ae2bb945fb79d3.tar.gz dexon-sol-tools-406aedfdc2062ecbdbc6db4a53ae2bb945fb79d3.tar.bz2 dexon-sol-tools-406aedfdc2062ecbdbc6db4a53ae2bb945fb79d3.tar.lz dexon-sol-tools-406aedfdc2062ecbdbc6db4a53ae2bb945fb79d3.tar.xz dexon-sol-tools-406aedfdc2062ecbdbc6db4a53ae2bb945fb79d3.tar.zst dexon-sol-tools-406aedfdc2062ecbdbc6db4a53ae2bb945fb79d3.zip |
Merge branch 'development' into fix/doc_bugs
* development: (21 commits)
Adjust the tests
Move tutorials to adhere to current dir structure
Make tests slightly nicer
Remove only
Improve the comments
Improve the comments
Add comments to Arbitrage contract
Don't pass tokenGet and tokenGive because we can get them from 0x order
Pretty-print ED contracts
Make external
Fix a typo
Change type to uint256
Make setAllowances external
Fix the comment
Put all ED contracts in one folder
Move tutorials contracts to src folder
Remove false-positive linter failure because of chai-as-pronmised incorrect types
Assert that the balances don't change if arbitrage fails
Initial implementation of Arbitrage contract with tests
Set max to 2 ETH/2 ZRX
...
Diffstat (limited to 'packages/testnet-faucets/src/ts/dispense_asset_tasks.ts')
-rw-r--r-- | packages/testnet-faucets/src/ts/dispense_asset_tasks.ts | 21 |
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, |