Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
printUtils.printAccounts();
// the amount the maker is selling of maker asset
const makerAssetAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(5), DECIMALS);
// the amount the maker wants of taker asset
const takerAssetAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(0.1), DECIMALS);
// the amount of fees the maker pays in ZRX
const makerFee = Web3Wrapper.toBaseUnitAmount(new BigNumber(0.01), DECIMALS);
// the amount of fees the taker pays in ZRX
const takerFee = Web3Wrapper.toBaseUnitAmount(new BigNumber(0.01), DECIMALS);
// 0x v2 uses hex encoded asset data strings to encode all the information needed to identify an asset
const makerAssetData = assetDataUtils.encodeERC20AssetData(zrxTokenAddress);
const takerAssetData = assetDataUtils.encodeERC20AssetData(etherTokenAddress);
let txHash;
const zrxToken = new ERC20TokenContract(zrxTokenAddress, providerEngine);
// Approve the ERC20 Proxy to move ZRX for maker
const makerZRXApprovalTxHash = await zrxToken.approve.validateAndSendTransactionAsync(
contractAddresses.erc20Proxy,
UNLIMITED_ALLOWANCE_IN_BASE_UNITS,
{ from: maker },
);
await printUtils.awaitTransactionMinedSpinnerAsync('Maker ZRX Approval', makerZRXApprovalTxHash);
// Approve the ERC20 Proxy to move ZRX for taker
const takerZRXApprovalTxHash = await zrxToken.approve.validateAndSendTransactionAsync(
contractAddresses.erc20Proxy,
UNLIMITED_ALLOWANCE_IN_BASE_UNITS,
{ from: taker },
);
await printUtils.awaitTransactionMinedSpinnerAsync('Taker ZRX Approval', takerZRXApprovalTxHash);
);
printUtils.printAccounts();
// the amount the maker is selling of maker asset
const makerAssetAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(10), DECIMALS);
// the amount the maker wants of taker asset
const takerAssetAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(0.4), DECIMALS);
// 0x v2 uses hex encoded asset data strings to encode all the information needed to identify an asset
const makerAssetData = assetDataUtils.encodeERC20AssetData(zrxTokenAddress);
const takerAssetData = assetDataUtils.encodeERC20AssetData(etherTokenAddress);
let txHash;
let txReceipt;
// Allow the 0x ERC20 Proxy to move ZRX on behalf of makerAccount
const zrxToken = new ERC20TokenContract(zrxTokenAddress, providerEngine);
const etherToken = new ERC20TokenContract(etherTokenAddress, providerEngine);
const leftMakerZRXApprovalTxHash = await zrxToken.approve.validateAndSendTransactionAsync(
contractAddresses.erc20Proxy,
UNLIMITED_ALLOWANCE_IN_BASE_UNITS,
{ from: leftMaker },
);
await printUtils.awaitTransactionMinedSpinnerAsync('Left Maker ZRX Approval', leftMakerZRXApprovalTxHash);
// Approve the ERC20 Proxy to move ZRX for rightMaker
const rightMakerZRXApprovalTxHash = await zrxToken.approve.validateAndSendTransactionAsync(
contractAddresses.erc20Proxy,
UNLIMITED_ALLOWANCE_IN_BASE_UNITS,
{ from: rightMaker },
);
await printUtils.awaitTransactionMinedSpinnerAsync('Right Maker ZRX Approval', rightMakerZRXApprovalTxHash);
// Approve the ERC20 Proxy to move ZRX for matcherAccount
const matcherZRXApprovalTxHash = await zrxToken.approve.validateAndSendTransactionAsync(
printUtils.printAccounts();
// the amount the maker is selling of maker asset
const makerAssetAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(5), DECIMALS);
// the amount the maker wants of taker asset
const takerAssetAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(0.1), DECIMALS);
// the amount of fees the maker pays in ZRX
const makerFee = Web3Wrapper.toBaseUnitAmount(new BigNumber(0.01), DECIMALS);
// the amount of fees the taker pays in ZRX
const takerFee = Web3Wrapper.toBaseUnitAmount(new BigNumber(0.01), DECIMALS);
// 0x v2 uses hex encoded asset data strings to encode all the information needed to identify an asset
const makerAssetData = assetDataUtils.encodeERC20AssetData(zrxTokenAddress);
const takerAssetData = assetDataUtils.encodeERC20AssetData(etherTokenAddress);
let txHash;
const zrxToken = new ERC20TokenContract(zrxTokenAddress, providerEngine);
// Approve the ERC20 Proxy to move ZRX for maker
const makerZRXApprovalTxHash = await zrxToken.approve.validateAndSendTransactionAsync(
contractAddresses.erc20Proxy,
UNLIMITED_ALLOWANCE_IN_BASE_UNITS,
{ from: maker },
);
await printUtils.awaitTransactionMinedSpinnerAsync('Maker ZRX Approval', makerZRXApprovalTxHash);
// Approve the ERC20 Proxy to move ZRX for taker
const takerZRXApprovalTxHash = await zrxToken.approve.validateAndSendTransactionAsync(
contractAddresses.erc20Proxy,
UNLIMITED_ALLOWANCE_IN_BASE_UNITS,
{ from: taker },
);
await printUtils.awaitTransactionMinedSpinnerAsync('Taker ZRX Approval', takerZRXApprovalTxHash);
{ maker, taker },
{ WETH: etherTokenAddress, ZRX: zrxTokenAddress },
);
printUtils.printAccounts();
// the amount the maker is selling of maker asset
const makerAssetAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(5), DECIMALS);
// the amount the maker wants of taker asset
const takerAssetAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(0.1), DECIMALS);
// 0x v2 uses hex encoded asset data strings to encode all the information needed to identify an asset
const makerAssetData = assetDataUtils.encodeERC20AssetData(zrxTokenAddress);
const takerAssetData = assetDataUtils.encodeERC20AssetData(etherTokenAddress);
let txHash;
let txReceipt;
const zrxToken = new ERC20TokenContract(zrxTokenAddress, providerEngine);
// Allow the 0x ERC20 Proxy to move ZRX on behalf of makerAccount
const makerZRXApprovalTxHash = await zrxToken.approve.validateAndSendTransactionAsync(
contractAddresses.erc20Proxy,
UNLIMITED_ALLOWANCE_IN_BASE_UNITS,
{ from: maker },
);
await printUtils.awaitTransactionMinedSpinnerAsync('Maker ZRX Approval', makerZRXApprovalTxHash);
// Allow the 0x ERC20 Proxy to move WETH on behalf of takerAccount
const takerWETHApprovalTxHash = await contractWrappers.weth9.approve.validateAndSendTransactionAsync(
contractAddresses.erc20Proxy,
UNLIMITED_ALLOWANCE_IN_BASE_UNITS,
{ from: taker },
);
await printUtils.awaitTransactionMinedSpinnerAsync('Taker WETH Approval', takerWETHApprovalTxHash);
{ maker, taker },
{ WETH: etherTokenAddress, ZRX: zrxTokenAddress },
);
printUtils.printAccounts();
const makerAssetData = assetDataUtils.encodeERC20AssetData(zrxTokenAddress);
const takerAssetData = assetDataUtils.encodeERC20AssetData(etherTokenAddress);
// the amount the maker is selling of maker asset
const makerAssetAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(5), DECIMALS);
// the amount the maker wants of taker asset
const takerAssetAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(0.1), DECIMALS);
let txHash;
let txReceipt;
const zrxToken = new ERC20TokenContract(zrxTokenAddress, providerEngine);
// Allow the 0x ERC20 Proxy to move ZRX on behalf of makerAccount
const makerZRXApprovalTxHash = await zrxToken.approve.validateAndSendTransactionAsync(
contractAddresses.erc20Proxy,
UNLIMITED_ALLOWANCE_IN_BASE_UNITS,
{ from: maker },
);
await printUtils.awaitTransactionMinedSpinnerAsync('Maker ZRX Approval', makerZRXApprovalTxHash);
// Allow the 0x ERC20 Proxy to move ZRX on behalf of takerAccount
const takerZRXApprovalTxHash = await zrxToken.approve.validateAndSendTransactionAsync(
contractAddresses.erc20Proxy,
UNLIMITED_ALLOWANCE_IN_BASE_UNITS,
{ from: taker },
);
await printUtils.awaitTransactionMinedSpinnerAsync('Taker ZRX Approval', takerZRXApprovalTxHash);
{ maker, taker },
{ WETH: etherTokenAddress, ZRX: zrxTokenAddress },
);
printUtils.printAccounts();
// the amount the maker is selling of maker asset
const makerAssetAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(5), DECIMALS);
// the amount the maker wants of taker asset
const takerAssetAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(0.1), DECIMALS);
// 0x v2 uses hex encoded asset data strings to encode all the information needed to identify an asset
const makerAssetData = assetDataUtils.encodeERC20AssetData(zrxTokenAddress);
const takerAssetData = assetDataUtils.encodeERC20AssetData(etherTokenAddress);
let txHash;
let txReceipt;
const zrxToken = new ERC20TokenContract(zrxTokenAddress, providerEngine);
// Allow the 0x ERC20 Proxy to move ZRX on behalf of makerAccount
const makerZRXApprovalTxHash = await zrxToken.approve.validateAndSendTransactionAsync(
contractAddresses.erc20Proxy,
UNLIMITED_ALLOWANCE_IN_BASE_UNITS,
{ from: maker },
);
await printUtils.awaitTransactionMinedSpinnerAsync('Maker ZRX Approval', makerZRXApprovalTxHash);
// With the Forwarding contract, the taker requires no set up
PrintUtils.printData('Setup', [['Maker ZRX Approval', makerZRXApprovalTxHash]]);
// Set up the Order and fill it
const randomExpiration = getRandomFutureDateInSeconds();
const exchangeAddress = contractAddresses.exchange;
// Create the order
const order: Order = {
{ WETH: etherTokenAddress, ZRX: zrxTokenAddress },
);
printUtils.printAccounts();
// the amount the maker is selling of maker asset
const makerAssetAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(10), DECIMALS);
// the amount the maker wants of taker asset
const takerAssetAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(0.4), DECIMALS);
// 0x v2 uses hex encoded asset data strings to encode all the information needed to identify an asset
const makerAssetData = assetDataUtils.encodeERC20AssetData(zrxTokenAddress);
const takerAssetData = assetDataUtils.encodeERC20AssetData(etherTokenAddress);
let txHash;
let txReceipt;
// Allow the 0x ERC20 Proxy to move ZRX on behalf of makerAccount
const zrxToken = new ERC20TokenContract(zrxTokenAddress, providerEngine);
const etherToken = new ERC20TokenContract(etherTokenAddress, providerEngine);
const leftMakerZRXApprovalTxHash = await zrxToken.approve.validateAndSendTransactionAsync(
contractAddresses.erc20Proxy,
UNLIMITED_ALLOWANCE_IN_BASE_UNITS,
{ from: leftMaker },
);
await printUtils.awaitTransactionMinedSpinnerAsync('Left Maker ZRX Approval', leftMakerZRXApprovalTxHash);
// Approve the ERC20 Proxy to move ZRX for rightMaker
const rightMakerZRXApprovalTxHash = await zrxToken.approve.validateAndSendTransactionAsync(
contractAddresses.erc20Proxy,
UNLIMITED_ALLOWANCE_IN_BASE_UNITS,
{ from: rightMaker },
);
await printUtils.awaitTransactionMinedSpinnerAsync('Right Maker ZRX Approval', rightMakerZRXApprovalTxHash);
// Approve the ERC20 Proxy to move ZRX for matcherAccount
public async fetchAndPrintContractBalancesAsync(): Promise {
const flattenedBalances = [];
const flattenedAccounts = Object.keys(this._accounts).map(
account => account.charAt(0).toUpperCase() + account.slice(1),
);
for (const tokenSymbol in this._tokens) {
const balances = [tokenSymbol];
const tokenAddress = this._tokens[tokenSymbol];
for (const account in this._accounts) {
const address = this._accounts[account];
const token = new ERC20TokenContract(tokenAddress, this._contractWrappers.getProvider());
const balanceBaseUnits = await token.balanceOf.callAsync(address);
const balance = Web3Wrapper.toUnitAmount(balanceBaseUnits, DECIMALS);
balances.push(balance.toString());
}
flattenedBalances.push(balances);
}
const ethBalances = ['ETH'];
// ETH
for (const account in this._accounts) {
const address = this._accounts[account];
const balanceBaseUnits = await this._web3Wrapper.getBalanceInWeiAsync(address);
const balance = Web3Wrapper.toUnitAmount(balanceBaseUnits, DECIMALS);
ethBalances.push(balance.toString());
}
flattenedBalances.push(ethBalances);
const table = new Table({
return async () => {
logUtils.log(`Processing ${tokenSymbol} ${recipientAddress}`);
const amountToDispense = new BigNumber(DISPENSE_AMOUNT_TOKEN);
const tokenIfExists = _.get(TOKENS_BY_CHAIN, [chainId, tokenSymbol]);
if (tokenIfExists === undefined) {
throw new Error(`Unsupported asset type: ${tokenSymbol}`);
}
const baseUnitAmount = Web3Wrapper.toBaseUnitAmount(amountToDispense, tokenIfExists.decimals);
const erc20Token = new ERC20TokenContract(tokenIfExists.address, provider);
const userBalanceBaseUnits = await erc20Token.balanceOf.callAsync(recipientAddress);
const maxAmountBaseUnits = Web3Wrapper.toBaseUnitAmount(
new BigNumber(DISPENSE_MAX_AMOUNT_TOKEN),
tokenIfExists.decimals,
);
if (userBalanceBaseUnits.isGreaterThanOrEqualTo(maxAmountBaseUnits)) {
logUtils.log(
`User exceeded token balance maximum (${maxAmountBaseUnits}) ${recipientAddress} ${userBalanceBaseUnits} `,
);
return;
}
const txHash = await erc20Token.transfer.sendTransactionAsync(recipientAddress, baseUnitAmount, {
from: configs.DISPENSER_ADDRESS,
});
logUtils.log(`Sent ${amountToDispense} ${tokenSymbol} to ${recipientAddress} tx: ${txHash}`);
};