aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/src/contract_wrappers/token_wrapper.ts
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-11-24 01:14:21 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-11-28 07:35:55 +0800
commit7a21c6854bec32f9a36e8ca3de14a815e9c9fa7d (patch)
treed86868444bc75f746ebd5d22acdaf853a795629e /packages/0x.js/src/contract_wrappers/token_wrapper.ts
parent54ef916b93ba0939dcb8824149c9a9fb74df4f2e (diff)
downloaddexon-sol-tools-7a21c6854bec32f9a36e8ca3de14a815e9c9fa7d.tar
dexon-sol-tools-7a21c6854bec32f9a36e8ca3de14a815e9c9fa7d.tar.gz
dexon-sol-tools-7a21c6854bec32f9a36e8ca3de14a815e9c9fa7d.tar.bz2
dexon-sol-tools-7a21c6854bec32f9a36e8ca3de14a815e9c9fa7d.tar.lz
dexon-sol-tools-7a21c6854bec32f9a36e8ca3de14a815e9c9fa7d.tar.xz
dexon-sol-tools-7a21c6854bec32f9a36e8ca3de14a815e9c9fa7d.tar.zst
dexon-sol-tools-7a21c6854bec32f9a36e8ca3de14a815e9c9fa7d.zip
Add option config for gasPrice and gasLimit for every transaction sending method
Diffstat (limited to 'packages/0x.js/src/contract_wrappers/token_wrapper.ts')
-rw-r--r--packages/0x.js/src/contract_wrappers/token_wrapper.ts41
1 files changed, 26 insertions, 15 deletions
diff --git a/packages/0x.js/src/contract_wrappers/token_wrapper.ts b/packages/0x.js/src/contract_wrappers/token_wrapper.ts
index 5c6cfeaed..4a1dfcf8d 100644
--- a/packages/0x.js/src/contract_wrappers/token_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/token_wrapper.ts
@@ -12,6 +12,7 @@ import {
TokenContract,
TokenContractEventArgs,
TokenEvents,
+ TransactionOpts,
ZeroExError,
} from '../types';
import {AbiDecoder} from '../utils/abi_decoder';
@@ -66,24 +67,21 @@ export class TokenWrapper extends ContractWrapper {
* for spenderAddress.
* @param spenderAddress The hex encoded user Ethereum address who will be able to spend the set allowance.
* @param amountInBaseUnits The allowance amount you would like to set.
+ * @param txOpts Transaction parameters.
* @return Transaction hash.
*/
public async setAllowanceAsync(tokenAddress: string, ownerAddress: string, spenderAddress: string,
- amountInBaseUnits: BigNumber): Promise<string> {
+ amountInBaseUnits: BigNumber, txOpts: TransactionOpts = {}): Promise<string> {
await assert.isSenderAddressAsync('ownerAddress', ownerAddress, this._web3Wrapper);
assert.isETHAddressHex('spenderAddress', spenderAddress);
assert.isETHAddressHex('tokenAddress', tokenAddress);
assert.isValidBaseUnitAmount('amountInBaseUnits', amountInBaseUnits);
const tokenContract = await this._getTokenContractAsync(tokenAddress);
- // Hack: for some reason default estimated gas amount causes `base fee exceeds gas limit` exception
- // on testrpc. Probably related to https://github.com/ethereumjs/testrpc/issues/294
- // TODO: Debug issue in testrpc and submit a PR, then remove this hack
- const networkId = this._web3Wrapper.getNetworkId();
- const gas = networkId === constants.TESTRPC_NETWORK_ID ? ALLOWANCE_TO_ZERO_GAS_AMOUNT : undefined;
const txHash = await tokenContract.approve.sendTransactionAsync(spenderAddress, amountInBaseUnits, {
from: ownerAddress,
- gas,
+ gas: txOpts.gasLimit,
+ gasPrice: txOpts.gasPrice,
});
return txHash;
}
@@ -96,12 +94,13 @@ export class TokenWrapper extends ContractWrapper {
* @param ownerAddress The hex encoded user Ethereum address who would like to set an allowance
* for spenderAddress.
* @param spenderAddress The hex encoded user Ethereum address who will be able to spend the set allowance.
+ * @param txOpts Transaction parameters.
* @return Transaction hash.
*/
public async setUnlimitedAllowanceAsync(tokenAddress: string, ownerAddress: string,
- spenderAddress: string): Promise<string> {
+ spenderAddress: string, txOpts: TransactionOpts = {}): Promise<string> {
const txHash = await this.setAllowanceAsync(
- tokenAddress, ownerAddress, spenderAddress, this.UNLIMITED_ALLOWANCE_IN_BASE_UNITS,
+ tokenAddress, ownerAddress, spenderAddress, this.UNLIMITED_ALLOWANCE_IN_BASE_UNITS, txOpts,
);
return txHash;
}
@@ -147,16 +146,19 @@ export class TokenWrapper extends ContractWrapper {
* @param ownerAddress The hex encoded user Ethereum address who is setting an allowance
* for the Proxy contract.
* @param amountInBaseUnits The allowance amount specified in baseUnits.
+ * @param txOpts Transaction parameters.
* @return Transaction hash.
*/
public async setProxyAllowanceAsync(tokenAddress: string, ownerAddress: string,
- amountInBaseUnits: BigNumber): Promise<string> {
+ amountInBaseUnits: BigNumber, txOpts: TransactionOpts = {}): Promise<string> {
assert.isETHAddressHex('ownerAddress', ownerAddress);
assert.isETHAddressHex('tokenAddress', tokenAddress);
assert.isValidBaseUnitAmount('amountInBaseUnits', amountInBaseUnits);
const proxyAddress = this._tokenTransferProxyWrapper.getContractAddress();
- const txHash = await this.setAllowanceAsync(tokenAddress, ownerAddress, proxyAddress, amountInBaseUnits);
+ const txHash = await this.setAllowanceAsync(
+ tokenAddress, ownerAddress, proxyAddress, amountInBaseUnits, txOpts,
+ );
return txHash;
}
/**
@@ -167,11 +169,14 @@ export class TokenWrapper extends ContractWrapper {
* @param tokenAddress The hex encoded contract Ethereum address where the ERC20 token is deployed.
* @param ownerAddress The hex encoded user Ethereum address who is setting an allowance
* for the Proxy contract.
+ * @param txOpts Transaction parameters.
* @return Transaction hash.
*/
- public async setUnlimitedProxyAllowanceAsync(tokenAddress: string, ownerAddress: string): Promise<string> {
+ public async setUnlimitedProxyAllowanceAsync(
+ tokenAddress: string, ownerAddress: string, txOpts: TransactionOpts = {},
+ ): Promise<string> {
const txHash = await this.setProxyAllowanceAsync(
- tokenAddress, ownerAddress, this.UNLIMITED_ALLOWANCE_IN_BASE_UNITS,
+ tokenAddress, ownerAddress, this.UNLIMITED_ALLOWANCE_IN_BASE_UNITS, txOpts,
);
return txHash;
}
@@ -181,10 +186,11 @@ export class TokenWrapper extends ContractWrapper {
* @param fromAddress The hex encoded user Ethereum address that will send the funds.
* @param toAddress The hex encoded user Ethereum address that will receive the funds.
* @param amountInBaseUnits The amount (specified in baseUnits) of the token to transfer.
+ * @param txOpts Transaction parameters.
* @return Transaction hash.
*/
public async transferAsync(tokenAddress: string, fromAddress: string, toAddress: string,
- amountInBaseUnits: BigNumber): Promise<string> {
+ amountInBaseUnits: BigNumber, txOpts: TransactionOpts = {}): Promise<string> {
assert.isETHAddressHex('tokenAddress', tokenAddress);
await assert.isSenderAddressAsync('fromAddress', fromAddress, this._web3Wrapper);
assert.isETHAddressHex('toAddress', toAddress);
@@ -199,6 +205,8 @@ export class TokenWrapper extends ContractWrapper {
const txHash = await tokenContract.transfer.sendTransactionAsync(toAddress, amountInBaseUnits, {
from: fromAddress,
+ gas: txOpts.gasLimit,
+ gasPrice: txOpts.gasPrice,
});
return txHash;
}
@@ -213,10 +221,11 @@ export class TokenWrapper extends ContractWrapper {
* `fromAddress` must have set an allowance to the `senderAddress`
* before this call.
* @param amountInBaseUnits The amount (specified in baseUnits) of the token to transfer.
+ * @param txOpts Transaction parameters.
* @return Transaction hash.
*/
public async transferFromAsync(tokenAddress: string, fromAddress: string, toAddress: string,
- senderAddress: string, amountInBaseUnits: BigNumber):
+ senderAddress: string, amountInBaseUnits: BigNumber, txOpts: TransactionOpts = {}):
Promise<string> {
assert.isETHAddressHex('tokenAddress', tokenAddress);
assert.isETHAddressHex('fromAddress', fromAddress);
@@ -240,6 +249,8 @@ export class TokenWrapper extends ContractWrapper {
fromAddress, toAddress, amountInBaseUnits,
{
from: senderAddress,
+ gas: txOpts.gasLimit,
+ gasPrice: txOpts.gasPrice,
},
);
return txHash;