Skip to content

Commit

Permalink
Merge pull request #4 from ambrosus/sourcify
Browse files Browse the repository at this point in the history
Sourcify
  • Loading branch information
SvineruS authored Mar 10, 2023
2 parents 39de7e7 + 979f978 commit a465aa9
Show file tree
Hide file tree
Showing 11 changed files with 240 additions and 99 deletions.
File renamed without changes.
35 changes: 23 additions & 12 deletions deployments/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"function transferOwnership(address newOwner)",
"function withdraw(address to, uint256 amount)"
],
"deployTx": "0x09c7a9ebf0599f3cba4edebd3d699218fad09e1e826db5867ca2d192614233ce"
"deployTx": "0x09c7a9ebf0599f3cba4edebd3d699218fad09e1e826db5867ca2d192614233ce",
"fullyQualifiedName": "contracts/multisig/Multisig.sol:Multisig"
},
"FinanceMaster": {
"address": "0xA4b0053a45DCEc895f7baB043c697eAEEaA539fd",
Expand All @@ -52,7 +53,8 @@
"function transferToBanks()",
"function withdraw(address addressTo, uint256 amount)"
],
"deployTx": "0x66f7c5efe648bbf80c81886e656bb4d6af2eef4570a09bc93723fbc7f36a2c3b"
"deployTx": "0x66f7c5efe648bbf80c81886e656bb4d6af2eef4570a09bc93723fbc7f36a2c3b",
"fullyQualifiedName": "contracts/finance/MasterFinance.sol:MasterFinance"
},
"FinanceRewards_Multisig": {
"address": "0x1BBA0e0a97AE8996C451dccb9a30a705Adc44918",
Expand Down Expand Up @@ -91,7 +93,8 @@
"function transferOwnership(address newOwner)",
"function withdraw(address to, uint256 amount)"
],
"deployTx": "0x4cbf59900d095240279e3114056d2bead7a69ded30d60dd12ee9ee71d583db89"
"deployTx": "0x4cbf59900d095240279e3114056d2bead7a69ded30d60dd12ee9ee71d583db89",
"fullyQualifiedName": "contracts/multisig/Multisig.sol:Multisig"
},
"FinanceRewards": {
"address": "0xf4F51DcEFd100394b1D0c224856B645e69444CFe",
Expand All @@ -104,7 +107,8 @@
"function transferOwnership(address newOwner)",
"function withdraw(address addressTo, uint256 amount)"
],
"deployTx": "0xfc5af2bc4321cb6179e6aafbef8327748a313c24e3c3f389d7f7d898e3bd0fe2"
"deployTx": "0xfc5af2bc4321cb6179e6aafbef8327748a313c24e3c3f389d7f7d898e3bd0fe2",
"fullyQualifiedName": "contracts/finance/Finance.sol:Finance"
},
"FinanceInvestors_Multisig": {
"address": "0x54EC87CeF515c6DF3E230d280D9795ec36aF5D40",
Expand Down Expand Up @@ -143,7 +147,8 @@
"function transferOwnership(address newOwner)",
"function withdraw(address to, uint256 amount)"
],
"deployTx": "0xc6059bfc4d7644b6f49cf9bf649bd2b8bb4a57f8714725207b45fa791a884c16"
"deployTx": "0xc6059bfc4d7644b6f49cf9bf649bd2b8bb4a57f8714725207b45fa791a884c16",
"fullyQualifiedName": "contracts/multisig/Multisig.sol:Multisig"
},
"FinanceInvestors": {
"address": "0xcF4Be089c7173ad35113863c822CB5d991C8dB5F",
Expand All @@ -156,7 +161,8 @@
"function transferOwnership(address newOwner)",
"function withdraw(address addressTo, uint256 amount)"
],
"deployTx": "0x3e4b4eb4d5e5b2aeb7cb342363c5e3a5a4b30efb019947d3352a37e5e5339655"
"deployTx": "0x3e4b4eb4d5e5b2aeb7cb342363c5e3a5a4b30efb019947d3352a37e5e5339655",
"fullyQualifiedName": "contracts/finance/Finance.sol:Finance"
},
"FinanceTeam_Multisig": {
"address": "0xc65c0e999D0a7cDAc5F7bC6fC243e60A914c91B7",
Expand Down Expand Up @@ -195,7 +201,8 @@
"function transferOwnership(address newOwner)",
"function withdraw(address to, uint256 amount)"
],
"deployTx": "0xb6ec3c137f0a4f4a67872e3d9fd8507953319d0433ae674e8e8d64916c6c138c"
"deployTx": "0xb6ec3c137f0a4f4a67872e3d9fd8507953319d0433ae674e8e8d64916c6c138c",
"fullyQualifiedName": "contracts/multisig/Multisig.sol:Multisig"
},
"FinanceTeam": {
"address": "0x3b9f6bB2840A220Fd873C9C903c272D335544d89",
Expand All @@ -208,7 +215,8 @@
"function transferOwnership(address newOwner)",
"function withdraw(address addressTo, uint256 amount)"
],
"deployTx": "0xaec9977c845e33f3bcfc8918443f4432651c9e15ffc66ada67aca1d2205ff3da"
"deployTx": "0xaec9977c845e33f3bcfc8918443f4432651c9e15ffc66ada67aca1d2205ff3da",
"fullyQualifiedName": "contracts/finance/Finance.sol:Finance"
},
"FinanceEcosystem_Multisig": {
"address": "0x01B35630DD6D459000eE7F36f3353EcF8B73fDa7",
Expand Down Expand Up @@ -247,7 +255,8 @@
"function transferOwnership(address newOwner)",
"function withdraw(address to, uint256 amount)"
],
"deployTx": "0xd0b1a3e8d77e2d855320b7a2f7bddf53659dbcb9a49a85972c3c360203fc5b1b"
"deployTx": "0xd0b1a3e8d77e2d855320b7a2f7bddf53659dbcb9a49a85972c3c360203fc5b1b",
"fullyQualifiedName": "contracts/multisig/Multisig.sol:Multisig"
},
"FinanceEcosystem": {
"address": "0xddf0B762dCFF0BB02B903D39a111fC173D07299d",
Expand All @@ -260,7 +269,8 @@
"function transferOwnership(address newOwner)",
"function withdraw(address addressTo, uint256 amount)"
],
"deployTx": "0x3e905d4e7d9ed8a8a0f39eea50e35500dc4c5647d2b429bebc8ba6c2994542b6"
"deployTx": "0x3e905d4e7d9ed8a8a0f39eea50e35500dc4c5647d2b429bebc8ba6c2994542b6",
"fullyQualifiedName": "contracts/finance/Finance.sol:Finance"
},
"MasterMultisig": {
"address": "0x17D3A416062724d15C29263d9FdB970132e40776",
Expand Down Expand Up @@ -302,6 +312,7 @@
"function transferOwnership(address newOwner)",
"function withdraw(address to, uint256 amount)"
],
"deployTx": "0x2eb3c0cf6a06842763a1640083a6d9783b612777d53bebf1ab57c5b0450d6771"
"deployTx": "0x2eb3c0cf6a06842763a1640083a6d9783b612777d53bebf1ab57c5b0450d6771",
"fullyQualifiedName": "contracts/multisig/MasterMultisig.sol:MasterMultisig"
}
}
}
13 changes: 10 additions & 3 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { HardhatUserConfig } from "hardhat/config";
import { HardhatUserConfig, task } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
import { ethers } from "ethers";
import * as dotenv from "dotenv";
import { sourcifyAll } from "./src/dev/sourcify";
import { HardhatRuntimeEnvironment } from "hardhat/types";

