aboutsummaryrefslogtreecommitdiffstats
path: root/src/contract_wrappers
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-07-12 05:16:09 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-07-12 08:54:57 +0800
commit6033c1a5d5f494d1ed27b00488ca458952341ae6 (patch)
tree17b53c7971047ca57b235c5351e972da721c09a4 /src/contract_wrappers
parent38fbf028a6699c7d8e853db4699a37cdf60e70c2 (diff)
downloaddexon-sol-tools-6033c1a5d5f494d1ed27b00488ca458952341ae6.tar
dexon-sol-tools-6033c1a5d5f494d1ed27b00488ca458952341ae6.tar.gz
dexon-sol-tools-6033c1a5d5f494d1ed27b00488ca458952341ae6.tar.bz2
dexon-sol-tools-6033c1a5d5f494d1ed27b00488ca458952341ae6.tar.lz
dexon-sol-tools-6033c1a5d5f494d1ed27b00488ca458952341ae6.tar.xz
dexon-sol-tools-6033c1a5d5f494d1ed27b00488ca458952341ae6.tar.zst
dexon-sol-tools-6033c1a5d5f494d1ed27b00488ca458952341ae6.zip
Use PascalCase names as string enum keys
Diffstat (limited to 'src/contract_wrappers')
-rw-r--r--src/contract_wrappers/contract_wrapper.ts6
-rw-r--r--src/contract_wrappers/ether_token_wrapper.ts4
-rw-r--r--src/contract_wrappers/exchange_wrapper.ts80
-rw-r--r--src/contract_wrappers/token_wrapper.ts8
4 files changed, 63 insertions, 35 deletions
diff --git a/src/contract_wrappers/contract_wrapper.ts b/src/contract_wrappers/contract_wrapper.ts
index f9c1bc1cf..1cce1b235 100644
--- a/src/contract_wrappers/contract_wrapper.ts
+++ b/src/contract_wrappers/contract_wrapper.ts
@@ -28,7 +28,7 @@ export class ContractWrapper {
if (!_.isUndefined(contractAddress)) {
const doesContractExist = await this._web3Wrapper.doesContractExistAtAddressAsync(contractAddress);
if (!doesContractExist) {
- throw new Error(ZeroExError.CONTRACT_DOES_NOT_EXIST);
+ throw new Error(ZeroExError.ContractDoesNotExist);
}
}
@@ -38,10 +38,10 @@ export class ContractWrapper {
} catch (err) {
const errMsg = `${err}`;
if (_.includes(errMsg, 'not been deployed to detected network')) {
- throw new Error(ZeroExError.CONTRACT_DOES_NOT_EXIST);
+ throw new Error(ZeroExError.ContractDoesNotExist);
} else {
utils.consoleLog(`Notice: Error encountered: ${err} ${err.stack}`);
- throw new Error(ZeroExError.UNHANDLED_ERROR);
+ throw new Error(ZeroExError.UnhandledError);
}
}
}
diff --git a/src/contract_wrappers/ether_token_wrapper.ts b/src/contract_wrappers/ether_token_wrapper.ts
index 03d714bd7..ee0ac2d8c 100644
--- a/src/contract_wrappers/ether_token_wrapper.ts
+++ b/src/contract_wrappers/ether_token_wrapper.ts
@@ -29,7 +29,7 @@ export class EtherTokenWrapper extends ContractWrapper {
await assert.isSenderAddressAsync('depositor', depositor, this._web3Wrapper);
const ethBalanceInWei = await this._web3Wrapper.getBalanceInWeiAsync(depositor);
- assert.assert(ethBalanceInWei.gte(amountInWei), ZeroExError.INSUFFICIENT_ETH_BALANCE_FOR_DEPOSIT);
+ assert.assert(ethBalanceInWei.gte(amountInWei), ZeroExError.InsufficientEthBalanceForDeposit);
const wethContract = await this._getEtherTokenContractAsync();
await wethContract.deposit({
@@ -49,7 +49,7 @@ export class EtherTokenWrapper extends ContractWrapper {
const wethContractAddress = await this.getContractAddressAsync();
const WETHBalanceInBaseUnits = await this._tokenWrapper.getBalanceAsync(wethContractAddress, withdrawer);
- assert.assert(WETHBalanceInBaseUnits.gte(amountInWei), ZeroExError.INSUFFICIENT_WETH_BALANCE_FOR_WITHDRAWAL);
+ assert.assert(WETHBalanceInBaseUnits.gte(amountInWei), ZeroExError.InsufficientWEthBalanceForWithdrawal);
const wethContract = await this._getEtherTokenContractAsync();
await wethContract.withdraw(amountInWei, {
diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts
index a6eab0fa2..2501ef24b 100644
--- a/src/contract_wrappers/exchange_wrapper.ts
+++ b/src/contract_wrappers/exchange_wrapper.ts
@@ -57,12 +57,12 @@ import * as ExchangeArtifacts from '../artifacts/Exchange.json';
*/
export class ExchangeWrapper extends ContractWrapper {
private _exchangeContractErrCodesToMsg = {
- [ExchangeContractErrCodes.ERROR_FILL_EXPIRED]: ExchangeContractErrs.ORDER_FILL_EXPIRED,
- [ExchangeContractErrCodes.ERROR_CANCEL_EXPIRED]: ExchangeContractErrs.ORDER_FILL_EXPIRED,
- [ExchangeContractErrCodes.ERROR_FILL_NO_VALUE]: ExchangeContractErrs.ORDER_REMAINING_FILL_AMOUNT_ZERO,
- [ExchangeContractErrCodes.ERROR_CANCEL_NO_VALUE]: ExchangeContractErrs.ORDER_REMAINING_FILL_AMOUNT_ZERO,
- [ExchangeContractErrCodes.ERROR_FILL_TRUNCATION]: ExchangeContractErrs.ORDER_FILL_ROUNDING_ERROR,
- [ExchangeContractErrCodes.ERROR_FILL_BALANCE_ALLOWANCE]: ExchangeContractErrs.FILL_BALANCE_ALLOWANCE_ERROR,
+ [ExchangeContractErrCodes.ERROR_FILL_EXPIRED]: ExchangeContractErrs.OrderFillExpired,
+ [ExchangeContractErrCodes.ERROR_CANCEL_EXPIRED]: ExchangeContractErrs.OrderFillExpired,
+ [ExchangeContractErrCodes.ERROR_FILL_NO_VALUE]: ExchangeContractErrs.OrderRemainingFillAmountZero,
+ [ExchangeContractErrCodes.ERROR_CANCEL_NO_VALUE]: ExchangeContractErrs.OrderRemainingFillAmountZero,
+ [ExchangeContractErrCodes.ERROR_FILL_TRUNCATION]: ExchangeContractErrs.OrderFillRoundingError,
+ [ExchangeContractErrCodes.ERROR_FILL_BALANCE_ALLOWANCE]: ExchangeContractErrs.FillBalanceAllowanceError,
};
private _exchangeContractIfExists?: ExchangeContract;
private _exchangeLogEventEmitters: ContractEventEmitter[];
@@ -220,7 +220,10 @@ export class ExchangeWrapper extends ContractWrapper {
assert.doesConformToSchema('signedOrders', signedOrders, signedOrdersSchema);
const takerTokenAddresses = _.map(signedOrders, signedOrder => signedOrder.takerTokenAddress);
assert.hasAtMostOneUniqueValue(takerTokenAddresses,
- ExchangeContractErrs.MULTIPLE_TAKER_TOKENS_IN_FILL_UP_TO_DISALLOWED);
+ ExchangeContractErrs.MultipleTakerTokensInFillUpToDisallowed);
+ const exchangeContractAddresses = _.map(signedOrders, signedOrder => signedOrder.exchangeContractAddress);
+ assert.hasAtMostOneUniqueValue(exchangeContractAddresses,
+ ExchangeContractErrs.BatchOrdersMustHaveSameExchangeAddress);
assert.isBigNumber('fillTakerTokenAmount', fillTakerTokenAmount);
assert.isBoolean('shouldThrowOnInsufficientBalanceOrAllowance', shouldThrowOnInsufficientBalanceOrAllowance);
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
@@ -300,6 +303,12 @@ export class ExchangeWrapper extends ContractWrapper {
shouldThrowOnInsufficientBalanceOrAllowance: boolean,
takerAddress: string): Promise<void> {
assert.doesConformToSchema('orderFillRequests', orderFillRequests, orderFillRequestsSchema);
+ const exchangeContractAddresses = _.map(
+ orderFillRequests,
+ orderFillRequest => orderFillRequest.signedOrder.exchangeContractAddress,
+ );
+ assert.hasAtMostOneUniqueValue(exchangeContractAddresses,
+ ExchangeContractErrs.BatchOrdersMustHaveSameExchangeAddress);
assert.isBoolean('shouldThrowOnInsufficientBalanceOrAllowance', shouldThrowOnInsufficientBalanceOrAllowance);
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
for (const orderFillRequest of orderFillRequests) {
@@ -416,7 +425,7 @@ export class ExchangeWrapper extends ContractWrapper {
orderFillOrKillRequest => orderFillOrKillRequest.signedOrder.exchangeContractAddress,
);
assert.hasAtMostOneUniqueValue(exchangeContractAddresses,
- ExchangeContractErrs.BATCH_ORDERS_MUST_HAVE_SAME_EXCHANGE_ADDRESS);
+ ExchangeContractErrs.BatchOrdersMustHaveSameExchangeAddress);
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
if (_.isEmpty(orderFillOrKillRequests)) {
return; // no-op
@@ -520,9 +529,9 @@ export class ExchangeWrapper extends ContractWrapper {
orderCancellationRequest => orderCancellationRequest.order.exchangeContractAddress,
);
assert.hasAtMostOneUniqueValue(exchangeContractAddresses,
- ExchangeContractErrs.BATCH_ORDERS_MUST_HAVE_SAME_EXCHANGE_ADDRESS);
+ ExchangeContractErrs.BatchOrdersMustHaveSameExchangeAddress);
const makers = _.map(orderCancellationRequests, cancellationRequest => cancellationRequest.order.maker);
- assert.hasAtMostOneUniqueValue(makers, ExchangeContractErrs.MULTIPLE_MAKERS_IN_SINGLE_CANCEL_BATCH_DISALLOWED);
+ assert.hasAtMostOneUniqueValue(makers, ExchangeContractErrs.MultipleMakersInSingleCancelBatchDisallowed);
const maker = makers[0];
await assert.isSenderAddressAsync('maker', maker, this._web3Wrapper);
for (const cancellationRequest of orderCancellationRequests) {
@@ -648,14 +657,14 @@ export class ExchangeWrapper extends ContractWrapper {
fillTakerAmount: BigNumber.BigNumber,
senderAddress: string): Promise<void> {
if (fillTakerAmount.eq(0)) {
- throw new Error(ExchangeContractErrs.ORDER_REMAINING_FILL_AMOUNT_ZERO);
+ throw new Error(ExchangeContractErrs.OrderRemainingFillAmountZero);
}
if (signedOrder.taker !== constants.NULL_ADDRESS && signedOrder.taker !== senderAddress) {
- throw new Error(ExchangeContractErrs.TRANSACTION_SENDER_IS_NOT_FILL_ORDER_TAKER);
+ throw new Error(ExchangeContractErrs.TransactionSenderIsNotFillOrderTaker);
}
const currentUnixTimestampSec = utils.getCurrentUnixTimestamp();
if (signedOrder.expirationUnixTimestampSec.lessThan(currentUnixTimestampSec)) {
- throw new Error(ExchangeContractErrs.ORDER_FILL_EXPIRED);
+ throw new Error(ExchangeContractErrs.OrderFillExpired);
}
const zrxTokenAddress = await this._getZRXTokenAddressAsync(signedOrder.exchangeContractAddress);
await this._validateFillOrderBalancesAndAllowancesAndThrowIfInvalidAsync(signedOrder, fillTakerAmount,
@@ -665,22 +674,22 @@ export class ExchangeWrapper extends ContractWrapper {
signedOrder.takerTokenAmount, fillTakerAmount, signedOrder.makerTokenAmount,
);
if (wouldRoundingErrorOccur) {
- throw new Error(ExchangeContractErrs.ORDER_FILL_ROUNDING_ERROR);
+ throw new Error(ExchangeContractErrs.OrderFillRoundingError);
}
}
private async _validateCancelOrderAndThrowIfInvalidAsync(
order: Order, takerTokenCancelAmount: BigNumber.BigNumber): Promise<void> {
if (takerTokenCancelAmount.eq(0)) {
- throw new Error(ExchangeContractErrs.ORDER_CANCEL_AMOUNT_ZERO);
+ throw new Error(ExchangeContractErrs.OrderCancelAmountZero);
}
const orderHash = utils.getOrderHashHex(order);
const unavailableAmount = await this.getUnavailableTakerAmountAsync(orderHash);
if (order.takerTokenAmount.minus(unavailableAmount).eq(0)) {
- throw new Error(ExchangeContractErrs.ORDER_ALREADY_CANCELLED_OR_FILLED);
+ throw new Error(ExchangeContractErrs.OrderAlreadyCancelledOrFilled);
}
const currentUnixTimestampSec = utils.getCurrentUnixTimestamp();
if (order.expirationUnixTimestampSec.lessThan(currentUnixTimestampSec)) {
- throw new Error(ExchangeContractErrs.ORDER_CANCEL_EXPIRED);
+ throw new Error(ExchangeContractErrs.OrderCancelExpired);
}
}
private async _validateFillOrKillOrderAndThrowIfInvalidAsync(signedOrder: SignedOrder,
@@ -690,7 +699,7 @@ export class ExchangeWrapper extends ContractWrapper {
const unavailableTakerAmount = await this.getUnavailableTakerAmountAsync(orderHashHex);
const remainingTakerAmount = signedOrder.takerTokenAmount.minus(unavailableTakerAmount);
if (remainingTakerAmount < fillTakerAmount) {
- throw new Error(ExchangeContractErrs.INSUFFICIENT_REMAINING_FILL_AMOUNT);
+ throw new Error(ExchangeContractErrs.InsufficientRemainingFillAmount);
}
}
/**
@@ -721,16 +730,16 @@ export class ExchangeWrapper extends ContractWrapper {
const fillMakerAmountInBaseUnits = fillTakerAmount.div(exchangeRate);
if (fillTakerAmount.greaterThan(takerBalance)) {
- throw new Error(ExchangeContractErrs.INSUFFICIENT_TAKER_BALANCE);
+ throw new Error(ExchangeContractErrs.InsufficientTakerBalance);
}
if (fillTakerAmount.greaterThan(takerAllowance)) {
- throw new Error(ExchangeContractErrs.INSUFFICIENT_TAKER_ALLOWANCE);
+ throw new Error(ExchangeContractErrs.InsufficientTakerAllowance);
}
if (fillMakerAmountInBaseUnits.greaterThan(makerBalance)) {
- throw new Error(ExchangeContractErrs.INSUFFICIENT_MAKER_BALANCE);
+ throw new Error(ExchangeContractErrs.InsufficientMakerBalance);
}
if (fillMakerAmountInBaseUnits.greaterThan(makerAllowance)) {
- throw new Error(ExchangeContractErrs.INSUFFICIENT_MAKER_ALLOWANCE);
+ throw new Error(ExchangeContractErrs.InsufficientMakerAllowance);
}
const makerFeeBalance = await this._tokenWrapper.getBalanceAsync(zrxTokenAddress,
@@ -742,16 +751,16 @@ export class ExchangeWrapper extends ContractWrapper {
senderAddress);
if (signedOrder.takerFee.greaterThan(takerFeeBalance)) {
- throw new Error(ExchangeContractErrs.INSUFFICIENT_TAKER_FEE_BALANCE);
+ throw new Error(ExchangeContractErrs.InsufficientTakerFeeBalance);
}
if (signedOrder.takerFee.greaterThan(takerFeeAllowance)) {
- throw new Error(ExchangeContractErrs.INSUFFICIENT_TAKER_FEE_ALLOWANCE);
+ throw new Error(ExchangeContractErrs.InsufficientTakerFeeAllowance);
}
if (signedOrder.makerFee.greaterThan(makerFeeBalance)) {
- throw new Error(ExchangeContractErrs.INSUFFICIENT_MAKER_FEE_BALANCE);
+ throw new Error(ExchangeContractErrs.InsufficientMakerFeeBalance);
}
if (signedOrder.makerFee.greaterThan(makerFeeAllowance)) {
- throw new Error(ExchangeContractErrs.INSUFFICIENT_MAKER_FEE_ALLOWANCE);
+ throw new Error(ExchangeContractErrs.InsufficientMakerFeeAllowance);
}
}
private _throwErrorLogsAsErrors(logs: ContractEvent[]): void {
@@ -777,8 +786,27 @@ export class ExchangeWrapper extends ContractWrapper {
return this._exchangeContractIfExists;
}
const contractInstance = await this._instantiateContractIfExistsAsync((ExchangeArtifacts as any));
+<<<<<<< HEAD
this._exchangeContractIfExists = contractInstance as ExchangeContract;
return this._exchangeContractIfExists;
+=======
+ this._exchangeContractByAddress[exchangeContractAddress] = contractInstance as ExchangeContract;
+ return this._exchangeContractByAddress[exchangeContractAddress];
+ }
+ private _getExchangeArtifactsByAddressOrThrow(exchangeContractAddress: string): ContractArtifact {
+ const exchangeArtifacts = _.values<ContractArtifact>(ExchangeArtifactsByName);
+ for (const exchangeArtifact of exchangeArtifacts) {
+ const networkSpecificExchangeArtifactValues = _.values(exchangeArtifact.networks);
+ const exchangeAddressesInArtifact = _.map(
+ networkSpecificExchangeArtifactValues,
+ networkSpecificExchangeArtifact => networkSpecificExchangeArtifact.address,
+ );
+ if (_.includes(exchangeAddressesInArtifact, exchangeContractAddress)) {
+ return exchangeArtifact;
+ }
+ }
+ throw new Error(ZeroExError.ExchangeContractDoesNotExist);
+>>>>>>> Use PascalCase names as string enum keys
}
private async _getZRXTokenAddressAsync(exchangeContractAddress: string): Promise<string> {
const exchangeInstance = await this._getExchangeContractAsync();
diff --git a/src/contract_wrappers/token_wrapper.ts b/src/contract_wrappers/token_wrapper.ts
index fdf711823..9c073f30b 100644
--- a/src/contract_wrappers/token_wrapper.ts
+++ b/src/contract_wrappers/token_wrapper.ts
@@ -146,7 +146,7 @@ export class TokenWrapper extends ContractWrapper {
const fromAddressBalance = await this.getBalanceAsync(tokenAddress, fromAddress);
if (fromAddressBalance.lessThan(amountInBaseUnits)) {
- throw new Error(ZeroExError.INSUFFICIENT_BALANCE_FOR_TRANSFER);
+ throw new Error(ZeroExError.InsufficientBalanceForTransfer);
}
await tokenContract.transfer(toAddress, amountInBaseUnits, {
@@ -178,12 +178,12 @@ export class TokenWrapper extends ContractWrapper {
const fromAddressAllowance = await this.getAllowanceAsync(tokenAddress, fromAddress, senderAddress);
if (fromAddressAllowance.lessThan(amountInBaseUnits)) {
- throw new Error(ZeroExError.INSUFFICIENT_ALLOWANCE_FOR_TRANSFER);
+ throw new Error(ZeroExError.InsufficientAllowanceForTransfer);
}
const fromAddressBalance = await this.getBalanceAsync(tokenAddress, fromAddress);
if (fromAddressBalance.lessThan(amountInBaseUnits)) {
- throw new Error(ZeroExError.INSUFFICIENT_BALANCE_FOR_TRANSFER);
+ throw new Error(ZeroExError.InsufficientBalanceForTransfer);
}
await tokenContract.transferFrom(fromAddress, toAddress, amountInBaseUnits, {
@@ -252,7 +252,7 @@ export class TokenWrapper extends ContractWrapper {
undefined :
(ProxyArtifacts as any).networks[networkIdIfExists];
if (_.isUndefined(proxyNetworkConfigsIfExists)) {
- throw new Error(ZeroExError.CONTRACT_NOT_DEPLOYED_ON_NETWORK);
+ throw new Error(ZeroExError.ContractNotDeployedOnNetwork);
}
const proxyAddress = proxyNetworkConfigsIfExists.address;
return proxyAddress;