-
Notifications
You must be signed in to change notification settings - Fork 465
Use Compressed Calldata in Contract Wrappers #1475
Conversation
8eac4c5
to
99f0fcf
Compare
Why did we remove all generated wrappers? |
@@ -275,6 +278,19 @@ export class ExchangeWrapper { | |||
); | |||
return data; | |||
} | |||
public abiDecodeFillOrder(data: string): AbiDecodedFillOrderData { | |||
// Lookup fillOrder ABI in exchange abi | |||
const fillOrderAbi = _.find(this._exchange.abi, (value: AbiDefinition) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe:
const fillOrderAbi = _.find(this._exchange.abi, (value: AbiDefinition) => { | |
const fillOrderAbi = _.find(this._exchange.abi, { name: 'fillOrder' }) as MethodAbi; |
We don't usually use that form but I feel like here it's more readable. It's not type safe, but the current solution is not either.
@@ -51,8 +51,26 @@ export abstract class DataType { | |||
return value; | |||
} | |||
|
|||
public decodeAsArray(returndata: string, rules?: DecodingRules): any { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public decodeAsArray(returndata: string, rules?: DecodingRules): any { | |
public decodeAsArray(returndata: string, rules?: DecodingRules): any[] { |
|
||
export interface AbiDecodedFillOrderData { | ||
order: SignedOrder; | ||
akerAssetFillAmount: BigNumber; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
akerAssetFillAmount: BigNumber; | |
makerAssetFillAmount: BigNumber; |
@@ -1,4 +1,4 @@ | |||
import { abiUtils, BigNumber } from '@0x/utils'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were we able to remove abiUtils and ethers.js entirely from our codebase?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
abiUtils
is still used to rename overloaded methods and assert correct encoding.
ethers
is used by deployAsync
.
There is a task to remove this from deployAsync
after which we can remove ethers.js.
); | ||
} | ||
const memberBlock = this._members[this._memberIndexByName[key]].generateCalldataBlock(value, block); | ||
const memberValue: any = (obj as { [key: string]: any })[memberName]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const memberValue: any = (obj as { [key: string]: any })[memberName]; | |
const memberValue: any = (obj as ObjectMap<any>)[memberName]; |
@@ -44,7 +44,19 @@ export class MethodDataType extends AbstractSetDataType { | |||
return returnValues; | |||
} | |||
|
|||
public getSignature(): string { | |||
public decodeReturnValuesAsArray(returndata: string, rules?: DecodingRules): any { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public decodeReturnValuesAsArray(returndata: string, rules?: DecodingRules): any { | |
public decodeReturnValuesAsArray(returnData: string, rules?: DecodingRules): any { |
Always camel--case variable names
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the return type here be any[]
?
return this._destination.getSignature(false); | ||
} | ||
|
||
public getSignature(detailed?: boolean): string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public getSignature(detailed?: boolean): string { | |
public getSignature(isDetailed?: boolean): string { |
Stick to boolean naming conventions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's investigate why was this not caught by linter rule
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect it's because it's a param name and not a variable. We should improve our linter rule.
@@ -0,0 +1,101 @@ | |||
import { DataItem } from 'ethereum-types'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this file name not snake-case? It should be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean snake case?
params.order, | ||
params.takerAssetFillAmount, | ||
params.signature, | ||
); | ||
expect(libsAbiEncodedData).to.be.equal(expectedAbiEncodedData, 'ABIEncodedFillOrderData'); | ||
const paramsDecodeddByClient = this.exchangeWrapper.abiDecodeFillOrder(abiDataEncodedByContract); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
paramsDecodedByClient
@@ -44,7 +44,19 @@ export class MethodDataType extends AbstractSetDataType { | |||
return returnValues; | |||
} | |||
|
|||
public getSignature(): string { | |||
public decodeReturnValuesAsArray(returndata: string, rules?: DecodingRules): any { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the return type here be any[]
?
@@ -1,1877 +0,0 @@ | |||
// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma whitespace class-name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are all of the generated wrappers deleted rather than replaced?
8f2c221
to
b183be4
Compare
|
||
export interface AbiDecodedFillOrderData { | ||
order: SignedOrder; | ||
makerAssetFillAmount: BigNumber; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
takerAssetFillAmount
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
facepalm
]); | ||
const ethersFunction = self._lookupEthersInterface(functionSignature).functions.owners; | ||
const encodedData = ethersFunction.encode([index_0 | ||
const encodedData = self._strictEncodeArguments('owners(uint256)', [index_0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't particularly matter since these are auto-generated, but I'm curious why the formatting is so strange (looks like it was this way before too).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a good question. I always figured it had something to do with Handlebars. @LogvinovLeon any ideas?
return returnValuesAsArray; | ||
} | ||
|
||
public decodeReturnValuesAsArrayOrNull(returnData: string, rules?: DecodingRules): any { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should also return any[]
.
@@ -44,7 +44,19 @@ export class MethodDataType extends AbstractSetDataType { | |||
return returnValues; | |||
} | |||
|
|||
public getSignature(): string { | |||
public decodeReturnValuesAsArray(returnData: string, rules?: DecodingRules): any[] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For all of these functions with an any
return type (or variant), should the signatures include a generic type? E.g:
public decodeReturnValuesAsArray<T>(returnData: string, rules?: DecodingRules): T[]
Thoughts @fabioberger @LogvinovLeon @hysz ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like this idea.
b2f5b12
to
b6a298f
Compare
@@ -44,7 +44,20 @@ export class MethodDataType extends AbstractSetDataType { | |||
return returnValues; | |||
} | |||
|
|||
public getSignature(): string { | |||
public strictDecodeReturnValue<T>(returndata: string, rules?: DecodingRules): T { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a point in having a non-strict version of this still? I feel like we could probably add generic types to the regular decodeReturnValues
.
Also this doesn't have to be in this PR if it's a lot of changes, but we should add generic types to the regular decode
function as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've created a task to use generics for all decoding. Shouldn't take long but I think it makes sense to have in a separate PR as well.
…thodAbi/DataItems are not readily available
b6a298f
to
b081785
Compare
Description
The contract templates now use the optimized ABI encoder to compress all calldata.
We wanted to do this without changing the interface of the templates at all, so a few minor changes were made to the encoder:
(this also fixes a bug in current return value decoding, where nested addresses would not always be decoded)
uint8
andint8
are decoded asnumber
instead ofBigNumber
Ex, signatures like
'string'
and'(string,uint256)'
and'(foo string,bar uint256)'
can now all be used to instantiate an optimized encoder.In a subsequent PR we'll add the ability for templates to decode calldata.
Testing instructions
Types of changes
Checklist:
[WIP]
if necessary.