Skip to content

Commit

Permalink
chore: update README's, types in deploy class and deploy spark actions
Browse files Browse the repository at this point in the history
  • Loading branch information
zerotucks committed Aug 30, 2023
1 parent e29e3b5 commit d9480e7
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 47 deletions.
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

Expand All @@ -45,7 +47,7 @@ yarn dev
yarn deploy:dev
```

# Running tests
## Running tests

1. Run all tests in the monorepo

Expand All @@ -72,15 +74,23 @@ _Command should be run from a respective package folder_
yarn clean & yarn hardhat test <path-to-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 <service-registry-address> --accountfactory <account-factory-address> --network <insert-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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 10 additions & 0 deletions packages/deploy-configurations/README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
24 changes: 12 additions & 12 deletions packages/deploy-configurations/configs/mainnet.conf.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -254,48 +254,48 @@ export const config: SystemConfig = {
name: 'AjnaRepayWithdraw',
deploy: false,
address: '0xc0BAFEa22AD2A2D92BF54B1d76eA175785aa9Eb1',
serviceRegistryName: SERVICE_REGISTRY_NAMES.ajna.REPAY_WITHDRAW,
serviceRegistryName: undefined,
history: [],
constructorArgs: ['address:ServiceRegistry'],
},
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'],
},
},
Expand Down
30 changes: 27 additions & 3 deletions packages/dma-contracts/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
# @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-<network-name>.ts --network <network-name>
```

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).

## 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.
Expand All @@ -14,5 +39,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
```
Please do not import tasks that are dependent on @dma-library into hardhat.config.ts
51 changes: 26 additions & 25 deletions packages/dma-contracts/scripts/deployment/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -438,27 +442,27 @@ 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)
await this.postRegistryEntry(configItem, address)
}
}

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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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`)
Expand Down Expand Up @@ -677,23 +678,23 @@ 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),
)
}

async deployActions() {
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),
)
}

Expand All @@ -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,
),
)
}
Expand All @@ -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,
),
)
}
Expand All @@ -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,
),
)
}
Expand All @@ -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,
),
)
}
Expand Down

0 comments on commit d9480e7

Please sign in to comment.