diff --git a/.gitignore b/.gitignore index 360a1e5..fb60ba3 100644 --- a/.gitignore +++ b/.gitignore @@ -54,3 +54,5 @@ artifacts .secret* *.sw* + +balances.csv diff --git a/package.json b/package.json index 00dc5b2..7f63337 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "start": "concurrently \"cd api && npm start\" \"cd app && npm run dev\"", "deploy": "npx hardhat run scripts/deployArchetype.ts --network sepolia", "network": "npx hardhat node", - "verify": "npx hardhat verify 0x17a23A733d7B8206a4F950cFdDbdB56563Ce3b7b --network sepolia" + "verify": "npx hardhat verify 0x17a23A733d7B8206a4F950cFdDbdB56563Ce3b7b --network sepolia", + "withdraw": "npx hardhat run --network mainnet scripts/getWithdrawable.ts" }, "repository": { "type": "git", diff --git a/scripts/getWithdrawable.ts b/scripts/getWithdrawable.ts index fd0b343..3876b1f 100644 --- a/scripts/getWithdrawable.ts +++ b/scripts/getWithdrawable.ts @@ -1,25 +1,38 @@ -import { ethers, run } from "hardhat"; -import fetch from 'node-fetch'; +import { ethers } from "hardhat"; +import fetch from "node-fetch"; +import fs from "fs"; +import path from "path"; + const ZERO = "0x0000000000000000000000000000000000000000"; async function main() { - const contracts = await (await fetch('https://scatter-api.fly.dev/api/contracts')).json() + const contracts = await (await fetch("https://scatter-api.fly.dev/api/contracts")).json(); + + // Prepare to write to a CSV file + const filePath = path.join(__dirname, "balances.csv"); + const header = "Contract Address,Owner Balance,Platform Balance\n"; + fs.writeFileSync(filePath, header, { encoding: "utf8" }); + + let totalPlat = 0; + for (const contract of contracts.body) { + try { + const archetype = await ethers.getContractAt("Archetype", contract); + const balance = await archetype.ownerBalance(); + const ownerBalance = ethers.utils.formatEther(balance.owner); + const platformBalance = ethers.utils.formatEther(balance.platform); + console.log(contract, "platform:", platformBalance, "owner:", ownerBalance); + totalPlat += Number(platformBalance); - let totalPlat = 0 - for(const contract of contracts.body) { - // const archetype = Archetype.attach(contract); - try{ - const archetype = await ethers.getContractAt("Archetype", contract); - const balance = await archetype.ownerBalance(); - console.log(contract, "platform:", ethers.utils.formatEther(balance.platform), "owner:", ethers.utils.formatEther(balance.owner)); - totalPlat += Number(ethers.utils.formatEther(balance.platform)) - } catch(e) { - console.log(contract, "not Archetype"); - continue - } + // Write the contract data to the CSV file + const line = `${contract},${ownerBalance},${platformBalance}\n`; + fs.appendFileSync(filePath, line, { encoding: "utf8" }); + } catch (e) { + console.error(e); + console.log(contract, "not Archetype"); } + } - console.log("total platform:", totalPlat) + console.log("total platform:", totalPlat); } main()