Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
select: function(operation, callback) {
try {
console.log(`\n${chalk.white.bold('AirSwap')}:Â ${chalk.white.bold(operation)}`)
// The private key used to sign orders
if (!process.env.ETHEREUM_ACCOUNT) throw new Error('ETHEREUM_ACCOUNT must be set in your .env file')
const currentAccount = new ethers.Wallet(Buffer.from(process.env.ETHEREUM_ACCOUNT, 'hex')).address
const selectedNetwork = constants.chainNames[process.env.CHAIN_ID || '4']
const networkName = process.env.CHAIN_ID === '1' ? chalk.green(selectedNetwork) : chalk.cyan(selectedNetwork)
console.log(chalk.gray(`Account ${currentAccount} ${networkName}\n`))
const signerPrivateKey = Buffer.from(process.env.ETHEREUM_ACCOUNT, 'hex')
const provider = ethers.getDefaultProvider(selectedNetwork)
const wallet = new ethers.Wallet(signerPrivateKey, provider)
const publicAddress = wallet.address
provider.getBalance(publicAddress).then(balance => {
if (balance.eq(0)) {
console.log(
chalk.red('\n\nError ') +
`The selected account (From .env: ${publicAddress}) must have some (${selectedNetwork}) ether to execute transactions.\n`,
async function erc20Transfer(cfg) {
try {
// consts
const depositer = constants.relayerAddresses[1];
const depositerPriv = constants.relayerPrivKeys[1];
const depositerWallet = new ethers.Wallet(depositerPriv, cfg.provider);
const recipient = constants.relayerAddresses[2];
// Instances
const erc20Instance = new ethers.Contract(constants.ERC20_ADDRESS, ERC20Contract.abi, depositerWallet);
const bridgeInstance = new ethers.Contract(constants.BRIDGE_ADDRESS, BridgeContract.abi, depositerWallet);
// Mint & Approve tokens
await erc20Instance.approve(constants.ERC20_HANDLER_ADDRESS, cfg.value);
console.log("[ERC20 Transfer] Approved tokens!");
const depositerPreBal = await erc20Instance.balanceOf(depositer);
const handlerPreBal = await erc20Instance.balanceOf(constants.ERC20_HANDLER_ADDRESS);
console.log("[ERC20 Transfer] Depositer token balance: ", depositerPreBal.toNumber());
console.log("[ERC20 Transfer] Handler token balance: ", handlerPreBal.toNumber());
console.log(cfg.dest)
// Make the deposit
if (cli.relayerThreshold <= cli.numRelayers) {
cli.relayerThreshold = cli.numRelayers;
}
if (cli.depositThreshold <= cli.numRelayers) {
cli.depositThreshold = cli.numRelayers;
}
if (cli.dest) {
cli.dest = Number(cli.dest);
}
if (cli.value) {
cli.value = Number(cli.value);
}
// Load the wallet to deploy the contract with
cli.mainWallet = new ethers.Wallet(constants.deployerPrivKey, cli.provider);
// Deployment is asynchronous, so we use an async IIFE
(async function () {
if (!cli.testOnly) {
await deploy.deployRelayerContract(cli);
await deploy.deployBridgeContract(cli);
await deploy.deployERC20Handler(cli);
//old
// await deploy.deployCentrifuge(cli);
// await deploy.deployEmitterTest(cli);
}
if (cli.depositErc) {
await trasnfer.erc20Transfer(cli);
} else if (cli.mintErc20) {
wallet.registerRpcMessageHandler(async (originString, requestObject) => {
console.log('received request', requestObject)
const privKey = await wallet.getAppKey();
console.log('privKey is ' + privKey)
const ethWallet = new ethers.Wallet(privKey, provider);
console.dir(ethWallet)
switch (requestObject.method) {
case 'address':
return ethWallet.address
case 'signMessage':
const message = requestObject.params[0]
console.log('trying to sign message', message)
return ethWallet.signMessage(message)
case 'sign':
const transaction = requestObject.params[0]
return ethWallet.sign(transaction)
default:
var wallet = new ethers.Wallet(privateKey);
wallet.encrypt(password, {
scrypt: {
N: 262144
}
}).then(function(finalAccount) {
finalAccountTmp = JSON.parse(finalAccount);
account = finalAccountTmp.address;
accountName = (new Date().toISOString() + '--' + account).split(':').join('-');
pathOfKey = pathOfKey + accountName;
fs.writeFileSync(pathOfKey, finalAccount, 'utf-8');
});
this.clearKeyFromPrivateKey();
this.$.importAnyDialog.close();
} else if (password.length > 0 && zxcvbn(password).score >= 2 && privateKey.length <= 64 && privateKey.length >= 60 && privateKey != password) {
var wallet = new ethers.Wallet("0x" + privateKey);
wallet.encrypt(password).then(function(finalAccount) {
finalAccountTmp = JSON.parse(finalAccount);
account = finalAccountTmp.address;
accountName = (new Date().toISOString() + '--' + account).split(':').join('-');
pathOfKey = pathOfKey + accountName;
fs.writeFileSync(pathOfKey, finalAccount, 'utf-8');
});
this.clearKeyFromPrivateKey();
this.$.importAnyDialog.close();
} else if (password.length = 0) {
this.clearKeyFromPrivateKey();
alert(document.querySelector("msc-profile-view").echo('profileJS_createNewAccount_password_empty'));
} else if (zxcvbn(password).score < 2) {
this.clearKeyFromPrivateKey();
alert(document.querySelector("msc-profile-view").echo('profileJS_createNewAccount_easy_password'));
} else if (privateKey = password) {
const getProposerSigner = async (): Promise => {
const l1Provider = new JsonRpcProvider(requiredEnvVars.L1_NODE_WEB3_URL)
if (useHardhat) {
if (!DEBUG_IMPERSONATE_PROPOSER_ADDRESS) {
throw new Error('Must pass DEBUG_IMPERSONATE_PROPOSER_ADDRESS')
}
await l1Provider.send('hardhat_impersonateAccount', [
DEBUG_IMPERSONATE_PROPOSER_ADDRESS,
])
return l1Provider.getSigner(DEBUG_IMPERSONATE_PROPOSER_ADDRESS)
}
if (PROPOSER_PRIVATE_KEY) {
return new Wallet(PROPOSER_PRIVATE_KEY, l1Provider)
} else if (PROPOSER_MNEMONIC) {
return Wallet.fromMnemonic(PROPOSER_MNEMONIC, PROPOSER_HD_PATH).connect(
l1Provider
)
}
throw new Error(
'Must pass one of PROPOSER_PRIVATE_KEY, MNEMONIC, or PROPOSER_MNEMONIC'
)
}
const encrypt = async (privateKey, password) => {
try {
const wallet = new Wallet(privateKey);
const encryptedJSON = await wallet.encrypt(password);
const encrypted = await JSON.parse(encryptedJSON);
return encrypted;
} catch (error) {
debug('encryptAndSave()', error);
throw error;
}
};
provider: function () {
network.setNetwork('ropsten')
wallet = new ethers.Wallet(network.privateKeys[0], network.provider)
return new HDWalletProvider(network.mnemonic, "https://ropsten.infura.io/metamask")
},
network_id: 3,
export const createInfuraRinkebyWalletSigner = async (wallet: Object) => {
let provider = new providers.InfuraProvider('rinkeby')
let signer = new Wallet(wallet.key, provider)
signer.signOrder = signOrder
signer.signTrade = signTrade
signer.createRawOrder = createRawOrder
signer.createOrderCancel = createOrderCancel
window.signer = { instance: signer, type: 'wallet' }
return wallet.address
}