aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/src/utils/exchange_transfer_simulator.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/0x.js/src/utils/exchange_transfer_simulator.ts')
-rw-r--r--packages/0x.js/src/utils/exchange_transfer_simulator.ts52
1 files changed, 26 insertions, 26 deletions
diff --git a/packages/0x.js/src/utils/exchange_transfer_simulator.ts b/packages/0x.js/src/utils/exchange_transfer_simulator.ts
index 2574bd9ac..8143112aa 100644
--- a/packages/0x.js/src/utils/exchange_transfer_simulator.ts
+++ b/packages/0x.js/src/utils/exchange_transfer_simulator.ts
@@ -34,16 +34,16 @@ const ERR_MSG_MAPPING = {
};
export class ExchangeTransferSimulator {
- private store: BalanceAndProxyAllowanceLazyStore;
- private UNLIMITED_ALLOWANCE_IN_BASE_UNITS: BigNumber;
- private static throwValidationError(failureReason: FailureReason, tradeSide: TradeSide,
- transferType: TransferType): never {
+ private _store: BalanceAndProxyAllowanceLazyStore;
+ private _UNLIMITED_ALLOWANCE_IN_BASE_UNITS: BigNumber;
+ private static _throwValidationError(failureReason: FailureReason, tradeSide: TradeSide,
+ transferType: TransferType): never {
const errMsg = ERR_MSG_MAPPING[failureReason][tradeSide][transferType];
throw new Error(errMsg);
}
constructor(token: TokenWrapper, defaultBlock: BlockParamLiteral) {
- this.store = new BalanceAndProxyAllowanceLazyStore(token, defaultBlock);
- this.UNLIMITED_ALLOWANCE_IN_BASE_UNITS = token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS;
+ this._store = new BalanceAndProxyAllowanceLazyStore(token, defaultBlock);
+ this._UNLIMITED_ALLOWANCE_IN_BASE_UNITS = token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS;
}
/**
* Simulates transferFrom call performed by a proxy
@@ -57,33 +57,33 @@ export class ExchangeTransferSimulator {
public async transferFromAsync(tokenAddress: string, from: string, to: string,
amountInBaseUnits: BigNumber, tradeSide: TradeSide,
transferType: TransferType): Promise<void> {
- const balance = await this.store.getBalanceAsync(tokenAddress, from);
- const proxyAllowance = await this.store.getProxyAllowanceAsync(tokenAddress, from);
+ const balance = await this._store.getBalanceAsync(tokenAddress, from);
+ const proxyAllowance = await this._store.getProxyAllowanceAsync(tokenAddress, from);
if (proxyAllowance.lessThan(amountInBaseUnits)) {
- ExchangeTransferSimulator.throwValidationError(FailureReason.ProxyAllowance, tradeSide, transferType);
+ ExchangeTransferSimulator._throwValidationError(FailureReason.ProxyAllowance, tradeSide, transferType);
}
if (balance.lessThan(amountInBaseUnits)) {
- ExchangeTransferSimulator.throwValidationError(FailureReason.Balance, tradeSide, transferType);
+ ExchangeTransferSimulator._throwValidationError(FailureReason.Balance, tradeSide, transferType);
}
- await this.decreaseProxyAllowanceAsync(tokenAddress, from, amountInBaseUnits);
- await this.decreaseBalanceAsync(tokenAddress, from, amountInBaseUnits);
- await this.increaseBalanceAsync(tokenAddress, to, amountInBaseUnits);
+ await this._decreaseProxyAllowanceAsync(tokenAddress, from, amountInBaseUnits);
+ await this._decreaseBalanceAsync(tokenAddress, from, amountInBaseUnits);
+ await this._increaseBalanceAsync(tokenAddress, to, amountInBaseUnits);
}
- private async decreaseProxyAllowanceAsync(tokenAddress: string, userAddress: string,
- amountInBaseUnits: BigNumber): Promise<void> {
- const proxyAllowance = await this.store.getProxyAllowanceAsync(tokenAddress, userAddress);
- if (!proxyAllowance.eq(this.UNLIMITED_ALLOWANCE_IN_BASE_UNITS)) {
- this.store.setProxyAllowance(tokenAddress, userAddress, proxyAllowance.minus(amountInBaseUnits));
+ private async _decreaseProxyAllowanceAsync(tokenAddress: string, userAddress: string,
+ amountInBaseUnits: BigNumber): Promise<void> {
+ const proxyAllowance = await this._store.getProxyAllowanceAsync(tokenAddress, userAddress);
+ if (!proxyAllowance.eq(this._UNLIMITED_ALLOWANCE_IN_BASE_UNITS)) {
+ this._store.setProxyAllowance(tokenAddress, userAddress, proxyAllowance.minus(amountInBaseUnits));
}
}
- private async increaseBalanceAsync(tokenAddress: string, userAddress: string,
- amountInBaseUnits: BigNumber): Promise<void> {
- const balance = await this.store.getBalanceAsync(tokenAddress, userAddress);
- this.store.setBalance(tokenAddress, userAddress, balance.plus(amountInBaseUnits));
+ private async _increaseBalanceAsync(tokenAddress: string, userAddress: string,
+ amountInBaseUnits: BigNumber): Promise<void> {
+ const balance = await this._store.getBalanceAsync(tokenAddress, userAddress);
+ this._store.setBalance(tokenAddress, userAddress, balance.plus(amountInBaseUnits));
}
- private async decreaseBalanceAsync(tokenAddress: string, userAddress: string,
- amountInBaseUnits: BigNumber): Promise<void> {
- const balance = await this.store.getBalanceAsync(tokenAddress, userAddress);
- this.store.setBalance(tokenAddress, userAddress, balance.minus(amountInBaseUnits));
+ private async _decreaseBalanceAsync(tokenAddress: string, userAddress: string,
+ amountInBaseUnits: BigNumber): Promise<void> {
+ const balance = await this._store.getBalanceAsync(tokenAddress, userAddress);
+ this._store.setBalance(tokenAddress, userAddress, balance.minus(amountInBaseUnits));
}
}