Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Use Compressed Calldata in Contract Wrappers #1475

Merged
merged 28 commits into from
Jan 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
285fb3d
Progress
hysz Dec 18, 2018
b89f986
Ensure that addresses are lower case
hysz Dec 18, 2018
2f1454e
Working for almost every test
hysz Dec 19, 2018
e4551c8
Works for almost all tests
hysz Dec 19, 2018
f8684d6
All contract tests working with new abi encoder
hysz Dec 19, 2018
e9a8290
Abi Encoder tests fixed + added a signature parser for cases where Me…
hysz Dec 19, 2018
7991de9
Generalized `create` for signature / dataItems. Cleaner.
hysz Dec 19, 2018
b06f823
Finished porting new abi encoder to contracts
hysz Dec 23, 2018
d1fd442
Use string argument encoding with new encoder
hysz Dec 24, 2018
0b6c9c8
Ran prettier
hysz Dec 24, 2018
6d832de
Decodes revert reason as array to appease Geth
hysz Dec 24, 2018
86caa4a
Ran prettier and linter
hysz Dec 24, 2018
33f3405
`let` -> `const` in callAsync
hysz Dec 24, 2018
f73c68e
Created an interface for abi decoded fillOrder data
hysz Dec 24, 2018
05adb38
Removed console log from handlebars
hysz Dec 24, 2018
f39c031
Ran linter
hysz Dec 24, 2018
6892f92
circle build failed. New commit to resubmit job.
hysz Dec 24, 2018
0b87aec
Renamed decode rule `structsAsObjects` to `shouldConvertStructsToObje…
hysz Jan 9, 2019
4f53335
Renamed signatureParser.ts to signature_parser.ts
hysz Jan 8, 2019
1c9a49c
Added back abi-gen-wrappers
hysz Jan 9, 2019
1cbc03a
Updated dutch auction wrapper
hysz Jan 9, 2019
892be49
Use simpler `_.find` to locate fillOrderBai
hysz Jan 9, 2019
82a4455
Style cleanup for Compressed Calldata in Contract Wrappers PR
hysz Jan 9, 2019
3a28eb1
Fix build after rebase
hysz Jan 10, 2019
80aa288
Linter
hysz Jan 10, 2019
cf2dee6
Ran prettier
hysz Jan 10, 2019
1907ecc
makerAssetFillAmount -> takerAssetFillAmount
hysz Jan 11, 2019
b081785
strict decoding of return values using generics
hysz Jan 12, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions contracts/protocol/test/utils/exchange_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ import {
} from '@0x/contracts-test-utils';
import { artifacts as tokensArtifacts } from '@0x/contracts-tokens';
import { SignedOrder } from '@0x/types';
import { BigNumber } from '@0x/utils';
import { AbiEncoder, BigNumber } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper';
import { Provider, TransactionReceiptWithDecodedLogs } from 'ethereum-types';
import { MethodAbi, Provider, TransactionReceiptWithDecodedLogs } from 'ethereum-types';
import * as _ from 'lodash';

import { ExchangeContract } from '../../generated-wrappers/exchange';
import { artifacts } from '../../src/artifacts';

import { AbiDecodedFillOrderData } from './types';

export class ExchangeWrapper {
private readonly _exchange: ExchangeContract;
private readonly _web3Wrapper: Web3Wrapper;
Expand Down Expand Up @@ -275,6 +278,14 @@ export class ExchangeWrapper {
);
return data;
}
public abiDecodeFillOrder(data: string): AbiDecodedFillOrderData {
// Lookup fillOrder ABI in exchange abi
const fillOrderAbi = _.find(this._exchange.abi, { name: 'fillOrder' }) as MethodAbi;
// Decode input data
const abiEncoder = new AbiEncoder.Method(fillOrderAbi);
const decodedData = abiEncoder.decode(data) as AbiDecodedFillOrderData;
return decodedData;
}
public getExchangeAddress(): string {
return this._exchange.address;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,13 +613,13 @@ export class FillOrderCombinatorialUtils {
takerAssetFillAmount: BigNumber,
): Promise<void> {
const params = orderUtils.createFill(signedOrder, takerAssetFillAmount);
const expectedAbiEncodedData = this.exchangeWrapper.abiEncodeFillOrder(signedOrder, { takerAssetFillAmount });
const libsAbiEncodedData = await this.testLibsContract.publicAbiEncodeFillOrder.callAsync(
const abiDataEncodedByContract = await this.testLibsContract.publicAbiEncodeFillOrder.callAsync(
params.order,
params.takerAssetFillAmount,
params.signature,
);
expect(libsAbiEncodedData).to.be.equal(expectedAbiEncodedData, 'ABIEncodedFillOrderData');
const paramsDecodedByClient = this.exchangeWrapper.abiDecodeFillOrder(abiDataEncodedByContract);
expect(paramsDecodedByClient).to.be.deep.equal(params, 'ABIEncodedFillOrderData');
}
private async _getTakerAssetFillAmountAsync(
signedOrder: SignedOrder,
Expand Down
8 changes: 8 additions & 0 deletions contracts/protocol/test/utils/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { SignedOrder } from '@0x/types';
import { BigNumber } from '@0x/utils';

export interface AbiDecodedFillOrderData {
order: SignedOrder;
takerAssetFillAmount: BigNumber;
signature: string;
}
2 changes: 1 addition & 1 deletion packages/abi-gen-templates/contract.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class {{contractName}}Contract extends BaseContract {
}
constructor(abi: ContractAbi, address: string, provider: Provider, txDefaults?: Partial<TxData>) {
super('{{contractName}}', abi, address, provider, txDefaults);
classUtils.bindAll(this, ['_ethersInterfacesByFunctionSignature', 'address', 'abi', '_web3Wrapper']);
classUtils.bindAll(this, ['_abiEncoderByFunctionSignature', 'address', 'abi', '_web3Wrapper']);
}
} // tslint:disable:max-file-line-count
// tslint:enable:no-unbound-method
17 changes: 6 additions & 11 deletions packages/abi-gen-templates/partials/callAsync.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ async callAsync(
defaultBlock?: BlockParam,
): Promise<{{> return_type outputs=outputs}}> {
const self = this as any as {{contractName}}Contract;
const functionSignature = '{{this.functionSignature}}';
const inputAbi = self._lookupAbi(functionSignature).inputs;
[{{> params inputs=inputs}}] = BaseContract._formatABIDataItemList(inputAbi, [{{> params inputs=inputs}}], BaseContract._bigNumberToString.bind(self));
BaseContract.strictArgumentEncodingCheck(inputAbi, [{{> params inputs=inputs}}]);
const ethersFunction = self._lookupEthersInterface(functionSignature).functions.{{this.name}};
const encodedData = ethersFunction.encode([{{> params inputs=inputs}}]);
const encodedData = self._strictEncodeArguments('{{this.functionSignature}}', [{{> params inputs=inputs}}]);
const callDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync(
{
to: self.address,
Expand All @@ -20,9 +15,9 @@ async callAsync(
);
const rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock);
BaseContract._throwIfRevertWithReasonCallResult(rawCallResult);
let resultArray = ethersFunction.decode(rawCallResult);
const outputAbi = (_.find(self.abi, {name: '{{this.name}}'}) as MethodAbi).outputs;
resultArray = BaseContract._formatABIDataItemList(outputAbi, resultArray, BaseContract._lowercaseAddress.bind(this));
resultArray = BaseContract._formatABIDataItemList(outputAbi, resultArray, BaseContract._bnToBigNumber.bind(this));
return resultArray{{#singleReturnValue}}[0]{{/singleReturnValue}};
const abiEncoder = self._lookupAbiEncoder('{{this.functionSignature}}');
// tslint:disable boolean-naming
const result = abiEncoder.strictDecodeReturnValue<{{> return_type outputs=outputs}}>(rawCallResult);
// tslint:enable boolean-naming
return result;
},
13 changes: 3 additions & 10 deletions packages/abi-gen-templates/partials/tx.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ public {{this.tsName}} = {
{{/this.payable}}
): Promise<string> {
const self = this as any as {{contractName}}Contract;
const inputAbi = self._lookupAbi('{{this.functionSignature}}').inputs;
[{{> params inputs=inputs}}] = BaseContract._formatABIDataItemList(inputAbi, [{{> params inputs=inputs}}], BaseContract._bigNumberToString.bind(self));
BaseContract.strictArgumentEncodingCheck(inputAbi, [{{> params inputs=inputs}}]);
const encodedData = self._lookupEthersInterface('{{this.functionSignature}}').functions.{{this.name}}.encode([{{> params inputs=inputs}}]);
const encodedData = self._strictEncodeArguments('{{this.functionSignature}}', [{{> params inputs=inputs}}]);
const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync(
{
to: self.address,
Expand All @@ -33,9 +30,7 @@ public {{this.tsName}} = {
txData: Partial<TxData> = {},
): Promise<number> {
const self = this as any as {{contractName}}Contract;
const inputAbi = self._lookupAbi('{{this.functionSignature}}').inputs;
[{{> params inputs=inputs}}] = BaseContract._formatABIDataItemList(inputAbi, [{{> params inputs=inputs}}], BaseContract._bigNumberToString);
const encodedData = self._lookupEthersInterface('{{this.functionSignature}}').functions.{{this.name}}.encode([{{> params inputs=inputs}}]);
const encodedData = self._strictEncodeArguments('{{this.functionSignature}}', [{{> params inputs=inputs}}]);
const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync(
{
to: self.address,
Expand All @@ -51,9 +46,7 @@ public {{this.tsName}} = {
{{> typed_params inputs=inputs}}
): string {
const self = this as any as {{contractName}}Contract;
const inputAbi = self._lookupAbi('{{this.functionSignature}}').inputs;
[{{> params inputs=inputs}}] = BaseContract._formatABIDataItemList(inputAbi, [{{> params inputs=inputs}}], BaseContract._bigNumberToString);
const abiEncodedTransactionData = self._lookupEthersInterface('{{this.functionSignature}}').functions.{{this.name}}.encode([{{> params inputs=inputs}}]);
const abiEncodedTransactionData = self._strictEncodeArguments('{{this.functionSignature}}', [{{> params inputs=inputs}}]);
return abiEncodedTransactionData;
},
{{> callAsync}}
Expand Down
Loading