address feedback
This commit is contained in:
@@ -21,10 +21,6 @@ const NULL_ADDRESS = '0x0000000000000000000000000000000000000000';
|
||||
const MAINNET_CHAIN_ID = 1;
|
||||
const ONE_SECOND_MS = 1000;
|
||||
const DEFAULT_PER_PAGE = 1000;
|
||||
const PROXY_IDS = {
|
||||
ERC20_PROXY_ID: '0xf47261b0',
|
||||
ERC721_PROXY_ID: '0x02571792',
|
||||
};
|
||||
|
||||
const DEFAULT_ORDER_PRUNER_OPTS: OrderPrunerOpts = {
|
||||
expiryBufferMs: 120000, // 2 minutes
|
||||
@@ -118,5 +114,4 @@ export const constants = {
|
||||
MARKET_UTILS_AMOUNT_BUFFER_PERCENTAGE,
|
||||
BRIDGE_ASSET_DATA_PREFIX: '0xdc1600f3',
|
||||
DEFAULT_CURVE_OPTS,
|
||||
PROXY_IDS,
|
||||
};
|
||||
|
@@ -1,5 +1,6 @@
|
||||
import { ContractAddresses } from '@0x/contract-addresses';
|
||||
import { assetDataUtils, generatePseudoRandomSalt } from '@0x/order-utils';
|
||||
import { SignedOrder } from '@0x/types';
|
||||
import { AbiEncoder, BigNumber } from '@0x/utils';
|
||||
|
||||
import { constants } from '../../constants';
|
||||
@@ -20,6 +21,22 @@ const { INFINITE_TIMESTAMP_SEC, WALLET_SIGNATURE } = marketOperationUtilConstant
|
||||
export class CreateOrderUtils {
|
||||
private readonly _contractAddress: ContractAddresses;
|
||||
|
||||
// utility function for asset-swapper to ignore market operation utils for specific asset types
|
||||
public static convertNativeOrderToFullyFillableOptimizedOrders(order: SignedOrder): OptimizedMarketOrder {
|
||||
return {
|
||||
...order,
|
||||
fillableMakerAssetAmount: order.makerAssetAmount,
|
||||
fillableTakerAssetAmount: order.takerAssetAmount,
|
||||
fillableTakerFeeAmount: order.takerFee,
|
||||
fill: {
|
||||
source: ERC20BridgeSource.Native,
|
||||
totalMakerAssetAmount: order.makerAssetAmount,
|
||||
totalTakerAssetAmount: order.takerAssetAmount,
|
||||
subFills: [],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
constructor(contractAddress: ContractAddresses) {
|
||||
this._contractAddress = contractAddress;
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { assetDataUtils, orderCalculationUtils } from '@0x/order-utils';
|
||||
import { SignedOrder } from '@0x/types';
|
||||
import { AssetProxyId, SignedOrder } from '@0x/types';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
|
||||
import { fillableAmountsUtils } from './fillable_amounts_utils';
|
||||
import { MarketOperationUtils } from './market_operation_utils';
|
||||
import { CreateOrderUtils } from './market_operation_utils/create_order';
|
||||
import { ERC20BridgeSource, OptimizedMarketOrder } from './market_operation_utils/types';
|
||||
import { ProtocolFeeUtils } from './protocol_fee_utils';
|
||||
import { utils } from './utils';
|
||||
@@ -143,40 +144,30 @@ export class SwapQuoteCalculator {
|
||||
fees: _.mapValues(opts.fees, (v, k) => v.times(gasPrice)),
|
||||
};
|
||||
|
||||
const firstOrderMakerAssetData = !!prunedOrders[0] ? assetDataUtils.decodeAssetDataOrThrow(prunedOrders[0].makerAssetData) : { assetProxyId: ''};
|
||||
const firstOrderMakerAssetData = !!prunedOrders[0]
|
||||
? assetDataUtils.decodeAssetDataOrThrow(prunedOrders[0].makerAssetData)
|
||||
: { assetProxyId: '' };
|
||||
|
||||
if (firstOrderMakerAssetData.assetProxyId === constants.PROXY_IDS.ERC721_PROXY_ID ) {
|
||||
resultOrders = prunedOrders.map(o => {
|
||||
if (firstOrderMakerAssetData.assetProxyId === AssetProxyId.ERC721) {
|
||||
// HACK: to conform ERC721 orders to the output of market operation utils, assumes complete fillable
|
||||
return {
|
||||
...o,
|
||||
fillableMakerAssetAmount: o.makerAssetAmount,
|
||||
fillableTakerAssetAmount: o.takerAssetAmount,
|
||||
fillableTakerFeeAmount: o.takerFee,
|
||||
fill: {
|
||||
source: ERC20BridgeSource.Native,
|
||||
totalMakerAssetAmount: o.makerAssetAmount,
|
||||
totalTakerAssetAmount: o.takerAssetAmount,
|
||||
subFills: [],
|
||||
},
|
||||
};
|
||||
});
|
||||
resultOrders = prunedOrders.map(o => CreateOrderUtils.convertNativeOrderToFullyFillableOptimizedOrders(o));
|
||||
} else {
|
||||
if (operation === MarketOperation.Buy) {
|
||||
resultOrders = await this._marketOperationUtils.getMarketBuyOrdersAsync(
|
||||
prunedOrders,
|
||||
assetFillAmount.plus(slippageBufferAmount),
|
||||
_opts,
|
||||
opts,
|
||||
);
|
||||
} else {
|
||||
resultOrders = await this._marketOperationUtils.getMarketSellOrdersAsync(
|
||||
prunedOrders,
|
||||
assetFillAmount.plus(slippageBufferAmount),
|
||||
_opts,
|
||||
opts,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// assetData information for the result
|
||||
const { makerAssetData, takerAssetData } = prunedOrders[0];
|
||||
return this._createSwapQuoteAsync(
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { assetDataUtils } from '@0x/order-utils';
|
||||
import { AssetData, ERC20AssetData, ERC20BridgeAssetData, Order, SignedOrder } from '@0x/types';
|
||||
import { AssetProxyId, AssetData, ERC20AssetData, ERC20BridgeAssetData, Order, SignedOrder } from '@0x/types';
|
||||
import { BigNumber, NULL_BYTES } from '@0x/utils';
|
||||
import { Web3Wrapper } from '@0x/web3-wrapper';
|
||||
|
||||
@@ -15,9 +15,9 @@ export const utils = {
|
||||
const takerAssetData = assetDataUtils.decodeAssetDataOrThrow(o.takerAssetData);
|
||||
const makerAssetData = assetDataUtils.decodeAssetDataOrThrow(o.makerAssetData);
|
||||
return (
|
||||
(makerAssetData.assetProxyId === constants.PROXY_IDS.ERC20_PROXY_ID ||
|
||||
makerAssetData.assetProxyId === constants.PROXY_IDS.ERC721_PROXY_ID) &&
|
||||
takerAssetData.assetProxyId === constants.PROXY_IDS.ERC20_PROXY_ID &&
|
||||
(makerAssetData.assetProxyId === AssetProxyId.ERC20 ||
|
||||
makerAssetData.assetProxyId === AssetProxyId.ERC721) &&
|
||||
takerAssetData.assetProxyId === AssetProxyId.ERC20 &&
|
||||
firstOrderMakerAssetData.assetProxyId === makerAssetData.assetProxyId
|
||||
); // checks that all native order maker assets are of the same type
|
||||
});
|
||||
|
Reference in New Issue
Block a user