Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]Chore: migrate from Infura to Alchemy #985

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ jobs:
lint-zen-bull-vault:
working_directory: ~/squeeth/packages/zen-bull
docker:
- image: ghcr.io/foundry-rs/foundry:latest
- image: ghcr.io/foundry-rs/foundry:nightly-0078471691de77b017b16ba0cd7aac6734b58db6
steps:
- checkout
- run:
Expand All @@ -240,7 +240,7 @@ jobs:
compile-zen-bull-vault:
working_directory: ~/squeeth/packages/zen-bull
docker:
- image: ghcr.io/foundry-rs/foundry:latest
- image: ghcr.io/foundry-rs/foundry:nightly-0078471691de77b017b16ba0cd7aac6734b58db6
steps:
- checkout
- run:
Expand All @@ -250,15 +250,15 @@ jobs:
test-zen-bull-vault:
working_directory: ~/squeeth/packages/zen-bull
docker:
- image: ghcr.io/foundry-rs/foundry:latest
- image: ghcr.io/foundry-rs/foundry:nightly-0078471691de77b017b16ba0cd7aac6734b58db6
steps:
- checkout
- run: cd packages/zen-bull-vault && FOUNDRY_PROFILE=test forge test -vv --gas-report

fuzzing-zen-bull-vault:
working_directory: ~/squeeth/packages/zen-bull
docker:
- image: ghcr.io/foundry-rs/foundry:latest
- image: ghcr.io/foundry-rs/foundry:nightly-0078471691de77b017b16ba0cd7aac6734b58db6
steps:
- checkout
- run:
Expand All @@ -278,7 +278,7 @@ jobs:
lint-crab-netting:
working_directory: ~/squeeth/packages/crab-netting
docker:
- image: ghcr.io/foundry-rs/foundry:latest
- image: ghcr.io/foundry-rs/foundry:nightly-0078471691de77b017b16ba0cd7aac6734b58db6
steps:
- checkout
- run:
Expand All @@ -288,7 +288,7 @@ jobs:
compile-crab-netting:
working_directory: ~/squeeth/packages/crab-netting
docker:
- image: ghcr.io/foundry-rs/foundry:latest
- image: ghcr.io/foundry-rs/foundry:nightly-0078471691de77b017b16ba0cd7aac6734b58db6
steps:
- checkout
- run:
Expand All @@ -298,7 +298,7 @@ jobs:
test-crab-netting:
working_directory: ~/squeeth/packages/crab-netting
docker:
- image: ghcr.io/foundry-rs/foundry:latest
- image: ghcr.io/foundry-rs/foundry:nightly-0078471691de77b017b16ba0cd7aac6734b58db6
steps:
- checkout
- run: cd packages/crab-netting && forge test -vv --gas-report
Expand All @@ -307,7 +307,7 @@ jobs:
lint-zen-bull-netting:
working_directory: ~/squeeth/packages/zen-bull-netting
docker:
- image: ghcr.io/foundry-rs/foundry:latest
- image: ghcr.io/foundry-rs/foundry:nightly-0078471691de77b017b16ba0cd7aac6734b58db6
steps:
- checkout
- run:
Expand All @@ -317,7 +317,7 @@ jobs:
compile-zen-bull-netting:
working_directory: ~/squeeth/packages/zen-bull-netting
docker:
- image: ghcr.io/foundry-rs/foundry:latest
- image: ghcr.io/foundry-rs/foundry:nightly-0078471691de77b017b16ba0cd7aac6734b58db6
steps:
- checkout
- run:
Expand All @@ -327,15 +327,15 @@ jobs:
test-zen-bull-netting:
working_directory: ~/squeeth/packages/zen-bull-netting
docker:
- image: ghcr.io/foundry-rs/foundry:latest
- image: ghcr.io/foundry-rs/foundry:nightly-0078471691de77b017b16ba0cd7aac6734b58db6
steps:
- checkout
- run: cd packages/zen-bull-netting && FOUNDRY_PROFILE=test forge test -vv --gas-report

