Skip to content

Commit

Permalink
Merge pull request #16 from CamposBruno/fix/deployment
Browse files Browse the repository at this point in the history
Deploy and Extract Addresses
  • Loading branch information
CamposBruno authored Apr 2, 2024
2 parents 10f26e7 + 80187f6 commit 0e73f1e
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 113 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,16 @@ jobs:
- name: Run Tests
run: yarn run test

- name: Create deployment folder
run: mkdir ./data/deployments

- name: Run Deploy
run: yarn run deploy --network testnet #change to mainnet before production

- name: Export Contract Addresses
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_options: '--no-verify --signoff'
branch: main
push_options: '--force'
file_pattern: './data/deployments/*.json'
192 changes: 79 additions & 113 deletions scripts/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,86 +1,36 @@
import { Contract, Signer } from 'ethers';
import { ethers } from 'hardhat';
import { AbiCoder } from 'ethers';
// import OnchainID from '@onchain-id/solidity';

async function deployIdentityProxy(implementationAuthority: Contract['address'], managementKey: string, signer: Signer) {
// const identity = await new ethers.ContractFactory(OnchainID.contracts.IdentityProxy.abi, OnchainID.contracts.IdentityProxy.bytecode, signer).deploy(
// implementationAuthority,
// managementKey,
// );
const identity = await ethers.deployContract('IdentityProxy', [implementationAuthority, managementKey], signer);
await identity.waitForDeployment();

return ethers.getContractAt('Identity', await identity.getAddress(), signer);
}

