Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
mnemonic,
nodeUrl,
store,
});
// Wait for channel to be available
const channelIsAvailable = async (channel) => {
const chan = await channel.getChannel()
return chan && chan.available
}
while (!(await channelIsAvailable(channel))) {
await new Promise(res => setTimeout(() => res(), 1000));
}
const freeBalanceAddress = channel.freeBalanceAddress || channel.myFreeBalanceAddress;
const token = new Contract(channel.config.contractAddresses.Token, tokenArtifacts.abi, cfWallet);
const swapRate = await channel.getLatestSwapRate(AddressZero, token.address);
console.log(`Client created successfully!`);
console.log(` - Public Identifier: ${channel.publicIdentifier}`);
console.log(` - Account multisig address: ${channel.opts.multisigAddress}`);
console.log(` - CF Account address: ${cfWallet.address}`);
console.log(` - Free balance address: ${freeBalanceAddress}`);
console.log(` - Token address: ${token.address}`);
console.log(` - Swap rate: ${swapRate}`)
channel.subscribeToSwapRates(AddressZero, token.address, (res) => {
if (!res || !res.swapRate) return;
console.log(`Got swap rate upate: ${this.state.swapRate} -> ${res.swapRate}`);
this.setState({ swapRate: res.swapRate });
})
throw new Error("No funder mnemonic provided");
}
if (!ethRpc) {
throw new Error("No eth rpc url provided");
}
if (!tokenAddress) {
throw new Error("No token address provided");
}
// make the funder account and wallet
const ethGift = "1";
const tokenGift = "10000";
const cfPath = "m/44'/60'/0'/25446";
const provider = new ethers.providers.JsonRpcProvider(ethRpc);
const funder = new ethers.Wallet.fromMnemonic(funderMnemonic).connect(provider);
const token = new ethers.Contract(tokenAddress, tokenArtifacts.abi, funder);
let obj = {};
for (let i = 0; i < number; i++) {
const botMnemonic = ethers.Wallet.createRandom().mnemonic;
const hdNode = ethers.utils.HDNode.fromMnemonic(botMnemonic).derivePath(cfPath);
const xpub = hdNode.neuter().extendedKey;
const addr = ethers.Wallet.fromMnemonic(botMnemonic, cfPath).address;
// send eth
console.log(`\nSending ${ethGift} eth to ${addr}`);
const ethTx = await funder.sendTransaction({
to: addr,
value: ethers.utils.parseEther(ethGift),
});
await funder.provider.waitForTransaction(ethTx.hash);
console.log(`Transaction mined! Hash: ${ethTx.hash}q`);
channel = await connext.connect({
ethProviderUrl: urls.ethProviderUrl,
logLevel: LOG_LEVEL,
channelProvider,
});
} else {
console.error("Could not create channel.");
return;
}
console.log(`Successfully connected channel`);
await channel.isAvailable();
const token = new Contract(
channel.config.contractAddresses.Token,
tokenArtifacts.abi,
ethProvider,
);
const swapRate = await channel.getLatestSwapRate(AddressZero, token.address);
console.log(`Client created successfully!`);
console.log(` - Public Identifier: ${channel.publicIdentifier}`);
console.log(` - Account multisig address: ${channel.multisigAddress}`);
console.log(` - CF Account address: ${channel.signerAddress}`);
console.log(` - Free balance address: ${channel.freeBalanceAddress}`);
console.log(` - Token address: ${token.address}`);
console.log(` - Swap rate: ${swapRate}`);
channel.subscribeToSwapRates(AddressZero, token.address, res => {
if (!res || !res.swapRate) return;
console.log(`Got swap rate upate: ${this.state.swapRate} -> ${res.swapRate}`);
this.setState({ swapRate: res.swapRate });