fuzzing-zen-bull-netting:
working_directory: ~/squeeth/packages/zen-bull-netting
docker:
- image: ghcr.io/foundry-rs/foundry:latest
- image: ghcr.io/foundry-rs/foundry:nightly-0078471691de77b017b16ba0cd7aac6734b58db6
steps:
- checkout
- run:
Expand All @@ -345,9 +345,8 @@ jobs:

coverage-zen-bull-netting:
working_directory: ~/squeeth/packages/zen-bull-netting
docker:
# - image: ghcr.io/foundry-rs/foundry:nightly-e9f274df045d36527eff66f8a6d4e836c7227231
- image: ghcr.io/foundry-rs/foundry:latest
docker:
- image: ghcr.io/foundry-rs/foundry:nightly-0078471691de77b017b16ba0cd7aac6734b58db6
steps:
- checkout
- run: cd packages/zen-bull-netting && FOUNDRY_PROFILE=coverage forge coverage
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ build
.DS_Store
.env

packages/hardhat/.env*
packages/hardhat/.env

# debug
npm-debug.log*
Expand Down
12 changes: 12 additions & 0 deletions packages/hardhat/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Supply an ALCHEMY_KEY to deploy and run scripts
ALCHEMY_KEY=

# For hardhat fork
FORK_RPC_ENDPOINT=https://alchemy/key

# Unit test gas report
COINMARKETCAP=
REPORT_GAS=

# For contract verification
ETHERSCAN_KEY=
2 changes: 1 addition & 1 deletion packages/hardhat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ yarn chain
yarn deploy
```

to deploying on testnet, with INFURA_KEY specified as environment variable
to deploying on testnet, with ALCHEMY_KEY specified as environment variable

```shell
npx hardhat deploy --network ropsten
Expand Down
6 changes: 3 additions & 3 deletions packages/hardhat/ci/e2e.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

# TO RUN: execute in packages/hardhat dir: INFURA_KEY=key ./ci/e2e.sh
# TO RUN: execute in packages/hardhat dir: ALCHEMY_KEY=key ./ci/e2e.sh

echo "Starting E2E mainnet fork tests"
echo "Using the current Infura key: " $INFURA_KEY
echo "Using the current Alchemy key: " $ALCHEMY_KEY

$(npm bin)/hardhat node --fork https://mainnet.infura.io/v3/$INFURA_KEY --fork-block-number 14345140 --no-deploy --network hardhat > /dev/null 2>&1 & sleep 10 && MAINNET_FORK=true $(npm bin)/hardhat test ./test/e2e/**.ts
$(npm bin)/hardhat node --fork https://eth-mainnet.g.alchemy.com/v2/$ALCHEMY_KEY --fork-block-number 14345140 --no-deploy --network hardhat > /dev/null 2>&1 & sleep 10 && MAINNET_FORK=true $(npm bin)/hardhat test ./test/e2e/**.ts
9 changes: 0 additions & 9 deletions packages/hardhat/env.example

This file was deleted.

50 changes: 7 additions & 43 deletions packages/hardhat/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,9 @@ import './tasks/increaseSlot'

// Load env variables
dotenv.config()
const InfuraKey = process.env.INFURA_KEY
const alchemyKey = process.env.ALCHEMY_KEY
const fs = require("fs");

/*
📡 This is where you configure your deploy configuration for 🏗 scaffold-eth

check out `packages/scripts/deploy.js` to customize your deployment

out of the box it will auto deploy anything in the `contracts` folder and named *.sol
plus it will use *.args for constructor args
*/

