Skip to content

Commit

Permalink
wip: fix: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
seinmyung25 committed Sep 2, 2024
1 parent dca2e01 commit 1200515
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 96 deletions.
2 changes: 1 addition & 1 deletion brownie-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ dependencies:
- OpenZeppelin/[email protected]
- OpenZeppelin/[email protected]
- OpenZeppelin/[email protected]
dev_deployment_artifacts: false
dev_deployment_artifacts: false
32 changes: 17 additions & 15 deletions eco-libs/const/chain-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,21 @@ export function isLayer2(id: bigint): boolean {
return layer2Values.includes(id);
}

export function bridgeAddresss(id:bigint) {
switch(id) {
case 1n: return "0x827962404D7104202C5aaa6b929115C8211d9596";
case 11155111n: return "0x38C9a0a694AA0f92c05238484C3a9bdE1e85ddE4";
case 7789n: return "0x9a8164cA007ff0899140719E9aEC9a9C889CbF1E";

case 255n:
case 2358n:
case 7791n:
return "0x4200000000000000000000000000000000000009";

default:
throw "not exist: bridge";

export function bridgeAddresss(id: bigint) {
switch (id) {
case 1n:
return "0x827962404D7104202C5aaa6b929115C8211d9596";
case 11155111n:
return "0x38C9a0a694AA0f92c05238484C3a9bdE1e85ddE4";
case 7789n:
return "0x9a8164cA007ff0899140719E9aEC9a9C889CbF1E";

case 255n:
case 2358n:
case 7791n:
return "0x4200000000000000000000000000000000000009";

default:
throw "not exist: bridge";
}
}
}
6 changes: 3 additions & 3 deletions eco-libs/const/named-address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const MainnetAuthorizedAddress: InterfaceAuthorizedAddress = {

questMasterVault: "0x83A0Cde8ED986A080Bfee9a6c466098a60882758",
questMasterSigner: "0xcB9E7b777a7dEE9fC460Cde767898FdCE9800119",
kgh_vault: "0xB83F38bF7aB3Df8121846a611F97775400212a09"
kgh_vault: "0xB83F38bF7aB3Df8121846a611F97775400212a09",
};

export const HHnetAuthorizedAddress: InterfaceAuthorizedAddress = {
Expand All @@ -38,12 +38,12 @@ export const DevnetAuthorizedAddress: InterfaceAuthorizedAddress = {
oracle_feeder: undefined,
};

export function AuthorizedAddress(chainId:bigint): InterfaceAuthorizedAddress {
export function AuthorizedAddress(chainId: bigint): InterfaceAuthorizedAddress {
return chain.isDevnet(chainId)
? DevnetAuthorizedAddress
: chain.isTestnet(chainId)
? TestnetAuthorizedAddress
: chain.isMainnet(chainId)
? MainnetAuthorizedAddress
: (undefined as unknown as InterfaceAuthorizedAddress);
}
}
8 changes: 4 additions & 4 deletions eco-libs/const/reuse-logic-address.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as chain from "./chain-list";

interface InterfaceLogicAddress {
proxyAdmin?:string
proxyAdmin?: string;
}

export const MainnetLogicAddress: InterfaceLogicAddress = {
Expand All @@ -16,12 +16,12 @@ export const DevnetLogicAddress: InterfaceLogicAddress = {
proxyAdmin: undefined,
};

export function LogicAddress(chainId:bigint): InterfaceLogicAddress {
export function LogicAddress(chainId: bigint): InterfaceLogicAddress {
return chain.isDevnet(chainId)
? DevnetLogicAddress
: chain.isTestnet(chainId)
? TestnetLogicAddress
: chain.isMainnet(chainId)
? MainnetLogicAddress
: {proxyAdmin: undefined};
}
: { proxyAdmin: undefined };
}
9 changes: 3 additions & 6 deletions eco-libs/eco-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export interface ContractFactoryTypeSupporter<CT extends BaseContract> {
attach(target: string | Addressable): unknown;
}


export type EcoContractFactory<CT extends BaseContract> = ContractFactoryTypeSupporter<CT> & ContractFactory;

export interface EcoProxyBaseProperties<CT> {
Expand Down Expand Up @@ -62,22 +61,20 @@ export class ProxyInstanceFactory extends AsyncConstructor {
const chainId = (await hre.ethers.provider.getNetwork()).chainId;
const reuseLogicAddress = reuseAddress.LogicAddress(chainId).proxyAdmin;

if(proxyAdminLogic !== undefined) {
if (proxyAdminLogic !== undefined) {
this.proxyAdminLogic = proxyAdminLogic;

} else if (reuseLogicAddress !== undefined && reuseLogicAddress !== hre.ethers.ZeroAddress) {
this.proxyAdminLogic = this.proxyAdminFactory.attach(
reuseAddress.LogicAddress(chainId).proxyAdmin as string
reuseAddress.LogicAddress(chainId).proxyAdmin as string,
) as EcoProxyAdmin;

} else {
this.proxyAdminLogic = await this.loadByServiceInfo();
}
}

async loadByServiceInfo() {
const logicInfo = await importContractInfo("admin", "EcoProxyAdmin");
if(logicInfo.address !== hre.ethers.ZeroAddress) {
if (logicInfo.address !== hre.ethers.ZeroAddress) {
return this.proxyAdminFactory.attach(logicInfo.address) as EcoProxyAdmin;
} else {
const deployedLogic = await this.proxyAdminFactory.deploy(this.deployer);
Expand Down
43 changes: 24 additions & 19 deletions eco-libs/helper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as fs from "fs";
import * as path from "path";


const DefaultInfoDir = "eco-contract-info/";
const DefaultAbiDir = DefaultInfoDir + "abi/";

Expand All @@ -23,7 +22,11 @@ export function getSelector(contractMethod: { fragment: { selector: string } }):

async function writeAbiFromArtifact(serviceLabel: string, artifactPath: string, abiDirectory: string) {
const hardhatArtifact = (await import(artifactPath)) as { abi: unknown[] };
fs.writeFileSync(path.join(abiDirectory, serviceLabel) + ".json", JSON.stringify(hardhatArtifact.abi, null, 2), "utf8");
fs.writeFileSync(
path.join(abiDirectory, serviceLabel) + ".json",
JSON.stringify(hardhatArtifact.abi, null, 2),
"utf8",
);
}

function filesInDirectory(startPath: string, filter = RegExp(/\.json$/)): string[] {
Expand Down Expand Up @@ -56,13 +59,13 @@ interface ContractInfo {
abi: string;
}

export async function exportContractInfo(domain:string, label: string, inst: BaseContract) {
export async function exportContractInfo(domain: string, label: string, inst: BaseContract) {
await inst.waitForDeployment();
const deployTxReceipt = await inst.deploymentTransaction()?.wait();
const _chainId = (await hre.ethers.provider.getNetwork()).chainId;
const chainId = _chainId.toString();

if(chain.isDevnet(_chainId)) return;
if (chain.isDevnet(_chainId)) return;

const contractPaths = filesInDirectory(__dirname + "/../artifacts/contracts/");
for (const contractPath of contractPaths) {
Expand All @@ -85,19 +88,19 @@ export async function exportContractInfo(domain:string, label: string, inst: Bas
fs.writeFileSync(path.join(servicePath, label + ".json"), JSON.stringify(instInfo, null, 2), "utf8");
}

export async function importContractInfo(domain:string, label: string, chainId?:string): Promise<ContractInfo> {
if(!chainId) {
export async function importContractInfo(domain: string, label: string, chainId?: string): Promise<ContractInfo> {
if (!chainId) {
chainId = (await hre.ethers.provider.getNetwork()).chainId.toString();
}

try {
const instancePath = path.join(DefaultInfoDir, chainId, domain, label + ".json");
const jsonString = fs.readFileSync(instancePath, "utf-8");
return JSON.parse(jsonString) as ContractInfo;
} catch(error) {
} catch (error) {
const err = error as FileError;
if(err.code === "ENOENT") {
return {address: hre.ethers.ZeroAddress} as ContractInfo;
if (err.code === "ENOENT") {
return { address: hre.ethers.ZeroAddress } as ContractInfo;
} else {
throw err;
}
Expand Down Expand Up @@ -132,25 +135,27 @@ export class EcoServiceHelper extends AsyncConstructor {

type Constructor<CF> = new (...args: any) => CF;

export class ContractInstance<CF extends ContractFactoryTypeSupporter<CT>, CT extends BaseContract> extends EcoServiceHelper {
factory!:CF;
export class ContractInstance<
CF extends ContractFactoryTypeSupporter<CT>,
CT extends BaseContract,
> extends EcoServiceHelper {
factory!: CF;
inst!: Awaited<ReturnType<CF["deploy"]>> | EcoProxiedInstanceWithFactory<CT>;
domain!:string;
domain!: string;
label!: string;

constructor(domain:string, fatoryType: Constructor<CF>, deployer?: HardhatEthersSigner) {
constructor(domain: string, fatoryType: Constructor<CF>, deployer?: HardhatEthersSigner) {
super(async () => {
this.domain = domain;
this.label = fatoryType.name.replace("__factory", "");
this.factory = await hre.ethers.getContractFactory(this.label) as unknown as CF;
this.factory = (await hre.ethers.getContractFactory(this.label)) as unknown as CF;
}, deployer);
}

async load(target?:string) {
async load(target?: string) {
const info = await importContractInfo("erc20", this.label);
if(target)
this.inst = this.factory.attach(target) as Awaited<ReturnType<CF["deploy"]>>;
else if(info.address) {
if (target) this.inst = this.factory.attach(target) as Awaited<ReturnType<CF["deploy"]>>;
else if (info.address) {
this.inst = this.factory.attach(info.address) as Awaited<ReturnType<CF["deploy"]>>;
} else {
throw "load: " + this.domain + "/" + this.label;
Expand All @@ -168,4 +173,4 @@ export class ContractInstance<CF extends ContractFactoryTypeSupporter<CT>, CT ex
async exportInstanceInfo() {
await exportContractInfo(this.domain, this.label, this.inst);
}
}
}
2 changes: 1 addition & 1 deletion eco-libs/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,4 @@ export class ProxiedInstance<
throw "exportInstanceInfo: not deployed";
}
}
}
}
4 changes: 2 additions & 2 deletions eco-libs/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from "hardhat";

export async function getTimestamp():Promise<number> {
export async function getTimestamp(): Promise<number> {
return (await ethers.provider.getBlock("latest"))?.timestamp as number;
}
}
26 changes: 12 additions & 14 deletions eco-tasks/namespace-slot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,22 @@ interface ERC7201NamespaceInfo {
value: string;
}

task("namespace-slot", "check solidity files namespace slot value(ERC7201)")
.setAction(async (
taskArgs: TaskArguments,
hre: HardhatRuntimeEnvironment
) => {
task("namespace-slot", "check solidity files namespace slot value(ERC7201)").setAction(
async (taskArgs: TaskArguments, hre: HardhatRuntimeEnvironment) => {
const contractsDir = hre.config.paths.sources;
const ERC7201NamespaceInfo = findERC7201NamespaceInfo(contractsDir);
ERC7201NamespaceInfo.forEach(data => {
const calcSlot = "0x"+namespaceSlot(data.namespace, hre);
if(calcSlot !== data.value) {
ERC7201NamespaceInfo.forEach((data) => {
const calcSlot = "0x" + namespaceSlot(data.namespace, hre);
if (calcSlot !== data.value) {
console.log(`File: ${data.file}\nNamespace: ${data.namespace}, Value: ${data.value}, Should: ${calcSlot}`);
}
});
});
},
);

function findERC7201NamespaceInfo(contractsDir: string) {
const results: ERC7201NamespaceInfo[] = [];
walkDir(contractsDir, filePath => {
walkDir(contractsDir, (filePath) => {
if (filePath.endsWith(".sol")) {
const data = extractData(filePath);
if (data) results.push(data);
Expand All @@ -37,7 +35,7 @@ function findERC7201NamespaceInfo(contractsDir: string) {
}

function walkDir(dir: string, callback: (filePath: string) => void) {
fs.readdirSync(dir).forEach(f => {
fs.readdirSync(dir).forEach((f) => {
const dirPath = path.join(dir, f);
const isDirectory = fs.statSync(dirPath).isDirectory();
isDirectory ? walkDir(dirPath, callback) : callback(path.join(dir, f));
Expand All @@ -57,14 +55,14 @@ function extractData(filePath: string): ERC7201NamespaceInfo | null {
return {
file: filePath,
namespace: namespaceMatch ? namespaceMatch[1] : "",
value: match[2]
value: match[2],
};
} else {
return null;
}
}

export function namespaceSlot(namespace: string, hre:HardhatRuntimeEnvironment) {
export function namespaceSlot(namespace: string, hre: HardhatRuntimeEnvironment) {
// keccak256(abi.encode(uint256(keccak256(namespace)) - 1)) & ~bytes32(uint256(0xff))
const hashNamespace = hre.ethers.keccak256(hre.ethers.toUtf8Bytes(namespace));

Expand All @@ -80,4 +78,4 @@ export function namespaceSlot(namespace: string, hre:HardhatRuntimeEnvironment)
} else {
return finalMasked;
}
}
}
8 changes: 4 additions & 4 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ const config: HardhatUserConfig = {
chainId: 255,
urls: {
apiURL: "https://api.kromascan.com/api",
browserURL: "https://kromascan.com/"
}
}
]
browserURL: "https://kromascan.com/",
},
},
],
},
// sourcify: {
// enabled: true
Expand Down
Loading

0 comments on commit 1200515

Please sign in to comment.