* UniswapV3 VIP (#237) * `@0x/contracts-zero-ex`: Add UniswapV3Feature * `@0x/contracts-zero-ex`: Add UniswapV3 VIP `@0x/contract-artifacts`: Regenerate. `@0x/contract-wrappers`: Regenerate. `@0x/asset-swapper`: Add UniswapV3 VIP support. * address review comments and appease linter * `@0x/contracts-zero-ex`: Add UniswapV3Feature tests * Multiplex UniswapV3 (#241) * Add UniswapV3 support to Multiplex batchFill * Add AssetSwapper support for Multiplex UniswapV3 * fix repo scripts that use PKG= env var (#242) Co-authored-by: Lawrence Forman <me@merklejerk.com> * `@0x/asset-swapper`: Adjust uniswap gas overhead Co-authored-by: Lawrence Forman <me@merklejerk.com> Co-authored-by: mzhu25 <mchl.zhu.96@gmail.com> * OTC orders feature (#244) * Add OTC orders feature contracts * Address PR feedback * Remove partial fills for takerSigned variant * Add function to query the min valid nonce * Add ETH support * Tightly pack expiry, nonceBucket, and nonce * Address PR feedback * OTC orders unit tests * Bump prettier version * Skip unnecessary math if takerTokenFillAmount == order.takerAmount * appease CI * Update contract-artifacts and contract-wrappers and CHANGELOGs * `@0x/contracts-zero-ex`: Address spot check feedback * `regen wrappers * prettier * `@0x/asset-swapper`: prettier and tweak gas schedule slightly for uni3 Co-authored-by: Lawrence Forman <me@merklejerk.com> Co-authored-by: mzhu25 <mchl.zhu.96@gmail.com>
53 lines
2.8 KiB
TypeScript
53 lines
2.8 KiB
TypeScript
import { constants, ExchangeFunctionName, orderHashUtils, provider } from '@0x/contracts-test-utils';
|
|
import { SignedOrder } from '@0x/types';
|
|
|
|
import { IExchangeContract } from './wrappers';
|
|
|
|
export const exchangeDataEncoder = {
|
|
encodeOrdersToExchangeData(fnName: ExchangeFunctionName, orders: SignedOrder[] = []): string {
|
|
const exchangeInstance = new IExchangeContract(constants.NULL_ADDRESS, provider);
|
|
let data;
|
|
if (constants.SINGLE_FILL_FN_NAMES.indexOf(fnName) !== -1) {
|
|
data = (exchangeInstance as any)
|
|
[fnName](orders[0], orders[0].takerAssetAmount, orders[0].signature)
|
|
.getABIEncodedTransactionData();
|
|
} else if (constants.BATCH_FILL_FN_NAMES.indexOf(fnName) !== -1) {
|
|
data = (exchangeInstance as any)
|
|
[fnName](
|
|
orders,
|
|
orders.map(order => order.takerAssetAmount),
|
|
orders.map(order => order.signature),
|
|
)
|
|
.getABIEncodedTransactionData();
|
|
} else if (constants.MARKET_FILL_FN_NAMES.indexOf(fnName) !== -1) {
|
|
const fillAsset = /Buy/.test(fnName) ? 'makerAssetAmount' : 'takerAssetAmount';
|
|
data = (exchangeInstance as any)
|
|
[fnName](
|
|
orders,
|
|
orders.map(order => order[fillAsset]).reduce((prev, curr) => prev.plus(curr)),
|
|
orders.map(order => order.signature),
|
|
)
|
|
.getABIEncodedTransactionData();
|
|
} else if (constants.MATCH_ORDER_FN_NAMES.indexOf(fnName) !== -1) {
|
|
data = exchangeInstance
|
|
.matchOrders(orders[0], orders[1], orders[0].signature, orders[1].signature)
|
|
.getABIEncodedTransactionData();
|
|
} else if (fnName === ExchangeFunctionName.CancelOrder) {
|
|
data = exchangeInstance.cancelOrder(orders[0]).getABIEncodedTransactionData();
|
|
} else if (fnName === ExchangeFunctionName.BatchCancelOrders) {
|
|
data = exchangeInstance.batchCancelOrders(orders).getABIEncodedTransactionData();
|
|
} else if (fnName === ExchangeFunctionName.CancelOrdersUpTo) {
|
|
data = exchangeInstance.cancelOrdersUpTo(constants.ZERO_AMOUNT).getABIEncodedTransactionData();
|
|
} else if (fnName === ExchangeFunctionName.PreSign) {
|
|
data = exchangeInstance.preSign(orderHashUtils.getOrderHashHex(orders[0])).getABIEncodedTransactionData();
|
|
} else if (fnName === ExchangeFunctionName.SetSignatureValidatorApproval) {
|
|
data = exchangeInstance
|
|
.setSignatureValidatorApproval(constants.NULL_ADDRESS, true)
|
|
.getABIEncodedTransactionData();
|
|
} else {
|
|
throw new Error(`Error: ${fnName} not a supported function`);
|
|
}
|
|
return data;
|
|
},
|
|
};
|