Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ RUN curl -L https://foundry.paradigm.xyz | bash
RUN echo 'export PATH="$PATH:/home/node/.foundry/bin"' >> ~/.zshrc
RUN echo 'export PATH="$PATH:/home/node/.foundry/bin"' >> ~/.bashrc
RUN /home/node/.foundry/bin/foundryup

RUN curl https://raw.githubusercontent.com/Tenderly/tenderly-cli/master/scripts/install-linux.sh | sudo sh
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,6 @@ jobs:

- name: Run deployment script
env:
SKIP_VERIFICATION: true
ENABLE_ETHERSCAN_VERIFICATION: true
run: hh run scripts/deploy_all.ts

46 changes: 42 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,30 +68,68 @@ The deploy script will deploy all required contracts and create a test instance

```bash
# run deployment on a locally created ganache instance
export SKIP_VERIFICATION=true
export ENABLE_ETHERSCAN_VERIFICATION=false
export ENABLE_TENDERLY_VERIFICATION=false
hh run scripts/deploy_all.ts
```

```bash
# set appropriate values vor env variables (see below)
# set appropriate values for env variables (see below)

# run deployment on another network
hh run --network <networkname> scripts/deploy_all.ts
```

Environment variables:

- `SKIP_VERIFICATION` set to `true` to skip etherscan verification (required for ganacht and anvil)
- `RESUMEABLE_DEPLOYMENT`set to `true` to skip deployment/verification of already deployed/verified contracts (based on ./deployment_state_<chainId>.json)
- `ENABLE_ETHERSCAN_VERIFICATION` set to `true` to skip etherscan verification (required for ganacht and anvil)
- `WEB3_INFURA_PROJECT_ID` set to infura project id (required for mumbai and mainnet)
- `WALLET_MNEMONIC` the mnemonic of the wallet to use for deployment (required for mumbai and mainnet)
- `ETHERSCAN_API_KEY` `POLYGONSCAN_API_KEY` the api key for etherscan/polygonscan (required for mumbai and mainnet)


#### Tenderly Testnet Deployment

if not already done:
* install hardhat-tenderly
* install tenderly cli

```bash
npm install @tenderly/hardhat-tenderly
curl https://raw.githubusercontent.com/Tenderly/tenderly-cli/master/scripts/install-linux.sh | sudo sh
```

login to tenderly
```bash
tenderly login
```
when prompted (1st time usage) enter access key (= access token, see https://dashboard.tenderly.co/account/authorization)

run deployment to tenderly testnet (eg <tenderlyNetwork>=virtualMainnet in the example below)

```bash
export RESUMEABLE_DEPLOYMENT=false
export ENABLE_ETHERSCAN_VERIFICATION=false
export ENABLE_TENDERLY_VERIFICATION=true
hh run --network <tenderlyNetwork> scripts/deploy_all.ts
```

Environment variables:

- `RESUMEABLE_DEPLOYMENT` set to `true` to skip deployment/verification of already deployed/verified contracts (based on ./deployment_state_<chainId>.json), set to `true` to force a redeploy
- `ENABLE_TENDERLY_VERIFICATION` set to `true` to perform verification of deployed contracts
# https://dashboard.tenderly.co/{TENDERLY_USERNAME}/{TENDERLY_PROJECT}/fork/{FORK_ID}
- `TENDERLY_DEVNET_RPC_URL` is the RPC_URL of a Tenderly Devnet, found on the devnet UI info tab
- `TENDERLY_USERNAME` is username, {TENDERLY_USERNAME} in the URL
- `TENDERLY_PROJECT` is project slug, {TENDERLY_PROJECT} in the URL

### Create a new instance

Requires previous step to be completed.

```bash
# set appropriate values vor env variables (see below)
# set appropriate values for env variables (see below)

hh run --network <networkname> scripts/new_instance.ts
```
Expand Down
7 changes: 7 additions & 0 deletions contracts/instance/IInstanceService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,11 @@ interface IInstanceService is IService {
) external;

function setComponentLocked(bool locked) external;


function getMasterInstanceAddress() external view returns (address);
function getMasterInstanceAdminAddress() external view returns (address);
function getMasterInstanceReaderAddress() external view returns (address);
function getMasterBundleManagerAddress() external view returns (address);
function getMasterInstanceStoreAddress() external view returns (address);
}
10 changes: 6 additions & 4 deletions contracts/instance/InstanceReader.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ import {RiskId} from "../type/RiskId.sol";
import {UFixed, MathLib, UFixedLib} from "../type/UFixed.sol";
import {Version} from "../type/Version.sol";
import {StateId} from "../type/StateId.sol";
import {TimestampLib} from "../type/Timestamp.sol";