//
// Select the network you want to deploy to here:
//
Expand Down Expand Up @@ -91,44 +82,26 @@ const config: HardhatUserConfig = {
(you can put in a mnemonic here to set the deployer locally)
*/
},
rinkeby: {
url: `https://rinkeby.infura.io/v3/${InfuraKey}`, // <---- YOUR INFURA ID! (or it won't work)
accounts,
},
goerli: {
url: `https://goerli.infura.io/v3/${InfuraKey}`, // <---- YOUR INFURA ID! (or it won't work)
accounts,
},
kovan: {
url: `https://kovan.infura.io/v3/${InfuraKey}`, // <---- YOUR INFURA ID! (or it won't work)
url: `https://eth-goerli.g.alchemy.com/v2/${alchemyKey}`,
accounts,
},
mainnet: {
url: `https://mainnet.infura.io/v3/${InfuraKey}`, // <---- YOUR INFURA ID! (or it won't work)
accounts,
},
ropsten: {
url: `https://ropsten.infura.io/v3/${InfuraKey}`, // <---- YOUR INFURA ID! (or it won't work)
accounts,
gas: 8000000000000000
},
xdai: {
url: "https://rpc.xdaichain.com/",
gasPrice: 1000000000,
url: `https://eth-mainnet.g.alchemy.com/v2/${alchemyKey}`,
accounts,
},
matic: {
url: "https://rpc-mainnet.maticvigil.com/",
url: "https://polygon-mainnet.g.alchemy.com/v2/",
gasPrice: 1000000000,
accounts,
},
rinkebyArbitrum: {
url: "https://rinkeby.arbitrum.io/rpc",
goerliArbitrum: {
url: `https://arb-goerli.g.alchemy.com/v2/${alchemyKey}`,
gasPrice: 30000000, // 0.03 gwei
gas: 30_000_000,
accounts,
companionNetworks: {
l1: "rinkeby",
l1: "goerli",
},
},
localArbitrum: {
Expand All @@ -147,15 +120,6 @@ const config: HardhatUserConfig = {
l2: "localArbitrum",
},
},
kovanOptimism: {
url: "https://kovan.optimism.io",
gasPrice: 0,
accounts,
ovm: true,
companionNetworks: {
l1: "kovan",
},
},
localOptimism: {
url: "http://localhost:8545",
gasPrice: 0,
Expand Down
8 changes: 4 additions & 4 deletions packages/hardhat/scripts/start_hardhat_fork.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# HOW TO USE:
# Run the following shell script using: INFURA_KEY=ur_keeeeey ./start_hardhat_fork.sh
# Run the following shell script using: ALCHEMY_KEY=ur_keeeeey ./start_hardhat_fork.sh
# To stop hardhat fork, run ./stop_hardhat_fork.sh

#!/bin/bash

infuraKey=$INFURA_KEY
alchemyKey=$ALCHEMY_KEY

echo "Using the current infura key: ${infuraKey}"
echo "Using the current alchemy key: ${alchemyKey}"

$(npm bin)/hardhat node --no-deploy --network hardhat --fork https://mainnet.infura.io/v3/$infuraKey
$(npm bin)/hardhat node --no-deploy --network hardhat --fork https://eth-mainnet.g.alchemy.com/v2/$alchemyKey
2 changes: 1 addition & 1 deletion packages/zen-bull-netting/src/FlashSwap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ library PoolAddress {
returns (PoolKey memory)
{
if (tokenA > tokenB) (tokenA, tokenB) = (tokenB, tokenA);
return PoolKey({token0: tokenA, token1: tokenB, fee: fee});
return PoolKey({ token0: tokenA, token1: tokenB, fee: fee });
}

/// @notice Deterministically computes the pool address given the factory and PoolKey
Expand Down
6 changes: 3 additions & 3 deletions packages/zen-bull-netting/src/NettingLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ library NettingLib {

emit TransferWethFromMarketMakers(
_trader, _oSqthToMint, wethAmount, remainingOsqthToMint, _clearingPrice
);
);
return (true, remainingOsqthToMint);
} else {
wethAmount = (_quantity * _clearingPrice) / 1e18;
Expand All @@ -63,7 +63,7 @@ library NettingLib {

emit TransferWethFromMarketMakers(
_trader, _quantity, wethAmount, remainingOsqthToMint, _clearingPrice
);
);
return (false, remainingOsqthToMint);
}
}
Expand Down Expand Up @@ -164,7 +164,7 @@ library NettingLib {

emit TransferWethToMarketMaker(
_trader, _bidId, _quantity, wethAmount, _remainingOsqthToPull, _clearingPrice
);
);

return _remainingOsqthToPull;
}
Expand Down
16 changes: 8 additions & 8 deletions packages/zen-bull-netting/src/ZenBullNetting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ contract ZenBullNetting is Ownable, EIP712, FlashSwap {
uint256 wethFromAuction = IWETH(weth).balanceOf(address(this));
IWETH(weth).withdraw(wethFromAuction);

ICrabStrategyV2(crab).deposit{value: ethIntoCrab}();
ICrabStrategyV2(crab).deposit{ value: ethIntoCrab }();

(uint256 wethToLend, uint256 usdcToBorrow) = NettingLib.calcWethToLendAndUsdcToBorrow(
eulerLens, zenBull, weth, usdc, IERC20(crab).balanceOf(address(this))
Expand Down Expand Up @@ -650,7 +650,7 @@ contract ZenBullNetting is Ownable, EIP712, FlashSwap {
usdcPoolFee: _params.wethUsdcPoolFee
});

IFlashZen(flashZenBull).flashDeposit{value: memVar.remainingEth}(params);
IFlashZen(flashZenBull).flashDeposit{ value: memVar.remainingEth }(params);
}
}

