Skip to content

Commit

Permalink
Upgrades contracts code to lates osx libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
emmdim committed Feb 14, 2024
1 parent 5c384ec commit d8a9399
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/contracts/deploy/01_repo/10_create_repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
};

export default func;
func.tags = ['PluginRepo', 'Deployment'];
func.tags = ['PluginRepo'];
7 changes: 5 additions & 2 deletions packages/contracts/deploy/02_setup/10_setup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {PLUGIN_SETUP_CONTRACT_NAME} from '../../plugin-settings';
import {getTokensAddresses} from '../../utils/helpers';
import {DeployFunction} from 'hardhat-deploy/types';
import {HardhatRuntimeEnvironment} from 'hardhat/types';

Expand All @@ -8,12 +9,14 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const {deployments, getNamedAccounts} = hre;
const {deploy} = deployments;
const {deployer} = await getNamedAccounts();
const addresses = getTokensAddresses(hre.network.name);
console.log('addresses', addresses);

await deploy(PLUGIN_SETUP_CONTRACT_NAME, {
from: deployer,
args: [
'0xf868169bde323f45005e476287f4c76411a610f8',
'0x073b8528bcfbb2454c8fa792558aa4a1e64c613b',
addresses[0], // GovernanceERC20
addresses[1], // GovernanceWrappedERC20
],
log: true,
});
Expand Down
9 changes: 5 additions & 4 deletions packages/contracts/deploy/02_setup/12_publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import {
PLUGIN_SETUP_CONTRACT_NAME,
VERSION,
} from '../../plugin-settings';
import {VocdoniVotingSetup__factory} from '../../typechain';
import {addCreatedVersion, getPluginInfo} from '../../utils/helpers';
import {toHex} from '../../utils/ipfs';
import {uploadToIPFS} from '../../utils/ipfs';
import {PluginRepo__factory, PluginSetup__factory} from '@aragon/osx-ethers';
import {PluginRepo__factory} from '@aragon/osx-ethers';
import {DeployFunction} from 'hardhat-deploy/types';
import {HardhatRuntimeEnvironment} from 'hardhat/types';

Expand All @@ -22,10 +23,10 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {

// Upload the metadata to IPFS
const releaseMetadataURI = `ipfs://${await uploadToIPFS(
JSON.stringify(METADATA.release),
JSON.stringify(METADATA.release)
)}`;
const buildMetadataURI = `ipfs://${await uploadToIPFS(
JSON.stringify(METADATA.build),
JSON.stringify(METADATA.build)
)}`;

console.log(`Uploaded release metadata: ${releaseMetadataURI}`);
Expand Down Expand Up @@ -87,7 +88,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
throw Error('something went wrong');
}

const implementationAddress = await PluginSetup__factory.connect(
const implementationAddress = await VocdoniVotingSetup__factory.connect(
setup.address,
deployer
).implementation();
Expand Down
16 changes: 16 additions & 0 deletions packages/contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const apiUrls: NetworkNameMapping = {
polygon: 'https://polygon-mainnet.infura.io/v3/',
polygonMumbai: 'https://polygon-mumbai.infura.io/v3/',
baseGoerli: 'https://goerli.base.org',
sepolia: 'https://sepolia.infura.io/v3/',
};

export const networks: {[index: string]: NetworkUserConfig} = {
Expand Down Expand Up @@ -58,6 +59,12 @@ export const networks: {[index: string]: NetworkUserConfig} = {
url: `${apiUrls.baseGoerli}`,
gasPrice: 20000000000,
},
sepolia: {
chainId: 11155111,
gasPrice: 100000000,
// blockGasLimit: 30000000,
url: `${apiUrls.sepolia}${process.env.INFURA_API_KEY}`,
},
};

// Uses hardhats private key if none is set. DON'T USE THIS ACCOUNT FOR DEPLOYMENTS
Expand Down Expand Up @@ -89,6 +96,7 @@ const config: HardhatUserConfig = {
goerli: process.env.ETHERSCAN_API_KEY || '',
polygon: process.env.POLYGONSCAN_API_KEY || '',
polygonMumbai: process.env.POLYGONSCAN_API_KEY || '',
sepolia: process.env.ETHERSCAN_API_KEY || '',
baseGoerli: process.env.BASESCAN_API_KEY || '',
},
customChains: [
Expand All @@ -100,6 +108,14 @@ const config: HardhatUserConfig = {
browserURL: 'https://goerli.basescan.org',
},
},
{
network: 'sepolia',
chainId: 11155111,
urls: {
apiURL: 'https://api-sepolia.etherscan.io/api',
browserURL: 'https://sepolia.etherscan.io',
},
},
],
},