import {IKeyValueStore} from "../shared/IKeyValueStore.sol";

import {IRisk} from "../instance/module/IRisk.sol";
import {IPolicy} from "../instance/module/IPolicy.sol";
import {IRegistry} from "../registry/IRegistry.sol";
import {IBundle} from "../instance/module/IBundle.sol";
import {IComponents} from "../instance/module/IComponents.sol";
import {IDistribution} from "../instance/module/IDistribution.sol";
import {IInstance} from "./IInstance.sol";
import {IKeyValueStore} from "../shared/IKeyValueStore.sol";
import {IPolicy} from "../instance/module/IPolicy.sol";
import {IRisk} from "../instance/module/IRisk.sol";
import {TimestampLib} from "../type/Timestamp.sol";


import {InstanceStore} from "./InstanceStore.sol";

Expand Down
131 changes: 73 additions & 58 deletions contracts/instance/InstanceService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ contract InstanceService is
Service,
IInstanceService
{

// TODO update to real hash when instance is stable
bytes32 public constant INSTANCE_CREATION_CODE_HASH = bytes32(0);

Expand Down Expand Up @@ -68,6 +67,51 @@ contract InstanceService is
_;
}

function setAndRegisterMasterInstance(address instanceAddress)
external
onlyOwner
returns(NftId masterInstanceNftId)
{
if(_masterInstance != address(0)) { revert ErrorInstanceServiceMasterInstanceAlreadySet(); }
if(_masterAccessManager != address(0)) { revert ErrorInstanceServiceMasterInstanceAccessManagerAlreadySet(); }
if(_masterInstanceAdmin != address(0)) { revert ErrorInstanceServiceMasterInstanceAdminAlreadySet(); }
if(_masterInstanceBundleManager != address(0)) { revert ErrorInstanceServiceMasterBundleManagerAlreadySet(); }

if(instanceAddress == address(0)) { revert ErrorInstanceServiceInstanceAddressZero(); }

IInstance instance = IInstance(instanceAddress);
InstanceAdmin instanceAdmin = instance.getInstanceAdmin();
address instanceAdminAddress = address(instanceAdmin);
InstanceReader instanceReader = instance.getInstanceReader();
address instanceReaderAddress = address(instanceReader);
BundleManager bundleManager = instance.getBundleManager();
address bundleManagerAddress = address(bundleManager);
InstanceStore instanceStore = instance.getInstanceStore();
address instanceStoreAddress = address(instanceStore);

if(instanceAdminAddress == address(0)) { revert ErrorInstanceServiceInstanceAdminZero(); }
if(instanceReaderAddress == address(0)) { revert ErrorInstanceServiceInstanceReaderZero(); }
if(bundleManagerAddress == address(0)) { revert ErrorInstanceServiceBundleManagerZero(); }
if(instanceStoreAddress == address(0)) { revert ErrorInstanceServiceInstanceStoreZero(); }

if(instance.authority() != instanceAdmin.authority()) { revert ErrorInstanceServiceInstanceAuthorityMismatch(); }
if(bundleManager.authority() != instanceAdmin.authority()) { revert ErrorInstanceServiceBundleManagerAuthorityMismatch(); }
if(instanceStore.authority() != instanceAdmin.authority()) { revert ErrorInstanceServiceInstanceStoreAuthorityMismatch(); }
if(bundleManager.getInstance() != instance) { revert ErrorInstanceServiceBundleMangerInstanceMismatch(); }
if(instanceReader.getInstance() != instance) { revert ErrorInstanceServiceInstanceReaderInstanceMismatch2(); }

_masterAccessManager = instance.authority();
_masterInstanceAdmin = instanceAdminAddress;
_masterInstance = instanceAddress;
_masterInstanceReader = instanceReaderAddress;
_masterInstanceBundleManager = bundleManagerAddress;
_masterInstanceStore = instanceStoreAddress;

IInstance masterInstance = IInstance(_masterInstance);
IRegistry.ObjectInfo memory info = _registryService.registerInstance(masterInstance, getOwner());
masterInstanceNftId = info.nftId;
}

function createInstanceClone()
external
returns (
Expand Down Expand Up @@ -167,61 +211,6 @@ contract InstanceService is
locked);
}


function getMasterInstanceReader() external view returns (address) {
return _masterInstanceReader;
}

