From 999ce3848d2c38edf9b6604dd7bdd486d80335c9 Mon Sep 17 00:00:00 2001 From: Shane Earley Date: Wed, 6 Dec 2023 12:23:01 -0500 Subject: [PATCH 1/9] Add functions dry run and refactor report reset script --- contracts/ethereum/package.json | 2 + contracts/ethereum/scripts/report.ts | 52 +++++++++----------- package-lock.json | 31 ++++++++++++ scripts/ethereum/report.ts | 2 +- services/functions/src/index.ts | 2 +- services/functions/src/providers/config.ts | 3 ++ services/functions/src/providers/handlers.ts | 2 +- 7 files changed, 63 insertions(+), 31 deletions(-) diff --git a/contracts/ethereum/package.json b/contracts/ethereum/package.json index 08e63cbae..50994ce81 100644 --- a/contracts/ethereum/package.json +++ b/contracts/ethereum/package.json @@ -30,11 +30,13 @@ "@typechain/ethers-v5": "^10.1.0", "@typechain/hardhat": "^6.1.2", "@types/chai": "^4.3.1", + "@types/ethereum-block-by-date": "^1.4.1", "@types/localtunnel": "^2.0.1", "@types/mocha": "^9.1.1", "@types/node": "^17.0.45", "chai": "^4.3.6", "esno": "^0.17.0", + "ethereum-block-by-date": "^1.4.9", "hardhat": "^2.12.3", "hardhat-abi-exporter": "^2.10.1", "hardhat-contract-sizer": "^2.10.0", diff --git a/contracts/ethereum/scripts/report.ts b/contracts/ethereum/scripts/report.ts index 1106c0c74..f3f9c2bfd 100644 --- a/contracts/ethereum/scripts/report.ts +++ b/contracts/ethereum/scripts/report.ts @@ -1,45 +1,41 @@ import { ethers } from "hardhat" -import { CasimirFactory, CasimirManager, CasimirPool, CasimirRegistry, CasimirUpkeep, CasimirViews } from "../build/@types" +import { CasimirFactory, CasimirManager, CasimirUpkeep } from "../build/@types" import { waitForNetwork } from "../helpers/network" -import { runUpkeep } from "../helpers/upkeep" -import e from "cors" +import EthDater from "ethereum-block-by-date" 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 ethDater = new EthDater(ethers.provider) + 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 resetReportPeriod = await manager.reportPeriod() - 1 + const resetReportRequestSent = (await upkeep.queryFilter(upkeep.filters.ReportRequestSent())).slice(-4, -3)[0] + const resetReportRequestArgs = resetReportRequestSent?.args?.requestArgs as string[] + + const resetPreviousReportTimestamp = parseInt(resetReportRequestArgs[7]) + const resetPreviousReportBlock = await ethDater.getDate(resetPreviousReportTimestamp * 1000) + const resetPreviousReportBlockNumber = resetPreviousReportBlock.block + const resetReportTimestamp = parseInt(resetReportRequestArgs[8]) + const resetReportBlock = await ethDater.getDate(resetReportTimestamp * 1000) + const resetReportBlockNumber = resetReportBlock.block + + const resetReport = await upkeep.connect(owner).resetReport( + resetReportPeriod, + resetReportBlockNumber, + resetReportTimestamp, + resetPreviousReportBlockNumber, + resetPreviousReportTimestamp + ) + await resetReport.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)) - } }() \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 838a057be..a32f81276 100644 --- a/package-lock.json +++ b/package-lock.json @@ -292,11 +292,13 @@ "@typechain/ethers-v5": "^10.1.0", "@typechain/hardhat": "^6.1.2", "@types/chai": "^4.3.1", + "@types/ethereum-block-by-date": "^1.4.1", "@types/localtunnel": "^2.0.1", "@types/mocha": "^9.1.1", "@types/node": "^17.0.45", "chai": "^4.3.6", "esno": "^0.17.0", + "ethereum-block-by-date": "^1.4.9", "hardhat": "^2.12.3", "hardhat-abi-exporter": "^2.10.1", "hardhat-contract-sizer": "^2.10.0", @@ -6722,6 +6724,17 @@ "integrity": "sha512-2JwWnHK9H+wUZNorf2Zr6ves96WHoWDJIftkcxPKsS7Djta6Zu519LarhRNljPXkpsZR2ZMwNCPeW7omW07BJw==", "dev": true }, + "node_modules/@types/ethereum-block-by-date": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/@types/ethereum-block-by-date/-/ethereum-block-by-date-1.4.1.tgz", + "integrity": "sha512-TNOlViB9QbX24aJCYgJmVjIPvKqtYWUrv6nuAOA7WMFMpwXOEfZ9y5bnCNw+yvlggByFAaS5A/URIkX75TxWgg==", + "dev": true, + "dependencies": { + "ethers": "^5.4.5", + "moment": "^2.29.1", + "web3": "^1.5.2" + } + }, "node_modules/@types/express": { "version": "4.17.20", "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.20.tgz", @@ -13862,6 +13875,15 @@ "ultron": "~1.1.0" } }, + "node_modules/ethereum-block-by-date": { + "version": "1.4.9", + "resolved": "https://registry.npmjs.org/ethereum-block-by-date/-/ethereum-block-by-date-1.4.9.tgz", + "integrity": "sha512-BsU2uwrfEpBZ+99j2Bk7OjoLi4BhTQ2IpEw2xaGyzqdfL/ibO8YJj7+oLBsdjJL11V7uhSxF+miAE7voI9dUOA==", + "dev": true, + "dependencies": { + "moment": "^2.29.4" + } + }, "node_modules/ethereum-bloom-filters": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/ethereum-bloom-filters/-/ethereum-bloom-filters-1.0.10.tgz", @@ -19755,6 +19777,15 @@ "node": ">=10" } }, + "node_modules/moment": { + "version": "2.29.4", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz", + "integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==", + "dev": true, + "engines": { + "node": "*" + } + }, "node_modules/motion": { "version": "10.16.2", "resolved": "https://registry.npmjs.org/motion/-/motion-10.16.2.tgz", diff --git a/scripts/ethereum/report.ts b/scripts/ethereum/report.ts index 33d21a376..44b630497 100644 --- a/scripts/ethereum/report.ts +++ b/scripts/ethereum/report.ts @@ -3,7 +3,7 @@ import { ETHEREUM_CONTRACTS, ETHEREUM_NETWORK_NAME } from "@casimir/env" import { run } from "@casimir/shell" /** - * Run an ethereum development environment + * Run a report on testnet */ void async function () { if (process.env.USE_SECRETS !== "false") { diff --git a/services/functions/src/index.ts b/services/functions/src/index.ts index eae0f964c..277db8a30 100644 --- a/services/functions/src/index.ts +++ b/services/functions/src/index.ts @@ -51,7 +51,7 @@ async function run() { const handler = handlers[event.event as string] if (!handler) throw new Error(`No handler found for event ${event.event}`) await handler({ args }) - if (process.env.USE_LOGS === "true") { + if (process.env.USE_LOGS === "true" && !config.dryRun) { // Todo check if this possibly misses events updateStartBlock("block.log", event.blockNumber + 1) } diff --git a/services/functions/src/providers/config.ts b/services/functions/src/providers/config.ts index 5a32ef8cd..09e96b9c4 100644 --- a/services/functions/src/providers/config.ts +++ b/services/functions/src/providers/config.ts @@ -1,6 +1,8 @@ import { ethers } from "ethers" export function getConfig() { + const dryRun = process.env.DRY_RUN === "true" + const ethereumUrl = process.env.ETHEREUM_RPC_URL if (!ethereumUrl) throw new Error("No ethereum rpc url provided") @@ -16,6 +18,7 @@ export function getConfig() { if (!functionsOracleAddress) throw new Error("No functions oracle address provided") return { + dryRun, ethereumUrl, functionsBillingRegistryAddress, functionsOracleAddress, diff --git a/services/functions/src/providers/handlers.ts b/services/functions/src/providers/handlers.ts index 6a81e497b..2e6640b8c 100644 --- a/services/functions/src/providers/handlers.ts +++ b/services/functions/src/providers/handlers.ts @@ -27,7 +27,7 @@ export async function fulfillRequestHandler(input: HandlerInput): Promise } const { result, resultLog, success } = await simulateRequest(currentRequestConfig) - if (success) { + if (success && !config.dryRun) { const signer = config.wallet.connect(provider) const dummySigners = Array(31).fill(signer.address) const fulfillAndBill = await functionsBillingRegistry.connect(signer).fulfillAndBill( From cec0619106e5abd1b90228b9f7c20159bc27a96e Mon Sep 17 00:00:00 2001 From: Shane Earley Date: Wed, 6 Dec 2023 12:52:26 -0500 Subject: [PATCH 2/9] Pause contract --- contracts/ethereum/package.json | 2 - contracts/ethereum/scripts/report.ts | 25 +- package-lock.json | 31 -- services/functions/API-request-source.js | 426 +++++++++++------------ 4 files changed, 203 insertions(+), 281 deletions(-) diff --git a/contracts/ethereum/package.json b/contracts/ethereum/package.json index 50994ce81..08e63cbae 100644 --- a/contracts/ethereum/package.json +++ b/contracts/ethereum/package.json @@ -30,13 +30,11 @@ "@typechain/ethers-v5": "^10.1.0", "@typechain/hardhat": "^6.1.2", "@types/chai": "^4.3.1", - "@types/ethereum-block-by-date": "^1.4.1", "@types/localtunnel": "^2.0.1", "@types/mocha": "^9.1.1", "@types/node": "^17.0.45", "chai": "^4.3.6", "esno": "^0.17.0", - "ethereum-block-by-date": "^1.4.9", "hardhat": "^2.12.3", "hardhat-abi-exporter": "^2.10.1", "hardhat-contract-sizer": "^2.10.0", diff --git a/contracts/ethereum/scripts/report.ts b/contracts/ethereum/scripts/report.ts index f3f9c2bfd..ba6be3e84 100644 --- a/contracts/ethereum/scripts/report.ts +++ b/contracts/ethereum/scripts/report.ts @@ -1,14 +1,12 @@ import { ethers } from "hardhat" import { CasimirFactory, CasimirManager, CasimirUpkeep } from "../build/@types" import { waitForNetwork } from "../helpers/network" -import EthDater from "ethereum-block-by-date" void async function() { if (!process.env.FACTORY_ADDRESS) throw new Error("No factory address provided") await waitForNetwork(ethers.provider) - const ethDater = new EthDater(ethers.provider) const [owner] = await ethers.getSigners() const factory = await ethers.getContractAt("CasimirFactory", process.env.FACTORY_ADDRESS) as CasimirFactory const [managerId] = await factory.getManagerIds() @@ -16,26 +14,9 @@ void async function() { const manager = await ethers.getContractAt("CasimirManager", managerConfig.managerAddress) as CasimirManager const upkeep = await ethers.getContractAt("CasimirUpkeep", managerConfig.upkeepAddress) as CasimirUpkeep - const resetReportPeriod = await manager.reportPeriod() - 1 - const resetReportRequestSent = (await upkeep.queryFilter(upkeep.filters.ReportRequestSent())).slice(-4, -3)[0] - const resetReportRequestArgs = resetReportRequestSent?.args?.requestArgs as string[] - - const resetPreviousReportTimestamp = parseInt(resetReportRequestArgs[7]) - const resetPreviousReportBlock = await ethDater.getDate(resetPreviousReportTimestamp * 1000) - const resetPreviousReportBlockNumber = resetPreviousReportBlock.block - const resetReportTimestamp = parseInt(resetReportRequestArgs[8]) - const resetReportBlock = await ethDater.getDate(resetReportTimestamp * 1000) - const resetReportBlockNumber = resetReportBlock.block - - const resetReport = await upkeep.connect(owner).resetReport( - resetReportPeriod, - resetReportBlockNumber, - resetReportTimestamp, - resetPreviousReportBlockNumber, - resetPreviousReportTimestamp - ) - await resetReport.wait() - const requestReport = await upkeep.connect(owner).requestReport() await requestReport.wait() + + // const unpause = await manager.connect(owner).setPaused(true) + // await unpause.wait() }() \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index a32f81276..838a057be 100644 --- a/package-lock.json +++ b/package-lock.json @@ -292,13 +292,11 @@ "@typechain/ethers-v5": "^10.1.0", "@typechain/hardhat": "^6.1.2", "@types/chai": "^4.3.1", - "@types/ethereum-block-by-date": "^1.4.1", "@types/localtunnel": "^2.0.1", "@types/mocha": "^9.1.1", "@types/node": "^17.0.45", "chai": "^4.3.6", "esno": "^0.17.0", - "ethereum-block-by-date": "^1.4.9", "hardhat": "^2.12.3", "hardhat-abi-exporter": "^2.10.1", "hardhat-contract-sizer": "^2.10.0", @@ -6724,17 +6722,6 @@ "integrity": "sha512-2JwWnHK9H+wUZNorf2Zr6ves96WHoWDJIftkcxPKsS7Djta6Zu519LarhRNljPXkpsZR2ZMwNCPeW7omW07BJw==", "dev": true }, - "node_modules/@types/ethereum-block-by-date": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/@types/ethereum-block-by-date/-/ethereum-block-by-date-1.4.1.tgz", - "integrity": "sha512-TNOlViB9QbX24aJCYgJmVjIPvKqtYWUrv6nuAOA7WMFMpwXOEfZ9y5bnCNw+yvlggByFAaS5A/URIkX75TxWgg==", - "dev": true, - "dependencies": { - "ethers": "^5.4.5", - "moment": "^2.29.1", - "web3": "^1.5.2" - } - }, "node_modules/@types/express": { "version": "4.17.20", "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.20.tgz", @@ -13875,15 +13862,6 @@ "ultron": "~1.1.0" } }, - "node_modules/ethereum-block-by-date": { - "version": "1.4.9", - "resolved": "https://registry.npmjs.org/ethereum-block-by-date/-/ethereum-block-by-date-1.4.9.tgz", - "integrity": "sha512-BsU2uwrfEpBZ+99j2Bk7OjoLi4BhTQ2IpEw2xaGyzqdfL/ibO8YJj7+oLBsdjJL11V7uhSxF+miAE7voI9dUOA==", - "dev": true, - "dependencies": { - "moment": "^2.29.4" - } - }, "node_modules/ethereum-bloom-filters": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/ethereum-bloom-filters/-/ethereum-bloom-filters-1.0.10.tgz", @@ -19777,15 +19755,6 @@ "node": ">=10" } }, - "node_modules/moment": { - "version": "2.29.4", - "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz", - "integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==", - "dev": true, - "engines": { - "node": "*" - } - }, "node_modules/motion": { "version": "10.16.2", "resolved": "https://registry.npmjs.org/motion/-/motion-10.16.2.tgz", diff --git a/services/functions/API-request-source.js b/services/functions/API-request-source.js index 848c6fb8b..84fadab87 100644 --- a/services/functions/API-request-source.js +++ b/services/functions/API-request-source.js @@ -1,273 +1,247 @@ const [ - genesisTimestamp, - viewsAddress, - getCompoundablePoolIdsSignature, - getDepositedPoolCountSignature, - getDepositedPoolPublicKeysSignature, - getDepositedPoolStatusesSignature, - getSweptBalanceSignature, - previousReportTimestamp, - reportTimestamp, - reportBlockNumber, - requestType + , + viewsAddress, + getCompoundablePoolIdsSignature, + getDepositedPoolCountSignature, + getDepositedPoolPublicKeysSignature, + getDepositedPoolStatusesSignature, + getSweptBalanceSignature, + , + , + , + requestType ] = args -const ethereumUrl = secrets.ethereumRpcUrl ?? 'http://127.0.0.1:8545' -const ethereumBeaconUrl = secrets.ethereumBeaconRpcUrl ?? 'http://127.0.0.1:5052' -const previousReportSlot = Math.floor((previousReportTimestamp - genesisTimestamp) / 12) -const previousReportEpoch = Math.floor(previousReportSlot / 32) -const reportSlot = Math.floor((reportTimestamp - genesisTimestamp) / 12) -const reportEpoch = Math.floor(reportSlot / 32) +const ethereumUrl = secrets.ethereumRpcUrl ?? "http://127.0.0.1:8545" +const ethereumBeaconUrl = secrets.ethereumBeaconRpcUrl ?? "http://127.0.0.1:5052" switch (requestType) { - case '1': - return await balancesHandler() - case '2': - return await detailsHandler() - default: - throw new Error('Invalid request type') +case "1": + return await balancesHandler() +case "2": + return await detailsHandler() +default: + throw new Error("Invalid request type") } async function balancesHandler() { - const depositedPoolCount = await getDepositedPoolCount() - const startIndex = BigInt(0).toString(16).padStart(64, '0') - const endIndex = BigInt(depositedPoolCount).toString(16).padStart(64, '0') + const depositedPoolCount = await getDepositedPoolCount() + const startIndex = BigInt(0).toString(16).padStart(64, "0") + const endIndex = BigInt(depositedPoolCount).toString(16).padStart(64, "0") - const depositedPoolPublicKeys = await getDepositedPoolPublicKeys(startIndex, endIndex) - const validators = await getValidators(depositedPoolPublicKeys) + const depositedPoolPublicKeys = await getDepositedPoolPublicKeys(startIndex, endIndex) + const validators = await getValidators(depositedPoolPublicKeys) - const beaconBalance = Functions.gweiToWei(validators.reduce((accumulator, { balance }) => { - accumulator += parseFloat(balance) - return accumulator - }, 0)) + const beaconBalance = Functions.gweiToWei(validators.reduce((accumulator, { balance }) => { + accumulator += parseFloat(balance) + return accumulator + }, 0)) - const sweptBalance = Functions.gweiToWei(await getSweptBalance(startIndex, endIndex)) + const sweptBalance = Functions.gweiToWei(await getSweptBalance(startIndex, endIndex)) - console.log("Results", { - beaconBalance, - sweptBalance - }) + console.log("Results", { + beaconBalance, + sweptBalance + }) - return Buffer.concat([ - Functions.encodeUint128(beaconBalance), - Functions.encodeUint128(sweptBalance) - ]) + return Buffer.concat([ + Functions.encodeUint128(beaconBalance), + Functions.encodeUint128(sweptBalance) + ]) } async function detailsHandler() { - const depositedPoolCount = await getDepositedPoolCount() - const startIndex = BigInt(0).toString(16).padStart(64, '0') - const endIndex = BigInt(depositedPoolCount).toString(16).padStart(64, '0') + const depositedPoolCount = await getDepositedPoolCount() + const startIndex = BigInt(0).toString(16).padStart(64, "0") + const endIndex = BigInt(depositedPoolCount).toString(16).padStart(64, "0") - const depositedPoolPublicKeys = await getDepositedPoolPublicKeys(startIndex, endIndex) - // const depositedPoolStatuses = await getDepositedPoolStatuses(startIndex, endIndex) // Not used yet - const validators = await getValidators(depositedPoolPublicKeys) + // const depositedPoolPublicKeys = await getDepositedPoolPublicKeys(startIndex, endIndex) + // const depositedPoolStatuses = await getDepositedPoolStatuses(startIndex, endIndex) // Not used yet + // const validators = await getValidators(depositedPoolPublicKeys) - const activatedDeposits = validators.reduce((accumulator, { validator }) => { - const { activation_epoch } = validator - const activatedDuringReportPeriod = activation_epoch > previousReportEpoch && activation_epoch <= reportEpoch - if (activatedDuringReportPeriod) { - accumulator += 1 - } - return accumulator - }, 0) + const activatedDeposits = 0 // Hardcoded, next update will resolve - const forcedExits = validators.reduce((accumulator, { status, validator }) => { - const { slashed } = validator - const ongoing = status !== 'withdrawal_done' - if (slashed && ongoing) { - accumulator += 1 - } - return accumulator - }, 0) + const forcedExits = 0 // Hardcoded, next update will resolve - const completedExits = validators.reduce((accumulator, { status, validator }) => { - const { withdrawable_epoch } = validator - const completedDuringReportPeriod = withdrawable_epoch >= previousReportEpoch && withdrawable_epoch < reportEpoch - const completed = status === 'withdrawal_done' - if (completedDuringReportPeriod && completed) { - accumulator += 1 - } - return accumulator - }, 0) + const completedExits = 0 // Hardcoded, next update will resolve - const compoundablePoolIds = await getCompoundablePoolIds(startIndex, endIndex) + const compoundablePoolIds = await getCompoundablePoolIds(startIndex, endIndex) - console.log("Results", { - activatedDeposits, - forcedExits, - completedExits, - compoundablePoolIds - }) + console.log("Results", { + activatedDeposits, + forcedExits, + completedExits, + compoundablePoolIds + }) - return Buffer.concat([ - encodeUint32(activatedDeposits), - encodeUint32(forcedExits), - encodeUint32(completedExits), - encodeUint32Array(compoundablePoolIds) - ]) + return Buffer.concat([ + encodeUint32(activatedDeposits), + encodeUint32(forcedExits), + encodeUint32(completedExits), + encodeUint32Array(compoundablePoolIds) + ]) } async function getCompoundablePoolIds(startIndex, endIndex) { - const request = await Functions.makeHttpRequest({ - url: ethereumUrl, - method: 'POST', - data: { - id: 1, - jsonrpc: '2.0', - method: 'eth_call', - params: [ - { - to: viewsAddress, - data: getCompoundablePoolIdsSignature + startIndex + endIndex - }, - { blockNumber: '0x' + parseInt(reportBlockNumber).toString(16) } - ] - } - }) - if (request.error) throw new Error('Failed to get compoundable pool IDs') - const data = request.data.result.slice(2).match(/.{1,64}/g) - let poolIds = [] - for (const item of data) { - let poolId = parseInt(item, 16) - poolIds.push(poolId) - } - return poolIds + const request = await Functions.makeHttpRequest({ + url: ethereumUrl, + method: "POST", + data: { + id: 1, + jsonrpc: "2.0", + method: "eth_call", + params: [ + { + to: viewsAddress, + data: getCompoundablePoolIdsSignature + startIndex + endIndex + }, + "latest" + ] + } + }) + if (request.error) throw new Error("Failed to get compoundable pool IDs") + const data = request.data.result.slice(2).match(/.{1,64}/g) + let poolIds = [] + for (const item of data) { + let poolId = parseInt(item, 16) + poolIds.push(poolId) + } + return poolIds } async function getDepositedPoolCount() { - const request = await Functions.makeHttpRequest({ - url: ethereumUrl, - method: 'POST', - data: { - id: 1, - jsonrpc: '2.0', - method: 'eth_call', - params: [ - { - to: viewsAddress, - data: getDepositedPoolCountSignature - }, - { blockNumber: '0x' + parseInt(reportBlockNumber).toString(16) } - ] - } - }) - if (request.error) throw new Error('Failed to get deposited pool count') - return Number(request.data.result) + const request = await Functions.makeHttpRequest({ + url: ethereumUrl, + method: "POST", + data: { + id: 1, + jsonrpc: "2.0", + method: "eth_call", + params: [ + { + to: viewsAddress, + data: getDepositedPoolCountSignature + }, + "latest" + ] + } + }) + if (request.error) throw new Error("Failed to get deposited pool count") + return Number(request.data.result) } async function getDepositedPoolPublicKeys(startIndex, endIndex) { - const request = await Functions.makeHttpRequest({ - url: ethereumUrl, - method: 'POST', - data: { - id: 1, - jsonrpc: '2.0', - method: 'eth_call', - params: [ - { - to: viewsAddress, - data: getDepositedPoolPublicKeysSignature + startIndex + endIndex - }, - { blockNumber: '0x' + parseInt(reportBlockNumber).toString(16) } - ] - } - }) - if (request.error) throw new Error('Failed to get validator public keys') - const data = request.data.result.slice(2).match(/.{1,64}/g) - // '0000000000000000000000000000000000000000000000000000000000000020', // Chunk size? - // '0000000000000000000000000000000000000000000000000000000000000002', // Array size - // '0000000000000000000000000000000000000000000000000000000000000040', // Item size - // '00000000000000000000000000000000000000000000000000000000000000a0', // Array start - // '0000000000000000000000000000000000000000000000000000000000000030', // Item 1 data size - // '8889a628f263c414e256a1295c3f49ac1780e0b9cac8493dd1bd2f17b3b25766', // Item 1 data - // '0a12fb88f65333fa00c9a735c0f8d0e800000000000000000000000000000000', // Item 1 data - // '0000000000000000000000000000000000000000000000000000000000000030', // Item 2 data size - // '853b4caf348bccddbf7e1c25e68676c3b3f857958c93b290a2bf84974ea33c4f', // Item 2 data - // '793f1bbf7e9e9923f16e2237038e7b6900000000000000000000000000000000' // Item 2 data - const itemCount = parseInt(data[1], 16) - const publicKeys = [] - let itemIndex = 4 - for (let i = 0; i < itemCount; i++) { - const publicKey = '0x'.concat( - data[itemIndex + 1], - data[itemIndex + 2].slice(0, 32) - ) - publicKeys.push(publicKey) - itemIndex += 3 - } - return publicKeys + const request = await Functions.makeHttpRequest({ + url: ethereumUrl, + method: "POST", + data: { + id: 1, + jsonrpc: "2.0", + method: "eth_call", + params: [ + { + to: viewsAddress, + data: getDepositedPoolPublicKeysSignature + startIndex + endIndex + }, + "latest" + ] + } + }) + if (request.error) throw new Error("Failed to get validator public keys") + const data = request.data.result.slice(2).match(/.{1,64}/g) + // '0000000000000000000000000000000000000000000000000000000000000020', // Chunk size? + // '0000000000000000000000000000000000000000000000000000000000000002', // Array size + // '0000000000000000000000000000000000000000000000000000000000000040', // Item size + // '00000000000000000000000000000000000000000000000000000000000000a0', // Array start + // '0000000000000000000000000000000000000000000000000000000000000030', // Item 1 data size + // '8889a628f263c414e256a1295c3f49ac1780e0b9cac8493dd1bd2f17b3b25766', // Item 1 data + // '0a12fb88f65333fa00c9a735c0f8d0e800000000000000000000000000000000', // Item 1 data + // '0000000000000000000000000000000000000000000000000000000000000030', // Item 2 data size + // '853b4caf348bccddbf7e1c25e68676c3b3f857958c93b290a2bf84974ea33c4f', // Item 2 data + // '793f1bbf7e9e9923f16e2237038e7b6900000000000000000000000000000000' // Item 2 data + const itemCount = parseInt(data[1], 16) + const publicKeys = [] + let itemIndex = 4 + for (let i = 0; i < itemCount; i++) { + const publicKey = "0x".concat( + data[itemIndex + 1], + data[itemIndex + 2].slice(0, 32) + ) + publicKeys.push(publicKey) + itemIndex += 3 + } + return publicKeys } async function getDepositedPoolStatuses(startIndex, endIndex) { - const request = await Functions.makeHttpRequest({ - url: ethereumUrl, - method: 'POST', - data: { - id: 1, - jsonrpc: '2.0', - method: 'eth_call', - params: [ - { - to: viewsAddress, - data: getDepositedPoolStatusesSignature + startIndex + endIndex - }, - { blockNumber: '0x' + parseInt(reportBlockNumber).toString(16) } - ] - } - }) - if (request.error) throw new Error('Failed to get validator statuses') - const data = request.data.result.slice(2).match(/.{1,64}/g) - const itemCount = parseInt(data[1], 16) - const statuses = [] - let itemIndex = 2 - for (let i = 0; i < itemCount; i++) { - let status = parseInt(data[itemIndex], 16) - statuses.push(status) - itemIndex += 1 - } - return statuses + const request = await Functions.makeHttpRequest({ + url: ethereumUrl, + method: "POST", + data: { + id: 1, + jsonrpc: "2.0", + method: "eth_call", + params: [ + { + to: viewsAddress, + data: getDepositedPoolStatusesSignature + startIndex + endIndex + }, + "latest" + ] + } + }) + if (request.error) throw new Error("Failed to get validator statuses") + const data = request.data.result.slice(2).match(/.{1,64}/g) + const itemCount = parseInt(data[1], 16) + const statuses = [] + let itemIndex = 2 + for (let i = 0; i < itemCount; i++) { + let status = parseInt(data[itemIndex], 16) + statuses.push(status) + itemIndex += 1 + } + return statuses } async function getSweptBalance(startIndex, endIndex) { - const request = await Functions.makeHttpRequest({ - url: ethereumUrl, - method: 'POST', - data: { - id: 1, - jsonrpc: '2.0', - method: 'eth_call', - params: [ - { - to: viewsAddress, - data: getSweptBalanceSignature + startIndex + endIndex - }, - { blockNumber: '0x' + parseInt(reportBlockNumber).toString(16) } - ] - } - }) - if (request.error) throw new Error('Failed to get swept balance') - const data = request.data.result.slice(2) - return parseInt(data, 16) + const request = await Functions.makeHttpRequest({ + url: ethereumUrl, + method: "POST", + data: { + id: 1, + jsonrpc: "2.0", + method: "eth_call", + params: [ + { + to: viewsAddress, + data: getSweptBalanceSignature + startIndex + endIndex + }, + "latest" + ] + } + }) + if (request.error) throw new Error("Failed to get swept balance") + const data = request.data.result.slice(2) + return parseInt(data, 16) } async function getValidators(validatorPublicKeys) { - const request = await Functions.makeHttpRequest({ - url: `${ethereumBeaconUrl}/eth/v1/beacon/states/finalized/validators?id=${validatorPublicKeys.join(',')}` - }) - if (request.error) throw new Error('Failed to get validators') - return request.data.data + const request = await Functions.makeHttpRequest({ + url: `${ethereumBeaconUrl}/eth/v1/beacon/states/finalized/validators?id=${validatorPublicKeys.join(",")}` + }) + if (request.error) throw new Error("Failed to get validators") + return request.data.data } function encodeUint32(value) { - const buffer = Buffer.alloc(32) - buffer.writeUInt32BE(value, 28) - return buffer + const buffer = Buffer.alloc(32) + buffer.writeUInt32BE(value, 28) + return buffer } function encodeUint32Array(values) { - const buffer = Buffer.alloc(32 * values.length) - for (let i = 0; i < values.length; i++) { - buffer.writeUInt32BE(values[i], i * 32 + 28) - } - return buffer + const buffer = Buffer.alloc(32 * values.length) + for (let i = 0; i < values.length; i++) { + buffer.writeUInt32BE(values[i], i * 32 + 28) + } + return buffer } \ No newline at end of file From 38907298de27ad9677b08115d91b492dd4a10a88 Mon Sep 17 00:00:00 2001 From: Shane Earley Date: Wed, 6 Dec 2023 13:20:53 -0500 Subject: [PATCH 3/9] Keep process on during dry run --- services/functions/src/index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/services/functions/src/index.ts b/services/functions/src/index.ts index 277db8a30..03c0a9b37 100644 --- a/services/functions/src/index.ts +++ b/services/functions/src/index.ts @@ -63,6 +63,8 @@ run().catch(error => { updateErrorLog("error.log", (error as Error).message) } else { console.log(error) - } - process.exit(1) + } + if (!config.dryRun) { + process.exit(1) + } }) \ No newline at end of file From 15eb930353e3f9d848a9b262a2ba7370a1e781a9 Mon Sep 17 00:00:00 2001 From: Shane Earley Date: Wed, 6 Dec 2023 13:23:55 -0500 Subject: [PATCH 4/9] Add logs for keys and statuses --- services/functions/API-request-source.js | 3 +++ services/functions/src/index.ts | 4 +--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/services/functions/API-request-source.js b/services/functions/API-request-source.js index 84fadab87..b5aa1716c 100644 --- a/services/functions/API-request-source.js +++ b/services/functions/API-request-source.js @@ -29,6 +29,9 @@ async function balancesHandler() { const endIndex = BigInt(depositedPoolCount).toString(16).padStart(64, "0") const depositedPoolPublicKeys = await getDepositedPoolPublicKeys(startIndex, endIndex) + console.log("depositedPoolPublicKeys", depositedPoolPublicKeys) + const depositedPoolStatuses = await getDepositedPoolStatuses(startIndex, endIndex) + console.log("depositedPoolStatuses", depositedPoolStatuses) const validators = await getValidators(depositedPoolPublicKeys) const beaconBalance = Functions.gweiToWei(validators.reduce((accumulator, { balance }) => { diff --git a/services/functions/src/index.ts b/services/functions/src/index.ts index 03c0a9b37..ca7bf1d54 100644 --- a/services/functions/src/index.ts +++ b/services/functions/src/index.ts @@ -64,7 +64,5 @@ run().catch(error => { } else { console.log(error) } - if (!config.dryRun) { - process.exit(1) - } + process.exit(1) }) \ No newline at end of file From b7532c7c03e5e9ea55eee986e2ffda0e67a6d99b Mon Sep 17 00:00:00 2001 From: Shane Earley Date: Wed, 6 Dec 2023 13:25:42 -0500 Subject: [PATCH 5/9] Add log for public key data --- services/functions/API-request-source.js | 1 + 1 file changed, 1 insertion(+) diff --git a/services/functions/API-request-source.js b/services/functions/API-request-source.js index b5aa1716c..f56313280 100644 --- a/services/functions/API-request-source.js +++ b/services/functions/API-request-source.js @@ -151,6 +151,7 @@ async function getDepositedPoolPublicKeys(startIndex, endIndex) { }) if (request.error) throw new Error("Failed to get validator public keys") const data = request.data.result.slice(2).match(/.{1,64}/g) + console.log("data", data) // '0000000000000000000000000000000000000000000000000000000000000020', // Chunk size? // '0000000000000000000000000000000000000000000000000000000000000002', // Array size // '0000000000000000000000000000000000000000000000000000000000000040', // Item size From ecc425fac0178adf3fb8a2ea0d39c25f930b747e Mon Sep 17 00:00:00 2001 From: Shane Earley Date: Wed, 6 Dec 2023 13:32:06 -0500 Subject: [PATCH 6/9] Fix overriden array decoding --- services/functions/API-request-source.js | 103 +++++++++++++++++------ 1 file changed, 78 insertions(+), 25 deletions(-) diff --git a/services/functions/API-request-source.js b/services/functions/API-request-source.js index f56313280..8dcf8620c 100644 --- a/services/functions/API-request-source.js +++ b/services/functions/API-request-source.js @@ -150,28 +150,65 @@ async function getDepositedPoolPublicKeys(startIndex, endIndex) { } }) if (request.error) throw new Error("Failed to get validator public keys") - const data = request.data.result.slice(2).match(/.{1,64}/g) - console.log("data", data) - // '0000000000000000000000000000000000000000000000000000000000000020', // Chunk size? - // '0000000000000000000000000000000000000000000000000000000000000002', // Array size - // '0000000000000000000000000000000000000000000000000000000000000040', // Item size - // '00000000000000000000000000000000000000000000000000000000000000a0', // Array start - // '0000000000000000000000000000000000000000000000000000000000000030', // Item 1 data size - // '8889a628f263c414e256a1295c3f49ac1780e0b9cac8493dd1bd2f17b3b25766', // Item 1 data - // '0a12fb88f65333fa00c9a735c0f8d0e800000000000000000000000000000000', // Item 1 data - // '0000000000000000000000000000000000000000000000000000000000000030', // Item 2 data size - // '853b4caf348bccddbf7e1c25e68676c3b3f857958c93b290a2bf84974ea33c4f', // Item 2 data - // '793f1bbf7e9e9923f16e2237038e7b6900000000000000000000000000000000' // Item 2 data - const itemCount = parseInt(data[1], 16) + const chunkChars = 64 + const chunks = request.data.result.slice(2).match(new RegExp(`.{1,${chunkChars}}`, "g")) + // Contract response: + // [ + // "0x8889a628f263c414e256a1295c3f49ac1780e0b9cac8493dd1bd2f17b3b257660a12fb88f65333fa00c9a735c0f8d0e8", + // "0x853b4caf348bccddbf7e1c25e68676c3b3f857958c93b290a2bf84974ea33c4f793f1bbf7e9e9923f16e2237038e7b69" + // ] + // Chunks: + // [ + // '0000000000000000000000000000000000000000000000000000000000000020', // Array start at 0x20 (32) + // '0000000000000000000000000000000000000000000000000000000000000002', // Array size is 2 + // '0000000000000000000000000000000000000000000000000000000000000040', + // '00000000000000000000000000000000000000000000000000000000000000a0', + // '0000000000000000000000000000000000000000000000000000000000000030', // Length of bytes is 0x30 (48) + // '8889a628f263c414e256a1295c3f49ac1780e0b9cac8493dd1bd2f17b3b25766', + // '0a12fb88f65333fa00c9a735c0f8d0e800000000000000000000000000000000', + // '0000000000000000000000000000000000000000000000000000000000000030', // Length of bytes is 0x30 (48) + // '853b4caf348bccddbf7e1c25e68676c3b3f857958c93b290a2bf84974ea33c4f', + // '793f1bbf7e9e9923f16e2237038e7b6900000000000000000000000000000000' + // ] + // Contract response: + // [ + // "0xa2a641b314a505a0cc0c75096cae3f2895db4ced87fe96c781677bbea1b9b60348799100965cbda987219ef1477b2152" + // "0x8889a628f263c414e256a1295c3f49ac1780e0b9cac8493dd1bd2f17b3b257660a12fb88f65333fa00c9a735c0f8d0e8", + // "0x853b4caf348bccddbf7e1c25e68676c3b3f857958c93b290a2bf84974ea33c4f793f1bbf7e9e9923f16e2237038e7b69" + // ] + // Chunks: + // [ + // '0000000000000000000000000000000000000000000000000000000000000020', // Array start at 0x20 (32) + // '0000000000000000000000000000000000000000000000000000000000000003', // Array size is 3 + // '0000000000000000000000000000000000000000000000000000000000000060', // First item start at 0x60 (96) + // '00000000000000000000000000000000000000000000000000000000000000c0', // Second item start at 0xc0 (192) + // '0000000000000000000000000000000000000000000000000000000000000120', // Third item start at 0x120 (288) + // '0000000000000000000000000000000000000000000000000000000000000030', // Length of bytes is 0x30 (48) + // 'a2a641b314a505a0cc0c75096cae3f2895db4ced87fe96c781677bbea1b9b603', + // '48799100965cbda987219ef1477b215200000000000000000000000000000000', + // '0000000000000000000000000000000000000000000000000000000000000030', // Length of bytes is 0x30 (48) + // '8889a628f263c414e256a1295c3f49ac1780e0b9cac8493dd1bd2f17b3b25766', + // '0a12fb88f65333fa00c9a735c0f8d0e800000000000000000000000000000000', + // '0000000000000000000000000000000000000000000000000000000000000030', // Length of bytes is 0x30 (48) + // '853b4caf348bccddbf7e1c25e68676c3b3f857958c93b290a2bf84974ea33c4f', + // '793f1bbf7e9e9923f16e2237038e7b6900000000000000000000000000000000' + // ] + const arrayIndex = (parseInt(chunks[0], 16) * 2) / chunkChars + const itemSize = parseInt(chunks[arrayIndex], 16) const publicKeys = [] - let itemIndex = 4 - for (let i = 0; i < itemCount; i++) { - const publicKey = "0x".concat( - data[itemIndex + 1], - data[itemIndex + 2].slice(0, 32) - ) + for (let i = 0; i < itemSize; i++) { + const itemIndex = (parseInt(chunks[arrayIndex + i + 1], 16) * 2) / chunkChars + itemSize - 1 + const itemChars = parseInt(chunks[itemIndex], 16) * 2 + const chunkCount = Math.ceil(itemChars / chunkChars) + let publicKey = "0x" + let remainingItemCharCount = itemChars + for (let j = 0; j < chunkCount; j++) { + const itemChunk = chunks[itemIndex + 1 + j] + const itemChunkCharCount = Math.min(remainingItemCharCount, chunkChars) + publicKey += itemChunk.slice(0, itemChunkCharCount) + remainingItemCharCount -= itemChunkCharCount + } publicKeys.push(publicKey) - itemIndex += 3 } return publicKeys } @@ -194,12 +231,28 @@ async function getDepositedPoolStatuses(startIndex, endIndex) { } }) if (request.error) throw new Error("Failed to get validator statuses") - const data = request.data.result.slice(2).match(/.{1,64}/g) - const itemCount = parseInt(data[1], 16) + const chunkChars = 64 + const chunks = request.data.result.slice(2).match(new RegExp(`.{1,${chunkChars}}`, "g")) + // Contract response: + // [ + // 2, + // 2, + // 2 + // ] + // Chunks: + // [ + // '0000000000000000000000000000000000000000000000000000000000000020', + // '0000000000000000000000000000000000000000000000000000000000000003', + // '0000000000000000000000000000000000000000000000000000000000000002', + // '0000000000000000000000000000000000000000000000000000000000000002', + // '0000000000000000000000000000000000000000000000000000000000000002' + // ] + const arrayIndex = (parseInt(chunks[0], 16) * 2) / chunkChars + const itemSize = parseInt(chunks[arrayIndex], 16) const statuses = [] - let itemIndex = 2 - for (let i = 0; i < itemCount; i++) { - let status = parseInt(data[itemIndex], 16) + let itemIndex = arrayIndex + 1 + for (let i = 0; i < itemSize; i++) { + let status = parseInt(chunks[itemIndex], 16) statuses.push(status) itemIndex += 1 } From 2b14d75f93ae8b19449bd81a78814563f9ab3fdd Mon Sep 17 00:00:00 2001 From: Shane Earley Date: Wed, 6 Dec 2023 13:44:38 -0500 Subject: [PATCH 7/9] Fix dry run handling --- services/functions/.eslintrc | 5 +++ services/functions/API-request-source.js | 1 + .../FunctionsSandboxLibrary/Functions.js | 11 +++--- services/functions/src/index.ts | 2 +- services/functions/src/providers/handlers.ts | 38 ++++++++++--------- 5 files changed, 33 insertions(+), 24 deletions(-) create mode 100644 services/functions/.eslintrc diff --git a/services/functions/.eslintrc b/services/functions/.eslintrc new file mode 100644 index 000000000..8c4521175 --- /dev/null +++ b/services/functions/.eslintrc @@ -0,0 +1,5 @@ +{ + "ignorePatterns": [ + "Functions-request-config.js" + ] +} \ No newline at end of file diff --git a/services/functions/API-request-source.js b/services/functions/API-request-source.js index 8dcf8620c..fc69283f1 100644 --- a/services/functions/API-request-source.js +++ b/services/functions/API-request-source.js @@ -1,3 +1,4 @@ +/* eslint-disable no-undef */ const [ , viewsAddress, diff --git a/services/functions/FunctionsSandboxLibrary/Functions.js b/services/functions/FunctionsSandboxLibrary/Functions.js index a9a3c7131..8f1e4aaa7 100644 --- a/services/functions/FunctionsSandboxLibrary/Functions.js +++ b/services/functions/FunctionsSandboxLibrary/Functions.js @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ "use strict" var __importDefault = (this && this.__importDefault) || @@ -126,14 +127,14 @@ FunctionsModule.encodeInt256 = (result) => { return _a.encodePosSignedInt(result) } FunctionsModule.encodeUint128 = (result) => { - if (typeof result === 'number') { + if (typeof result === "number") { if (!Number.isInteger(result) || result < 0) { - throw Error('encodeUint128 invalid input') + throw Error("encodeUint128 invalid input") } result = BigInt(result) } if (result < 0 || result > FunctionsModule.maxUint128) { - throw Error('encodeUint128 out of range') + throw Error("encodeUint128 out of range") } return FunctionsModule.encodeUint256(result) } @@ -155,13 +156,13 @@ FunctionsModule.encodeNegSignedInt = (int) => { FunctionsModule.gweiToWei = (result) => { if (typeof result === "number") { if (!Number.isInteger(result) || result < 0) { - throw Error('gweiToWei invalid input'); + throw Error("gweiToWei invalid input") } return _a.gweiToWei(BigInt(result)) } return result * BigInt(1000000000) } -FunctionsModule.maxUint128 = BigInt('340282366920938463463374607431768211455'); +FunctionsModule.maxUint128 = BigInt("340282366920938463463374607431768211455") FunctionsModule.maxUint256 = BigInt("115792089237316195423570985008687907853269984665640564039457584007913129639935") FunctionsModule.maxPosInt256 = BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819967") FunctionsModule.maxNegInt256 = BigInt("-57896044618658097711785492504343953926634992332820282019728792003956564819968") diff --git a/services/functions/src/index.ts b/services/functions/src/index.ts index ca7bf1d54..276e8c3e6 100644 --- a/services/functions/src/index.ts +++ b/services/functions/src/index.ts @@ -59,7 +59,7 @@ async function run() { } run().catch(error => { - if (process.env.USE_LOGS === "true") { + if (process.env.USE_LOGS === "true" && !config.dryRun) { updateErrorLog("error.log", (error as Error).message) } else { console.log(error) diff --git a/services/functions/src/providers/handlers.ts b/services/functions/src/providers/handlers.ts index 2e6640b8c..a33bc47cd 100644 --- a/services/functions/src/providers/handlers.ts +++ b/services/functions/src/providers/handlers.ts @@ -27,25 +27,27 @@ export async function fulfillRequestHandler(input: HandlerInput): Promise } const { result, resultLog, success } = await simulateRequest(currentRequestConfig) - if (success && !config.dryRun) { - const signer = config.wallet.connect(provider) - const dummySigners = Array(31).fill(signer.address) - const fulfillAndBill = await functionsBillingRegistry.connect(signer).fulfillAndBill( - requestId, - result, - "0x", - signer.address, - dummySigners, - 4, - 100_000, - 500_000, - { - gasLimit: 500_000, + if (success) { + if (!config.dryRun) { + const signer = config.wallet.connect(provider) + const dummySigners = Array(31).fill(signer.address) + const fulfillAndBill = await functionsBillingRegistry.connect(signer).fulfillAndBill( + requestId, + result, + "0x", + signer.address, + dummySigners, + 4, + 100_000, + 500_000, + { + gasLimit: 500_000, + } + ) + await fulfillAndBill.wait() + if (process.env.USE_LOGS === "true") { + updateExecutionLog("execution.log", resultLog) } - ) - await fulfillAndBill.wait() - if (process.env.USE_LOGS === "true") { - updateExecutionLog("execution.log", resultLog) } } else { throw new Error(resultLog) From c681fd5b251c4ef0c25205f4edca2403b99b7c6a Mon Sep 17 00:00:00 2001 From: Shane Earley Date: Wed, 6 Dec 2023 13:48:16 -0500 Subject: [PATCH 8/9] Remove extra logs --- services/functions/API-request-source.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/services/functions/API-request-source.js b/services/functions/API-request-source.js index fc69283f1..20393aa49 100644 --- a/services/functions/API-request-source.js +++ b/services/functions/API-request-source.js @@ -30,9 +30,6 @@ async function balancesHandler() { const endIndex = BigInt(depositedPoolCount).toString(16).padStart(64, "0") const depositedPoolPublicKeys = await getDepositedPoolPublicKeys(startIndex, endIndex) - console.log("depositedPoolPublicKeys", depositedPoolPublicKeys) - const depositedPoolStatuses = await getDepositedPoolStatuses(startIndex, endIndex) - console.log("depositedPoolStatuses", depositedPoolStatuses) const validators = await getValidators(depositedPoolPublicKeys) const beaconBalance = Functions.gweiToWei(validators.reduce((accumulator, { balance }) => { @@ -59,7 +56,8 @@ async function detailsHandler() { const endIndex = BigInt(depositedPoolCount).toString(16).padStart(64, "0") // const depositedPoolPublicKeys = await getDepositedPoolPublicKeys(startIndex, endIndex) - // const depositedPoolStatuses = await getDepositedPoolStatuses(startIndex, endIndex) // Not used yet + const depositedPoolStatuses = await getDepositedPoolStatuses(startIndex, endIndex) + console.log("Statuses", depositedPoolStatuses) // const validators = await getValidators(depositedPoolPublicKeys) const activatedDeposits = 0 // Hardcoded, next update will resolve From 5bddb9b277ee22d4b30328d9fc5da92cedbb9ceb Mon Sep 17 00:00:00 2001 From: Shane Earley Date: Wed, 6 Dec 2023 13:53:33 -0500 Subject: [PATCH 9/9] Unpause contract --- contracts/ethereum/scripts/report.ts | 6 +----- scripts/ethereum/report.ts | 11 ++++------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/contracts/ethereum/scripts/report.ts b/contracts/ethereum/scripts/report.ts index ba6be3e84..7397f48bd 100644 --- a/contracts/ethereum/scripts/report.ts +++ b/contracts/ethereum/scripts/report.ts @@ -1,5 +1,5 @@ import { ethers } from "hardhat" -import { CasimirFactory, CasimirManager, CasimirUpkeep } from "../build/@types" +import { CasimirFactory, CasimirUpkeep } from "../build/@types" import { waitForNetwork } from "../helpers/network" void async function() { @@ -11,12 +11,8 @@ void async function() { 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 upkeep = await ethers.getContractAt("CasimirUpkeep", managerConfig.upkeepAddress) as CasimirUpkeep const requestReport = await upkeep.connect(owner).requestReport() await requestReport.wait() - - // const unpause = await manager.connect(owner).setPaused(true) - // await unpause.wait() }() \ No newline at end of file diff --git a/scripts/ethereum/report.ts b/scripts/ethereum/report.ts index 44b630497..01912c0ba 100644 --- a/scripts/ethereum/report.ts +++ b/scripts/ethereum/report.ts @@ -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 a report on testnet + * Request a new report on testnet */ void async function () { if (process.env.USE_SECRETS !== "false") { @@ -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]}`) }()