Skip to content

Commit

Permalink
Merge pull request #482 from consensusnetworks/bug/functions
Browse files Browse the repository at this point in the history
Fix functions bug
  • Loading branch information
shanejearley authored Dec 6, 2023
2 parents 35d8f6e + 5bddb9b commit 7b82ca0
Show file tree
Hide file tree
Showing 8 changed files with 298 additions and 287 deletions.
31 changes: 2 additions & 29 deletions contracts/ethereum/scripts/report.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,18 @@
import { ethers } from "hardhat"
import { CasimirFactory, CasimirManager, CasimirPool, CasimirRegistry, CasimirUpkeep, CasimirViews } from "../build/@types"
import { CasimirFactory, CasimirUpkeep } from "../build/@types"
import { waitForNetwork } from "../helpers/network"
import { runUpkeep } from "../helpers/upkeep"
import e from "cors"

void async function() {
if (!process.env.FACTORY_ADDRESS) throw new Error("No factory address provided")

await waitForNetwork(ethers.provider)

const [owner, , donTransmitter] = await ethers.getSigners()
const [owner] = await ethers.getSigners()
const factory = await ethers.getContractAt("CasimirFactory", process.env.FACTORY_ADDRESS) as CasimirFactory
const [managerId] = await factory.getManagerIds()
const managerConfig = await factory.getManagerConfig(managerId)
const manager = await ethers.getContractAt("CasimirManager", managerConfig.managerAddress) as CasimirManager
const registry = await ethers.getContractAt("CasimirRegistry", managerConfig.registryAddress) as CasimirRegistry
const upkeep = await ethers.getContractAt("CasimirUpkeep", managerConfig.upkeepAddress) as CasimirUpkeep
const views = await ethers.getContractAt("CasimirViews", managerConfig.viewsAddress) as CasimirViews

// const pause = await manager.connect(owner).setPaused(false)
// await pause.wait()
const requestReport = await upkeep.connect(owner).requestReport()
await requestReport.wait()

if (process.env.SIMULATE_UPKEEP === "true") {
await runUpkeep({ donTransmitter, upkeep })
let finalizedReport = false
while (!finalizedReport) {
finalizedReport = await runUpkeep({ donTransmitter, upkeep })
await new Promise(resolve => setTimeout(resolve, 2500))
}
const poolIds = await manager.getStakedPoolIds()
const sweptBalance = await views.getSweptBalance(0, poolIds.length)
console.log("Swept balance", ethers.utils.formatEther(sweptBalance))
let totalBalance = ethers.BigNumber.from(0)
for (const poolId of poolIds) {
const poolAddress = await manager.getPoolAddress(poolId)
const poolBalance = await ethers.provider.getBalance(poolAddress)
totalBalance = totalBalance.add(poolBalance)
console.log("Pool", poolId, ethers.utils.formatEther(poolBalance))
}
console.log("Total balance", ethers.utils.formatEther(totalBalance))
}
}()
11 changes: 4 additions & 7 deletions scripts/ethereum/report.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { loadCredentials, getSecret } from "@casimir/aws"
import { ETHEREUM_CONTRACTS, ETHEREUM_NETWORK_NAME } from "@casimir/env"
import { ETHEREUM_NETWORK_NAME } from "@casimir/env"
import { run } from "@casimir/shell"

/**
* Run an ethereum development environment
* Request a new report on testnet
*/
void async function () {
if (process.env.USE_SECRETS !== "false") {
Expand All @@ -13,10 +13,7 @@ void async function () {
process.env.BIP39_SEED = process.env.BIP39_SEED || "inflict ball claim confirm cereal cost note dad mix donate traffic patient"
}
console.log(`Your mnemonic seed is ${process.env.BIP39_SEED}`)
const networkName = process.env.NETWORK?.toUpperCase() || "TESTNET"

process.env.SSV_NETWORK_ADDRESS = ETHEREUM_CONTRACTS["TESTNET"].SSV_NETWORK_ADDRESS
process.env.SSV_VIEWS_ADDRESS = ETHEREUM_CONTRACTS["TESTNET"].SSV_VIEWS_ADDRESS
process.env.SWAP_FACTORY_ADDRESS = ETHEREUM_CONTRACTS["TESTNET"].SWAP_FACTORY_ADDRESS

run(`npm run report --workspace @casimir/ethereum -- --network ${ETHEREUM_NETWORK_NAME["TESTNET"]}`)
run(`npm run report --workspace @casimir/ethereum -- --network ${ETHEREUM_NETWORK_NAME[networkName]}`)
}()
5 changes: 5 additions & 0 deletions services/functions/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"ignorePatterns": [
"Functions-request-config.js"
]
}
Loading

0 comments on commit 7b82ca0

Please sign in to comment.