Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Commit

Permalink
AP-724 mainnet readiness (#345)
Browse files Browse the repository at this point in the history
* Change config to match new username/project

* Added ProxyAdmin multisig singleton, changed deployer back to  Signer

* Added proxyAdminSigner to env deps on prod/dev, upgrade tasks now submit upgrade txs to proxyAdminMultisig

* Fixes according to tsc output

* Lint

* fix remaining issues with tests, typo in env.config

* Resolved open conversation with env switching proxyAdminSigner

* Add pkey helper method, rename contract to ProxyAdminMultisig

* Remove _PROD proxyAdmin signer

* Move proxyAdmin address into multiSig struct, Address PR comments

* Address tsc complains from refactor

* Add type safety to env.config, remove unused env vars

* explicitly call deploy scripts with a deployer Signer

* Added config fields for prod, made apTeamMultisig and charityApplications optional signers

* Added multisig signer args to tasks

* lint

* Fix useless ternary

* Fix order of accounts in env.config.ts (+refactor)

* Rename PROXY_ADMIN_DEV_[] to PROXY_ADMIN_[]

* Rename ProxyAdmin__factory uses to ProxyAdminMultiSig__factory

* Refactor getSigners

* Add JSON.stringify when printing newly created endowment

* Refactor resetContractAddresses

* Refactor networkHelpers.ts

* Set ProxyAdminMultiSig as diamond's contract owner

* Await ownership transfer on deployGasFwd

* Refactor deployCharityApplications

* Refactor deployIndexFund

* Update deployEndowmentMultiSig > rename 'admin' to 'proxyAdmin'

* Update deployVaultEmitter > rename 'admin' to 'proxyAdmin'

* Update deployAPTeamMultiSig > rename 'admin' to 'proxyAdmin'

* Fix typo in proxyAdminPkey param description

* Fix upgrade:ContractsUsingAccountStorage

* Refactor upgradeFacets/cutDiamond

* Deploy ProxyAdminMultiSig by default

* Remove proxyAdminMultiSig from saved addresses

* Increase transaction expiry time for ProxyAdminMultiSig

* Fix modifier error messages in MultiSig(s)

* Fix Accounts diamond owner to be set to APTeamMultiSig

* Add yes flag to deploy:GasFwd

* Better logs

* Use apTeam2 wallet in createEndowment

* Use isConfirmed in MultiSigGeneric where possible

* Fix CharityApplications executeProposal only if enough confirmations achieved

* Update createEndowment to work with prod and dev

* Minor fixes in manage:accounts:updateConfig

* Fix upgrade:endowmentMultiSig:emitter - use ITransparentUpgradeableProxy__factory

* Transfer EndowmentMultiSigFactory ownership to ProxyAdminMultiSig after creation

* Make proxyAdmin and implementationAddress in EndowmentMultiSigFactory public

* add missing env vars to template

* remove override

* Set EndowmentMultiSigFactory owner to APTeamMultiSig proxy

* Update deployGasFwd.Data.admin -> proxyAdmin

* Remove address validation in OwnershipFacet.owner

* Fix manage:changeAdmin

* Add missing address validation to OwnershipFacet.transferOwnership

* Remove NETWORK and VERIFY_CONTRACTS from .env

* FYEO-ANGL-ID-29: Fix last of missing Zero Address checks (#348)

* FYEO-ANGL-ID-29: MISSING ZERO ADDRESS CHECKS

* validator used in core contracts

* add more checks w/ Validator; Fix validator imports;

---------

Co-authored-by: Andrey <SovereignAndrey>

* Pass owners array to deployProxyAdminMultiSig

* Pass ProxyAdminMultiSig owners in deploy scripts

---------

Co-authored-by: Nenad <[email protected]>
Co-authored-by: Andrey <SovereignAndrey>
Co-authored-by: SovereignAndrey <[email protected]>
  • Loading branch information
3 people authored Aug 30, 2023
1 parent dc37705 commit 283a226
Show file tree
Hide file tree
Showing 95 changed files with 2,077 additions and 676 deletions.
5 changes: 0 additions & 5 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
## Network where to deploy contracts
# options=[hardhat, polygon, mumbai, goerli]
NETWORK="hardhat"
VERIFY_CONTRACTS=false

## Etherscan explorer API config
ETHERSCAN_API_KEY="put your key here plz"
MAINNET_URL="https://api.etherscan.io/"
Expand Down
34 changes: 29 additions & 5 deletions config/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import dotenv from "dotenv";
import {ethers} from "ethers";
import {Config} from "./types";

import {BigNumber} from "ethers";
dotenv.config({path: __dirname + "/./../.env"});

const config: Config = {
AP_TEAM_MULTISIG_DATA: {
threshold: 1,
requireExecution: false,
transactionExpiry: 100000,
transactionExpiry: 604800,
},
PROXY_ADMIN_MULTISIG_DATA: {
threshold: 1,
requireExecution: false,
transactionExpiry: 345600,
},
REGISTRAR_DATA: {
taxRate: 1,
Expand All @@ -26,10 +31,10 @@ const config: Config = {
CHARITY_APPLICATIONS_DATA: {
threshold: 1,
requireExecution: false,
transactionExpiry: 100000,
transactionExpiry: 345600,
seedSplitToLiquid: 0,
gasAmount: 0,
seedAmount: 100,
gasAmount: BigNumber.from("180000000000000000"), // 0.18 Ether
seedAmount: 0,
},
DONATION_MATCH_CHARITY_DATA: {
poolFee: 300,
Expand All @@ -50,6 +55,25 @@ const config: Config = {
// vestingOwner : "0x1F98431c8aD98523631AE4a59f267346ea31F984",
// vestingGenesisTime : 50000
},
PROD_CONFIG: {
APTeamMultiSigOwners: [
"0xF71eba1cf57997B6C52eA33D7939A330D6D85502",
"0x165d1f1361490974ea2F2A4079b5828E81F13b11",
"0x109641d919da899c7bd1ce27413d0c02b3bb611d",
"0x13C9060a611e4277a93ca259068256271fC2d7B4",
],
CharityApplicationsOwners: [
"0xF71eba1cf57997B6C52eA33D7939A330D6D85502",
"0x165d1f1361490974ea2F2A4079b5828E81F13b11",
"0x13C9060a611e4277a93ca259068256271fC2d7B4",
],
ProxyAdminMultiSigOwners: [
"0xF71eba1cf57997B6C52eA33D7939A330D6D85502",
"0x109641d919da899c7bd1ce27413d0c02b3bb611d",
"0x0f6d331f26C0B64fc6EACddABd5645b55cf2d8e0",
],
Treasury: "0x4C6cDdFC00064D73E64B34aE453884de1Bf6D639",
},
};

export default config;
13 changes: 12 additions & 1 deletion config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ export type Config = {
requireExecution: boolean;
transactionExpiry: number;
};
PROXY_ADMIN_MULTISIG_DATA: {
threshold: number;
requireExecution: boolean;
transactionExpiry: number;
};
REGISTRAR_DATA: {
taxRate: number;
acceptedTokens: {
Expand All @@ -25,7 +30,7 @@ export type Config = {
requireExecution: boolean;
transactionExpiry: number;
seedSplitToLiquid: number;
gasAmount: number;
gasAmount: BigNumber;
seedAmount: number;
};
DONATION_MATCH_CHARITY_DATA: {
Expand All @@ -44,4 +49,10 @@ export type Config = {
CommunitySpendLimit: number;
distributorSpendLimit: number;
};
PROD_CONFIG: {
APTeamMultiSigOwners: string[];
CharityApplicationsOwners: string[];
ProxyAdminMultiSigOwners: string[];
Treasury: string;
};
};
85 changes: 43 additions & 42 deletions contract-address.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,36 +131,36 @@
},
"31337": {
"accounts": {
"diamond": "0x3Ca355541eAe06EFBb53A489b89B1F2966FC044a",
"diamond": "0xb463AFC0b3A499a2D826155fc6E6E73061BEF826",
"facets": {
"accountsDepositWithdrawEndowments": "0xf9Bf69b6319fe9061c549BcFf984c6fa967c3116",
"accountsAllowance": "0xFa2B78ACc38204E6aB7465d79c4FB6672Ad6EcD2",
"accountsCreateEndowment": "0x581Ca6F583472fdf76F8070dD6b23D2D2599ed86",
"accountsGasManager": "0x13AeE574292F9934ED631216E53bc8a08683cA90",
"accountsQueryEndowments": "0x78F2fb36ad2268aFdE137F152716dE7c762a5cef",
"accountsStrategy": "0x8F15FE529f12a239364219e87cC4f308d7a02932",
"accountsSwapRouter": "0x6Eb46Cb6f3EDB24A8bc942f7e357BE7befB8B0d7",
"accountsUpdate": "0xAc7337B92f469F438E26bd9AB3078CD35014462c",
"accountsUpdateEndowments": "0x5A1D883B9ecf8A4D88290d26682F625FEc620706",
"accountsUpdateEndowmentSettingsController": "0xA4C4bC12A1Ab33EeFd40BB216CcF44235d8Dc5de",
"accountsUpdateStatusEndowments": "0x06499E212Ce9F9D4a2147e82242F137c5e32f8C8",
"diamondCutFacet": "0x9f9985900ddadc4A3Cb9b626Ae78c45A9Ca4D22C",
"diamondInitFacet": "0xd5Ce55AF9EC550C4fd77B9cd8F9fa84730b53b4c",
"diamondLoupeFacet": "0x36884aEE2eB53f350a67AC5b487b5cf08ed884ac",
"ownershipFacet": "0x22b28c6461746Fa4FAa41C45Db5862be36341961"
"accountsDepositWithdrawEndowments": "0x635D1fE12b3b8af7174eED21536319b5280B4453",
"accountsAllowance": "0xBfA2d241f8f2ecaeA58A7D60E2a358f851D5c1b1",
"accountsCreateEndowment": "0x6843cd0Ccc776EA0FE7E26e6527C925F06dDD76C",
"accountsGasManager": "0x5C680949386aCD7c85FBC6f56413936f091e3f47",
"accountsQueryEndowments": "0x38f05a857a1D4FE6eB712A794a63C61D2b282b30",
"accountsStrategy": "0x84efD60753f006DE6878C7139675b110Da654459",
"accountsSwapRouter": "0x4F4d5EABF5A8fDaeE5794DEFff4eE88e6e2c5f51",
"accountsUpdate": "0x620119C4952f0648Ee905cdE00C3077CA3f9961e",
"accountsUpdateEndowments": "0x33936aF12923725cEc788e2AC5beBa03c7a5BD79",
"accountsUpdateEndowmentSettingsController": "0x243f0Fd94F12dEB0a8B73deEA25138479ee7E4aA",
"accountsUpdateStatusEndowments": "0x2A8f0893A534983c63e4F52E39dDf3527b130768",
"diamondCutFacet": "0xAb3aa8BCEA9832CB18153Aa9731E989A289277f7",
"diamondInitFacet": "0xacE2a31e8B8d66C24DAea008d1eDaf571369A728",
"diamondLoupeFacet": "0x53557e97deED0DdEEf2404a6A29A415e379051bb",
"ownershipFacet": "0xB1A33A8f6cD8572976004C3653AbCEb3E697b9ad"
}
},
"axelar": {
"gasService": "0xC9783d89a8e0Fd3202D84a7F8e1768Ae8383C0C0",
"gateway": "0x9D04A92f355E89afaE8609620321866dfB3a1737"
"gasService": "0x7E891709346B193ff9f37Eb739C8a294B2395Ba6",
"gateway": "0xfC8caFA21dc76a1065494E213dE9F94E788DaAC9"
},
"fundraising": {
"implementation": "",
"proxy": ""
},
"gasFwd": {
"factory": "0x600eCa807e7952AC66E81Ea44279a74Eb9c5Ba05",
"implementation": "0x1C07F4d1e01AF47146EccB64B4C526A312Ad70Df"
"factory": "0x3Bfc59C12e4f838419C483B4CCb86D5798f29DFF",
"implementation": "0x790094B9fdC8C8a83507f7Eb275DEe903Ffd71eD"
},
"giftcards": {
"implementation": "",
Expand Down Expand Up @@ -218,50 +218,51 @@
}
},
"indexFund": {
"implementation": "0x41E4c81a60346b5f76aD669Af7e5bCAee30107E4",
"proxy": "0x3F1E0C7b13fb5b616EADFA8fbcC439B207aD960c"
"implementation": "0x7Eb691CaD47e698642Ac507aC0383d8Ef1A20C7D",
"proxy": "0x03d1823DCE06d5bD225cB18773bb090b2aD33b5D"
},
"multiSig": {
"charityApplications": {
"implementation": "0x1aCC68E90145A8Db8D223370e2B29A5Aa2415169",
"proxy": "0xC2790723ab94Ad77F7B102E6010a0aEA85bFbd3E"
"implementation": "0xd9Ee17555a04f2E34ea43528628582AC45A6E984",
"proxy": "0x402e14f3f9118A3745d8554EC4106450fB91aE23"
},
"apTeam": {
"implementation": "0xd8A98Ee63B135CA4d19458cBe07Ff47Ac2a9C9dF",
"proxy": "0x9a5D723096c87843E2384FC6Dc7893922277a3cE"
"implementation": "0x730EEB14F27B5D6132b9BF7D62eF877D89600F55",
"proxy": "0x45CCb6251F3500c7EE3219eE47C213fB239346cB"
},
"endowment": {
"emitter": {
"implementation": "0x7a576Cc05680F04D1Da3C4c33eA11e1Eba355028",
"proxy": "0xed7c73439a5A6487518B13A568951ae8C0b4F2d9"
"implementation": "0xC79662B65F21A222EE95d22557664C3BE14Ec0FE",
"proxy": "0xd62A19ffb64C3f00271Dd7BBf455824aa799d074"
},
"factory": "0x76e48b41810e5ec24f3FEa3c47a7C9Ae1d4F0F19",
"implementation": "0xd607fc8FCfc5FDF5b499daBf3C76f7349bfc624B"
}
"factory": "0x79AF01164e25B9c6Ff828A5f795CFA62A635CFC3",
"implementation": "0x7a0f853900040d5b131342018EAb9453723d9dcc"
},
"proxyAdmin": "0x5602bAF3002df39FbAA568C0657bBBBB8e84527a"
},
"registrar": {
"implementation": "0xaBCe32FBA4C591E8Ea5A5f711F7112dC08BCee74",
"proxy": "0x1BE9451496bfB6aDcFfbc308b673018a8972AFFE"
"implementation": "0xbF6b148a440acAb936796ad40947C0C33C78639A",
"proxy": "0x03Bb663AccB9FD14aD3c37B2D66B025bbd4Fc533"
},
"router": {
"implementation": "0x1F624f6259d6C61224E9Fd5cD11481C271a2bf75",
"proxy": "0x5f437141bCF08A919863603C946D5c8AEa66B32b"
"implementation": "0x658E94B5FfBDe68b99203BBbBAef618D36862766",
"proxy": "0x486b1C056AC365dD969056C717ab8E7AEd59a178"
},
"tokens": {
"dai": "",
"halo": "",
"reserveToken": "",
"seedAsset": "0xF82ABBea7Edb7A6602a02eE69e6c5330C049CDa5",
"usdc": "0x715e97514F641A256bC77a6A08edd8bEA908066e",
"wmatic": "0xcC46d552a29E99c71779d05AFF3675DD90d127D6"
"seedAsset": "0xB2BD05A652973f567aD6472b9FEa29FE293f6cD9",
"usdc": "0x9B1a72BD9efC089935766f7Ebc8779B67C0F7495",
"wmatic": "0x42f293b5D45C0a949639EE229E4c9acD51DF904D"
},
"uniswap": {
"factory": "0x3304eD6a8D90Ab57bb7b797aF9f66447CDf09C3E",
"swapRouter": "0x3304eD6a8D90Ab57bb7b797aF9f66447CDf09C3E"
"factory": "0x40B5D836dBeAf26c652210D8f07169B99E77C994",
"swapRouter": "0x40B5D836dBeAf26c652210D8f07169B99E77C994"
},
"vaultEmitter": {
"implementation": "0x0Bd2640F272D074e0d8c2111373526bA946255A9",
"proxy": "0xEC9d58EDD9752AdC448769Fff558cE19A7473Dbc"
"implementation": "0x6eB34f65AcC0dd09C3AA72C3C4bA08578a4A3F96",
"proxy": "0x675017e864CB39CEbe4A0CDBA639750f6ee0BDE2"
}
},
"80001": {
Expand Down
15 changes: 8 additions & 7 deletions contracts/accessory/gift-cards/scripts/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
import {HardhatRuntimeEnvironment} from "hardhat/types";
import {getContractName, getSigners, logger, updateAddresses, verify} from "utils";

import {GiftCardsMessage} from "typechain-types/contracts/accessory/gift-cards/GiftCards";
import {GiftCards__factory, ProxyContract__factory} from "typechain-types";

export async function deployGiftCard(
GiftCardsDataInput: GiftCardsMessage.InstantiateMsgStruct,
admin: string,
verify_contracts: boolean,
hre: HardhatRuntimeEnvironment
) {
try {
const {ethers, run, network} = hre;
const {proxyAdmin} = await getSigners(hre);
const GiftCards = await ethers.getContractFactory("GiftCards");
const {deployer} = await getSigners(hre);

const GiftCards = new GiftCards__factory(deployer);
const GiftCardsInstance = await GiftCards.deploy();
await GiftCardsInstance.deployed();
logger.out(`GiftCards implementation address: ${GiftCardsInstance.address}"`);

const ProxyContract = await ethers.getContractFactory("ProxyContract");
const ProxyContract = new ProxyContract__factory(deployer);
const GiftCardsData = GiftCardsInstance.interface.encodeFunctionData("initialize", [
GiftCardsDataInput,
]);
const GiftCardsProxy = await ProxyContract.deploy(
GiftCardsInstance.address,
proxyAdmin.address,
admin,
GiftCardsData
);
await GiftCardsProxy.deployed();
Expand All @@ -42,7 +43,7 @@ export async function deployGiftCard(
if (verify_contracts) {
await verify(hre, {
address: GiftCardsProxy.address,
constructorArguments: [GiftCardsInstance.address, proxyAdmin.address, GiftCardsData],
constructorArguments: [GiftCardsInstance.address, admin, GiftCardsData],
contractName: getContractName(GiftCards),
});
}
Expand Down
7 changes: 4 additions & 3 deletions contracts/core/accounts/diamond/Diamond.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ pragma solidity ^0.8.19;

import {LibDiamond} from "./libraries/LibDiamond.sol";
import {IDiamondCut} from "./interfaces/IDiamondCut.sol";
import {Validator} from "../../validator.sol";

contract Diamond {
constructor(address contractowner, address diamondcutfacet) payable {
require(contractowner != address(0), "Invalid Address");
require(diamondcutfacet != address(0), "Invalid Address");
require(Validator.addressChecker(contractowner), "Invalid Address");
require(Validator.addressChecker(diamondcutfacet), "Invalid Address");
LibDiamond.setContractOwner(contractowner);

// Add the diamondCut external function from the diamondCutFacet
Expand All @@ -33,7 +34,7 @@ contract Diamond {
}
// get facet from function selector
address facet = ds.selectorToFacetAndPosition[msg.sig].facetAddress;
require(facet != address(0), "Diamond: Function does not exist");
require(Validator.addressChecker(facet), "Diamond: Function does not exist");
// Execute external function from facet using delegatecall and return any value.
assembly {
// copy function selector and any arguments
Expand Down
2 changes: 1 addition & 1 deletion contracts/core/accounts/diamond/facets/OwnershipFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import {Validator} from "../../../validator.sol";
contract OwnershipFacet is IERC173 {
function transferOwnership(address newOwner) external override {
LibDiamond.enforceIsContractOwner();
require(Validator.addressChecker(newOwner), "Invalid address");
LibDiamond.setContractOwner(newOwner);
}

function owner() external view override returns (address owner_) {
require(Validator.addressChecker(owner_), "Invalid address");
owner_ = LibDiamond.contractOwner();
}
}
41 changes: 30 additions & 11 deletions contracts/core/accounts/scripts/deploy/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
import {SignerWithAddress} from "@nomiclabs/hardhat-ethers/signers";
import {HardhatRuntimeEnvironment} from "hardhat/types";
import {DiamondCutFacet__factory, DiamondInit__factory, Diamond__factory} from "typechain-types";
import {Deployment, getContractName, getSigners, logger, updateAddresses} from "utils";
import {
DiamondCutFacet__factory,
DiamondInit__factory,
Diamond__factory,
IERC173__factory,
} from "typechain-types";
import {Deployment, getContractName, logger, updateAddresses} from "utils";
import cutDiamond from "./cutDiamond";
import deployFacets from "./deployFacets";

export async function deployAccountsDiamond(
owner: string,
registrar: string,
diamondAdmin: string,
deployer: SignerWithAddress,
hre: HardhatRuntimeEnvironment
): Promise<{
diamond: Deployment;
facets: Array<Deployment>;
}> {
logger.out("Deploying and setting up Accounts Diamond and all its facets...");

const {proxyAdmin} = await getSigners(hre);
const {diamond, diamondCutFacet} = await deployDiamond(deployer, hre);

const {diamond, diamondCutFacet} = await deployDiamond(proxyAdmin, hre);
const diamondInit = await deployDiamondInit(deployer, hre);

const diamondInit = await deployDiamondInit(proxyAdmin, hre);
const cuts = await deployFacets(deployer, hre);

const cuts = await deployFacets(proxyAdmin, hre);
await cutDiamond(diamond.address, diamondInit.address, deployer, owner, registrar, cuts, hre);

await cutDiamond(diamond.address, diamondInit.address, proxyAdmin, owner, registrar, cuts, hre);
await setDiamondContractOwner(diamond.address, diamondAdmin, deployer);

return {
diamond,
Expand All @@ -37,19 +44,19 @@ export async function deployAccountsDiamond(
}

async function deployDiamond(
admin: SignerWithAddress,
deployer: SignerWithAddress,
hre: HardhatRuntimeEnvironment
): Promise<{diamond: Deployment; diamondCutFacet: Deployment}> {
const DiamondCutFacet = new DiamondCutFacet__factory(admin);
const DiamondCutFacet = new DiamondCutFacet__factory(deployer);
const diamondCutFacet = await DiamondCutFacet.deploy();
await diamondCutFacet.deployed();
logger.out(`DiamondCutFacet deployed at: ${diamondCutFacet.address}`);

const constructorArguments: Parameters<Diamond__factory["deploy"]> = [
admin.address,
deployer.address,
diamondCutFacet.address,
];
const Diamond = new Diamond__factory(admin);
const Diamond = new Diamond__factory(deployer);
const diamond = await Diamond.deploy(...constructorArguments);
await diamond.deployed();
logger.out(`Diamond deployed at: ${diamond.address}`);
Expand Down Expand Up @@ -93,3 +100,15 @@ async function deployDiamondInit(
contractName: getContractName(DiamondInit),
};
}

async function setDiamondContractOwner(
address: string,
newOwner: string,
curOwner: SignerWithAddress
) {
logger.out(`Transferring ownership from "${curOwner}" to "${newOwner}"...`);
const accountsDiamond = IERC173__factory.connect(address, curOwner);
const tx = await accountsDiamond.transferOwnership(newOwner);
logger.out(`Tx hash: ${tx.hash}`);
await tx.wait();
}
Loading

0 comments on commit 283a226

Please sign in to comment.