Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { APIOrder, SignedOrder } from '@0x/connect';
import { DevUtilsContract } from '@0x/contracts-dev-utils';
import { BigNumber } from '@0x/utils';
const devUtilsContract = new DevUtilsContract('0x0000000000000000000000000000000000000000', {
isEIP1193: true,
} as any);
export const utils = {
async getOrderHashAsync(order: APIOrder | SignedOrder): Promise {
if ((order as APIOrder).metaData) {
const apiOrder = order as APIOrder;
const orderHash =
(apiOrder.metaData as any).orderHash ||
(await devUtilsContract
.getOrderHash(apiOrder.order, new BigNumber(apiOrder.order.chainId), apiOrder.order.exchangeAddress)
.callAsync());
return orderHash;
} else {
const signedOrder = order as SignedOrder;
const orderHash = await devUtilsContract
constructor(provider: ZeroExProvider, tokenOwnerAddresses: string[], contractOwnerAddress: string) {
this._dummyTokenContracts = [];
this._provider = provider;
this._tokenOwnerAddresses = tokenOwnerAddresses;
this._contractOwnerAddress = contractOwnerAddress;
this._devUtils = new DevUtilsContract(constants.NULL_ADDRESS, provider);
}
public async deployDummyTokensAsync(
constructor(provider: Provider, tokenOwnerAddresses: string[], contractOwnerAddress: string) {
this._web3Wrapper = new Web3Wrapper(provider);
this._provider = provider;
const allArtifacts = _.merge(artifacts, erc1155Artifacts);
this._logDecoder = new LogDecoder(this._web3Wrapper, allArtifacts);
this._dummyTokenWrappers = [];
this._assetProxyInterface = new IAssetProxyContract(constants.NULL_ADDRESS, provider);
this._devUtils = new DevUtilsContract(constants.NULL_ADDRESS, provider);
this._tokenOwnerAddresses = tokenOwnerAddresses;
this._contractOwnerAddress = contractOwnerAddress;
this._fungibleTokenIds = [];
this._nonFungibleTokenIds = [];
this._nfts = [];
}
/**
takerAssetAmount: BigNumber,
takerAssetData: string,
exchangeAddress: string,
createOrderOpts?: CreateOrderOpts,
): Promise {
const order = orderFactory.createOrder(
makerAddress,
makerAssetAmount,
makerAssetData,
takerAssetAmount,
takerAssetData,
exchangeAddress,
await providerUtils.getChainIdAsync(supportedProvider),
createOrderOpts,
);
const orderHash = await new DevUtilsContract('0x0000000000000000000000000000000000000000', {
isEIP1193: true,
} as any)
.getOrderHash(order, new BigNumber(order.chainId), order.exchangeAddress)
.callAsync();
const signature = await signatureUtils.ecSignHashAsync(supportedProvider, orderHash, makerAddress);
const signedOrder: SignedOrder = _.assign(order, { signature });
return signedOrder;
},
};