aboutsummaryrefslogtreecommitdiffstats
path: root/packages/base-contract
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-05-16 03:52:49 +0800
committerAmir Bandeali <abandeali1@gmail.com>2018-05-16 03:52:49 +0800
commit9e0471bfbb4bb2b3b490e10ce34b16c88e8bab9a (patch)
treef72aae5170b6f1f6d3d70ebf6c03ed171680ff50 /packages/base-contract
parent9744b1906a111aa0c65c8fafb4db66aef32a5a23 (diff)
parent6aed4fb1ae27dabed027c855f2cbdc0bfb4f3b6b (diff)
downloaddexon-0x-contracts-9e0471bfbb4bb2b3b490e10ce34b16c88e8bab9a.tar.gz
dexon-0x-contracts-9e0471bfbb4bb2b3b490e10ce34b16c88e8bab9a.tar.zst
dexon-0x-contracts-9e0471bfbb4bb2b3b490e10ce34b16c88e8bab9a.zip
Merge branch 'development' into v2-prototype
Diffstat (limited to 'packages/base-contract')
-rw-r--r--packages/base-contract/CHANGELOG.json12
-rw-r--r--packages/base-contract/CHANGELOG.md12
-rw-r--r--packages/base-contract/package.json14
-rw-r--r--packages/base-contract/src/index.ts43
4 files changed, 64 insertions, 17 deletions
diff --git a/packages/base-contract/CHANGELOG.json b/packages/base-contract/CHANGELOG.json
index c5d467b7f..106c26989 100644
--- a/packages/base-contract/CHANGELOG.json
+++ b/packages/base-contract/CHANGELOG.json
@@ -1,12 +1,22 @@
[
{
+ "timestamp": 1525477860,
+ "version": "0.3.1",
+ "changes": [
+ {
+ "note": "Dependencies updated"
+ }
+ ]
+ },
+ {
"version": "0.3.0",
"changes": [
{
"note": "Update ethers-contracts to ethers.js",
"pr": 540
}
- ]
+ ],
+ "timestamp": 1525428773
},
{
"timestamp": 1524044013,
diff --git a/packages/base-contract/CHANGELOG.md b/packages/base-contract/CHANGELOG.md
index 90f1ff5ed..b57bd5fc0 100644
--- a/packages/base-contract/CHANGELOG.md
+++ b/packages/base-contract/CHANGELOG.md
@@ -5,11 +5,19 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
+## v0.3.1 - _May 5, 2018_
+
+ * Dependencies updated
+
+## v0.3.0 - _May 4, 2018_
+
+ * Update ethers-contracts to ethers.js (#540)
+
## v0.2.1 - _April 18, 2018_
* Dependencies updated
-## v0.2.0 - _April 12, 2018_
+## v0.2.0 - _April 11, 2018_
* Contract wrappers now accept Provider and defaults instead of Web3Wrapper (#501)
@@ -23,6 +31,6 @@ CHANGELOG
* Dependencies updated
-## v0.0.2 - _March 4, 2018_
+## v0.0.2 - _March 3, 2018_
* Initial release
diff --git a/packages/base-contract/package.json b/packages/base-contract/package.json
index 78dcbfe7f..90253616b 100644
--- a/packages/base-contract/package.json
+++ b/packages/base-contract/package.json
@@ -1,6 +1,6 @@
{
"name": "@0xproject/base-contract",
- "version": "0.2.1",
+ "version": "0.3.1",
"description": "0x Base TS contract",
"main": "lib/src/index.js",
"types": "lib/src/index.d.ts",
@@ -26,8 +26,8 @@
},
"homepage": "https://github.com/0xProject/0x-monorepo/packages/base-contract/README.md",
"devDependencies": {
- "@0xproject/monorepo-scripts": "^0.1.18",
- "@0xproject/tslint-config": "^0.4.16",
+ "@0xproject/monorepo-scripts": "^0.1.19",
+ "@0xproject/tslint-config": "^0.4.17",
"@types/lodash": "4.14.104",
"chai": "^4.0.1",
"copyfiles": "^1.2.0",
@@ -38,10 +38,10 @@
"typescript": "2.7.1"
},
"dependencies": {
- "@0xproject/types": "^0.6.1",
- "@0xproject/typescript-typings": "^0.2.0",
- "@0xproject/utils": "^0.5.2",
- "@0xproject/web3-wrapper": "^0.6.1",
+ "@0xproject/types": "^0.6.3",
+ "@0xproject/typescript-typings": "^0.3.1",
+ "@0xproject/utils": "^0.6.1",
+ "@0xproject/web3-wrapper": "^0.6.3",
"ethers": "^3.0.15",
"lodash": "^4.17.4"
},
diff --git a/packages/base-contract/src/index.ts b/packages/base-contract/src/index.ts
index e95b18db6..f9298f413 100644
--- a/packages/base-contract/src/index.ts
+++ b/packages/base-contract/src/index.ts
@@ -1,6 +1,7 @@
import {
AbiDefinition,
AbiType,
+ ConstructorAbi,
ContractAbi,
DataItem,
MethodAbi,
@@ -24,6 +25,8 @@ export class BaseContract {
protected _web3Wrapper: Web3Wrapper;
public abi: ContractAbi;
public address: string;
+ public contractName: string;
+ public constructorArgs: any[] = [];
protected static _formatABIDataItemList(
abis: DataItem[],
values: any[],
@@ -37,11 +40,31 @@ export class BaseContract {
protected static _bigNumberToString(type: string, value: any): any {
return _.isObject(value) && value.isBigNumber ? value.toString() : value;
}
+ protected static _lookupConstructorAbi(abi: ContractAbi): ConstructorAbi {
+ const constructorAbiIfExists = _.find(
+ abi,
+ (abiDefinition: AbiDefinition) => abiDefinition.type === AbiType.Constructor,
+ ) as ConstructorAbi | undefined;
+ if (!_.isUndefined(constructorAbiIfExists)) {
+ return constructorAbiIfExists;
+ } else {
+ // If the constructor is not explicitly defined, it won't be included in the ABI. It is
+ // still callable however, so we construct what the ABI would look like were it to exist.
+ const defaultConstructorAbi: ConstructorAbi = {
+ type: AbiType.Constructor,
+ stateMutability: 'nonpayable',
+ payable: false,
+ inputs: [],
+ };
+ return defaultConstructorAbi;
+ }
+ }
protected static _bnToBigNumber(type: string, value: any): any {
return _.isObject(value) && value._bn ? new BigNumber(value.toString()) : value;
}
- protected async _applyDefaultsToTxDataAsync<T extends Partial<TxData | TxDataPayable>>(
+ protected static async _applyDefaultsToTxDataAsync<T extends Partial<TxData | TxDataPayable>>(
txData: T,
+ txDefaults: Partial<TxData>,
estimateGasAsync?: (txData: T) => Promise<number>,
): Promise<TxData> {
// Gas amount sourced with the following priorities:
@@ -49,13 +72,12 @@ export class BaseContract {
// 2. Global config passed in at library instantiation
// 3. Gas estimate calculation + safety margin
const removeUndefinedProperties = _.pickBy;
- const txDataWithDefaults = ({
- to: this.address,
- ...removeUndefinedProperties(this._web3Wrapper.getContractDefaults()),
+ const txDataWithDefaults: TxData = {
+ ...removeUndefinedProperties(txDefaults),
...removeUndefinedProperties(txData as any),
// HACK: TS can't prove that T is spreadable.
// Awaiting https://github.com/Microsoft/TypeScript/pull/13288 to be merged
- } as any) as TxData;
+ } as any;
if (_.isUndefined(txDataWithDefaults.gas) && !_.isUndefined(estimateGasAsync)) {
const estimatedGas = await estimateGasAsync(txData);
txDataWithDefaults.gas = estimatedGas;
@@ -82,8 +104,15 @@ export class BaseContract {
}) as MethodAbi;
return methodAbi;
}
- constructor(abi: ContractAbi, address: string, provider: Provider, defaults?: Partial<TxData>) {
- this._web3Wrapper = new Web3Wrapper(provider, defaults);
+ constructor(
+ contractName: string,
+ abi: ContractAbi,
+ address: string,
+ provider: Provider,
+ txDefaults?: Partial<TxData>,
+ ) {
+ this.contractName = contractName;
+ this._web3Wrapper = new Web3Wrapper(provider, txDefaults);
this.abi = abi;
this.address = address;
const methodAbis = this.abi.filter(