Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const web3Wrapper = new Web3Wrapper(providerEngine);
const [maker, taker, feeRecipient] = await web3Wrapper.getAvailableAddressesAsync();
const zrxTokenAddress = contractAddresses.zrxToken;
const etherTokenAddress = contractAddresses.etherToken;
const printUtils = new PrintUtils(
web3Wrapper,
contractWrappers,
{ maker, taker, feeRecipient },
{ WETH: etherTokenAddress, ZRX: zrxTokenAddress },
);
printUtils.printAccounts();
// the amount the maker is selling in 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;
let txReceipt;
const zrxToken = new ERC20TokenContract(zrxTokenAddress, providerEngine);
// Approve the ERC20 Proxy to move ZRX for maker and taker
const makerZRXApprovalTxHash = await zrxToken.approve.validateAndSendTransactionAsync(
contractAddresses.erc20Proxy,
UNLIMITED_ALLOWANCE_IN_BASE_UNITS,
// Initialize the Web3Wrapper, this provides helper functions around fetching
// account information, balances, general contract logs
const web3Wrapper = new Web3Wrapper(providerEngine);
const [leftMaker, rightMaker, matcherAccount] = await web3Wrapper.getAvailableAddressesAsync();
const zrxTokenAddress = contractAddresses.zrxToken;
const etherTokenAddress = contractAddresses.etherToken;
const printUtils = new PrintUtils(
web3Wrapper,
contractWrappers,
{ leftMaker, rightMaker, matcherAccount },
{ 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 },
);
// 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 zrxTokenAddress = contractAddresses.zrxToken;
const etherTokenAddress = contractAddresses.etherToken;
const printUtils = new PrintUtils(
web3Wrapper,
contractWrappers,
{ 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);
.createStakingPool(operatorSharePpm, true)
.awaitTransactionSuccessAsync({
from: maker,
});
const createStakingPoolLog = stakingPoolReceipt.logs[0];
const poolId = (createStakingPoolLog as any).args.poolId;
await printUtils.awaitTransactionMinedSpinnerAsync(`Create Pool ${poolId}`, stakingPoolReceipt.transactionHash);
// Approve the ZRX token for Staking using the ERC20Proxy
const zrxTokenContract = new ERC20TokenContract(zrxTokenAddress, providerEngine, { from: maker });
await zrxTokenContract
.approve(contractWrappers.contractAddresses.erc20Proxy, UNLIMITED_ALLOWANCE_IN_BASE_UNITS)
.sendTransactionAsync();
// Stake 1000 ZRX
const stakeAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(100), DECIMALS);
// Transfer the ZRX to the Staking Contract
txHash = await stakingContract.stake(stakeAmount).sendTransactionAsync({ from: maker });
await printUtils.awaitTransactionMinedSpinnerAsync('Stake ZRX', txHash);
// Move the staked ZRX to delegate the Staking Pool
txHash = await stakingContract
.moveStake(
{ status: StakeStatus.Undelegated, poolId: NIL_POOL_ID },
{ status: StakeStatus.Delegated, poolId },
stakeAmount,
)
.sendTransactionAsync({ from: maker });
await printUtils.awaitTransactionMinedSpinnerAsync('Move Stake To Pool', txHash);
// Join the Pool with another maker address
// This is useful if you wish to Market Make from different addresses
txHash = await stakingContract.joinStakingPoolAsMaker(poolId).sendTransactionAsync({ from: otherMaker });
const printUtils = new PrintUtils(
web3Wrapper,
contractWrappers,
{ maker, taker, sender },
{ 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);
// 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(
takerAddress: NULL_ADDRESS,
senderAddress: NULL_ADDRESS,
feeRecipientAddress: NULL_ADDRESS,
expirationTimeSeconds: randomExpiration,
salt: generatePseudoRandomSalt(),
makerAssetAmount,
takerAssetAmount,
makerAssetData,
takerAssetData,
makerFee: ZERO,
takerFee: ZERO,
};
PrintUtils.printData('Left Order', Object.entries(leftOrder));
// Create the matched order
const rightOrderTakerAssetAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(0.2), DECIMALS);
const rightOrder: Order = {
exchangeAddress,
makerAddress: rightMaker,
takerAddress: NULL_ADDRESS,
senderAddress: NULL_ADDRESS,
feeRecipientAddress: NULL_ADDRESS,
expirationTimeSeconds: randomExpiration,
salt: generatePseudoRandomSalt(),
makerAssetAmount: leftOrder.takerAssetAmount,
takerAssetAmount: rightOrderTakerAssetAmount,
makerAssetData: leftOrder.takerAssetData,
takerAssetData: leftOrder.makerAssetData,
makerFee: ZERO,
takerFee: ZERO,
};
PrintUtils.printData('Right Order', Object.entries(rightOrder));
const web3Wrapper = new Web3Wrapper(providerEngine);
const [maker, taker] = await web3Wrapper.getAvailableAddressesAsync();
const zrxTokenAddress = contractAddresses.zrxToken;
const etherTokenAddress = contractAddresses.etherToken;
const printUtils = new PrintUtils(
web3Wrapper,
contractWrappers,
{ 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
DUMMY_TOKEN_DECIMALS: new BigNumber(18),
DUMMY_TOKEN_TOTAL_SUPPLY: new BigNumber(0),
NULL_BYTES: '0x',
NUM_DUMMY_ERC20_TO_DEPLOY: 3,
NUM_DUMMY_ERC721_TO_DEPLOY: 2,
NUM_ERC721_TOKENS_TO_MINT: 2,
NUM_DUMMY_ERC1155_TO_DEPLOY: 1,
NUM_ERC1155_FUNGIBLE_TOKENS_MINT: 3,
NUM_ERC1155_NONFUNGIBLE_TOKENS_MINT: 3,
NULL_ADDRESS: '0x0000000000000000000000000000000000000000',
UNLIMITED_ALLOWANCE_IN_BASE_UNITS: new BigNumber(2).pow(256).minus(1),
TESTRPC_PRIVATE_KEYS: _.map(TESTRPC_PRIVATE_KEYS_STRINGS, privateKeyString => ethUtil.toBuffer(privateKeyString)),
INITIAL_ERC20_BALANCE: Web3Wrapper.toBaseUnitAmount(new BigNumber(10000), 18),
INITIAL_ERC20_ALLOWANCE: Web3Wrapper.toBaseUnitAmount(new BigNumber(10000), 18),
INITIAL_ERC1155_FUNGIBLE_BALANCE: Web3Wrapper.toBaseUnitAmount(new BigNumber(10000), 18),
INITIAL_ERC1155_FUNGIBLE_ALLOWANCE: Web3Wrapper.toBaseUnitAmount(new BigNumber(10000), 18),
STATIC_ORDER_PARAMS: {
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18),
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(200), 18),
makerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(1), 18),
takerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(1), 18),
},
WORD_LENGTH: 32,
ZERO_AMOUNT: new BigNumber(0),
PERCENTAGE_DENOMINATOR: new BigNumber(10).pow(18),
FUNCTIONS_WITH_MUTEX: [
'FILL_ORDER',
'FILL_OR_KILL_ORDER',
'BATCH_FILL_ORDERS',
'BATCH_FILL_OR_KILL_ORDERS',
'MARKET_BUY_ORDERS',
'MARKET_SELL_ORDERS',
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}`);
export function toBaseUnitAmount(amount: Numberish): BigNumber {
const decimals = 18;
const amountAsBigNumber = new BigNumber(amount);
const baseUnitAmount = Web3Wrapper.toBaseUnitAmount(amountAsBigNumber, decimals);
return baseUnitAmount;
}