Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async ecSignOrderAsync(
supportedProvider: SupportedProvider,
order: Order,
signerAddress: string,
): Promise {
assert.doesConformToSchema('order', order, schemas.orderSchema, [schemas.hexSchema]);
try {
const signedOrder = await signatureUtils.ecSignTypedDataOrderAsync(supportedProvider, order, signerAddress);
return signedOrder;
} catch (err) {
// HACK: We are unable to handle specific errors thrown since provider is not an object
// under our control. It could be Metamask Web3, Ethers, or any general RPC provider.
// We check for a user denying the signature request in a way that supports Metamask and
// Coinbase Wallet. Unfortunately for signers with a different error message,
// they will receive two signature requests.
if (err.message.includes('User denied message signature')) {
throw err;
}
const orderHash = await orderHashUtils.getOrderHashAsync(order);
const signatureHex = await signatureUtils.ecSignHashAsync(supportedProvider, orderHash, signerAddress);
const signedOrder = {
...order,
getOrderHashHex(order: SignedOrder | Order): string {
try {
assert.doesConformToSchema('order', order, schemas.orderSchema, [schemas.hexSchema]);
} catch (error) {
if (_.includes(error.message, INVALID_TAKER_FORMAT)) {
const errMsg = `Order taker must be of type string. If you want anyone to be able to fill an order - pass ${NULL_ADDRESS}`;
throw new Error(errMsg);
}
throw error;
}
const orderHashBuff = orderHashUtils.getOrderHashBuffer(order);
const orderHashHex = `0x${orderHashBuff.toString('hex')}`;
return orderHashHex;
},
/**
getFeeAdjustedRateOfFeeOrder(feeOrder: Order): BigNumber {
assert.doesConformToSchema('feeOrder', feeOrder, schemas.orderSchema);
const zrxAmountAfterFees = feeOrder.makerAssetAmount.minus(feeOrder.takerFee);
assert.assert(
zrxAmountAfterFees.isGreaterThan(constants.ZERO_AMOUNT),
`Expected takerFee: ${JSON.stringify(feeOrder.takerFee)} to be less than makerAssetAmount: ${JSON.stringify(
feeOrder.makerAssetAmount,
)}`,
);
const rate = feeOrder.takerAssetAmount.div(zrxAmountAfterFees);
return rate;
},
};
public cancelOrderTx(order: Order | SignedOrder): string {
assert.doesConformToSchema('order', order, schemas.orderSchema);
const abiEncodedData = this._getExchangeContract().cancelOrder.getABIEncodedTransactionData(order);
return abiEncodedData;
}
/**
public async fillOrKillOrderAsync(
order: Order,
takerAssetFillAmount: BigNumber,
signature: string,
txData: TxData,
sendTxOpts: Partial = { shouldValidate: true },
): Promise {
assert.doesConformToSchema('order', order, schemas.orderSchema);
assert.isValidBaseUnitAmount('takerAssetFillAmount', takerAssetFillAmount);
return this._executeTxThroughCoordinatorAsync(
ExchangeFunctionName.FillOrKillOrder,
txData,
sendTxOpts,
[order],
order,
takerAssetFillAmount,
signature,
);
}
public matchOrdersTx(leftOrder: SignedOrder, rightOrder: SignedOrder): string {
assert.doesConformToSchema('leftOrder', leftOrder, schemas.orderSchema);
assert.doesConformToSchema('rightOrder', rightOrder, schemas.orderSchema);
const abiEncodedData = this._getExchangeContract().matchOrders.getABIEncodedTransactionData(
leftOrder,
rightOrder,
leftOrder.signature,
rightOrder.signature,
);
return abiEncodedData;
}
/**
public async cancelOrderAsync(
order: Order | SignedOrder,
orderTransactionOpts: OrderTransactionOpts = { shouldValidate: true },
): Promise {
assert.doesConformToSchema('order', order, schemas.orderSchema);
await assert.isSenderAddressAsync('order.maker', order.makerAddress, this._web3Wrapper);
assert.doesConformToSchema('orderTransactionOpts', orderTransactionOpts, orderTxOptsSchema, [txOptsSchema]);
const normalizedMakerAddress = order.makerAddress.toLowerCase();
if (orderTransactionOpts.shouldValidate) {
await this._exchangeContract.cancelOrder.callAsync(order, {
from: normalizedMakerAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,
nonce: orderTransactionOpts.nonce,
});
}
const txHash = await this._exchangeContract.cancelOrder.sendTransactionAsync(order, {
from: normalizedMakerAddress,
gas: orderTransactionOpts.gasLimit,
gasPrice: orderTransactionOpts.gasPrice,