From 65c79481d1bcad2f48eceb93372375302624a9f6 Mon Sep 17 00:00:00 2001 From: Sam McCord Date: Thu, 1 Dec 2022 11:27:26 -0700 Subject: [PATCH] put back address tmpfiles, change addresses path --- .gitignore | 1 - .prettierrc.json | 35 +++++ .prittierrc.json | 35 ----- addresses_master.json => addresses.json | 0 deploy/helpers.ts | 171 ++++++++++++------------ deployments/addresses_last.example.json | 4 + deployments/addresses_last.json | 16 +++ package.json | 4 +- 8 files changed, 144 insertions(+), 122 deletions(-) create mode 100644 .prettierrc.json delete mode 100644 .prittierrc.json rename addresses_master.json => addresses.json (100%) create mode 100644 deployments/addresses_last.example.json create mode 100644 deployments/addresses_last.json diff --git a/.gitignore b/.gitignore index 5af87e1..76806a9 100644 --- a/.gitignore +++ b/.gitignore @@ -13,5 +13,4 @@ broadcast/ # Code Editors .vscode -deployments/**/ diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..16c2227 --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,35 @@ +{ + "printWidth": 100, + "useTabs": false, + "bracketSpacing": true, + "overrides": [ + { + "files": "*.js", + "options": { + "semi": true, + "trailingComma": "all", + "tabWidth": 2, + "singleQuote": false, + "explicitTypes": "always" + } + }, + { + "files": "*.ts", + "options": { + "semi": true, + "trailingComma": "all", + "tabWidth": 2, + "singleQuote": false, + "explicitTypes": "always" + } + }, + { + "files": "*.sol", + "options": { + "tabWidth": 4, + "singleQuote": false, + "explicitTypes": "always" + } + } + ] +} diff --git a/.prittierrc.json b/.prittierrc.json deleted file mode 100644 index b9c63ec..0000000 --- a/.prittierrc.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "printWidth": 100, - "useTabs": false, - "bracketSpacing": true, - "overrides": [ - { - "files": "*.js", - "options": { - "semi": true, - "trailingComma": "all", - "tabWidth": 2, - "singleQuote": false, - "explicitTypes": "always" - } - }, - { - "files": "*.ts", - "options": { - "semi": true, - "trailingComma": "all", - "tabWidth": 2, - "singleQuote": false, - "explicitTypes": "always" - } - }, - { - "files": "*.sol", - "options": { - "tabWidth": 4, - "singleQuote": false, - "explicitTypes": "always" - } - } - ] - } \ No newline at end of file diff --git a/addresses_master.json b/addresses.json similarity index 100% rename from addresses_master.json rename to addresses.json diff --git a/deploy/helpers.ts b/deploy/helpers.ts index 19e40ec..afbd545 100644 --- a/deploy/helpers.ts +++ b/deploy/helpers.ts @@ -1,105 +1,108 @@ -import { SignatureParam, DeployParams, MasterAddresses, Networks, CommandParams, AddressParams } from "./types"; -import {exec} from "child_process"; +import { + SignatureParam, + DeployParams, + MasterAddresses, + Networks, + CommandParams, + AddressParams, +} from "./types"; +import { exec } from "child_process"; import addresses from "../addresses_master.json"; -import { writeFileSync, readdirSync, lstatSync } from "fs"; +import { writeFileSync, readdirSync, lstatSync } from "fs"; import * as networks from "./networks.json"; import { copyFile } from "fs/promises"; import path from "path"; export function getNetworkRPC(network: string): string { - let n: Networks = networks; - return n[network]; + let n: Networks = networks; + return n[network]; } -export async function generateSignature(params: SignatureParam[], ): Promise { - let typeString: string = ""; - let valueString: string = ""; - - if (params.length == 0) { - return "0xc0406226"; - } +export async function generateSignature(params: SignatureParam[]): Promise { + let typeString: string = ""; + let valueString: string = ""; - params.forEach((param: SignatureParam, i: number) => { - let { type, value } = param; - typeString += type; - valueString += type == "string" ? `"${value}"` : value; - if (i+1 != params.length) { - typeString += ","; - valueString += " "; - } - }) + if (params.length == 0) { + return "0xc0406226"; + } - let command: string = `cast calldata "run(${typeString})" ${valueString}`; - return await execute(command); + params.forEach((param: SignatureParam, i: number) => { + let { type, value } = param; + typeString += type; + valueString += type == "string" ? `"${value}"` : value; + if (i + 1 != params.length) { + typeString += ","; + valueString += " "; + } + }); + + let command: string = `cast calldata "run(${typeString})" ${valueString}`; + return await execute(command); } export async function execute(command: string): Promise { - return new Promise((resolve) => { - exec(command, (e, r) => { - if (e) { - console.log(e); - return; - } - let res: string = r.replace(/^\s+|\s+$/g, '') - resolve(res); - }); - }) + return new Promise((resolve) => { + exec(command, (e, r) => { + if (e) { + console.log(e); + return; + } + let res: string = r.replace(/^\s+|\s+$/g, ""); + resolve(res); + }); + }); } export function generateForgeCommand(p: CommandParams): string { - return `forge script scripts/${p.contractName}.s.sol:${p.contractName} --fork-url ${p.forkUrl} --private-key ${p.privateKey} --sig ${p.sig} --broadcast -vvvv`; + return `forge script scripts/${p.contractName}.s.sol:${p.contractName} --fork-url ${p.forkUrl} --private-key ${p.privateKey} --sig ${p.sig} --broadcast -vvvv`; } export async function updateAddresses(p: AddressParams): Promise { - await copyFile( - "deployments/addresses_last.example.json", - "deployments/addresses_last.json", - 0 - ) - let tempAddresses: {[key:string]: string} = require("../../deployments/addresses_last.json"); - let updated: MasterAddresses = addresses; - return new Promise<{ - updated: MasterAddresses, - tempAddresses: {[key:string]: string} - }>(((resolve) => { - let latestLog: string | undefined = getMostRecentFile(`broadcast/${p.contractName}.s.sol/1/`); - if (!latestLog) return; - let json = require(`../../broadcast/${p.contractName}.s.sol/1/${latestLog}`); - json.transactions.forEach((trx: any) => { - if (p.contractName == "DeployCurvePool") { - let { transactionType, address } = trx.additionalContracts[0]; - if (transactionType == "CREATE") { - updated[p.network].core.CurvePool = address; - tempAddresses.CurvePool = address; - } - } else { - if (trx.transactionType == "CREATE") { - let cl = p.contractLabel || trx.contractName; - if (p.isCore) { - updated[p.network].core[cl] = trx.contractAddress; - } else { - updated[p.network].modules[cl] = trx.contractAddress; - } - tempAddresses[cl] = trx.contractAddress; - } - } - }); - resolve({ updated, tempAddresses }) - })).then((res) => { - let { updated, tempAddresses } = res; - writeFileSync("addresses_master.json", JSON.stringify(updated), { flag: "w+" }); - writeFileSync("deployments/addresses_last.json", JSON.stringify(tempAddresses), { flag: "w+" }); - }) + await copyFile("deployments/addresses_last.example.json", "deployments/addresses_last.json", 0); + let tempAddresses: { [key: string]: string } = require("../../deployments/addresses_last.json"); + let updated: MasterAddresses = addresses; + return new Promise<{ + updated: MasterAddresses; + tempAddresses: { [key: string]: string }; + }>((resolve) => { + let latestLog: string | undefined = getMostRecentFile(`broadcast/${p.contractName}.s.sol/1/`); + if (!latestLog) return; + let json = require(`../../broadcast/${p.contractName}.s.sol/1/${latestLog}`); + json.transactions.forEach((trx: any) => { + if (p.contractName == "DeployCurvePool") { + let { transactionType, address } = trx.additionalContracts[0]; + if (transactionType == "CREATE") { + updated[p.network].core.CurvePool = address; + tempAddresses.CurvePool = address; + } + } else { + if (trx.transactionType == "CREATE") { + let cl = p.contractLabel || trx.contractName; + if (p.isCore) { + updated[p.network].core[cl] = trx.contractAddress; + } else { + updated[p.network].modules[cl] = trx.contractAddress; + } + tempAddresses[cl] = trx.contractAddress; + } + } + }); + resolve({ updated, tempAddresses }); + }).then((res) => { + let { updated, tempAddresses } = res; + writeFileSync("addresses.json", JSON.stringify(updated), { flag: "w+" }); + writeFileSync("deployments/addresses_last.json", JSON.stringify(tempAddresses), { flag: "w+" }); + }); +} + +function getMostRecentFile(dir: string): string | undefined { + const files = orderRecentFiles(dir); + return files.length ? files[0].file : undefined; } -function getMostRecentFile(dir: string): string | undefined{ - const files = orderRecentFiles(dir); - return files.length ? files[0].file : undefined; - }; - -function orderRecentFiles(dir: string): {file: string, mtime: Date}[] { - return readdirSync(dir) - .filter((file) => lstatSync(path.join(dir, file)).isFile()) - .map((file) => ({ file, mtime: lstatSync(path.join(dir, file)).mtime })) - .sort((a, b) => b.mtime.getTime() - a.mtime.getTime()); - }; \ No newline at end of file +function orderRecentFiles(dir: string): { file: string; mtime: Date }[] { + return readdirSync(dir) + .filter((file) => lstatSync(path.join(dir, file)).isFile()) + .map((file) => ({ file, mtime: lstatSync(path.join(dir, file)).mtime })) + .sort((a, b) => b.mtime.getTime() - a.mtime.getTime()); +} diff --git a/deployments/addresses_last.example.json b/deployments/addresses_last.example.json new file mode 100644 index 0000000..55cab05 --- /dev/null +++ b/deployments/addresses_last.example.json @@ -0,0 +1,4 @@ +{ + "phoGovernance": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + "tonGovernance": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" +} diff --git a/deployments/addresses_last.json b/deployments/addresses_last.json new file mode 100644 index 0000000..a97ec18 --- /dev/null +++ b/deployments/addresses_last.json @@ -0,0 +1,16 @@ +{ + "phoGovernance": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + "tonGovernance": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + "PHO": "0xb9A62F59F8c1359E24830e4FD209954E21B7DF37", + "TON": "0x8e32b3a6D82DdD3a5d9E327eBAe8FE1e8a5Ba61e", + "Kernel": "0xB5D6528752d60E23137fe088380dA24BDe347eb3", + "ModuleManager": "0xd3aAA70197b22116c6732a964edC09C853AaC941", + "ChainlinkPriceFeed": "0x72b46c86aA67f2aBa435414f410bb48300C064Bf", + "CurvePool": "0xC61557C5d177bd7DC889A3b621eEC333e168f68A", + "PriceController": "0xCDa53a4bCEefbB873581d2206316a439a7498172", + "StablecoinDepositModuleUSDC": "0x6d824682aA66da4e6738c6f3e16cC15fe9ce6F79", + "StablecoinDepositModuleFRAX": "0x81D0043Fa848D07A36899388E46765aeA0e11a6b", + "StablecoinDepositModuleLUSD": "0xc9fb11FEEbf439cEb7E04D94FDd4A0314F01c597", + "MapleDepositModuleUSDC": "0x406e5D7dDaA4029eB8B957aD7677c63e15c28AC7", + "ZCBModuleUSDC": "0x2EeA9517B018B2f63072a9729ceC3EE524809460" +} diff --git a/package.json b/package.json index 37ded7a..43b6f49 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@ekonomia-tech/protocol-alpha", + "name": "@ekonomia/protocol-alpha", "version": "0.0.1-alpha", "description": "Alpha version of the Photon Finance Decentralized Stablecoin protocol. Photon is a modular, risk and profit separated decentralized stablecoin.", "types": "build/index.d.ts", @@ -18,7 +18,7 @@ "build": "rm -rf build && forge build && npm run typechain && tsc -d build/types/*.ts --outdir build --esModuleInterop", "test": "echo \"Error: no test specified\" && exit 1", "typechain": "typechain --target ethers-v5 --out-dir build/types build/abis/*[^.s][^.t].sol/*.json", - "prettier:addresses": "prettier --write 'addresses*.json'", + "prettier:addresses": "prettier --write 'addresses.json'", "prepublishOnly": "npm run build" }, "repository": {