Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const makerAssetAmount = Web3Wrapper.toBaseUnitAmount(ASSET_AMOUNT, makerTokenIfExists.decimals);
const takerAssetAmount = Web3Wrapper.toBaseUnitAmount(ASSET_AMOUNT, takerTokenIfExists.decimals);
const makerAssetData = assetDataUtils.encodeERC20AssetData(makerTokenIfExists.address);
const takerAssetData = assetDataUtils.encodeERC20AssetData(takerTokenIfExists.address);
const contractAddresses = getContractAddressesForChainOrThrow(chainConfig.chainId);
const order: Order = {
makerAddress: configs.DISPENSER_ADDRESS,
takerAddress: req.params.recipient as string,
makerFee: ZERO,
takerFee: ZERO,
makerAssetAmount,
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,
exchangeAddress,
makerAddress: maker,
takerAddress: NULL_ADDRESS,
expirationTimeSeconds: randomExpiration,
makerAssetAmount,
takerAssetAmount,
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
return;
}
// Initialize the Web3Wrapper, this provides helper functions around fetching
// account information, balances, general contract logs
const web3Wrapper = new Web3Wrapper(providerEngine);
const [maker, taker] = await web3Wrapper.getAvailableAddressesAsync();
const printUtils = new PrintUtils(web3Wrapper, contractWrappers, { maker, taker }, { WETH: etherTokenAddress });
printUtils.printAccounts();
// the amount the maker is selling of maker asset (1 ERC721 Token)
const makerAssetAmount = new BigNumber(1);
// the amount the maker wants of taker asset
const takerAssetAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(0.1), DECIMALS);
// Generate a random token id
const tokenId = generatePseudoRandomSalt();
// 0x v2 uses hex encoded asset data strings to encode all the information needed to identify an asset
const makerAssetData = assetDataUtils.encodeERC721AssetData(dummyERC721TokenContract.address, tokenId);
const takerAssetData = assetDataUtils.encodeERC20AssetData(etherTokenAddress);
let txHash;
// Mint a new ERC721 token for the maker
const mintTxHash = await dummyERC721TokenContract.mint.sendTransactionAsync(maker, tokenId, { from: maker });
await printUtils.awaitTransactionMinedSpinnerAsync('Mint ERC721 Token', mintTxHash);
const erc721Token = new ERC721TokenContract(dummyERC721TokenContract.address, providerEngine);
// Allow the 0x ERC721 Proxy to move ERC721 tokens on behalf of maker
const makerERC721ApprovalTxHash = await erc721Token.setApprovalForAll.validateAndSendTransactionAsync(
contractAddresses.erc721Proxy,
true,
{ from: maker },
);
['Taker ZRX Approval', takerZRXApprovalTxHash],
['Taker WETH Approval', takerWETHApprovalTxHash],
['Taker WETH Deposit', takerWETHDepositTxHash],
]);
// Set up the Order and fill it
const randomExpiration = getRandomFutureDateInSeconds();
// Create the order
const orderWithoutExchangeAddress = {
makerAddress: maker,
takerAddress: NULL_ADDRESS,
senderAddress: NULL_ADDRESS,
feeRecipientAddress,
expirationTimeSeconds: randomExpiration,
salt: generatePseudoRandomSalt(),
makerAssetAmount,
takerAssetAmount,
makerAssetData,
takerAssetData,
makerFee,
takerFee,
};
const exchangeAddress = contractAddresses.exchange;
const order: Order = {
...orderWithoutExchangeAddress,
exchangeAddress,
};
printUtils.printOrder(order);
// Print out the Balances and Allowances
// 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,
};
let orderInfo = await contractWrappers.exchange.getOrderInfo.callAsync(signedOrder);
printUtils.printOrderInfos({ order: orderInfo });
// This is an ABI encoded function call that the taker wishes to perform
// in this scenario it is a fillOrder
const cancelData = contractWrappers.exchange.cancelOrder.getABIEncodedTransactionData(signedOrder);
// Generate a random salt to mitigate replay attacks
const makerCancelOrderTransactionSalt = generatePseudoRandomSalt();
// The maker signs the operation data (cancelOrder) with the salt
const zeroExTransaction = {
data: cancelData,
salt: makerCancelOrderTransactionSalt,
signerAddress: maker,
verifyingContractAddress: contractAddresses.exchange,
};
const executeTransactionHex = transactionHashUtils.getTransactionHashHex(zeroExTransaction);
const makerCancelOrderSignatureHex = await signatureUtils.ecSignHashAsync(
providerEngine,
executeTransactionHex,
maker,
);
// The sender submits this operation via executeTransaction passing in the signature from the taker
txHash = await contractWrappers.exchange.executeTransaction.validateAndSendTransactionAsync(
zeroExTransaction.salt,
['Maker ERC721 Token Approval', makerERC721ApprovalTxHash],
]);
// Set up the Order and fill it
const randomExpiration = getRandomFutureDateInSeconds();
const exchangeAddress = contractAddresses.exchange;
// Create the order
const order: Order = {
exchangeAddress,
makerAddress: maker,
takerAddress: NULL_ADDRESS,
senderAddress: NULL_ADDRESS,
feeRecipientAddress: NULL_ADDRESS,
expirationTimeSeconds: randomExpiration,
salt: generatePseudoRandomSalt(),
makerAssetAmount,
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);
// Maker signs the order
['Taker WETH Deposit', takerWETHDepositTxHash],
]);
// Set up the Order and fill it
const randomExpiration = getRandomFutureDateInSeconds();
const exchangeAddress = contractAddresses.exchange;
// Create the order
const order: Order = {
exchangeAddress,
makerAddress: maker,
takerAddress: NULL_ADDRESS,
senderAddress: NULL_ADDRESS,
feeRecipientAddress: NULL_ADDRESS,
expirationTimeSeconds: randomExpiration,
salt: generatePseudoRandomSalt(),
makerAssetAmount,
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
['Taker WETH Deposit', takerWETHDepositTxHash],
]);
// Set up the Order and fill it
const randomExpiration = getRandomFutureDateInSeconds();
const exchangeAddress = contractAddresses.exchange;
// Create the order
const order: Order = {
exchangeAddress,
makerAddress: maker,
takerAddress: NULL_ADDRESS,
senderAddress: NULL_ADDRESS,
feeRecipientAddress: NULL_ADDRESS,
expirationTimeSeconds: randomExpiration,
salt: generatePseudoRandomSalt(),
makerAssetAmount,
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