Expand Down
6 changes: 4 additions & 2 deletions packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@
"tmp-promise": "^3.0.3"
},
"dependencies": {
"@aragon/osx": "^1.3.0-rc0.3",
"@aragon/osx-ethers": "^1.3.0-rc0.3",
"@aragon/osx": "1.3.0",
"@aragon/osx-ethers": "1.4.0-alpha.0",
"@aragon/osx-commons-configs": "0.2.0",
"@aragon/osx-commons-contracts": "1.4.0-alpha.3",
"@ensdomains/ens-contracts": "0.0.20",
"@openzeppelin/contracts": "^4.8.2",
"@openzeppelin/contracts-upgradeable": "^4.8.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"strict": true,
"target": "es6"
},
"exclude": ["node_modules"],
"exclude": ["node_modules", "../../node_modules"],
"files": ["./hardhat.config.ts"],
"include": [
"src/**/*",
Expand Down
65 changes: 57 additions & 8 deletions packages/contracts/utils/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import {activeContractsList} from '@aragon/osx-ethers';
import {
getLatestNetworkDeployment,
getNetworkByNameOrAlias,
} from '@aragon/osx-commons-configs';
// import {activeContractsList} from '@aragon/osx-ethers';
import {ContractFactory, ContractTransaction} from 'ethers';
import {
Interface,
Expand All @@ -19,14 +23,15 @@ export type ContractBlockNumberList = {
[index: string]: {[index: string]: {address: string; blockNumber: number}};
};

export const osxContracts: ContractList = activeContractsList;
// export const osxContracts: ContractList = activeContractsList;

export const networkNameMapping: NetworkNameMapping = {
mainnet: 'mainnet',
goerli: 'goerli',
polygon: 'polygon',
polygonMumbai: 'mumbai',
baseGoerli: 'baseGoerli',
sepolia: 'sepolia',
};

export const ERRORS = {
Expand All @@ -44,26 +49,70 @@ export function getPluginRepoFactoryAddress(networkName: string) {
? process.env.NETWORK_NAME
: 'mainnet';

pluginRepoFactoryAddr = osxContracts[hardhatForkNetwork].PluginRepoFactory;
const network = getNetworkByNameOrAlias(hardhatForkNetwork);
if (!network) {
throw new Error(`Network "${networkName}" not found`);
}
const version = getLatestNetworkDeployment(network.name);
pluginRepoFactoryAddr = version?.PluginRepoFactory.address as string;
// pluginRepoFactoryAddr = osxContracts[hardhatForkNetwork].PluginRepoFactory;
console.log(
`Using the "${hardhatForkNetwork}" PluginRepoFactory address (${pluginRepoFactoryAddr}) for deployment testing on network "${networkName}"`
);
} else {
pluginRepoFactoryAddr =
osxContracts[networkNameMapping[networkName]].PluginRepoFactory;

const network = getNetworkByNameOrAlias(networkName);
if (!network) {
throw new Error(`Network "${networkName}" not found`);
}
const version = getLatestNetworkDeployment(network.name);
pluginRepoFactoryAddr = version?.PluginRepoFactory.address as string;
console.log(
`Using the ${networkNameMapping[networkName]} PluginRepoFactory address (${pluginRepoFactoryAddr}) for deployment...`
);
}
return pluginRepoFactoryAddr;
}

export function getTokensAddresses(networkName: string) {
let addresses: string[] = [];
if (
networkName === 'localhost' ||
networkName === 'hardhat' ||
networkName === 'coverage'
) {
const hardhatForkNetwork = process.env.NETWORK_NAME
? process.env.NETWORK_NAME
: 'mainnet';

const network = getNetworkByNameOrAlias(hardhatForkNetwork);
if (!network) {
throw new Error(`Network "${networkName}" not found`);
}
const version = getLatestNetworkDeployment(network.name);
addresses = [
version?.GovernanceERC20.address ?? '',
version?.GovernanceWrappedERC20.address ?? '',
];
// pluginRepoFactoryAddr = osxContracts[hardhatForkNetwork].PluginRepoFactory;
} else {
const network = getNetworkByNameOrAlias(networkName);
if (!network) {
throw new Error(`Network "${networkName}" not found`);
}
const version = getLatestNetworkDeployment(network.name);
addresses = [
version?.GovernanceERC20.address ?? '',
version?.GovernanceWrappedERC20.address ?? '',
];
}
return addresses;
}

export function getPluginInfo(networkName: string): any {
let pluginInfoFilePath: string;
let pluginInfo: any = {};

if (['localhost', 'hardhat', 'coverage'].includes(networkName)) {
if (['localhost', 'hardhat', 'coverage', 'sepolia'].includes(networkName)) {
pluginInfoFilePath = 'plugin-info-testing.json';
} else {
pluginInfoFilePath = 'plugin-info.json';
Expand All @@ -85,7 +134,7 @@ export function getPluginInfo(networkName: string): any {
}

function storePluginInfo(networkName: string, pluginInfo: any) {
if (['localhost', 'hardhat', 'coverage'].includes(networkName)) {
if (['localhost', 'hardhat', 'coverage', 'sepolia'].includes(networkName)) {
writeFileSync(
'plugin-info-testing.json',
JSON.stringify(pluginInfo, null, 2) + '\n'
Expand Down

0 comments on commit d8a9399

Please sign in to comment.