Expand Down Expand Up @@ -708,7 +708,7 @@ contract ZenBullNetting is Ownable, EIP712, FlashSwap {
zenBullAmountToSend,
k,
ethAmountToSend
);
);
} else {
ethBalance[depositReceipt.sender] -= memVar.remainingDeposits;

Expand All @@ -731,7 +731,7 @@ contract ZenBullNetting is Ownable, EIP712, FlashSwap {
zenBullAmountToSend,
k,
ethAmountToSend
);
);
break;
}
}
Expand All @@ -745,7 +745,7 @@ contract ZenBullNetting is Ownable, EIP712, FlashSwap {
_params.clearingPrice,
memVar.oSqthBalance,
k
);
);
}

/**
Expand Down Expand Up @@ -790,7 +790,7 @@ contract ZenBullNetting is Ownable, EIP712, FlashSwap {
);

// send WETH to market makers
IWETH(weth).deposit{value: address(this).balance - initialEthBalance}();
IWETH(weth).deposit{ value: address(this).balance - initialEthBalance }();
toExchange = oSqthAmount;
for (uint256 i = 0; i < _params.orders.length && toExchange > 0; i++) {
toExchange = NettingLib.transferWethToMarketMaker(
Expand Down Expand Up @@ -865,13 +865,13 @@ contract ZenBullNetting is Ownable, EIP712, FlashSwap {
uint256 zenBullAmountToBurn = abi.decode(callData, (uint256));

IZenBullStrategy(zenBull).withdraw(zenBullAmountToBurn);
IWETH(weth).deposit{value: amountToPay}();
IWETH(weth).deposit{ value: amountToPay }();
IWETH(weth).transfer(pool, amountToPay);
} else if (callSource == 1) {
uint256 wethToLend = abi.decode(callData, (uint256));

IWETH(weth).withdraw(IWETH(weth).balanceOf(address(this)));
IZenBullStrategy(zenBull).deposit{value: wethToLend}(
IZenBullStrategy(zenBull).deposit{ value: wethToLend }(
IERC20(crab).balanceOf(address(this))
);
IERC20(usdc).transfer(pool, amountToPay);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ contract ZenBullNettingBaseSetup is Test {

function _queueEth(address _user, uint256 _amount) internal {
vm.startPrank(_user);
zenBullNetting.queueEth{value: _amount}();
zenBullNetting.queueEth{ value: _amount }();
vm.stopPrank();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ contract DepositAuctionFuzzing is ZenBullNettingBaseSetup {
vm.deal(mm2, 5000e18);

vm.prank(mm1);
IWETH(WETH).deposit{value: 5000e18}();
IWETH(WETH).deposit{ value: 5000e18 }();
vm.prank(mm2);
IWETH(WETH).deposit{value: 5000e18}();
IWETH(WETH).deposit{ value: 5000e18 }();

// update ZenBull cap to 100000 ETH
vm.store(ZEN_BULL, bytes32(uint256(9)), bytes32(uint256(100000e18)));
Expand Down
Loading