Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async matchOrdersAsync(
buyOrder: SignedOrder,
sellOrder: SignedOrder,
takerAddress: string,
orderTransactionOpts: OrderTransactionOpts = { shouldValidate: true },
): Promise {
// type assertions
assert.doesConformToSchema('buyOrder', buyOrder, schemas.signedOrderSchema);
assert.doesConformToSchema('sellOrder', sellOrder, schemas.signedOrderSchema);
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
assert.doesConformToSchema('orderTransactionOpts', orderTransactionOpts, orderTxOptsSchema, [txOptsSchema]);
const normalizedTakerAddress = takerAddress.toLowerCase();
// other assertions
if (
sellOrder.makerAssetData !== buyOrder.takerAssetData ||
sellOrder.takerAssetData !== buyOrder.makerAssetData
) {
throw new Error(DutchAuctionWrapperError.AssetDataMismatch);
}
// validate transaction
if (orderTransactionOpts.shouldValidate) {
await this._dutchAuctionContract.matchOrders.callAsync(
buyOrder,
sellOrder,
buyOrder.signature,
public async matchOrdersAsync(
buyOrder: SignedOrder,
sellOrder: SignedOrder,
takerAddress: string,
orderTransactionOpts: OrderTransactionOpts = { shouldValidate: true },
): Promise {
// type assertions
assert.doesConformToSchema('buyOrder', buyOrder, schemas.signedOrderSchema);
assert.doesConformToSchema('sellOrder', sellOrder, schemas.signedOrderSchema);
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
assert.doesConformToSchema('orderTransactionOpts', orderTransactionOpts, orderTxOptsSchema, [txOptsSchema]);
const normalizedTakerAddress = takerAddress.toLowerCase();
// other assertions
if (
sellOrder.makerAssetData !== buyOrder.takerAssetData ||
sellOrder.takerAssetData !== buyOrder.makerAssetData
) {
throw new Error(DutchAuctionWrapperError.AssetDataMismatch);
}
// validate transaction
if (orderTransactionOpts.shouldValidate) {
await this._dutchAuctionContract.matchOrders.callAsync(
buyOrder,
sellOrder,
public fillOrderNoThrowTx(signedOrder: SignedOrder, takerAssetFillAmount: BigNumber): string {
assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema);
assert.isValidBaseUnitAmount('takerAssetFillAmount', takerAssetFillAmount);
const abiEncodedData = this._getExchangeContract().fillOrderNoThrow.getABIEncodedTransactionData(
signedOrder,
takerAssetFillAmount,
signedOrder.signature,
);
return abiEncodedData;
}
/**
public async validateOrderFillableOrThrowAsync(
signedOrder: SignedOrder,
opts: ValidateOrderFillableOpts = {},
): Promise {
assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema);
assert.doesConformToSchema('opts', opts, validateOrderFillableOptsSchema);
const balanceAllowanceFetcher = new AssetBalanceAndProxyAllowanceFetcher(
this._erc20TokenWrapper,
this._erc721TokenWrapper,
BlockParamLiteral.Latest,
);
const balanceAllowanceStore = new BalanceAndProxyAllowanceLazyStore(balanceAllowanceFetcher);
const exchangeTradeSimulator = new ExchangeTransferSimulator(balanceAllowanceStore);
const filledCancelledFetcher = new OrderFilledCancelledFetcher(this, BlockParamLiteral.Latest);
let fillableTakerAssetAmount;
const shouldValidateRemainingOrderAmountIsFillable =
opts.validateRemainingOrderAmountIsFillable === undefined
? true
: opts.validateRemainingOrderAmountIsFillable;
public async submitOrderAsync(signedOrder: SignedOrder, requestOpts?: RequestOpts): Promise {
assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema);
const httpRequestOpts = {
params: requestOpts,
payload: signedOrder,
};
await this._requestAsync('/order', HttpRequestType.Post, httpRequestOpts);
}
private async _requestAsync(
public async getOrderAndTraderInfoAsync(order: SignedOrder, takerAddress: string): Promise {
assert.doesConformToSchema('order', order, schemas.signedOrderSchema);
assert.isETHAddressHex('takerAddress', takerAddress);
const orderAndTraderInfo = await this._orderValidatorContract.getOrderAndTraderInfo.callAsync(
order,
takerAddress,
);
const result = {
orderInfo: orderAndTraderInfo[0],
traderInfo: orderAndTraderInfo[1],
};
return result;
}
/**
public async addOrderAsync(signedOrder: SignedOrder): Promise {
assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema);
const orderHash = orderHashUtils.getOrderHashHex(signedOrder);
await assert.isValidSignatureAsync(this._provider, orderHash, signedOrder.signature, signedOrder.makerAddress);
const expirationUnixTimestampMs = signedOrder.expirationTimeSeconds.times(MILLISECONDS_IN_A_SECOND);
this._expirationWatcher.addOrder(orderHash, expirationUnixTimestampMs);
this._orderByOrderHash[orderHash] = signedOrder;
this._dependentOrderHashesTracker.addToDependentOrderHashes(signedOrder);
const orderAssetDatas = [signedOrder.makerAssetData, signedOrder.takerAssetData];
_.each(orderAssetDatas, assetData => this._addAssetDataToAbiDecoder(assetData));
}
/**
public async matchOrdersAsync(
leftSignedOrder: SignedOrder,
rightSignedOrder: SignedOrder,
takerAddress: string,
orderTransactionOpts: OrderTransactionOpts = { shouldValidate: true },
): Promise {
assert.doesConformToSchema('leftSignedOrder', leftSignedOrder, schemas.signedOrderSchema);
assert.doesConformToSchema('rightSignedOrder', rightSignedOrder, schemas.signedOrderSchema);
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
assert.doesConformToSchema('orderTransactionOpts', orderTransactionOpts, orderTxOptsSchema, [txOptsSchema]);
const normalizedTakerAddress = takerAddress.toLowerCase();
if (
rightSignedOrder.makerAssetData !== leftSignedOrder.takerAssetData ||
rightSignedOrder.takerAssetData !== leftSignedOrder.makerAssetData
) {
throw new Error(ExchangeWrapperError.AssetDataMismatch);
}
if (orderTransactionOpts.shouldValidate) {
await this._exchangeContract.matchOrders.callAsync(
leftSignedOrder,
rightSignedOrder,
leftSignedOrder.signature,
rightSignedOrder.signature,
{