Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// // console.log(result)
// // })
// })
// zeroEx.tokenRegistry.getTokensAsync().then((tokens) => {
// console.log('tokens returned')
// commit('ADD_TOKENS', tokens)
// console.log('tokens:', tokens)
// const symbols = getters.tokenSymbols
// var index = symbols.indexOf('WETH')
// if (index !== -1) {
// symbols[index] = 'ETH'
// }
//
// })
commit('SET_NULL_ADDRESS', ZeroEx.NULL_ADDRESS)
zeroEx.etherToken.getContractAddressAsync().then((address) => {
commit('SET_WETH_ADDRESS', address)
})
zeroEx.exchange.getZRXTokenAddressAsync().then((address) => {
commit('SET_ZRX_ADDRESS', address)
})
zeroEx.exchange.getContractAddressAsync().then((address) => {
commit('SET_EXCHANGE_ADDRESS', address)
})
zeroEx.getAvailableAddressesAsync().then((addresses) => {
commit('SET_ADDRESSES', addresses)
})
},
addTokenAddress ({commit}, address) {
const mainAsync = async () => {
// const tokens = transformToTokens(tokensToAddJSON);
const tokens = TOKENS_TO_ADD;
const provider = providerFactory.getLedgerProvider();
const zeroEx = new ZeroEx(provider, ZERO_EX_CONFIG);
const accounts = await zeroEx.getAvailableAddressesAsync();
const primaryAccount = _.head(accounts);
console.log(`Primary account address: ${primaryAccount}`);
const existingTokens = await zeroEx.tokenRegistry.getTokensAsync();
const existingTokenAddresses = _.map(existingTokens, token => token.address);
for (const token of tokens) {
if (!_.includes(existingTokenAddresses, token.address)) {
console.log(`Attempting to add token symbol: ${token.symbol} address: ${token.address}`);
const txHash = await zeroEx.tokenRegistry.addTokenAsync(token, primaryAccount || ZeroEx.NULL_ADDRESS);
console.log(`Awaiting txHash: ${txHash}`);
opn(`https://etherscan.io/tx/${txHash}`);
const txReceipt = await zeroEx.awaitTransactionMinedAsync(txHash);
console.log(`Added receipt: ${JSON.stringify(txReceipt)}`);
}
}
};
const setTakerAllowTxHash = await zeroEx.token.setUnlimitedProxyAllowanceAsync(WETH_ADDRESS, takerAddress);
await zeroEx.awaitTransactionMinedAsync(setTakerAllowTxHash);
console.log('Taker allowance mined...');
// Deposit WETH
const ethAmount = new BigNumber(1);
const ethToConvert = ZeroEx.toBaseUnitAmount(ethAmount, DECIMALS); // Number of ETH to convert to WETH
const convertEthTxHash = await zeroEx.etherToken.depositAsync(WETH_ADDRESS, ethToConvert, takerAddress);
await zeroEx.awaitTransactionMinedAsync(convertEthTxHash);
console.log(`${ethAmount} ETH -> WETH conversion mined...`);
// Generate order
const order = {
maker: makerAddress,
taker: ZeroEx.NULL_ADDRESS,
feeRecipient: ZeroEx.NULL_ADDRESS,
makerTokenAddress: ZRX_ADDRESS,
takerTokenAddress: WETH_ADDRESS,
exchangeContractAddress: EXCHANGE_ADDRESS,
salt: ZeroEx.generatePseudoRandomSalt(),
makerFee: new BigNumber(0),
takerFee: new BigNumber(0),
makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(0.2), DECIMALS), // Base 18 decimals
takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(0.3), DECIMALS), // Base 18 decimals
expirationUnixTimestampSec: new BigNumber(Date.now() + 3600000), // Valid for up to an hour
};
// Create orderHash
const orderHash = ZeroEx.getOrderHashHex(order);
// Signing orderHash -> ecSignature
await zeroEx.awaitTransactionMinedAsync(setTakerAllowTxHash);
console.log('Taker allowance mined...');
// Deposit WETH
const ethAmount = new BigNumber(1);
const ethToConvert = ZeroEx.toBaseUnitAmount(ethAmount, DECIMALS); // Number of ETH to convert to WETH
const convertEthTxHash = await zeroEx.etherToken.depositAsync(WETH_ADDRESS, ethToConvert, takerAddress);
await zeroEx.awaitTransactionMinedAsync(convertEthTxHash);
console.log(`${ethAmount} ETH -> WETH conversion mined...`);
// Generate order
const order = {
maker: makerAddress,
taker: ZeroEx.NULL_ADDRESS,
feeRecipient: ZeroEx.NULL_ADDRESS,
makerTokenAddress: ZRX_ADDRESS,
takerTokenAddress: WETH_ADDRESS,
exchangeContractAddress: EXCHANGE_ADDRESS,
salt: ZeroEx.generatePseudoRandomSalt(),
makerFee: new BigNumber(0),
takerFee: new BigNumber(0),
makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(0.2), DECIMALS), // Base 18 decimals
takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(0.3), DECIMALS), // Base 18 decimals
expirationUnixTimestampSec: new BigNumber(Date.now() + 3600000), // Valid for up to an hour
};
// Create orderHash
const orderHash = ZeroEx.getOrderHashHex(order);
// Signing orderHash -> ecSignature
const shouldAddPersonalMessagePrefix = false;
const mainAsync = async () => {
const provider = providerFactory.getLedgerProvider();
const zeroEx = new ZeroEx(provider, ZERO_EX_CONFIG);
const accounts = await zeroEx.getAvailableAddressesAsync();
const primaryAccount = _.head(accounts);
console.log(`Primary account address: ${primaryAccount}`);
const tokenAddresses = await zeroEx.tokenRegistry.getTokenAddressesAsync();
for (const addressToRemove of TOKEN_ADDRESSES_TO_REMOVE) {
console.log(`Attempting to remove token address: ${addressToRemove}`);
const index = _.indexOf(tokenAddresses, addressToRemove);
if (index >= 0) {
const txHash = await zeroEx.tokenRegistry.removeTokenAsync(
addressToRemove,
new BigNumber(index),
primaryAccount || ZeroEx.NULL_ADDRESS,
);
console.log(`Awaiting txHash: ${txHash}`);
const txReceipt = await zeroEx.awaitTransactionMinedAsync(txHash);
console.log(`Removed receipt: ${JSON.stringify(txReceipt)}`);
} else {
console.log(`Could not find token address: ${addressToRemove}`);
}
}
};