Skip to content

Commit

Permalink
put back address tmpfiles, change addresses path
Browse files Browse the repository at this point in the history
  • Loading branch information
sammccord committed Dec 1, 2022
1 parent f21fc2d commit 65c7948
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 122 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ broadcast/

# Code Editors
.vscode
deployments/**/

35 changes: 35 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
}
35 changes: 0 additions & 35 deletions .prittierrc.json

This file was deleted.

File renamed without changes.
171 changes: 87 additions & 84 deletions deploy/helpers.ts
Original file line number Diff line number Diff line change
@@ -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<string> {
let typeString: string = "";
let valueString: string = "";

if (params.length == 0) {
return "0xc0406226";
}
export async function generateSignature(params: SignatureParam[]): Promise<string> {
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<any> {
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<void> {
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());
};
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());
}
4 changes: 4 additions & 0 deletions deployments/addresses_last.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"phoGovernance": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"tonGovernance": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
}
16 changes: 16 additions & 0 deletions deployments/addresses_last.json
Original file line number Diff line number Diff line change
@@ -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"
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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": {
Expand Down

0 comments on commit 65c7948

Please sign in to comment.