async function deployClaimIssuer(managementKey: string, signer: Signer) {
// const claimIssuer = await new ethers.ContractFactory(OnchainID.contracts.ClaimIssuer.abi, OnchainID.contracts.ClaimIssuer.bytecode, signer).deploy(
// managementKey,
// );
const claimIssuer = await ethers.deployContract('ClaimIssuer', [managementKey], signer);
await claimIssuer.waitForDeployment();
import { writeFile } from 'fs/promises';

return ethers.getContractAt('ClaimIssuer', await claimIssuer.getAddress(), signer);
// Initial function for logs and configs
async function init(): Promise<Record<string, any>> {
console.log(" - Deploying contracts...");
return {};
}

async function deployTRex() {
// Deploy main contracts for the ERC3643 Standart (T-REX)
async function deployERC3643(contracts: Record<string, any>): Promise<Record<string, any>> {
console.log(' - Deploying ERC3643 contracts...');
const [deployer] = await ethers.getSigners();

const claimIssuerSigningKey = deployer;
const tokenIssuer = deployer
const claimIssuer = deployer

//Deploy implementations
const claimTopicsRegistryImplementation = await ethers.deployContract('ClaimTopicsRegistry', deployer);
console.log("claimTopicsRegistryImplementation", await claimTopicsRegistryImplementation.getAddress());
const trustedIssuersRegistryImplementation = await ethers.deployContract('TrustedIssuersRegistry', deployer);
console.log("trustedIssuersRegistryImplementation", await trustedIssuersRegistryImplementation.getAddress());
const identityRegistryStorageImplementation = await ethers.deployContract('IdentityRegistryStorage', deployer);
console.log("identityRegistryStorageImplementation", await identityRegistryStorageImplementation.getAddress());
const identityRegistryImplementation = await ethers.deployContract('IdentityRegistry', deployer);
console.log("identityRegistryImplementation", await identityRegistryImplementation.getAddress());
const modularComplianceImplementation = await ethers.deployContract('ModularCompliance', deployer);
console.log("modularComplianceImplementation", await modularComplianceImplementation.getAddress());
const tokenImplementation = await ethers.deployContract('Token', deployer);
console.log("tokenImplementation", await tokenImplementation.getAddress());

// const identityImplementation = await new ethers.ContractFactory(
// OnchainID.contracts.Identity.abi,
// OnchainID.contracts.Identity.bytecode,
// deployer,
// ).deploy(await deployer.getAddress(), true);
const identityImplementation = await ethers.deployContract('Identity', [deployer.address, true], deployer);
console.log("identityImplementation", await identityImplementation.getAddress());

// const identityImplementationAuthority = await new ethers.ContractFactory(
// OnchainID.contracts.ImplementationAuthority.abi,
// OnchainID.contracts.ImplementationAuthority.bytecode,
// deployer,
// ).deploy(await identityImplementation.getAddress());
const identityImplementationAuthority = await ethers.deployContract('ImplementationAuthority', [await identityImplementation.getAddress()], deployer);
console.log("identityImplementationAuthority", await identityImplementationAuthority.getAddress());

// const identityFactory = await new ethers.ContractFactory(
// OnchainID.contracts.Factory.abi,
// OnchainID.contracts.Factory.bytecode,
// deployer
// ).deploy(await identityImplementationAuthority.getAddress(),);
const identityFactory = await ethers.deployContract('IdFactory', [await identityImplementationAuthority.getAddress()], deployer);
console.log("identityFactory", await identityFactory.getAddress());

const trexImplementationAuthority = await ethers.deployContract(
'TREXImplementationAuthority',
[true, ethers.ZeroAddress, ethers.ZeroAddress],
deployer,
);
console.log("trexImplementationAuthority", await trexImplementationAuthority.getAddress());
const trexImplementationAuthority = await ethers.deployContract('TREXImplementationAuthority', [true, ethers.ZeroAddress, ethers.ZeroAddress], deployer);

// creates TREX Factory
const versionStruct = {
major: 4,
minor: 0,
patch: 0,
};

const contractsStruct = {
tokenImplementation: await tokenImplementation.getAddress(),
ctrImplementation: await claimTopicsRegistryImplementation.getAddress(),
Expand All @@ -95,75 +45,91 @@ async function deployTRex() {
await trexImplementationAuthority.getAddress()
);

await trexImplementationAuthorityContract.addAndUseTREXVersion(versionStruct, contractsStruct, {
gasLimit: 15000000,
});
await trexImplementationAuthorityContract.addAndUseTREXVersion(versionStruct, contractsStruct, { gasLimit: 15000000 });


const TREXFactory = await ethers.getContractFactory('TREXFactory');
const trexFactory = await TREXFactory.deploy(
await trexImplementationAuthority.getAddress(),
await identityFactory.getAddress(),
{
gasLimit: 15000000,
}
await identityFactory.getAddress(),{ gasLimit: 15000000 }
);
await trexFactory.waitForDeployment();
console.log("trexFactory", await trexFactory.getAddress());

// @ts-ignore
await identityFactory.addTokenFactory(await trexFactory.getAddress());

const claimTopicsRegistry = await ethers
.deployContract('ClaimTopicsRegistryProxy', [await trexImplementationAuthority.getAddress()], deployer)
.then(async (proxy) => ethers.getContractAt('ClaimTopicsRegistry', await proxy.getAddress()));
console.log("claimTopicsRegistryProxy", await claimTopicsRegistry.getAddress());

const trustedIssuersRegistry = await ethers
.deployContract('TrustedIssuersRegistryProxy', [await trexImplementationAuthority.getAddress()], deployer)
.then(async (proxy) => ethers.getContractAt('TrustedIssuersRegistry', await proxy.getAddress()));
console.log("trustedIssuersRegistryProxy", await trustedIssuersRegistry.getAddress());

const identityRegistryStorage = await ethers
.deployContract('IdentityRegistryStorageProxy', [await trexImplementationAuthority.getAddress()], deployer)
.then(async (proxy) => ethers.getContractAt('IdentityRegistryStorage', await proxy.getAddress()));
console.log("identityRegistryStorageProxy", await identityRegistryStorage.getAddress());

const defaultCompliance = await ethers.deployContract('DefaultCompliance', deployer);
console.log("defaultCompliance", await defaultCompliance.getAddress());

const identityRegistry = await ethers
.deployContract(
'IdentityRegistryProxy',
[await trexImplementationAuthority.getAddress(), await trustedIssuersRegistry.getAddress(), await claimTopicsRegistry.getAddress() , await identityRegistryStorage.getAddress()],
deployer,
)
.then(async (proxy) => ethers.getContractAt('IdentityRegistry', await proxy.getAddress()));
console.log("identityRegistryProxy", await identityRegistry.getAddress());

// @ts-ignore
const tokenOID = await deployIdentityProxy(await identityImplementationAuthority.getAddress(), await tokenIssuer.getAddress(), deployer);
console.log("tokenOID", await tokenOID.getAddress());
return {
...contracts,
implementations: {
Token: await tokenImplementation.getAddress(),
ClaimTopicsRegistry: await claimTopicsRegistryImplementation.getAddress(),
TrustedIssuersRegistry: await trustedIssuersRegistryImplementation.getAddress(),
IdentityRegistryStorage: await identityRegistryStorageImplementation.getAddress(),
IdentityRegistry: await identityRegistryImplementation.getAddress(),
ModularCompliance: await modularComplianceImplementation.getAddress(),
Identity: await identityImplementation.getAddress(),
ImplementationAuthority: await identityImplementationAuthority.getAddress(),
},
factories: {
IdFactory: await identityFactory.getAddress(),
TREXImplementationAuthority: await trexImplementationAuthority.getAddress(),
TREXFactory: await trexFactory.getAddress(),
}
}

}

async function deployComplianceModules(contracts: Record<string, any>): Promise<Record<string, any>> {
const [deployer] = await ethers.getSigners();

// Deploy compliance Modules
const requiresNFTModule = await ethers.deployContract('RequiresNFTModule', deployer);
const countryAllowModule = await ethers.deployContract('CountryAllowModule', deployer);

await identityRegistryStorage.connect(deployer).bindIdentityRegistry(await identityRegistry.getAddress());
return {
...contracts,
compliance: {
RequiresNFTModule: await requiresNFTModule.getAddress(),
CountryAllowModule: await countryAllowModule.getAddress(),
}
}
}

// Deploy Vault contracts
async function deployVault(contracts: Record<string, any>): Promise<Record<string, any>> {
console.log(' - Deploying Vault contracts...');
return {
...contracts,
vault: {

const claimTopics = [ethers.id('CLAIM_TOPIC')];
await claimTopicsRegistry.connect(deployer).addClaimTopic(claimTopics[0]);

const claimIssuerContract = await deployClaimIssuer(await claimIssuer.getAddress(), deployer);
console.log("claimIssuerContract", await claimIssuerContract.getAddress());
}
};
}

await claimIssuerContract
.connect(claimIssuer)
//@ts-ignore
.addKey(ethers.keccak256(AbiCoder.defaultAbiCoder().encode(['address'], [await claimIssuerSigningKey.getAddress()])), 3, 1);
// creates a deployment file into data/deployments (eg: data/deployments/mainnet.json)
async function exportDeploymentVersion(contracts: Record<string, any>): Promise<Record<string, any>> {
console.log(' - Export Deployment contract addresses...');
const network = await ethers.provider.getNetwork();
const filePath = `./data/deployments/chain-${network.chainId.toString()}.json`
const jsonData = JSON.stringify(contracts, null, 2);
await writeFile(filePath, jsonData, 'utf-8');
console.log(` - Deployment addresses written to ${filePath}`);

await trustedIssuersRegistry.connect(deployer).addTrustedIssuer(await claimIssuerContract.getAddress(), claimTopics);
return contracts;
}

console.log('done');
// Finish function
async function finish(): Promise<void> {
console.log(' - Finished');
process.exit();
}

deployTRex()
init()
// add subsequent deployment script after this comment
.then(deployERC3643)
.then(deployComplianceModules)
.then(deployVault)
.then(exportDeploymentVersion)
.then(finish)
.catch((error) => {
console.error(error);
process.exitCode = 1;
Expand Down

0 comments on commit 0e73f1e

Please sign in to comment.