Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
takerAssetAmount,
makerAssetData,
takerAssetData,
salt: generatePseudoRandomSalt(),
makerFeeAssetData: makerAssetData,
takerFeeAssetData: takerAssetData,
feeRecipientAddress: NULL_ADDRESS,
senderAddress: NULL_ADDRESS,
expirationTimeSeconds: new BigNumber(Date.now() + FIVE_DAYS_IN_MS)
// tslint:disable-next-line:custom-no-magic-numbers
.div(1000)
.integerValue(BigNumber.ROUND_FLOOR),
exchangeAddress: contractAddresses.exchange,
chainId: chainConfig.chainId,
};
const orderHash = orderHashUtils.getOrderHashHex(order);
const signature = await signatureUtils.ecSignHashAsync(
chainConfig.web3Wrapper.getProvider(),
orderHash,
configs.DISPENSER_ADDRESS,
);
const signedOrder: SignedOrder = {
...order,
signature,
};
const payload = JSON.stringify(signedOrder);
logUtils.log(`Dispensed signed order: ${payload}`);
res.status(constants.SUCCESS_STATUS).send(payload);
}
}
app.post('/v2/order', (req, res) => {
console.log('HTTP: POST order');
const networkIdRaw = req.query.networkId;
// tslint:disable-next-line:custom-no-magic-numbers
const networkId = parseInt(networkIdRaw, 10);
if (networkId !== NETWORK_CONFIGS.networkId) {
console.log(`Incorrect Network ID: ${networkId}`);
res.status(HTTP_BAD_REQUEST_STATUS).send({});
} else {
const signedOrder = parseHTTPOrder(req.body);
const orderHash = orderHashUtils.getOrderHashHex(signedOrder);
ordersByHash[orderHash] = signedOrder;
orders.push(signedOrder);
res.status(HTTP_OK_STATUS).send({});
}
});
app.listen(HTTP_PORT, () => console.log('Standard relayer API (HTTP) listening on port 3000!'));
takerFee,
};
const exchangeAddress = contractAddresses.exchange;
const order: Order = {
...orderWithoutExchangeAddress,
exchangeAddress,
};
printUtils.printOrder(order);
// Print out the Balances and Allowances
await printUtils.fetchAndPrintContractAllowancesAsync();
await printUtils.fetchAndPrintContractBalancesAsync();
// Generate the order hash and sign it
const orderHashHex = orderHashUtils.getOrderHashHex(order);
const signature = await signatureUtils.ecSignHashAsync(providerEngine, orderHashHex, maker);
const signedOrder: SignedOrder = {
...order,
signature,
};
// This is an ABI encoded function call that the taker wishes to perform
// in this scenario it is a fillOrder
const fillData = contractWrappers.exchange.fillOrder.getABIEncodedTransactionData(
signedOrder,
takerAssetAmount,
signedOrder.signature,
);
// Generate a random salt to mitigate replay attacks
const takerTransactionSalt = generatePseudoRandomSalt();
// Print out the Balances and Allowances
await printUtils.fetchAndPrintContractAllowancesAsync();
await printUtils.fetchAndPrintContractBalancesAsync();
// Match the orders via 0x Exchange
txHash = await contractWrappers.exchange.matchOrders.validateAndSendTransactionAsync(
leftSignedOrder,
rightSignedOrder,
leftSignedOrder.signature,
rightSignedOrder.signature,
{
gas: TX_DEFAULTS.gas,
from: matcherAccount,
},
);
const leftOrderHashHex = orderHashUtils.getOrderHashHex(leftOrder);
const rightOrderHashHex = orderHashUtils.getOrderHashHex(rightOrder);
txReceipt = await printUtils.awaitTransactionMinedSpinnerAsync('matchOrders', txHash);
printUtils.printTransaction('matchOrders', txReceipt, [
['left orderHash', leftOrderHashHex],
['right orderHash', rightOrderHashHex],
]);
// Print the Balances
await printUtils.fetchAndPrintContractBalancesAsync();
// Stop the Provider Engine
providerEngine.stop();
}
makerAssetAmount,
takerAssetAmount,
makerAssetData,
takerAssetData,
makerFee: ZERO,
takerFee: ZERO,
};
printUtils.printOrder(order);
// Print out the Balances and Allowances
await printUtils.fetchAndPrintContractAllowancesAsync();
await printUtils.fetchAndPrintContractBalancesAsync();
// Generate the order hash and sign it
const orderHashHex = orderHashUtils.getOrderHashHex(order);
const signature = await signatureUtils.ecSignHashAsync(providerEngine, orderHashHex, maker);
const signedOrder = { ...order, signature };
// Validate the order is Fillable before calling fillOrder
// Fill the Order via 0x Exchange contract
txHash = await contractWrappers.exchange.fillOrder.validateAndSendTransactionAsync(
signedOrder,
takerAssetAmount,
signedOrder.signature,
{ from: taker, gas: TX_DEFAULTS.gas },
);
txReceipt = await printUtils.awaitTransactionMinedSpinnerAsync('fillOrder', txHash);
printUtils.printTransaction('fillOrder', txReceipt, [['orderHash', orderHashHex]]);
// Print the Balances
await printUtils.fetchAndPrintContractBalancesAsync();
makerAssetData,
takerAssetData,
};
const orderConfig = await httpClient.getOrderConfigAsync(orderConfigRequest, {
networkId: NETWORK_CONFIGS.networkId,
});
// Create the order
const order: Order = {
salt: generatePseudoRandomSalt(),
...orderConfigRequest,
...orderConfig,
};
// Generate the order hash and sign it
const orderHashHex = orderHashUtils.getOrderHashHex(order);
const signature = await signatureUtils.ecSignHashAsync(providerEngine, orderHashHex, maker);
const signedOrder = { ...order, signature };
// Validate this order
// await contractWrappers.exchange.validateOrderFillableOrThrowAsync(signedOrder);
// Submit the order to the SRA Endpoint
await httpClient.submitOrderAsync(signedOrder, { networkId: NETWORK_CONFIGS.networkId });
// Taker queries the Orderbook from the Relayer
const orderbookRequest: OrderbookRequest = { baseAssetData: makerAssetData, quoteAssetData: takerAssetData };
const response = await httpClient.getOrderbookAsync(orderbookRequest, { networkId: NETWORK_CONFIGS.networkId });
if (response.asks.total === 0) {
throw new Error('No orders found on the SRA Endpoint');
}
const sraOrder = response.asks.records[0].order;
takerAssetAmount,
makerAssetData,
takerAssetData,
makerFee: ZERO,
takerFee: ZERO,
};
printUtils.printOrder(order);
// Print out the Balances and Allowances
await printUtils.fetchAndPrintContractAllowancesAsync();
await printUtils.fetchAndPrintContractBalancesAsync();
await printUtils.fetchAndPrintERC721OwnerAsync(dummyERC721TokenContract.address, tokenId);
// Generate the order hash and sign it
const orderHashHex = orderHashUtils.getOrderHashHex(order);
const signature = await signatureUtils.ecSignHashAsync(providerEngine, orderHashHex, maker);
const signedOrder = { ...order, signature };
// Fill the Order via 0x.js Exchange contract
txHash = await contractWrappers.exchange.fillOrder.validateAndSendTransactionAsync(
signedOrder,
takerAssetAmount,
signedOrder.signature,
{
gas: TX_DEFAULTS.gas,
from: taker,
},
);
const txReceipt = await printUtils.awaitTransactionMinedSpinnerAsync('fillOrder', txHash);
printUtils.printTransaction('fillOrder', txReceipt, [['orderHash', orderHashHex]]);
// Print the Balances
expirationTimeSeconds: new BigNumber(Math.floor(Date.now() / 1000)).add(
80000
),
salt: new BigNumber(555),
makerAssetAmount: new BigNumber(trade1.sellQuantity),
takerAssetAmount: new BigNumber(trade1.buyQuantity),
makerAssetData: assetDataUtils.encodeERC20AssetData(
mlnToken.options.address.toLowerCase()
),
takerAssetData: assetDataUtils.encodeERC20AssetData(
ethToken.options.address.toLowerCase()
),
makerFee: new BigNumber(0),
takerFee
};
const orderHashHex = orderHashUtils.getOrderHashHex(order);
orderSignature = await signatureUtils.ecSignOrderHashAsync(
web3.currentProvider,
orderHashHex,
deployer,
SignerType.Default
);
await mlnToken.methods
.approve(erc20ProxyAddress, trade1.sellQuantity)
.send({ from: deployer });
const signatureValid = await signatureUtils.isValidSignatureAsync(
web3.currentProvider,
orderHashHex,
orderSignature,
makerAddress
);