forked from bancorprotocol/carbon-contracts
-
Notifications
You must be signed in to change notification settings - Fork 1
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 bancorprotocol#124 from bancorprotocol/tenderly-te…
…stnet-support Tenderly testnet support
- Loading branch information
Showing
8 changed files
with
219 additions
and
10 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
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,182 @@ | ||
import Contracts from '../components/Contracts'; | ||
import { getNamedSigners, isTenderlyTestnet, runPendingDeployments } from '../utils/Deploy'; | ||
import Logger from '../utils/Logger'; | ||
import { ZERO_ADDRESS } from '../utils/Constants'; | ||
import { NATIVE_TOKEN_ADDRESS } from '../utils/TokenData'; | ||
import { toWei } from '../utils/Types'; | ||
import '@nomiclabs/hardhat-ethers'; | ||
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; | ||
import '@tenderly/hardhat-tenderly'; | ||
import '@typechain/hardhat'; | ||
import AdmZip from 'adm-zip'; | ||
import { BigNumber } from 'ethers'; | ||
import { getNamedAccounts } from 'hardhat'; | ||
import 'hardhat-deploy'; | ||
import { capitalize } from 'lodash'; | ||
import path from 'path'; | ||
|
||
interface EnvOptions { | ||
DEV_ADDRESSES: string; | ||
TESTNET_NAME: string; | ||
TENDERLY_PROJECT: string; | ||
TENDERLY_USERNAME: string; | ||
TENDERLY_TESTNET_ID: string; | ||
TENDERLY_FORK_NETWORK_NAME: string; | ||
TENDERLY_TESTNET_PROVIDER_URL?: string; | ||
} | ||
|
||
const { | ||
DEV_ADDRESSES, | ||
TESTNET_NAME, | ||
TENDERLY_PROJECT, | ||
TENDERLY_USERNAME, | ||
TENDERLY_TESTNET_ID: testnetId = '', | ||
TENDERLY_FORK_NETWORK_NAME = 'mainnet', | ||
TENDERLY_TESTNET_PROVIDER_URL: testnetRpcUrl | ||
}: EnvOptions = process.env as any as EnvOptions; | ||
|
||
interface FundingRequest { | ||
token: string; | ||
tokenName: string; | ||
amount: BigNumber; | ||
whale: SignerWithAddress; | ||
} | ||
|
||
const fundAccount = async (account: string, fundingRequests: FundingRequest[]) => { | ||
Logger.log(`Funding ${account}...`); | ||
|
||
for (const fundingRequest of fundingRequests) { | ||
// for tokens which are missing on a network skip funding request | ||
if (fundingRequest.token === ZERO_ADDRESS) { | ||
continue; | ||
} | ||
if (fundingRequest.token === NATIVE_TOKEN_ADDRESS) { | ||
await fundingRequest.whale.sendTransaction({ | ||
value: fundingRequest.amount, | ||
to: account | ||
}); | ||
|
||
continue; | ||
} | ||
|
||
const tokenContract = await Contracts.ERC20.attach(fundingRequest.token); | ||
await tokenContract.connect(fundingRequest.whale).transfer(account, fundingRequest.amount); | ||
} | ||
}; | ||
|
||
const fundAccounts = async () => { | ||
Logger.log('Funding test accounts...'); | ||
Logger.log(); | ||
|
||
const { dai, link, usdc, wbtc, bnt } = await getNamedAccounts(); | ||
const { ethWhale, bntWhale, daiWhale, linkWhale, usdcWhale, wbtcWhale } = await getNamedSigners(); | ||
|
||
const fundingRequests = [ | ||
{ | ||
token: NATIVE_TOKEN_ADDRESS, | ||
tokenName: 'eth', | ||
amount: toWei(1000), | ||
whale: ethWhale | ||
}, | ||
{ | ||
token: bnt, | ||
tokenName: 'bnt', | ||
amount: toWei(10_000), | ||
whale: bntWhale | ||
}, | ||
{ | ||
token: dai, | ||
tokenName: 'dai', | ||
amount: toWei(100_000), | ||
whale: daiWhale | ||
}, | ||
{ | ||
token: link, | ||
tokenName: 'link', | ||
amount: toWei(10_000), | ||
whale: linkWhale | ||
}, | ||
{ | ||
token: usdc, | ||
tokenName: 'usdc', | ||
amount: toWei(100_000, 6), | ||
whale: usdcWhale | ||
}, | ||
{ | ||
token: wbtc, | ||
tokenName: 'wbtc', | ||
amount: toWei(100, 8), | ||
whale: wbtcWhale | ||
} | ||
]; | ||
|
||
const devAddresses = DEV_ADDRESSES.split(','); | ||
|
||
for(const fundingRequest of fundingRequests) { | ||
if(fundingRequest.token == ZERO_ADDRESS) { | ||
Logger.log(`Skipping funding for ${fundingRequest.tokenName}`); | ||
} | ||
} | ||
|
||
for (const account of devAddresses) { | ||
await fundAccount(account, fundingRequests); | ||
} | ||
|
||
Logger.log(); | ||
}; | ||
|
||
const runDeployments = async () => { | ||
Logger.log('Running pending deployments...'); | ||
Logger.log(); | ||
|
||
await runPendingDeployments(); | ||
|
||
Logger.log(); | ||
}; | ||
|
||
const archiveArtifacts = async () => { | ||
const zip = new AdmZip(); | ||
|
||
const srcDir = path.resolve(path.join(__dirname, './tenderly-testnet')); | ||
const dest = path.resolve(path.join(__dirname, `../testnet-${testnetId}.zip`)); | ||
|
||
zip.addLocalFolder(srcDir); | ||
zip.writeZip(dest); | ||
|
||
Logger.log(`Archived ${srcDir} to ${dest}...`); | ||
Logger.log(); | ||
}; | ||
|
||
const main = async () => { | ||
if (!isTenderlyTestnet()) { | ||
throw new Error('Invalid network'); | ||
} | ||
|
||
Logger.log(); | ||
|
||
await runDeployments(); | ||
|
||
await fundAccounts(); | ||
|
||
await archiveArtifacts(); | ||
|
||
const networkName = capitalize(TENDERLY_FORK_NETWORK_NAME); | ||
|
||
const description = `${networkName} ${TESTNET_NAME ? TESTNET_NAME : ""} Tenderly Testnet`; | ||
|
||
Logger.log('********************************************************************************'); | ||
Logger.log(); | ||
Logger.log(description); | ||
Logger.log('‾'.repeat(description.length)); | ||
Logger.log(` RPC: ${testnetRpcUrl}`); | ||
Logger.log(` Dashboard: https://dashboard.tenderly.co/${TENDERLY_USERNAME}/${TENDERLY_PROJECT}/testnet/${testnetId}`); | ||
Logger.log(); | ||
Logger.log('********************************************************************************'); | ||
}; | ||
|
||
main() | ||
.then(() => process.exit(0)) | ||
.catch((error) => { | ||
Logger.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
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