From 097ded897dc1ed1570b9b197049fc88ac19664f0 Mon Sep 17 00:00:00 2001 From: James Tuckett Date: Wed, 30 Aug 2023 09:58:50 +0100 Subject: [PATCH] [SC-11220] Deploy spark actions (#449) * chore: update README's, types in deploy class and deploy spark actions * chore: update docs about post deployment * chore: add missing SR name for AjnaRepayWithdraw back into mainnet config --- README.md | 22 +++++--- package.json | 3 +- packages/deploy-configurations/README.md | 10 ++++ .../configs/mainnet.conf.ts | 22 ++++---- packages/dma-contracts/README.md | 32 ++++++++++-- .../scripts/deployment/deploy.ts | 51 ++++++++++--------- 6 files changed, 94 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index 206e27bfb..95d720458 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,10 @@ -# Environment variables +# Summer Mono + +## Environment variables Copy and populate an `.env` file according to the .env.template file. -# Setup +## Setup 1. Install dependencies @@ -29,7 +31,7 @@ Contracts are automatically compiled when running `yarn build` but can also be c yarn compile ``` -# Local development +## Local development Running a local node & deploying the system to a locally running node @@ -45,7 +47,7 @@ yarn dev yarn deploy:dev ``` -# Running tests +## Running tests 1. Run all tests in the monorepo @@ -72,15 +74,23 @@ _Command should be run from a respective package folder_ yarn clean & yarn hardhat test ``` -# Naming conventions +## Naming conventions - TS files and all folders are named using kebab-case - -Solidity files (interfaces, contracts etc) are named using Pascal case -# Hardhat tasks +## Hardhat tasks 1. Create multiply positions on a network of your choosing ```shell cd packages/dma-contracts && yarn hardhat createMultiplyPositions --serviceregistry --accountfactory --network ``` + +**Note:** There's an issue with circular dependencies between packages. You'll need to ensure that tasks which causes circular dependencies are +not included in the hardhat.config.ts file in @oasisdex/dma-contracts. For more info see the [readme](./packages/dma-contracts/README.md) in the packages/dma-contracts folder + +## Deploy contracts + +Please see the [readme](./packages/dma-contracts/README.md) in the packages/dma-contracts folder for more information + diff --git a/package.json b/package.json index d1a0606dc..0a92a40d7 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,8 @@ "test:e2e": "lerna run test:e2e --stream", "test:unit": "lerna run test:unit --stream", "clean": "rm -rf .parcel-cache && lerna run clean --stream", - "compile": "npx ts-node symlink-contracts.ts && lerna run compile --stream", + "compile": "yarn symlink && lerna run compile --stream", + "symlink": "npx ts-node symlink-contracts.ts", "build": "yarn compile && lerna run build --stream", "format": "lerna run format --stream", "format:check": "lerna run format:check --stream", diff --git a/packages/deploy-configurations/README.md b/packages/deploy-configurations/README.md index 0bbd69f83..5bf439f57 100644 --- a/packages/deploy-configurations/README.md +++ b/packages/deploy-configurations/README.md @@ -1,3 +1,13 @@ +# @oasisdex/deploy-configurations + +## Deployment configurations + +See configs directory. There are primary mainnet and testnet configs. There are also test deployment configs for use +by tests only. These are housed in /configs/test. + +Please review these configs before proceeding with a deployment to see what contracts are marked for deployment or +redeployment. + ## AaveLike addresses Protocol system contracts are named slightly differently across Aave V2, Aave V3 and Spark protocol. diff --git a/packages/deploy-configurations/configs/mainnet.conf.ts b/packages/deploy-configurations/configs/mainnet.conf.ts index 9fc2d02d9..16b536e9f 100644 --- a/packages/deploy-configurations/configs/mainnet.conf.ts +++ b/packages/deploy-configurations/configs/mainnet.conf.ts @@ -1,4 +1,4 @@ -import { ADDRESS_ZERO, loadContractNames } from '@deploy-configurations/constants' +import { loadContractNames } from '@deploy-configurations/constants' import { SystemConfig } from '@deploy-configurations/types/deployment-config' import { Network } from '@deploy-configurations/types/network' @@ -261,41 +261,41 @@ export const config: SystemConfig = { SparkBorrow: { name: 'SparkBorrow', deploy: true, - address: ADDRESS_ZERO, + address: '0xc69156420307048c9BAAe8191f9012391521a88d', serviceRegistryName: SERVICE_REGISTRY_NAMES.spark.BORROW, - history: [], + history: ['0x0000000000000000000000000000000000000000'], constructorArgs: ['address:ServiceRegistry'], }, SparkWithdraw: { name: 'SparkWithdraw', deploy: true, - address: ADDRESS_ZERO, + address: '0x0cCa782002c4fE95e1ed7A75d41bB56bEfa0C167', serviceRegistryName: SERVICE_REGISTRY_NAMES.spark.WITHDRAW, - history: [], + history: ['0x0000000000000000000000000000000000000000'], constructorArgs: ['address:ServiceRegistry'], }, SparkDeposit: { name: 'SparkDeposit', deploy: true, - address: ADDRESS_ZERO, + address: '0xC58F2Ee4Ef92F2bE314743442496D6Fad0339d56', serviceRegistryName: SERVICE_REGISTRY_NAMES.spark.DEPOSIT, - history: [], + history: ['0x0000000000000000000000000000000000000000'], constructorArgs: ['address:ServiceRegistry'], }, SparkPayback: { name: 'SparkPayback', deploy: true, - address: ADDRESS_ZERO, + address: '0x068875B4254aC431BE7B8a10C56D80324fA0d043', serviceRegistryName: SERVICE_REGISTRY_NAMES.spark.PAYBACK, - history: [], + history: ['0x0000000000000000000000000000000000000000'], constructorArgs: ['address:ServiceRegistry'], }, SparkSetEMode: { name: 'SparkSetEMode', deploy: true, - address: ADDRESS_ZERO, + address: '0x79d428e563D946DaBe43C681f92c8D714F5157cE', serviceRegistryName: SERVICE_REGISTRY_NAMES.spark.SET_EMODE, - history: [], + history: ['0x0000000000000000000000000000000000000000'], constructorArgs: ['address:ServiceRegistry'], }, }, diff --git a/packages/dma-contracts/README.md b/packages/dma-contracts/README.md index d698826c3..07975639a 100644 --- a/packages/dma-contracts/README.md +++ b/packages/dma-contracts/README.md @@ -1,11 +1,38 @@ # @oasisdex/dma-contracts -## Run Before Using @dma-contracts +## Deploying contracts +Decide which network you want to deploy to. The following networks are supported: +- `local` - local hardhat node +- `mainnet` - mainnet +- `goerli` - goerli testnet +- `optimism` - optimism mainnet +- `arbitrum` - arbitrum mainnet + +Then run the following command: +```bash +yarn hardhat run scripts/deployment/deploy-.ts --network +``` + +If the network is a protected network you will be asked to confirm the action. + +Finally, please review the configs in @oasisdex/deploy-configurations to see which contracts have the deploy flag set to `true`. +Only contracts with the deploy flag set to `true` will be deployed. + +For more info see the deployment configs [readme](../deploy-configurations/README.md). + +After deployment, the addresses of the deployed contracts will be saved directly in the deployment configs. + +## Symlink contracts before Using @dma-contracts You need to create a symlink, to include `ajna-contracts` in `dma-contracts` for proper solc compilation. ```bash /oasis-earn-sc/packages/dma-contracts$ ln -s ~/absolute_path_to_the_repository/oasis-earn-sc/packages/ajna-contracts/contracts/ajna ./contracts/ ``` +You can also run the following script to create the symlink from the project root +``` +yarn symlink +``` + ## Circular dependencies Some HH Tasks in @dma-contracts depend on the library. @@ -14,5 +41,4 @@ A special script has been created to run these tasks yarn hardhat run scripts/run-dependent-task.ts --network local ``` -Please do not import tasks that are dependent on @dma-library into hardhat.config.ts -``` \ No newline at end of file +Please do not import tasks that are dependent on @dma-library into hardhat.config.ts \ No newline at end of file diff --git a/packages/dma-contracts/scripts/deployment/deploy.ts b/packages/dma-contracts/scripts/deployment/deploy.ts index 5dcba88d7..8e0e7ccc8 100644 --- a/packages/dma-contracts/scripts/deployment/deploy.ts +++ b/packages/dma-contracts/scripts/deployment/deploy.ts @@ -34,10 +34,10 @@ import { SystemTemplate, } from '@deploy-configurations/types/deployed-system' import { - DeployedSystemContracts, - DeploymentConfig, + ConfigEntry, SystemConfig, - SystemConfigItem, + SystemConfigEntry, + SystemContracts, } from '@deploy-configurations/types/deployment-config' import { EtherscanGasPrice } from '@deploy-configurations/types/etherscan' import { Network } from '@deploy-configurations/types/network' @@ -127,6 +127,10 @@ abstract class DeployedSystemHelpers { !this.hideLogging && console.log(...args) } + useGnosisSafeServiceClient() { + return gnosisSafeServiceUrl[this.network] !== '' + } + async init(hideLogging = false) { if (!this.hre) throw new Error('HardhatRuntimeEnvironment is not defined!') this.hideLogging = hideLogging @@ -334,11 +338,11 @@ export class DeploymentSystem extends DeployedSystemHelpers { return configPath } - async postInstantiation(configItem: DeploymentConfig, contract: Contract) { + async postInstantiation(configItem: ConfigEntry, contract: Contract) { this.log('POST INITIALIZATION', configItem.name, contract.address) } - async postRegistryEntry(configItem: DeploymentConfig, address: string) { + async postRegistryEntry(configItem: ConfigEntry, address: string) { if (!configItem.serviceRegistryName) throw new Error('No service registry name provided') this.log( 'REGISTRY ENTRY', @@ -367,7 +371,7 @@ export class DeploymentSystem extends DeployedSystemHelpers { // SERVICE REGISTRY addition if (configItem.serviceRegistryName) { - if (gnosisSafeServiceUrl[this.network] !== '') { + if (this.useGnosisSafeServiceClient()) { /** * Currently throws the following error: * Error: Unprocessable Entity @@ -438,19 +442,19 @@ export class DeploymentSystem extends DeployedSystemHelpers { return '' } - async addRegistryEntries(addressesConfig: DeploymentConfig[]) { + async addRegistryEntries(addressesConfig: ConfigEntry[]) { if (!this.serviceRegistryHelper) throw new Error('No service registry helper set') for (const configItem of addressesConfig) { if (configItem.serviceRegistryName) { const address = - this.deployedSystem?.[configItem.name as DeployedSystemContracts]?.contract.address || + this.deployedSystem?.[configItem.name as SystemContracts]?.contract.address || configItem.address await this.addRegistryEntry(configItem, address) } } } - async addRegistryEntry(configItem: DeploymentConfig, address: string) { + async addRegistryEntry(configItem: ConfigEntry, address: string) { if (!this.serviceRegistryHelper) throw new Error('ServiceRegistryHelper not initialized') if (configItem.serviceRegistryName) { await this.serviceRegistryHelper.addEntry(configItem.serviceRegistryName, address) @@ -458,7 +462,7 @@ export class DeploymentSystem extends DeployedSystemHelpers { } } - async removeRegistryEntry(configItem: DeploymentConfig) { + async removeRegistryEntry(configItem: ConfigEntry) { if (!this.serviceRegistryHelper) throw new Error('ServiceRegistryHelper not initialized') if (configItem.serviceRegistryName) { this.serviceRegistryHelper.removeEntry(configItem.serviceRegistryName) @@ -486,7 +490,7 @@ export class DeploymentSystem extends DeployedSystemHelpers { } } - async instantiateContracts(addressesConfig: SystemConfigItem[]) { + async instantiateContracts(addressesConfig: SystemConfigEntry[]) { if (!this.signer) throw new Error('Signer not initialized') for (const configItem of addressesConfig) { this.log('INSTANTIATING ', configItem.name, configItem.address) @@ -571,7 +575,7 @@ export class DeploymentSystem extends DeployedSystemHelpers { } } - async deployContracts(addressesConfig: SystemConfigItem[]) { + async deployContracts(addressesConfig: SystemConfigEntry[]) { if (!this.signer) throw new Error('Signer not initialized') if (this.isRestrictedNetwork) { await this.promptBeforeDeployment() @@ -582,10 +586,7 @@ export class DeploymentSystem extends DeployedSystemHelpers { if (configItem.constructorArgs && configItem.constructorArgs?.length !== 0) { constructorParams = configItem.constructorArgs.map((param: string | number) => { if (typeof param === 'string' && param.indexOf('address:') >= 0) { - const contractName = (param as string).replace( - 'address:', - '', - ) as DeployedSystemContracts + const contractName = (param as string).replace('address:', '') as SystemContracts if (!this.deployedSystem[contractName]?.contract.address) { throw new Error(`Contract ${contractName} not deployed`) @@ -677,11 +678,11 @@ export class DeploymentSystem extends DeployedSystemHelpers { if (!this.config) throw new Error('No config set') await this.instantiateContracts( Object.values(this.config.mpa.core).filter( - (item: SystemConfigItem) => item.address !== '' && !item.deploy, + (item: SystemConfigEntry) => item.address !== '' && !item.deploy, ), ) await this.deployContracts( - Object.values(this.config.mpa.core).filter((item: SystemConfigItem) => item.deploy), + Object.values(this.config.mpa.core).filter((item: SystemConfigEntry) => item.deploy), ) } @@ -689,11 +690,11 @@ export class DeploymentSystem extends DeployedSystemHelpers { if (!this.config) throw new Error('No config set') await this.instantiateContracts( Object.values(this.config.mpa.actions).filter( - (item: SystemConfigItem) => item.address !== '' && !item.deploy, + (item: SystemConfigEntry) => item.address !== '' && !item.deploy, ), ) await this.deployContracts( - Object.values(this.config.mpa.actions).filter((item: SystemConfigItem) => item.deploy), + Object.values(this.config.mpa.actions).filter((item: SystemConfigEntry) => item.deploy), ) } @@ -706,7 +707,7 @@ export class DeploymentSystem extends DeployedSystemHelpers { if (!this.config) throw new Error('No config set') await this.addRegistryEntries( Object.values(this.config.common).filter( - (item: DeploymentConfig) => item.address !== '' && item.serviceRegistryName, + (item: ConfigEntry) => item.address !== '' && item.serviceRegistryName, ), ) } @@ -715,12 +716,12 @@ export class DeploymentSystem extends DeployedSystemHelpers { if (!this.config) throw new Error('No config set') await this.addRegistryEntries( Object.values(this.config.aave.v2 || {}).filter( - (item: DeploymentConfig) => item.address !== '' && item.serviceRegistryName, + (item: ConfigEntry) => item.address !== '' && item.serviceRegistryName, ), ) await this.addRegistryEntries( Object.values(this.config.aave.v3 || {}).filter( - (item: DeploymentConfig) => item.address !== '' && item.serviceRegistryName, + (item: ConfigEntry) => item.address !== '' && item.serviceRegistryName, ), ) } @@ -729,7 +730,7 @@ export class DeploymentSystem extends DeployedSystemHelpers { if (!this.config) throw new Error('No config set') await this.addRegistryEntries( Object.values(this.config.maker.common).filter( - (item: DeploymentConfig) => item.address !== '' && item.serviceRegistryName, + (item: ConfigEntry) => item.address !== '' && item.serviceRegistryName, ), ) } @@ -738,7 +739,7 @@ export class DeploymentSystem extends DeployedSystemHelpers { if (!this.config) throw new Error('No config set') await this.addRegistryEntries( Object.values(this.config.ajna).filter( - (item: DeploymentConfig) => item.address !== '' && item.serviceRegistryName, + (item: ConfigEntry) => item.address !== '' && item.serviceRegistryName, ), ) }