// From IService
function getDomain() public pure override returns(ObjectType) {
return INSTANCE();
}

function setAndRegisterMasterInstance(address instanceAddress)
external
onlyOwner
returns(NftId masterInstanceNftId)
{
if(_masterInstance != address(0)) { revert ErrorInstanceServiceMasterInstanceAlreadySet(); }
if(_masterAccessManager != address(0)) { revert ErrorInstanceServiceMasterInstanceAccessManagerAlreadySet(); }
if(_masterInstanceAdmin != address(0)) { revert ErrorInstanceServiceMasterInstanceAdminAlreadySet(); }
if(_masterInstanceBundleManager != address(0)) { revert ErrorInstanceServiceMasterBundleManagerAlreadySet(); }

if(instanceAddress == address(0)) { revert ErrorInstanceServiceInstanceAddressZero(); }

IInstance instance = IInstance(instanceAddress);
InstanceAdmin instanceAdmin = instance.getInstanceAdmin();
address instanceAdminAddress = address(instanceAdmin);
InstanceReader instanceReader = instance.getInstanceReader();
address instanceReaderAddress = address(instanceReader);
BundleManager bundleManager = instance.getBundleManager();
address bundleManagerAddress = address(bundleManager);
InstanceStore instanceStore = instance.getInstanceStore();
address instanceStoreAddress = address(instanceStore);

if(instanceAdminAddress == address(0)) { revert ErrorInstanceServiceInstanceAdminZero(); }
if(instanceReaderAddress == address(0)) { revert ErrorInstanceServiceInstanceReaderZero(); }
if(bundleManagerAddress == address(0)) { revert ErrorInstanceServiceBundleManagerZero(); }
if(instanceStoreAddress == address(0)) { revert ErrorInstanceServiceInstanceStoreZero(); }

if(instance.authority() != instanceAdmin.authority()) { revert ErrorInstanceServiceInstanceAuthorityMismatch(); }
if(bundleManager.authority() != instanceAdmin.authority()) { revert ErrorInstanceServiceBundleManagerAuthorityMismatch(); }
if(instanceStore.authority() != instanceAdmin.authority()) { revert ErrorInstanceServiceInstanceStoreAuthorityMismatch(); }
if(bundleManager.getInstance() != instance) { revert ErrorInstanceServiceBundleMangerInstanceMismatch(); }
if(instanceReader.getInstance() != instance) { revert ErrorInstanceServiceInstanceReaderInstanceMismatch2(); }

_masterAccessManager = instance.authority();
_masterInstanceAdmin = instanceAdminAddress;
_masterInstance = instanceAddress;
_masterInstanceReader = instanceReaderAddress;
_masterInstanceBundleManager = bundleManagerAddress;
_masterInstanceStore = instanceStoreAddress;

IInstance masterInstance = IInstance(_masterInstance);
IRegistry.ObjectInfo memory info = _registryService.registerInstance(masterInstance, getOwner());
masterInstanceNftId = info.nftId;
}

function upgradeMasterInstanceReader(address instanceReaderAddress) external onlyOwner {
if(_masterInstanceReader == address(0)) { revert ErrorInstanceServiceMasterInstanceReaderNotSet(); }
if(instanceReaderAddress == address(0)) { revert ErrorInstanceServiceInstanceReaderAddressZero(); }
Expand All @@ -246,7 +235,6 @@ contract InstanceService is
instance.setInstanceReader(upgradedInstanceReaderClone);
}


function createGifTarget(
NftId instanceNftId,
address targetAddress,
Expand All @@ -267,7 +255,6 @@ contract InstanceService is
);
}


function createComponentTarget(
NftId instanceNftId,
address targetAddress,
Expand All @@ -288,6 +275,34 @@ contract InstanceService is
);
}

function getMasterInstanceAddress() external view returns (address) {
return _masterInstance;
}

function getMasterInstanceAdminAddress() external view returns (address) {
return _masterInstanceAdmin;
}

function getMasterBundleManagerAddress() external view returns (address) {
return _masterInstanceBundleManager;
}

function getMasterInstanceStoreAddress() external view returns (address) {
return _masterInstanceStore;
}

function getMasterInstanceReaderAddress() external view returns (address) {
return _masterInstanceReader;
}

// From IService

function getDomain() public pure override returns(ObjectType) {
return INSTANCE();
}

// ----------- internal functions -------------


/// all gif targets MUST be children of instanceNftId
function _createGifTarget(
Expand Down
Loading