Skip to content

Commit

Permalink
Merge pull request #104 from OasisDEX/create-fork-and-add-funds-2-fix-3
Browse files Browse the repository at this point in the history
Improve create-fork-github function
  • Loading branch information
juan-langa authored Dec 15, 2023
2 parents 5808fe3 + 3bb46db commit b12e850
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 106 deletions.
68 changes: 56 additions & 12 deletions utils/tenderly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,54 @@ export const deleteFork = async (forkId: string) => {
return await request.delete(`${TENDERLY_FORK_API}/${forkId}`);
};

const mainnetTokenAddresses = {
DAI: '0x6b175474e89094c44da98b954eedeac495271d0f',
SDAI: '0x83F20F44975D03b1b09e64809B757c47f942BEeA',
RETH: '0xae78736cd615f374d3085123a210448e74fc6393',
WSTETH: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0',
CBETH: '0xbe9895146f7af43049ca1c1ae358b0541ea49704',
WBTC: '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599',
export const tokenAddresses = {
mainnet: {
AJNA: '0x9a96ec9b57fb64fbc60b423d1f4da7691bd35079',
CBETH: '0xbe9895146f7af43049ca1c1ae358b0541ea49704',
DAI: '0x6b175474e89094c44da98b954eedeac495271d0f',
GHO: '0x40D16FC0246aD3160Ccc09B8D0D3A2cD28aE6C2f',
RETH: '0xae78736cd615f374d3085123a210448e74fc6393',
SDAI: '0x83F20F44975D03b1b09e64809B757c47f942BEeA',
TBTC: '0x18084fbA666a33d37592fA2633fD49a74DD93a88',
USDC: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
WBTC: '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599',
WETH: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
WSTETH: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0',
},
arbitrum: {
DAI: '0xda10009cbd5d07dd0cecc66161fc93d7c9000da1',
RETH: '0xEC70Dcb4A1EFa46b8F2D97C310C9c4790ba5ffA8',
USDC: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
WBTC: '0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f',
WSTETH: '0x5979D7b546E38E414F7E9822514be443A4800529',
},
base: {
CBETH: '0x2Ae3F1Ec7F1F5012CFEab0185bfc7aa3cf0DEc22',
DAI: '0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb',
USDC: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
},
optimism: {
DAI: '0xda10009cbd5d07dd0cecc66161fc93d7c9000da1',
RETH: '0x9Bcef72be871e61ED4fBbc7630889beE758eb81D',
USDC: '0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85',
WBTC: '0x68f180fcCe6836688e9084f035309E29Bf0A2095',
WSTETH: '0x1F32b1c2345538c0c6f582fCB022739c4A194Ebb',
},
};

export const tokenBalances = {
AJNA: '10000',
CBETH: '1000',
DAI: '200000',
ETH: '1000',
GHO: '10000',
RETH: '1000',
SDAI: '200000',
TBTC: '10000',
USDC: '200000',
WBTC: '10',
WETH: '1000',
WSTETH: '1000',
};

/**
Expand All @@ -51,14 +92,15 @@ const mainnetTokenAddresses = {
*/
export const setTokenBalance = async ({
forkId,
network,
token,
balance,
walletAddress,
}: {
forkId: string;
token: 'ETH' | 'DAI' | 'SDAI' | 'RETH' | 'WSTETH' | 'CBETH' | 'WBTC';
network: 'mainnet' | 'optimism' | 'arbitrum' | 'base';
token: 'CBETH' | 'DAI' | 'ETH' | 'USDC' | 'RETH' | 'SDAI' | 'WBTC' | 'WSTETH';
balance: string;
// walletAddress?: string;
walletAddress: string;
}) => {
const provider = new JsonRpcProvider(`https://rpc.tenderly.co/fork/${forkId}`);
Expand All @@ -72,10 +114,12 @@ export const setTokenBalance = async ({
]);
} else {
await provider.send('tenderly_setErc20Balance', [
mainnetTokenAddresses[token],
tokenAddresses[network][token],
walletAddress,
token.includes('BTC')
token === 'WBTC'
? ethers.toQuantity(ethers.parseUnits(balance, 8))
: token === 'USDC'
? ethers.toQuantity(ethers.parseUnits(balance, 6))
: ethers.toQuantity(ethers.parseUnits(balance, 'ether')),
]);
}
Expand Down Expand Up @@ -216,7 +260,7 @@ export const setCbEthBalanceBase = async ({

/**
*
* @param wbtcBalance In cbETH units
* @param wbtcBalance In WBTC units
*/
export const setWbtcBalance = async ({
forkId,
Expand Down
59 changes: 33 additions & 26 deletions utilsManualTesting/createFork.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { input, rawlist } from '@inquirer/prompts';
import * as tenderly from '../utils/tenderly';

type Tokens = 'CBETH' | 'DAI' | 'ETH' | 'USDC' | 'RETH' | 'SDAI' | 'WBTC' | 'WSTETH';

let walletAddress: string;

(async () => {
const network: 'mainnet' | 'optimism' | 'arbitrum' | 'base' = await rawlist({
message: 'Select a network',
Expand All @@ -11,37 +15,40 @@ import * as tenderly from '../utils/tenderly';
{ name: 'Optimism', value: 'optimism' },
],
});
let walletAddress: string;

const tokens = Object.keys(tenderly.tokenAddresses[network]) as Tokens[];

const resp = await tenderly.createFork({ network });
const forkId = resp.data.root_transaction.fork_id;
console.log(`Selected network: ${network}`);

if (network === 'mainnet') {
walletAddress = await input({ message: 'Enter your wallet address: ' });
console.log(`Wallet address: ${walletAddress}`);

// When using 'Promise.all()' some of the transactions randomly fail
await tenderly.setTokenBalance({ forkId, token: 'ETH', balance: '5000', walletAddress });
await tenderly.setTokenBalance({ forkId, token: 'DAI', balance: '200000', walletAddress });
await tenderly.setTokenBalance({ forkId, token: 'SDAI', balance: '200000', walletAddress });
await tenderly.setTokenBalance({ forkId, token: 'RETH', balance: '5000', walletAddress });
await tenderly.setTokenBalance({ forkId, token: 'WSTETH', balance: '5000', walletAddress });
await tenderly.setTokenBalance({ forkId, token: 'CBETH', balance: '5000', walletAddress });
await tenderly.setTokenBalance({ forkId, token: 'WBTC', balance: '10', walletAddress });
}
walletAddress = await input({ message: 'Enter your wallet address: ' });

if (network === 'mainnet') {
console.log('-------------------------------------');
console.log('Tokens and balance:');
console.log('ETH - 5000');
console.log('RETH - 5000');
console.log('WSTETH - 5000');
console.log('CBETH - 5000');
console.log('DAI - 200000');
console.log('SDAI - 200000');
console.log('WBTC - 10');
console.log('-------------------------------------');
await tenderly.setTokenBalance({
forkId,
network,
token: 'ETH',
balance: tenderly.tokenBalances['ETH'],
walletAddress: walletAddress,
});

for (const token of tokens) {
await tenderly.setTokenBalance({
forkId,
network,
token,
balance: tenderly.tokenBalances[token],
walletAddress: walletAddress,
});
}

console.log(`Selected network: ${network}`);
console.log(`Wallet address: ${walletAddress}`);
console.log('-------------------------------------');
console.log('*** FUNDS ***');
console.log(`ETH - ${tenderly.tokenBalances['ETH']}`);
tokens.forEach((token) => {
console.log(`${token} - ${tenderly.tokenBalances[token]}`);
});
console.log('-------------------------------------');
console.log('Fork RPC: ', `https://rpc.tenderly.co/fork/${forkId}`);
})();
91 changes: 23 additions & 68 deletions utilsManualTesting/createForkGithub.ts
Original file line number Diff line number Diff line change
@@ -1,89 +1,44 @@
import * as tenderly from '../utils/tenderly';

type Networks = 'mainnet' | 'optimism' | 'arbitrum' | 'base';
type Tokens = 'CBETH' | 'DAI' | 'ETH' | 'USDC' | 'RETH' | 'SDAI' | 'WBTC' | 'WSTETH';

const { NETWORK, WALLET_ADDRESS } = process.env;
let network: Networks;
switch (NETWORK) {
case 'mainnet':
default:
network = 'mainnet';
break;
case 'arbitrum':
network = 'arbitrum';
break;
case 'base':
network = 'base';
break;
case 'optimism':
network = 'optimism';
break;
}
const network = NETWORK as Networks;

const tokens = Object.keys(tenderly.tokenAddresses[network]) as Tokens[];
let walletAddress: string = WALLET_ADDRESS;

(async () => {
const resp = await tenderly.createFork({ network });
const forkId = resp.data.root_transaction.fork_id;

if (NETWORK === 'mainnet') {
await tenderly.setTokenBalance({
forkId,
token: 'ETH',
balance: '5000',
walletAddress: walletAddress,
});
await tenderly.setTokenBalance({
forkId,
token: 'DAI',
balance: '200000',
walletAddress: WALLET_ADDRESS,
});
await tenderly.setTokenBalance({
forkId,
network,
token: 'ETH',
balance: tenderly.tokenBalances['ETH'],
walletAddress: walletAddress,
});

for (const token of tokens) {
await tenderly.setTokenBalance({
forkId,
token: 'SDAI',
balance: '200000',
network,
token,
balance: tenderly.tokenBalances[token],
walletAddress: walletAddress,
});
await tenderly.setTokenBalance({
forkId,
token: 'RETH',
balance: '5000',
walletAddress: WALLET_ADDRESS,
});
await tenderly.setTokenBalance({
forkId,
token: 'WSTETH',
balance: '5000',
walletAddress: WALLET_ADDRESS,
});
await tenderly.setTokenBalance({
forkId,
token: 'CBETH',
balance: '5000',
walletAddress: WALLET_ADDRESS,
});
await tenderly.setTokenBalance({
forkId,
token: 'WBTC',
balance: '10',
walletAddress: WALLET_ADDRESS,
});
}

console.log(`Selected network: ${NETWORK}`);
if (NETWORK === 'mainnet') {
console.log(`Wallet address: ${WALLET_ADDRESS}`);
console.log('-------------------------------------');
console.log('Tokens and balance:');
console.log('ETH - 5000');
console.log('RETH - 5000');
console.log('WSTETH - 5000');
console.log('CBETH - 5000');
console.log('DAI - 200000');
console.log('SDAI - 200000');
console.log('WBTC - 10');
console.log('-------------------------------------');
}
console.log(`Wallet address: ${WALLET_ADDRESS}`);
console.log('-------------------------------------');
console.log('*** FUNDS ***');
console.log(`ETH - ${tenderly.tokenBalances['ETH']}`);
tokens.forEach((token) => {
console.log(`${token} - ${tenderly.tokenBalances[token]}`);
});
console.log('-------------------------------------');
console.log('Fork RPC: ', `https://rpc.tenderly.co/fork/${forkId}`);
})();

0 comments on commit b12e850

Please sign in to comment.