dotenv.config();

Expand All @@ -15,12 +17,12 @@ const config: HardhatUserConfig = {
],
hardfork: "byzantium",
},
"test/amb": {
test: {
url: "https://network.ambrosus-test.io",
hardfork: "byzantium",
accounts: [process.env.PRIVATEKEY_OWNER_AMB || ethers.constants.HashZero],
},
"main/amb": {
main: {
url: "https://network.ambrosus.io",
hardfork: "byzantium",
accounts: [process.env.PRIVATEKEY_OWNER_AMB || ethers.constants.HashZero],
Expand All @@ -44,4 +46,9 @@ const config: HardhatUserConfig = {
},
};

task("sourcify", "verify contracts using sourcify").setAction(async (args: any, hre: HardhatRuntimeEnvironment) => {
await hre.run("compile"); // compile contract first
await sourcifyAll(hre);
});

export default config;
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
"coverage": "COVERAGE=true hardhat coverage",
"format:check": "eslint ./ && prettier --check ./",
"format:fix": "eslint --fix ./ && prettier --write ./",
"deploy_multisig": "hardhat run ./scripts/deploy_multisig.ts --network test/amb",
"deploy_finance": "hardhat run ./scripts/deploy_finance.ts --network test/amb",
"test_script": "hardhat run ./scripts/test.ts --network test/amb"
"deploy_multisig": "hardhat run ./scripts/deploy_multisig.ts --network test",
"deploy_finance": "hardhat run ./scripts/deploy_finance.ts --network test",
"test_script": "hardhat run ./scripts/test.ts --network test",
"sourcify": "hardhat sourcify --network test"
},
"devDependencies": {
"@nomicfoundation/hardhat-toolbox": "^2.0.1",
Expand Down
32 changes: 15 additions & 17 deletions scripts/deploy_finance.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { ethers } from "hardhat";
import { deploy, loadDeployment } from "../src/utils/deployments";
import { loadDeployment } from "../src/utils/deployments";
import { ContractNames } from "../src";
import { Andrii, AndriiTest, DimaTest, Igor, Kevin, Lang, Rory, Seth, SharedDev, Stefan } from "./addresses";
import { deploy } from "../src/dev/deploy";
import { Finance__factory, MasterFinance__factory, Multisig__factory } from "../typechain-types";

async function main() {
const MultisigFactory = await ethers.getContractFactory("Multisig");
const MasterFinanceFactory = await ethers.getContractFactory("MasterFinance");
const FinanceFactory = await ethers.getContractFactory("Finance");

const networkName = (await ethers.provider.getNetwork()).chainId.toString();
const networkName = ethers.provider.network.name;
const [deployer] = await ethers.getSigners();

const masterMultisig = loadDeployment(ContractNames.MasterMultisig, networkName).address;
Expand All @@ -22,14 +20,14 @@ async function main() {
const multisigName = (financeName + "_Multisig") as ContractNames;
console.assert(Object.values(ContractNames).includes(multisigName), `can't find ${multisigName} in ContractNames`);

const multisig = await deploy(
const multisig = await deploy<Multisig__factory>(
multisigName,
networkName,
MultisigFactory,
"Multisig",
[signers, isInitiator, threshold, masterMultisig],
deployer
);
await deploy(financeName, networkName, FinanceFactory, [multisig.address], deployer);
await deploy<Finance__factory>(financeName, networkName, "Finance", [multisig.address], deployer);
}

if (networkName == "16718") {
Expand All @@ -39,17 +37,17 @@ async function main() {
const bankCount = 50;

// finance master
const multisig = await deploy(
const multisig = await deploy<Multisig__factory>(
ContractNames.FinanceMasterMultisig,
networkName,
MultisigFactory,
"Multisig",
[[Lang, Igor, Rory, Kevin, Stefan], [true, true, true, true, true], 75, masterMultisig],
deployer
);
await deploy(
await deploy<MasterFinance__factory>(
ContractNames.FinanceMaster,
networkName,
MasterFinanceFactory,
"MasterFinance",
[multisig.address, bankCount, maxBankBalance],
deployer
);
Expand All @@ -69,10 +67,10 @@ async function main() {
const bankCount = 50;

// finance master
const multisig = await deploy(
const multisig = await deploy<Multisig__factory>(
ContractNames.FinanceMasterMultisig,
networkName,
MultisigFactory,
"Multisig",
[
[
SharedDev,
Expand All @@ -90,10 +88,10 @@ async function main() {
],
deployer
);
await deploy(
await deploy<MasterFinance__factory>(
ContractNames.FinanceMaster,
networkName,
MasterFinanceFactory,
"MasterFinance",
[multisig.address, bankCount, maxBankBalance],
deployer
);
Expand Down
32 changes: 18 additions & 14 deletions scripts/deploy_multisig.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
import { ethers } from "hardhat";
import { deploy } from "../src/utils/deployments";
import { ContractNames } from "../src";
import { Andrii, AndriiTest, DimaTest, Igor, Lang, SharedDev } from "./addresses";
import { deploy } from "../src/dev/deploy";
import { MasterMultisig__factory } from "../typechain-types";

async function main() {
const MultisigMasterFactory = await ethers.getContractFactory("MasterMultisig");

const networkName = (await ethers.provider.getNetwork()).chainId.toString();
const networkName = ethers.provider.network.name;
const [deployer] = await ethers.getSigners();

if (networkName == "16718") {
console.log("--- MAINNET DEPLOYMENT ---");

await deploy(ContractNames.MasterMultisig, networkName, MultisigMasterFactory, [
[Lang, Igor, Andrii],
[true, true, true],
51,
]);
await deploy<MasterMultisig__factory>(
ContractNames.MasterMultisig,
networkName,
"MasterMultisig",
[[Lang, Igor, Andrii], [true, true, true], 51],
deployer
);
} else {
await deploy(ContractNames.MasterMultisig, networkName, MultisigMasterFactory, [
[SharedDev, DimaTest, AndriiTest],
[true, true, true],
51,
]);
await deploy<MasterMultisig__factory>(
ContractNames.MasterMultisig,
networkName,
"MasterMultisig",
[[SharedDev, DimaTest, AndriiTest], [true, true, true], 51],
deployer
);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/contracts/contracts.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Contract, Signer } from "ethers";
import { loadAllDeployments } from "../utils/deployments";
import { chainIDToName, loadAllDeployments } from "../utils/deployments";
import { ContractNames } from "./names";

export class Contracts {
private contracts: { [contractName: string]: Contract };
private nameByAddress: { [address: string]: ContractNames };

constructor(signer: Signer, chainId: number) {
this.contracts = loadAllDeployments(chainId.toString(), signer);
this.contracts = loadAllDeployments(chainIDToName[chainId], signer);
this.nameByAddress = {};

for (const [name, contract] of Object.entries(this.contracts))
Expand Down
60 changes: 60 additions & 0 deletions src/dev/deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { ContractFactory, Signer } from "ethers";
import fs from "fs";
import { _contractFromDeployment, _loadDeployments } from "../utils/deployments";
import { GetARGsTypeFromFactory, GetContractTypeFromFactory } from "../../typechain-types/common";
import { artifacts, ethers } from "hardhat";
import { ContractNames } from "../contracts/names";
import path from "path";
import { getFullyQualifiedName } from "hardhat/src/utils/contract-names";

// this file use method from hardhat, so
// don't include it into SDK build

/**
* @param contractName - The name under which to save the contract. Must be unique.
* @param networkName - Network name used as filename in deployments folder.
* @param artifactName - Name of the contract artifact. For example, ERC20.
* @param deployArgs - Deploy arguments
* @param signer - Signer, that will deploy contract (or with witch contract will be loaded from deployment)
* @param loadIfAlreadyDeployed - Load contract if it already deployed; Otherwise throw exception
* @returns Deployed contract or contract loaded from deployments
*/
export async function deploy<N extends ContractFactory>(
contractName: ContractNames,
networkName: string,
artifactName: string,
deployArgs: GetARGsTypeFromFactory<N>,
signer: Signer,
loadIfAlreadyDeployed = false
): Promise<GetContractTypeFromFactory<N>> {
const deployments = _loadDeployments(networkName);

if (deployments[contractName]) {
if (loadIfAlreadyDeployed) {
console.log(`Already deployed ${contractName}`);
return _contractFromDeployment(deployments[contractName], signer) as GetContractTypeFromFactory<N>;
}
throw new Error(`Already deployed ${contractName}`);
}

const factory = await ethers.getContractFactory(artifactName);
const artifact = await artifacts.readArtifact(artifactName);
const fullyQualifiedName = getFullyQualifiedName(artifact.sourceName, artifact.contractName);

console.log(`deploying ${contractName} in ${networkName}...`);
const res = await factory.deploy(...deployArgs);
await res.deployed();
console.log(`deployed ${contractName} at`, res.address);

deployments[contractName] = {
address: res.address,
abi: res.interface.format() as string[],
deployTx: res.deployTransaction.hash,
fullyQualifiedName: fullyQualifiedName,
};

const deploymentPath = path.resolve(__dirname, `../../deployments/${networkName}.json`);
fs.writeFileSync(deploymentPath, JSON.stringify(deployments, null, 2));

return res as GetContractTypeFromFactory<N>;
}
Loading

0 comments on commit a465aa9

Please sign in to comment.