Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private async _handleFillsAsync(
coordinatorOrders: Order[],
txOrigin: string,
signedTransaction: SignedZeroExTransaction,
takerAssetFillAmounts: BigNumber[],
chainId: number,
): Promise {
await Handlers._validateFillsAllowedOrThrowAsync(signedTransaction, coordinatorOrders, takerAssetFillAmounts);
const transactionHash = transactionHashUtils.getTransactionHashHex(signedTransaction);
const fillRequestReceivedEvent = {
type: EventTypes.FillRequestReceived,
data: {
transactionHash,
},
};
this._broadcastCallback(fillRequestReceivedEvent, chainId);
await utils.sleepAsync(this._configs.SELECTIVE_DELAY_MS); // Await selective delay
// Check that still a valid fill request after selective delay
if (this._configs.SELECTIVE_DELAY_MS !== 0) {
await Handlers._validateFillsAllowedOrThrowAsync(
signedTransaction,
coordinatorOrders,
takerAssetFillAmounts,
);
});
if (_.isEmpty(coordinatorOrders)) {
throw new ValidationError([
{
field: 'signedTransaction.data',
code: ValidationErrorCodes.NoCoordinatorOrdersIncluded,
reason:
'0x transaction data does not include any orders involving this coordinators feeRecipientAddresses',
},
]);
}
// 4. Enforce that a 0x transaction hasn't been used before. This prevents someone from requesting
// the same transaction with a different `txOrigin` in an attempt to fill the order through an
// alternative tx.origin entry-point.
const transactionHash = transactionHashUtils.getTransactionHashHex(signedTransaction);
const transactionIfExists = await transactionModel.findByHashAsync(transactionHash);
if (transactionIfExists !== undefined) {
throw new ValidationError([
{
field: 'signedTransaction',
code: ValidationErrorCodes.TransactionAlreadyUsed,
reason: `A transaction can only be approved once. To request approval to perform the same actions, generate and sign an identical transaction with a different salt value.`,
},
]);
}
// 5. Validate the 0x transaction signature
const isValidSignature = await this._chainIdToContractWrappers[chainId].exchange
.isValidHashSignature(transactionHash, signedTransaction.signerAddress, signedTransaction.signature)
.callAsync();
if (!isValidSignature) {