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 _convertDecodedLogToFillAsync(decodedLog: LogWithDecodedArgs): Promise {
const args = decodedLog.args;
const blockTimestamp = await this._web3Wrapper.getBlockTimestampAsync(decodedLog.blockHash);
const makerToken = assetDataUtils.decodeERC20AssetData(args.makerAssetData).tokenAddress;
const takerToken = assetDataUtils.decodeERC20AssetData(args.takerAssetData).tokenAddress;
const fill = {
filledTakerTokenAmount: args.takerAssetFilledAmount,
filledMakerTokenAmount: args.makerAssetFilledAmount,
logIndex: decodedLog.logIndex,
maker: args.makerAddress,
orderHash: args.orderHash,
taker: args.takerAddress,
makerToken,
takerToken,
paidMakerFee: args.makerFeePaid,
paidTakerFee: args.takerFeePaid,
transactionHash: decodedLog.transactionHash,
blockTimestamp,
};
return fill;
private async _checkForUntrackedTokensAndAskToAddAsync(): Promise {
if (!_.isEmpty(this.state.orderJSONErrMsg)) {
return;
}
const makerTokenAddress = assetDataUtils.decodeERC20AssetData(this.state.parsedOrder.signedOrder.makerAssetData)
.tokenAddress;
const takerTokenAddress = assetDataUtils.decodeERC20AssetData(this.state.parsedOrder.signedOrder.takerAssetData)
.tokenAddress;
const makerTokenIfExists = this.props.tokenByAddress[makerTokenAddress];
const takerTokenIfExists = this.props.tokenByAddress[takerTokenAddress];
const tokensToTrack: Token[] = [];
const isUnseenMakerToken = makerTokenIfExists === undefined;
const isMakerTokenTracked = makerTokenIfExists !== undefined && utils.isTokenTracked(makerTokenIfExists);
if (isUnseenMakerToken) {
tokensToTrack.push({
...this.state.parsedOrder.metadata.makerToken,
address: makerTokenAddress,
iconUrl: undefined,
trackedTimestamp: undefined,
isRegistered: false,
});
} else if (!isMakerTokenTracked) {
tokensToTrack.push(makerTokenIfExists);
private _getDependentOrderHashesByERC20AssetData(makerAddress: string, erc20AssetData: string): string[] {
const tokenAddress = assetDataUtils.decodeERC20AssetData(erc20AssetData).tokenAddress;
let dependentOrderHashes: string[] = [];
if (
!_.isUndefined(this._orderHashesByERC20ByMakerAddress[makerAddress]) &&
!_.isUndefined(this._orderHashesByERC20ByMakerAddress[makerAddress][tokenAddress])
) {
dependentOrderHashes = Array.from(this._orderHashesByERC20ByMakerAddress[makerAddress][tokenAddress]);
}
return dependentOrderHashes;
}
private _getDependentOrderHashesByERC721AssetData(makerAddress: string, erc721AssetData: string): string[] {
private _renderVisualOrder(): React.ReactNode {
const takerTokenAddress = assetDataUtils.decodeERC20AssetData(this.state.parsedOrder.signedOrder.takerAssetData)
.tokenAddress;
const takerToken = this.props.tokenByAddress[takerTokenAddress];
const orderTakerAmount = this.state.parsedOrder.signedOrder.takerAssetAmount;
const orderMakerAmount = this.state.parsedOrder.signedOrder.makerAssetAmount;
const takerAssetToken = {
amount: orderTakerAmount.minus(this.state.unavailableTakerAmount),
symbol: takerToken.symbol,
};
const fillToken = this.props.tokenByAddress[takerTokenAddress];
const makerTokenAddress = assetDataUtils.decodeERC20AssetData(this.state.parsedOrder.signedOrder.makerAssetData)
.tokenAddress;
const makerToken = this.props.tokenByAddress[makerTokenAddress];
const makerAssetToken = {
amount: orderMakerAmount
.times(takerAssetToken.amount)
.div(orderTakerAmount)
.integerValue(BigNumber.ROUND_FLOOR),
symbol: makerToken.symbol,
};
const fillAssetToken = {
amount: this.props.orderFillAmount,
symbol: takerToken.symbol,
};
const parsedOrderExpiration = this.state.parsedOrder.signedOrder.expirationTimeSeconds;
let orderReceiveAmount = 0;
const postProcess = async (
environment,
result,
{ params },
): Promise => {
const takerTokenAddress = assetDataUtils.decodeERC20AssetData(
params.signedOrder.takerAssetData,
).tokenAddress;
const takerToken = await getToken(environment, takerTokenAddress);
const info = {
hash: result.orderHash,
status: result.orderStatus,
takerFilled: createQuantity(takerToken, result.orderTakerAssetFilledAmount),
};
return info;
};
private async _convertDecodedLogToFillAsync(decodedLog: LogWithDecodedArgs): Promise {
const args = decodedLog.args;
const blockTimestamp = await this._web3Wrapper.getBlockTimestampAsync(decodedLog.blockHash);
const makerToken = assetDataUtils.decodeERC20AssetData(args.makerAssetData).tokenAddress;
const takerToken = assetDataUtils.decodeERC20AssetData(args.takerAssetData).tokenAddress;
const fill = {
filledTakerTokenAmount: args.takerAssetFilledAmount,
filledMakerTokenAmount: args.makerAssetFilledAmount,
logIndex: decodedLog.logIndex,
maker: args.makerAddress,
orderHash: args.orderHash,
taker: args.takerAddress,
makerToken,
takerToken,
paidMakerFee: args.makerFeePaid,
paidTakerFee: args.takerFeePaid,
transactionHash: decodedLog.transactionHash,
blockTimestamp,
};
return fill;
}
const approveOrder = async (
environment: Environment,
exchange: Address,
order: Order,
) => {
const erc20Proxy = await getAssetProxy(environment, exchange);
const makerTokenAddress = assetDataUtils.decodeERC20AssetData(
order.makerAssetData,
).tokenAddress;
const makerToken = await getToken(environment, makerTokenAddress);
const makerQuantity = createQuantity(
makerToken,
order.makerAssetAmount.toString(),
);
await approve(environment, { howMuch: makerQuantity, spender: erc20Proxy });
};
const orderInfo = await getOrderInfo(environment, contractAddress, {
signedOrder,
});
ensure(
orderInfo.status === `${OrderStatus.FILLABLE}`,
`Order is not fillable. Got status: ${OrderStatus[orderInfo.status]}`,
);
const validSignature = await isValidSignature(environment, contractAddress, {
signedOrder,
});
ensure(validSignature, 'Signature invalid');
const { tokenAddress } = assetDataUtils.decodeERC20AssetData(
signedOrder.takerAssetData,
);
const takerToken = await getToken(environment, tokenAddress);
const takerQuantity =
providedTakerQuantity ||
createQuantity(takerToken, signedOrder.takerAssetAmount.toString());
const erc20Proxy = await getAssetProxy(environment, contractAddress);
await approve(environment, { howMuch: takerQuantity, spender: erc20Proxy });
};