Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
parse(utf8Data: string): OrdersChannelMessage {
// parse the message
const messageObj = JSON.parse(utf8Data);
// ensure we have a type parameter to switch on
const type: string = _.get(messageObj, 'type');
assert.assert(type !== undefined, `Message is missing a type parameter: ${utf8Data}`);
assert.isString('type', type);
// ensure we have a request id for the resulting message
const requestId: string = _.get(messageObj, 'requestId');
assert.assert(requestId !== undefined, `Message is missing a requestId parameter: ${utf8Data}`);
assert.isString('requestId', requestId);
switch (type) {
case OrdersChannelMessageTypes.Update: {
assert.doesConformToSchema('message', messageObj, schemas.relayerApiOrdersChannelUpdateSchema);
const ordersJson = messageObj.payload;
const orders = relayerResponseJsonParsers.parseAPIOrdersJson(ordersJson);
return _.assign(messageObj, { payload: orders });
}
default: {
return {
type: OrdersChannelMessageTypes.Unknown,
requestId,
payload: undefined,
};
}
}
},
};
public async getLogsAsync(
eventName: ForwarderEvents,
blockRange: BlockRange,
indexFilterValues: IndexedFilterValues,
): Promise>> {
assert.doesBelongToStringEnum('eventName', eventName, ForwarderEvents);
assert.doesConformToSchema('blockRange', blockRange, schemas.blockRangeSchema);
assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
const logs = await this._subscriptionManager.getLogsAsync(
this.address,
eventName,
blockRange,
indexFilterValues,
ForwarderContract.ABI(),
);
return logs;
}
constructor(
public subscribe(
eventName: ZRXTokenEvents,
indexFilterValues: IndexedFilterValues,
callback: EventCallback,
isVerbose: boolean = false,
blockPollingIntervalMs?: number,
): string {
assert.doesBelongToStringEnum('eventName', eventName, ZRXTokenEvents);
assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
assert.isFunction('callback', callback);
const subscriptionToken = this._subscriptionManager.subscribe(
this.address,
eventName,
indexFilterValues,
ZRXTokenContract.ABI(),
callback,
isVerbose,
blockPollingIntervalMs,
);
return subscriptionToken;
}
/**
assert.isString('primaryType', primaryType);
const typedData = {
types: {
EIP712Domain: constants.DEFAULT_DOMAIN_SCHEMA.parameters,
...types,
},
domain: {
name: domain.name === undefined ? constants.EXCHANGE_DOMAIN_NAME : domain.name,
version: domain.version === undefined ? constants.EXCHANGE_DOMAIN_VERSION : domain.version,
chainId: domain.chainId,
verifyingContract: domain.verifyingContract,
},
message,
primaryType,
};
assert.doesConformToSchema('typedData', typedData, schemas.eip712TypedDataSchema);
return typedData;
},
/**
public async getLogsAsync(
eventName: ERC20TokenEvents,
blockRange: BlockRange,
indexFilterValues: IndexedFilterValues,
): Promise>> {
assert.doesBelongToStringEnum('eventName', eventName, ERC20TokenEvents);
assert.doesConformToSchema('blockRange', blockRange, schemas.blockRangeSchema);
assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
const logs = await this._subscriptionManager.getLogsAsync(
this.address,
eventName,
blockRange,
indexFilterValues,
ERC20TokenContract.ABI(),
);
return logs;
}
constructor(
isValidSwapQuote(variableName: string, swapQuote: SwapQuote): void {
sharedAssert.isHexString(`${variableName}.takerAssetData`, swapQuote.takerAssetData);
sharedAssert.isHexString(`${variableName}.makerAssetData`, swapQuote.makerAssetData);
sharedAssert.doesConformToSchema(`${variableName}.orders`, swapQuote.orders, schemas.signedOrdersSchema);
sharedAssert.doesConformToSchema(`${variableName}.feeOrders`, swapQuote.feeOrders, schemas.signedOrdersSchema);
assert.isValidSwapQuoteInfo(`${variableName}.bestCaseQuoteInfo`, swapQuote.bestCaseQuoteInfo);
assert.isValidSwapQuoteInfo(`${variableName}.worstCaseQuoteInfo`, swapQuote.worstCaseQuoteInfo);
if (utils.isSwapQuoteMarketBuy(swapQuote)) {
sharedAssert.isBigNumber(`${variableName}.makerAssetFillAmount`, swapQuote.makerAssetFillAmount);
} else if (utils.isSwapQuoteMarketSell(swapQuote)) {
sharedAssert.isBigNumber(`${variableName}.takerAssetFillAmount`, swapQuote.takerAssetFillAmount);
} else {
throw new Error(SwapQuoteConsumerError.InvalidMarketSellOrMarketBuySwapQuote);
}
},
isValidForwarderSwapQuote(variableName: string, swapQuote: SwapQuote, wethAssetData: string): void {
public async getLogsAsync(
eventName: ERC1155MintableEvents,
blockRange: BlockRange,
indexFilterValues: IndexedFilterValues,
): Promise>> {
assert.doesBelongToStringEnum('eventName', eventName, ERC1155MintableEvents);
assert.doesConformToSchema('blockRange', blockRange, schemas.blockRangeSchema);
assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
const logs = await this._subscriptionManager.getLogsAsync(
this.address,
eventName,
blockRange,
indexFilterValues,
ERC1155MintableContract.ABI(),
);
return logs;
}
constructor(
public subscribe(
eventName: StakingProxyEvents,
indexFilterValues: IndexedFilterValues,
callback: EventCallback,
isVerbose: boolean = false,
blockPollingIntervalMs?: number,
): string {
assert.doesBelongToStringEnum('eventName', eventName, StakingProxyEvents);
assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
assert.isFunction('callback', callback);
const subscriptionToken = this._subscriptionManager.subscribe(
this.address,
eventName,
indexFilterValues,
StakingProxyContract.ABI(),
callback,
isVerbose,
blockPollingIntervalMs,
);
return subscriptionToken;
}
/**
constructor(supportedProvider: SupportedProvider, config: ContractWrappersConfig) {
assert.doesConformToSchema('config', config, ContractWrappersConfigSchema);
const txDefaults = {
gasPrice: config.gasPrice,
};
this._web3Wrapper = new Web3Wrapper(supportedProvider, txDefaults);
const contractsArray = [
CoordinatorContract,
DevUtilsContract,
ERC20TokenContract,
ERC721TokenContract,
ExchangeContract,
ForwarderContract,
StakingContract,
WETH9Contract,
];
contractsArray.forEach(contract => {
this._web3Wrapper.abiDecoder.addABI(contract.ABI(), contract.contractName);
public subscribe(
eventName: ERC20ProxyEvents,
indexFilterValues: IndexedFilterValues,
callback: EventCallback,
isVerbose: boolean = false,
blockPollingIntervalMs?: number,
): string {
assert.doesBelongToStringEnum('eventName', eventName, ERC20ProxyEvents);
assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
assert.isFunction('callback', callback);
const subscriptionToken = this._subscriptionManager.subscribe(
this.address,
eventName,
indexFilterValues,
ERC20ProxyContract.ABI(),
callback,
isVerbose,
blockPollingIntervalMs,
);
return subscriptionToken;
}
/**