aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contract-wrappers/src/contract_wrappers/ether_token_wrapper.ts
diff options
context:
space:
mode:
authorAugust Skare <post@augustskare.no>2018-11-13 16:52:41 +0800
committerAugust Skare <post@augustskare.no>2018-11-13 16:52:41 +0800
commite43988aa44225ef66c95d0b26764de57b3d26c3a (patch)
tree5f2bdff05e3e6a336b600bcb7a766da4793afc76 /packages/contract-wrappers/src/contract_wrappers/ether_token_wrapper.ts
parentee91f56bbe69534885da47f58a81302bf3c37f28 (diff)
parentc41622c20aea8ba89dc9899ff8b3ab6f22f53503 (diff)
downloaddexon-sol-tools-e43988aa44225ef66c95d0b26764de57b3d26c3a.tar
dexon-sol-tools-e43988aa44225ef66c95d0b26764de57b3d26c3a.tar.gz
dexon-sol-tools-e43988aa44225ef66c95d0b26764de57b3d26c3a.tar.bz2
dexon-sol-tools-e43988aa44225ef66c95d0b26764de57b3d26c3a.tar.lz
dexon-sol-tools-e43988aa44225ef66c95d0b26764de57b3d26c3a.tar.xz
dexon-sol-tools-e43988aa44225ef66c95d0b26764de57b3d26c3a.tar.zst
dexon-sol-tools-e43988aa44225ef66c95d0b26764de57b3d26c3a.zip
Merge branch 'development' into dev-tools-pages
Diffstat (limited to 'packages/contract-wrappers/src/contract_wrappers/ether_token_wrapper.ts')
-rw-r--r--packages/contract-wrappers/src/contract_wrappers/ether_token_wrapper.ts53
1 files changed, 15 insertions, 38 deletions
diff --git a/packages/contract-wrappers/src/contract_wrappers/ether_token_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/ether_token_wrapper.ts
index 1ac01812e..913c47cf7 100644
--- a/packages/contract-wrappers/src/contract_wrappers/ether_token_wrapper.ts
+++ b/packages/contract-wrappers/src/contract_wrappers/ether_token_wrapper.ts
@@ -1,29 +1,28 @@
-import { schemas } from '@0xproject/json-schemas';
-import { BigNumber } from '@0xproject/utils';
-import { Web3Wrapper } from '@0xproject/web3-wrapper';
+import { WETH9Contract, WETH9EventArgs, WETH9Events } from '@0x/abi-gen-wrappers';
+import { WETH9 } from '@0x/contract-artifacts';
+import { schemas } from '@0x/json-schemas';
+import { BigNumber } from '@0x/utils';
+import { Web3Wrapper } from '@0x/web3-wrapper';
import { ContractAbi, LogWithDecodedArgs } from 'ethereum-types';
import * as _ from 'lodash';
-import { artifacts } from '../artifacts';
import { BlockRange, ContractWrappersError, EventCallback, IndexedFilterValues, TransactionOpts } from '../types';
import { assert } from '../utils/assert';
+import { utils } from '../utils/utils';
import { ContractWrapper } from './contract_wrapper';
import { ERC20TokenWrapper } from './erc20_token_wrapper';
-import { WETH9Contract, WETH9EventArgs, WETH9Events } from './generated/weth9';
-
-const removeUndefinedProperties = _.pickBy;
/**
* This class includes all the functionality related to interacting with a wrapped Ether ERC20 token contract.
* The caller can convert ETH into the equivalent number of wrapped ETH ERC20 tokens and back.
*/
export class EtherTokenWrapper extends ContractWrapper {
- public abi: ContractAbi = artifacts.EtherToken.compilerOutput.abi;
- private _etherTokenContractsByAddress: {
+ public abi: ContractAbi = WETH9.compilerOutput.abi;
+ private readonly _etherTokenContractsByAddress: {
[address: string]: WETH9Contract;
} = {};
- private _erc20TokenWrapper: ERC20TokenWrapper;
+ private readonly _erc20TokenWrapper: ERC20TokenWrapper;
/**
* Instantiate EtherTokenWrapper.
* @param web3Wrapper Web3Wrapper instance to use
@@ -67,7 +66,7 @@ export class EtherTokenWrapper extends ContractWrapper {
const wethContract = await this._getEtherTokenContractAsync(normalizedEtherTokenAddress);
const txHash = await wethContract.deposit.sendTransactionAsync(
- removeUndefinedProperties({
+ utils.removeUndefinedProperties({
from: normalizedDepositorAddress,
value: amountInWei,
gas: txOpts.gasLimit,
@@ -109,7 +108,7 @@ export class EtherTokenWrapper extends ContractWrapper {
const wethContract = await this._getEtherTokenContractAsync(normalizedEtherTokenAddress);
const txHash = await wethContract.withdraw.sendTransactionAsync(
amountInWei,
- removeUndefinedProperties({
+ utils.removeUndefinedProperties({
from: normalizedWithdrawerAddress,
gas: txOpts.gasLimit,
gasPrice: txOpts.gasPrice,
@@ -142,7 +141,7 @@ export class EtherTokenWrapper extends ContractWrapper {
eventName,
blockRange,
indexFilterValues,
- artifacts.EtherToken.compilerOutput.abi,
+ WETH9.compilerOutput.abi,
);
return logs;
}
@@ -172,7 +171,7 @@ export class EtherTokenWrapper extends ContractWrapper {
normalizedEtherTokenAddress,
eventName,
indexFilterValues,
- artifacts.EtherToken.compilerOutput.abi,
+ WETH9.compilerOutput.abi,
callback,
isVerbose,
);
@@ -192,36 +191,14 @@ export class EtherTokenWrapper extends ContractWrapper {
public unsubscribeAll(): void {
super._unsubscribeAll();
}
- /**
- * Retrieves the Ethereum address of the EtherToken contract deployed on the network
- * that the user-passed web3 provider is connected to. If it's not Kovan, Ropsten, Rinkeby, Mainnet or TestRPC
- * (networkId: 50), it will return undefined (e.g a private network).
- * @returns The Ethereum address of the EtherToken contract or undefined.
- */
- public getContractAddressIfExists(): string | undefined {
- const networkSpecificArtifact = artifacts.EtherToken.networks[this._networkId];
- const contractAddressIfExists = _.isUndefined(networkSpecificArtifact)
- ? undefined
- : networkSpecificArtifact.address;
- return contractAddressIfExists;
- }
- // tslint:disable-next-line:no-unused-variable
- private _invalidateContractInstance(): void {
- this.unsubscribeAll();
- this._etherTokenContractsByAddress = {};
- }
private async _getEtherTokenContractAsync(etherTokenAddress: string): Promise<WETH9Contract> {
let etherTokenContract = this._etherTokenContractsByAddress[etherTokenAddress];
if (!_.isUndefined(etherTokenContract)) {
return etherTokenContract;
}
- const [abi, address] = await this._getContractAbiAndAddressFromArtifactsAsync(
- artifacts.EtherToken,
- etherTokenAddress,
- );
const contractInstance = new WETH9Contract(
- abi,
- address,
+ this.abi,
+ etherTokenAddress,
this._web3Wrapper.getProvider(),
this._web3Wrapper.getContractDefaults(),
);