-
Notifications
You must be signed in to change notification settings - Fork 465
Conversation
packages/instant/src/index.umd.ts
Outdated
@@ -108,15 +108,15 @@ export interface ZeroExInstantConfig extends ZeroExInstantOverlayProps { | |||
shouldDisablePushToHistory?: boolean; | |||
} | |||
|
|||
export const render = (config: ZeroExInstantConfig, selector: string = DEFAULT_ZERO_EX_CONTAINER_SELECTOR) => { |
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 couldn't find where this was being called, so didn't rename it to renderAsync
. Worried this breaks something else. Where is this used? @fragosti @steveklebanoff
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.
heh all these functions are exported so developers can use them when importing the UMD bundle. So while they're not used in instant, they are exposed for convenience.
79fa0c0
to
2a37c9d
Compare
packages/instant/src/index.umd.ts
Outdated
@@ -108,15 +108,15 @@ export interface ZeroExInstantConfig extends ZeroExInstantOverlayProps { | |||
shouldDisablePushToHistory?: boolean; | |||
} | |||
|
|||
export const render = (config: ZeroExInstantConfig, selector: string = DEFAULT_ZERO_EX_CONTAINER_SELECTOR) => { |
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.
heh all these functions are exported so developers can use them when importing the UMD bundle. So while they're not used in instant, they are exposed for convenience.
@@ -0,0 +1,5 @@ | |||
import { DevUtilsContract } from '@0x/contract-wrappers'; | |||
import { NULL_ADDRESS } 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.
Maybe a little comment about what is going on.
packages/instant/src/index.umd.ts
Outdated
export const assetDataForERC20TokenAddress = (tokenAddress: string): string => { | ||
export const assetDataForERC20TokenAddressAsync = async (tokenAddress: string): Promise<string> => { | ||
assert.isETHAddressHex('tokenAddress', tokenAddress); | ||
return assetDataUtils.encodeERC20AssetData(tokenAddress); | ||
return devUtilsContract.encodeERC20AssetData(tokenAddress).callAsync(); | ||
}; | ||
|
||
export const assetDataForERC721TokenAddress = (tokenAddress: string, tokenId: string | number): string => { | ||
export const assetDataForERC721TokenAddressAsync = async ( | ||
tokenAddress: string, | ||
tokenId: string | number, | ||
): Promise<string> => { | ||
assert.isETHAddressHex('tokenAddress', tokenAddress); | ||
return assetDataUtils.encodeERC721AssetData(tokenAddress, new BigNumber(tokenId)); | ||
return devUtilsContract.encodeERC721AssetData(tokenAddress, new BigNumber(tokenId)).callAsync(); |
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 is a significant breaking change. Obviously I'm lacking context on this decision but it seems odd that you can no longer get assetDatas in a synchronous way.
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.
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.
Not easily, we currently use putContractCode
and runCall
from ethereumjs-vm
and they are async.
@jalextowle showed me a synchronous work-around using IAssetDataContract
though:
const assetDataEncoder = new IAssetDataContract(NULL_ADDRESS, fakeProvider);
const encoded = assetDataEncoder.ERC20Token(tokenAddress).getABIEncodedTransactionData()
…tant to decode asset data synchronously
2a37c9d
to
48bf1e3
Compare
|
00b6b38
to
f7e5aac
Compare
4e464d3
to
b27434c
Compare
10a99a7
to
3b8bee4
Compare
3b8bee4
to
81c6d98
Compare
@@ -158,12 +158,12 @@ export const ERC20_PROXY_ID = AssetProxyId.ERC20; | |||
|
|||
export const assetDataForERC20TokenAddress = (tokenAddress: string): string => { | |||
assert.isETHAddressHex('tokenAddress', tokenAddress); | |||
return assetDataUtils.encodeERC20AssetData(tokenAddress); | |||
return assetDataEncoder.ERC20Token(tokenAddress).getABIEncodedTransactionData(); |
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.
😍 so much better!
export function decodeAssetProxyId(assetData: string): string { | ||
return hexSlice(assetData, 0, 4); | ||
} |
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 something like this be in order-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.
Maybe but right now nothing else uses it and instant
doesn't use order-utils
as a dependency yet...
Still feel like I'm lacking context though. Why are we removing |
@fragosti the motivation is to stop maintaining separate typescript libs for encoding/decoding asset data, and only have the code implemented and tested once in Solidity. Cutting unnecessary overhead is gonna save us time in the future; e.g. in this instance we already neglected to add ERC20Bridge support, but it's already implemented in Solidity. @fabio @dekz btw, I think we should encourage devs to use |
contracts/coordinator/test/mixins.ts
Outdated
randomAddress, | ||
TransactionFactory, | ||
transactionHashUtils, | ||
} from '@0x/contracts-test-utils'; | ||
import { LibBytesRevertErrors } from '@0x/contracts-utils'; | ||
import { SignatureType, SignedOrder } from '@0x/types'; | ||
import { BigNumber, CoordinatorRevertErrors } from '@0x/utils'; | ||
import { BigNumber, CoordinatorRevertErrors, hexConcat, hexSlice } 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.
Can we export a hexUtils
from @0x/utils
instead of several hex prefixed methods?
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.
done!
* remove assetDataUtils everywhere * export IAssetDataContract from @0x/contract-wrappers to allow @0x/instant to decode asset data synchronously * export generic function `decodeAssetDataOrThrow` and add ERC20Bridge support * export `hexUtils` from order-utils instead of contracts-test-utils
Description
I started removing uses of
assetDataUtils
a while ago, but left the task incomplete as it was easier to wait for things to be removed from the monorepo rather than refactor them.This PR replaces the last few uses of
assetDataUtils
withDevUtilsContract
and removesassetDataUtils
completely.After making a few needed fixes, this PR has grown somewhat unwieldy:
hex_utils.ts
from @0x/contracts-test-utils to @0x/utilsassetDataUtils
from@0x/order-utils
assetDataUtils
everywhere in monorepodecodeAssetDataOrThrow
in@0x/order-utils
, this time with ERC20Bridge supportERC20BridgeAssetData
type and interface to @0x/typesApologies for combining the
hex_utils
rename in this PR. Trying to get a fix in sooner rather than later as the currently publishedassetDataUtils
does not supportERC20Bridge
.Testing instructions
Types of changes
Checklist:
[WIP]
if necessary.