Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function scenarioAsync(): Promise {
await runMigrationsOnceIfRequiredAsync();
PrintUtils.printScenario('Match Orders');
// Initialize the ContractWrappers, this provides helper functions around calling
// 0x contracts as well as ERC20/ERC721 token contracts on the blockchain
const contractWrappers = new ContractWrappers(providerEngine, { networkId: NETWORK_CONFIGS.networkId });
// 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
export async function scenarioAsync(): Promise {
await runMigrationsOnceIfRequiredAsync();
PrintUtils.printScenario('Execute Transaction cancelOrderOrder');
// Initialize the ContractWrappers, this provides helper functions around calling
// 0x contracts as well as ERC20/ERC721 token contracts on the blockchain
const contractWrappers = new ContractWrappers(providerEngine, { networkId: NETWORK_CONFIGS.networkId });
// Initialize the Web3Wrapper, this provides helper functions around fetching
// account information, balances, general contract logs
const web3Wrapper = new Web3Wrapper(providerEngine);
const [maker, taker, sender] = await web3Wrapper.getAvailableAddressesAsync();
const feeRecipientAddress = sender;
const zrxTokenAddress = contractAddresses.zrxToken;
const etherTokenAddress = contractAddresses.etherToken;
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);
public async getUserAccountsAsync(): Promise {
utils.assert(!_.isUndefined(this._contractWrappers), 'ContractWrappers must be instantiated.');
const provider = this._contractWrappers.getProvider();
const web3Wrapper = new Web3Wrapper(provider);
const userAccountsIfExists = await web3Wrapper.getAvailableAddressesAsync();
return userAccountsIfExists;
}
// HACK: When a user is using a Ledger, we simply dispatch the selected userAddress, which
export async function scenarioAsync(): Promise {
await runMigrationsOnceIfRequiredAsync();
PrintUtils.printScenario('Fill Order with Fees');
// Initialize the ContractWrappers, this provides helper functions around calling
// 0x contracts as well as ERC20/ERC721 token contracts on the blockchain
const contractWrappers = new ContractWrappers(providerEngine, { networkId: NETWORK_CONFIGS.networkId });
// Initialize the Web3Wrapper, this provides helper functions around fetching
// account information, balances, general contract logs
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
private async _showEtherScanLinkAndAwaitTransactionMinedAsync(
txHash: string,
): Promise {
const etherScanLinkIfExists = sharedUtils.getEtherScanLinkIfExists(
txHash,
this.networkId,
EtherscanLinkSuffixes.Tx,
);
this._dispatcher.showFlashMessage(
React.createElement(TransactionSubmitted, {
etherScanLinkIfExists,
}),
);
const provider = this._contractWrappers.getProvider();
const web3Wrapper = new Web3Wrapper(provider);
const exchangeAbi = this._contractWrappers.exchange.abi;
web3Wrapper.abiDecoder.addABI(exchangeAbi);
const receipt = await web3Wrapper.awaitTransactionSuccessAsync(txHash);
return receipt;
}
private _doesUserAddressExist(): boolean {
export const runMigrationsOnceIfRequiredAsync = async (): Promise => {
if (NETWORK_CONFIGS === GANACHE_CONFIGS) {
PrintUtils.printScenario('Deploying Contracts');
const web3Wrapper = new Web3Wrapper(providerEngine);
const [owner] = await web3Wrapper.getAvailableAddressesAsync();
await runMigrationsOnceAsync(providerEngine, { from: owner });
}
};
async function calculateEndBlockAsync(provider: Web3ProviderEngine): Promise {
const web3Wrapper = new Web3Wrapper(provider);
const currentBlock = await web3Wrapper.getBlockNumberAsync();
return currentBlock - BLOCK_FINALITY_THRESHOLD;
}
constructor(supportedProvider: SupportedProvider, config: ContractWrappersConfig) {
assert.doesConformToSchema('config', config, ContractWrappersConfigSchema);
const txDefaults = {
gasPrice: config.gasPrice,
};
this._web3Wrapper = new Web3Wrapper(supportedProvider, txDefaults);
const contractsArray = [
CoordinatorContract,
DevUtilsContract,
ERC20TokenContract,
ERC721TokenContract,
ExchangeContract,
ForwarderContract,
StakingContract,
WETH9Contract,
];
contractsArray.forEach(contract => {
this._web3Wrapper.abiDecoder.addABI(contract.ABI(), contract.contractName);
});
const contractAddresses =
config.contractAddresses === undefined
? _getDefaultContractAddresses(config.chainId)