-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1284 from airswap/develop
Publish latest to NPM
- Loading branch information
Showing
41 changed files
with
588 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const { | ||
chainNames, | ||
chainCurrencies, | ||
EVM_NATIVE_TOKEN_DECIMALS, | ||
} = require('@airswap/utils') | ||
|
||
module.exports = { | ||
displayDeployerInfo: async function (deployer) { | ||
const gasPrice = await deployer.getGasPrice() | ||
const chainId = await deployer.getChainId() | ||
const balance = ethers.utils.formatUnits( | ||
(await deployer.getBalance()).toString(), | ||
EVM_NATIVE_TOKEN_DECIMALS | ||
) | ||
console.log(`\nNetwork: ${chainNames[chainId].toUpperCase()}`) | ||
console.log(`Gas price: ${gasPrice / 10 ** 9} gwei`) | ||
console.log(`\nDeployer: ${deployer.address}`) | ||
console.log(`Balance: ${balance} ${chainCurrencies[chainId]}`) | ||
|
||
console.log( | ||
`\nNext contract address will be:\n${ethers.utils.getContractAddress({ | ||
from: deployer.address, | ||
nonce: await deployer.provider.getTransactionCount(deployer.address), | ||
})}\n` | ||
) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
require('dotenv').config({ path: './.env' }) | ||
const Confirm = require('prompt-confirm') | ||
const { ethers } = require('ethers') | ||
const { | ||
ChainIds, | ||
chainNames, | ||
chainCurrencies, | ||
apiUrls, | ||
getReceiptUrl, | ||
ADDRESS_ZERO, | ||
EVM_NATIVE_TOKEN_DECIMALS, | ||
} = require('@airswap/utils') | ||
|
||
const CONFIRMATIONS = 2 | ||
const RECIPIENT = '0x0000000000000000000000000000000000000000' | ||
|
||
async function main() { | ||
let chainId | ||
if (process.argv[2] === '--network') { | ||
chainId = ChainIds[process.argv[3].toUpperCase()] | ||
} | ||
|
||
if (!chainId) { | ||
console.log('Value for --network flag is required') | ||
return | ||
} | ||
|
||
const provider = new ethers.providers.JsonRpcProvider(apiUrls[chainId]) | ||
const deployer = new ethers.Wallet(process.env.PRIVATE_KEY, provider) | ||
const gasPrice = await deployer.getGasPrice() | ||
|
||
const balance = await deployer.getBalance() | ||
const balanceFormatted = ethers.utils.formatUnits( | ||
balance.toString(), | ||
EVM_NATIVE_TOKEN_DECIMALS | ||
) | ||
|
||
if (balance.isZero()) { | ||
console.log( | ||
`\n✘ Balance is already 0 on ${process.argv[3].toUpperCase()}.\n` | ||
) | ||
process.exit(0) | ||
} | ||
|
||
if (RECIPIENT === ADDRESS_ZERO) { | ||
console.log(`\n✘ RECIPIENT must be set.\n`) | ||
process.exit(0) | ||
} | ||
|
||
const estimation = await provider.estimateGas({ | ||
to: RECIPIENT, | ||
value: 1, | ||
}) | ||
|
||
const cost = estimation.mul(gasPrice) | ||
const costFormatted = ethers.utils.formatUnits( | ||
cost, | ||
EVM_NATIVE_TOKEN_DECIMALS | ||
) | ||
const value = balance.sub(cost) | ||
|
||
console.log(`\nNetwork: ${chainNames[chainId].toUpperCase()}`) | ||
console.log(`Gas price: ${gasPrice / 10 ** 9} gwei`) | ||
console.log(`\nDeployer: ${deployer.address}`) | ||
console.log(`Balance: ${balanceFormatted} ${chainCurrencies[chainId]}`) | ||
console.log(`Transfer cost: ${costFormatted} ${chainCurrencies[chainId]}`) | ||
console.log( | ||
`Net amount: ${ethers.utils.formatUnits( | ||
value, | ||
EVM_NATIVE_TOKEN_DECIMALS | ||
)} ${chainCurrencies[chainId]}\n` | ||
) | ||
|
||
if (value.isNegative()) { | ||
console.log(`✘ Not enough balance to perform transfer.\n`) | ||
process.exit(0) | ||
} | ||
|
||
const prompt = new Confirm(`Transfer ${balanceFormatted} to ${RECIPIENT}?`) | ||
if (await prompt.run()) { | ||
const tx = await deployer.sendTransaction({ | ||
to: RECIPIENT, | ||
value, | ||
gasPrice, | ||
}) | ||
console.log('Transferring...', getReceiptUrl(chainId, tx.hash), '\n') | ||
await tx.wait(CONFIRMATIONS) | ||
console.log(`✔ Balance transfer complete.\n`) | ||
} | ||
} | ||
|
||
main() | ||
.then(() => process.exit(0)) | ||
.catch((error) => { | ||
console.error(error) | ||
process.exit(1) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,19 @@ | ||
module.exports = { | ||
80001: 45223507, | ||
11155111: 5163580, | ||
1: 19169067, | ||
31: 4777071, | ||
41: 280846804, | ||
56: 35875924, | ||
97: 37478338, | ||
137: 53161285, | ||
8453: 10229545, | ||
17000: 882749, | ||
42161: 178078680, | ||
43113: 29753793, | ||
43114: 41340327, | ||
59140: 3405398, | ||
59144: 2075793, | ||
80001: 45576937, | ||
84532: 5688630, | ||
421614: 11923855, | ||
11155111: 5225773, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,19 @@ | ||
module.exports = { | ||
80001: '0x2f9848b5644833b9A55F14375D5dAFCFa4d0E107', | ||
11155111: '0x2f9848b5644833b9A55F14375D5dAFCFa4d0E107', | ||
1: '0xd88cf00477B0Edd2C514e6474Ecfc44222830F58', | ||
31: '0xd88cf00477B0Edd2C514e6474Ecfc44222830F58', | ||
41: '0xd88cf00477B0Edd2C514e6474Ecfc44222830F58', | ||
56: '0xd88cf00477B0Edd2C514e6474Ecfc44222830F58', | ||
97: '0xd88cf00477B0Edd2C514e6474Ecfc44222830F58', | ||
137: '0xd88cf00477B0Edd2C514e6474Ecfc44222830F58', | ||
8453: '0xd88cf00477B0Edd2C514e6474Ecfc44222830F58', | ||
17000: '0xd88cf00477B0Edd2C514e6474Ecfc44222830F58', | ||
42161: '0xd88cf00477B0Edd2C514e6474Ecfc44222830F58', | ||
43113: '0xd88cf00477B0Edd2C514e6474Ecfc44222830F58', | ||
43114: '0xd88cf00477B0Edd2C514e6474Ecfc44222830F58', | ||
59140: '0xd88cf00477B0Edd2C514e6474Ecfc44222830F58', | ||
59144: '0xd88cf00477B0Edd2C514e6474Ecfc44222830F58', | ||
80001: '0xd88cf00477B0Edd2C514e6474Ecfc44222830F58', | ||
84532: '0xd88cf00477B0Edd2C514e6474Ecfc44222830F58', | ||
421614: '0xd88cf00477B0Edd2C514e6474Ecfc44222830F58', | ||
11155111: '0xd88cf00477B0Edd2C514e6474Ecfc44222830F58', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
console.log(`\n✘ Balances is not ownable.\n`) | ||
console.log(`\n✘ BatchCall is not ownable.\n`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.