Skip to content

Commit

Permalink
fix fork creation
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanzhelyazkov committed Oct 28, 2024
1 parent 60fa652 commit 201bd04
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
8 changes: 7 additions & 1 deletion deployments/run-fork.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ else
project=${TENDERLY_PROJECT}
fi

echo "Creating a Mainnet Tenderly Fork... "
echo

TENDERLY_FORK_API="https://api.tenderly.co/api/v1/account/${username}/project/${project}/fork"

cleanup() {
Expand All @@ -30,9 +33,12 @@ fork_id=$(curl -sX POST "${TENDERLY_FORK_API}" \
-H "Content-Type: application/json" -H "X-Access-Key: ${TENDERLY_ACCESS_KEY}" \
-d '{"network_id": "1"}' | jq -r '.simulation_fork.id')

echo "Created a fork ${fork_id} at ${username}/${project}..."
echo "Created Tenderly Fork ${fork_id} at ${username}/${project}..."
echo

# Create a new dir for the deploy script files and copy them there
rm -rf deployments/tenderly && cp -rf deployments/mainnet/. deployments/tenderly

command="TENDERLY_FORK_ID=${fork_id} ${@:1}"

echo "Running:"
Expand Down
43 changes: 41 additions & 2 deletions deployments/setup-fork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DeployedContracts, getNamedSigners, isTenderlyFork, runPendingDeploymen
import Logger from '../utils/Logger';
import { NATIVE_TOKEN_ADDRESS } from '../utils/TokenData';
import { toWei } from '../utils/Types';
import { ZERO_ADDRESS } from '../utils/Constants';
import '@nomiclabs/hardhat-ethers';
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import '@tenderly/hardhat-tenderly';
Expand Down Expand Up @@ -41,6 +42,14 @@ const fundAccount = async (account: string, fundingRequests: FundingRequest[]) =
Logger.log(`Funding ${account}...`);

for (const fundingRequest of fundingRequests) {
// for tokens which are missing skip funding request
if (fundingRequest.token === ZERO_ADDRESS) {
continue;
}
const { whale } = fundingRequest;
if (!whale) {
continue;
}
if (fundingRequest.token === NATIVE_TOKEN_ADDRESS) {
await fundingRequest.whale.sendTransaction({
value: fundingRequest.amount,
Expand All @@ -51,7 +60,13 @@ const fundAccount = async (account: string, fundingRequests: FundingRequest[]) =
}

const tokenContract = await Contracts.ERC20.attach(fundingRequest.token);
await tokenContract.connect(fundingRequest.whale).transfer(account, fundingRequest.amount);
// check if whale has enough balance
const whaleBalance = await tokenContract.balanceOf(whale.address);
if (whaleBalance.lt(fundingRequest.amount)) {
Logger.error(`Whale ${whale.address} has insufficient balance for ${fundingRequest.token}`);
continue;
}
await tokenContract.connect(whale).transfer(account, fundingRequest.amount);
}
};

Expand Down Expand Up @@ -96,8 +111,32 @@ const fundAccounts = async () => {
}
];

if (DEV_ADDRESSES === undefined || DEV_ADDRESSES === '') {
Logger.log('No dev addresses to fund');
return;
}

const devAddresses = DEV_ADDRESSES.split(',');

for(const fundingRequest of fundingRequests) {
if(fundingRequest.token == ZERO_ADDRESS) {
Logger.log(`Skipping funding for ${fundingRequest.token}`);
}
const { whale } = fundingRequest;
if (!whale) {
continue;
}
const whaleBalance = await whale.getBalance();
// transfer ETH to the funding account if it doesn't have ETH

if (whaleBalance.lt(toWei(1))) {
await fundingRequests[0].whale.sendTransaction({
value: toWei(1),
to: whale.address
});
}
}

for (const account of devAddresses) {
await fundAccount(account, fundingRequests);
}
Expand Down Expand Up @@ -156,7 +195,7 @@ const main = async () => {

await archiveArtifacts();

const description = `${FORK_NAME} Fork`;
const description = FORK_NAME ? `Bancor V3 ${FORK_NAME} Fork` : 'Bancor V3 Mainnet Fork';

Logger.log('********************************************************************************');
Logger.log();
Expand Down

0 comments on commit 201bd04

Please sign in to comment.