Skip to content

Commit

Permalink
Use deployed contract fork in dev script
Browse files Browse the repository at this point in the history
  • Loading branch information
shanejearley committed Nov 3, 2023
1 parent 7be0cd2 commit ae04716
Show file tree
Hide file tree
Showing 22 changed files with 665 additions and 627 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,14 @@ Test the Ethereum contracts.

```zsh
# From the root directory
npm run test:ethereum
npm run test --workspace @casimir/ethereum
```

Deploy the Ethereum contracts to local network and simulate events and oracle handling.
Fork the Ethereum contracts to local network and simulate events and oracle handling.

```zsh
# From the root directory
npm run dev:ethereum
npm run dev --workspace @casimir/ethereum
```

See the [@casimir/ethereum README.md](contracts/ethereum/README.md) for detailed documentation.
Expand Down
3 changes: 2 additions & 1 deletion common/env/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ enum ETHEREUM_WS_URL {

enum HARDHAT_NETWORK_KEY {
GOERLI = 'TESTNET',
HARDHAT = 'TESTNET'
HARDHAT = 'TESTNET',
LOCALHOST = 'TESTNET'
}

export {
Expand Down
2 changes: 1 addition & 1 deletion common/env/src/mock/validators.json

Large diffs are not rendered by default.

27 changes: 11 additions & 16 deletions contracts/ethereum/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'hardhat-abi-exporter'
import 'hardhat-contract-sizer'
import 'solidity-docgen'
// import '@tenderly/hardhat-tenderly'
import { ETHEREUM_CONTRACTS, ETHEREUM_RPC_URL, ETHEREUM_SIGNERS, HARDHAT_NETWORK_KEY } from '@casimir/env'
import { ETHEREUM_CONTRACTS, ETHEREUM_RPC_URL, HARDHAT_NETWORK_KEY } from '@casimir/env'

// Seed is provided
const mnemonic = process.env.BIP39_SEED as string
Expand All @@ -30,6 +30,16 @@ const forkConfig = { url: forkUrl, blockNumber: parseInt(process.env.ETHEREUM_FO
const hardhatKey = hardhatNetwork?.toUpperCase() as keyof typeof HARDHAT_NETWORK_KEY
const networkKey = HARDHAT_NETWORK_KEY[hardhatKey] || 'TESTNET'

process.env.ETHEREUM_RPC_URL = process.env.ETHEREUM_RPC_URL || ETHEREUM_RPC_URL[networkKey]
process.env.FACTORY_ADDRESS = ETHEREUM_CONTRACTS[networkKey].FACTORY_ADDRESS
process.env.BEACON_LIBRARY_ADDRESS = ETHEREUM_CONTRACTS[networkKey].BEACON_LIBRARY_ADDRESS
process.env.MANAGER_BEACON_ADDRESS = ETHEREUM_CONTRACTS[networkKey].MANAGER_BEACON_ADDRESS
process.env.POOL_BEACON_ADDRESS = ETHEREUM_CONTRACTS[networkKey].POOL_BEACON_ADDRESS
process.env.REGISTRY_BEACON_ADDRESS = ETHEREUM_CONTRACTS[networkKey].REGISTRY_BEACON_ADDRESS
process.env.UPKEEP_BEACON_ADDRESS = ETHEREUM_CONTRACTS[networkKey].UPKEEP_BEACON_ADDRESS
process.env.VIEWS_BEACON_ADDRESS = ETHEREUM_CONTRACTS[networkKey].VIEWS_BEACON_ADDRESS
process.env.FUNCTIONS_BILLING_REGISTRY_ADDRESS = ETHEREUM_CONTRACTS[networkKey].FUNCTIONS_BILLING_REGISTRY_ADDRESS
process.env.FUNCTIONS_ORACLE_ADDRESS = ETHEREUM_CONTRACTS[networkKey].FUNCTIONS_ORACLE_ADDRESS
process.env.DEPOSIT_CONTRACT_ADDRESS = ETHEREUM_CONTRACTS[networkKey].DEPOSIT_CONTRACT_ADDRESS
process.env.KEEPER_REGISTRAR_ADDRESS = ETHEREUM_CONTRACTS[networkKey].KEEPER_REGISTRAR_ADDRESS
process.env.KEEPER_REGISTRY_ADDRESS = ETHEREUM_CONTRACTS[networkKey].KEEPER_REGISTRY_ADDRESS
Expand All @@ -42,21 +52,6 @@ process.env.SWAP_FACTORY_ADDRESS = ETHEREUM_CONTRACTS[networkKey].SWAP_FACTORY_A
process.env.SWAP_ROUTER_ADDRESS = ETHEREUM_CONTRACTS[networkKey].SWAP_ROUTER_ADDRESS
process.env.WETH_TOKEN_ADDRESS = ETHEREUM_CONTRACTS[networkKey].WETH_TOKEN_ADDRESS

if (hardhatNetwork !== 'localhost') {
process.env.ETHEREUM_RPC_URL = process.env.ETHEREUM_RPC_URL || ETHEREUM_RPC_URL[networkKey]
process.env.OWNER_ADDRESS = ETHEREUM_SIGNERS[networkKey].OWNER_ADDRESS
process.env.DAO_ORACLE_ADDRESS = ETHEREUM_SIGNERS[networkKey].DAO_ORACLE_ADDRESS
process.env.BEACON_LIBRARY_ADDRESS = ETHEREUM_CONTRACTS[networkKey].BEACON_LIBRARY_ADDRESS
process.env.MANAGER_BEACON_ADDRESS = ETHEREUM_CONTRACTS[networkKey].MANAGER_BEACON_ADDRESS
process.env.POOL_BEACON_ADDRESS = ETHEREUM_CONTRACTS[networkKey].POOL_BEACON_ADDRESS
process.env.REGISTRY_BEACON_ADDRESS = ETHEREUM_CONTRACTS[networkKey].REGISTRY_BEACON_ADDRESS
process.env.UPKEEP_BEACON_ADDRESS = ETHEREUM_CONTRACTS[networkKey].UPKEEP_BEACON_ADDRESS
process.env.VIEWS_BEACON_ADDRESS = ETHEREUM_CONTRACTS[networkKey].VIEWS_BEACON_ADDRESS
process.env.FACTORY_ADDRESS = ETHEREUM_CONTRACTS[networkKey].FACTORY_ADDRESS
process.env.FUNCTIONS_BILLING_REGISTRY_ADDRESS = ETHEREUM_CONTRACTS[networkKey].FUNCTIONS_BILLING_REGISTRY_ADDRESS
process.env.FUNCTIONS_ORACLE_ADDRESS = ETHEREUM_CONTRACTS[networkKey].FUNCTIONS_ORACLE_ADDRESS
}

const compilerSettings = {
viaIR: true,
optimizer: {
Expand Down
6 changes: 3 additions & 3 deletions contracts/ethereum/helpers/upkeep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ export async function runUpkeep({
upkeep: CasimirUpkeep,
}) {
let ranUpkeep = false
const checkData = ethers.utils.toUtf8Bytes('')
const checkData = ethers.utils.toUtf8Bytes('0x')
const { ...check } = await upkeep.connect(donTransmitter).checkUpkeep(checkData)
const { upkeepNeeded } = check
if (upkeepNeeded) {
const performData = ethers.utils.toUtf8Bytes('')
const performData = ethers.utils.toUtf8Bytes('0x')
const performUpkeep = await upkeep.connect(donTransmitter).performUpkeep(performData)
await performUpkeep.wait()
ranUpkeep = true
Expand Down Expand Up @@ -43,7 +43,7 @@ export async function fulfillReport({
}) {
const { beaconBalance, sweptBalance, activatedDeposits, forcedExits, completedExits, compoundablePoolIds } = values

const requestIds = (await upkeep.queryFilter(upkeep.filters.RequestSent())).slice(-2).map((event) => event.args.id)
const requestIds = (await upkeep.queryFilter(upkeep.filters.ReportRequestSent(), -2)).map((event) => event.args.requestId)

const balancesRequestId = requestIds[0]

Expand Down
3 changes: 1 addition & 2 deletions contracts/ethereum/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"node": "npx hardhat node",
"report": "npx hardhat run scripts/report.ts",
"size": "npx hardhat size-contracts",
"test": "npx hardhat test",
"test:debug": "npx hardhat test test/debug.ts",
"test": "npx esno -r dotenv/config -r scripts/test.ts",
"upgrade:all": "npx hardhat run scripts/upgrade-all.ts",
"upgrade:proxies": "npx hardhat run scripts/upgrade-proxies.ts",
"verify": "npx hardhat verify"
Expand Down
16 changes: 8 additions & 8 deletions contracts/ethereum/scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void async function () {
await factory.deployed()
console.log(`CasimirFactory contract deployed at ${factory.address}`)

const baseStrategy = {
const simpleStrategy = {
minCollateral: ethers.utils.parseEther('1.0'),
lockPeriod: 0,
userFee: 5,
Expand All @@ -146,18 +146,18 @@ void async function () {
privateOperators: false,
verifiedOperators: false
}
const deployBaseManager = await factory.deployManager(
const deploySimpleManager = await factory.deployManager(
daoOracle.address,
functionsOracle.address,
baseStrategy
simpleStrategy
)
await deployBaseManager.wait()
await deploySimpleManager.wait()
const [managerId] = await factory.getManagerIds()
const managerConfig = await factory.getManagerConfig(managerId)
console.log(`Base CasimirManager contract deployed to ${managerConfig.managerAddress}`)
console.log(`Base CasimirRegistry contract deployed to ${managerConfig.registryAddress}`)
console.log(`Base CasimirUpkeep contract deployed to ${managerConfig.upkeepAddress}`)
console.log(`Base CasimirViews contract deployed to ${managerConfig.viewsAddress}`)
console.log(`Simple CasimirManager contract deployed to ${managerConfig.managerAddress}`)
console.log(`Simple CasimirRegistry contract deployed to ${managerConfig.registryAddress}`)
console.log(`Simple CasimirUpkeep contract deployed to ${managerConfig.upkeepAddress}`)
console.log(`Simple CasimirViews contract deployed to ${managerConfig.viewsAddress}`)
const upkeep = await ethers.getContractAt('CasimirUpkeep', managerConfig.upkeepAddress) as CasimirUpkeep

requestConfig.args[1] = managerConfig.viewsAddress
Expand Down
Loading

0 comments on commit ae04716

Please sign in to comment.